Mon Mar 9 15:22:21 2020 UTC ()
Pull up the following, requested by christos in ticket #776:

	usr.bin/config/TODO                             up to 1.32
	usr.bin/config/defs.h                           up to 1.105
	usr.bin/config/files.c                          up to 1.37
	usr.bin/config/gram.y                           up to 1.55
	usr.bin/config/main.c                           up to 1.99
	usr.bin/config/scan.l                           up to 1.30
	usr.bin/config/sem.c                            up to 1.84
	usr.bin/config/util.c                           up to 1.21

config(1): fix issue with incorrect handling of elifdef statements.


(martin)
diff -r1.31 -r1.31.18.1 src/usr.bin/config/TODO
diff -r1.104 -r1.104.2.1 src/usr.bin/config/defs.h
diff -r1.36 -r1.36.16.1 src/usr.bin/config/files.c
diff -r1.54 -r1.54.16.1 src/usr.bin/config/gram.y
diff -r1.98 -r1.98.2.1 src/usr.bin/config/main.c
diff -r1.26 -r1.26.16.1 src/usr.bin/config/scan.l
diff -r1.83 -r1.83.4.1 src/usr.bin/config/sem.c
diff -r1.20 -r1.20.18.1 src/usr.bin/config/util.c

cvs diff -r1.31 -r1.31.18.1 src/usr.bin/config/TODO (expand / switch to unified diff)

--- src/usr.bin/config/TODO 2015/11/22 01:20:36 1.31
+++ src/usr.bin/config/TODO 2020/03/09 15:22:21 1.31.18.1
@@ -249,27 +249,27 @@ o Control ELF sections using linker scri @@ -249,27 +249,27 @@ o Control ELF sections using linker scri
249 netbsd.ko ---> netbsd.ro Kernel MI linkage 249 netbsd.ko ---> netbsd.ro Kernel MI linkage
250 netbsd.ro ---> netbsd Kernel MD linkage 250 netbsd.ro ---> netbsd Kernel MD linkage
251 251
252 Modular build (kernel): 252 Modular build (kernel):
253 *.o ---> *.ko Generic + Per-module MI linkage 253 *.o ---> *.ko Generic + Per-module MI linkage
254 *.ko ---> netbsd.ro Kernel MI linkage 254 *.ko ---> netbsd.ro Kernel MI linkage
255 netbsd.ro ---> netbsd Kernel MD linkage 255 netbsd.ro ---> netbsd Kernel MD linkage
256 256
257 Modular build (module): 257 Modular build (module):
258 *.o ---> *.ko Generic + Per-module MI linkage 258 *.o ---> *.ko Generic + Per-module MI linkage
259 *.ko ---> *.ro Modular MI linkage 259 *.ko ---> *.ro Modular MI linkage
260 *.ro ---> *.kmod Modular MD linkage 260 *.ro ---> *.kmod Modular MD linkage
261 261
262 Genric MI linkage is for processing MI linkage that can be applied generally. 262 Generic MI linkage is for processing MI linkage that can be applied generally.
263 Data section alignment (.data.read_mostly and .data.cacheline_aligned) is 263 Data section alignment (.data.read_mostly and .data.cacheline_aligned) is
264 processed here. 264 processed here.
265 265
266 Per-module MI linkage is for modules that want some ordering. For example, 266 Per-module MI linkage is for modules that want some ordering. For example,
267 machdep.ko wants to put entry code at the top of .text and .data. 267 machdep.ko wants to put entry code at the top of .text and .data.
268 268
269 Kernel MI linkage is for collecting kernel global section data, that is what 269 Kernel MI linkage is for collecting kernel global section data, that is what
270 link-set is used for now. Once they are collected and symbols to the ranges 270 link-set is used for now. Once they are collected and symbols to the ranges
271 are assigned, those sections are merged into the pre-existing sections 271 are assigned, those sections are merged into the pre-existing sections
272 (.rodata) because link-set sections in "netbsd" will never be interpreted by 272 (.rodata) because link-set sections in "netbsd" will never be interpreted by
273 external loaders. 273 external loaders.
274 274
275 Kernel MD linkage is used purely for MD purposes, that is, how kernels are 275 Kernel MD linkage is used purely for MD purposes, that is, how kernels are

cvs diff -r1.104 -r1.104.2.1 src/usr.bin/config/defs.h (expand / switch to unified diff)

--- src/usr.bin/config/defs.h 2018/08/27 16:04:45 1.104
+++ src/usr.bin/config/defs.h 2020/03/09 15:22:21 1.104.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: defs.h,v 1.104 2018/08/27 16:04:45 riastradh Exp $ */ 1/* $NetBSD: defs.h,v 1.104.2.1 2020/03/09 15:22:21 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -100,63 +100,69 @@ @@ -100,63 +100,69 @@
100extern const char *progname; 100extern const char *progname;
101#define setprogname(s) ((void)(progname = (s))) 101#define setprogname(s) ((void)(progname = (s)))
102#define getprogname() (progname) 102#define getprogname() (progname)
103 103
104#define ARRCHR '#' 104#define ARRCHR '#'
105 105
106/* 106/*
107 * The next two lines define the current version of the config(1) binary, 107 * The next two lines define the current version of the config(1) binary,
108 * and the minimum version of the configuration files it supports. 108 * and the minimum version of the configuration files it supports.
109 */ 109 */
110#define CONFIG_VERSION 20180827 110#define CONFIG_VERSION 20180827
111#define CONFIG_MINVERSION 0 111#define CONFIG_MINVERSION 0
112 112
 113struct where {
 114 const char *w_srcfile; /* file name where we are defined */
 115 u_short w_srcline; /* line number where we are defined */
 116};
