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) {
95 alloc_string(yytext, yyleng);
96 zconflval.string = text;
100 \n current_file->lineno++; BEGIN(INITIAL);
106 "(" return T_OPEN_PAREN;
107 ")" return T_CLOSE_PAREN;
110 "!=" return T_UNEQUAL;
116 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
119 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
120 if (id && id->flags & TF_PARAM)
122 alloc_string(yytext, yyleng);
123 zconflval.string = text;
127 \\\n current_file->lineno++;
136 append_string(yytext, yyleng);
137 zconflval.string = text;
141 append_string(yytext, yyleng);
144 append_string(yytext + 1, yyleng - 1);
145 zconflval.string = text;
149 append_string(yytext + 1, yyleng - 1);
152 if (str == yytext[0]) {
154 zconflval.string = text;
157 append_string(yytext, 1);
160 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
161 current_file->lineno++;
173 for (i = 0; i < yyleng; i++) {
174 if (yytext[i] == '\t')
187 append_string(" ", 8);
190 append_string(" ", ts);
194 current_file->lineno++;
199 current_file->lineno++;
200 append_string("\n", 1);
203 append_string(yytext, yyleng);
223 void zconf_starthelp(void)
226 last_ts = first_ts = 0;
230 static void zconf_endhelp(void)
232 zconflval.string = text;
238 * Try to open specified file with following names:
241 * The latter is used when srctree is separate from objtree
242 * when compiling the kernel.
243 * Return NULL if file is not found.
245 FILE *zconf_fopen(const char *name)
247 char *env, fullname[PATH_MAX+1];
250 f = fopen(name, "r");
251 if (!f && name[0] != '/') {
252 env = getenv(SRCTREE);
254 sprintf(fullname, "%s/%s", env, name);
255 f = fopen(fullname, "r");
261 void zconf_initscan(const char *name)
263 yyin = zconf_fopen(name);
265 printf("can't find file %s\n", name);
269 current_buf = malloc(sizeof(*current_buf));
270 memset(current_buf, 0, sizeof(*current_buf));
272 current_file = file_lookup(name);
273 current_file->lineno = 1;
274 current_file->flags = FILE_BUSY;
277 void zconf_nextfile(const char *name)
279 struct file *file = file_lookup(name);
280 struct buffer *buf = malloc(sizeof(*buf));
281 memset(buf, 0, sizeof(*buf));
283 current_buf->state = YY_CURRENT_BUFFER;
284 yyin = zconf_fopen(name);
286 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
289 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
290 buf->parent = current_buf;
293 if (file->flags & FILE_BUSY) {
294 printf("recursive scan (%s)?\n", name);
297 if (file->flags & FILE_SCANNED) {
298 printf("file %s already scanned?\n", name);
301 file->flags |= FILE_BUSY;
303 file->parent = current_file;
307 static struct buffer *zconf_endfile(void)
309 struct buffer *parent;
311 current_file->flags |= FILE_SCANNED;
312 current_file->flags &= ~FILE_BUSY;
313 current_file = current_file->parent;
315 parent = current_buf->parent;
318 yy_delete_buffer(YY_CURRENT_BUFFER);
319 yy_switch_to_buffer(parent->state);
322 current_buf = parent;
327 int zconf_lineno(void)
330 return current_file->lineno - 1;
335 char *zconf_curname(void)
338 return current_file->name;