1 %option nostdinit noyywrap never-interactive full ecs
2 %option 8bit nodefault yylineno
3 %x COMMAND HELP STRING PARAM ASSIGN_VAL
6 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
7 * Released under the terms of the GNU GPL v2.0.
19 #define YY_DECL static int yylex1(void)
21 #define START_STRSIZE 16
28 static int prev_token = T_EOL;
30 static int text_size, text_asize;
33 struct buffer *parent;
34 YY_BUFFER_STATE state;
37 struct buffer *current_buf;
39 static int last_ts, first_ts;
41 static char *expand_token(const char *in, size_t n);
42 static void append_expanded_string(const char *in);
43 static void zconf_endhelp(void);
44 static void zconf_endfile(void);
46 static void new_string(void)
48 text = xmalloc(START_STRSIZE);
49 text_asize = START_STRSIZE;
54 static void append_string(const char *str, int size)
56 int new_size = text_size + size + 1;
57 if (new_size > text_asize) {
58 new_size += START_STRSIZE - 1;
59 new_size &= -START_STRSIZE;
60 text = xrealloc(text, new_size);
61 text_asize = new_size;
63 memcpy(text + text_size, str, size);
68 static void alloc_string(const char *str, int size)
70 text = xmalloc(size + 1);
71 memcpy(text, str, size);
75 static void warn_ignored_character(char chr)
78 "%s:%d:warning: ignoring unsupported character '%c'\n",
79 current_file->name, yylineno, chr);
102 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
103 current_pos.file = current_file;
104 current_pos.lineno = yylineno;
105 if (id && id->flags & TF_COMMAND) {
109 alloc_string(yytext, yyleng);
110 yylval.string = text;
114 /* this token includes at least one '$' */
115 yylval.string = expand_token(yytext, yyleng);
116 if (strlen(yylval.string))
120 "=" { BEGIN(ASSIGN_VAL); return T_EQUAL; }
121 ":=" { BEGIN(ASSIGN_VAL); return T_COLON_EQUAL; }
122 "+=" { BEGIN(ASSIGN_VAL); return T_PLUS_EQUAL; }
124 . warn_ignored_character(*yytext);
133 alloc_string(yytext, yyleng);
134 yylval.string = text;
137 \n { BEGIN(INITIAL); return T_EOL; }
142 "modules" return T_MODULES;
143 "defconfig_list" return T_DEFCONFIG_LIST;
144 "allnoconfig_y" return T_ALLNOCONFIG_Y;
147 "(" return T_OPEN_PAREN;
148 ")" return T_CLOSE_PAREN;
151 "!=" return T_UNEQUAL;
152 "<=" return T_LESS_EQUAL;
153 ">=" return T_GREATER_EQUAL;
155 ">" return T_GREATER;
161 \n BEGIN(INITIAL); return T_EOL;
163 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
164 if (id && id->flags & TF_PARAM) {
167 alloc_string(yytext, yyleng);
168 yylval.string = text;
172 /* this token includes at least one '$' */
173 yylval.string = expand_token(yytext, yyleng);
174 if (strlen(yylval.string))
181 . warn_ignored_character(*yytext);
185 "$".* append_expanded_string(yytext);
187 append_string(yytext, yyleng);
190 append_string(yytext + 1, yyleng - 1);
193 if (str == yytext[0]) {
195 yylval.string = text;
198 append_string(yytext, 1);
202 "%s:%d:warning: multi-line strings not supported\n",
203 zconf_curname(), zconf_lineno());
206 yylval.string = text;
211 yylval.string = text;
219 for (i = 0; i < yyleng; i++) {
220 if (yytext[i] == '\t')
233 append_string(" ", 8);
236 append_string(" ", ts);
244 append_string("\n", 1);
248 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
252 append_string(yytext, yyleng);
265 if (prev_token != T_EOL && prev_token != T_HELPTEXT)
266 fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
267 current_file->name, yylineno);
279 /* second stage lexer */
287 /* Do not pass unneeded T_EOL to the parser. */
288 if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
296 static char *expand_token(const char *in, size_t n)
301 const char *rest, *end;
304 append_string(in, n);
306 /* get the whole line because we do not know the end of token. */
307 while ((c = input()) != EOF) {
313 append_string(&c2, 1);
317 out = expand_one_token(&rest);
319 /* push back unused characters to the input stream */
320 end = rest + strlen(rest);
329 static void append_expanded_string(const char *str)
336 res = expand_dollar(&str);
338 /* push back unused characters to the input stream */
339 end = str + strlen(str);
343 append_string(res, strlen(res));
348 void zconf_starthelp(void)
351 last_ts = first_ts = 0;
355 static void zconf_endhelp(void)
357 yylval.string = text;
363 * Try to open specified file with following names:
366 * The latter is used when srctree is separate from objtree
367 * when compiling the firmware.
368 * Return NULL if file is not found.
370 FILE *zconf_fopen(const char *name)
372 char *env, fullname[PATH_MAX+1];
375 f = fopen(name, "r");
376 if (!f && name != NULL && name[0] != '/') {
377 env = getenv(SRCTREE);
379 sprintf(fullname, "%s/%s", env, name);
380 f = fopen(fullname, "r");
386 void zconf_initscan(const char *name)
388 yyin = zconf_fopen(name);
390 fprintf(stderr, "can't find file %s\n", name);
394 current_buf = xmalloc(sizeof(*current_buf));
395 memset(current_buf, 0, sizeof(*current_buf));
397 current_file = file_lookup(name);
401 void zconf_nextfile(const char *name)
404 struct file *file = file_lookup(name);
405 struct buffer *buf = xmalloc(sizeof(*buf));
406 memset(buf, 0, sizeof(*buf));
408 current_buf->state = YY_CURRENT_BUFFER;
409 yyin = zconf_fopen(file->name);
411 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
412 zconf_curname(), zconf_lineno(), file->name);
415 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
416 buf->parent = current_buf;
419 current_file->lineno = yylineno;
420 file->parent = current_file;
422 for (iter = current_file; iter; iter = iter->parent) {
423 if (!strcmp(iter->name, file->name)) {
425 "Recursive inclusion detected.\n"
427 " current file : %s\n", file->name);
431 fprintf(stderr, " included from: %s:%d\n",
432 iter->name, iter->lineno - 1);
433 } while (strcmp(iter->name, file->name));
442 static void zconf_endfile(void)
444 struct buffer *parent;
446 current_file = current_file->parent;
448 yylineno = current_file->lineno;
450 parent = current_buf->parent;
453 yy_delete_buffer(YY_CURRENT_BUFFER);
454 yy_switch_to_buffer(parent->state);
457 current_buf = parent;
460 int zconf_lineno(void)
462 return current_pos.lineno;
465 const char *zconf_curname(void)
467 return current_pos.file ? current_pos.file->name : "<none>";