113/* 117/*
114 * Name/value lists. Values can be strings or pointers and/or can carry 118 * Name/value lists. Values can be strings or pointers and/or can carry
115 * integers. The names can be NULL, resulting in simple value lists. 119 * integers. The names can be NULL, resulting in simple value lists.
116 */ 120 */
117struct nvlist { 121struct nvlist {
118 struct nvlist *nv_next; 122 struct nvlist *nv_next;
119 const char *nv_name; 123 const char *nv_name;
120 const char *nv_str; 124 const char *nv_str;
121 void *nv_ptr; 125 void *nv_ptr;
122 long long nv_num; 126 long long nv_num;
123 int nv_ifunit; /* XXX XXX XXX */ 127 int nv_ifunit; /* XXX XXX XXX */
124 int nv_flags; 128 int nv_flags;
125#define NV_DEPENDED 1 129#define NV_DEPENDED 1
 130 struct where nv_where;
126}; 131};
127 132
128/* 133/*
129 * Kernel configurations. 134 * Kernel configurations.
130 */ 135 */
131struct config { 136struct config {
132 TAILQ_ENTRY(config) cf_next; 137 TAILQ_ENTRY(config) cf_next;
133 const char *cf_name; /* "netbsd" */ 138 const char *cf_name; /* "netbsd" */
134 int cf_lineno; /* source line */ 
135 const char *cf_fstype; /* file system type */ 139 const char *cf_fstype; /* file system type */
136 struct nvlist *cf_root; /* "root on ra0a" */ 140 struct nvlist *cf_root; /* "root on ra0a" */
137 struct nvlist *cf_dump; /* "dumps on ra0b" */ 141 struct nvlist *cf_dump; /* "dumps on ra0b" */
 142 struct where cf_where;
138}; 143};
139 144
140/* 145/*
141 * Option definition list 146 * Option definition list
142 */ 147 */
143struct defoptlist { 148struct defoptlist {
144 struct defoptlist *dl_next; 149 struct defoptlist *dl_next;
145 const char *dl_name; 150 const char *dl_name;
146 const char *dl_value; 151 const char *dl_value;
147 const char *dl_lintvalue; 152 const char *dl_lintvalue;
148 int dl_obsolete; 153 int dl_obsolete;
149 struct nvlist *dl_depends; 154 struct nvlist *dl_depends;
 155 struct where dl_where;
150}; 156};
151 157
152struct files; 158struct files;
153TAILQ_HEAD(filelist, files); 159TAILQ_HEAD(filelist, files);
154 160
155struct module { 161struct module {
156 const char *m_name; 162 const char *m_name;
157#if 1 163#if 1
158 struct attrlist *m_deps; 164 struct attrlist *m_deps;
159#else 165#else
160 struct attrlist *m_attrs; 166 struct attrlist *m_attrs;
161 struct modulelist *m_deps; 167 struct modulelist *m_deps;
162#endif 168#endif
@@ -189,26 +195,27 @@ struct attr { @@ -189,26 +195,27 @@ struct attr {
189#define a_files a_m.m_files 195#define a_files a_m.m_files
190#define a_weight a_m.m_weight 196#define a_weight a_m.m_weight
191 197
192 /* "interface attribute" */ 198 /* "interface attribute" */
193 uint8_t a_iattr; /* true => allows children */ 199 uint8_t a_iattr; /* true => allows children */
194 uint8_t a_deselected; /* deselected */  200 uint8_t a_deselected; /* deselected */
195 struct loclist *a_locs; /* locators required */ 201 struct loclist *a_locs; /* locators required */
196 int a_loclen; /* length of above list */ 202 int a_loclen; /* length of above list */
197 struct nvlist *a_devs; /* children */ 203 struct nvlist *a_devs; /* children */
198 struct nvlist *a_refs; /* parents */ 204 struct nvlist *a_refs; /* parents */
199 205
200 /* "device class" */ 206 /* "device class" */
201 const char *a_devclass; /* device class described */ 207 const char *a_devclass; /* device class described */
 208 struct where a_where;
202}; 209};
203 210
204/* 211/*
205 * List of attributes. 212 * List of attributes.
206 */ 213 */
207struct attrlist { 214struct attrlist {
208 struct attrlist *al_next; 215 struct attrlist *al_next;
209 struct attr *al_this; 216 struct attr *al_this;
210}; 217};
211 218
212/* 219/*
213 * List of locators. (Either definitions or uses...) 220 * List of locators. (Either definitions or uses...)
214 * 221 *
@@ -267,97 +274,92 @@ struct devbase { @@ -267,97 +274,92 @@ struct devbase {
267 TAILQ_ENTRY(devbase) d_next; 274 TAILQ_ENTRY(devbase) d_next;
268 int d_level; 275 int d_level;
269 struct devbase *d_levelparent; 276 struct devbase *d_levelparent;
270 int d_isdef; /* set once properly defined */ 277 int d_isdef; /* set once properly defined */
271 int d_ispseudo; /* is a pseudo-device */ 278 int d_ispseudo; /* is a pseudo-device */
272 devmajor_t d_major; /* used for "root on sd0", e.g. */ 279 devmajor_t d_major; /* used for "root on sd0", e.g. */
273 struct attrlist *d_attrs; /* attributes, if any */ 280 struct attrlist *d_attrs; /* attributes, if any */
274 int d_umax; /* highest unit number + 1 */ 281 int d_umax; /* highest unit number + 1 */
275 struct devi *d_ihead; /* first instance, if any */ 282 struct devi *d_ihead; /* first instance, if any */
276 struct devi **d_ipp; /* used for tacking on more instances */ 283 struct devi **d_ipp; /* used for tacking on more instances */
277 struct deva *d_ahead; /* first attachment, if any */ 284 struct deva *d_ahead; /* first attachment, if any */
278 struct deva **d_app; /* used for tacking on attachments */ 285 struct deva **d_app; /* used for tacking on attachments */
279 struct attr *d_classattr; /* device class attribute (if any) */ 286 struct attr *d_classattr; /* device class attribute (if any) */
280 const char *d_srcfile; /* file name where we are defined */ 287 struct where d_where;
281 u_short d_srcline; /* line number where we are defined */ 
282}; 288};
283 289
284struct deva { 290struct deva {
285 const char *d_name; /* name of attachment, e.g. "com_isa" */ 291 const char *d_name; /* name of attachment, e.g. "com_isa" */
286 TAILQ_ENTRY(deva) d_next; /* list of all instances */ 292 TAILQ_ENTRY(deva) d_next; /* list of all instances */
287 struct deva *d_bsame; /* list on same base */ 293 struct deva *d_bsame; /* list on same base */
288 int d_isdef; /* set once properly defined */ 294 int d_isdef; /* set once properly defined */
289 struct devbase *d_devbase; /* the base device */ 295 struct devbase *d_devbase; /* the base device */
290 struct nvlist *d_atlist; /* e.g., "at tg" (attr list) */ 296 struct nvlist *d_atlist; /* e.g., "at tg" (attr list) */
291 struct attrlist *d_attrs; /* attributes, if any */ 297 struct attrlist *d_attrs; /* attributes, if any */
292 struct devi *d_ihead; /* first instance, if any */ 298 struct devi *d_ihead; /* first instance, if any */
293 struct devi **d_ipp; /* used for tacking on more instances */ 299 struct devi **d_ipp; /* used for tacking on more instances */
294 const char *d_srcfile; /* file name where we are defined */ 300 struct where d_where;
295 u_short d_srcline; /* line number where we are defined */ 
296}; 301};
297 302
298/* 303/*
299 * An "instance" of a device. The same instance may be listed more 304 * An "instance" of a device. The same instance may be listed more
300 * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR". 305 * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
301 * 306 *
302 * After everything has been read in and verified, the devi's are 307 * After everything has been read in and verified, the devi's are
303 * "packed" to collect all the information needed to generate ioconf.c. 308 * "packed" to collect all the information needed to generate ioconf.c.
304 * In particular, we try to collapse multiple aliases into a single entry. 309 * In particular, we try to collapse multiple aliases into a single entry.
305 * We then assign each "primary" (non-collapsed) instance a cfdata index. 310 * We then assign each "primary" (non-collapsed) instance a cfdata index.
306 * Note that there may still be aliases among these. 311 * Note that there may still be aliases among these.
307 */ 312 */
308struct devi { 313struct devi {
309 /* created while parsing config file */ 314 /* created while parsing config file */
310 const char *i_name; /* e.g., "sd0" */ 315 const char *i_name; /* e.g., "sd0" */
311 int i_unit; /* unit from name, e.g., 0 */ 316 int i_unit; /* unit from name, e.g., 0 */
312 struct devbase *i_base;/* e.g., pointer to "sd" base */ 317 struct devbase *i_base;/* e.g., pointer to "sd" base */
313 TAILQ_ENTRY(devi) i_next; /* list of all instances */ 318 TAILQ_ENTRY(devi) i_next; /* list of all instances */
314 struct devi *i_bsame; /* list on same base */ 319 struct devi *i_bsame; /* list on same base */
315 struct devi *i_asame; /* list on same base attachment */ 320 struct devi *i_asame; /* list on same base attachment */
316 struct devi *i_alias; /* other aliases of this instance */ 321 struct devi *i_alias; /* other aliases of this instance */
317 const char *i_at; /* where this is "at" (NULL if at root) */ 322 const char *i_at; /* where this is "at" (NULL if at root) */
318 struct pspec *i_pspec; /* parent spec (NULL if at root) */ 323 struct pspec *i_pspec; /* parent spec (NULL if at root) */
319 struct deva *i_atdeva; 324 struct deva *i_atdeva;
320 const char **i_locs; /* locators (as given by pspec's iattr) */ 325 const char **i_locs; /* locators (as given by pspec's iattr) */
321 int i_cfflags; /* flags from config line */ 326 int i_cfflags; /* flags from config line */
322 int i_lineno; /* line # in config, for later errors */ 
323 const char *i_srcfile; /* file it appears in */ 
324 int i_level; /* position between negated instances */ 327 int i_level; /* position between negated instances */
325 int i_active; 328 int i_active;
326#define DEVI_ORPHAN 0 /* instance has no active parent */ 329#define DEVI_ORPHAN 0 /* instance has no active parent */
327#define DEVI_ACTIVE 1 /* instance has an active parent */ 330#define DEVI_ACTIVE 1 /* instance has an active parent */
328#define DEVI_IGNORED 2 /* instance's parent has been removed */ 331#define DEVI_IGNORED 2 /* instance's parent has been removed */
329#define DEVI_BROKEN 3 /* instance is broken (syntax error) */ 332#define DEVI_BROKEN 3 /* instance is broken (syntax error) */
330 int i_pseudoroot; /* instance is pseudoroot */ 333 int i_pseudoroot; /* instance is pseudoroot */
331 334
332 /* created during packing or ioconf.c generation */ 335 /* created during packing or ioconf.c generation */
333 short i_collapsed; /* set => this alias no longer needed */ 336 short i_collapsed; /* set => this alias no longer needed */
334 u_short i_cfindex; /* our index in cfdata */ 337 u_short i_cfindex; /* our index in cfdata */
335 int i_locoff; /* offset in locators.vec */ 338 int i_locoff; /* offset in locators.vec */
336 339 struct where i_where;
337}; 340};
338/* special units */ 341/* special units */
339#define STAR (-1) /* unit number for, e.g., "sd*" */ 342#define STAR (-1) /* unit number for, e.g., "sd*" */
340#define WILD (-2) /* unit number for, e.g., "sd?" */ 343#define WILD (-2) /* unit number for, e.g., "sd?" */
341 344
342/* 345/*
343 * Files (*.c, *.S, or *.o). This structure defines the common fields 346 * Files (*.c, *.S, or *.o). This structure defines the common fields
344 * between the two. 347 * between the two.
345 */ 348 */
346struct files { 349struct files {
347 TAILQ_ENTRY(files) fi_next; 350 TAILQ_ENTRY(files) fi_next;
348 TAILQ_ENTRY(files) fi_snext; /* per-suffix list */ 351 TAILQ_ENTRY(files) fi_snext; /* per-suffix list */
349 const char *fi_srcfile; /* the name of the "files" file that got us */ 352 struct where fi_where;
350 u_short fi_srcline; /* and the line number */ 
351 u_char fi_flags; /* as below */ 353 u_char fi_flags; /* as below */
352 const char *fi_tail; /* name, i.e., strrchr(fi_path, '/') + 1 */ 354 const char *fi_tail; /* name, i.e., strrchr(fi_path, '/') + 1 */
353 const char *fi_base; /* tail minus ".c" (or whatever) */ 355 const char *fi_base; /* tail minus ".c" (or whatever) */
354 const char *fi_dir; /* path to file */ 356 const char *fi_dir; /* path to file */
355 const char *fi_path; /* full file path */ 357 const char *fi_path; /* full file path */
356 const char *fi_prefix; /* any file prefix */ 358 const char *fi_prefix; /* any file prefix */
357 const char *fi_buildprefix; /* prefix in builddir */ 359 const char *fi_buildprefix; /* prefix in builddir */
358 int fi_suffix; /* single char suffix */ 360 int fi_suffix; /* single char suffix */
359 size_t fi_len; /* path string length */ 361 size_t fi_len; /* path string length */
360 struct condexpr *fi_optx; /* options expression */ 362 struct condexpr *fi_optx; /* options expression */
361 struct nvlist *fi_optf; /* flattened version of above, if needed */ 363 struct nvlist *fi_optf; /* flattened version of above, if needed */
362 const char *fi_mkrule; /* special make rule, if any */ 364 const char *fi_mkrule; /* special make rule, if any */
363 struct attr *fi_attr; /* owner attr */ 365 struct attr *fi_attr; /* owner attr */
@@ -408,33 +410,32 @@ struct condexpr { @@ -408,33 +410,32 @@ struct condexpr {
408struct prefix; 410struct prefix;
409SLIST_HEAD(prefixlist, prefix); 411SLIST_HEAD(prefixlist, prefix);
410 412
411struct prefix { 413struct prefix {
412 SLIST_ENTRY(prefix) pf_next; /* next prefix in stack */ 414 SLIST_ENTRY(prefix) pf_next; /* next prefix in stack */
413 const char *pf_prefix; /* the actual prefix */ 415 const char *pf_prefix; /* the actual prefix */
414}; 416};
415 417
416/* 418/*
417 * Device major informations. 419 * Device major informations.
418 */ 420 */
419struct devm { 421struct devm {
420 TAILQ_ENTRY(devm) dm_next; 422 TAILQ_ENTRY(devm) dm_next;
421 const char *dm_srcfile; /* the name of the "majors" file */ 
422 u_short dm_srcline; /* the line number */ 
423 const char *dm_name; /* [bc]devsw name */ 423 const char *dm_name; /* [bc]devsw name */
424 devmajor_t dm_cmajor; /* character major */ 424 devmajor_t dm_cmajor; /* character major */
425 devmajor_t dm_bmajor; /* block major */ 425 devmajor_t dm_bmajor; /* block major */
426 struct condexpr *dm_opts; /* options */ 426 struct condexpr *dm_opts; /* options */
427 struct nvlist *dm_devnodes; /* information on /dev nodes */ 427 struct nvlist *dm_devnodes; /* information on /dev nodes */
 428 struct where dm_where;
428}; 429};
429 430
430/* 431/*
431 * Hash tables look up name=value pairs. The pointer value of the name 432 * Hash tables look up name=value pairs. The pointer value of the name
432 * is assumed to be constant forever; this can be arranged by interning 433 * is assumed to be constant forever; this can be arranged by interning
433 * the name. (This is fairly convenient since our lexer does this for 434 * the name. (This is fairly convenient since our lexer does this for
434 * all identifier-like strings---it has to save them anyway, lest yacc's 435 * all identifier-like strings---it has to save them anyway, lest yacc's
435 * look-ahead wipe out the current one.) 436 * look-ahead wipe out the current one.)
436 */ 437 */
437struct hashtab; 438struct hashtab;
438 439
439int lkmmode; 440int lkmmode;
440const char *conffile; /* source file, e.g., "GENERIC.sparc" */ 441const char *conffile; /* source file, e.g., "GENERIC.sparc" */
@@ -571,40 +572,40 @@ extern int Sflag; @@ -571,40 +572,40 @@ extern int Sflag;
571void addoption(const char *, const char *); 572void addoption(const char *, const char *);
572void addfsoption(const char *); 573void addfsoption(const char *);
573void addmkoption(const char *, const char *); 574void addmkoption(const char *, const char *);
574void appendmkoption(const char *, const char *); 575void appendmkoption(const char *, const char *);
575void appendcondmkoption(struct condexpr *, const char *, const char *); 576void appendcondmkoption(struct condexpr *, const char *, const char *);
576void deffilesystem(struct nvlist *, struct nvlist *); 577void deffilesystem(struct nvlist *, struct nvlist *);
577void defoption(const char *, struct defoptlist *, struct nvlist *); 578void defoption(const char *, struct defoptlist *, struct nvlist *);
578void defflag(const char *, struct defoptlist *, struct nvlist *, int); 579void defflag(const char *, struct defoptlist *, struct nvlist *, int);
579void defparam(const char *, struct defoptlist *, struct nvlist *, int); 580void defparam(const char *, struct defoptlist *, struct nvlist *, int);
580void deloption(const char *, int); 581void deloption(const char *, int);
581void delfsoption(const char *, int); 582void delfsoption(const char *, int);
582void delmkoption(const char *, int); 583void delmkoption(const char *, int);
583int devbase_has_instances(struct devbase *, int); 584int devbase_has_instances(struct devbase *, int);
584int is_declared_option(const char *); 585struct where *find_declared_option(const char *);
585int deva_has_instances(struct deva *, int); 586int deva_has_instances(struct deva *, int);
586void setupdirs(void); 587void setupdirs(void);
587void fixmaxusers(void); 588void fixmaxusers(void);
588void fixmkoption(void); 589void fixmkoption(void);
589const char *strtolower(const char *); 590const char *strtolower(const char *);
590 591
591/* tests on option types */ 592/* tests on option types */
592#define OPT_FSOPT(n) (nvhash_lookup(deffstab, (n)) != NULL) 593#define OPT_FSOPT(n) (nvhash_lookup(deffstab, (n)) != NULL)
593#define OPT_DEFOPT(n) (dlhash_lookup(defopttab, (n)) != NULL) 594#define OPT_DEFOPT(n) (dlhash_lookup(defopttab, (n)) != NULL)
594#define OPT_DEFFLAG(n) (dlhash_lookup(defflagtab, (n)) != NULL) 595#define OPT_DEFFLAG(n) (dlhash_lookup(defflagtab, (n)) != NULL)
595#define OPT_DEFPARAM(n) (dlhash_lookup(defparamtab, (n)) != NULL) 596#define OPT_DEFPARAM(n) (dlhash_lookup(defparamtab, (n)) != NULL)
596#define OPT_OBSOLETE(n) (dlhash_lookup(obsopttab, (n)) != NULL) 597#define OPT_OBSOLETE(n) (dlhash_lookup(obsopttab, (n)) != NULL)
597#define DEFINED_OPTION(n) (is_declared_option((n))) 598#define DEFINED_OPTION(n) (find_declared_option((n)))
598 599
599/* main.c */ 600/* main.c */
600void logconfig_include(FILE *, const char *); 601void logconfig_include(FILE *, const char *);
601 602
602/* mkdevsw.c */ 603/* mkdevsw.c */
603int mkdevsw(void); 604int mkdevsw(void);
604 605
605/* mkheaders.c */ 606/* mkheaders.c */
606int mkheaders(void); 607int mkheaders(void);
607int moveifchanged(const char *, const char *); 608int moveifchanged(const char *, const char *);
608int emitlocs(void); 609int emitlocs(void);
609int emitioconfh(void); 610int emitioconfh(void);
610 611

cvs diff -r1.36 -r1.36.16.1 src/usr.bin/config/files.c (expand / switch to unified diff)

--- src/usr.bin/config/files.c 2016/09/09 21:09:11 1.36
+++ src/usr.bin/config/files.c 2020/03/09 15:22:21 1.36.16.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: files.c,v 1.36 2016/09/09 21:09:11 christos Exp $ */ 1/* $NetBSD: files.c,v 1.36.16.1 2020/03/09 15:22:21 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -35,27 +35,27 @@ @@ -35,27 +35,27 @@
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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 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 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * from: @(#)files.c 8.1 (Berkeley) 6/6/93 40 * from: @(#)files.c 8.1 (Berkeley) 6/6/93
41 */ 41 */
42 42
43#if HAVE_NBTOOL_CONFIG_H 43#if HAVE_NBTOOL_CONFIG_H
44#include "nbtool_config.h" 44#include "nbtool_config.h"
45#endif 45#endif
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__RCSID("$NetBSD: files.c,v 1.36 2016/09/09 21:09:11 christos Exp $"); 48__RCSID("$NetBSD: files.c,v 1.36.16.1 2020/03/09 15:22:21 martin Exp $");
49 49
50#include <sys/param.h> 50#include <sys/param.h>
51#include <assert.h> 51#include <assert.h>
52#include <errno.h> 52#include <errno.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <string.h> 55#include <string.h>
56#include <util.h> 56#include <util.h>
57#include "defs.h" 57#include "defs.h"
58 58
59extern const char *yyfile; 59extern const char *yyfile;
60 60
61int nallfiles; 61int nallfiles;
@@ -148,39 +148,39 @@ addfile(const char *path, struct condexp @@ -148,39 +148,39 @@ addfile(const char *path, struct condexp
148 free(fi); 148 free(fi);
149 if ((fi = ht_lookup(pathtab, path)) == NULL) 149 if ((fi = ht_lookup(pathtab, path)) == NULL)
150 panic("addfile: ht_lookup(%s)", path); 150 panic("addfile: ht_lookup(%s)", path);
151 151
152 /* 152 /*
153 * If it's a duplicate entry, it is must specify a make 153 * If it's a duplicate entry, it is must specify a make
154 * rule, and only a make rule, and must come from 154 * rule, and only a make rule, and must come from
155 * a different source file than the original entry. 155 * a different source file than the original entry.
156 * If it does otherwise, it is disallowed. This allows 156 * If it does otherwise, it is disallowed. This allows
157 * machine-dependent files to override the compilation 157 * machine-dependent files to override the compilation
158 * options for specific files. 158 * options for specific files.
159 */ 159 */
160 if (rule != NULL && optx == NULL && flags == 0 && 160 if (rule != NULL && optx == NULL && flags == 0 &&
161 yyfile != fi->fi_srcfile) { 161 yyfile != fi->fi_where.w_srcfile) {
162 fi->fi_mkrule = rule; 162 fi->fi_mkrule = rule;
163 return; 163 return;
164 } 164 }
165 cfgerror("duplicate file %s", path); 165 cfgerror("duplicate file %s", path);
166 cfgxerror(fi->fi_srcfile, fi->fi_srcline, 166 cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
167 "here is the original definition"); 167 "here is the original definition");
168 goto bad; 168 goto bad;
169 } 169 }
170 memcpy(base, tail, baselen); 170 memcpy(base, tail, baselen);
171 base[baselen] = '\0'; 171 base[baselen] = '\0';
172 fi->fi_srcfile = yyfile; 172 fi->fi_where.w_srcfile = yyfile;
173 fi->fi_srcline = currentline(); 173 fi->fi_where.w_srcline = currentline();
174 fi->fi_flags = flags; 174 fi->fi_flags = flags;
175 fi->fi_path = path; 175 fi->fi_path = path;
176 fi->fi_tail = tail; 176 fi->fi_tail = tail;
177 fi->fi_base = intern(base); 177 fi->fi_base = intern(base);
178 fi->fi_dir = intern(dir); 178 fi->fi_dir = intern(dir);
179 fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL : 179 fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
180 SLIST_FIRST(&prefixes)->pf_prefix; 180 SLIST_FIRST(&prefixes)->pf_prefix;
181 fi->fi_buildprefix = SLIST_EMPTY(&buildprefixes) ? NULL : 181 fi->fi_buildprefix = SLIST_EMPTY(&buildprefixes) ? NULL :
182 SLIST_FIRST(&buildprefixes)->pf_prefix; 182 SLIST_FIRST(&buildprefixes)->pf_prefix;
183 fi->fi_len = strlen(path); 183 fi->fi_len = strlen(path);
184 fi->fi_suffix = path[fi->fi_len - 1]; 184 fi->fi_suffix = path[fi->fi_len - 1];
185 fi->fi_optx = optx; 185 fi->fi_optx = optx;
186 fi->fi_optf = NULL; 186 fi->fi_optf = NULL;
@@ -194,27 +194,27 @@ addfile(const char *path, struct condexp @@ -194,27 +194,27 @@ addfile(const char *path, struct condexp
194 break; 194 break;
195 case 'S': 195 case 'S':
196 fi->fi_suffix = 's'; 196 fi->fi_suffix = 's';
197 /* FALLTHRU */ 197 /* FALLTHRU */
198 case 's': 198 case 's':
199 TAILQ_INSERT_TAIL(&allsfiles, fi, fi_snext); 199 TAILQ_INSERT_TAIL(&allsfiles, fi, fi_snext);
200 TAILQ_INSERT_TAIL(&allfiles, fi, fi_next); 200 TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
201 break; 201 break;
202 case 'o': 202 case 'o':
203 TAILQ_INSERT_TAIL(&allofiles, fi, fi_snext); 203 TAILQ_INSERT_TAIL(&allofiles, fi, fi_snext);
204 TAILQ_INSERT_TAIL(&allfiles, fi, fi_next); 204 TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
205 break; 205 break;
206 default: 206 default:
207 cfgxerror(fi->fi_srcfile, fi->fi_srcline, 207 cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
208 "unknown suffix"); 208 "unknown suffix");
209 break; 209 break;
210 } 210 }
211 CFGDBG(3, "file added `%s' at order score %d", fi->fi_path, fi->fi_order); 211 CFGDBG(3, "file added `%s' at order score %d", fi->fi_path, fi->fi_order);
212 nallfiles++; 212 nallfiles++;
213 return; 213 return;
214 bad: 214 bad:
215 if (optx != NULL) { 215 if (optx != NULL) {
216 condexpr_destroy(optx); 216 condexpr_destroy(optx);
217 } 217 }
218} 218}
219 219
220static void 220static void
@@ -252,27 +252,27 @@ checkfiles(void) @@ -252,27 +252,27 @@ checkfiles(void)
252 unchecked = &TAILQ_NEXT(last, fi_next); 252 unchecked = &TAILQ_NEXT(last, fi_next);
253} 253}
254 254
255/* 255/*
256 * Auxiliary function for checkfiles, called from expr_eval. 256 * Auxiliary function for checkfiles, called from expr_eval.
257 * We are not actually interested in the expression's value. 257 * We are not actually interested in the expression's value.
258 */ 258 */
259static int 259static int
260checkaux(const char *name, void *context) 260checkaux(const char *name, void *context)
261{ 261{
262 struct files *fi = context; 262 struct files *fi = context;
263 263
264 if (ht_lookup(devbasetab, name) == NULL) { 264 if (ht_lookup(devbasetab, name) == NULL) {
265 cfgxerror(fi->fi_srcfile, fi->fi_srcline, 265 cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
266 "`%s' is not a countable device", 266 "`%s' is not a countable device",
267 name); 267 name);
268 /* keep fixfiles() from complaining again */ 268 /* keep fixfiles() from complaining again */
269 fi->fi_flags |= FI_HIDDEN; 269 fi->fi_flags |= FI_HIDDEN;
270 } 270 }
271 return (0); 271 return (0);
272} 272}
273 273
274static int 274static int
275cmpfiles(const void *a, const void *b) 275cmpfiles(const void *a, const void *b)
276{ 276{
277 const struct files * const *fia = a, * const *fib = b; 277 const struct files * const *fia = a, * const *fib = b;
278 int sa = (*fia)->fi_order; 278 int sa = (*fia)->fi_order;
@@ -346,30 +346,30 @@ fixfiles(void) @@ -346,30 +346,30 @@ fixfiles(void)
346 if ((ofi = ht_lookup(basetab, fi->fi_base)) == NULL) 346 if ((ofi = ht_lookup(basetab, fi->fi_base)) == NULL)
347 panic("fixfiles ht_lookup(%s)", fi->fi_base); 347 panic("fixfiles ht_lookup(%s)", fi->fi_base);
348 /* 348 /*
349 * If the new file comes from a different source, 349 * If the new file comes from a different source,
350 * allow the new one to override the old one. 350 * allow the new one to override the old one.
351 */ 351 */
352 if (fi->fi_path != ofi->fi_path) { 352 if (fi->fi_path != ofi->fi_path) {
353 if (ht_replace(basetab, fi->fi_base, fi) != 1) 353 if (ht_replace(basetab, fi->fi_base, fi) != 1)
354 panic("fixfiles ht_replace(%s)", 354 panic("fixfiles ht_replace(%s)",
355 fi->fi_base); 355 fi->fi_base);
356 ofi->fi_flags &= (u_char)~FI_SEL; 356 ofi->fi_flags &= (u_char)~FI_SEL;
357 ofi->fi_flags |= FI_HIDDEN; 357 ofi->fi_flags |= FI_HIDDEN;
358 } else { 358 } else {
359 cfgxerror(fi->fi_srcfile, fi->fi_srcline, 359 cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
360 "object file collision on %s.o, from %s", 360 "object file collision on %s.o, from %s",
361 fi->fi_base, fi->fi_path); 361 fi->fi_base, fi->fi_path);
362 cfgxerror(ofi->fi_srcfile, ofi->fi_srcline, 362 cfgxerror(ofi->fi_where.w_srcfile, ofi->fi_where.w_srcline,
363 "here is the previous file: %s", 363 "here is the previous file: %s",
364 ofi->fi_path); 364 ofi->fi_path);
365 err = 1; 365 err = 1;
366 } 366 }
367 } 367 }
368 fi->fi_flags |= FI_SEL; 368 fi->fi_flags |= FI_SEL;
369 nselfiles++; 369 nselfiles++;
370 CFGDBG(3, "file selected `%s'", fi->fi_path); 370 CFGDBG(3, "file selected `%s'", fi->fi_path);
371 371
372 /* Add other files to the default "netbsd" attribute. */ 372 /* Add other files to the default "netbsd" attribute. */
373 if (fi->fi_attr == NULL) { 373 if (fi->fi_attr == NULL) {
374 addfiletoattr(allattr.a_name, fi); 374 addfiletoattr(allattr.a_name, fi);
375 } 375 }
@@ -402,88 +402,92 @@ fixdevsw(void) @@ -402,88 +402,92 @@ fixdevsw(void)
402 int error; 402 int error;
403 struct devm *dm, *res; 403 struct devm *dm, *res;
404 struct hashtab *fixdevmtab; 404 struct hashtab *fixdevmtab;
405 char mstr[16]; 405 char mstr[16];
406 406
407 error = 0; 407 error = 0;
408 fixdevmtab = ht_new(); 408 fixdevmtab = ht_new();
409 409
410 TAILQ_FOREACH(dm, &alldevms, dm_next) { 410 TAILQ_FOREACH(dm, &alldevms, dm_next) {
411 res = ht_lookup(fixdevmtab, intern(dm->dm_name)); 411 res = ht_lookup(fixdevmtab, intern(dm->dm_name));
412 if (res != NULL) { 412 if (res != NULL) {
413 if (res->dm_cmajor != dm->dm_cmajor || 413 if (res->dm_cmajor != dm->dm_cmajor ||
414 res->dm_bmajor != dm->dm_bmajor) { 414 res->dm_bmajor != dm->dm_bmajor) {
415 cfgxerror(res->dm_srcfile, res->dm_srcline, 415 cfgxerror(res->dm_where.w_srcfile,
416 "device-major '%s' " 416 res->dm_where.w_srcline,
417 "block %d, char %d redefined" 417 "device-major '%s' "
418 " at %s:%d as block %d, char %d", 418 "block %d, char %d redefined"
419 res->dm_name, 419 " at %s:%d as block %d, char %d",
420 res->dm_bmajor, res->dm_cmajor, 420 res->dm_name,
421 dm->dm_srcfile, dm->dm_srcline, 421 res->dm_bmajor, res->dm_cmajor,
422 dm->dm_bmajor, dm->dm_cmajor); 422 dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
 423 dm->dm_bmajor, dm->dm_cmajor);
423 } else { 424 } else {
424 cfgxerror(res->dm_srcfile, res->dm_srcline, 425 cfgxerror(res->dm_where.w_srcfile,
425 "device-major '%s' " 426 res->dm_where.w_srcline,
426 "(block %d, char %d) duplicated" 427 "device-major '%s' "
427 " at %s:%d", 428 "(block %d, char %d) duplicated"
428 dm->dm_name, dm->dm_bmajor, 429 " at %s:%d",
429 dm->dm_cmajor, 430 dm->dm_name, dm->dm_bmajor,
430 dm->dm_srcfile, dm->dm_srcline); 431 dm->dm_cmajor,
 432 dm->dm_where.w_srcfile,
 433 dm->dm_where.w_srcline);
431 } 434 }
432 error = 1; 435 error = 1;
433 goto out; 436 goto out;
434 } 437 }
435 if (ht_insert(fixdevmtab, intern(dm->dm_name), dm)) { 438 if (ht_insert(fixdevmtab, intern(dm->dm_name), dm)) {
436 panic("fixdevsw: %s char %d block %d", 439 panic("fixdevsw: %s char %d block %d",
437 dm->dm_name, dm->dm_cmajor, dm->dm_bmajor); 440 dm->dm_name, dm->dm_cmajor, dm->dm_bmajor);
438 } 441 }
439 442
440 if (dm->dm_opts != NULL && 443 if (dm->dm_opts != NULL &&
441 !expr_eval(dm->dm_opts, fixsel, NULL)) 444 !expr_eval(dm->dm_opts, fixsel, NULL))
442 continue; 445 continue;
443 446
444 if (dm->dm_cmajor != NODEVMAJOR) { 447 if (dm->dm_cmajor != NODEVMAJOR) {
445 if (ht_lookup(cdevmtab, intern(dm->dm_name)) != NULL) { 448 if (ht_lookup(cdevmtab, intern(dm->dm_name)) != NULL) {
446 cfgxerror(dm->dm_srcfile, dm->dm_srcline, 449 cfgxerror(dm->dm_where.w_srcfile,
447 "device-major of character device '%s' " 450 dm->dm_where.w_srcline,
448 "is already defined", dm->dm_name); 451 "device-major of character device '%s' "
 452 "is already defined", dm->dm_name);
449 error = 1; 453 error = 1;
450 goto out; 454 goto out;
451 } 455 }
452 (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_cmajor); 456 (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_cmajor);
453 if (ht_lookup(cdevmtab, intern(mstr)) != NULL) { 457 if (ht_lookup(cdevmtab, intern(mstr)) != NULL) {
454 cfgxerror(dm->dm_srcfile, dm->dm_srcline, 458 cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
455 "device-major of character major '%d' " 459 "device-major of character major '%d' "
456 "is already defined", dm->dm_cmajor); 460 "is already defined", dm->dm_cmajor);
457 error = 1; 461 error = 1;
458 goto out; 462 goto out;
459 } 463 }
460 if (ht_insert(cdevmtab, intern(dm->dm_name), dm) || 464 if (ht_insert(cdevmtab, intern(dm->dm_name), dm) ||
461 ht_insert(cdevmtab, intern(mstr), dm)) { 465 ht_insert(cdevmtab, intern(mstr), dm)) {
462 panic("fixdevsw: %s character major %d", 466 panic("fixdevsw: %s character major %d",
463 dm->dm_name, dm->dm_cmajor); 467 dm->dm_name, dm->dm_cmajor);
464 } 468 }
465 } 469 }
466 if (dm->dm_bmajor != NODEVMAJOR) { 470 if (dm->dm_bmajor != NODEVMAJOR) {
467 if (ht_lookup(bdevmtab, intern(dm->dm_name)) != NULL) { 471 if (ht_lookup(bdevmtab, intern(dm->dm_name)) != NULL) {
468 cfgxerror(dm->dm_srcfile, dm->dm_srcline, 472 cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
469 "device-major of block device '%s' " 473 "device-major of block device '%s' "
470 "is already defined", dm->dm_name); 474 "is already defined", dm->dm_name);
471 error = 1; 475 error = 1;
472 goto out; 476 goto out;
473 } 477 }
474 (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_bmajor); 478 (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_bmajor);
475 if (ht_lookup(bdevmtab, intern(mstr)) != NULL) { 479 if (ht_lookup(bdevmtab, intern(mstr)) != NULL) {
476 cfgxerror(dm->dm_srcfile, dm->dm_srcline, 480 cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
477 "device-major of block major '%d' " 481 "device-major of block major '%d' "
478 "is already defined", dm->dm_bmajor); 482 "is already defined", dm->dm_bmajor);
479 error = 1; 483 error = 1;
480 goto out; 484 goto out;
481 } 485 }
482 if (ht_insert(bdevmtab, intern(dm->dm_name), dm) ||  486 if (ht_insert(bdevmtab, intern(dm->dm_name), dm) ||
483 ht_insert(bdevmtab, intern(mstr), dm)) { 487 ht_insert(bdevmtab, intern(mstr), dm)) {
484 panic("fixdevsw: %s block major %d", 488 panic("fixdevsw: %s block major %d",
485 dm->dm_name, dm->dm_bmajor); 489 dm->dm_name, dm->dm_bmajor);
486 } 490 }
487 } 491 }
488 } 492 }
489 493

