Merge from vendor branch AWK:
[dragonfly.git] / contrib / amd / amd / conf_tok.l
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: conf_tok.l,v 1.2 1999/01/10 21:53:45 ezk Exp $
43  *
44  */
45
46 /*
47  * Lexical analyzer for AMD configuration parser.
48  */
49
50 #ifdef HAVE_CONFIG_H
51 # include <config.h>
52 #endif /* HAVE_CONFIG_H */
53 /*
54  * Some systems include a definition for the macro ECHO in <sys/ioctl.h>,
55  * and their (bad) version of lex defines it too at the very beginning of
56  * the generated lex.yy.c file (before it can be easily undefined),
57  * resulting in a conflict.  So undefine it here before needed.
58  * Luckily, it does not appear that this macro is actually used in the rest
59  * of the generated lex.yy.c file.
60  */
61 #ifdef ECHO
62 # undef ECHO
63 #endif /* ECHO */
64 #include <am_defs.h>
65 #include <amd.h>
66 #include <conf_parse.h>
67 /* and once again undefine this, just in case */
68 #ifdef ECHO
69 # undef ECHO
70 #endif /* ECHO */
71
72 /*
73  * There are some things that need to be defined only if using GNU flex.
74  * These must not be defined if using standard lex
75  */
76 #ifdef FLEX_SCANNER
77 # ifndef ECHO
78 #  define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
79 # endif /* not ECHO */
80 int yylineno = 0;
81 #endif /* FLEX_SCANNER */
82
83 int yylex(void);
84 /*
85  * some systems such as DU-4.x have a different GNU flex in /usr/bin
86  * which automatically generates yywrap macros and symbols.  So I must
87  * distinguish between them and when yywrap is actually needed.
88  */
89 #ifndef yywrap
90 int yywrap(void);
91 #endif /* not yywrap */
92
93 #define TOK_DEBUG 0
94
95 #if TOK_DEBUG
96 # define dprintf(f,s) fprintf(stderr, (f), yylineno, (s))
97 # define amu_return(v)
98 #else
99 # define dprintf(f,s)
100 # define amu_return(v) return((v))
101 #endif /* TOK_DEBUG */
102
103 /* no need to use yyunput() or yywrap() */
104 #define YY_NO_UNPUT
105 #define YY_SKIP_YYWRAP
106
107 %}
108
109 DIGIT           [0-9]
110 ALPHA           [A-Za-z]
111 ALPHANUM        [A-Za-z0-9]
112 SYMBOL          [A-Za-z0-9_-]
113 PATH            [A-Za-z0-9_-/]
114 NONWSCHAR       [^ \t\n\[\]=]
115 NONWSEQCHAR     [^ \t\n\[\]]
116 NONNL           [^\n]
117 NONQUOTE        [^\"]
118
119 %%
120
121 \n                      {
122                         yylineno++;
123                         amu_return(NEWLINE);
124                         }
125
126 \[                      {
127                         dprintf("%8d: Left bracket \"%s\"\n", yytext);
128                         yylval.strtype = strdup((char *)yytext);
129                         amu_return(LEFT_BRACKET);
130                         }
131
132 \]                      {
133                         dprintf("%8d: Right bracket \"%s\"\n", yytext);
134                         yylval.strtype = strdup((char *)yytext);
135                         amu_return(RIGHT_BRACKET);
136                         }
137
138 =                       {
139                         dprintf("%8d: Equal \"%s\"\n", yytext);
140                         yylval.strtype = strdup((char *)yytext);
141                         amu_return(EQUAL);
142                         }
143
144 [ \t]*                  {
145                         dprintf("%8d: Whitespace \"%s\"\n", yytext);
146                         }
147 "#"[^\n]*\n             {
148                         /* a comment line includes the terminating \n */
149                         yylineno++;
150                         yytext[strlen((char *)yytext)-1] = '\0';
151                         dprintf("%8d: Comment \"%s\"\n", yytext);
152                         }
153
154 {NONWSCHAR}{NONWSCHAR}* {
155                         dprintf("%8d: Non-WS string \"%s\"\n", yytext);
156                         yylval.strtype = strdup((char *)yytext);
157                         amu_return(NONWS_STRING);
158                         }
159
160 \"{NONQUOTE}{NONQUOTE}*\"       {
161                         dprintf("%8d: QUOTED-Non-WS-EQ string \"%s\"\n", yytext);
162                         /* must strip quotes */
163                         yytext[strlen((char *)yytext)-1] = '\0';
164                         yylval.strtype = strdup((char *)&yytext[1]);
165                         amu_return(QUOTED_NONWSEQ_STRING);
166                         }
167
168 {NONWSEQCHAR}{NONWSEQCHAR}*     {
169                         dprintf("%8d: Non-WS-EQ string \"%s\"\n", yytext);
170                         yylval.strtype = strdup((char *)yytext);
171                         amu_return(NONWSEQ_STRING);
172                         }
173
174 %%
175
176 /*
177  * some systems such as DU-4.x have a different GNU flex in /usr/bin
178  * which automatically generates yywrap macros and symbols.  So I must
179  * distinguish between them and when yywrap is actually needed.
180  */
181 #ifndef yywrap
182 int yywrap(void)
183 {
184   return 1;
185 }
186 #endif /* not yywrap */