1 %option nostdinit noyywrap never-interactive full ecs
2 %option 8bit nodefault perf-report perf-report
4 %x COMMAND HELP STRING PARAM
7 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
8 * Released under the terms of the GNU GPL v2.0.
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);
41 static void new_string(void)
43 text = xmalloc(START_STRSIZE);
44 text_asize = START_STRSIZE;
49 static void append_string(const char *str, int size)
51 int new_size = text_size + size + 1;
52 if (new_size > text_asize) {
53 new_size += START_STRSIZE - 1;
54 new_size &= -START_STRSIZE;
55 text = realloc(text, new_size);
56 text_asize = new_size;
58 memcpy(text + text_size, str, size);
63 static void alloc_string(const char *str, int size)
65 text = xmalloc(size + 1);
66 memcpy(text, str, size);
79 current_file->lineno++;
97 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
99 current_pos.file = current_file;
100 current_pos.lineno = current_file->lineno;
101 if (id && id->flags & TF_COMMAND) {
105 alloc_string(yytext, yyleng);
106 zconflval.string = text;
112 current_file->lineno++;
120 "(" return T_OPEN_PAREN;
121 ")" return T_CLOSE_PAREN;
124 "!=" return T_UNEQUAL;
130 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
133 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
134 if (id && id->flags & TF_PARAM) {
138 alloc_string(yytext, yyleng);
139 zconflval.string = text;
143 \\\n current_file->lineno++;
147 "%s:%d:warning: ignoring unsupported character '%c'\n",
148 zconf_curname(), zconf_lineno(), *yytext);
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);
225 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
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 firmware.
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 != NULL && 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 = xmalloc(sizeof(*current_buf));
296 memset(current_buf, 0, sizeof(*current_buf));
298 current_file = file_lookup(name);
299 current_file->lineno = 1;
302 void zconf_nextfile(const char *name)
305 struct file *file = file_lookup(name);
306 struct buffer *buf = xmalloc(sizeof(*buf));
307 memset(buf, 0, sizeof(*buf));
309 current_buf->state = YY_CURRENT_BUFFER;
310 yyin = zconf_fopen(file->name);
312 printf("%s:%d: can't open file \"%s\"\n",
313 zconf_curname(), zconf_lineno(), file->name);
316 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
317 buf->parent = current_buf;
320 for (iter = current_file->parent; iter; iter = iter->parent ) {
321 if (!strcmp(current_file->name,iter->name) ) {
322 printf("%s:%d: recursive inclusion detected. "
323 "Inclusion path:\n current file : '%s'\n",
324 zconf_curname(), zconf_lineno(),
326 iter = current_file->parent;
328 strcmp(iter->name,current_file->name)) {
329 printf(" included from: '%s:%d'\n",
330 iter->name, iter->lineno-1);
334 printf(" included from: '%s:%d'\n",
335 iter->name, iter->lineno+1);
340 file->parent = current_file;
344 static void zconf_endfile(void)
346 struct buffer *parent;
348 current_file = current_file->parent;
350 parent = current_buf->parent;
353 yy_delete_buffer(YY_CURRENT_BUFFER);
354 yy_switch_to_buffer(parent->state);
357 current_buf = parent;
360 int zconf_lineno(void)
362 return current_pos.lineno;
365 const char *zconf_curname(void)
367 return current_pos.file ? current_pos.file->name : "<none>";