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
27 static int text_size, text_asize;
30 struct buffer *parent;
31 YY_BUFFER_STATE state;
34 struct buffer *current_buf;
36 static int last_ts, first_ts;
38 static void zconf_endhelp(void);
39 static void zconf_endfile(void);
43 text = malloc(START_STRSIZE);
44 text_asize = START_STRSIZE;
49 void append_string(const char *str, int size)
51 int new_size = text_size + size + 1;
53 fprintf (stderr, "%s:%d error: Overlong line\n",
54 current_file->name, current_file->lineno);
56 if (new_size > text_asize) {
57 new_size += START_STRSIZE - 1;
58 new_size &= -START_STRSIZE;
59 text = realloc(text, new_size);
60 text_asize = new_size;
62 memcpy(text + text_size, str, size);
67 void alloc_string(const char *str, int size)
69 text = malloc(size + 1);
70 memcpy(text, str, size);
84 current_file->lineno++;
102 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
104 current_pos.file = current_file;
105 current_pos.lineno = current_file->lineno;
106 if (id && id->flags & TF_COMMAND) {
110 alloc_string(yytext, yyleng);
111 zconflval.string = text;
117 current_file->lineno++;
125 "(" return T_OPEN_PAREN;
126 ")" return T_CLOSE_PAREN;
129 "!=" return T_UNEQUAL;
135 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
138 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
139 if (id && id->flags & TF_PARAM) {
143 alloc_string(yytext, yyleng);
144 zconflval.string = text;
148 \\\n current_file->lineno++;
157 append_string(yytext, yyleng);
158 zconflval.string = text;
162 append_string(yytext, yyleng);
165 append_string(yytext + 1, yyleng - 1);
166 zconflval.string = text;
170 append_string(yytext + 1, yyleng - 1);
173 if (str == yytext[0]) {
175 zconflval.string = text;
178 append_string(yytext, 1);
181 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
182 current_file->lineno++;
194 for (i = 0; i < yyleng; i++) {
195 if (yytext[i] == '\t')
208 append_string(" ", 8);
211 append_string(" ", ts);
215 current_file->lineno++;
220 current_file->lineno++;
221 append_string("\n", 1);
224 append_string(yytext, yyleng);
244 void zconf_starthelp(void)
247 last_ts = first_ts = 0;
251 static void zconf_endhelp(void)
253 zconflval.string = text;
259 * Try to open specified file with following names:
262 * The latter is used when srctree is separate from objtree
263 * when compiling the kernel.
264 * Return NULL if file is not found.
266 FILE *zconf_fopen(const char *name)
268 char *env, fullname[PATH_MAX+1];
271 f = fopen(name, "r");
272 if (!f && name[0] != '/') {
273 env = getenv(SRCTREE);
275 sprintf(fullname, "%s/%s", env, name);
276 f = fopen(fullname, "r");
282 void zconf_initscan(const char *name)
284 yyin = zconf_fopen(name);
286 printf("can't find file %s\n", name);
290 current_buf = malloc(sizeof(*current_buf));
291 memset(current_buf, 0, sizeof(*current_buf));
293 current_file = file_lookup(name);
294 current_file->lineno = 1;
295 current_file->flags = FILE_BUSY;
298 void zconf_nextfile(const char *name)
300 struct file *file = file_lookup(name);
301 struct buffer *buf = malloc(sizeof(*buf));
302 memset(buf, 0, sizeof(*buf));
304 current_buf->state = YY_CURRENT_BUFFER;
305 yyin = zconf_fopen(name);
307 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
310 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
311 buf->parent = current_buf;
314 if (file->flags & FILE_BUSY) {
315 printf("recursive scan (%s)?\n", name);
318 if (file->flags & FILE_SCANNED) {
319 printf("file %s already scanned?\n", name);
322 file->flags |= FILE_BUSY;
324 file->parent = current_file;
328 static void zconf_endfile(void)
330 struct buffer *parent;
332 current_file->flags |= FILE_SCANNED;
333 current_file->flags &= ~FILE_BUSY;
334 current_file = current_file->parent;
336 parent = current_buf->parent;
339 yy_delete_buffer(YY_CURRENT_BUFFER);
340 yy_switch_to_buffer(parent->state);
343 current_buf = parent;
346 int zconf_lineno(void)
348 return current_pos.lineno;
351 char *zconf_curname(void)
353 return current_pos.file ? current_pos.file->name : "<none>";