fixed "make filters"
[unix-history] / usr / src / usr.sbin / config / lang.l
CommitLineData
bc2ed385 1%{
22d68ad0 2/* lang.l 1.12 82/10/25 */
bc2ed385
MT
3
4#include <ctype.h>
5#include "y.tab.h"
6#include "config.h"
7
8#define tprintf if (do_trace) printf
b3043913 9
bc2ed385
MT
10/*
11 * Key word table
12 */
13
14struct kt {
15 char *kt_name;
16 int kt_val;
17} key_words[] = {
0bf41cfc 18 "machine", MACHINE,
bc2ed385
MT
19 "cpu", CPU, "ident", IDENT, "config", CONFIG, "options", OPTIONS,
20 "device", DEVICE, "controller", CONTROLLER, "uba", UBA, "mba", MBA,
21 "csr", CSR, "nexus", NEXUS, "drive", DRIVE, "vector", VECTOR,
22 "pseudo-device", PSEUDO_DEVICE, "flags", FLAGS, "trace", TRACE,
5ff81582 23 "disk", DISK, "tape", DEVICE, "slave", SLAVE, "at", AT,
a5e18d6b 24 "hz", HZ, "timezone", TIMEZONE, "dst", DST, "maxusers", MAXUSERS,
0bf41cfc 25 "master", MASTER, "priority", PRIORITY,
bc2ed385
MT
26 0,0,
27};
28%}
b3043913 29WORD [A-Za-z_][-A-Za-z_]*
bc2ed385
MT
30%%
31{WORD} {
32 int i;
33
34 if ((i = kw_lookup(yytext)) == -1)
35 {
22d68ad0 36 yylval.str = yytext;
bc2ed385
MT
37 tprintf("id(%s) ", yytext);
38 return ID;
39 }
40 tprintf("(%s) ", yytext);
41 return i;
42 }
dea0cacc
MT
43\"[^"]+\" {
44 yytext[strlen(yytext)-1] = '\0';
22d68ad0 45 yylval.val = yytext + 1;
dea0cacc
MT
46 return ID;
47 }
bc2ed385 480[0-7]* {
22d68ad0
BJ
49 yylval.val = octal(yytext);
50 tprintf("#O:%o ", yylval.val);
bc2ed385
MT
51 return NUMBER;
52 }
530x[0-9a-f]+ {
22d68ad0
BJ
54 yylval.val = hex(yytext);
55 tprintf("#X:%x ", yylval.val);
bc2ed385
MT
56 return NUMBER;
57 }
58[1-9][0-9]* {
22d68ad0
BJ
59 yylval.val = atoi(yytext);
60 tprintf("#D:%d ", yylval.val);
bc2ed385
MT
61 return NUMBER;
62 }
a5e18d6b 63[0-9]"."[0-9]* {
22d68ad0
BJ
64 double atof();
65 yylval.val = (int) (60 * atof(yytext) + 0.5);
a5e18d6b
MT
66 return FPNUMBER;
67 }
57b7808b
BJ
68"-" {
69 return MINUS;
70 }
bc2ed385 71"?" {
22d68ad0 72 yylval.val = -1;
bc2ed385
MT
73 tprintf("? ");
74 return NUMBER;
75 }
76\n/[ \t] {
77 yyline++;
78 tprintf("\n... ");
79 }
80\n {
81 yyline++;
82 tprintf("\n");
83 return SEMICOLON;
84 }
45a827f6 85#.* { /* Ignored (comment) */; }
bc2ed385
MT
86[ \t]* { /* Ignored (white space) */; }
87";" { return SEMICOLON; }
9c98d1fb 88"," { return COMMA; }
45a827f6 89"=" { return EQUALS; }
0bf41cfc 90"@" { return AT; }
45a827f6
RE
91. { return yytext[0]; }
92
bc2ed385
MT
93%%
94/*
95 * kw_lookup
96 * Look up a string in the keyword table. Returns a -1 if the
97 * string is not a keyword otherwise it returns the keyword number
98 */
99
100kw_lookup(word)
101register char *word;
102{
103 register struct kt *kp;
104
105 for (kp = key_words; kp->kt_name != 0; kp++)
106 if (eq(word, kp->kt_name))
107 return kp->kt_val;
108 return -1;
109}
110
111/*
112 * Number conversion routines
113 */
114
115octal(str)
116char *str;
117{
118 int num;
119
22d68ad0 120 (void) sscanf(str, "%o", &num);
bc2ed385
MT
121 return num;
122}
123
124hex(str)
125char *str;
126{
127 int num;
128
22d68ad0 129 (void) sscanf(str+2, "%x", &num);
bc2ed385
MT
130 return num;
131}