summaryrefslogtreecommitdiff
path: root/scripts/kconfig/zconf.l
Unidiff
Diffstat (limited to 'scripts/kconfig/zconf.l') (more/less context) (ignore whitespace changes)
-rw-r--r--scripts/kconfig/zconf.l23
1 files changed, 15 insertions, 8 deletions
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 1471630..55517b2 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -51,309 +51,316 @@ void append_string(const char *str, int size)
51 text_asize = new_size; 51 text_asize = new_size;
52 text_ptr = text + text_size; 52 text_ptr = text + text_size;
53 } 53 }
54 memcpy(text_ptr, str, size); 54 memcpy(text_ptr, str, size);
55 text_ptr += size; 55 text_ptr += size;
56 text_size += size; 56 text_size += size;
57 *text_ptr = 0; 57 *text_ptr = 0;
58} 58}
59 59
60void alloc_string(const char *str, int size) 60void alloc_string(const char *str, int size)
61{ 61{
62 text = malloc(size + 1); 62 text = malloc(size + 1);
63 memcpy(text, str, size); 63 memcpy(text, str, size);
64 text[size] = 0; 64 text[size] = 0;
65} 65}
66%} 66%}
67 67
68 ws[ \n\t] 68 ws[ \n\t]
69 n[A-Za-z0-9_] 69 n[A-Za-z0-9_]
70 70
71%% 71%%
72 int str = 0; 72 int str = 0;
73 int ts, i; 73 int ts, i;
74 74
75 [ \t]*#.*\ncurrent_file->lineno++; 75 [ \t]*#.*\ncurrent_file->lineno++;
76[ \t]*#.* 76[ \t]*#.*
77 77
78 [ \t]*\ncurrent_file->lineno++; return T_EOL; 78 [ \t]*\ncurrent_file->lineno++; return T_EOL;
79 79
80 [ \t]+{ 80 [ \t]+{
81 BEGIN(COMMAND); 81 BEGIN(COMMAND);
82} 82}
83 83
84 .{ 84 .{
85 unput(yytext[0]); 85 unput(yytext[0]);
86 BEGIN(COMMAND); 86 BEGIN(COMMAND);
87} 87}
88 88
89 89
90<COMMAND>{ 90<COMMAND>{
91 "mainmenu" BEGIN(PARAM); return T_MAINMENU; 91 "mainmenu" BEGIN(PARAM); return T_MAINMENU;
92 "menu" BEGIN(PARAM); return T_MENU; 92 "menu" BEGIN(PARAM); return T_MENU;
93 "endmenu" BEGIN(PARAM); return T_ENDMENU; 93 "endmenu" BEGIN(PARAM); return T_ENDMENU;
94 "source" BEGIN(PARAM); return T_SOURCE; 94 "source" BEGIN(PARAM); return T_SOURCE;
95 "choice" BEGIN(PARAM); return T_CHOICE; 95 "choice" BEGIN(PARAM); return T_CHOICE;
96 "endchoice" BEGIN(PARAM); return T_ENDCHOICE; 96 "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
97 "comment" BEGIN(PARAM); return T_COMMENT; 97 "comment" BEGIN(PARAM); return T_COMMENT;
98 "config" BEGIN(PARAM); return T_CONFIG; 98 "config" BEGIN(PARAM); return T_CONFIG;
99 "menuconfig" BEGIN(PARAM); return T_MENUCONFIG;
99 "help" BEGIN(PARAM); return T_HELP; 100 "help" BEGIN(PARAM); return T_HELP;
100 "if" BEGIN(PARAM); return T_IF; 101 "if" BEGIN(PARAM); return T_IF;
101 "endif" BEGIN(PARAM); return T_ENDIF; 102 "endif" BEGIN(PARAM); return T_ENDIF;
102 "depends" BEGIN(PARAM); return T_DEPENDS; 103 "depends" BEGIN(PARAM); return T_DEPENDS;
103 "requires" BEGIN(PARAM); return T_REQUIRES; 104 "requires" BEGIN(PARAM); return T_REQUIRES;
104 "optional" BEGIN(PARAM); return T_OPTIONAL; 105 "optional" BEGIN(PARAM); return T_OPTIONAL;
105 "default" BEGIN(PARAM); return T_DEFAULT; 106 "default" BEGIN(PARAM); return T_DEFAULT;
106 "prompt" BEGIN(PARAM); return T_PROMPT; 107 "prompt" BEGIN(PARAM); return T_PROMPT;
107 "tristate" BEGIN(PARAM); return T_TRISTATE; 108 "tristate" BEGIN(PARAM); return T_TRISTATE;
109 "def_tristate" BEGIN(PARAM); return T_DEF_TRISTATE;
108 "bool" BEGIN(PARAM); return T_BOOLEAN; 110 "bool" BEGIN(PARAM); return T_BOOLEAN;
109 "boolean" BEGIN(PARAM); return T_BOOLEAN; 111 "boolean" BEGIN(PARAM); return T_BOOLEAN;
112 "def_bool" BEGIN(PARAM); return T_DEF_BOOLEAN;
113 "def_boolean" BEGIN(PARAM); return T_DEF_BOOLEAN;
110 "int" BEGIN(PARAM); return T_INT; 114 "int" BEGIN(PARAM); return T_INT;
111 "hex" BEGIN(PARAM); return T_HEX; 115 "hex" BEGIN(PARAM); return T_HEX;
112 "string" BEGIN(PARAM); return T_STRING; 116 "string" BEGIN(PARAM); return T_STRING;
117 "select" BEGIN(PARAM); return T_SELECT;
118 "enable" BEGIN(PARAM); return T_SELECT;
119 "range" BEGIN(PARAM); return T_RANGE;
113 {n}+{ 120 {n}+{
114 alloc_string(yytext, yyleng); 121 alloc_string(yytext, yyleng);
115 zconflval.string = text; 122 zconflval.string = text;
116 return T_WORD; 123 return T_WORD;
117 } 124 }
118 . 125 .
119 \ncurrent_file->lineno++; BEGIN(INITIAL); 126 \ncurrent_file->lineno++; BEGIN(INITIAL);
120} 127}
121 128
122<PARAM>{ 129<PARAM>{
123 "&&"return T_AND; 130 "&&"return T_AND;
124 "||"return T_OR; 131 "||"return T_OR;
125 "("return T_OPEN_PAREN; 132 "("return T_OPEN_PAREN;
126 ")"return T_CLOSE_PAREN; 133 ")"return T_CLOSE_PAREN;
127 "!"return T_NOT; 134 "!"return T_NOT;
128 "="return T_EQUAL; 135 "="return T_EQUAL;
129 "!="return T_UNEQUAL; 136 "!="return T_UNEQUAL;
130 "if"return T_IF; 137 "if"return T_IF;
131 "on"return T_ON; 138 "on"return T_ON;
132 \"|\'{ 139 \"|\'{
133 str = yytext[0]; 140 str = yytext[0];
134 new_string(); 141 new_string();
135 BEGIN(STRING); 142 BEGIN(STRING);
136 } 143 }
137 \nBEGIN(INITIAL); current_file->lineno++; return T_EOL; 144 \nBEGIN(INITIAL); current_file->lineno++; return T_EOL;
138 ---/* ignore */ 145 ---/* ignore */
139 ({n}|[-/.])+{ 146 ({n}|[-/.])+{
140 alloc_string(yytext, yyleng); 147 alloc_string(yytext, yyleng);
141 zconflval.string = text; 148 zconflval.string = text;
142 return T_WORD; 149 return T_WORD;
143 } 150 }
151 #.*/* comment */
144 \\\ncurrent_file->lineno++; 152 \\\ncurrent_file->lineno++;
145 . 153 .
146 <<EOF>> { 154 <<EOF>> {
147 BEGIN(INITIAL); 155 BEGIN(INITIAL);
148 } 156 }
149} 157}
150 158
151<STRING>{ 159<STRING>{
152 [^'"\\\n]+/\n{ 160 [^'"\\\n]+/\n{
153 append_string(yytext, yyleng); 161 append_string(yytext, yyleng);
154 zconflval.string = text; 162 zconflval.string = text;
155 return T_STRING; 163 return T_WORD_QUOTE;
156 } 164 }
157 [^'"\\\n]+{ 165 [^'"\\\n]+{
158 append_string(yytext, yyleng); 166 append_string(yytext, yyleng);
159 } 167 }
160 \\.?/\n{ 168 \\.?/\n{
161 append_string(yytext + 1, yyleng - 1); 169 append_string(yytext + 1, yyleng - 1);
162 zconflval.string = text; 170 zconflval.string = text;
163 return T_STRING; 171 return T_WORD_QUOTE;
164 } 172 }
165 \\.?{ 173 \\.?{
166 append_string(yytext + 1, yyleng - 1); 174 append_string(yytext + 1, yyleng - 1);
167 } 175 }
168 \'|\"{ 176 \'|\"{
169 if (str == yytext[0]) { 177 if (str == yytext[0]) {
170 BEGIN(PARAM); 178 BEGIN(PARAM);
171 zconflval.string = text; 179 zconflval.string = text;
172 return T_STRING; 180 return T_WORD_QUOTE;
173 } else 181 } else
174 append_string(yytext, 1); 182 append_string(yytext, 1);
175 } 183 }
176 \n{ 184 \n{
177 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno()); 185 printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno());
178 current_file->lineno++; 186 current_file->lineno++;
179 BEGIN(INITIAL); 187 BEGIN(INITIAL);
180 return T_EOL; 188 return T_EOL;
181 } 189 }
182 <<EOF>>{ 190 <<EOF>>{
183 BEGIN(INITIAL); 191 BEGIN(INITIAL);
184 } 192 }
185} 193}
186 194
187<HELP>{ 195<HELP>{
188 [ \t]+{ 196 [ \t]+{
189 ts = 0; 197 ts = 0;
190 for (i = 0; i < yyleng; i++) { 198 for (i = 0; i < yyleng; i++) {
191 if (yytext[i] == '\t') 199 if (yytext[i] == '\t')
192 ts = (ts & ~7) + 8; 200 ts = (ts & ~7) + 8;
193 else 201 else
194 ts++; 202 ts++;
195 } 203 }
196 last_ts = ts; 204 last_ts = ts;
197 if (first_ts) { 205 if (first_ts) {
198 if (ts < first_ts) { 206 if (ts < first_ts) {
199 zconf_endhelp(); 207 zconf_endhelp();
200 return T_HELPTEXT; 208 return T_HELPTEXT;
201 } 209 }
202 ts -= first_ts; 210 ts -= first_ts;
203 while (ts > 8) { 211 while (ts > 8) {
204 append_string(" ", 8); 212 append_string(" ", 8);
205 ts -= 8; 213 ts -= 8;
206 } 214 }
207 append_string(" ", ts); 215 append_string(" ", ts);
208 } 216 }
209
210 } 217 }
211 \n/[^ \t\n] { 218 [ \t]*\n/[^ \t\n] {
212 current_file->lineno++; 219 current_file->lineno++;
213 zconf_endhelp(); 220 zconf_endhelp();
214 return T_HELPTEXT; 221 return T_HELPTEXT;
215 } 222 }
216 [ \t]*\n{ 223 [ \t]*\n{
217 current_file->lineno++; 224 current_file->lineno++;
218 append_string("\n", 1); 225 append_string("\n", 1);
219 } 226 }
220 [^ \t\n].* { 227 [^ \t\n].* {
221 append_string(yytext, yyleng); 228 append_string(yytext, yyleng);
222 if (!first_ts) 229 if (!first_ts)
223 first_ts = last_ts; 230 first_ts = last_ts;
224 } 231 }
225 <<EOF>>{ 232 <<EOF>>{
226 zconf_endhelp(); 233 zconf_endhelp();
227 return T_HELPTEXT; 234 return T_HELPTEXT;
228 } 235 }
229} 236}
230 237
231 <<EOF>>{ 238 <<EOF>>{
232 if (current_buf) { 239 if (current_buf) {
233 zconf_endfile(); 240 zconf_endfile();
234 return T_EOF; 241 return T_EOF;
235 } 242 }
236 fclose(yyin); 243 fclose(yyin);
237 yyterminate(); 244 yyterminate();
238} 245}
239 246
240%% 247%%
241void zconf_starthelp(void) 248void zconf_starthelp(void)
242{ 249{
243 new_string(); 250 new_string();
244 last_ts = first_ts = 0; 251 last_ts = first_ts = 0;
245 BEGIN(HELP); 252 BEGIN(HELP);
246} 253}
247 254
248static void zconf_endhelp(void) 255static void zconf_endhelp(void)
249{ 256{
250 zconflval.string = text; 257 zconflval.string = text;
251 BEGIN(INITIAL); 258 BEGIN(INITIAL);
252} 259}
253 260
254 261
255/* 262/*
256 * Try to open specified file with following names: 263 * Try to open specified file with following names:
257 * ./name 264 * ./name
258 * $(srctree)/name 265 * $(srctree)/name
259 * The latter is used when srctree is separate from objtree 266 * The latter is used when srctree is separate from objtree
260 * when compiling the kernel. 267 * when compiling the kernel.
261 * Return NULL if file is not found. 268 * Return NULL if file is not found.
262 */ 269 */
263FILE *zconf_fopen(const char *name) 270FILE *zconf_fopen(const char *name)
264{ 271{
265 char *env, fullname[PATH_MAX+1]; 272 char *env, fullname[PATH_MAX+1];
266 FILE *f; 273 FILE *f;
267 274
268 f = fopen(name, "r"); 275 f = fopen(name, "r");
269 if (!f && name[0] != '/') { 276 if (!f && name[0] != '/') {
270 env = getenv(SRCTREE); 277 env = getenv(SRCTREE);
271 if (env) { 278 if (env) {
272 sprintf(fullname, "%s/%s", env, name); 279 sprintf(fullname, "%s/%s", env, name);
273 f = fopen(fullname, "r"); 280 f = fopen(fullname, "r");
274 } 281 }
275 } 282 }
276 return f; 283 return f;
277} 284}
278 285
279void zconf_initscan(const char *name) 286void zconf_initscan(const char *name)
280{ 287{
281 yyin = zconf_fopen(name); 288 yyin = zconf_fopen(name);
282 if (!yyin) { 289 if (!yyin) {
283 printf("can't find file %s\n", name); 290 printf("can't find file %s\n", name);
284 exit(1); 291 exit(1);
285 } 292 }
286 293
287 current_buf = malloc(sizeof(*current_buf)); 294 current_buf = malloc(sizeof(*current_buf));
288 memset(current_buf, 0, sizeof(*current_buf)); 295 memset(current_buf, 0, sizeof(*current_buf));
289 296
290 current_file = file_lookup(name); 297 current_file = file_lookup(name);
291 current_file->lineno = 1; 298 current_file->lineno = 1;
292 current_file->flags = FILE_BUSY; 299 current_file->flags = FILE_BUSY;
293} 300}
294 301
295void zconf_nextfile(const char *name) 302void zconf_nextfile(const char *name)
296{ 303{
297 struct file *file = file_lookup(name); 304 struct file *file = file_lookup(name);
298 struct buffer *buf = malloc(sizeof(*buf)); 305 struct buffer *buf = malloc(sizeof(*buf));
299 memset(buf, 0, sizeof(*buf)); 306 memset(buf, 0, sizeof(*buf));
300 307
301 current_buf->state = YY_CURRENT_BUFFER; 308 current_buf->state = YY_CURRENT_BUFFER;
302 yyin = zconf_fopen(name); 309 yyin = zconf_fopen(name);
303 if (!yyin) { 310 if (!yyin) {
304 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); 311 printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name);
305 exit(1); 312 exit(1);
306 } 313 }
307 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); 314 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
308 buf->parent = current_buf; 315 buf->parent = current_buf;
309 current_buf = buf; 316 current_buf = buf;
310 317
311 if (file->flags & FILE_BUSY) { 318 if (file->flags & FILE_BUSY) {
312 printf("recursive scan (%s)?\n", name); 319 printf("recursive scan (%s)?\n", name);
313 exit(1); 320 exit(1);
314 } 321 }
315 if (file->flags & FILE_SCANNED) { 322 if (file->flags & FILE_SCANNED) {
316 printf("file %s already scanned?\n", name); 323 printf("file %s already scanned?\n", name);
317 exit(1); 324 exit(1);
318 } 325 }
319 file->flags |= FILE_BUSY; 326 file->flags |= FILE_BUSY;
320 file->lineno = 1; 327 file->lineno = 1;
321 file->parent = current_file; 328 file->parent = current_file;
322 current_file = file; 329 current_file = file;
323} 330}
324 331
325static struct buffer *zconf_endfile(void) 332static struct buffer *zconf_endfile(void)
326{ 333{
327 struct buffer *parent; 334 struct buffer *parent;
328 335
329 current_file->flags |= FILE_SCANNED; 336 current_file->flags |= FILE_SCANNED;
330 current_file->flags &= ~FILE_BUSY; 337 current_file->flags &= ~FILE_BUSY;
331 current_file = current_file->parent; 338 current_file = current_file->parent;
332 339
333 parent = current_buf->parent; 340 parent = current_buf->parent;
334 if (parent) { 341 if (parent) {
335 fclose(yyin); 342 fclose(yyin);
336 yy_delete_buffer(YY_CURRENT_BUFFER); 343 yy_delete_buffer(YY_CURRENT_BUFFER);
337 yy_switch_to_buffer(parent->state); 344 yy_switch_to_buffer(parent->state);
338 } 345 }
339 free(current_buf); 346 free(current_buf);
340 current_buf = parent; 347 current_buf = parent;
341 348
342 return parent; 349 return parent;
343} 350}
344 351
345int zconf_lineno(void) 352int zconf_lineno(void)
346{ 353{
347 if (current_buf) 354 if (current_buf)
348 return current_file->lineno; 355 return current_file->lineno - 1;
349 else 356 else
350 return 0; 357 return 0;
351} 358}
352 359
353char *zconf_curname(void) 360char *zconf_curname(void)
354{ 361{
355 if (current_buf) 362 if (current_buf)
356 return current_file->name; 363 return current_file->name;
357 else 364 else
358 return "<none>"; 365 return "<none>";
359} 366}