Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 #ifndef _CFG_PARSER_H
00036 #define _CFG_PARSER_H
00037
00038 #include "str.h"
00039 #include <stdio.h>
00040
00041 #define MAX_TOKEN_LEN 512
00045 typedef enum cfg_flags {
00046
00050 CFG_EXTENDED_ALPHA = (1 << 0),
00051
00056 CFG_CASE_SENSITIVE = (1 << 1),
00057
00063 CFG_DEFAULT = (1 << 2),
00064
00065
00069 CFG_PREFIX = (1 << 3),
00070
00075 CFG_STR_PKGMEM = (1 << 4),
00076
00081 CFG_STR_SHMMEM = (1 << 5),
00082
00087 CFG_STR_MALLOC = (1 << 6),
00088
00093 CFG_STR_STATIC = (1 << 7),
00094
00095 } cfg_flags_t;
00096
00097
00098 enum cfg_token_type {
00099 CFG_TOKEN_EOF = -1,
00100 CFG_TOKEN_ALPHA = -2,
00101 CFG_TOKEN_STRING = -3
00102 };
00103
00104
00106 typedef struct cfg_token {
00107 char buf [MAX_TOKEN_LEN];
00108 int type;
00109 str val;
00110 struct {
00111 int line;
00112 int col;
00113 } start, end;
00114 } cfg_token_t;
00115
00116
00117 struct cfg_parser;
00118
00119 typedef int (*cfg_func_f)(void* param, struct cfg_parser* st,
00120 unsigned int flags);
00121
00122
00128 typedef struct cfg_option {
00129 char* name;
00130 unsigned int flags;
00131 void* param;
00132 int val;
00133 cfg_func_f f;
00134 } cfg_option_t;
00135
00136
00138 typedef struct cfg_parser {
00139 FILE* f;
00140 char* file;
00141 int line;
00142 int col;
00143 struct cfg_option* options;
00144 struct {
00145 cfg_func_f parser;
00146 void* param;
00147 } section;
00148 struct cfg_token* cur_opt;
00149 } cfg_parser_t;
00150
00151
00152 extern struct cfg_option cfg_bool_values[];
00153
00154 struct cfg_parser* cfg_parser_init(str* basedir, str* filename);
00155
00156 void cfg_section_parser(struct cfg_parser* st, cfg_func_f parser, void* param);
00157
00158 void cfg_set_options(struct cfg_parser* st, struct cfg_option* options);
00159
00160 int sr_cfg_parse(struct cfg_parser* st);
00161
00162 void cfg_parser_close(struct cfg_parser* st);
00163
00164 struct cfg_option* cfg_lookup_token(struct cfg_option* options, str* token);
00165
00167 int cfg_get_token(struct cfg_token* token, struct cfg_parser* st, unsigned int flags);
00168
00169
00170
00171 int cfg_eat_equal(struct cfg_parser* st, unsigned int flags);
00172
00173 int cfg_eat_eol(struct cfg_parser* st, unsigned int flags);
00174
00179 int cfg_parse_section(void* param, struct cfg_parser* st, unsigned int flags);
00180
00182 int cfg_parse_str_opt(void* param, struct cfg_parser* st, unsigned int flags);
00183
00184 int cfg_parse_str(void* param, struct cfg_parser* st, unsigned int flags);
00185
00186 int cfg_parse_enum_opt(void* param, struct cfg_parser* st, unsigned int flags);
00187
00188 int cfg_parse_enum(void* param, struct cfg_parser* st, unsigned int flags);
00189
00191 int cfg_parse_int_opt(void* param, struct cfg_parser* st, unsigned int flags);
00192
00193 int cfg_parse_int(void* param, struct cfg_parser* st, unsigned int flags);
00194
00196 int cfg_parse_bool_opt(void* param, struct cfg_parser* st, unsigned int flags);
00197
00198 int cfg_parse_bool(void* param, struct cfg_parser* st, unsigned int flags);
00199
00200 #endif