1 %option nostdinit noyywrap never-interactive full ecs
2 %option 8bit nodefault yylineno
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.
18 #define START_STRSIZE 16
26 static int text_size, text_asize;
29 struct buffer *parent;
30 YY_BUFFER_STATE state;
33 struct buffer *current_buf;
35 static int last_ts, first_ts;
37 static char *expand_token(const char *in, size_t n);
38 static void append_expanded_string(const char *in);
39 static void zconf_endhelp(void);
40 static void zconf_endfile(void);
42 static void new_string(void)
44 text = xmalloc(START_STRSIZE);
45 text_asize = START_STRSIZE;
50 static void append_string(const char *str, int size)
52 int new_size = text_size + size + 1;
53 if (new_size > text_asize) {
54 new_size += START_STRSIZE - 1;
55 new_size &= -START_STRSIZE;
56 text = xrealloc(text, new_size);
57 text_asize = new_size;
59 memcpy(text + text_size, str, size);
64 static void alloc_string(const char *str, int size)
66 text = xmalloc(size + 1);
67 memcpy(text, str, size);
71 static void warn_ignored_character(char chr)
74 "%s:%d:warning: ignoring unsupported character '%c'\n",
75 zconf_curname(), zconf_lineno(), chr);
104 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
106 current_pos.file = current_file;
107 current_pos.lineno = yylineno;
108 if (id && id->flags & TF_COMMAND) {
112 alloc_string(yytext, yyleng);
113 yylval.string = text;
116 . warn_ignored_character(*yytext);
126 "(" return T_OPEN_PAREN;
127 ")" return T_CLOSE_PAREN;
130 "!=" return T_UNEQUAL;
131 "<=" return T_LESS_EQUAL;
132 ">=" return T_GREATER_EQUAL;
134 ">" return T_GREATER;
140 \n BEGIN(INITIAL); return T_EOL;
142 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
143 if (id && id->flags & TF_PARAM) {
147 alloc_string(yytext, yyleng);
148 yylval.string = text;
152 /* this token includes at least one '$' */
153 yylval.string = expand_token(yytext, yyleng);
154 if (strlen(yylval.string))
161 . warn_ignored_character(*yytext);
168 "$".* append_expanded_string(yytext);
170 append_string(yytext, yyleng);
171 yylval.string = text;
175 append_string(yytext, yyleng);
178 append_string(yytext + 1, yyleng - 1);
179 yylval.string = text;
183 append_string(yytext + 1, yyleng - 1);
186 if (str == yytext[0]) {
188 yylval.string = text;
191 append_string(yytext, 1);
195 "%s:%d:warning: multi-line strings not supported\n",
196 zconf_curname(), zconf_lineno());
208 for (i = 0; i < yyleng; i++) {
209 if (yytext[i] == '\t')
222 append_string(" ", 8);
225 append_string(" ", ts);
233 append_string("\n", 1);
237 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
241 append_string(yytext, yyleng);
261 static char *expand_token(const char *in, size_t n)
266 const char *rest, *end;
269 append_string(in, n);
271 /* get the whole line because we do not know the end of token. */
272 while ((c = input()) != EOF) {
278 append_string(&c2, 1);
282 out = expand_one_token(&rest);
284 /* push back unused characters to the input stream */
285 end = rest + strlen(rest);
294 static void append_expanded_string(const char *str)
301 res = expand_dollar(&str);
303 /* push back unused characters to the input stream */
304 end = str + strlen(str);
308 append_string(res, strlen(res));
313 void zconf_starthelp(void)
316 last_ts = first_ts = 0;
320 static void zconf_endhelp(void)
322 yylval.string = text;
328 * Try to open specified file with following names:
331 * The latter is used when srctree is separate from objtree
332 * when compiling the kernel.
333 * Return NULL if file is not found.
335 FILE *zconf_fopen(const char *name)
337 char *env, fullname[PATH_MAX+1];
340 f = fopen(name, "r");
341 if (!f && name != NULL && name[0] != '/') {
342 env = getenv(SRCTREE);
344 sprintf(fullname, "%s/%s", env, name);
345 f = fopen(fullname, "r");
351 void zconf_initscan(const char *name)
353 yyin = zconf_fopen(name);
355 fprintf(stderr, "can't find file %s\n", name);
359 current_buf = xmalloc(sizeof(*current_buf));
360 memset(current_buf, 0, sizeof(*current_buf));
362 current_file = file_lookup(name);
366 void zconf_nextfile(const char *name)
369 struct file *file = file_lookup(name);
370 struct buffer *buf = xmalloc(sizeof(*buf));
371 memset(buf, 0, sizeof(*buf));
373 current_buf->state = YY_CURRENT_BUFFER;
374 yyin = zconf_fopen(file->name);
376 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
377 zconf_curname(), zconf_lineno(), file->name);
380 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
381 buf->parent = current_buf;
384 current_file->lineno = yylineno;
385 file->parent = current_file;
387 for (iter = current_file; iter; iter = iter->parent) {
388 if (!strcmp(iter->name, file->name)) {
390 "Recursive inclusion detected.\n"
392 " current file : %s\n", file->name);
396 fprintf(stderr, " included from: %s:%d\n",
397 iter->name, iter->lineno - 1);
398 } while (strcmp(iter->name, file->name));
407 static void zconf_endfile(void)
409 struct buffer *parent;
411 current_file = current_file->parent;
413 yylineno = current_file->lineno;
415 parent = current_buf->parent;
418 yy_delete_buffer(YY_CURRENT_BUFFER);
419 yy_switch_to_buffer(parent->state);
422 current_buf = parent;
425 int zconf_lineno(void)
427 return current_pos.lineno;
430 const char *zconf_curname(void)
432 return current_pos.file ? current_pos.file->name : "<none>";