drm/i915: Fix hangs on some broadwell machines
[dragonfly.git] / contrib / amd / fsinfo / fsi_lex.l
CommitLineData
984263bc
MD
1%{
2/*
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.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Jan-Simon Pendry at Imperial College, London.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
27 *
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
38 * SUCH DAMAGE.
39 *
40 * %W% (Berkeley) %G%
41 *
42 * $Id: fsi_lex.l,v 1.3 1999/09/30 21:01:41 ezk Exp $
43 *
44 */
45
46/*
47 * Lexical analyzer for fsinfo.
48 * TODO: Needs rewriting.
49 */
50
51#ifdef FLEX_SCANNER
ff8bd418 52static int ayylineno;
984263bc
MD
53# define INIT_STATE { \
54 switch ((yy_start - 1) / 2) { \
55 case 0: \
56 BEGIN F; \
57 break; \
58 } \
59}
60
61#else /* not FLEX_SCANNER */
62
63/*
64 * Using old lex...
65 */
66# define INIT_STATE { \
67 switch (yybgin - yysvec - 1) { \
68 case 0: \
69 BEGIN F; \
70 break; \
71 } \
72}
73
74#endif /* end FLEX_SCANNER */
75
76#ifdef HAVE_CONFIG_H
77# include <config.h>
78#endif /* HAVE_CONFIG_H */
79/*
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.
86 */
87#ifdef ECHO
88# undef ECHO
89#endif /* ECHO */
90#include <am_defs.h>
91#include <fsi_data.h>
92#include <fsinfo.h>
93#include <fsi_gram.h>
94/* and once again undefine this, just in case */
95#ifdef ECHO
96# undef ECHO
97#endif /* ECHO */
98
99/*
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
102 */
103#ifdef FLEX_SCANNER
104# ifndef ECHO
105# define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
106# endif /* not ECHO */
107#endif /* FLEX_SCANNER */
108
109/*
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.
113 */
114#ifndef yywrap
115int yywrap(void);
116#endif /* not yywrap */
117
118YYSTYPE yylval;
119static char *fsi_filename;
120static char *optr;
121static char ostr[1024];
122static int find_resword(char *);
123static int quoted;
124
125struct r {
126 char *rw;
127 int tok;
128} rr[] = {
129 { "->", tEQ },
130 { "arch", tARCH },
131 { "as", tAS },
132 { "automount", tAUTOMOUNT },
133 { "cluster", tCLUSTER },
134 { "config", tCONFIG },
135 { "direct", tDIRECT },
136 { "dumpset", tDUMPSET },
137 { "exportfs", tEXPORTFS },
138 { "freq", tFREQ },
139 { "from", tFROM },
140 { "fs", tFS },
141 { "fstype", tFSTYPE },
142 { "host", tHOST },
143 { "hwaddr", tHWADDR },
144 { "inaddr", tINADDR },
145 { "localhost", tLOCALHOST },
146 { "log", tLOG },
147 { "mount", tMOUNT },
148 { "netif", tNETIF },
149 { "netmask", tNETMASK },
150 { "nfsalias", tNFSEQ },
151 { "opts", tOPTS },
152 { "os", tOS },
153 { "passno", tPASSNO },
154 { "sel", tSEL },
155 { "volname", tVOLNAME },
156 { 0, 0 },
157};
158#define NRES_WORDS (sizeof(rr)/sizeof(rr[0])-1)
159
160%}
161
162%start F Q
163
164%%
165 INIT_STATE; /* witchcraft */
166
167<F>[^ \t\n"={}]+ { return find_resword(yytext); } /* dummy " */
168<F>[ \t] ;
ff8bd418 169<F>"\n" { ayylineno++; }
984263bc
MD
170<F>[={}] { return *yytext; }
171
172<F>\" { BEGIN Q; optr = ostr; quoted = 1; }
ff8bd418 173<Q>\n { ayylineno++; yyerror("\" expected"); BEGIN F; }
984263bc
MD
174<Q>\\b { *optr++ = '\b'; /* escape */ }
175<Q>\\t { *optr++ = '\t'; /* escape */ }
176<Q>\\\" { *optr++ = '\"'; /* escape */ }
177<Q>\\\\ { *optr++ = '\\'; /* escape */ }
ff8bd418 178<Q>\\\n { ayylineno++; /* continue */ }
984263bc
MD
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"); }
ff8bd418 184<Q>([ \t]|"\\\n"){2,} { char *p = (char *) yytext-1; while ((p = strchr(p+1, '\n'))) ayylineno++; }
984263bc
MD
185<Q>\" { BEGIN F; quoted = 0;
186 *optr = '\0';
187 yylval.s = strdup(ostr);
188 return tSTR;
189 }
190<Q>. { *optr++ = *yytext; }
191
192%%
193
194
195static int
196find_resword(char *s)
197{
198 int tok = 0;
199 int l = 0, m = NRES_WORDS/2, h = NRES_WORDS-1;
200 int rc = 0;
201
202 m = NRES_WORDS/2;
203
204#define FSTRCMP(p, q) ((*(p) == *(q)) ? strcmp((p)+1, (q)+1) : *(p) - *(q))
205
206 while ((l <= h) && (rc = FSTRCMP(s, rr[m].rw))) {
207 if (rc < 0)
208 h = m - 1;
209 else
210 l = m + 1;
211 m = (h + l) / 2;
212 }
213
214 if (rc == 0)
215 tok = rr[m].tok;
216
217 switch (tok) {
218 case tLOCALHOST:
219 s = "${host}";
220 /* fall through... */
221 case 0:
222 yylval.s = strdup(s);
223 tok = tSTR;
224 /* fall through... */
225 default:
226 return tok;
227 }
228}
229
230
231int
232yyerror(char *fmt, ...)
233{
234 va_list ap;
235
236 va_start(ap, fmt);
237 col_cleanup(0);
ff8bd418 238 fprintf(stderr, "%s:%d: ", fsi_filename ? fsi_filename : "/dev/stdin", ayylineno);
984263bc
MD
239 fprintf(stderr, fmt, ap);
240 fputc('\n', stderr);
241 parse_errors++;
242 va_end(ap);
243 if (0) unput(0);/* dummy to shut gcc up: "unput defined but not used" */
244 return 0;
245}
246
247
248ioloc *
249current_location(void)
250{
251 ioloc *ip = CALLOC(struct ioloc);
ff8bd418 252 ip->i_line = ayylineno;
984263bc
MD
253 ip->i_file = fsi_filename;
254 return ip;
255}
256
257
258/*
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.
262 */
263#ifndef yywrap
264int yywrap(void)
265{
266 return 1;
267}
268#endif /* not yywrap */