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 */ 48int current_lineno; 49 50static int lex_number(char *); 51static int lex_units(char *, int, int); 52static int lex_float(char *); 53static int lex_string(char *); 54 55%} 56 57int [0-9]+ 58hex 0x[0-9a-fA-F]+ 59flt [0-9]+\.[0-9]* 60str \"([^"]|\\.)*\" 61 62%% 63 64\n current_lineno++; 65[ \t]* /* skip */ ; 66[ ]*[#;].* /* skip */ ; 67 68funcid return FUNCID; 69mfc return MFC; 70manfid return MANFID; 71vers_1 return VERS_1; 72checksum return CHECKSUM; 73 74common_jedec return CJEDEC; 75attr_jedec return AJEDEC; 76 77dev_info return DEV_INFO; 78attr_dev_info return ATTR_DEV_INFO; 79no_info return NO_INFO; 80NULL return lex_number("0"); 81ROM return lex_number("1"); 82EPROM return lex_number("3"); 83EEPROM return lex_number("4"); 84FLASH return lex_number("5"); 85SRAM return lex_number("6"); 86DRAM return lex_number("7"); 87fn_specific return lex_number("13"); 88 89config return CONFIG; 90base return BASE; 91mask return MASK; 92last_index return LAST_INDEX; 93\[post\] return POST; 94\[rom\] return ROM; 95 96cftable_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 106Vcc return VCC; 107Vpp1 return VPP1; 108Vpp2 return VPP2; 109Vnom return VNOM; 110Vmin return VMIN; 111Vmax return VMAX; 112Istatic return ISTATIC; 113Iavg return IAVG; 114Ipeak return IPEAK; 115Idown return IDOWN; 116 117io return IO; 118memory return MEM; 119\[8bit\] return BIT8; 120\[16bit\] return BIT16; 121\[lines return LINES; 122\[range\] return RANGE; 123 124irq return IRQ_NO; 125\[level\] return LEVEL; 126\[pulse\] return PULSE; 127\[shared\] return SHARED; 128 129timing return TIMING; 130wait return WAIT; 131ready return READY; 132reserved return RESERVED; 133 134multi_function return lex_number("0"); 135memory_card return lex_number("1"); 136serial_port return lex_number("2"); 137parallel_port return lex_number("3"); 138fixed_disk return lex_number("4"); 139video_adapter return lex_number("5"); 140network_adapter return lex_number("6"); 141aims_card return lex_number("7"); 142scsi_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 183int yywrap() { return 1; } 184#endif 185 186/*====================================================================== 187 188 Stuff to parse basic data types 189 190======================================================================*/ 191 192static int lex_number(char *s) 193{ 194 yylval.num = strtoul(s, NULL, 0); 195 return NUMBER; 196} 197 198static int lex_float(char *s) 199{ 200 yylval.flt = strtod(s, NULL); 201 return FLOAT; 202} 203 204static 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 212static 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 227void parse_cis(FILE *f) 228{ 229 current_lineno = 1; 230 yyrestart(f); 231 yyparse(); 232 fclose(f); 233} 234 235