aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/zconf.l
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kconfig/zconf.l')
-rw-r--r--scripts/kconfig/zconf.l96
1 files changed, 40 insertions, 56 deletions
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 55517b2877cd..cfa46077c6b4 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -18,8 +18,12 @@
18 18
19#define START_STRSIZE 16 19#define START_STRSIZE 16
20 20
21char *text; 21static struct {
22static char *text_ptr; 22 struct file *file;
23 int lineno;
24} current_pos;
25
26static char *text;
23static int text_size, text_asize; 27static int text_size, text_asize;
24 28
25struct buffer { 29struct buffer {
@@ -32,29 +36,28 @@ struct buffer *current_buf;
32static int last_ts, first_ts; 36static int last_ts, first_ts;
33 37
34static void zconf_endhelp(void); 38static void zconf_endhelp(void);
35static struct buffer *zconf_endfile(void); 39static void zconf_endfile(void);
36 40
37void new_string(void) 41void new_string(void)
38{ 42{
39 text = malloc(START_STRSIZE); 43 text = malloc(START_STRSIZE);
40 text_asize = START_STRSIZE; 44 text_asize = START_STRSIZE;
41 text_ptr = text;
42 text_size = 0; 45 text_size = 0;
43 *text_ptr = 0; 46 *text = 0;
44} 47}
45 48
46void append_string(const char *str, int size) 49void append_string(const char *str, int size)
47{ 50{
48 int new_size = text_size + size + 1; 51 int new_size = text_size + size + 1;
49 if (new_size > text_asize) { 52 if (new_size > text_asize) {
53 new_size += START_STRSIZE - 1;
54 new_size &= -START_STRSIZE;
50 text = realloc(text, new_size); 55 text = realloc(text, new_size);
51 text_asize = new_size; 56 text_asize = new_size;
52 text_ptr = text + text_size;
53 } 57 }
54 memcpy(text_ptr, str, size); 58 memcpy(text + text_size, str, size);
55 text_ptr += size;
56 text_size += size; 59 text_size += size;
57 *text_ptr = 0; 60 text[text_size] = 0;
58} 61}
59 62
60void alloc_string(const char *str, int size) 63void alloc_string(const char *str, int size)
@@ -72,10 +75,13 @@ n [A-Za-z0-9_]
72 int str = 0; 75 int str = 0;
73 int ts, i; 76 int ts, i;
74 77
75[ \t]*#.*\n current_file->lineno++; 78[ \t]*#.*\n |
79[ \t]*\n {
80 current_file->lineno++;
81 return T_EOL;
82}
76[ \t]*#.* 83[ \t]*#.*
77 84
78[ \t]*\n current_file->lineno++; return T_EOL;
79 85
80[ \t]+ { 86[ \t]+ {
81 BEGIN(COMMAND); 87 BEGIN(COMMAND);
@@ -88,42 +94,25 @@ n [A-Za-z0-9_]
88 94
89 95
90<COMMAND>{ 96<COMMAND>{
91 "mainmenu" BEGIN(PARAM); return T_MAINMENU;
92 "menu" BEGIN(PARAM); return T_MENU;
93 "endmenu" BEGIN(PARAM); return T_ENDMENU;
94 "source" BEGIN(PARAM); return T_SOURCE;
95 "choice" BEGIN(PARAM); return T_CHOICE;
96 "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
97 "comment" BEGIN(PARAM); return T_COMMENT;
98 "config" BEGIN(PARAM); return T_CONFIG;
99 "menuconfig" BEGIN(PARAM); return T_MENUCONFIG;
100 "help" BEGIN(PARAM); return T_HELP;
101 "if" BEGIN(PARAM); return T_IF;
102 "endif" BEGIN(PARAM); return T_ENDIF;
103 "depends" BEGIN(PARAM); return T_DEPENDS;
104 "requires" BEGIN(PARAM); return T_REQUIRES;
105 "optional" BEGIN(PARAM); return T_OPTIONAL;
106 "default" BEGIN(PARAM); return T_DEFAULT;
107 "prompt" BEGIN(PARAM); return T_PROMPT;
108 "tristate" BEGIN(PARAM); return T_TRISTATE;
109 "def_tristate" BEGIN(PARAM); return T_DEF_TRISTATE;
110 "bool" 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;
114 "int" BEGIN(PARAM); return T_INT;
115 "hex" BEGIN(PARAM); return T_HEX;
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;
120 {n}+ { 97 {n}+ {
98 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
99 BEGIN(PARAM);
100 current_pos.file = current_file;
101 current_pos.lineno = current_file->lineno;
102 if (id && id->flags & TF_COMMAND) {
103 zconflval.id = id;
104 return id->token;
105 }
121 alloc_string(yytext, yyleng); 106 alloc_string(yytext, yyleng);
122 zconflval.string = text; 107 zconflval.string = text;
123 return T_WORD; 108 return T_WORD;
124 } 109 }
125 . 110 .
126 \n current_file->lineno++; BEGIN(INITIAL); 111 \n {
112 BEGIN(INITIAL);
113 current_file->lineno++;
114 return T_EOL;
115 }
127} 116}
128 117
129<PARAM>{ 118<PARAM>{
@@ -134,8 +123,6 @@ n [A-Za-z0-9_]
134 "!" return T_NOT; 123 "!" return T_NOT;
135 "=" return T_EQUAL; 124 "=" return T_EQUAL;
136 "!=" return T_UNEQUAL; 125 "!=" return T_UNEQUAL;
137 "if" return T_IF;
138 "on" return T_ON;
139 \"|\' { 126 \"|\' {
140 str = yytext[0]; 127 str = yytext[0];
141 new_string(); 128 new_string();
@@ -144,6 +131,11 @@ n [A-Za-z0-9_]
144 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL; 131 \n BEGIN(INITIAL); current_file->lineno++; return T_EOL;
145 --- /* ignore */ 132 --- /* ignore */
146 ({n}|[-/.])+ { 133 ({n}|[-/.])+ {
134 struct kconf_id *id = kconf_id_lookup(yytext, yyleng);
135 if (id && id->flags & TF_PARAM) {
136 zconflval.id = id;
137 return id->token;
138 }
147 alloc_string(yytext, yyleng); 139 alloc_string(yytext, yyleng);
148 zconflval.string = text; 140 zconflval.string = text;
149 return T_WORD; 141 return T_WORD;
@@ -236,9 +228,9 @@ n [A-Za-z0-9_]
236} 228}
237 229
238<<EOF>> { 230<<EOF>> {
239 if (current_buf) { 231 if (current_file) {
240 zconf_endfile(); 232 zconf_endfile();
241 return T_EOF; 233 return T_EOL;
242 } 234 }
243 fclose(yyin); 235 fclose(yyin);
244 yyterminate(); 236 yyterminate();
@@ -329,7 +321,7 @@ void zconf_nextfile(const char *name)
329 current_file = file; 321 current_file = file;
330} 322}
331 323
332static struct buffer *zconf_endfile(void) 324static void zconf_endfile(void)
333{ 325{
334 struct buffer *parent; 326 struct buffer *parent;
335 327
@@ -345,22 +337,14 @@ static struct buffer *zconf_endfile(void)
345 } 337 }
346 free(current_buf); 338 free(current_buf);
347 current_buf = parent; 339 current_buf = parent;
348
349 return parent;
350} 340}
351 341
352int zconf_lineno(void) 342int zconf_lineno(void)
353{ 343{
354 if (current_buf) 344 return current_pos.lineno;
355 return current_file->lineno - 1;
356 else
357 return 0;
358} 345}
359 346
360char *zconf_curname(void) 347char *zconf_curname(void)
361{ 348{
362 if (current_buf) 349 return current_pos.file ? current_pos.file->name : "<none>";
363 return current_file->name;
364 else
365 return "<none>";
366} 350}