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.
16 #define LKC_DIRECT_LINK
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 "menuconfig" BEGIN(PARAM); return T_MENUCONFIG;
100 "help" BEGIN(PARAM); return T_HELP;
101 "if" BEGIN(PARAM); return T_IF;
102 "endif" BEGIN(PARAM); return T_ENDIF;
103 "depends" BEGIN(PARAM); return T_DEPENDS;
104 "requires" BEGIN(PARAM); return T_REQUIRES;
105 "optional" BEGIN(PARAM); return T_OPTIONAL;
106 "default" BEGIN(PARAM); return T_DEFAULT;
107 "prompt" BEGIN(PARAM); return T_PROMPT;
108 "tristate" BEGIN(PARAM); return T_TRISTATE;
109 "def_tristate" BEGIN(PARAM); return T_DEF_TRISTATE;
110 "bool" BEGIN(PARAM); return T_BOOLEAN;
111 "boolean" BEGIN(PARAM); return T_BOOLEAN;
112 "def_bool" BEGIN(PARAM); return T_DEF_BOOLEAN;
113 "def_boolean" BEGIN(PARAM); return T_DEF_BOOLEAN;
114 "int" BEGIN(PARAM); return T_INT;
115 "hex" BEGIN(PARAM); return T_HEX;
116 "string" BEGIN(PARAM); return T_STRING;
117 "select" BEGIN(PARAM); return T_SELECT;
118 "enable" BEGIN(PARAM); return T_SELECT;
119 "range" BEGIN(PARAM); return T_RANGE;
121 alloc_string(yytext, yyleng);
122 zconflval.string = text;
126 \n current_file->lineno++; BEGIN(INITIAL);
132 "(" return T_OPEN_PAREN;
133 ")" return T_CLOSE_PAREN;
136 "!=" return T_UNEQUAL;
144 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
147 alloc_string(yytext, yyleng);
148 zconflval.string = text;
152 \\\n current_file->lineno++;
161 append_string(yytext, yyleng);
162 zconflval.string = text;
166 append_string(yytext, yyleng);
169 append_string(yytext + 1, yyleng - 1);
170 zconflval.string = text;
174 append_string(yytext + 1, yyleng - 1);
177 if (str == yytext[0]) {
179 zconflval.string = text;
182 append_string(yytext, 1);
185 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
186 current_file->lineno++;
198 for (i = 0; i < yyleng; i++) {
199 if (yytext[i] == '\t')
212 append_string(" ", 8);
215 append_string(" ", ts);
219 current_file->lineno++;
224 current_file->lineno++;
225 append_string("\n", 1);
228 append_string(yytext, yyleng);
248 void zconf_starthelp(void)
251 last_ts = first_ts = 0;
255 static void zconf_endhelp(void)
257 zconflval.string = text;
263 * Try to open specified file with following names:
266 * The latter is used when srctree is separate from objtree
267 * when compiling the kernel.
268 * Return NULL if file is not found.
270 FILE *zconf_fopen(const char *name)
272 char *env, fullname[PATH_MAX+1];
275 f = fopen(name, "r");
276 if (!f && name[0] != '/') {
277 env = getenv(SRCTREE);
279 sprintf(fullname, "%s/%s", env, name);
280 f = fopen(fullname, "r");
286 void zconf_initscan(const char *name)
288 yyin = zconf_fopen(name);
290 printf("can't find file %s\n", name);
294 current_buf = malloc(sizeof(*current_buf));
295 memset(current_buf, 0, sizeof(*current_buf));
297 current_file = file_lookup(name);
298 current_file->lineno = 1;
299 current_file->flags = FILE_BUSY;
302 void zconf_nextfile(const char *name)
304 struct file *file = file_lookup(name);
305 struct buffer *buf = malloc(sizeof(*buf));
306 memset(buf, 0, sizeof(*buf));
308 current_buf->state = YY_CURRENT_BUFFER;
309 yyin = zconf_fopen(name);
311 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
314 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
315 buf->parent = current_buf;
318 if (file->flags & FILE_BUSY) {
319 printf("recursive scan (%s)?\n", name);
322 if (file->flags & FILE_SCANNED) {
323 printf("file %s already scanned?\n", name);
326 file->flags |= FILE_BUSY;
328 file->parent = current_file;
332 static struct buffer *zconf_endfile(void)
334 struct buffer *parent;
336 current_file->flags |= FILE_SCANNED;
337 current_file->flags &= ~FILE_BUSY;
338 current_file = current_file->parent;
340 parent = current_buf->parent;
343 yy_delete_buffer(YY_CURRENT_BUFFER);
344 yy_switch_to_buffer(parent->state);
347 current_buf = parent;
352 int zconf_lineno(void)
355 return current_file->lineno - 1;
360 char *zconf_curname(void)
363 return current_file->name;