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);
220 append_string(yytext, yyleng);
240 void zconf_starthelp(void)
243 last_ts = first_ts = 0;
247 static void zconf_endhelp(void)
249 zconflval.string = text;
255 * Try to open specified file with following names:
258 * The latter is used when srctree is separate from objtree
259 * when compiling the kernel.
260 * Return NULL if file is not found.
262 FILE *zconf_fopen(const char *name)
264 char *env, fullname[PATH_MAX+1];
267 f = fopen(name, "r");
268 if (!f && name[0] != '/') {
269 env = getenv(SRCTREE);
271 sprintf(fullname, "%s/%s", env, name);
272 f = fopen(fullname, "r");
278 void zconf_initscan(const char *name)
280 yyin = zconf_fopen(name);
282 printf("can't find file %s\n", name);
286 current_buf = malloc(sizeof(*current_buf));
287 memset(current_buf, 0, sizeof(*current_buf));
289 current_file = file_lookup(name);
290 current_file->lineno = 1;
291 current_file->flags = FILE_BUSY;
294 void zconf_nextfile(const char *name)
296 struct file *file = file_lookup(name);
297 struct buffer *buf = malloc(sizeof(*buf));
298 memset(buf, 0, sizeof(*buf));
300 current_buf->state = YY_CURRENT_BUFFER;
301 yyin = zconf_fopen(name);
303 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
306 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
307 buf->parent = current_buf;
310 if (file->flags & FILE_BUSY) {
311 printf("recursive scan (%s)?\n", name);
314 if (file->flags & FILE_SCANNED) {
315 printf("file %s already scanned?\n", name);
318 file->flags |= FILE_BUSY;
320 file->parent = current_file;
324 static void zconf_endfile(void)
326 struct buffer *parent;
328 current_file->flags |= FILE_SCANNED;
329 current_file->flags &= ~FILE_BUSY;
330 current_file = current_file->parent;
332 parent = current_buf->parent;
335 yy_delete_buffer(YY_CURRENT_BUFFER);
336 yy_switch_to_buffer(parent->state);
339 current_buf = parent;
342 int zconf_lineno(void)
344 return current_pos.lineno;
347 char *zconf_curname(void)
349 return current_pos.file ? current_pos.file->name : "<none>";