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_prev_token = T_EOL;
29 static int prev_token = T_EOL;
31 static int text_size, text_asize;
34 struct buffer *parent;
35 YY_BUFFER_STATE state;
38 struct buffer *current_buf;
40 static int last_ts, first_ts;
42 static char *expand_token(const char *in, size_t n);
43 static void append_expanded_string(const char *in);
44 static void zconf_endhelp(void);
45 static void zconf_endfile(void);
47 static void new_string(void)
49 text = xmalloc(START_STRSIZE);
50 text_asize = START_STRSIZE;
55 static void append_string(const char *str, int size)
57 int new_size = text_size + size + 1;
58 if (new_size > text_asize) {
59 new_size += START_STRSIZE - 1;
60 new_size &= -START_STRSIZE;
61 text = xrealloc(text, new_size);
62 text_asize = new_size;
64 memcpy(text + text_size, str, size);
69 static void alloc_string(const char *str, int size)
71 text = xmalloc(size + 1);
72 memcpy(text, str, size);
76 static void warn_ignored_character(char chr)
79 "%s:%d:warning: ignoring unsupported character '%c'\n",
80 current_file->name, yylineno, chr);
103 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
104 current_pos.file = current_file;
105 current_pos.lineno = yylineno;
106 if (id && id->flags & TF_COMMAND) {
110 alloc_string(yytext, yyleng);
111 yylval.string = text;
115 /* this token includes at least one '$' */
116 yylval.string = expand_token(yytext, yyleng);
117 if (strlen(yylval.string))
122 ":=" return T_COLON_EQUAL;
123 "+=" return T_PLUS_EQUAL;
125 . warn_ignored_character(*yytext);
134 alloc_string(yytext, yyleng);
135 yylval.string = text;
138 \n { BEGIN(INITIAL); return T_EOL; }
143 "modules" return T_MODULES;
144 "defconfig_list" return T_DEFCONFIG_LIST;
145 "allnoconfig_y" return T_ALLNOCONFIG_Y;
148 "(" return T_OPEN_PAREN;
149 ")" return T_CLOSE_PAREN;
152 "!=" return T_UNEQUAL;
153 "<=" return T_LESS_EQUAL;
154 ">=" return T_GREATER_EQUAL;
156 ">" return T_GREATER;
162 \n BEGIN(INITIAL); return T_EOL;
164 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
165 if (id && id->flags & TF_PARAM) {
168 alloc_string(yytext, yyleng);
169 yylval.string = text;
173 /* this token includes at least one '$' */
174 yylval.string = expand_token(yytext, yyleng);
175 if (strlen(yylval.string))
182 . warn_ignored_character(*yytext);
186 "$".* append_expanded_string(yytext);
188 append_string(yytext, yyleng);
191 append_string(yytext + 1, yyleng - 1);
194 if (str == yytext[0]) {
196 yylval.string = text;
199 append_string(yytext, 1);
203 "%s:%d:warning: multi-line strings not supported\n",
204 zconf_curname(), zconf_lineno());
207 yylval.string = text;
212 yylval.string = text;
220 for (i = 0; i < yyleng; i++) {
221 if (yytext[i] == '\t')
234 append_string(" ", 8);
237 append_string(" ", ts);
245 append_string("\n", 1);
249 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
253 append_string(yytext, yyleng);
266 if (prev_token != T_EOL && prev_token != T_HELPTEXT)
267 fprintf(stderr, "%s:%d:warning: no new line at end of file\n",
268 current_file->name, yylineno);
280 /* second stage lexer */
288 /* Do not pass unneeded T_EOL to the parser. */
289 if ((prev_token == T_EOL || prev_token == T_HELPTEXT) && token == T_EOL)
292 if (prev_prev_token == T_EOL && prev_token == T_WORD &&
293 (token == T_EQUAL || token == T_COLON_EQUAL || token == T_PLUS_EQUAL))
296 prev_prev_token = prev_token;
302 static char *expand_token(const char *in, size_t n)
307 const char *rest, *end;
310 append_string(in, n);
312 /* get the whole line because we do not know the end of token. */
313 while ((c = input()) != EOF) {
319 append_string(&c2, 1);
323 out = expand_one_token(&rest);
325 /* push back unused characters to the input stream */
326 end = rest + strlen(rest);
335 static void append_expanded_string(const char *str)
342 res = expand_dollar(&str);
344 /* push back unused characters to the input stream */
345 end = str + strlen(str);
349 append_string(res, strlen(res));
354 void zconf_starthelp(void)
357 last_ts = first_ts = 0;
361 static void zconf_endhelp(void)
363 yylval.string = text;
369 * Try to open specified file with following names:
372 * The latter is used when srctree is separate from objtree
373 * when compiling the firmware.
374 * Return NULL if file is not found.
376 FILE *zconf_fopen(const char *name)
378 char *env, fullname[PATH_MAX+1];
381 f = fopen(name, "r");
382 if (!f && name != NULL && name[0] != '/') {
383 env = getenv(SRCTREE);
385 sprintf(fullname, "%s/%s", env, name);
386 f = fopen(fullname, "r");
392 void zconf_initscan(const char *name)
394 yyin = zconf_fopen(name);
396 fprintf(stderr, "can't find file %s\n", name);
400 current_buf = xmalloc(sizeof(*current_buf));
401 memset(current_buf, 0, sizeof(*current_buf));
403 current_file = file_lookup(name);
407 void zconf_nextfile(const char *name)
410 struct file *file = file_lookup(name);
411 struct buffer *buf = xmalloc(sizeof(*buf));
412 memset(buf, 0, sizeof(*buf));
414 current_buf->state = YY_CURRENT_BUFFER;
415 yyin = zconf_fopen(file->name);
417 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
418 zconf_curname(), zconf_lineno(), file->name);
421 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
422 buf->parent = current_buf;
425 current_file->lineno = yylineno;
426 file->parent = current_file;
428 for (iter = current_file; iter; iter = iter->parent) {
429 if (!strcmp(iter->name, file->name)) {
431 "Recursive inclusion detected.\n"
433 " current file : %s\n", file->name);
437 fprintf(stderr, " included from: %s:%d\n",
438 iter->name, iter->lineno - 1);
439 } while (strcmp(iter->name, file->name));
448 static void zconf_endfile(void)
450 struct buffer *parent;
452 current_file = current_file->parent;
454 yylineno = current_file->lineno;
456 parent = current_buf->parent;
459 yy_delete_buffer(YY_CURRENT_BUFFER);
460 yy_switch_to_buffer(parent->state);
463 current_buf = parent;
466 int zconf_lineno(void)
468 return current_pos.lineno;
471 const char *zconf_curname(void)
473 return current_pos.file ? current_pos.file->name : "<none>";