13 enum yytokentype keytoks;
16 static struct keys kwds[] =
22 {"discard", KW_DISCARD}
26 read_conf(char* filename)
28 conf = fopen(filename, "r");
34 void __attribute__ ((noreturn))
40 vfprintf(stderr, msg, args);
51 if (!(ret = malloc(size)))
58 xrealloc(void* buf, size_t size)
60 buf = realloc(buf, size);
68 static void __attribute__ ((noreturn))
69 parse_err(char* msg, ...)
74 fprintf(stderr, "Line %d: ", line);
75 vfprintf(stderr, msg, args);
82 xstrdup(const char* s)
86 if (!(ret = strdup(s)))
93 get_string_out(int delim)
100 while ((c = getc(conf)) != delim || last == '\\'){
101 if (last=='\\' && c != delim)
109 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
119 return (c >= '0' && c <= '9' ) ||
120 (c >= 'a' && c <= 'z') ||
121 (c >= 'A' && c <= 'Z') ||
129 return (c >= 'a' && c <= 'z') ||
130 (c >= 'A' && c <= 'Z');
138 while ((c = getc(conf)) == ' ' || c == '\t' || c =='\n'){
149 case CC('!','='): yylval.n = CC('!','='); return NEQ;
150 case CC('!','~'): yylval.n = CC('!','='); return NRE;
151 case CC('<','='): yylval.n = CC('<','='); return LE;
152 case CC('>','='): yylval.n = CC('>','='); return GE;
153 case CC('=','='): yylval.n = CC('=','='); return EQ;
154 case CC('~','~'): yylval.n = CC('~','~'); return RE;
155 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
183 yylval.str = get_string_out(c);
187 if (c >= '0' && c <= '9'){
192 while ((c = getc(conf))>= '0' && c<= '9'){
196 parse_err("Too long number");
200 yylval.str = xstrdup(buf);
209 while (is_var_id(c = getc(conf))){
213 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
217 yylval.str = xstrdup(buf);
227 while (is_alpha(c = getc(conf))){
230 parse_err("Keyword too long");
235 n = (sizeof(kwds)/sizeof(struct keys));
236 for (i = 0; i < n; i++){
237 if (!strcmp(buf,kwds[i].keywords))
238 return kwds[i].keytoks;
241 parse_err("Unknown keyword %s", buf);
244 parse_err("Unknown character %c", c);