1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef __LEXER_H
#define __LEXER_H
#include <list.h>
#define DIRECTIVE_IS(key) strncmp(buffer + n, key, strlen(key)) == 0
typedef enum {
_RAW,
INCLUDE,
CONTENT,
CONTENTFOR,
ENDCONTENT,
BODY,
EACHDO,
ENDEACHDO,
PUT
} directive_e;
typedef struct {
unsigned int offset;
unsigned int length;
} key_match_t;
typedef struct {
directive_e type;
void *operands;
} directive_t;
/* TODO: strlen(content) instead of length? */
typedef struct {
char *key;
char *content;
unsigned int length;
} contentfor_operand_t;
typedef struct {
char *key;
char *content;
size_t length;
} eachdo_operands_t;
list_t *lex(char *buffer);
directive_t *find_directive(char *content, key_match_t *match);
key_match_t *find_next_key(char *buffer, size_t skip);
char *find_contentfor_value(list_t *content_headers, char *key);
void directive_delete(directive_t *directive);
void lexer_handle_include(directive_t *directive,
key_match_t *match,
char *buffer,
size_t n);
void lexer_handle_contentfor(directive_t *directive,
key_match_t *match,
char *buffer,
char *content,
size_t n);
void lexer_handle_content(directive_t *directive,
key_match_t *match,
char *buffer,
size_t n);
void lexer_handle_eachdo(directive_t *directive,
key_match_t *match,
char *buffer,
size_t n);
void lexer_handle_put(directive_t *directive,
key_match_t *match,
char *buffer,
size_t n);
#endif
|