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