xref: /haiku/src/bin/pcmcia-cs/lex_cis.l (revision a175829ffcb8e9a8991a302325d684b0d7c9d8e9)
1 /* Special state for handling include files */
2 %x src
3 
4 %{
5 /*
6  * lex_cis.l 1.15 2001/08/24 12:21:41
7  *
8  * The contents of this file are subject to the Mozilla Public License
9  * Version 1.1 (the "License"); you may not use this file except in
10  * compliance with the License. You may obtain a copy of the License
11  * at http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS"
14  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15  * the License for the specific language governing rights and
16  * limitations under the License.
17  *
18  * The initial developer of the original code is David A. Hinds
19  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
20  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
21  *
22  * Alternatively, the contents of this file may be used under the
23  * terms of the GNU General Public License version 2 (the "GPL"), in
24  * which case the provisions of the GPL are applicable instead of the
25  * above.  If you wish to allow the use of your version of this file
26  * only under the terms of the GPL and not to allow others to use
27  * your version of this file under the MPL, indicate your decision by
28  * deleting the provisions above and replace them with the notice and
29  * other provisions required by the GPL.  If you do not delete the
30  * provisions above, a recipient may use your version of this file
31  * under either the MPL or the GPL.
32  */
33 
34 #undef src
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <string.h>
38 #include <syslog.h>
39 #define src 1
40 
41 #include <pcmcia/cs_types.h>
42 #include <pcmcia/cistpl.h>
43 
44 #include "pack_cis.h"
45 #include "yacc_cis.h"
46 
47 /* For assembling nice error messages */
48 int current_lineno;
49 
50 static int lex_number(char *);
51 static int lex_units(char *, int, int);
52 static int lex_float(char *);
53 static int lex_string(char *);
54 
55 %}
56 
57 int	[0-9]+
58 hex	0x[0-9a-fA-F]+
59 flt	[0-9]+\.[0-9]*
60 str	\"([^"]|\\.)*\"
61 
62 %%
63 
64 \n		current_lineno++;
65 [ \t]*		/* skip */ ;
66 [ ]*[#;].*	/* skip */ ;
67 
68 funcid		return FUNCID;
69 mfc		return MFC;
70 manfid		return MANFID;
71 vers_1		return VERS_1;
72 checksum	return CHECKSUM;
73 
74 common_jedec	return CJEDEC;
75 attr_jedec	return AJEDEC;
76 
77 dev_info	return DEV_INFO;
78 attr_dev_info	return ATTR_DEV_INFO;
79 no_info		return NO_INFO;
80 NULL		return lex_number("0");
81 ROM		return lex_number("1");
82 EPROM		return lex_number("3");
83 EEPROM		return lex_number("4");
84 FLASH		return lex_number("5");
85 SRAM		return lex_number("6");
86 DRAM		return lex_number("7");
87 fn_specific	return lex_number("13");
88 
89 config		return CONFIG;
90 base		return BASE;
91 mask		return MASK;
92 last_index	return LAST_INDEX;
93 \[post\]	return POST;
94 \[rom\]		return ROM;
95 
96 cftable_entry	return CFTABLE;
97 \[default\]	return DEFAULT;
98 \[bvd\]		return BVD;
99 \[wp\]		return WP;
100 \[rdybsy\]	return RDYBSY;
101 \[mwait\]	return MWAIT;
102 \[audio\]	return AUDIO;
103 \[readonly\]	return READONLY;
104 \[pwrdown\]	return PWRDOWN;
105 
106 Vcc		return VCC;
107 Vpp1		return VPP1;
108 Vpp2		return VPP2;
109 Vnom		return VNOM;
110 Vmin		return VMIN;
111 Vmax		return VMAX;
112 Istatic		return ISTATIC;
113 Iavg		return IAVG;
114 Ipeak		return IPEAK;
115 Idown		return IDOWN;
116 
117 io		return IO;
118 memory		return MEM;
119 \[8bit\]	return BIT8;
120 \[16bit\]	return BIT16;
121 \[lines		return LINES;
122 \[range\]	return RANGE;
123 
124 irq		return IRQ_NO;
125 \[level\]	return LEVEL;
126 \[pulse\]	return PULSE;
127 \[shared\]	return SHARED;
128 
129 timing		return TIMING;
130 wait		return WAIT;
131 ready		return READY;
132 reserved	return RESERVED;
133 
134 multi_function	return lex_number("0");
135 memory_card	return lex_number("1");
136 serial_port	return lex_number("2");
137 parallel_port	return lex_number("3");
138 fixed_disk	return lex_number("4");
139 video_adapter	return lex_number("5");
140 network_adapter	return lex_number("6");
141 aims_card	return lex_number("7");
142 scsi_adapter	return lex_number("8");
143 
144 {int}		return lex_number(yytext);
145 {hex}		return lex_number(yytext);
146 
147 {int}b		return lex_units(yytext, 1, SIZE);
148 {int}kb		return lex_units(yytext, 1024, SIZE);
149 {int}mb		return lex_units(yytext, 1024*1024, SIZE);
150 
151 {flt}s		return lex_units(yytext, 1000000000, TIME);
152 {flt}ms		return lex_units(yytext, 1000000, TIME);
153 {flt}us		return lex_units(yytext, 1000, TIME);
154 {flt}ns		return lex_units(yytext, 1, TIME);
155 {int}s		return lex_units(yytext, 1000000000, TIME);
156 {int}ms		return lex_units(yytext, 1000000, TIME);
157 {int}us		return lex_units(yytext, 1000, TIME);
158 {int}ns		return lex_units(yytext, 1, TIME);
159 
160 {flt}V		return lex_units(yytext, 100000, VOLTAGE);
161 {flt}mV		return lex_units(yytext, 100, VOLTAGE);
162 {flt}uV		return lex_units(yytext, 0.1, VOLTAGE);
163 {int}V		return lex_units(yytext, 100000, VOLTAGE);
164 {int}mV		return lex_units(yytext, 100, VOLTAGE);
165 {int}uV		return lex_units(yytext, 0.1, VOLTAGE);
166 
167 {flt}A		return lex_units(yytext, 10000000, CURRENT);
168 {flt}mA		return lex_units(yytext, 10000, CURRENT);
169 {flt}uA		return lex_units(yytext, 10, CURRENT);
170 {int}A		return lex_units(yytext, 10000000, CURRENT);
171 {int}mA		return lex_units(yytext, 10000, CURRENT);
172 {int}uA		return lex_units(yytext, 10, CURRENT);
173 
174 {flt}		return lex_float(yytext);
175 
176 {str}		return lex_string(yytext);
177 
178 .		return yytext[0];
179 
180 %%
181 
182 #ifndef yywrap
183 int yywrap() { return 1; }
184 #endif
185 
186 /*======================================================================
187 
188     Stuff to parse basic data types
189 
190 ======================================================================*/
191 
192 static int lex_number(char *s)
193 {
194     yylval.num = strtoul(s, NULL, 0);
195     return NUMBER;
196 }
197 
198 static int lex_float(char *s)
199 {
200     yylval.flt = strtod(s, NULL);
201     return FLOAT;
202 }
203 
204 static int lex_units(char *s, int scale, int token)
205 {
206     float f;
207     sscanf(s, "%f", &f);
208     yylval.num = scale*f + 0.5;
209     return token;
210 }
211 
212 static int lex_string(char *s)
213 {
214     int n = strlen(s);
215     yylval.str = malloc(n-1);
216     strncpy(yylval.str, s+1, n-2);
217     yylval.str[n-2] = '\0';
218     return STRING;
219 }
220 
221 /*======================================================================
222 
223     The main parser entry point
224 
225 ======================================================================*/
226 
227 void parse_cis(FILE *f)
228 {
229     current_lineno = 1;
230     yyrestart(f);
231     yyparse();
232     fclose(f);
233 }
234 
235