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/amd/conf_tok.l
42 * Lexical analyzer for AMD configuration parser.
47 #endif /* HAVE_CONFIG_H */
49 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
50 * and their (bad) version of lex defines it too at the very beginning of
51 * the generated lex.yy.c file (before it can be easily undefined),
52 * resulting in a conflict. So undefine it here before needed.
53 * Luckily, it does not appear that this macro is actually used in the rest
54 * of the generated lex.yy.c file.
61 #include <conf_parse.h>
62 /* and once again undefine this, just in case */
68 * There are some things that need to be defined only if using GNU flex.
69 * These must not be defined if using standard lex
73 # define ECHO __IGNORE(fwrite( yytext, yyleng, 1, yyout ))
74 # endif /* not ECHO */
75 #endif /* FLEX_SCANNER */
81 * some systems such as DU-4.x have a different GNU flex in /usr/bin
82 * which automatically generates yywrap macros and symbols. So I must
83 * distinguish between them and when yywrap is actually needed.
85 #if !defined(yywrap) || defined(yylex)
87 #endif /* not yywrap or yylex */
92 # define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s))
93 # define amu_return(v)
94 #else /* not TOK_DEBUG */
96 # define amu_return(v) return((v))
97 #endif /* not TOK_DEBUG */
99 /* no need to use yywrap() */
100 #define YY_SKIP_YYWRAP
104 /* This option causes Solaris lex to fail. Use flex. See BUGS file */
105 /* no need to use yyunput() */
109 /* allocate more output slots so lex scanners don't run out of mem */
117 NONWSCHAR [^ \t\n\[\]=]
118 NONWSEQCHAR [^ \t\n\[\]]
130 dprintf("%8d: Left bracket \"%s\"\n", yytext);
131 conf_lval.strtype = xstrdup(yytext);
132 amu_return(LEFT_BRACKET);
136 dprintf("%8d: Right bracket \"%s\"\n", yytext);
137 conf_lval.strtype = xstrdup(yytext);
138 amu_return(RIGHT_BRACKET);
142 dprintf("%8d: Equal \"%s\"\n", yytext);
143 conf_lval.strtype = xstrdup(yytext);
148 dprintf("%8d: Whitespace \"%s\"\n", yytext);
151 /* a comment line includes the terminating \n */
153 yytext[strlen((char *)yytext)-1] = '\0';
154 dprintf("%8d: Comment \"%s\"\n", yytext);
157 {NONWSCHAR}{NONWSCHAR}* {
158 dprintf("%8d: Non-WS string \"%s\"\n", yytext);
159 conf_lval.strtype = xstrdup(yytext);
160 amu_return(NONWS_STRING);
163 \"{NONQUOTE}{NONQUOTE}*\" {
164 dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext);
165 /* must strip quotes */
166 yytext[strlen((char *)yytext)-1] = '\0';
167 conf_lval.strtype = xstrdup(&yytext[1]);
168 amu_return(QUOTED_NONWSEQ_STRING);
171 {NONWSEQCHAR}{NONWSEQCHAR}* {
172 dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext);
173 conf_lval.strtype = xstrdup(yytext);
174 amu_return(NONWSEQ_STRING);
180 * some systems such as DU-4.x have a different GNU flex in /usr/bin
181 * which automatically generates yywrap macros and symbols. So I must
182 * distinguish between them and when yywrap is actually needed.
184 #if !defined(yywrap) || defined(yylex)
189 #endif /* not yywrap or yylex */