3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
6 * This software was developed by the Computer Systems Engineering group
7 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
8 * contributed to Berkeley.
10 * All advertising materials mentioning features or use of this software
11 * must display the following acknowledgement:
12 * This product includes software developed by the University of
13 * California, Lawrence Berkeley Laboratories.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the University of
26 * California, Berkeley and its contributors.
27 * 4. Neither the name of the University nor the names of its contributors
28 * may be used to endorse or promote products derived from this software
29 * without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * @(#)scan.l 8.1 (Berkeley) 6/6/93
46 #include <sys/param.h>
59 int include __P((const char *, int));
62 * Data for returning to previous files from include files.
65 struct incl *in_prev; /* previous includes in effect, if any */
66 YY_BUFFER_STATE in_buf; /* previous lex state */
67 const char *in_fname; /* previous file name */
68 int in_lineno; /* previous line number */
69 int in_preveof; /* previous eoftoken */
71 static struct incl *incl;
72 static int eoftoken; /* current EOF token */
73 static void endinclude __P((void));
79 PATH [-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]*
80 WORD [A-Za-z_][-A-Za-z_0-9]*
87 compile-with { return COMPILE_WITH; }
88 config { return CONFIG; }
89 define { return DEFINE; }
90 device { return DEVICE; }
91 dumps { return DUMPS; }
92 flags { return FLAGS; }
93 file { return XFILE; }
94 include { return INCLUDE; }
95 machine { return XMACHINE; }
96 major { return MAJOR; }
97 makeoptions { return MAKEOPTIONS; }
98 maxusers { return MAXUSERS; }
99 minor { return MINOR; }
101 options { return OPTIONS; }
102 "pseudo-device" { return PSEUDO_DEVICE; }
103 root { return ROOT; }
104 swap { return SWAP; }
105 vector { return VECTOR; }
107 /* keywords with values */
108 config-dependent { yylval.val = FI_CONFIGDEP; return FFLAG; }
109 device-driver { yylval.val = FI_DRIVER; return FFLAG; }
110 needs-count { yylval.val = FI_NEEDSCOUNT; return FFLAG; }
111 needs-flag { yylval.val = FI_NEEDSFLAG; return FFLAG; }
114 {PATH} { yylval.str = intern(yytext); return PATHNAME; }
115 {WORD} { yylval.str = intern(yytext); return WORD; }
118 yylval.str = intern(yytext + 1);
119 (void)input(); /* eat closing quote */
123 yylval.val = strtol(yytext, NULL, 8);
127 yylval.val = strtol(yytext + 2, NULL, 16);
131 yylval.val = strtol(yytext, NULL, 10);
141 #.* { /* ignored (comment) */; }
142 [ \t]* { /* ignored (white space) */; }
143 . { return yytext[0]; }
157 * Open the "main" file (conffile).
164 if ((yyin = fopen(fname, "r")) == NULL)
166 yyfile = conffile = fname;
173 * Open the named file for inclusion at the current point. Returns 0 on
174 * success (file opened and previous state pushed), nonzero on failure
175 * (fopen failed, complaint made). The `ateof' parameter controls the
176 * token to be returned at the end of the include file (typically '\n'
180 include(fname, ateof)
185 register struct incl *in;
187 if ((fp = fopen(fname, "r")) == NULL) {
188 error("cannot open %s for reading: %s\n",
189 fname, strerror(errno));
192 in = emalloc(sizeof *in);
194 in->in_buf = YY_CURRENT_BUFFER;
195 in->in_fname = yyfile;
196 in->in_lineno = yyline;
197 in->in_preveof = eoftoken;
199 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
200 yyfile = intern(fname);
207 * Terminate the most recent inclusion.
212 register struct incl *in;
214 if ((in = incl) == NULL)
218 yy_delete_buffer(YY_CURRENT_BUFFER);
220 yy_switch_to_buffer(in->in_buf);
221 yyfile = in->in_fname;
222 yyline = in->in_lineno;
223 eoftoken = in->in_preveof;
228 * Return the current line number. If yacc has looked ahead and caused
229 * us to consume a newline, we have to subtract one. yychar is yacc's
230 * token lookahead, so we can tell.
237 return (yyline - (yychar == '\n'));