]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/config.new/scan.l
Restore back -i for adjkerntz
[FreeBSD/FreeBSD.git] / usr.sbin / config.new / scan.l
1 %{
2 /* 
3  * Copyright (c) 1992, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  *
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.
9  *
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.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
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.
30  *
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
41  * SUCH DAMAGE.
42  *
43  *      @(#)scan.l      8.1 (Berkeley) 6/6/93
44  */
45
46 #include <sys/param.h>
47 #include <errno.h>
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <unistd.h>
52 #include "config.h"
53 #include "y.tab.h"
54
55 int     yyline;
56 const char *yyfile;
57 const char *lastfile;
58
59 int     include __P((const char *, int));
60
61 /*
62  * Data for returning to previous files from include files.
63  */
64 struct incl {
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 */
70 };
71 static struct incl *incl;
72 static int eoftoken;            /* current EOF token */
73 static void endinclude __P((void));
74
75 #define yywrap() 1
76
77 %}
78
79 PATH    [-/A-Za-z0-9_.]*[./][-/A-Za-z0-9_.]*
80 WORD    [A-Za-z_][-A-Za-z_0-9]*
81
82 %%
83
84                 /* plain keywords */
85 and             { return AND; }
86 at              { return AT; }
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; }
100 on              { return ON; }
101 options         { return OPTIONS; }
102 "pseudo-device" { return PSEUDO_DEVICE; }
103 root            { return ROOT; }
104 swap            { return SWAP; }
105 vector          { return VECTOR; }
106
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; }
112
113                 /* all the rest */
114 {PATH}          { yylval.str = intern(yytext); return PATHNAME; }
115 {WORD}          { yylval.str = intern(yytext); return WORD; }
116
117 \"[^"]+/\" {
118                 yylval.str = intern(yytext + 1);
119                 (void)input();  /* eat closing quote */
120                 return WORD;
121         }
122 0[0-7]* {
123                 yylval.val = strtol(yytext, NULL, 8);
124                 return NUMBER;
125         }
126 0[xX][0-9a-fA-F]+ {
127                 yylval.val = strtol(yytext + 2, NULL, 16);
128                 return NUMBER;
129         }
130 [1-9][0-9]* {
131                 yylval.val = strtol(yytext, NULL, 10);
132                 return NUMBER;
133         }
134 \n/[ \t] {
135                 yyline++;
136         }
137 \n      {
138                 yyline++;
139                 return '\n';
140         }
141 #.*     { /* ignored (comment) */; }
142 [ \t]*  { /* ignored (white space) */; }
143 .       { return yytext[0]; }
144 <<EOF>> {
145                 int tok;
146
147                 tok = eoftoken;
148                 eoftoken = YY_NULL;
149                 if (incl != NULL)
150                         endinclude();
151                 return (tok);
152         }
153
154 %%
155
156 /*
157  * Open the "main" file (conffile).
158  */
159 int
160 firstfile(fname)
161         const char *fname;
162 {
163
164         if ((yyin = fopen(fname, "r")) == NULL)
165                 return (-1);
166         yyfile = conffile = fname;
167         yyline = 1;
168         eoftoken = YY_NULL;
169         return (0);
170 }
171
172 /*
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'
177  * or ENDFILE).
178  */
179 int
180 include(fname, ateof)
181         const char *fname;
182         int ateof;
183 {
184         register FILE *fp;
185         register struct incl *in;
186
187         if ((fp = fopen(fname, "r")) == NULL) {
188                 error("cannot open %s for reading: %s\n",
189                     fname, strerror(errno));
190                 return (-1);
191         }
192         in = emalloc(sizeof *in);
193         in->in_prev = incl;
194         in->in_buf = YY_CURRENT_BUFFER;
195         in->in_fname = yyfile;
196         in->in_lineno = yyline;
197         in->in_preveof = eoftoken;
198         incl = in;
199         yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
200         yyfile = intern(fname);
201         yyline = 1;
202         eoftoken = ateof;
203         return (0);
204 }
205
206 /*
207  * Terminate the most recent inclusion.
208  */
209 static void
210 endinclude()
211 {
212         register struct incl *in;
213
214         if ((in = incl) == NULL)
215                 panic("endinclude");
216         incl = in->in_prev;
217         lastfile = yyfile;
218         yy_delete_buffer(YY_CURRENT_BUFFER);
219         (void)fclose(yyin);
220         yy_switch_to_buffer(in->in_buf);
221         yyfile = in->in_fname;
222         yyline = in->in_lineno;
223         eoftoken = in->in_preveof;
224         free(in);
225 }
226
227 /*
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.
231  */
232 int
233 currentline()
234 {
235         extern int yychar;
236
237         return (yyline - (yychar == '\n'));
238 }