summaryrefslogtreecommitdiff
path: root/scripts/kconfig/cml1.l
Unidiff
Diffstat (limited to 'scripts/kconfig/cml1.l') (more/less context) (ignore whitespace changes)
-rw-r--r--scripts/kconfig/cml1.l213
1 files changed, 213 insertions, 0 deletions
diff --git a/scripts/kconfig/cml1.l b/scripts/kconfig/cml1.l
new file mode 100644
index 0000000..d6c33a0
--- a/dev/null
+++ b/scripts/kconfig/cml1.l
@@ -0,0 +1,213 @@
1%option nounput backup nostdinit noyywrap full ecs
2%option 8bit backup nodefault perf-report perf-report
3%x STRING
4%{
5/*
6 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
7 * Released under the terms of the GNU GPL v2.0.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <unistd.h>
14#include "cml1.h"
15
16char *text;
17static char *text_ptr;
18static int text_size, text_asize;
19
20struct buffer {
21 struct buffer *parent;
22 YY_BUFFER_STATE state;
23};
24
25struct buffer *current_buf;
26
27int lineno(void)
28{
29 if (current_buf)
30 return current_file->lineno;
31 else
32 return 0;
33}
34
35void scan_init(char *file)
36{
37 struct buffer *buf = malloc(sizeof(*buf));
38 memset(buf, 0, sizeof(*buf));
39
40 yyin = fopen(file, "r");
41 if (!yyin) {
42 printf("can't find file %s\n", file);
43 exit(1);
44 }
45 current_buf = buf;
46
47 current_file = lookup_file(file);
48 current_file->lineno = 0;
49 current_file->flags = FILE_BUSY;
50}
51
52void scan_nextfile(char *name)
53{
54 struct file *file = lookup_file(name);
55 struct buffer *buf = malloc(sizeof(*buf));
56 memset(buf, 0, sizeof(*buf));
57
58 current_buf->state = YY_CURRENT_BUFFER;
59 yyin = fopen(name, "r");
60 if (!yyin) {
61 printf("can't find file %s\n", name);
62 exit(1);
63 }
64 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
65 buf->parent = current_buf;
66 current_buf = buf;
67
68 if (file->flags & FILE_BUSY) {
69 printf("recursive scan (%s)?\n", name);
70 exit(1);
71 }
72 file->flags |= FILE_BUSY;
73 file->lineno = 0;
74 file->parent = current_file;
75 current_file = file;
76}
77
78 #define START_STRSIZE16
79
80void new_string(void)
81{
82 text = malloc(START_STRSIZE);
83 text_asize = START_STRSIZE;
84 text_ptr = text;
85 text_size = 0;
86 *text_ptr = 0;
87}
88
89void append_string(const char *str, int size)
90{
91 int new_size = text_size + size + 1;
92 if (new_size > text_asize) {
93 text = realloc(text, new_size);
94 text_asize = new_size;
95 text_ptr = text + text_size;
96 }
97 memcpy(text_ptr, str, size);
98 text_ptr += size;
99 text_size += size;
100 *text_ptr = 0;
101}
102
103void alloc_string(const char *str, int size)
104{
105 text = malloc(size + 1);
106 memcpy(text, str, size);
107 text[size] = 0;
108}
109
110%}
111%%
112 int str = 0;
113
114 \"|\'{
115 str = yytext[0];
116 new_string();
117 BEGIN(STRING);
118}
119<STRING>{
120 [^'"\n\\]+{
121 append_string(yytext, yyleng);
122 }
123 \'|\"{
124 if (str == yytext[0]) {
125 BEGIN(INITIAL);
126 cml1lval.string = text;
127 //printf("s:%s", text);
128 return str == '"' ? T_WORD_DQUOTE : T_WORD_QUOTE;
129 } else
130 append_string(yytext, 1);
131 }
132 \\[ \t]*\nappend_string(yytext+yyleng-1, 1); current_file->lineno++;
133 \\[ \t]*append_string(yytext+1, yyleng-1);
134 \\. append_string(yytext+1, 1);
135 \n{
136 printf(":%d: open string!\n", current_file->lineno+1);
137 exit(0);
138 }
139 <<EOF>>{
140 printf(":%d: open string!\n", current_file->lineno+1);
141 exit(0);
142 }
143}
144 mainmenu_name[ \t]return T_MAINMENU_NAME;
145 mainmenu_option[ \t]return T_MAINMENU_OPTION;
146 next_comment/[ \t\n]return T_NEXT_COMMENT;
147 endmenu/[ \t\n] return T_ENDMENU;
148 comment[ \t] return T_COMMENT;
149 bool[ \t] return T_BOOL;
150 hex[ \t] return T_HEX;
151 int[ \t] return T_INT;
152 string[ \t] return T_STRING;
153 tristate[ \t] return T_TRISTATE;
154 define_bool[ \t]return T_DEFINE_BOOL;
155 define_hex[ \t] return T_DEFINE_HEX;
156 define_int[ \t] return T_DEFINE_INT;
157 define_string[ \t]return T_DEFINE_STRING;
158 define_tristate[ \t]return T_DEFINE_TRISTATE;
159 dep_bool[ \t] return T_DEP_BOOL;
160 dep_mbool[ \t] return T_DEP_MBOOL;
161 dep_tristate[ \t]return T_DEP_TRISTATE;
162 unset[ \t] return T_UNSET;
163 choice[ \t] return T_CHOICE;
164 source[ \t] return T_SOURCE;
165 if[ \t] return T_IF;
166 else/[ \t\n] return T_ELSE;
167 fi/[ \t\n] return T_FI;
168 then/[ \t\n] return T_THEN;
169 \[ return '[';
170 \] return ']';
171 ; return ';';
172 != return T_UNEQUAL;
173 = return '=';
174 ! return '!';
175 -a return T_AND;
176 -o return T_OR;
177 #[^\n]*{
178 /* comment */
179 current_file->lineno++;
180 alloc_string(yytext, yyleng);
181 cml1lval.string = text;
182 return T_SH_COMMENT;
183}
184 [ \t]+ /* space */
185 \\\n current_file->lineno++;/* ignore */
186 \n{
187 current_file->lineno++;
188 return '\n';
189}
190 [[:alnum:]$/][[:graph:]]*{
191 alloc_string(yytext, yyleng);
192 cml1lval.string = text;
193 //printf("w:%s", text);
194 return T_WORD;
195}
196 .{
197 printf("%s:%d: invalid character 0x%x(%c)\n", current_file->name, current_file->lineno+1, yytext[0], yytext[0]);
198 exit(1);
199}
200 <<EOF>>{
201 if (current_buf->parent) {
202 struct buffer *buf = current_buf;
203 current_buf = buf->parent;
204 current_file->flags |= FILE_SCANNED;
205 current_file->flags &= ~FILE_BUSY;
206 current_file = current_file->parent;
207 yy_delete_buffer(YY_CURRENT_BUFFER);
208 yy_switch_to_buffer(current_buf->state);
209 free(buf);
210 } else
211 yyterminate();
212}
213%%