cvs diff -r1.54 -r1.54.16.1 src/usr.bin/config/gram.y (expand / switch to unified diff)

--- src/usr.bin/config/gram.y 2016/08/07 10:37:24 1.54
+++ src/usr.bin/config/gram.y 2020/03/09 15:22:21 1.54.16.1
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: gram.y,v 1.54 2016/08/07 10:37:24 christos Exp $ */ 2/* $NetBSD: gram.y,v 1.54.16.1 2020/03/09 15:22:21 martin 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: @(#)gram.y 8.1 (Berkeley) 6/6/93 41 * from: @(#)gram.y 8.1 (Berkeley) 6/6/93
42 */ 42 */
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45__RCSID("$NetBSD: gram.y,v 1.54 2016/08/07 10:37:24 christos Exp $"); 45__RCSID("$NetBSD: gram.y,v 1.54.16.1 2020/03/09 15:22:21 martin Exp $");
46 46
47#include <sys/types.h> 47#include <sys/types.h>
48#include <sys/param.h> 48#include <sys/param.h>
49#include <ctype.h> 49#include <ctype.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 <errno.h> 53#include <errno.h>
54#include "defs.h" 54#include "defs.h"
55#include "sem.h" 55#include "sem.h"
56 56
57#define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \ 57#define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
58 ((n).fmt == 16) ? "0x%llx" : "%lld") 58 ((n).fmt == 16) ? "0x%llx" : "%lld")
@@ -888,27 +888,27 @@ no_opt_list: @@ -888,27 +888,27 @@ no_opt_list:
888 no_option 888 no_option
889 | no_opt_list ',' no_option 889 | no_opt_list ',' no_option
890; 890;
891 891
892/* one option that had NO in front */ 892/* one option that had NO in front */
893no_option: 893no_option:
894 WORD { deloption($1, nowarn); } 894 WORD { deloption($1, nowarn); }
895; 895;
896 896
897/* the name in "config name root on ..." */ 897/* the name in "config name root on ..." */
898conf: 898conf:
899 WORD { 899 WORD {
900 conf.cf_name = $1; 900 conf.cf_name = $1;
901 conf.cf_lineno = currentline(); 901 conf.cf_where.w_srcline = currentline();
902 conf.cf_fstype = NULL; 902 conf.cf_fstype = NULL;
903 conf.cf_root = NULL; 903 conf.cf_root = NULL;
904 conf.cf_dump = NULL; 904 conf.cf_dump = NULL;
905 } 905 }
906; 906;
907 907
908/* root fs specification */ 908/* root fs specification */
909root_spec: 909root_spec:
910 ROOT on_opt dev_spec { setconf(&conf.cf_root, "root", $3); } 910 ROOT on_opt dev_spec { setconf(&conf.cf_root, "root", $3); }
911 | ROOT on_opt dev_spec fs_spec { setconf(&conf.cf_root, "root", $3); } 911 | ROOT on_opt dev_spec fs_spec { setconf(&conf.cf_root, "root", $3); }
912; 912;
913 913
914/* device for root fs or dump */ 914/* device for root fs or dump */

