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.
17 #define LKC_DIRECT_LINK
20 #define START_STRSIZE 16
23 static char *text_ptr;
24 static int text_size, text_asize;
27 struct buffer *parent;
28 YY_BUFFER_STATE state;
31 struct buffer *current_buf;
33 static int last_ts, first_ts;
35 static void zconf_endhelp(void);
36 static struct buffer *zconf_endfile(void);
40 text = malloc(START_STRSIZE);
41 text_asize = START_STRSIZE;
47 void append_string(const char *str, int size)
49 int new_size = text_size + size + 1;
50 if (new_size > text_asize) {
51 text = realloc(text, new_size);
52 text_asize = new_size;
53 text_ptr = text + text_size;
55 memcpy(text_ptr, str, size);
61 void alloc_string(const char *str, int size)
63 text = malloc(size + 1);
64 memcpy(text, str, size);
76 [ \t]*#.*\n current_file->lineno++;
79 [ \t]*\n current_file->lineno++; return T_EOL;
92 "mainmenu" BEGIN(PARAM); return T_MAINMENU;
93 "menu" BEGIN(PARAM); return T_MENU;
94 "endmenu" BEGIN(PARAM); return T_ENDMENU;
95 "source" BEGIN(PARAM); return T_SOURCE;
96 "choice" BEGIN(PARAM); return T_CHOICE;
97 "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
98 "comment" BEGIN(PARAM); return T_COMMENT;
99 "config" BEGIN(PARAM); return T_CONFIG;
100 "menuconfig" BEGIN(PARAM); return T_MENUCONFIG;
101 "help" BEGIN(PARAM); return T_HELP;
102 "if" BEGIN(PARAM); return T_IF;
103 "endif" BEGIN(PARAM); return T_ENDIF;
104 "depends" BEGIN(PARAM); return T_DEPENDS;
105 "requires" BEGIN(PARAM); return T_REQUIRES;
106 "optional" BEGIN(PARAM); return T_OPTIONAL;
107 "default" BEGIN(PARAM); return T_DEFAULT;
108 "prompt" BEGIN(PARAM); return T_PROMPT;
109 "tristate" BEGIN(PARAM); return T_TRISTATE;
110 "def_tristate" BEGIN(PARAM); return T_DEF_TRISTATE;
111 "bool" BEGIN(PARAM); return T_BOOLEAN;
112 "boolean" BEGIN(PARAM); return T_BOOLEAN;
113 "def_bool" BEGIN(PARAM); return T_DEF_BOOLEAN;
114 "def_boolean" BEGIN(PARAM); return T_DEF_BOOLEAN;
115 "int" BEGIN(PARAM); return T_INT;
116 "hex" BEGIN(PARAM); return T_HEX;
117 "string" BEGIN(PARAM); return T_STRING;
118 "select" BEGIN(PARAM); return T_SELECT;
119 "enable" BEGIN(PARAM); return T_SELECT;
120 "range" BEGIN(PARAM); return T_RANGE;
122 alloc_string(yytext, yyleng);
123 zconflval.string = text;
127 \n current_file->lineno++; BEGIN(INITIAL);
133 "(" return T_OPEN_PAREN;
134 ")" return T_CLOSE_PAREN;
137 "!=" return T_UNEQUAL;
145 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
148 alloc_string(yytext, yyleng);
149 zconflval.string = text;
153 \\\n current_file->lineno++;
162 append_string(yytext, yyleng);
163 zconflval.string = text;
167 append_string(yytext, yyleng);
170 append_string(yytext + 1, yyleng - 1);
171 zconflval.string = text;
175 append_string(yytext + 1, yyleng - 1);
178 if (str == yytext[0]) {
180 zconflval.string = text;
183 append_string(yytext, 1);
186 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
187 current_file->lineno++;
199 for (i = 0; i < yyleng; i++) {
200 if (yytext[i] == '\t')
213 append_string(" ", 8);
216 append_string(" ", ts);
220 current_file->lineno++;
225 current_file->lineno++;
226 append_string("\n", 1);
229 append_string(yytext, yyleng);
249 void zconf_starthelp(void)
252 last_ts = first_ts = 0;
256 static void zconf_endhelp(void)
258 zconflval.string = text;
264 * Try to open specified file with following names:
267 * The latter is used when srctree is separate from objtree
268 * when compiling the kernel.
269 * Return NULL if file is not found.
271 FILE *zconf_fopen(const char *name)
273 char *env, fullname[PATH_MAX+1];
276 f = fopen(name, "r");
277 if (!f && name[0] != '/') {
278 env = getenv(SRCTREE);
280 sprintf(fullname, "%s/%s", env, name);
281 f = fopen(fullname, "r");
287 void zconf_initscan(const char *name)
289 yyin = zconf_fopen(name);
291 printf("can't find file %s\n", name);
295 current_buf = malloc(sizeof(*current_buf));
296 memset(current_buf, 0, sizeof(*current_buf));
298 current_file = file_lookup(name);
299 current_file->lineno = 1;
300 current_file->flags = FILE_BUSY;
303 void zconf_nextfile(const char *name)
312 retval = glob(name, GLOB_ERR | GLOB_MARK, NULL, &files);
313 if (retval == GLOB_NOSPACE || retval == GLOB_ABORTED || retval == GLOB_NOMATCH) {
314 printf("%s:%d: glob failed: %s \"%s\"\n", zconf_curname(), zconf_lineno(),
315 retval == GLOB_NOSPACE ? "failed to allocate memory" :
316 retval == GLOB_ABORTED ? "read error" : "no match",
321 for (i = files.gl_pathc-1; i != (size_t)-1; --i) {
322 filename = files.gl_pathv[i];
324 file = file_lookup(filename);
325 buf = malloc(sizeof(*buf));
326 memset(buf, 0, sizeof(*buf));
327 current_buf->state = YY_CURRENT_BUFFER;
328 zconfin = zconf_fopen(filename);
330 printf("%s:%d: can't open file \"%s\"\n",
331 zconf_curname(), zconf_lineno(), filename);
334 zconf_switch_to_buffer(zconf_create_buffer(zconfin,YY_BUF_SIZE));
335 buf->parent = current_buf;
338 if (file->flags & FILE_BUSY) {
339 printf("recursive scan (%s)?\n", filename);
342 if (file->flags & FILE_SCANNED) {
343 printf("file %s already scanned?\n", filename);
346 file->flags |= FILE_BUSY;
348 file->parent = current_file;
353 static struct buffer *zconf_endfile(void)
355 struct buffer *parent;
357 current_file->flags |= FILE_SCANNED;
358 current_file->flags &= ~FILE_BUSY;
359 current_file = current_file->parent;
361 parent = current_buf->parent;
364 yy_delete_buffer(YY_CURRENT_BUFFER);
365 yy_switch_to_buffer(parent->state);
368 current_buf = parent;
373 int zconf_lineno(void)
376 return current_file->lineno - 1;
381 char *zconf_curname(void)
384 return current_file->name;