lang.l (53047) | lang.l (61640) |
---|---|
1%{ 2/*- 3 * Copyright (c) 1980, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)lang.l 8.1 (Berkeley) 6/6/93 | 1%{ 2/*- 3 * Copyright (c) 1980, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 18 unchanged lines hidden (view full) --- 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)lang.l 8.1 (Berkeley) 6/6/93 |
35 * $FreeBSD: head/usr.sbin/config/lang.l 53047 1999-11-09 07:20:22Z peter $ | 35 * $FreeBSD: head/usr.sbin/config/lang.l 61640 2000-06-13 22:28:50Z peter $ |
36 */ 37 38#include <ctype.h> 39#include <string.h> 40#include "y.tab.h" 41#include "config.h" 42 43#define YY_NO_UNPUT 44 45/* 46 * Key word table 47 */ 48 49struct kt { 50 char *kt_name; 51 int kt_val; 52} key_words[] = { | 36 */ 37 38#include <ctype.h> 39#include <string.h> 40#include "y.tab.h" 41#include "config.h" 42 43#define YY_NO_UNPUT 44 45/* 46 * Key word table 47 */ 48 49struct kt { 50 char *kt_name; 51 int kt_val; 52} key_words[] = { |
53 { "at", AT }, 54 { "bus", BUS }, 55 { "conflicts", CONFLICTS }, | |
56 { "config", CONFIG }, | 53 { "config", CONFIG }, |
57 { "controller", CONTROLLER }, | |
58 { "cpu", CPU }, 59 { "device", DEVICE }, | 54 { "cpu", CPU }, 55 { "device", DEVICE }, |
60 { "disable", DISABLE }, 61 { "disk", DISK }, 62 { "drive", DRIVE }, 63 { "drq", DRQ }, 64 { "flags", FLAGS }, | 56 { "hints", HINTS }, |
65 { "ident", IDENT }, | 57 { "ident", IDENT }, |
66 { "iomem", IOMEM }, 67 { "iosiz", IOSIZ }, 68 { "irq", IRQ }, | |
69 { "machine", ARCH }, /* MACHINE is defined in /sys/param.h */ 70 { "makeoptions", MAKEOPTIONS }, 71 { "maxusers", MAXUSERS }, | 58 { "machine", ARCH }, /* MACHINE is defined in /sys/param.h */ 59 { "makeoptions", MAKEOPTIONS }, 60 { "maxusers", MAXUSERS }, |
72 { "nexus", NEXUS }, | |
73 { "option", OPTIONS }, 74 { "options", OPTIONS }, | 61 { "option", OPTIONS }, 62 { "options", OPTIONS }, |
75 { "port", PORT }, 76 { "pseudo-device",PSEUDO_DEVICE }, 77 { "tape", TAPE }, 78 { "target", TARGET }, 79 { "unit", UNIT }, | |
80 { 0, 0 }, 81}; 82 83 | 63 { 0, 0 }, 64}; 65 66 |
84int kw_lookup __P((char *)); 85int octal __P((char *)); 86int hex __P((char *)); | 67int kw_lookup(char *); 68int octal(char *); 69int hex(char *); |
87 88%} 89WORD [A-Za-z_][-A-Za-z_]* 90ID [A-Za-z_][-A-Za-z_0-9]* 91%START NONUM TOEOL 92%% 93<NONUM>{WORD} { 94 int i; --- 6 unchanged lines hidden (view full) --- 101 } 102 return i; 103 } 104<INITIAL>{WORD}/[0-9]* { 105 int i; 106 107 if ((i = kw_lookup(yytext)) == -1) 108 REJECT; | 70 71%} 72WORD [A-Za-z_][-A-Za-z_]* 73ID [A-Za-z_][-A-Za-z_0-9]* 74%START NONUM TOEOL 75%% 76<NONUM>{WORD} { 77 int i; --- 6 unchanged lines hidden (view full) --- 84 } 85 return i; 86 } 87<INITIAL>{WORD}/[0-9]* { 88 int i; 89 90 if ((i = kw_lookup(yytext)) == -1) 91 REJECT; |
109 if (i == CONTROLLER || i == DEVICE || i == DISK || i == TAPE || 110 i == PSEUDO_DEVICE || i == AT) | 92 if (i == DEVICE) |
111 BEGIN NONUM; 112 return i; 113 } 114<INITIAL>{ID} { 115 BEGIN 0; 116 yylval.str = strdup(yytext); 117 return ID; 118 } --- 22 unchanged lines hidden (view full) --- 1410x[0-9a-fA-F]+ { 142 yylval.val = hex(yytext); 143 return NUMBER; 144 } 145-?[1-9][0-9]* { 146 yylval.val = atoi(yytext); 147 return NUMBER; 148 } | 93 BEGIN NONUM; 94 return i; 95 } 96<INITIAL>{ID} { 97 BEGIN 0; 98 yylval.str = strdup(yytext); 99 return ID; 100 } --- 22 unchanged lines hidden (view full) --- 1230x[0-9a-fA-F]+ { 124 yylval.val = hex(yytext); 125 return NUMBER; 126 } 127-?[1-9][0-9]* { 128 yylval.val = atoi(yytext); 129 return NUMBER; 130 } |
149[0-9]"."[0-9]* { 150 yylval.val = (int) (60 * atof(yytext) + 0.5); 151 return FPNUMBER; 152 } | |
153"?" { 154 yylval.val = -1; 155 return NUMBER; 156 } 157\n/[ \t] { 158 yyline++; 159 } 160\n { 161 yyline++; 162 return SEMICOLON; 163 } 164#.* { /* Ignored (comment) */; } 165[ \t\f]* { /* Ignored (white space) */; } 166";" { return SEMICOLON; } 167"," { return COMMA; } 168"=" { BEGIN TOEOL; return EQUALS; } | 131"?" { 132 yylval.val = -1; 133 return NUMBER; 134 } 135\n/[ \t] { 136 yyline++; 137 } 138\n { 139 yyline++; 140 return SEMICOLON; 141 } 142#.* { /* Ignored (comment) */; } 143[ \t\f]* { /* Ignored (white space) */; } 144";" { return SEMICOLON; } 145"," { return COMMA; } 146"=" { BEGIN TOEOL; return EQUALS; } |
169"@" { return AT; } | |
170. { return yytext[0]; } 171 172%% 173/* 174 * kw_lookup 175 * Look up a string in the keyword table. Returns a -1 if the 176 * string is not a keyword otherwise it returns the keyword number 177 */ 178 179int | 147. { return yytext[0]; } 148 149%% 150/* 151 * kw_lookup 152 * Look up a string in the keyword table. Returns a -1 if the 153 * string is not a keyword otherwise it returns the keyword number 154 */ 155 156int |
180kw_lookup(word) 181register char *word; | 157kw_lookup(char *word) |
182{ | 158{ |
183 register struct kt *kp; | 159 struct kt *kp; |
184 185 for (kp = key_words; kp->kt_name != 0; kp++) 186 if (eq(word, kp->kt_name)) 187 return kp->kt_val; 188 return -1; 189} 190 191/* 192 * Number conversion routines 193 */ 194 195int | 160 161 for (kp = key_words; kp->kt_name != 0; kp++) 162 if (eq(word, kp->kt_name)) 163 return kp->kt_val; 164 return -1; 165} 166 167/* 168 * Number conversion routines 169 */ 170 171int |
196octal(str) 197char *str; | 172octal(char *str) |
198{ 199 int num; 200 201 (void) sscanf(str, "%o", &num); 202 return num; 203} 204 205int | 173{ 174 int num; 175 176 (void) sscanf(str, "%o", &num); 177 return num; 178} 179 180int |
206hex(str) 207char *str; | 181hex(char *str) |
208{ 209 int num; 210 211 (void) sscanf(str+2, "%x", &num); 212 return num; 213} | 182{ 183 int num; 184 185 (void) sscanf(str+2, "%x", &num); 186 return num; 187} |