cvs diff -r1.98 -r1.98.2.1 src/usr.bin/config/main.c (expand / switch to unified diff)

--- src/usr.bin/config/main.c 2018/12/24 02:07:44 1.98
+++ src/usr.bin/config/main.c 2020/03/09 15:22:21 1.98.2.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.98 2018/12/24 02:07:44 christos Exp $ */ 1/* $NetBSD: main.c,v 1.98.2.1 2020/03/09 15:22:21 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -35,27 +35,27 @@ @@ -35,27 +35,27 @@
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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 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 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * from: @(#)main.c 8.1 (Berkeley) 6/6/93 40 * from: @(#)main.c 8.1 (Berkeley) 6/6/93
41 */ 41 */
42 42
43#if HAVE_NBTOOL_CONFIG_H 43#if HAVE_NBTOOL_CONFIG_H
44#include "nbtool_config.h" 44#include "nbtool_config.h"
45#endif 45#endif
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__RCSID("$NetBSD: main.c,v 1.98 2018/12/24 02:07:44 christos Exp $"); 48__RCSID("$NetBSD: main.c,v 1.98.2.1 2020/03/09 15:22:21 martin Exp $");
49 49
50#ifndef MAKE_BOOTSTRAP 50#ifndef MAKE_BOOTSTRAP
51#include <sys/cdefs.h> 51#include <sys/cdefs.h>
52#define COPYRIGHT(x) __COPYRIGHT(x) 52#define COPYRIGHT(x) __COPYRIGHT(x)
53#else 53#else
54#define COPYRIGHT(x) static const char copyright[] = x 54#define COPYRIGHT(x) static const char copyright[] = x
55#endif 55#endif
56 56
57#ifndef lint 57#ifndef lint
58COPYRIGHT("@(#) Copyright (c) 1992, 1993\ 58COPYRIGHT("@(#) Copyright (c) 1992, 1993\
59 The Regents of the University of California. All rights reserved."); 59 The Regents of the University of California. All rights reserved.");
60#endif /* not lint */ 60#endif /* not lint */
61 61
@@ -746,27 +746,27 @@ check_dependencies(const char *thing, st @@ -746,27 +746,27 @@ check_dependencies(const char *thing, st
746 /* 746 /*
747 * If the dependency is an attribute, it must not 747 * If the dependency is an attribute, it must not
748 * be an interface attribute. Otherwise, it must 748 * be an interface attribute. Otherwise, it must
749 * be a previously declared option. 749 * be a previously declared option.
750 */ 750 */
751 if ((a = ht_lookup(attrtab, dep->nv_name)) != NULL) { 751 if ((a = ht_lookup(attrtab, dep->nv_name)) != NULL) {
752 if (a->a_iattr) 752 if (a->a_iattr)
753 cfgerror("option `%s' dependency `%s' " 753 cfgerror("option `%s' dependency `%s' "
754 "is an interface attribute", 754 "is an interface attribute",
755 thing, a->a_name); 755 thing, a->a_name);
756 } else if (OPT_OBSOLETE(dep->nv_name)) { 756 } else if (OPT_OBSOLETE(dep->nv_name)) {
757 cfgerror("option `%s' dependency `%s' " 757 cfgerror("option `%s' dependency `%s' "
758 "is obsolete", thing, dep->nv_name); 758 "is obsolete", thing, dep->nv_name);
759 } else if (!is_declared_option(dep->nv_name)) { 759 } else if (!find_declared_option(dep->nv_name)) {
760 cfgerror("option `%s' dependency `%s' " 760 cfgerror("option `%s' dependency `%s' "
761 "is an unknown option", 761 "is an unknown option",
762 thing, dep->nv_name); 762 thing, dep->nv_name);
763 } 763 }
764 } 764 }
765} 765}
766 766
767static void 767static void
768add_fs_dependencies(struct nvlist *nv, struct nvlist *deps) 768add_fs_dependencies(struct nvlist *nv, struct nvlist *deps)
769{ 769{
770 /* Use nv_ptr to link any other options that are implied. */ 770 /* Use nv_ptr to link any other options that are implied. */
771 nv->nv_ptr = deps; 771 nv->nv_ptr = deps;
772 check_dependencies(nv->nv_name, deps); 772 check_dependencies(nv->nv_name, deps);
@@ -776,34 +776,36 @@ static void @@ -776,34 +776,36 @@ static void
776add_opt_dependencies(struct defoptlist *dl, struct nvlist *deps) 776add_opt_dependencies(struct defoptlist *dl, struct nvlist *deps)
777{ 777{
778 dl->dl_depends = deps; 778 dl->dl_depends = deps;
779 check_dependencies(dl->dl_name, deps); 779 check_dependencies(dl->dl_name, deps);
780} 780}
781 781
782/* 782/*
783 * Define one or more file systems. 783 * Define one or more file systems.
784 */ 784 */
785void 785void
786deffilesystem(struct nvlist *fses, struct nvlist *deps) 786deffilesystem(struct nvlist *fses, struct nvlist *deps)
787{ 787{
788 struct nvlist *nv; 788 struct nvlist *nv;
 789 struct where *w;
789 790
790 /* 791 /*
791 * Mark these options as ones to skip when creating the Makefile. 792 * Mark these options as ones to skip when creating the Makefile.
792 */ 793 */
793 for (nv = fses; nv != NULL; nv = nv->nv_next) { 794 for (nv = fses; nv != NULL; nv = nv->nv_next) {
794 if (DEFINED_OPTION(nv->nv_name)) { 795 if ((w = DEFINED_OPTION(nv->nv_name)) != NULL) {
795 cfgerror("file system or option `%s' already defined", 796 cfgerror("file system or option `%s' already defined"
796 nv->nv_name); 797 " at %s:%hu", nv->nv_name, w->w_srcfile,
 798 w->w_srcline);
797 return; 799 return;
798 } 800 }
799 801
800 /* 802 /*
801 * Also mark it as a valid file system, which may be 803 * Also mark it as a valid file system, which may be
802 * used in "file-system" directives in the config 804 * used in "file-system" directives in the config
803 * file. 805 * file.
804 */ 806 */
805 if (nvhash_insert(deffstab, nv->nv_name, nv)) 807 if (nvhash_insert(deffstab, nv->nv_name, nv))
806 panic("file system `%s' already in table?!", 808 panic("file system `%s' already in table?!",
807 nv->nv_name); 809 nv->nv_name);
808 810
809 add_fs_dependencies(nv, deps); 811 add_fs_dependencies(nv, deps);
@@ -868,87 +870,90 @@ find_declared_fs_option(const char *name @@ -868,87 +870,90 @@ find_declared_fs_option(const char *name
868 struct nvlist *fs; 870 struct nvlist *fs;
869 871
870 if ((fs = nvhash_lookup(deffstab, name)) != NULL) { 872 if ((fs = nvhash_lookup(deffstab, name)) != NULL) {
871 return fs; 873 return fs;
872 } 874 }
873 875
874 return (NULL); 876 return (NULL);
875} 877}
876 878
877/* 879/*
878 * Like find_declared_option but doesn't return what it finds, so it 880 * Like find_declared_option but doesn't return what it finds, so it
879 * can search both the various kinds of options and also filesystems. 881 * can search both the various kinds of options and also filesystems.
880 */ 882 */
881int 883struct where *
882is_declared_option(const char *name) 884find_declared_option(const char *name)
883{ 885{
884 struct defoptlist *option = NULL; 886 struct defoptlist *option = NULL;
885 struct nvlist *fs; 887 struct nvlist *fs;
886 888
887 if ((option = dlhash_lookup(defopttab, name)) != NULL || 889 if ((option = dlhash_lookup(defopttab, name)) != NULL ||
888 (option = dlhash_lookup(defparamtab, name)) != NULL || 890 (option = dlhash_lookup(defparamtab, name)) != NULL ||
889 (option = dlhash_lookup(defflagtab, name)) != NULL) { 891 (option = dlhash_lookup(defflagtab, name)) != NULL) {
890 return 1; 892 return &option->dl_where;
891 } 893 }
892 if ((fs = nvhash_lookup(deffstab, name)) != NULL) { 894 if ((fs = nvhash_lookup(deffstab, name)) != NULL) {
893 return 1; 895 return &fs->nv_where;
894 } 896 }
895 897
896 return 0; 898 return NULL;
897} 899}
898 900
899/* 901/*
900 * Define one or more standard options. If an option file name is specified, 902 * Define one or more standard options. If an option file name is specified,
901 * place all options in one file with the specified name. Otherwise, create 903 * place all options in one file with the specified name. Otherwise, create
902 * an option file for each option. 904 * an option file for each option.
903 * record the option information in the specified table. 905 * record the option information in the specified table.
904 */ 906 */
905void 907void
906defopt(struct dlhash *ht, const char *fname, struct defoptlist *opts, 908defopt(struct dlhash *ht, const char *fname, struct defoptlist *opts,
907 struct nvlist *deps, int obs) 909 struct nvlist *deps, int obs)
908{ 910{
909 struct defoptlist *dl, *nextdl, *olddl; 911 struct defoptlist *dl, *nextdl, *olddl;
910 const char *name; 912 const char *name;
 913 struct where *w;
911 char buf[500]; 914 char buf[500];
912 915
913 if (fname != NULL && badfilename(fname)) { 916 if (fname != NULL && badfilename(fname)) {
914 return; 917 return;
915 } 918 }
916 919
917 /* 920 /*
918 * Mark these options as ones to skip when creating the Makefile. 921 * Mark these options as ones to skip when creating the Makefile.
919 */ 922 */
920 for (dl = opts; dl != NULL; dl = nextdl) { 923 for (dl = opts; dl != NULL; dl = nextdl) {
921 nextdl = dl->dl_next; 924 nextdl = dl->dl_next;
922 925
923 if (dl->dl_lintvalue != NULL) { 926 if (dl->dl_lintvalue != NULL) {
924 /* 927 /*
925 * If an entry already exists, then we are about to 928 * If an entry already exists, then we are about to
926 * complain, so no worry. 929 * complain, so no worry.
927 */ 930 */
928 (void) dlhash_insert(defoptlint, dl->dl_name, 931 (void) dlhash_insert(defoptlint, dl->dl_name,
929 dl); 932 dl);
930 } 933 }
931 934
932 /* An option name can be declared at most once. */ 935 /* An option name can be declared at most once. */
933 if (DEFINED_OPTION(dl->dl_name)) { 936 if ((w = DEFINED_OPTION(dl->dl_name)) != NULL) {
934 cfgerror("file system or option `%s' already defined", 937 cfgerror("file system or option `%s' already defined"
935 dl->dl_name); 938 " at %s:%hu", dl->dl_name, w->w_srcfile,
 939 w->w_srcline);
936 return; 940 return;
937 } 941 }
938 942
939 if (dlhash_insert(ht, dl->dl_name, dl)) { 943 if (dlhash_insert(ht, dl->dl_name, dl)) {
940 cfgerror("file system or option `%s' already defined", 944 cfgerror("file system or option `%s' already defined"
941 dl->dl_name); 945 " at %s:%hu", dl->dl_name, dl->dl_where.w_srcfile,
 946 dl->dl_where.w_srcline);
942 return; 947 return;
943 } 948 }
944 949
945 if (fname == NULL) { 950 if (fname == NULL) {
946 /* 951 /*
947 * Each option will be going into its own file. 952 * Each option will be going into its own file.
948 * Convert the option name to lower case. This 953 * Convert the option name to lower case. This
949 * lower case name will be used as the option 954 * lower case name will be used as the option
950 * file name. 955 * file name.
951 */ 956 */
952 (void) snprintf(buf, sizeof(buf), "opt_%s.h", 957 (void) snprintf(buf, sizeof(buf), "opt_%s.h",
953 strtolower(dl->dl_name)); 958 strtolower(dl->dl_name));
954 name = intern(buf); 959 name = intern(buf);
@@ -1369,28 +1374,28 @@ cfcrosscheck(struct config *cf, const ch @@ -1369,28 +1374,28 @@ cfcrosscheck(struct config *cf, const ch
1369 else 1374 else
1370 devunit = (int)(minor(nv->nv_num) / maxpartitions); 1375 devunit = (int)(minor(nv->nv_num) / maxpartitions);
1371 if (devbase_has_instances(dev, devunit)) 1376 if (devbase_has_instances(dev, devunit))
1372 continue; 1377 continue;
1373 if (devbase_has_instances(dev, STAR) && 1378 if (devbase_has_instances(dev, STAR) &&
1374 devunit >= dev->d_umax) 1379 devunit >= dev->d_umax)
1375 continue; 1380 continue;
1376 TAILQ_FOREACH(pd, &allpseudo, i_next) { 1381 TAILQ_FOREACH(pd, &allpseudo, i_next) {
1377 if (pd->i_base == dev && devunit < dev->d_umax && 1382 if (pd->i_base == dev && devunit < dev->d_umax &&
1378 devunit >= 0) 1383 devunit >= 0)
1379 goto loop; 1384 goto loop;
1380 } 1385 }
1381 (void)fprintf(stderr, 1386 (void)fprintf(stderr,
1382 "%s:%d: %s says %s on %s, but there's no %s\n", 1387 "%s:%hu: %s says %s on %s, but there's no %s\n",
1383 conffile, cf->cf_lineno, 1388 conffile, cf->cf_where.w_srcline,
1384 cf->cf_name, what, nv->nv_str, nv->nv_str); 1389 cf->cf_name, what, nv->nv_str, nv->nv_str);
1385 errs++; 1390 errs++;
1386 loop: 1391 loop:
1387 ; 1392 ;
1388 } 1393 }
1389 return (errs); 1394 return (errs);
1390} 1395}
1391 1396
1392/* 1397/*
1393 * Cross-check the configuration: make sure that each target device 1398 * Cross-check the configuration: make sure that each target device
1394 * or attribute (`at foo[0*?]') names at least one real device. Also 1399 * or attribute (`at foo[0*?]') names at least one real device. Also
1395 * see that the root and dump devices for all configurations are there. 1400 * see that the root and dump devices for all configurations are there.
1396 */ 1401 */

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

--- src/usr.bin/config/scan.l 2016/08/07 10:37:24 1.26
+++ src/usr.bin/config/scan.l 2020/03/09 15:22:21 1.26.16.1
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: scan.l,v 1.26 2016/08/07 10:37:24 christos Exp $ */ 2/* $NetBSD: scan.l,v 1.26.16.1 2020/03/09 15:22:21 martin 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,102 +32,110 @@ @@ -32,102 +32,110 @@
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.26 2016/08/07 10:37:24 christos Exp $"); 45__RCSID("$NetBSD: scan.l,v 1.26.16.1 2020/03/09 15:22:21 martin 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"
59#include "gram.h" 59#include "gram.h"
60 60
61int yyline; 61int yyline;
62const char *yyfile; 62const char *yyfile;
63const char *lastfile; 63const char *lastfile;
64char curinclpath[PATH_MAX]; 64char curinclpath[PATH_MAX];
65int ifdefstate = -1; 65uint64_t ifdefstate;
66int st; 66int ifdefshift = -1;
 67
 68/*
 69 * The state is represented by 3 bits.
 70 */
 71#define IDS_MATCH 1ll
 72#define IDS_ELIF 2ll
 73#define IDS_ELSE 4ll
 74
 75#define IDS_BITS 7
 76#define IDS_SHIFT 3
 77
 78#define IDS_ISMATCH(st) (((st) & IDS_MATCH) != 0)
67#define IDS_PARENT_DISABLED \ 79#define IDS_PARENT_DISABLED \
68 ((ifdefstate > 6) && ((((ifdefstate/6)-1) & 1) == 1)) 80 (ifdefshift > 0 && !IDS_ISMATCH(ifdefstate >> IDS_SHIFT))
69#define IDS_MAX_DEPTH 362797056 /* 6^11 */ 81#define IDS_MAX_DEPTH 21 /* 64 / 3 */
70/* States for ifdefstate: 82
71 83#ifdef IDS_DEBUG
72 0 -> matched ifdef 84# define IDS_PRINT(s, st, x) \
73 1 -> unmatched ifdef 85 do { \
74 2 -> matched elifdef 86 for (int i = 0; i < ifdefshift + 1; i++) \
75 3 -> unmatched elifdef 87 fprintf(stderr, " "); \
76 4 -> matched else 88 printf("%s%s [%d,%d,%d] %#" PRIx64 "\n", x, # s, \
77 5 -> unmatched else 89 IDS_PARENT_DISABLED, IDS_ISMATCH(st), getcurifdef(), \
78 90 ifdefstate); \
79 Upon "ifdef", add one and multiply by 6. 91 } while (/*CONSTCOND*/0)
80 Upon "endif", divide by 6, remove 1. 92#else
81 93# define IDS_PRINT(s, st, x) __nothing
82 ifdef -> MATCH => continue 94#endif
83 MISMATCH => set to 1 95
84 elifdef -> if (!1) -> MISMATCH 96#define IDS_ENTER(s, st) \
85 MATCH => set to 2 97 IDS_PRINT(s, st, ">")
86 MISMATCH => if (2 || 3) set to 3, else set to 1 98#define IDS_EXIT(s, st) \
87 else -> if (1) -> MATCH 99 IDS_PRINT(s, st, "<")
88 MATCH => set to 4 100
89 MISMATCH => set to 5 
90 
91 in each case, if parent & 1 == 1, MISMATCH 
92*/ 
93  
94/* 101/*
95 * Data for returning to previous files from include files. 102 * Data for returning to previous files from include files.
96 */ 103 */
97struct incl { 104struct incl {
98 struct incl *in_prev; /* previous includes in effect, if any */ 105 struct incl *in_prev; /* previous includes in effect, if any */
99 YY_BUFFER_STATE in_buf; /* previous lex state */ 106 YY_BUFFER_STATE in_buf; /* previous lex state */
100 const char *in_fname; /* previous file name */ 107 struct where in_where;
101 int in_lineno; /* previous line number */ 
102 int in_ateof; /* token to insert at EOF */ 108 int in_ateof; /* token to insert at EOF */
103 int in_interesting; /* previous value for "interesting" */ 109 int in_interesting; /* previous value for "interesting" */
104 int in_ifdefstate; /* conditional level */ 110 uint64_t in_ifdefstate; /* conditional level */
 111 int in_ifdefshift; /* conditional level */
105}; 112};
106static struct incl *incl; 113static struct incl *incl;
107static int endinclude(void); 114static int endinclude(void);
108static int getincludepath(void); 115static int getincludepath(void);
109static int getcurifdef(void); 116static int getcurifdef(void);
110 117
111 118
112%} 119%}
113 120
114%option noyywrap nounput noinput 121%option noyywrap nounput noinput
115 122
116PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]* 123PATH [A-Za-z_0-9]*[./][-A-Za-z_0-9./]*
117QCHARS \"(\\.|[^\\"])*\"  124QCHARS \"(\\.|[^\\"])*\"
118WORD [A-Za-z_][-A-Za-z_0-9]* 125WORD [A-Za-z_][-A-Za-z_0-9]*
119FILENAME ({PATH}|{QCHARS}) 126FILENAME ({PATH}|{QCHARS})
120RESTOFLINE [ \t]*(#[^\n]*)?\n 127RESTOFLINE [ \t]*(#[^\n]*)?\n
 128WS ^[ \t]*
121 129
122%x IGNORED 130%x IGNORED
123 131
124%% 132%%
125 /* Local variables for yylex() */ 133 /* Local variables for yylex() */
126 int tok; 134 int tok;
127 135
128and return AND; 136and return AND;
129at return AT; 137at return AT;
130attach return ATTACH; 138attach return ATTACH;
131block return BLOCK; 139block return BLOCK;
132build return BUILD; 140build return BUILD;
133char return CHAR; 141char return CHAR;
@@ -170,118 +178,121 @@ pseudo-device return PSEUDO_DEVICE; @@ -170,118 +178,121 @@ pseudo-device return PSEUDO_DEVICE;
170pseudo-root return PSEUDO_ROOT; 178pseudo-root return PSEUDO_ROOT;
171root return ROOT; 179root return ROOT;
172select return SELECT; 180select return SELECT;
173single return SINGLE; 181single return SINGLE;
174source return SOURCE; 182source return SOURCE;
175type return TYPE; 183type return TYPE;
176vector return VECTOR; 184vector return VECTOR;
177version return VERSION; 185version return VERSION;
178with return WITH; 186with return WITH;
179 187
180\+= return PLUSEQ; 188\+= return PLUSEQ;
181:= return COLONEQ; 189:= return COLONEQ;
182 190
183<*>ifdef[ \t]+{WORD}{RESTOFLINE} { 191<*>{WS}ifdef[ \t]+{WORD}{RESTOFLINE} {
184 ifdefstate = (ifdefstate + 1) * 6; 192 ifdefstate <<= IDS_SHIFT;
185 if (ifdefstate >= IDS_MAX_DEPTH) { 193 if (++ifdefshift >= IDS_MAX_DEPTH) {
186 yyerror("too many levels of conditional"); 194 yyerror("too many levels of conditional");
187 } 195 }
188 if (!IDS_PARENT_DISABLED && getcurifdef()) { 196 IDS_ENTER(ifdef, 0);
189 BEGIN(INITIAL); 197 if (IDS_PARENT_DISABLED || !getcurifdef()) {
190 } else { 
191 ifdefstate++; 
192 BEGIN(IGNORED); 198 BEGIN(IGNORED);
 199 } else {
 200 ifdefstate |= IDS_MATCH;
 201 BEGIN(INITIAL);
193 } 202 }
 203 IDS_EXIT(ifdef, 0);
194 yyline++; 204 yyline++;
195 } 205 }
196 206
197<*>ifndef[ \t]+{WORD}{RESTOFLINE} { 207<*>{WS}ifndef[ \t]+{WORD}{RESTOFLINE} {
198 ifdefstate = (ifdefstate + 1) * 6; 208 ifdefstate <<= IDS_SHIFT;
199 if (ifdefstate >= IDS_MAX_DEPTH) { 209 if (++ifdefshift >= IDS_MAX_DEPTH) {
200 yyerror("too many levels of conditional"); 210 yyerror("too many levels of conditional");
201 } 211 }
202 if (!IDS_PARENT_DISABLED && !getcurifdef()) { 212 IDS_ENTER(ifndef, 0);
203 BEGIN(INITIAL); 213 if (IDS_PARENT_DISABLED || getcurifdef()) {
204 } else { 
205 ifdefstate++; 
206 BEGIN(IGNORED); 214 BEGIN(IGNORED);
 215 } else {
 216 ifdefstate |= IDS_MATCH;
 217 BEGIN(INITIAL);
207 } 218 }
 219 IDS_EXIT(ifndef, 0);
208 yyline++; 220 yyline++;
209 } 221 }
210 222
211 223
212<*>elifdef[ \t]+{WORD}{RESTOFLINE} { 224<*>{WS}elifdef[ \t]+{WORD}{RESTOFLINE} {
213 st = ifdefstate % 6; 225 int st = ifdefstate & IDS_BITS;
214 if (ifdefstate < 0 || st > 3) { 226 IDS_ENTER(elifdef, st);
 227 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
215 yyerror("mismatched elifdef"); 228 yyerror("mismatched elifdef");
216 } 229 }
217 if (IDS_PARENT_DISABLED || 230 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || !getcurifdef()) {
218 st != 1 || !getcurifdef()) { 
219 if (st == 2 || st == 3) { 
220 ifdefstate += 3 - st; 
221 } else { 
222 ifdefstate += 1 - st; 
223 } 
224 BEGIN(IGNORED); 231 BEGIN(IGNORED);
225 } else { 232 } else {
226 ifdefstate++; 233 ifdefstate |= IDS_MATCH;
227 BEGIN(INITIAL); 234 BEGIN(INITIAL);
228 } 235 }
 236 ifdefstate |= IDS_ELIF;
 237 IDS_EXIT(elifdef, st);
229 yyline++; 238 yyline++;
230 } 239 }
231 240
232<*>elifndef[ \t]+{WORD}{RESTOFLINE} { 241<*>{WS}elifndef[ \t]+{WORD}{RESTOFLINE} {
233 st = ifdefstate % 6; 242 int st = ifdefstate & IDS_BITS;
234 if (ifdefstate < 0 || st > 3) { 243 IDS_ENTER(elifndef, st);
 244 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
235 yyerror("mismatched elifndef"); 245 yyerror("mismatched elifndef");
236 } 246 }
237 if (IDS_PARENT_DISABLED || 247 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st) || getcurifdef()) {
238 st != 1 || getcurifdef()) { 
239 if (st == 2 || st == 3) { 
240 ifdefstate += 3 - st; 
241 } else { 
242 ifdefstate += 1 - st; 
243 } 
244 BEGIN(IGNORED); 248 BEGIN(IGNORED);
245 } else { 249 } else {
246 ifdefstate++; 250 ifdefstate |= IDS_MATCH;
247 BEGIN(INITIAL); 251 BEGIN(INITIAL);
248 } 252 }
 253 ifdefstate |= IDS_ELIF;
 254 IDS_EXIT(elifndef, st);
