1 /* $NetBSD: conf_tok.l,v 1.1.1.2 2009/03/20 20:26:49 christos Exp $ */
5 * Copyright (c) 1997-2009 Erez Zadok
6 * Copyright (c) 1989 Jan-Simon Pendry
7 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
8 * Copyright (c) 1989 The Regents of the University of California.
11 * This code is derived from software contributed to Berkeley by
12 * Jan-Simon Pendry at Imperial College, London.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgment:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * File: am-utils/amd/conf_tok.l
48 * Lexical analyzer for AMD configuration parser.
53 #endif /* HAVE_CONFIG_H */
55 * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
56 * and their (bad) version of lex defines it too at the very beginning of
57 * the generated lex.yy.c file (before it can be easily undefined),
58 * resulting in a conflict. So undefine it here before needed.
59 * Luckily, it does not appear that this macro is actually used in the rest
60 * of the generated lex.yy.c file.
67 #include <conf_parse.h>
68 /* and once again undefine this, just in case */
74 * There are some things that need to be defined only if using GNU flex.
75 * These must not be defined if using standard lex
79 # define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
80 # endif /* not ECHO */
81 #endif /* FLEX_SCANNER */
87 * some systems such as DU-4.x have a different GNU flex in /usr/bin
88 * which automatically generates yywrap macros and symbols. So I must
89 * distinguish between them and when yywrap is actually needed.
91 #if !defined(yywrap) || defined(yylex)
93 #endif /* not yywrap or yylex */
98 # define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s))
99 # define amu_return(v)
100 #else /* not TOK_DEBUG */
101 # define dprintf(f,s)
102 # define amu_return(v) return((v))
103 #endif /* not TOK_DEBUG */
105 /* no need to use yywrap() */
106 #define YY_SKIP_YYWRAP
110 /* This option causes Solaris lex to fail. Use flex. See BUGS file */
111 /* no need to use yyunput() */
114 /* allocate more output slots so lex scanners don't run out of mem */
122 NONWSCHAR [^ \t\n\[\]=]
123 NONWSEQCHAR [^ \t\n\[\]]
135 dprintf("%8d: Left bracket \"%s\"\n", yytext);
136 yylval.strtype = strdup((char *)yytext);
137 amu_return(LEFT_BRACKET);
141 dprintf("%8d: Right bracket \"%s\"\n", yytext);
142 yylval.strtype = strdup((char *)yytext);
143 amu_return(RIGHT_BRACKET);
147 dprintf("%8d: Equal \"%s\"\n", yytext);
148 yylval.strtype = strdup((char *)yytext);
153 dprintf("%8d: Whitespace \"%s\"\n", yytext);
156 /* a comment line includes the terminating \n */
158 yytext[strlen((char *)yytext)-1] = '\0';
159 dprintf("%8d: Comment \"%s\"\n", yytext);
162 {NONWSCHAR}{NONWSCHAR}* {
163 dprintf("%8d: Non-WS string \"%s\"\n", yytext);
164 yylval.strtype = strdup((char *)yytext);
165 amu_return(NONWS_STRING);
168 \"{NONQUOTE}{NONQUOTE}*\" {
169 dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext);
170 /* must strip quotes */
171 yytext[strlen((char *)yytext)-1] = '\0';
172 yylval.strtype = strdup((char *)&yytext[1]);
173 amu_return(QUOTED_NONWSEQ_STRING);
176 {NONWSEQCHAR}{NONWSEQCHAR}* {
177 dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext);
178 yylval.strtype = strdup((char *)yytext);
179 amu_return(NONWSEQ_STRING);
185 * some systems such as DU-4.x have a different GNU flex in /usr/bin
186 * which automatically generates yywrap macros and symbols. So I must
187 * distinguish between them and when yywrap is actually needed.
189 #if !defined(yywrap) || defined(yylex)
194 #endif /* not yywrap or yylex */