1 %option backup nostdinit noyywrap never-interactive full ecs
2 %option 8bit backup nodefault perf-report perf-report
3 %x COMMAND HELP STRING PARAM
6 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
7 * Released under the terms of the GNU GPL v2.0.
15 #define LKC_DIRECT_LINK
17 #include "zconf.tab.h"
19 #define START_STRSIZE 16
22 static char *text_ptr;
23 static int text_size, text_asize;
26 struct buffer *parent;
27 YY_BUFFER_STATE state;
30 struct buffer *current_buf;
32 static int last_ts, first_ts;
34 static void zconf_endhelp(void);
35 static struct buffer *zconf_endfile(void);
39 text = malloc(START_STRSIZE);
40 text_asize = START_STRSIZE;
46 void append_string(const char *str, int size)
48 int new_size = text_size + size + 1;
49 if (new_size > text_asize) {
50 text = realloc(text, new_size);
51 text_asize = new_size;
52 text_ptr = text + text_size;
54 memcpy(text_ptr, str, size);
60 void alloc_string(const char *str, int size)
62 text = malloc(size + 1);
63 memcpy(text, str, size);
75 [ \t]*#.*\n current_file->lineno++;
78 [ \t]*\n current_file->lineno++; return T_EOL;
91 "mainmenu" BEGIN(PARAM); return T_MAINMENU;
92 "menu" BEGIN(PARAM); return T_MENU;
93 "endmenu" BEGIN(PARAM); return T_ENDMENU;
94 "source" BEGIN(PARAM); return T_SOURCE;
95 "choice" BEGIN(PARAM); return T_CHOICE;
96 "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
97 "comment" BEGIN(PARAM); return T_COMMENT;
98 "config" BEGIN(PARAM); return T_CONFIG;
99 "help" BEGIN(PARAM); return T_HELP;
100 "if" BEGIN(PARAM); return T_IF;
101 "endif" BEGIN(PARAM); return T_ENDIF;
102 "depends" BEGIN(PARAM); return T_DEPENDS;
103 "requires" BEGIN(PARAM); return T_REQUIRES;
104 "optional" BEGIN(PARAM); return T_OPTIONAL;
105 "default" BEGIN(PARAM); return T_DEFAULT;
106 "prompt" BEGIN(PARAM); return T_PROMPT;
107 "tristate" BEGIN(PARAM); return T_TRISTATE;
108 "bool" BEGIN(PARAM); return T_BOOLEAN;
109 "boolean" BEGIN(PARAM); return T_BOOLEAN;
110 "int" BEGIN(PARAM); return T_INT;
111 "hex" BEGIN(PARAM); return T_HEX;
112 "string" BEGIN(PARAM); return T_STRING;
114 alloc_string(yytext, yyleng);
115 zconflval.string = text;
119 \n current_file->lineno++; BEGIN(INITIAL);
125 "(" return T_OPEN_PAREN;
126 ")" return T_CLOSE_PAREN;
129 "!=" return T_UNEQUAL;
137 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
140 alloc_string(yytext, yyleng);
141 zconflval.string = text;
152 append_string(yytext, yyleng);
153 zconflval.string = text;
157 append_string(yytext, yyleng);
160 append_string(yytext+1, yyleng);
161 zconflval.string = text;
165 append_string(yytext+1, yyleng);
168 if (str == yytext[0]) {
170 zconflval.string = text;
173 append_string(yytext, 1);
176 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
188 for (i = 0; i < yyleng; i++) {
189 if (yytext[i] == '\t')
202 append_string(" ", 8);
205 append_string(" ", ts);
210 current_file->lineno++;
215 current_file->lineno++;
216 append_string("\n", 1);
219 append_string(yytext, yyleng);
239 void zconf_starthelp(void)
242 last_ts = first_ts = 0;
246 static void zconf_endhelp(void)
248 zconflval.string = text;
252 void zconf_initscan(const char *name)
254 yyin = fopen(name, "r");
256 printf("can't find file %s\n", name);
260 current_buf = malloc(sizeof(*current_buf));
261 memset(current_buf, 0, sizeof(*current_buf));
263 current_file = file_lookup(name);
264 current_file->lineno = 1;
265 current_file->flags = FILE_BUSY;
268 void zconf_nextfile(const char *name)
270 struct file *file = file_lookup(name);
271 struct buffer *buf = malloc(sizeof(*buf));
272 memset(buf, 0, sizeof(*buf));
274 current_buf->state = YY_CURRENT_BUFFER;
275 yyin = fopen(name, "r");
277 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
280 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
281 buf->parent = current_buf;
284 if (file->flags & FILE_BUSY) {
285 printf("recursive scan (%s)?\n", name);
288 if (file->flags & FILE_SCANNED) {
289 printf("file %s already scanned?\n", name);
292 file->flags |= FILE_BUSY;
294 file->parent = current_file;
298 static struct buffer *zconf_endfile(void)
300 struct buffer *parent;
302 current_file->flags |= FILE_SCANNED;
303 current_file->flags &= ~FILE_BUSY;
304 current_file = current_file->parent;
306 parent = current_buf->parent;
309 yy_delete_buffer(YY_CURRENT_BUFFER);
310 yy_switch_to_buffer(parent->state);
313 current_buf = parent;
318 int zconf_lineno(void)
321 return current_file->lineno;
326 char *zconf_curname(void)
329 return current_file->name;