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
22 static int text_size, text_asize;
25 struct buffer *parent;
26 YY_BUFFER_STATE state;
29 struct buffer *current_buf;
31 static int last_ts, first_ts;
33 static void zconf_endhelp(void);
34 static struct buffer *zconf_endfile(void);
38 text = malloc(START_STRSIZE);
39 text_asize = START_STRSIZE;
44 void append_string(const char *str, int size)
46 int new_size = text_size + size + 1;
47 if (new_size > text_asize) {
48 new_size += START_STRSIZE - 1;
49 new_size &= -START_STRSIZE;
50 text = realloc(text, new_size);
51 text_asize = new_size;
53 memcpy(text + text_size, str, size);
58 void alloc_string(const char *str, int size)
60 text = malloc(size + 1);
61 memcpy(text, str, size);
73 [ \t]*#.*\n current_file->lineno++;
76 [ \t]*\n current_file->lineno++; return T_EOL;
90 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
91 if (id && id->flags & TF_COMMAND) {
96 alloc_string(yytext, yyleng);
97 zconflval.string = text;
101 \n current_file->lineno++; BEGIN(INITIAL);
107 "(" return T_OPEN_PAREN;
108 ")" return T_CLOSE_PAREN;
111 "!=" return T_UNEQUAL;
117 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
120 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
121 if (id && id->flags & TF_PARAM) {
125 alloc_string(yytext, yyleng);
126 zconflval.string = text;
130 \\\n current_file->lineno++;
139 append_string(yytext, yyleng);
140 zconflval.string = text;
144 append_string(yytext, yyleng);
147 append_string(yytext + 1, yyleng - 1);
148 zconflval.string = text;
152 append_string(yytext + 1, yyleng - 1);
155 if (str == yytext[0]) {
157 zconflval.string = text;
160 append_string(yytext, 1);
163 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
164 current_file->lineno++;
176 for (i = 0; i < yyleng; i++) {
177 if (yytext[i] == '\t')
190 append_string(" ", 8);
193 append_string(" ", ts);
197 current_file->lineno++;
202 current_file->lineno++;
203 append_string("\n", 1);
206 append_string(yytext, yyleng);
226 void zconf_starthelp(void)
229 last_ts = first_ts = 0;
233 static void zconf_endhelp(void)
235 zconflval.string = text;
241 * Try to open specified file with following names:
244 * The latter is used when srctree is separate from objtree
245 * when compiling the kernel.
246 * Return NULL if file is not found.
248 FILE *zconf_fopen(const char *name)
250 char *env, fullname[PATH_MAX+1];
253 f = fopen(name, "r");
254 if (!f && name[0] != '/') {
255 env = getenv(SRCTREE);
257 sprintf(fullname, "%s/%s", env, name);
258 f = fopen(fullname, "r");
264 void zconf_initscan(const char *name)
266 yyin = zconf_fopen(name);
268 printf("can't find file %s\n", name);
272 current_buf = malloc(sizeof(*current_buf));
273 memset(current_buf, 0, sizeof(*current_buf));
275 current_file = file_lookup(name);
276 current_file->lineno = 1;
277 current_file->flags = FILE_BUSY;
280 void zconf_nextfile(const char *name)
282 struct file *file = file_lookup(name);
283 struct buffer *buf = malloc(sizeof(*buf));
284 memset(buf, 0, sizeof(*buf));
286 current_buf->state = YY_CURRENT_BUFFER;
287 yyin = zconf_fopen(name);
289 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
292 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
293 buf->parent = current_buf;
296 if (file->flags & FILE_BUSY) {
297 printf("recursive scan (%s)?\n", name);
300 if (file->flags & FILE_SCANNED) {
301 printf("file %s already scanned?\n", name);
304 file->flags |= FILE_BUSY;
306 file->parent = current_file;
310 static struct buffer *zconf_endfile(void)
312 struct buffer *parent;
314 current_file->flags |= FILE_SCANNED;
315 current_file->flags &= ~FILE_BUSY;
316 current_file = current_file->parent;
318 parent = current_buf->parent;
321 yy_delete_buffer(YY_CURRENT_BUFFER);
322 yy_switch_to_buffer(parent->state);
325 current_buf = parent;
330 int zconf_lineno(void)
333 return current_file->lineno - 1;
338 char *zconf_curname(void)
341 return current_file->name;