14 enum yytokentype keytoks;
17 static struct keys kwds[] =
23 {"discard", KW_DISCARD}
27 read_conf(char* filename)
29 conf = fopen(filename, "r");
35 void __attribute__ ((noreturn))
41 vfprintf(stderr, msg, args);
52 if (!(ret = malloc(size)))
59 xrealloc(void* buf, size_t size)
61 buf = realloc(buf, size);
69 static void __attribute__ ((noreturn))
70 parse_err(char* msg, ...)
75 fprintf(stderr, "Line %d: ", line);
76 vfprintf(stderr, msg, args);
87 if (!(ret = strdup(s)))
94 get_string_out(int delim)
101 while ((c = getc(conf)) != delim || last == '\\'){
102 if (last=='\\' && c != delim)
110 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
120 return (c >= '0' && c <= '9' ) ||
121 (c >= 'a' && c <= 'z') ||
122 (c >= 'A' && c <= 'Z') ||
130 return (c >= 'a' && c <= 'z') ||
131 (c >= 'A' && c <= 'Z');
139 while ((c = getc(conf)) == ' ' || c == '\t' || c =='\n'){
150 case CC('!','='): yylval.n = CC('!','='); return NEQ;
151 case CC('!','~'): yylval.n = CC('!','='); return NRE;
152 case CC('<','='): yylval.n = CC('<','='); return LE;
153 case CC('>','='): yylval.n = CC('>','='); return GE;
154 case CC('=','='): yylval.n = CC('=','='); return EQ;
155 case CC('~','~'): yylval.n = CC('~','~'); return RE;
156 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
184 yylval.str = get_string_out(c);
188 if (c >= '0' && c <= '9'){
193 while ((c = getc(conf))>= '0' && c<= '9'){
197 parse_err("Too long number");
201 yylval.str = xstrdup(buf);
210 while (is_var_id(c = getc(conf))){
214 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
218 yylval.str = xstrdup(buf);
228 while (is_alpha(c = getc(conf))){
231 parse_err("Keyword too long");
236 n = (sizeof(kwds)/sizeof(struct keys));
237 for (i = 0; i < n; i++){
238 if (!strcmp(buf,kwds[i].keywords))
239 return kwds[i].keytoks;
242 parse_err("Unknown keyword %s", buf);
245 parse_err("Unknown character %c", c);