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 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 char *expand_token(const char *in, size_t n);
39 static void append_expanded_string(const char *in);
40 static void zconf_endhelp(void);
41 static void zconf_endfile(void);
43 static void new_string(void)
45 text = xmalloc(START_STRSIZE);
46 text_asize = START_STRSIZE;
51 static void append_string(const char *str, int size)
53 int new_size = text_size + size + 1;
54 if (new_size > text_asize) {
55 new_size += START_STRSIZE - 1;
56 new_size &= -START_STRSIZE;
57 text = xrealloc(text, new_size);
58 text_asize = new_size;
60 memcpy(text + text_size, str, size);
65 static void alloc_string(const char *str, int size)
67 text = xmalloc(size + 1);
68 memcpy(text, str, size);
72 static void warn_ignored_character(char chr)
75 "%s:%d:warning: ignoring unsupported character '%c'\n",
76 zconf_curname(), zconf_lineno(), chr);
105 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) {
113 alloc_string(yytext, yyleng);
114 yylval.string = text;
118 /* this token includes at least one '$' */
119 yylval.string = expand_token(yytext, yyleng);
120 if (strlen(yylval.string))
124 "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; }
125 ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; }
126 "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; }
128 . warn_ignored_character(*yytext);
137 alloc_string(yytext, yyleng);
138 yylval.string = text;
141 \n { BEGIN(INITIAL); return T_EOL; }
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) {
169 alloc_string(yytext, yyleng);
170 yylval.string = text;
174 /* this token includes at least one '$' */
175 yylval.string = expand_token(yytext, yyleng);
176 if (strlen(yylval.string))
183 . warn_ignored_character(*yytext);
190 "$".* append_expanded_string(yytext);
192 append_string(yytext, yyleng);
193 yylval.string = text;
197 append_string(yytext, yyleng);
200 append_string(yytext + 1, yyleng - 1);
201 yylval.string = text;
205 append_string(yytext + 1, yyleng - 1);
208 if (str == yytext[0]) {
210 yylval.string = text;
213 append_string(yytext, 1);
217 "%s:%d:warning: multi-line strings not supported\n",
218 zconf_curname(), zconf_lineno());
230 for (i = 0; i < yyleng; i++) {
231 if (yytext[i] == '\t')
244 append_string(" ", 8);
247 append_string(" ", ts);
255 append_string("\n", 1);
259 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
263 append_string(yytext, yyleng);
283 static char *expand_token(const char *in, size_t n)
288 const char *rest, *end;
291 append_string(in, n);
293 /* get the whole line because we do not know the end of token. */
294 while ((c = input()) != EOF) {
300 append_string(&c2, 1);
304 out = expand_one_token(&rest);
306 /* push back unused characters to the input stream */
307 end = rest + strlen(rest);
316 static void append_expanded_string(const char *str)
323 res = expand_dollar(&str);
325 /* push back unused characters to the input stream */
326 end = str + strlen(str);
330 append_string(res, strlen(res));
335 void zconf_starthelp(void)
338 last_ts = first_ts = 0;
342 static void zconf_endhelp(void)
344 yylval.string = text;
350 * Try to open specified file with following names:
353 * The latter is used when srctree is separate from objtree
354 * when compiling the kernel.
355 * Return NULL if file is not found.
357 FILE *zconf_fopen(const char *name)
359 char *env, fullname[PATH_MAX+1];
362 f = fopen(name, "r");
363 if (!f && name != NULL && name[0] != '/') {
364 env = getenv(SRCTREE);
366 sprintf(fullname, "%s/%s", env, name);
367 f = fopen(fullname, "r");
373 void zconf_initscan(const char *name)
375 yyin = zconf_fopen(name);
377 fprintf(stderr, "can't find file %s\n", name);
381 current_buf = xmalloc(sizeof(*current_buf));
382 memset(current_buf, 0, sizeof(*current_buf));
384 current_file = file_lookup(name);
388 void zconf_nextfile(const char *name)
391 struct file *file = file_lookup(name);
392 struct buffer *buf = xmalloc(sizeof(*buf));
393 memset(buf, 0, sizeof(*buf));
395 current_buf->state = YY_CURRENT_BUFFER;
396 yyin = zconf_fopen(file->name);
398 fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
399 zconf_curname(), zconf_lineno(), file->name);
402 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
403 buf->parent = current_buf;
406 current_file->lineno = yylineno;
407 file->parent = current_file;
409 for (iter = current_file; iter; iter = iter->parent) {
410 if (!strcmp(iter->name, file->name)) {
412 "Recursive inclusion detected.\n"
414 " current file : %s\n", file->name);
418 fprintf(stderr, " included from: %s:%d\n",
419 iter->name, iter->lineno - 1);
420 } while (strcmp(iter->name, file->name));
429 static void zconf_endfile(void)
431 struct buffer *parent;
433 current_file = current_file->parent;
435 yylineno = current_file->lineno;
437 parent = current_buf->parent;
440 yy_delete_buffer(YY_CURRENT_BUFFER);
441 yy_switch_to_buffer(parent->state);
444 current_buf = parent;
447 int zconf_lineno(void)
449 return current_pos.lineno;
452 const char *zconf_curname(void)
454 return current_pos.file ? current_pos.file->name : "<none>";