1 /* Special state for handling include files */
6 * lex_cis.l 1.15 2001/08/24 12:21:41
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/
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.
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.
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.
41 #include <pcmcia/cs_types.h>
42 #include <pcmcia/cistpl.h>
47 /* For assembling nice error messages */
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 *);
66 [ ]*[#;].* /* skip */ ;
72 checksum return CHECKSUM;
74 common_jedec return CJEDEC;
75 attr_jedec return AJEDEC;
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");
92 last_index return LAST_INDEX;
96 cftable_entry return CFTABLE;
97 \[default\] return DEFAULT;
100 \[rdybsy\] return RDYBSY;
101 \[mwait\] return MWAIT;
102 \[audio\] return AUDIO;
103 \[readonly\] return READONLY;
104 \[pwrdown\] return PWRDOWN;
112 Istatic return ISTATIC;
119 \[8bit\] return BIT8;
120 \[16bit\] return BIT16;
121 \[lines return LINES;
122 \[range\] return RANGE;
125 \[level\] return LEVEL;
126 \[pulse\] return PULSE;
127 \[shared\] return SHARED;
129 timing return TIMING;
132 reserved return RESERVED;
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");
144 {int} return lex_number(yytext);
145 {hex} return lex_number(yytext);
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);
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);
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);
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);
174 {flt} return lex_float(yytext);
176 {str} return lex_string(yytext);
183 int yywrap() { return 1; }
186 /*======================================================================
188 Stuff to parse basic data types
190 ======================================================================*/
192 static int lex_number(char *s)
194 yylval.num = strtoul(s, NULL, 0);
198 static int lex_float(char *s)
200 yylval.flt = strtod(s, NULL);
204 static int lex_units(char *s, int scale, int token)
208 yylval.num = scale*f + 0.5;
212 static int lex_string(char *s)
215 yylval.str = malloc(n-1);
216 strncpy(yylval.str, s+1, n-2);
217 yylval.str[n-2] = '\0';
221 /*======================================================================
223 The main parser entry point
225 ======================================================================*/
227 void parse_cis(FILE *f)