| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: scan.l,v 1.28 2020/03/07 22:35:16 christos Exp $ */ | | 2 | /* $NetBSD: scan.l,v 1.29 2020/03/08 00:04:11 christos Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 1992, 1993 | | 5 | * Copyright (c) 1992, 1993 |
6 | * The Regents of the University of California. All rights reserved. | | 6 | * The Regents of the University of California. All rights reserved. |
7 | * | | 7 | * |
8 | * This software was developed by the Computer Systems Engineering group | | 8 | * This software was developed by the Computer Systems Engineering group |
9 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 9 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
10 | * contributed to Berkeley. | | 10 | * contributed to Berkeley. |
11 | * | | 11 | * |
12 | * All advertising materials mentioning features or use of this software | | 12 | * All advertising materials mentioning features or use of this software |
13 | * must display the following acknowledgement: | | 13 | * must display the following acknowledgement: |
14 | * This product includes software developed by the University of | | 14 | * This product includes software developed by the University of |
15 | * California, Lawrence Berkeley Laboratories. | | 15 | * California, Lawrence Berkeley Laboratories. |
| @@ -32,27 +32,27 @@ | | | @@ -32,27 +32,27 @@ |
32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 35 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 36 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 37 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
38 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 38 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
39 | * SUCH DAMAGE. | | 39 | * SUCH DAMAGE. |
40 | * | | 40 | * |
41 | * from: @(#)scan.l 8.1 (Berkeley) 6/6/93 | | 41 | * from: @(#)scan.l 8.1 (Berkeley) 6/6/93 |
42 | */ | | 42 | */ |
43 | | | 43 | |
44 | #include <sys/cdefs.h> | | 44 | #include <sys/cdefs.h> |
45 | __RCSID("$NetBSD: scan.l,v 1.28 2020/03/07 22:35:16 christos Exp $"); | | 45 | __RCSID("$NetBSD: scan.l,v 1.29 2020/03/08 00:04:11 christos Exp $"); |
46 | | | 46 | |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <errno.h> | | 48 | #include <errno.h> |
49 | #include <libgen.h> | | 49 | #include <libgen.h> |
50 | #include <stdio.h> | | 50 | #include <stdio.h> |
51 | #include <stdlib.h> | | 51 | #include <stdlib.h> |
52 | #include <string.h> | | 52 | #include <string.h> |
53 | #include <unistd.h> | | 53 | #include <unistd.h> |
54 | #include <stddef.h> | | 54 | #include <stddef.h> |
55 | #include <ctype.h> | | 55 | #include <ctype.h> |
56 | #include <util.h> | | 56 | #include <util.h> |
57 | #undef ECHO | | 57 | #undef ECHO |
58 | #include "defs.h" | | 58 | #include "defs.h" |
| @@ -97,26 +97,27 @@ static int endinclude(void); | | | @@ -97,26 +97,27 @@ static int endinclude(void); |
97 | static int getincludepath(void); | | 97 | static int getincludepath(void); |
98 | static int getcurifdef(void); | | 98 | static int getcurifdef(void); |
99 | | | 99 | |
100 | | | 100 | |
101 | %} | | 101 | %} |
102 | | | 102 | |
103 | %option noyywrap nounput noinput | | 103 | %option noyywrap nounput noinput |
104 | | | 104 | |
105 | PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]* | | 105 | PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]* |
106 | QCHARS \"(\\.|[^\\"])*\" | | 106 | QCHARS \"(\\.|[^\\"])*\" |
107 | WORD [A-Za-z_][-A-Za-z_0-9]* | | 107 | WORD [A-Za-z_][-A-Za-z_0-9]* |
108 | FILENAME ({PATH}|{QCHARS}) | | 108 | FILENAME ({PATH}|{QCHARS}) |
109 | RESTOFLINE [ \t]*(#[^\n]*)?\n | | 109 | RESTOFLINE [ \t]*(#[^\n]*)?\n |
| | | 110 | WS ^[ \t]* |
110 | | | 111 | |
111 | %x IGNORED | | 112 | %x IGNORED |
112 | | | 113 | |
113 | %% | | 114 | %% |
114 | /* Local variables for yylex() */ | | 115 | /* Local variables for yylex() */ |
115 | int tok; | | 116 | int tok; |
116 | | | 117 | |
117 | and return AND; | | 118 | and return AND; |
118 | at return AT; | | 119 | at return AT; |
119 | attach return ATTACH; | | 120 | attach return ATTACH; |
120 | block return BLOCK; | | 121 | block return BLOCK; |
121 | build return BUILD; | | 122 | build return BUILD; |
122 | char return CHAR; | | 123 | char return CHAR; |
| @@ -159,101 +160,101 @@ pseudo-device return PSEUDO_DEVICE; | | | @@ -159,101 +160,101 @@ pseudo-device return PSEUDO_DEVICE; |
159 | pseudo-root return PSEUDO_ROOT; | | 160 | pseudo-root return PSEUDO_ROOT; |
160 | root return ROOT; | | 161 | root return ROOT; |
161 | select return SELECT; | | 162 | select return SELECT; |
162 | single return SINGLE; | | 163 | single return SINGLE; |
163 | source return SOURCE; | | 164 | source return SOURCE; |
164 | type return TYPE; | | 165 | type return TYPE; |
165 | vector return VECTOR; | | 166 | vector return VECTOR; |
166 | version return VERSION; | | 167 | version return VERSION; |
167 | with return WITH; | | 168 | with return WITH; |
168 | | | 169 | |
169 | \+= return PLUSEQ; | | 170 | \+= return PLUSEQ; |
170 | := return COLONEQ; | | 171 | := return COLONEQ; |
171 | | | 172 | |
172 | <*>ifdef[ \t]+{WORD}{RESTOFLINE} { | | 173 | <*>{WS}ifdef[ \t]+{WORD}{RESTOFLINE} { |
173 | ifdefstate <<= IDS_SHIFT; | | 174 | ifdefstate <<= IDS_SHIFT; |
174 | if (++ifdefshift >= IDS_MAX_DEPTH) { | | 175 | if (++ifdefshift >= IDS_MAX_DEPTH) { |
175 | yyerror("too many levels of conditional"); | | 176 | yyerror("too many levels of conditional"); |
176 | } | | 177 | } |
177 | if (IDS_PARENT_DISABLED || !getcurifdef()) { | | 178 | if (IDS_PARENT_DISABLED || !getcurifdef()) { |
178 | BEGIN(IGNORED); | | 179 | BEGIN(IGNORED); |
179 | } else { | | 180 | } else { |
180 | ifdefstate |= IDS_MATCH; | | 181 | ifdefstate |= IDS_MATCH; |
181 | BEGIN(INITIAL); | | 182 | BEGIN(INITIAL); |
182 | } | | 183 | } |
183 | yyline++; | | 184 | yyline++; |
184 | } | | 185 | } |
185 | | | 186 | |
186 | <*>ifndef[ \t]+{WORD}{RESTOFLINE} { | | 187 | <*>{WS}ifndef[ \t]+{WORD}{RESTOFLINE} { |
187 | ifdefstate <<= IDS_SHIFT; | | 188 | ifdefstate <<= IDS_SHIFT; |
188 | if (++ifdefshift >= IDS_MAX_DEPTH) { | | 189 | if (++ifdefshift >= IDS_MAX_DEPTH) { |
189 | yyerror("too many levels of conditional"); | | 190 | yyerror("too many levels of conditional"); |
190 | } | | 191 | } |
191 | if (IDS_PARENT_DISABLED || getcurifdef()) { | | 192 | if (IDS_PARENT_DISABLED || getcurifdef()) { |
192 | BEGIN(IGNORED); | | 193 | BEGIN(IGNORED); |
193 | } else { | | 194 | } else { |
194 | ifdefstate |= IDS_MATCH; | | 195 | ifdefstate |= IDS_MATCH; |
195 | BEGIN(INITIAL); | | 196 | BEGIN(INITIAL); |
196 | } | | 197 | } |
197 | yyline++; | | 198 | yyline++; |
198 | } | | 199 | } |
199 | | | 200 | |
200 | | | 201 | |
201 | <*>elifdef[ \t]+{WORD}{RESTOFLINE} { | | 202 | <*>{WS}elifdef[ \t]+{WORD}{RESTOFLINE} { |
202 | int st = ifdefstate & IDS_BITS; | | 203 | int st = ifdefstate & IDS_BITS; |
203 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { | | 204 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { |
204 | yyerror("mismatched elifdef"); | | 205 | yyerror("mismatched elifdef"); |
205 | } | | 206 | } |
206 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || !getcurifdef()) { | | 207 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || !getcurifdef()) { |
207 | BEGIN(IGNORED); | | 208 | BEGIN(IGNORED); |
208 | } else { | | 209 | } else { |
209 | ifdefstate |= IDS_MATCH; | | 210 | ifdefstate |= IDS_MATCH; |
210 | BEGIN(INITIAL); | | 211 | BEGIN(INITIAL); |
211 | } | | 212 | } |
212 | ifdefstate |= IDS_ELIF; | | 213 | ifdefstate |= IDS_ELIF; |
213 | yyline++; | | 214 | yyline++; |
214 | } | | 215 | } |
215 | | | 216 | |
216 | <*>elifndef[ \t]+{WORD}{RESTOFLINE} { | | 217 | <*>{WS}elifndef[ \t]+{WORD}{RESTOFLINE} { |
217 | int st = ifdefstate & IDS_BITS; | | 218 | int st = ifdefstate & IDS_BITS; |
218 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { | | 219 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { |
219 | yyerror("mismatched elifndef"); | | 220 | yyerror("mismatched elifndef"); |
220 | } | | 221 | } |
221 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || getcurifdef()) { | | 222 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || getcurifdef()) { |
222 | BEGIN(IGNORED); | | 223 | BEGIN(IGNORED); |
223 | } else { | | 224 | } else { |
224 | ifdefstate |= IDS_MATCH; | | 225 | ifdefstate |= IDS_MATCH; |
225 | BEGIN(INITIAL); | | 226 | BEGIN(INITIAL); |
226 | } | | 227 | } |
227 | ifdefstate |= IDS_ELIF; | | 228 | ifdefstate |= IDS_ELIF; |
228 | yyline++; | | 229 | yyline++; |
229 | } | | 230 | } |
230 | | | 231 | |
231 | <*>else{RESTOFLINE} { | | 232 | <*>{WS}else{RESTOFLINE} { |
232 | int st = ifdefstate & IDS_BITS; | | 233 | int st = ifdefstate & IDS_BITS; |
233 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { | | 234 | if (ifdefshift == -1 || (st & IDS_ELSE) != 0) { |
234 | yyerror("mismatched else"); | | 235 | yyerror("mismatched else"); |
235 | } | | 236 | } |
236 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st)) { | | 237 | if (IDS_PARENT_DISABLED || IDS_ISMATCH(st)) { |
237 | BEGIN(IGNORED); | | 238 | BEGIN(IGNORED); |
238 | } else { | | 239 | } else { |
239 | ifdefstate |= IDS_MATCH; | | 240 | ifdefstate |= IDS_MATCH; |
240 | BEGIN(INITIAL); | | 241 | BEGIN(INITIAL); |
241 | } | | 242 | } |
242 | ifdefstate |= IDS_ELSE; | | 243 | ifdefstate |= IDS_ELSE; |
243 | yyline++; | | 244 | yyline++; |
244 | } | | 245 | } |
245 | | | 246 | |
246 | <*>endif{RESTOFLINE} { | | 247 | <*>{WS}endif{RESTOFLINE} { |
247 | if (ifdefshift == -1) { | | 248 | if (ifdefshift == -1) { |
248 | yyerror("mismatched endif"); | | 249 | yyerror("mismatched endif"); |
249 | } | | 250 | } |
250 | if (!IDS_PARENT_DISABLED) { | | 251 | if (!IDS_PARENT_DISABLED) { |
251 | BEGIN(INITIAL); | | 252 | BEGIN(INITIAL); |
252 | } | | 253 | } |
253 | ifdefshift--; | | 254 | ifdefshift--; |
254 | ifdefstate >>= IDS_SHIFT; | | 255 | ifdefstate >>= IDS_SHIFT; |
255 | yyline++; | | 256 | yyline++; |
256 | } | | 257 | } |
257 | | | 258 | |
258 | <IGNORED>\n { | | 259 | <IGNORED>\n { |
259 | yyline++; | | 260 | yyline++; |