]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/amd/amd/conf_tok.l
MFC r308493, r308619: Update amd from am-utils 6.1.5 to 6.2.
[FreeBSD/stable/10.git] / contrib / amd / amd / conf_tok.l
1 %{
2 /*
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.
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. 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.
23  *
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
34  * SUCH DAMAGE.
35  *
36  *
37  * File: am-utils/amd/conf_tok.l
38  *
39  */
40
41 /*
42  * Lexical analyzer for AMD configuration parser.
43  */
44
45 #ifdef HAVE_CONFIG_H
46 # include <config.h>
47 #endif /* HAVE_CONFIG_H */
48 /*
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.
55  */
56 #ifdef ECHO
57 # undef ECHO
58 #endif /* ECHO */
59 #include <am_defs.h>
60 #include <amd.h>
61 #include <conf_parse.h>
62 /* and once again undefine this, just in case */
63 #ifdef ECHO
64 # undef ECHO
65 #endif /* ECHO */
66
67 /*
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
70  */
71 #ifdef FLEX_SCANNER
72 # ifndef ECHO
73 #  define ECHO __IGNORE(fwrite( yytext, yyleng, 1, yyout ))
74 # endif /* not ECHO */
75 #endif /* FLEX_SCANNER */
76
77 int ayylineno = 0;
78
79 int yylex(void);
80 /*
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.
84  */
85 #if !defined(yywrap) || defined(yylex)
86 int yywrap(void);
87 #endif /* not yywrap or yylex */
88
89 #define TOK_DEBUG 0
90
91 #if TOK_DEBUG
92 # define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s))
93 # define amu_return(v)
94 #else /* not TOK_DEBUG */
95 # define dprintf(f,s)
96 # define amu_return(v) return((v))
97 #endif /* not TOK_DEBUG */
98
99 /* no need to use yywrap() */
100 #define YY_SKIP_YYWRAP
101
102 %}
103
104 /* This option causes Solaris lex to fail.  Use flex.  See BUGS file */
105 /* no need to use yyunput() */
106 %option nounput
107 %option noinput
108
109 /* allocate more output slots so lex scanners don't run out of mem */
110 %o 1024
111
112 DIGIT           [0-9]
113 ALPHA           [A-Za-z]
114 ALPHANUM        [A-Za-z0-9]
115 SYMBOL          [A-Za-z0-9_-]
116 PATH            [A-Za-z0-9_-/]
117 NONWSCHAR       [^ \t\n\[\]=]
118 NONWSEQCHAR     [^ \t\n\[\]]
119 NONNL           [^\n]
120 NONQUOTE        [^\"]
121
122 %%
123
124 \n                      {
125                         ayylineno++;
126                         amu_return(NEWLINE);
127                         }
128
129 \[                      {
130                         dprintf("%8d: Left bracket \"%s\"\n", yytext);
131                         conf_lval.strtype = xstrdup(yytext);
132                         amu_return(LEFT_BRACKET);
133                         }
134
135 \]                      {
136                         dprintf("%8d: Right bracket \"%s\"\n", yytext);
137                         conf_lval.strtype = xstrdup(yytext);
138                         amu_return(RIGHT_BRACKET);
139                         }
140
141 =                       {
142                         dprintf("%8d: Equal \"%s\"\n", yytext);
143                         conf_lval.strtype = xstrdup(yytext);
144                         amu_return(EQUAL);
145                         }
146
147 [ \t]*                  {
148                         dprintf("%8d: Whitespace \"%s\"\n", yytext);
149                         }
150 "#"[^\n]*\n             {
151                         /* a comment line includes the terminating \n */
152                         ayylineno++;
153                         yytext[strlen((char *)yytext)-1] = '\0';
154                         dprintf("%8d: Comment \"%s\"\n", yytext);
155                         }
156
157 {NONWSCHAR}{NONWSCHAR}* {
158                         dprintf("%8d: Non-WS string \"%s\"\n", yytext);
159                         conf_lval.strtype = xstrdup(yytext);
160                         amu_return(NONWS_STRING);
161                         }
162
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);
169                         }
170
171 {NONWSEQCHAR}{NONWSEQCHAR}*     {
172                         dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext);
173                         conf_lval.strtype = xstrdup(yytext);
174                         amu_return(NONWSEQ_STRING);
175                         }
176
177 %%
178
179 /*
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.
183  */
184 #if !defined(yywrap) || defined(yylex)
185 int yywrap(void)
186 {
187   return 1;
188 }
189 #endif /* not yywrap or yylex */