3 * Copyright (c) 1997-2014 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. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * File: am-utils/fsinfo/fsi_lex.l
42 * Lexical analyzer for fsinfo.
43 * TODO: Needs rewriting.
49 # define INIT_STATE { \
50 switch ((yy_start - 1) / 2) { \
57 #else /* not FLEX_SCANNER */
62 # define INIT_STATE { \
63 switch (yybgin - yysvec - 1) { \
70 #endif /* end FLEX_SCANNER */
74 #endif /* HAVE_CONFIG_H */
76 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
77 * and their (bad) version of lex defines it too at the very beginning of
78 * the generated lex.yy.c file (before it can be easily undefined),
79 * resulting in a conflict. So undefine it here before needed.
80 * Luckily, it does not appear that this macro is actually used in the rest
81 * of the generated lex.yy.c file.
90 /* and once again undefine this, just in case */
96 * There are some things that need to be defined only if using GNU flex.
97 * These must not be defined if using standard lex
101 # define ECHO __IGNORE(fwrite( yytext, yyleng, 1, yyout ))
102 # endif /* not ECHO */
103 #endif /* FLEX_SCANNER */
106 * some systems such as DU-4.x have a different GNU flex in /usr/bin
107 * which automatically generates yywrap macros and symbols. So I must
108 * distinguish between them and when yywrap is actually needed.
110 #if !defined(yywrap) || defined(yylex)
112 #endif /* not yywrap or yylex */
114 int fsi_error(const char *, ...);
117 static char *fsi_filename;
119 static char ostr[1024];
120 static int find_resword(char *);
130 { "automount", tAUTOMOUNT },
131 { "cluster", tCLUSTER },
132 { "config", tCONFIG },
133 { "direct", tDIRECT },
134 { "dumpset", tDUMPSET },
135 { "exportfs", tEXPORTFS },
139 { "fstype", tFSTYPE },
141 { "hwaddr", tHWADDR },
142 { "inaddr", tINADDR },
143 { "localhost", tLOCALHOST },
147 { "netmask", tNETMASK },
148 { "nfsalias", tNFSEQ },
151 { "passno", tPASSNO },
153 { "volname", tVOLNAME },
156 #define NRES_WORDS (sizeof(rr)/sizeof(rr[0])-1)
160 /* This option causes Solaris lex to fail. Use flex. See BUGS file */
161 /* no need to use yyunput() */
165 /* allocate more output slots so lex scanners don't run out of mem */
171 INIT_STATE; /* witchcraft */
173 <F>[^ \t\n"={}]+ { return find_resword(yytext); } /* dummy " */
175 <F>"\n" { ayylineno++; }
176 <F>[={}] { return *yytext; }
178 <F>\" { BEGIN Q; optr = ostr; quoted = 1; }
179 <Q>\n { ayylineno++; fsi_error("\" expected"); BEGIN F; }
180 <Q>\\b { *optr++ = '\b'; /* escape */ }
181 <Q>\\t { *optr++ = '\t'; /* escape */ }
182 <Q>\\\" { *optr++ = '\"'; /* escape */ }
183 <Q>\\\\ { *optr++ = '\\'; /* escape */ }
184 <Q>\\\n { ayylineno++; /* continue */ }
185 <Q>\\r { *optr++ = '\r'; /* escape */ }
186 <Q>\\n { *optr++ = '\n'; /* escape */ }
187 <Q>\\f { *optr++ = '\f'; /* escape */ }
188 <Q>"\\ " { *optr++ = ' '; /* force space */ }
189 <Q>\\. { fsi_error("Unknown \\ sequence"); }
190 <Q>([ \t]|"\\\n"){2,} { char *p = (char *) yytext-1; while ((p = strchr(p+1, '\n'))) ayylineno++; }
191 <Q>\" { BEGIN F; quoted = 0;
193 yylval.s = xstrdup(ostr);
196 <Q>. { *optr++ = *yytext; }
202 find_resword(char *s)
205 int l = 0, m = NRES_WORDS/2, h = NRES_WORDS-1;
210 #define FSTRCMP(p, q) ((*(p) == *(q)) ? strcmp((p)+1, (q)+1) : *(p) - *(q))
212 while ((l <= h) && (rc = FSTRCMP(s, rr[m].rw))) {
228 yylval.s = xstrdup(s);
238 fsi_error(const char *fmt, ...)
244 fprintf(stderr, "%s:%d: ", fsi_filename ? fsi_filename : "/dev/stdin", ayylineno);
245 vfprintf(stderr, fmt, ap);
254 current_location(void)
256 ioloc *ip = CALLOC(struct ioloc);
257 ip->i_line = ayylineno;
258 ip->i_file = fsi_filename;
264 * some systems such as DU-4.x have a different GNU flex in /usr/bin
265 * which automatically generates yywrap macros and symbols. So I must
266 * distinguish between them and when yywrap is actually needed.
268 #if !defined(yywrap) || defined(yylex)
273 #endif /* not yywrap or yylex */