1 %option backup nostdinit noyywrap never-interactive full ecs
2 %option 8bit backup nodefault perf-report perf-report
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.
16 #define LKC_DIRECT_LINK
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);
43 text = malloc(START_STRSIZE);
44 text_asize = START_STRSIZE;
49 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 void alloc_string(const char *str, int size)
65 text = malloc(size + 1);
66 memcpy(text, str, size);
80 current_file->lineno++;
98 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 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 = malloc(sizeof(*current_buf));
292 memset(current_buf, 0, sizeof(*current_buf));
294 current_file = file_lookup(name);
295 current_file->lineno = 1;
296 current_file->flags = FILE_BUSY;
299 void zconf_nextfile(const char *name)
301 struct file *file = file_lookup(name);
302 struct buffer *buf = malloc(sizeof(*buf));
303 memset(buf, 0, sizeof(*buf));
305 current_buf->state = YY_CURRENT_BUFFER;
306 yyin = zconf_fopen(name);
308 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
311 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
312 buf->parent = current_buf;
315 if (file->flags & FILE_BUSY) {
316 printf("recursive scan (%s)?\n", name);
319 if (file->flags & FILE_SCANNED) {
320 printf("file %s already scanned?\n", name);
323 file->flags |= FILE_BUSY;
325 file->parent = current_file;
329 static void zconf_endfile(void)
331 struct buffer *parent;
333 current_file->flags |= FILE_SCANNED;
334 current_file->flags &= ~FILE_BUSY;
335 current_file = current_file->parent;
337 parent = current_buf->parent;
340 yy_delete_buffer(YY_CURRENT_BUFFER);
341 yy_switch_to_buffer(parent->state);
344 current_buf = parent;
347 int zconf_lineno(void)
349 return current_pos.lineno;
352 char *zconf_curname(void)
354 return current_pos.file ? current_pos.file->name : "<none>";