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);
80 current_file->lineno++;
98 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
100 current_pos.file = current_file;
101 current_pos.lineno = current_file->lineno;
102 if (id && id->flags & TF_COMMAND) {
106 alloc_string(yytext, yyleng);
107 zconflval.string = text;
113 current_file->lineno++;
121 "(" return T_OPEN_PAREN;
122 ")" return T_CLOSE_PAREN;
125 "!=" return T_UNEQUAL;
131 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
134 const struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
135 if (id && id->flags & TF_PARAM) {
139 alloc_string(yytext, yyleng);
140 zconflval.string = text;
144 \\\n current_file->lineno++;
153 append_string(yytext, yyleng);
154 zconflval.string = text;
158 append_string(yytext, yyleng);
161 append_string(yytext + 1, yyleng - 1);
162 zconflval.string = text;
166 append_string(yytext + 1, yyleng - 1);
169 if (str == yytext[0]) {
171 zconflval.string = text;
174 append_string(yytext, 1);
177 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
178 current_file->lineno++;
190 for (i = 0; i < yyleng; i++) {
191 if (yytext[i] == '\t')
204 append_string(" ", 8);
207 append_string(" ", ts);
211 current_file->lineno++;
216 current_file->lineno++;
217 append_string("\n", 1);
221 if ((yytext[yyleng-1] != ' ') && (yytext[yyleng-1] != '\t'))
225 append_string(yytext, yyleng);
245 void zconf_starthelp(void)
248 last_ts = first_ts = 0;
252 static void zconf_endhelp(void)
254 zconflval.string = text;
260 * Try to open specified file with following names:
263 * The latter is used when srctree is separate from objtree
264 * when compiling the kernel.
265 * Return NULL if file is not found.
267 FILE *zconf_fopen(const char *name)
269 char *env, fullname[PATH_MAX+1];
272 f = fopen(name, "r");
273 if (!f && name != NULL && name[0] != '/') {
274 env = getenv(SRCTREE);
276 sprintf(fullname, "%s/%s", env, name);
277 f = fopen(fullname, "r");
283 void zconf_initscan(const char *name)
285 yyin = zconf_fopen(name);
287 printf("can't find file %s\n", name);
291 current_buf = xmalloc(sizeof(*current_buf));
292 memset(current_buf, 0, sizeof(*current_buf));
294 current_file = file_lookup(name);
295 current_file->lineno = 1;
298 void zconf_nextfile(const char *name)
301 struct file *file = file_lookup(name);
302 struct buffer *buf = xmalloc(sizeof(*buf));
303 memset(buf, 0, sizeof(*buf));
305 current_buf->state = YY_CURRENT_BUFFER;
306 yyin = zconf_fopen(file->name);
308 printf("%s:%d: can't open file \"%s\"\n",
309 zconf_curname(), zconf_lineno(), file->name);
312 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
313 buf->parent = current_buf;
316 for (iter = current_file->parent; iter; iter = iter->parent ) {
317 if (!strcmp(current_file->name,iter->name) ) {
318 printf("%s:%d: recursive inclusion detected. "
319 "Inclusion path:\n current file : '%s'\n",
320 zconf_curname(), zconf_lineno(),
322 iter = current_file->parent;
324 strcmp(iter->name,current_file->name)) {
325 printf(" included from: '%s:%d'\n",
326 iter->name, iter->lineno-1);
330 printf(" included from: '%s:%d'\n",
331 iter->name, iter->lineno+1);
336 file->parent = current_file;
340 static void zconf_endfile(void)
342 struct buffer *parent;
344 current_file = current_file->parent;
346 parent = current_buf->parent;
349 yy_delete_buffer(YY_CURRENT_BUFFER);
350 yy_switch_to_buffer(parent->state);
353 current_buf = parent;
356 int zconf_lineno(void)
358 return current_pos.lineno;
361 const char *zconf_curname(void)
363 return current_pos.file ? current_pos.file->name : "<none>";