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)))
58 static void __attribute__ ((noreturn))
59 parse_err(char* msg, ...)
64 fprintf(stderr, "Line %d: ", line);
65 vfprintf(stderr, msg, args);
76 if (!(ret = strdup(s)))
83 get_string_out(int delim)
90 while ((c = getc(conf)) != delim || last == '\\'){
91 if (last=='\\' && c != delim)
99 parse_err("Too long string, max allowed length is %d",BUFSIZE-1);
109 return (c >= '0' && c <= '9' ) ||
110 (c >= 'a' && c <= 'z') ||
111 (c >= 'A' && c <= 'Z') ||
119 return (c >= 'a' && c <= 'z') ||
120 (c >= 'A' && c <= 'Z');
128 while ((c = getc(conf)) == ' ' || c == '\t' || c =='\n'){
139 case CC('!','='): yylval.n = CC('!','='); return NEQ;
140 case CC('!','~'): yylval.n = CC('!','='); return NRE;
141 case CC('<','='): yylval.n = CC('<','='); return LE;
142 case CC('>','='): yylval.n = CC('>','='); return GE;
143 case CC('=','='): yylval.n = CC('=','='); return EQ;
144 case CC('~','~'): yylval.n = CC('~','~'); return RE;
145 case CC('-','>'): yylval.n = CC('-','>'); return ARROW;
173 yylval.str = get_string_out(c);
177 if (c >= '0' && c <= '9'){
182 while ((c = getc(conf))>= '0' && c<= '9'){
186 parse_err("Too long number");
190 yylval.str = xstrdup(buf);
199 while (is_var_id(c = getc(conf))){
203 parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);
207 yylval.str = xstrdup(buf);
217 while (is_alpha(c = getc(conf))){
220 parse_err("Keyword too long");
225 n = (sizeof(kwds)/sizeof(struct keys));
226 for (i = 0; i < n; i++){
227 if (!strcmp(buf,kwds[i].keywords))
228 return kwds[i].keytoks;
231 parse_err("Unknown keyword %s", buf);
234 parse_err("Unknown character %c", c);