3 * Copyright (c) 1997-1999 Erez Zadok
4 * Copyright (c) 1989 Jan-Simon Pendry
5 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
6 * Copyright (c) 1989 The Regents of the University of California.
9 * This code is derived from software contributed to Berkeley by
10 * Jan-Simon Pendry at Imperial College, London.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgment:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * $Id: fsi_lex.l,v 1.3 1999/09/30 21:01:41 ezk Exp $
47 * Lexical analyzer for fsinfo.
48 * TODO: Needs rewriting.
53 # define INIT_STATE { \
54 switch ((yy_start - 1) / 2) { \
61 #else /* not FLEX_SCANNER */
66 # define INIT_STATE { \
67 switch (yybgin - yysvec - 1) { \
74 #endif /* end FLEX_SCANNER */
78 #endif /* HAVE_CONFIG_H */
80 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
81 * and their (bad) version of lex defines it too at the very beginning of
82 * the generated lex.yy.c file (before it can be easily undefined),
83 * resulting in a conflict. So undefine it here before needed.
84 * Luckily, it does not appear that this macro is actually used in the rest
85 * of the generated lex.yy.c file.
94 /* and once again undefine this, just in case */
100 * There are some things that need to be defined only if using GNU flex.
101 * These must not be defined if using standard lex
105 # define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
106 # endif /* not ECHO */
107 #endif /* FLEX_SCANNER */
110 * some systems such as DU-4.x have a different GNU flex in /usr/bin
111 * which automatically generates yywrap macros and symbols. So I must
112 * distinguish between them and when yywrap is actually needed.
116 #endif /* not yywrap */
119 static char *fsi_filename;
121 static char ostr[1024];
122 static int find_resword(char *);
132 { "automount", tAUTOMOUNT },
133 { "cluster", tCLUSTER },
134 { "config", tCONFIG },
135 { "direct", tDIRECT },
136 { "dumpset", tDUMPSET },
137 { "exportfs", tEXPORTFS },
141 { "fstype", tFSTYPE },
143 { "hwaddr", tHWADDR },
144 { "inaddr", tINADDR },
145 { "localhost", tLOCALHOST },
149 { "netmask", tNETMASK },
150 { "nfsalias", tNFSEQ },
153 { "passno", tPASSNO },
155 { "volname", tVOLNAME },
158 #define NRES_WORDS (sizeof(rr)/sizeof(rr[0])-1)
165 INIT_STATE; /* witchcraft */
167 <F>[^ \t\n"={}]+ { return find_resword(yytext); } /* dummy " */
169 <F>"\n" { yylineno++; }
170 <F>[={}] { return *yytext; }
172 <F>\" { BEGIN Q; optr = ostr; quoted = 1; }
173 <Q>\n { yylineno++; yyerror("\" expected"); BEGIN F; }
174 <Q>\\b { *optr++ = '\b'; /* escape */ }
175 <Q>\\t { *optr++ = '\t'; /* escape */ }
176 <Q>\\\" { *optr++ = '\"'; /* escape */ }
177 <Q>\\\\ { *optr++ = '\\'; /* escape */ }
178 <Q>\\\n { yylineno++; /* continue */ }
179 <Q>\\r { *optr++ = '\r'; /* escape */ }
180 <Q>\\n { *optr++ = '\n'; /* escape */ }
181 <Q>\\f { *optr++ = '\f'; /* escape */ }
182 <Q>"\\ " { *optr++ = ' '; /* force space */ }
183 <Q>\\. { yyerror("Unknown \\ sequence"); }
184 <Q>([ \t]|"\\\n"){2,} { char *p = (char *) yytext-1; while ((p = strchr(p+1, '\n'))) yylineno++; }
185 <Q>\" { BEGIN F; quoted = 0;
187 yylval.s = strdup(ostr);
190 <Q>. { *optr++ = *yytext; }
196 find_resword(char *s)
199 int l = 0, m = NRES_WORDS/2, h = NRES_WORDS-1;
204 #define FSTRCMP(p, q) ((*(p) == *(q)) ? strcmp((p)+1, (q)+1) : *(p) - *(q))
206 while ((l <= h) && (rc = FSTRCMP(s, rr[m].rw))) {
220 /* fall through... */
222 yylval.s = strdup(s);
224 /* fall through... */
232 yyerror(char *fmt, ...)
238 fprintf(stderr, "%s:%d: ", fsi_filename ? fsi_filename : "/dev/stdin", yylineno);
239 fprintf(stderr, fmt, ap);
243 if (0) unput(0);/* dummy to shut gcc up: "unput defined but not used" */
249 current_location(void)
251 ioloc *ip = CALLOC(struct ioloc);
252 ip->i_line = yylineno;
253 ip->i_file = fsi_filename;
259 * some systems such as DU-4.x have a different GNU flex in /usr/bin
260 * which automatically generates yywrap macros and symbols. So I must
261 * distinguish between them and when yywrap is actually needed.
268 #endif /* not yywrap */