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