249 yyline++; 255 yyline++;
250 } 256 }
251 257
252<*>else{RESTOFLINE} { 258<*>{WS}else{RESTOFLINE} {
253 st = ifdefstate % 6; 259 int st = ifdefstate & IDS_BITS;
254 if (ifdefstate < 0 || st > 3) { 260 IDS_ENTER(else, st);
 261 if (ifdefshift == -1 || (st & IDS_ELSE) != 0) {
255 yyerror("mismatched else"); 262 yyerror("mismatched else");
256 } 263 }
257 if (!IDS_PARENT_DISABLED && (st == 1)) { 264 if (IDS_PARENT_DISABLED || IDS_ISMATCH(st)) {
258 ifdefstate += 3; 
259 BEGIN(INITIAL); 
260 } else { 
261 ifdefstate += 5 - st; 
262 BEGIN(IGNORED); 265 BEGIN(IGNORED);
 266 } else {
 267 ifdefstate |= IDS_MATCH;
 268 BEGIN(INITIAL);
263 } 269 }
 270 ifdefstate |= IDS_ELSE;
 271 IDS_ENTER(else, st);
264 yyline++; 272 yyline++;
265 } 273 }
266 274
267<*>endif{RESTOFLINE} { 275<*>{WS}endif{RESTOFLINE} {
268 if (ifdefstate < 0) { 276 IDS_ENTER(endif, 0);
 277 if (ifdefshift == -1) {
269 yyerror("mismatched endif"); 278 yyerror("mismatched endif");
270 } 279 }
271 if (!IDS_PARENT_DISABLED) { 280 if (!IDS_PARENT_DISABLED) {
272 BEGIN(INITIAL); 281 BEGIN(INITIAL);
273 } 282 }
274 ifdefstate = (ifdefstate/6) - 1; 283 IDS_EXIT(endif, 0);
 284 ifdefshift--;
 285 ifdefstate >>= IDS_SHIFT;
275 yyline++; 286 yyline++;
276 } 287 }
277 288
278<IGNORED>\n { 289<IGNORED>\n {
279 yyline++; 290 yyline++;
280 } 291 }
281 292
282<IGNORED>. /* ignore */ 293<IGNORED>. /* ignore */
283 294
284include[ \t]+{FILENAME}{RESTOFLINE} { 295include[ \t]+{FILENAME}{RESTOFLINE} {
285 yyline++; 296 yyline++;
286 if (getincludepath()) { 297 if (getincludepath()) {
287 include(curinclpath, 0, 0, 1); 298 include(curinclpath, 0, 0, 1);
@@ -360,27 +371,27 @@ package[ \t]+{FILENAME}{RESTOFLINE} { @@ -360,27 +371,27 @@ package[ \t]+{FILENAME}{RESTOFLINE} {
360 yyline++; 371 yyline++;
361 return '\n'; 372 return '\n';
362 } 373 }
363\00 { 374\00 {
364 /* Detect NUL characters in the config file and 375 /* Detect NUL characters in the config file and
365 * error out. 376 * error out.
366 */ 377 */
367 cfgerror("NUL character detected at line %i", yyline); 378 cfgerror("NUL character detected at line %i", yyline);
368 } 379 }
369#.* { /* ignored (comment) */; } 380#.* { /* ignored (comment) */; }
370[ \t]+ { /* ignored (white space) */; } 381[ \t]+ { /* ignored (white space) */; }
371. { return yytext[0]; } 382. { return yytext[0]; }
372<*><<EOF>> { 383<*><<EOF>> {
373 if (ifdefstate > (incl == NULL ? -1 : incl->in_ifdefstate)) { 384 if (ifdefshift > (incl == NULL ? -1 : incl->in_ifdefshift)) {
374 yyerror("reached EOF while looking for endif"); 385 yyerror("reached EOF while looking for endif");
375 } 386 }
376 if (incl == NULL) 387 if (incl == NULL)
377 return YY_NULL; 388 return YY_NULL;
378 tok = endinclude(); 389 tok = endinclude();
379 if (tok) 390 if (tok)
380 return tok; 391 return tok;
381 /* otherwise continue scanning */ 392 /* otherwise continue scanning */
382 } 393 }
383 394
384%% 395%%
385 396
386int interesting = 1; 397int interesting = 1;
@@ -516,31 +527,32 @@ include(const char *fname, int ateof, in @@ -516,31 +527,32 @@ include(const char *fname, int ateof, in
516 s, strerror(errno)); 527 s, strerror(errno));
517 free(s); 528 free(s);
518 return (-1); 529 return (-1);
519 } 530 }
520 if (curdir_push(s) == -1) { 531 if (curdir_push(s) == -1) {
521 cfgerror("cannot record current working directory for %s", s); 532 cfgerror("cannot record current working directory for %s", s);
522 fclose(fp); 533 fclose(fp);
523 free(s); 534 free(s);
524 return (-1); 535 return (-1);
525 } 536 }
526 in = ecalloc(1, sizeof *in); 537 in = ecalloc(1, sizeof *in);
527 in->in_prev = incl; 538 in->in_prev = incl;
528 in->in_buf = YY_CURRENT_BUFFER; 539 in->in_buf = YY_CURRENT_BUFFER;
529 in->in_fname = yyfile; 540 in->in_where.w_srcfile = yyfile;
530 in->in_lineno = yyline; 541 in->in_where.w_srcline = (u_short)yyline;
531 in->in_ateof = ateof; 542 in->in_ateof = ateof;
532 in->in_interesting = interesting; 543 in->in_interesting = interesting;
533 in->in_ifdefstate = ifdefstate; 544 in->in_ifdefstate = ifdefstate;
 545 in->in_ifdefshift = ifdefshift;
534 interesting = direct & interesting; 546 interesting = direct & interesting;
535 if (interesting) 547 if (interesting)
536 logconfig_include(fp, fname); 548 logconfig_include(fp, fname);
537 incl = in; 549 incl = in;
538 CFGDBG(1, "include `%s' from `%s' line %d", fname, yyfile, yyline); 550 CFGDBG(1, "include `%s' from `%s' line %d", fname, yyfile, yyline);
539 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); 551 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
540 yyfile = intern(s); 552 yyfile = intern(s);
541 yyline = 1; 553 yyline = 1;
542 free(s); 554 free(s);
543 includedepth++; 555 includedepth++;
544 return (0); 556 return (0);
545} 557}
546 558
@@ -587,30 +599,32 @@ static int @@ -587,30 +599,32 @@ static int
587endinclude(void) 599endinclude(void)
588{ 600{
589 struct incl *in; 601 struct incl *in;
590 int ateof; 602 int ateof;
591 603
592 curdir_pop(); 604 curdir_pop();
593 if ((in = incl) == NULL) 605 if ((in = incl) == NULL)
594 panic("endinclude"); 606 panic("endinclude");
595 incl = in->in_prev; 607 incl = in->in_prev;
596 lastfile = yyfile; 608 lastfile = yyfile;
597 yy_delete_buffer(YY_CURRENT_BUFFER); 609 yy_delete_buffer(YY_CURRENT_BUFFER);
598 (void)fclose(yyin); 610 (void)fclose(yyin);
599 yy_switch_to_buffer(in->in_buf); 611 yy_switch_to_buffer(in->in_buf);
600 yyfile = in->in_fname; 612 yyfile = in->in_where.w_srcfile;
601 yyline = in->in_lineno; 613 yyline = in->in_where.w_srcline;
602 ateof = in->in_ateof; 614 ateof = in->in_ateof;
603 interesting = in->in_interesting; 615 interesting = in->in_interesting;
 616 ifdefstate = in->in_ifdefstate;
 617 ifdefshift = in->in_ifdefshift;
604 free(in); 618 free(in);
605 619
606 includedepth--; 620 includedepth--;
607 621
608 return (ateof); 622 return (ateof);
609} 623}
610 624
611/* 625/*
612 * Return the current line number. If yacc has looked ahead and caused 626 * Return the current line number. If yacc has looked ahead and caused
613 * us to consume a newline, we have to subtract one. yychar is yacc's 627 * us to consume a newline, we have to subtract one. yychar is yacc's
614 * token lookahead, so we can tell. 628 * token lookahead, so we can tell.
615 */ 629 */
616u_short 630u_short

