add getopt; create system directory if it doesn't already exist
[unix-history] / usr / src / usr.sbin / config / lang.l
CommitLineData
bc2ed385 1%{
cd68466f
DF
2
3/*
4 * Copyright (c) 1980 Regents of the University of California.
5 * All rights reserved. The Berkeley software License Agreement
6 * specifies the terms and conditions for redistribution.
7 *
a0105456 8 * @(#)lang.l 5.3 (Berkeley) %G%
cd68466f 9 */
bc2ed385
MT
10
11#include <ctype.h>
12#include "y.tab.h"
13#include "config.h"
14
15#define tprintf if (do_trace) printf
b3043913 16
bc2ed385
MT
17/*
18 * Key word table
19 */
20
21struct kt {
22 char *kt_name;
23 int kt_val;
24} key_words[] = {
36edb824
SL
25 { "and", AND },
26 { "args", ARGS },
27 { "at", AT },
28 { "config", CONFIG },
29 { "controller", CONTROLLER },
30 { "cpu", CPU },
31 { "csr", CSR },
32 { "device", DEVICE },
33 { "disk", DISK },
34 { "drive", DRIVE },
35 { "dst", DST },
36 { "dumps", DUMPS },
37 { "flags", FLAGS },
38 { "hz", HZ },
39 { "ident", IDENT },
40 { "machine", MACHINE },
41 { "major", MAJOR },
7c1d4665 42 { "makeoptions", MAKEOPTIONS },
36edb824
SL
43 { "master", MASTER },
44 { "maxusers", MAXUSERS },
45 { "mba", MBA },
46 { "minor", MINOR },
47 { "nexus", NEXUS },
48 { "on", ON },
49 { "options", OPTIONS },
50 { "priority", PRIORITY },
51 { "pseudo-device",PSEUDO_DEVICE },
52 { "root", ROOT },
53 { "size", SIZE },
54 { "slave", SLAVE },
55 { "swap", SWAP },
56 { "tape", DEVICE },
57 { "timezone", TIMEZONE },
58 { "trace", TRACE },
59 { "uba", UBA },
a0105456 60 { "vba", VBA },
36edb824
SL
61 { "vector", VECTOR },
62 { 0, 0 },
bc2ed385
MT
63};
64%}
b3043913 65WORD [A-Za-z_][-A-Za-z_]*
bc2ed385
MT
66%%
67{WORD} {
68 int i;
69
70 if ((i = kw_lookup(yytext)) == -1)
71 {
22d68ad0 72 yylval.str = yytext;
bc2ed385
MT
73 tprintf("id(%s) ", yytext);
74 return ID;
75 }
76 tprintf("(%s) ", yytext);
77 return i;
78 }
dea0cacc
MT
79\"[^"]+\" {
80 yytext[strlen(yytext)-1] = '\0';
36edb824 81 yylval.str = yytext + 1;
dea0cacc
MT
82 return ID;
83 }
bc2ed385 840[0-7]* {
22d68ad0
BJ
85 yylval.val = octal(yytext);
86 tprintf("#O:%o ", yylval.val);
bc2ed385
MT
87 return NUMBER;
88 }
4cab9f3e 890x[0-9a-fA-F]+ {
22d68ad0
BJ
90 yylval.val = hex(yytext);
91 tprintf("#X:%x ", yylval.val);
bc2ed385
MT
92 return NUMBER;
93 }
94[1-9][0-9]* {
22d68ad0
BJ
95 yylval.val = atoi(yytext);
96 tprintf("#D:%d ", yylval.val);
bc2ed385
MT
97 return NUMBER;
98 }
a5e18d6b 99[0-9]"."[0-9]* {
22d68ad0
BJ
100 double atof();
101 yylval.val = (int) (60 * atof(yytext) + 0.5);
a5e18d6b
MT
102 return FPNUMBER;
103 }
57b7808b
BJ
104"-" {
105 return MINUS;
106 }
bc2ed385 107"?" {
22d68ad0 108 yylval.val = -1;
bc2ed385
MT
109 tprintf("? ");
110 return NUMBER;
111 }
112\n/[ \t] {
113 yyline++;
114 tprintf("\n... ");
115 }
116\n {
117 yyline++;
118 tprintf("\n");
119 return SEMICOLON;
120 }
45a827f6 121#.* { /* Ignored (comment) */; }
bc2ed385
MT
122[ \t]* { /* Ignored (white space) */; }
123";" { return SEMICOLON; }
9c98d1fb 124"," { return COMMA; }
45a827f6 125"=" { return EQUALS; }
0bf41cfc 126"@" { return AT; }
45a827f6
RE
127. { return yytext[0]; }
128
bc2ed385
MT
129%%
130/*
131 * kw_lookup
132 * Look up a string in the keyword table. Returns a -1 if the
133 * string is not a keyword otherwise it returns the keyword number
134 */
135
136kw_lookup(word)
137register char *word;
138{
139 register struct kt *kp;
140
141 for (kp = key_words; kp->kt_name != 0; kp++)
142 if (eq(word, kp->kt_name))
143 return kp->kt_val;
144 return -1;
145}
146
147/*
148 * Number conversion routines
149 */
150
151octal(str)
152char *str;
153{
154 int num;
155
22d68ad0 156 (void) sscanf(str, "%o", &num);
bc2ed385
MT
157 return num;
158}
159
160hex(str)
161char *str;
162{
163 int num;
164
22d68ad0 165 (void) sscanf(str+2, "%x", &num);
bc2ed385
MT
166 return num;
167}