Sun Mar 8 00:04:12 2020 UTC ()
Recognize {if{,n}def,elfif{,n}def,else,endif} only at the beginning of the
line or after whitespace.


(christos)
diff -r1.28 -r1.29 src/usr.bin/config/scan.l

cvs diff -r1.28 -r1.29 src/usr.bin/config/scan.l (expand / switch to unified diff)

--- src/usr.bin/config/scan.l 2020/03/07 22:35:16 1.28
+++ src/usr.bin/config/scan.l 2020/03/08 00:04:11 1.29
@@ -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);
97static int getincludepath(void); 97static int getincludepath(void);
98static int getcurifdef(void); 98static int getcurifdef(void);
99 99
100 100
101%} 101%}
102 102
103%option noyywrap nounput noinput 103%option noyywrap nounput noinput
104 104
105PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]* 105PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]*
106QCHARS \"(\\.|[^\\"])*\"  106QCHARS \"(\\.|[^\\"])*\"
107WORD [A-Za-z_][-A-Za-z_0-9]* 107WORD [A-Za-z_][-A-Za-z_0-9]*
108FILENAME ({PATH}|{QCHARS}) 108FILENAME ({PATH}|{QCHARS})
109RESTOFLINE [ \t]*(#[^\n]*)?\n 109RESTOFLINE [ \t]*(#[^\n]*)?\n
 110WS ^[ \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
117and return AND; 118and return AND;
118at return AT; 119at return AT;
119attach return ATTACH; 120attach return ATTACH;
120block return BLOCK; 121block return BLOCK;
121build return BUILD; 122build return BUILD;
122char return CHAR; 123char return CHAR;
@@ -159,101 +160,101 @@ pseudo-device return PSEUDO_DEVICE; @@ -159,101 +160,101 @@ pseudo-device return PSEUDO_DEVICE;
159pseudo-root return PSEUDO_ROOT; 160pseudo-root return PSEUDO_ROOT;
160root return ROOT; 161root return ROOT;
161select return SELECT; 162select return SELECT;
162single return SINGLE; 163single return SINGLE;
163source return SOURCE; 164source return SOURCE;
164type return TYPE; 165type return TYPE;
165vector return VECTOR; 166vector return VECTOR;
166version return VERSION; 167version return VERSION;
167with return WITH; 168with 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++;