cvs diff -r1.83 -r1.83.4.1 src/usr.bin/config/sem.c (expand / switch to unified diff)

--- src/usr.bin/config/sem.c 2018/04/09 17:46:56 1.83
+++ src/usr.bin/config/sem.c 2020/03/09 15:22:21 1.83.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sem.c,v 1.83 2018/04/09 17:46:56 christos Exp $ */ 1/* $NetBSD: sem.c,v 1.83.4.1 2020/03/09 15:22:21 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -35,27 +35,27 @@ @@ -35,27 +35,27 @@
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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 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 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * from: @(#)sem.c 8.1 (Berkeley) 6/6/93 40 * from: @(#)sem.c 8.1 (Berkeley) 6/6/93
41 */ 41 */
42 42
43#if HAVE_NBTOOL_CONFIG_H 43#if HAVE_NBTOOL_CONFIG_H
44#include "nbtool_config.h" 44#include "nbtool_config.h"
45#endif 45#endif
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__RCSID("$NetBSD: sem.c,v 1.83 2018/04/09 17:46:56 christos Exp $"); 48__RCSID("$NetBSD: sem.c,v 1.83.4.1 2020/03/09 15:22:21 martin Exp $");
49 49
50#include <sys/param.h> 50#include <sys/param.h>
51#include <ctype.h> 51#include <ctype.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <stdlib.h> 53#include <stdlib.h>
54#include <string.h> 54#include <string.h>
55#include <util.h> 55#include <util.h>
56#include "defs.h" 56#include "defs.h"
57#include "sem.h" 57#include "sem.h"
58 58
59/* 59/*
60 * config semantics. 60 * config semantics.
61 */ 61 */
@@ -266,37 +266,44 @@ void @@ -266,37 +266,44 @@ void
266setdefmaxusers(int min, int def, int max) 266setdefmaxusers(int min, int def, int max)
267{ 267{
268 268
269 if (min < 1 || min > def || def > max) 269 if (min < 1 || min > def || def > max)
270 cfgerror("maxusers must have 1 <= min (%d) <= default (%d) " 270 cfgerror("maxusers must have 1 <= min (%d) <= default (%d) "
271 "<= max (%d)", min, def, max); 271 "<= max (%d)", min, def, max);
272 else { 272 else {
273 minmaxusers = min; 273 minmaxusers = min;
274 defmaxusers = def; 274 defmaxusers = def;
275 maxmaxusers = max; 275 maxmaxusers = max;
276 } 276 }
277} 277}
278 278
 279static const char *maxusers_srcfile;
 280static u_short maxusers_srcline;
 281
