1 |
/* |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
4 |
*/ |
*/ |
5 |
|
|
15 |
PARSER_ERROR_UNEXP_EOL, /* Unexpected end of line */ |
PARSER_ERROR_UNEXP_EOL, /* Unexpected end of line */ |
16 |
}; |
}; |
17 |
|
|
18 |
|
/* Parser states */ |
19 |
|
enum { |
20 |
|
PARSER_STATE_DONE, |
21 |
|
PARSER_STATE_SKIP, |
22 |
|
PARSER_STATE_BLANK, |
23 |
|
PARSER_STATE_STRING, |
24 |
|
PARSER_STATE_QUOTED_STRING, |
25 |
|
}; |
26 |
|
|
27 |
/* Token */ |
/* Token */ |
28 |
typedef struct parser_token parser_token_t; |
typedef struct parser_token parser_token_t; |
29 |
struct parser_token { |
struct parser_token { |
31 |
struct parser_token *next; |
struct parser_token *next; |
32 |
}; |
}; |
33 |
|
|
34 |
/* Get a description given an error code */ |
/* Parser context */ |
35 |
char *parser_strerror(int error); |
typedef struct parser_context parser_context_t; |
36 |
|
struct parser_context { |
37 |
|
/* Token list */ |
38 |
|
parser_token_t *tok_head,*tok_last; |
39 |
|
int tok_count; |
40 |
|
|
41 |
|
/* Temporary token */ |
42 |
|
char *tmp_tok; |
43 |
|
size_t tmp_tot_len,tmp_cur_len; |
44 |
|
|
45 |
|
/* Parser state and error */ |
46 |
|
int state,error; |
47 |
|
|
48 |
|
/* Number of consumed chars */ |
49 |
|
size_t consumed_len; |
50 |
|
}; |
51 |
|
|
52 |
/* Free a token list */ |
/* Get a description given an error code */ |
53 |
void parser_free_tokens(parser_token_t *tok_list); |
char *parser_strerror(parser_context_t *ctx); |
54 |
|
|
55 |
/* Dump a token list */ |
/* Dump a token list */ |
56 |
void parser_dump_tokens(parser_token_t *tok_list); |
void parser_dump_tokens(parser_context_t *ctx); |
57 |
|
|
58 |
/* Map a token list to an array */ |
/* Map a token list to an array */ |
59 |
char **parser_map_array(parser_token_t *tok_list,int tok_count); |
char **parser_map_array(parser_context_t *ctx); |
60 |
|
|
61 |
|
/* Initialize parser context */ |
62 |
|
void parser_context_init(parser_context_t *ctx); |
63 |
|
|
64 |
|
/* Free memory used by a parser context */ |
65 |
|
void parser_context_free(parser_context_t *ctx); |
66 |
|
|
67 |
|
/* Send a buffer to the tokenizer */ |
68 |
|
int parser_scan_buffer(parser_context_t *ctx,u_char *buf,size_t buf_size); |
69 |
|
|
70 |
/* Tokenize a string */ |
/* Tokenize a string */ |
71 |
int parser_tokenize(char *str,struct parser_token **tokens,int *tok_count); |
int parser_tokenize(char *str,struct parser_token **tokens,int *tok_count); |