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