279void 282void
280setmaxusers(int n) 283setmaxusers(int n)
281{ 284{
282 285
283 if (maxusers == n) { 286 if (maxusers == n) {
284 cfgerror("duplicate maxusers parameter"); 287 cfgerror("duplicate maxusers parameter at %s:%hu",
 288 maxusers_srcfile, maxusers_srcline);
285 return; 289 return;
286 } 290 }
287 if (vflag && maxusers != 0) 291 if (vflag && maxusers != 0)
288 cfgwarn("warning: maxusers already defined"); 292 cfgwarn("warning: maxusers already defined at %s:%hu",
 293 maxusers_srcfile, maxusers_srcline);
289 maxusers = n; 294 maxusers = n;
 295 maxusers_srcfile = yyfile;
 296 maxusers_srcline = currentline();
290 if (n < minmaxusers) { 297 if (n < minmaxusers) {
291 cfgerror("warning: minimum of %d maxusers assumed", 298 cfgerror("warning: minimum of %d maxusers assumed",
292 minmaxusers); 299 minmaxusers);
293 errors--; /* take it away */ 300 errors--; /* take it away */
294 maxusers = minmaxusers; 301 maxusers = minmaxusers;
295 } else if (n > maxmaxusers) { 302 } else if (n > maxmaxusers) {
296 cfgerror("warning: maxusers (%d) > %d", n, maxmaxusers); 303 cfgerror("warning: maxusers (%d) > %d", n, maxmaxusers);
297 errors--; 304 errors--;
298 } 305 }
299} 306}
300 307
301void 308void
302setident(const char *i) 309setident(const char *i)
@@ -328,27 +335,28 @@ defattr0(const char *name, struct loclis @@ -328,27 +335,28 @@ defattr0(const char *name, struct loclis
328 return defdevclass(name, locs, deps, devclass); 335 return defdevclass(name, locs, deps, devclass);
329 else 336 else
330 return defattr(name, locs, deps, devclass); 337 return defattr(name, locs, deps, devclass);
331} 338}
332 339
333int 340int
334defattr(const char *name, struct loclist *locs, struct attrlist *deps, 341defattr(const char *name, struct loclist *locs, struct attrlist *deps,
335 int devclass) 342 int devclass)
336{ 343{
337 struct attr *a, *dep; 344 struct attr *a, *dep;
338 struct attrlist *al; 345 struct attrlist *al;
339 346
340 if (getrefattr(name, &a)) { 347 if (getrefattr(name, &a)) {
341 cfgerror("attribute `%s' already defined", name); 348 cfgerror("attribute `%s' already defined at %s:%hu", name,
 349 a->a_where.w_srcfile, a->a_where.w_srcline);
342 loclist_destroy(locs); 350 loclist_destroy(locs);
343 return (1); 351 return (1);
344 } 352 }
345 if (a == NULL) 353 if (a == NULL)
346 a = mkattr(name); 354 a = mkattr(name);
347 355
348 /* 356 /*
349 * If this attribute depends on any others, make sure none of 357 * If this attribute depends on any others, make sure none of
350 * the dependencies are interface attributes. 358 * the dependencies are interface attributes.
351 */ 359 */
352 for (al = deps; al != NULL; al = al->al_next) { 360 for (al = deps; al != NULL; al = al->al_next) {
353 dep = al->al_this; 361 dep = al->al_this;
354 if (dep->a_iattr) { 362 if (dep->a_iattr) {
@@ -370,26 +378,28 @@ defattr(const char *name, struct loclist @@ -370,26 +378,28 @@ defattr(const char *name, struct loclist
370} 378}
371 379
372struct attr * 380struct attr *
373mkattr(const char *name) 381mkattr(const char *name)
374{ 382{
375 struct attr *a; 383 struct attr *a;
376 384
377 a = ecalloc(1, sizeof *a); 385 a = ecalloc(1, sizeof *a);
378 if (ht_insert(attrtab, name, a)) { 386 if (ht_insert(attrtab, name, a)) {
379 free(a); 387 free(a);
380 return NULL; 388 return NULL;
381 } 389 }
382 a->a_name = name; 390 a->a_name = name;
 391 a->a_where.w_srcfile = yyfile;
 392 a->a_where.w_srcline = currentline();
383 TAILQ_INIT(&a->a_files); 393 TAILQ_INIT(&a->a_files);
384 CFGDBG(3, "attr `%s' allocated", name); 394 CFGDBG(3, "attr `%s' allocated", name);
385 395
386 return a; 396 return a;
387} 397}
388 398
389/* "interface attribute" initialization */ 399/* "interface attribute" initialization */
390int 400int
391defiattr(const char *name, struct loclist *locs, struct attrlist *deps, 401defiattr(const char *name, struct loclist *locs, struct attrlist *deps,
392 int devclass) 402 int devclass)
393{ 403{
394 struct attr *a; 404 struct attr *a;
395 int len; 405 int len;
@@ -500,27 +510,27 @@ addtoattr(struct nvlist *l, struct devba @@ -500,27 +510,27 @@ addtoattr(struct nvlist *l, struct devba
500 * attribute and/or refer to existing attributes. 510 * attribute and/or refer to existing attributes.
501 */ 511 */
502void 512void
503defdev(struct devbase *dev, struct loclist *loclist, struct attrlist *attrs, 513defdev(struct devbase *dev, struct loclist *loclist, struct attrlist *attrs,
504 int ispseudo) 514 int ispseudo)
505{ 515{
506 struct loclist *ll; 516 struct loclist *ll;
507 struct attrlist *al; 517 struct attrlist *al;
508 518
509 if (dev == &errdev) 519 if (dev == &errdev)
510 goto bad; 520 goto bad;
511 if (dev->d_isdef) { 521 if (dev->d_isdef) {
512 cfgerror("redefinition of `%s' (previously defined at %s:%d)", 522 cfgerror("redefinition of `%s' (previously defined at %s:%d)",
513 dev->d_name, dev->d_srcfile, dev->d_srcline); 523 dev->d_name, dev->d_where.w_srcfile, dev->d_where.w_srcline);
514 goto bad; 524 goto bad;
515 } 525 }
516 526
517 dev->d_isdef = 1; 527 dev->d_isdef = 1;
518 if (has_errobj(attrs, &errattr)) 528 if (has_errobj(attrs, &errattr))
519 goto bad; 529 goto bad;
520 530
521 /* 531 /*
522 * Handle implicit attribute definition from locator list. Do 532 * Handle implicit attribute definition from locator list. Do
523 * this before scanning the `at' list so that we can have, e.g.: 533 * this before scanning the `at' list so that we can have, e.g.:
524 * device foo at other, foo { slot = -1 } 534 * device foo at other, foo { slot = -1 }
525 * (where you can plug in a foo-bus extender to a foo-bus). 535 * (where you can plug in a foo-bus extender to a foo-bus).
526 */ 536 */
@@ -615,28 +625,28 @@ getdevbase(const char *name) @@ -615,28 +625,28 @@ getdevbase(const char *name)
615 } 625 }
616 dev = ht_lookup(devbasetab, name); 626 dev = ht_lookup(devbasetab, name);
617 if (dev == NULL) { 627 if (dev == NULL) {
618 dev = ecalloc(1, sizeof *dev); 628 dev = ecalloc(1, sizeof *dev);
619 dev->d_name = name; 629 dev->d_name = name;
620 dev->d_isdef = 0; 630 dev->d_isdef = 0;
621 dev->d_major = NODEVMAJOR; 631 dev->d_major = NODEVMAJOR;
622 dev->d_attrs = NULL; 632 dev->d_attrs = NULL;
623 dev->d_ihead = NULL; 633 dev->d_ihead = NULL;
624 dev->d_ipp = &dev->d_ihead; 634 dev->d_ipp = &dev->d_ihead;
625 dev->d_ahead = NULL; 635 dev->d_ahead = NULL;
626 dev->d_app = &dev->d_ahead; 636 dev->d_app = &dev->d_ahead;
627 dev->d_umax = 0; 637 dev->d_umax = 0;
628 dev->d_srcfile = yyfile; 638 dev->d_where.w_srcfile = yyfile;
629 dev->d_srcline = currentline(); 639 dev->d_where.w_srcline = currentline();
630 TAILQ_INSERT_TAIL(&allbases, dev, d_next); 640 TAILQ_INSERT_TAIL(&allbases, dev, d_next);
631 if (ht_insert(devbasetab, name, dev)) 641 if (ht_insert(devbasetab, name, dev))
632 panic("%s: Can't insert %s", __func__, name); 642 panic("%s: Can't insert %s", __func__, name);
633 CFGDBG(3, "devbase defined `%s'", dev->d_name); 643 CFGDBG(3, "devbase defined `%s'", dev->d_name);
634 } 644 }
635 return (dev); 645 return (dev);
636} 646}
637 647
638/* 648/*
639 * Define some of a device's allowable parent attachments. 649 * Define some of a device's allowable parent attachments.
640 * There may be a list of (plain) attributes. 650 * There may be a list of (plain) attributes.
641 */ 651 */
642void 652void
@@ -649,27 +659,27 @@ defdevattach(struct deva *deva, struct d @@ -649,27 +659,27 @@ defdevattach(struct deva *deva, struct d
649 659
650 if (dev == &errdev) 660 if (dev == &errdev)
651 goto bad; 661 goto bad;
652 if (deva == NULL) 662 if (deva == NULL)
653 deva = getdevattach(dev->d_name); 663 deva = getdevattach(dev->d_name);
654 if (deva == &errdeva) 664 if (deva == &errdeva)
655 goto bad; 665 goto bad;
656 if (!dev->d_isdef) { 666 if (!dev->d_isdef) {
657 cfgerror("attaching undefined device `%s'", dev->d_name); 667 cfgerror("attaching undefined device `%s'", dev->d_name);
658 goto bad; 668 goto bad;
659 } 669 }
660 if (deva->d_isdef) { 670 if (deva->d_isdef) {
661 cfgerror("redefinition of `%s' (previously defined at %s:%d)", 671 cfgerror("redefinition of `%s' (previously defined at %s:%d)",
662 deva->d_name, deva->d_srcfile, deva->d_srcline); 672 deva->d_name, deva->d_where.w_srcfile, deva->d_where.w_srcline);
663 goto bad; 673 goto bad;
664 } 674 }
665 if (dev->d_ispseudo) { 675 if (dev->d_ispseudo) {
666 cfgerror("pseudo-devices can't attach"); 676 cfgerror("pseudo-devices can't attach");
667 goto bad; 677 goto bad;
668 } 678 }
669 679
670 deva->d_isdef = 1; 680 deva->d_isdef = 1;
671 if (has_errobj(attrs, &errattr)) 681 if (has_errobj(attrs, &errattr))
672 goto bad; 682 goto bad;
673 for (al = attrs; al != NULL; al = al->al_next) { 683 for (al = attrs; al != NULL; al = al->al_next) {
674 a = al->al_this; 684 a = al->al_this;
675 if (a == &errattr) 685 if (a == &errattr)
@@ -758,28 +768,28 @@ getdevattach(const char *name) @@ -758,28 +768,28 @@ getdevattach(const char *name)
758 return (&errdeva); 768 return (&errdeva);
759 } 769 }
760 deva = ht_lookup(devatab, name); 770 deva = ht_lookup(devatab, name);
761 if (deva == NULL) { 771 if (deva == NULL) {
762 deva = ecalloc(1, sizeof *deva); 772 deva = ecalloc(1, sizeof *deva);
763 deva->d_name = name; 773 deva->d_name = name;
764 deva->d_bsame = NULL; 774 deva->d_bsame = NULL;
765 deva->d_isdef = 0; 775 deva->d_isdef = 0;
766 deva->d_devbase = NULL; 776 deva->d_devbase = NULL;
767 deva->d_atlist = NULL; 777 deva->d_atlist = NULL;
768 deva->d_attrs = NULL; 778 deva->d_attrs = NULL;
769 deva->d_ihead = NULL; 779 deva->d_ihead = NULL;
770 deva->d_ipp = &deva->d_ihead; 780 deva->d_ipp = &deva->d_ihead;
771 deva->d_srcfile = yyfile; 781 deva->d_where.w_srcfile = yyfile;
772 deva->d_srcline = currentline(); 782 deva->d_where.w_srcline = currentline();
773 TAILQ_INSERT_TAIL(&alldevas, deva, d_next); 783 TAILQ_INSERT_TAIL(&alldevas, deva, d_next);
774 if (ht_insert(devatab, name, deva)) 784 if (ht_insert(devatab, name, deva))
775 panic("%s: Can't insert %s", __func__, name); 785 panic("%s: Can't insert %s", __func__, name);
776 } 786 }
777 return (deva); 787 return (deva);
778} 788}
779 789
780/* 790/*
781 * Look up an attribute. 791 * Look up an attribute.
782 */ 792 */
783struct attr * 793struct attr *
784getattr(const char *name) 794getattr(const char *name)
785{ 795{
@@ -1029,33 +1039,38 @@ resolve(struct nvlist **nvp, const char  @@ -1029,33 +1039,38 @@ resolve(struct nvlist **nvp, const char
1029 return (0); 1039 return (0);
1030} 1040}
1031 1041
1032/* 1042/*
1033 * Add a completed configuration to the list. 1043 * Add a completed configuration to the list.
1034 */ 1044 */
1035void 1045void
1036addconf(struct config *cf0) 1046addconf(struct config *cf0)
1037{ 1047{
1038 struct config *cf; 1048 struct config *cf;
1039 const char *name; 1049 const char *name;
1040 1050
1041 name = cf0->cf_name; 1051 name = cf0->cf_name;
 1052 if ((cf = ht_lookup(cfhashtab, name)) != NULL) {
 1053 cfgerror("configuration `%s' already defined %s:%hu", name,
 1054 cf->cf_where.w_srcfile, cf->cf_where.w_srcline);
 1055 goto bad;
 1056 }
1042 cf = ecalloc(1, sizeof *cf); 1057 cf = ecalloc(1, sizeof *cf);
1043 if (ht_insert(cfhashtab, name, cf)) { 1058 if (ht_insert(cfhashtab, name, cf)) {
1044 cfgerror("configuration `%s' already defined", name); 
1045 free(cf); 1059 free(cf);
1046 goto bad; 
1047 } 1060 }
1048 *cf = *cf0; 1061 *cf = *cf0;
 1062 cf->cf_where.w_srcfile = yyfile;
 1063 cf->cf_where.w_srcline = currentline();
1049 1064
1050 /* 1065 /*
1051 * Resolve the root device. 1066 * Resolve the root device.
1052 */ 1067 */
1053 if (cf->cf_root == NULL) { 1068 if (cf->cf_root == NULL) {
1054 cfgerror("%s: no root device specified", name); 1069 cfgerror("%s: no root device specified", name);
1055 goto bad; 1070 goto bad;
1056 } 1071 }
1057 if (cf->cf_root && cf->cf_root->nv_str != s_qmark) { 1072 if (cf->cf_root && cf->cf_root->nv_str != s_qmark) {
1058 struct nvlist *nv; 1073 struct nvlist *nv;
1059 nv = cf->cf_root; 1074 nv = cf->cf_root;
1060 if (resolve(&cf->cf_root, name, "root", nv, 'a')) 1075 if (resolve(&cf->cf_root, name, "root", nv, 'a'))
1061 goto bad; 1076 goto bad;
@@ -1147,31 +1162,33 @@ newdevi(const char *name, int unit, stru @@ -1147,31 +1162,33 @@ newdevi(const char *name, int unit, stru
1147 1162
1148 i = ecalloc(1, sizeof *i); 1163 i = ecalloc(1, sizeof *i);
1149 i->i_name = name; 1164 i->i_name = name;
1150 i->i_unit = unit; 1165 i->i_unit = unit;
1151 i->i_base = d; 1166 i->i_base = d;
1152 i->i_bsame = NULL; 1167 i->i_bsame = NULL;
1153 i->i_asame = NULL; 1168 i->i_asame = NULL;
1154 i->i_alias = NULL; 1169 i->i_alias = NULL;
1155 i->i_at = NULL; 1170 i->i_at = NULL;
1156 i->i_pspec = NULL; 1171 i->i_pspec = NULL;
1157 i->i_atdeva = NULL; 1172 i->i_atdeva = NULL;
1158 i->i_locs = NULL; 1173 i->i_locs = NULL;
1159 i->i_cfflags = 0; 1174 i->i_cfflags = 0;
1160 i->i_lineno = currentline(); 1175 i->i_where.w_srcline = currentline();
1161 i->i_srcfile = yyfile; 1176 i->i_where.w_srcfile = yyfile;
1162 i->i_active = DEVI_ORPHAN; /* Proper analysis comes later */ 1177 i->i_active = DEVI_ORPHAN; /* Proper analysis comes later */
1163 i->i_level = devilevel; 1178 i->i_level = devilevel;
1164 i->i_pseudoroot = 0; 1179 i->i_pseudoroot = 0;
 1180 i->i_where.w_srcfile = yyfile;
 1181 i->i_where.w_srcline = currentline();
1165 if (unit >= d->d_umax) 1182 if (unit >= d->d_umax)
1166 d->d_umax = unit + 1; 1183 d->d_umax = unit + 1;
1167 return (i); 1184 return (i);
1168} 1185}
1169 1186
1170static struct attr * 1187static struct attr *
1171finddevattr(const char *name, const char *at, struct devbase *ib, 1188finddevattr(const char *name, const char *at, struct devbase *ib,
1172 struct devbase **ab, int *atunit) 1189 struct devbase **ab, int *atunit)
1173{ 1190{
1174 const char *cp; 1191 const char *cp;
1175 char atbuf[NAMESIZE]; 1192 char atbuf[NAMESIZE];
1176 struct attrlist *al; 1193 struct attrlist *al;
1177 struct attr *attr; 1194 struct attr *attr;
@@ -1786,28 +1803,29 @@ addpseudo(const char *name, int number) @@ -1786,28 +1803,29 @@ addpseudo(const char *name, int number)
1786{ 1803{
1787 struct devbase *d; 1804 struct devbase *d;
1788 struct devi *i; 1805 struct devi *i;
1789 1806
1790 d = ht_lookup(devbasetab, name); 1807 d = ht_lookup(devbasetab, name);
1791 if (d == NULL) { 1808 if (d == NULL) {
1792 cfgerror("undefined pseudo-device %s", name); 1809 cfgerror("undefined pseudo-device %s", name);
1793 return; 1810 return;
1794 } 1811 }
1795 if (!d->d_ispseudo) { 1812 if (!d->d_ispseudo) {
1796 cfgerror("%s is a real device, not a pseudo-device", name); 1813 cfgerror("%s is a real device, not a pseudo-device", name);
1797 return; 1814 return;
1798 } 1815 }
1799 if (ht_lookup(devitab, name) != NULL) { 1816 if ((i = ht_lookup(devitab, name)) != NULL) {
1800 cfgerror("`%s' already defined", name); 1817 cfgerror("`%s' already defined at %s:%hu", name,
 1818 i->i_where.w_srcfile, i->i_where.w_srcline);
1801 return; 1819 return;
1802 } 1820 }
1803 i = newdevi(name, number - 1, d); /* foo 16 => "foo0..foo15" */ 1821 i = newdevi(name, number - 1, d); /* foo 16 => "foo0..foo15" */
1804 if (ht_insert(devitab, name, i)) 1822 if (ht_insert(devitab, name, i))
1805 panic("%s: %s", __func__, name); 1823 panic("%s: %s", __func__, name);
1806 /* Useful to retrieve the instance from the devbase */ 1824 /* Useful to retrieve the instance from the devbase */
1807 d->d_ihead = i; 1825 d->d_ihead = i;
1808 i->i_active = DEVI_ACTIVE; 1826 i->i_active = DEVI_ACTIVE;
1809 TAILQ_INSERT_TAIL(&allpseudo, i, i_next); 1827 TAILQ_INSERT_TAIL(&allpseudo, i, i_next);
1810} 1828}
1811 1829
1812void 1830void
1813delpseudo(const char *name, int nowarn) 1831delpseudo(const char *name, int nowarn)
@@ -1845,28 +1863,28 @@ adddevm(const char *name, devmajor_t cma @@ -1845,28 +1863,28 @@ adddevm(const char *name, devmajor_t cma
1845 cfgerror("block major %d is invalid", bmajor); 1863 cfgerror("block major %d is invalid", bmajor);
1846 condexpr_destroy(cond); 1864 condexpr_destroy(cond);
1847 nvfreel(nv_nodes); 1865 nvfreel(nv_nodes);
1848 return; 1866 return;
1849 } 1867 }
1850 if (cmajor == NODEVMAJOR && bmajor == NODEVMAJOR) { 1868 if (cmajor == NODEVMAJOR && bmajor == NODEVMAJOR) {
1851 cfgerror("both character/block majors are not specified"); 1869 cfgerror("both character/block majors are not specified");
1852 condexpr_destroy(cond); 1870 condexpr_destroy(cond);
1853 nvfreel(nv_nodes); 1871 nvfreel(nv_nodes);
1854 return; 1872 return;
1855 } 1873 }
1856 1874
1857 dm = ecalloc(1, sizeof(*dm)); 1875 dm = ecalloc(1, sizeof(*dm));
1858 dm->dm_srcfile = yyfile; 1876 dm->dm_where.w_srcfile = yyfile;
1859 dm->dm_srcline = currentline(); 1877 dm->dm_where.w_srcline = currentline();
1860 dm->dm_name = name; 1878 dm->dm_name = name;
1861 dm->dm_cmajor = cmajor; 1879 dm->dm_cmajor = cmajor;
1862 dm->dm_bmajor = bmajor; 1880 dm->dm_bmajor = bmajor;
1863 dm->dm_opts = cond; 1881 dm->dm_opts = cond;
1864 dm->dm_devnodes = nv_nodes; 1882 dm->dm_devnodes = nv_nodes;
1865 1883
1866 TAILQ_INSERT_TAIL(&alldevms, dm, dm_next); 1884 TAILQ_INSERT_TAIL(&alldevms, dm, dm_next);
1867 1885
1868 maxcdevm = MAX(maxcdevm, dm->dm_cmajor); 1886 maxcdevm = MAX(maxcdevm, dm->dm_cmajor);
1869 maxbdevm = MAX(maxbdevm, dm->dm_bmajor); 1887 maxbdevm = MAX(maxbdevm, dm->dm_bmajor);
1870} 1888}
1871 1889
1872int 1890int
@@ -1880,31 +1898,31 @@ fixdevis(void) @@ -1880,31 +1898,31 @@ fixdevis(void)
1880 TAILQ_FOREACH(i, &alldevi, i_next) { 1898 TAILQ_FOREACH(i, &alldevi, i_next) {
1881 CFGDBG(3, "fixing devis `%s'", i->i_name); 1899 CFGDBG(3, "fixing devis `%s'", i->i_name);
1882 if (i->i_active == DEVI_ACTIVE) 1900 if (i->i_active == DEVI_ACTIVE)
1883 selectbase(i->i_base, i->i_atdeva); 1901 selectbase(i->i_base, i->i_atdeva);
1884 else if (i->i_active == DEVI_ORPHAN) { 1902 else if (i->i_active == DEVI_ORPHAN) {
1885 /* 1903 /*
1886 * At this point, we can't have instances for which 1904 * At this point, we can't have instances for which
1887 * i_at or i_pspec are NULL. 1905 * i_at or i_pspec are NULL.
1888 */ 1906 */
1889 ++error; 1907 ++error;
1890 p = i->i_pspec; 1908 p = i->i_pspec;
1891 msg = p == NULL ? "no parent" : 1909 msg = p == NULL ? "no parent" :
1892 (p->p_atunit == WILD ? "nothing matching" : "no"); 1910 (p->p_atunit == WILD ? "nothing matching" : "no");
1893 cfgxerror(i->i_srcfile, i->i_lineno, 1911 cfgxerror(i->i_where.w_srcfile, i->i_where.w_srcline,
1894 "`%s at %s' is orphaned (%s `%s' found)",  1912 "`%s at %s' is orphaned (%s `%s' found)",
1895 i->i_name, i->i_at, msg, i->i_at); 1913 i->i_name, i->i_at, msg, i->i_at);
1896 } else if (vflag && i->i_active == DEVI_IGNORED) 1914 } else if (vflag && i->i_active == DEVI_IGNORED)
1897 cfgxwarn(i->i_srcfile, i->i_lineno, "ignoring " 1915 cfgxwarn(i->i_where.w_srcfile, i->i_where.w_srcline, "ignoring "
1898 "explicitly orphaned instance `%s at %s'", 1916 "explicitly orphaned instance `%s at %s'",
1899 i->i_name, i->i_at); 1917 i->i_name, i->i_at);
1900 } 1918 }
1901 1919
1902 if (error) 1920 if (error)
1903 return error; 1921 return error;
1904 1922
1905 TAILQ_FOREACH(i, &allpseudo, i_next) 1923 TAILQ_FOREACH(i, &allpseudo, i_next)
1906 if (i->i_active == DEVI_ACTIVE) 1924 if (i->i_active == DEVI_ACTIVE)
1907 selectbase(i->i_base, NULL); 1925 selectbase(i->i_base, NULL);
1908 return 0; 1926 return 0;
1909} 1927}
1910 1928

cvs diff -r1.20 -r1.20.18.1 src/usr.bin/config/util.c (expand / switch to unified diff)

--- src/usr.bin/config/util.c 2015/09/01 13:42:48 1.20
+++ src/usr.bin/config/util.c 2020/03/09 15:22:21 1.20.18.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: util.c,v 1.20 2015/09/01 13:42:48 uebayasi Exp $ */ 1/* $NetBSD: util.c,v 1.20.18.1 2020/03/09 15:22:21 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This software was developed by the Computer Systems Engineering group 7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley. 9 * contributed to Berkeley.
10 * 10 *
11 * All advertising materials mentioning features or use of this software 11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement: 12 * must display the following acknowledgement:
13 * This product includes software developed by the University of 13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories. 14 * California, Lawrence Berkeley Laboratories.
@@ -35,39 +35,41 @@ @@ -35,39 +35,41 @@
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 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 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 37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE. 38 * SUCH DAMAGE.
39 * 39 *
40 * from: @(#)util.c 8.1 (Berkeley) 6/6/93 40 * from: @(#)util.c 8.1 (Berkeley) 6/6/93
41 */ 41 */
42 42
43#if HAVE_NBTOOL_CONFIG_H 43#if HAVE_NBTOOL_CONFIG_H
44#include "nbtool_config.h" 44#include "nbtool_config.h"
45#endif 45#endif
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__RCSID("$NetBSD: util.c,v 1.20 2015/09/01 13:42:48 uebayasi Exp $"); 48__RCSID("$NetBSD: util.c,v 1.20.18.1 2020/03/09 15:22:21 martin Exp $");
49 49
50#include <sys/types.h> 50#include <sys/types.h>
51#include <assert.h> 51#include <assert.h>
52#include <ctype.h> 52#include <ctype.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <string.h> 55#include <string.h>
56#include <stdarg.h> 56#include <stdarg.h>
57#include <util.h> 57#include <util.h>
58#include <err.h> 58#include <err.h>
59#include "defs.h" 59#include "defs.h"
60 60
 61extern const char *yyfile;
 62
61static void cfgvxerror(const char *, int, const char *, va_list) 63static void cfgvxerror(const char *, int, const char *, va_list)
62 __printflike(3, 0); 64 __printflike(3, 0);
63static void cfgvxdbg(const char *, int, const char *, va_list) 65static void cfgvxdbg(const char *, int, const char *, va_list)
64 __printflike(3, 0); 66 __printflike(3, 0);
65static void cfgvxwarn(const char *, int, const char *, va_list) 67static void cfgvxwarn(const char *, int, const char *, va_list)
66 __printflike(3, 0); 68 __printflike(3, 0);
67static void cfgvxmsg(const char *, int, const char *, const char *, va_list) 69static void cfgvxmsg(const char *, int, const char *, const char *, va_list)
68 __printflike(4, 0); 70 __printflike(4, 0);
69 71
70/************************************************************/ 72/************************************************************/
71 73
72/* 74/*
73 * Prefix stack 75 * Prefix stack
@@ -188,26 +190,28 @@ sourcepath(const char *file) @@ -188,26 +190,28 @@ sourcepath(const char *file)
188 */ 190 */
189 191
190struct nvlist * 192struct nvlist *
191newnv(const char *name, const char *str, void *ptr, long long i, struct nvlist *next) 193newnv(const char *name, const char *str, void *ptr, long long i, struct nvlist *next)
192{ 194{
193 struct nvlist *nv; 195 struct nvlist *nv;
194 196
195 nv = ecalloc(1, sizeof(*nv)); 197 nv = ecalloc(1, sizeof(*nv));
196 nv->nv_next = next; 198 nv->nv_next = next;
197 nv->nv_name = name; 199 nv->nv_name = name;
198 nv->nv_str = str; 200 nv->nv_str = str;
199 nv->nv_ptr = ptr; 201 nv->nv_ptr = ptr;
200 nv->nv_num = i; 202 nv->nv_num = i;
 203 nv->nv_where.w_srcfile = yyfile;
 204 nv->nv_where.w_srcline = currentline();
201 return nv; 205 return nv;
202} 206}
203 207
204/* 208/*
205 * Free an nvlist structure (just one). 209 * Free an nvlist structure (just one).
206 */ 210 */
207void 211void
208nvfree(struct nvlist *nv) 212nvfree(struct nvlist *nv)
209{ 213{
210 214
211 free(nv); 215 free(nv);
212} 216}
213 217
@@ -245,26 +249,28 @@ nvcat(struct nvlist *nv1, struct nvlist  @@ -245,26 +249,28 @@ nvcat(struct nvlist *nv1, struct nvlist
245 249
246struct defoptlist * 250struct defoptlist *
247defoptlist_create(const char *name, const char *val, const char *lintval) 251defoptlist_create(const char *name, const char *val, const char *lintval)
248{ 252{
249 struct defoptlist *dl; 253 struct defoptlist *dl;
250 254
251 dl = emalloc(sizeof(*dl)); 255 dl = emalloc(sizeof(*dl));
252 dl->dl_next = NULL; 256 dl->dl_next = NULL;
253 dl->dl_name = name; 257 dl->dl_name = name;
254 dl->dl_value = val; 258 dl->dl_value = val;
255 dl->dl_lintvalue = lintval; 259 dl->dl_lintvalue = lintval;
256 dl->dl_obsolete = 0; 260 dl->dl_obsolete = 0;
257 dl->dl_depends = NULL; 261 dl->dl_depends = NULL;
 262 dl->dl_where.w_srcfile = yyfile;
 263 dl->dl_where.w_srcline = currentline();
258 return dl; 264 return dl;
259} 265}
260 266
261void 267void
262defoptlist_destroy(struct defoptlist *dl) 268defoptlist_destroy(struct defoptlist *dl)
263{ 269{
264 struct defoptlist *next; 270 struct defoptlist *next;
265 271
266 while (dl != NULL) { 272 while (dl != NULL) {
267 next = dl->dl_next; 273 next = dl->dl_next;
268 dl->dl_next = NULL; 274 dl->dl_next = NULL;
269 275
270 // XXX should we assert that dl->dl_deps is null to 276 // XXX should we assert that dl->dl_deps is null to