Home | History | Annotate | Line # | Download | only in config
gram.y revision 1.55
      1 %{
      2 /*	$NetBSD: gram.y,v 1.55 2020/03/07 19:26:13 christos Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 1992, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This software was developed by the Computer Systems Engineering group
      9  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     10  * contributed to Berkeley.
     11  *
     12  * All advertising materials mentioning features or use of this software
     13  * must display the following acknowledgement:
     14  *	This product includes software developed by the University of
     15  *	California, Lawrence Berkeley Laboratories.
     16  *
     17  * Redistribution and use in source and binary forms, with or without
     18  * modification, are permitted provided that the following conditions
     19  * are met:
     20  * 1. Redistributions of source code must retain the above copyright
     21  *    notice, this list of conditions and the following disclaimer.
     22  * 2. Redistributions in binary form must reproduce the above copyright
     23  *    notice, this list of conditions and the following disclaimer in the
     24  *    documentation and/or other materials provided with the distribution.
     25  * 3. Neither the name of the University nor the names of its contributors
     26  *    may be used to endorse or promote products derived from this software
     27  *    without specific prior written permission.
     28  *
     29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     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
     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
     39  * SUCH DAMAGE.
     40  *
     41  *	from: @(#)gram.y	8.1 (Berkeley) 6/6/93
     42  */
     43 
     44 #include <sys/cdefs.h>
     45 __RCSID("$NetBSD: gram.y,v 1.55 2020/03/07 19:26:13 christos Exp $");
     46 
     47 #include <sys/types.h>
     48 #include <sys/param.h>
     49 #include <ctype.h>
     50 #include <stdio.h>
     51 #include <stdlib.h>
     52 #include <string.h>
     53 #include <errno.h>
     54 #include "defs.h"
     55 #include "sem.h"
     56 
     57 #define	FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
     58     ((n).fmt == 16) ? "0x%llx" : "%lld")
     59 
     60 #define	stop(s)	cfgerror(s), exit(1)
     61 
     62 static	struct	config conf;	/* at most one active at a time */
     63 static	int	nowarn;		/* if warning suppression is on */
     64 
     65 
     66 /*
     67  * Allocation wrapper functions
     68  */
     69 static void wrap_alloc(void *ptr, unsigned code);
     70 static void wrap_continue(void);
     71 static void wrap_cleanup(void);
     72 
     73 /*
     74  * Allocation wrapper type codes
     75  */
     76 #define WRAP_CODE_nvlist	1
     77 #define WRAP_CODE_defoptlist	2
     78 #define WRAP_CODE_loclist	3
     79 #define WRAP_CODE_attrlist	4
     80 #define WRAP_CODE_condexpr	5
     81 
     82 /*
     83  * The allocation wrappers themselves
     84  */
     85 #define DECL_ALLOCWRAP(t)	static struct t *wrap_mk_##t(struct t *arg)
     86 
     87 DECL_ALLOCWRAP(nvlist);
     88 DECL_ALLOCWRAP(defoptlist);
     89 DECL_ALLOCWRAP(loclist);
     90 DECL_ALLOCWRAP(attrlist);
     91 DECL_ALLOCWRAP(condexpr);
     92 
     93 /* allow shorter names */
     94 #define wrap_mk_loc(p) wrap_mk_loclist(p)
     95 #define wrap_mk_cx(p) wrap_mk_condexpr(p)
     96 
     97 /*
     98  * Macros for allocating new objects
     99  */
    100 
    101 /* old-style for struct nvlist */
    102 #define	new0(n,s,p,i,x)	wrap_mk_nvlist(newnv(n, s, p, i, x))
    103 #define	new_n(n)	new0(n, NULL, NULL, 0, NULL)
    104 #define	new_nx(n, x)	new0(n, NULL, NULL, 0, x)
    105 #define	new_ns(n, s)	new0(n, s, NULL, 0, NULL)
    106 #define	new_si(s, i)	new0(NULL, s, NULL, i, NULL)
    107 #define	new_spi(s, p, i)	new0(NULL, s, p, i, NULL)
    108 #define	new_nsi(n,s,i)	new0(n, s, NULL, i, NULL)
    109 #define	new_np(n, p)	new0(n, NULL, p, 0, NULL)
    110 #define	new_s(s)	new0(NULL, s, NULL, 0, NULL)
    111 #define	new_p(p)	new0(NULL, NULL, p, 0, NULL)
    112 #define	new_px(p, x)	new0(NULL, NULL, p, 0, x)
    113 #define	new_sx(s, x)	new0(NULL, s, NULL, 0, x)
    114 #define	new_nsx(n,s,x)	new0(n, s, NULL, 0, x)
    115 #define	new_i(i)	new0(NULL, NULL, NULL, i, NULL)
    116 
    117 /* new style, type-polymorphic; ordinary and for types with multiple flavors */
    118 #define MK0(t)		wrap_mk_##t(mk_##t())
    119 #define MK1(t, a0)	wrap_mk_##t(mk_##t(a0))
    120 #define MK2(t, a0, a1)	wrap_mk_##t(mk_##t(a0, a1))
    121 #define MK3(t, a0, a1, a2)	wrap_mk_##t(mk_##t(a0, a1, a2))
    122 
    123 #define MKF0(t, f)		wrap_mk_##t(mk_##t##_##f())
    124 #define MKF1(t, f, a0)		wrap_mk_##t(mk_##t##_##f(a0))
    125 #define MKF2(t, f, a0, a1)	wrap_mk_##t(mk_##t##_##f(a0, a1))
    126 
    127 /*
    128  * Data constructors
    129  */
    130 
    131 static struct defoptlist *mk_defoptlist(const char *, const char *,
    132 					const char *);
    133 static struct loclist *mk_loc(const char *, const char *, long long);
    134 static struct loclist *mk_loc_val(const char *, struct loclist *);
    135 static struct attrlist *mk_attrlist(struct attrlist *, struct attr *);
    136 static struct condexpr *mk_cx_atom(const char *);
    137 static struct condexpr *mk_cx_not(struct condexpr *);
    138 static struct condexpr *mk_cx_and(struct condexpr *, struct condexpr *);
    139 static struct condexpr *mk_cx_or(struct condexpr *, struct condexpr *);
    140 
    141 /*
    142  * Other private functions
    143  */
    144 
    145 static	void	setmachine(const char *, const char *, struct nvlist *, int);
    146 static	void	check_maxpart(void);
    147 
    148 static struct loclist *present_loclist(struct loclist *ll);
    149 static void app(struct loclist *, struct loclist *);
    150 static struct loclist *locarray(const char *, int, struct loclist *, int);
    151 static struct loclist *namelocvals(const char *, struct loclist *);
    152 
    153 %}
    154 
    155 %union {
    156 	struct	attr *attr;
    157 	struct	devbase *devb;
    158 	struct	deva *deva;
    159 	struct	nvlist *list;
    160 	struct defoptlist *defoptlist;
    161 	struct loclist *loclist;
    162 	struct attrlist *attrlist;
    163 	struct condexpr *condexpr;
    164 	const char *str;
    165 	struct	numconst num;
    166 	int64_t	val;
    167 	u_char	flag;
    168 	devmajor_t devmajor;
    169 	int32_t i32;
    170 }
    171 
    172 %token	AND AT ATTACH
    173 %token	BLOCK BUILD
    174 %token	CHAR COLONEQ COMPILE_WITH CONFIG
    175 %token	DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
    176 %token	DEVICE DEVCLASS DUMPS DEVICE_MAJOR
    177 %token	ENDFILE
    178 %token	XFILE FILE_SYSTEM FLAGS
    179 %token	IDENT IOCONF
    180 %token	LINKZERO
    181 %token	XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
    182 %token	NEEDS_COUNT NEEDS_FLAG NO CNO
    183 %token	XOBJECT OBSOLETE ON OPTIONS
    184 %token	PACKAGE PLUSEQ PREFIX BUILDPREFIX PSEUDO_DEVICE PSEUDO_ROOT
    185 %token	ROOT
    186 %token	SELECT SINGLE SOURCE
    187 %token	TYPE
    188 %token	VECTOR VERSION
    189 %token	WITH
    190 %token	<num> NUMBER
    191 %token	<str> PATHNAME QSTRING WORD EMPTYSTRING
    192 %token	ENDDEFS
    193 
    194 %type	<condexpr>	fopts condexpr condatom
    195 %type	<condexpr>	cond_or_expr cond_and_expr cond_prefix_expr
    196 %type	<condexpr>	 cond_base_expr
    197 %type	<str>	fs_spec
    198 %type	<flag>	fflags fflag oflags oflag
    199 %type	<str>	rule
    200 %type	<attr>	depend
    201 %type	<devb>	devbase
    202 %type	<deva>	devattach_opt
    203 %type	<list>	atlist
    204 %type	<loclist> interface_opt
    205 %type	<str>	atname
    206 %type	<loclist>	loclist locdef
    207 %type	<str>	locdefault
    208 %type	<loclist>	values locdefaults
    209 %type	<attrlist>	depend_list depends
    210 %type	<loclist>	locators locator
    211 %type	<list>	dev_spec
    212 %type	<str>	device_instance
    213 %type	<str>	attachment
    214 %type	<str>	value
    215 %type	<val>	major_minor
    216 %type	<num>	signed_number
    217 %type	<i32>	int32 npseudo device_flags no
    218 %type	<str>	deffs
    219 %type	<list>	deffses
    220 %type	<defoptlist>	defopt
    221 %type	<defoptlist>	defopts
    222 %type	<str>	optdepend
    223 %type	<list>	optdepends
    224 %type	<list>	optdepend_list
    225 %type	<str>	optfile_opt
    226 %type	<list>	subarches
    227 %type	<str>	filename stringvalue locname mkvarname
    228 %type	<devmajor>	device_major_block device_major_char
    229 %type	<list>	devnodes devnodetype devnodeflags devnode_dims
    230 
    231 %%
    232 
    233 /*
    234  * A complete configuration consists of both the selection part (a
    235  * kernel config such as GENERIC or SKYNET, plus also the various
    236  * std.* files), which selects the material to be in the kernel, and
    237  * also the definition part (files, files.*, etc.) that declares what
    238  * material is available to be placed in kernels.
    239  *
    240  * The two parts have almost entirely separate syntaxes. This grammar
    241  * covers both of them. When config is run on a kernel configuration
    242  * file, the std.* file for the port is included explicitly. The
    243  * files.* files are included implicitly when the std.* file declares
    244  * the machine type.
    245  *
    246  * The machine spec, which brings in the definition part, must appear
    247  * before all configuration material except for the "topthings"; these
    248  * are the "source" and "build" declarations that tell config where
    249  * things are. These are not used by default.
    250  *
    251  * A previous version of this comment contained the following text:
    252  *
    253  *       Note that we do not have sufficient keywords to enforce any
    254  *       order between elements of "topthings" without introducing
    255  *       shift/reduce conflicts.  Instead, check order requirements in
    256  *       the C code.
    257  *
    258  * As of March 2012 this comment makes no sense, as there are only two
    259  * topthings and no reason for them to be forcibly ordered.
    260  * Furthermore, the statement about conflicts is false.
    261  */
    262 
    263 /* Complete configuration. */
    264 configuration:
    265 	topthings machine_spec definition_part selection_part
    266 ;
    267 
    268 /* Sequence of zero or more topthings. */
    269 topthings:
    270 	  /* empty */
    271 	| topthings topthing
    272 ;
    273 
    274 /* Directory specification. */
    275 topthing:
    276 	                  '\n'
    277 	| SOURCE filename '\n'		{ if (!srcdir) srcdir = $2; }
    278 	| BUILD  filename '\n'		{ if (!builddir) builddir = $2; }
    279 ;
    280 
    281 /* "machine foo" from std.whatever */
    282 machine_spec:
    283 	  XMACHINE WORD '\n'			{ setmachine($2,NULL,NULL,0); }
    284 	| XMACHINE WORD WORD '\n'		{ setmachine($2,$3,NULL,0); }
    285 	| XMACHINE WORD WORD subarches '\n'	{ setmachine($2,$3,$4,0); }
    286 	| IOCONF WORD '\n'			{ setmachine($2,NULL,NULL,1); }
    287 	| error { stop("cannot proceed without machine or ioconf specifier"); }
    288 ;
    289 
    290 /* One or more sub-arches. */
    291 subarches:
    292 	  WORD				{ $$ = new_n($1); }
    293 	| subarches WORD		{ $$ = new_nx($2, $1); }
    294 ;
    295 
    296 no:
    297 	  NO	{ $$ = 0; }
    298 	| CNO	{ $$ = 1; }
    299 ;
    300 
    301 /************************************************************/
    302 
    303 /*
    304  * The machine definitions grammar.
    305  */
    306 
    307 /* Complete definition part: the contents of all files.* files. */
    308 definition_part:
    309 	definitions ENDDEFS		{ check_maxpart(); check_version(); }
    310 ;
    311 
    312 /* Zero or more definitions. Trap errors. */
    313 definitions:
    314 	  /* empty */
    315 	| definitions '\n'
    316 	| definitions definition '\n'	{ wrap_continue(); }
    317 	| definitions error '\n'	{ wrap_cleanup(); }
    318 	| definitions ENDFILE		{ enddefs(); checkfiles(); }
    319 ;
    320 
    321 /* A single definition. */
    322 definition:
    323 	  define_file
    324 	| define_object
    325 	| define_device_major
    326 	| define_prefix
    327 	| define_buildprefix
    328 	| define_devclass
    329 	| define_filesystems
    330 	| define_attribute
    331 	| define_option
    332 	| define_flag
    333 	| define_obsolete_flag
    334 	| define_param
    335 	| define_obsolete_param
    336 	| define_device
    337 	| define_device_attachment
    338 	| define_maxpartitions
    339 	| define_maxusers
    340 	| define_makeoptions
    341 	| define_pseudo
    342 	| define_pseudodev
    343 	| define_major
    344 	| define_version
    345 ;
    346 
    347 /* source file: file foo/bar.c bar|baz needs-flag compile-with blah */
    348 define_file:
    349 	XFILE filename fopts fflags rule	{ addfile($2, $3, $4, $5); }
    350 ;
    351 
    352 /* object file: object zot.o foo|zot needs-flag */
    353 define_object:
    354 	XOBJECT filename fopts oflags	{ addfile($2, $3, $4, NULL); }
    355 ;
    356 
    357 /* device major declaration */
    358 define_device_major:
    359 	DEVICE_MAJOR WORD device_major_char device_major_block fopts devnodes
    360 					{
    361 		adddevm($2, $3, $4, $5, $6);
    362 		do_devsw = 1;
    363 	}
    364 ;
    365 
    366 /* prefix delimiter */
    367 define_prefix:
    368 	  PREFIX filename		{ prefix_push($2); }
    369 	| PREFIX			{ prefix_pop(); }
    370 ;
    371 
    372 define_buildprefix:
    373 	  BUILDPREFIX filename		{ buildprefix_push($2); }
    374 	| BUILDPREFIX WORD		{ buildprefix_push($2); }
    375 	| BUILDPREFIX			{ buildprefix_pop(); }
    376 ;
    377 
    378 define_devclass:
    379 	DEVCLASS WORD			{ (void)defdevclass($2, NULL, NULL, 1); }
    380 ;
    381 
    382 define_filesystems:
    383 	DEFFS deffses optdepend_list	{ deffilesystem($2, $3); }
    384 ;
    385 
    386 define_attribute:
    387 	DEFINE WORD interface_opt depend_list
    388 					{ (void)defattr0($2, $3, $4, 0); }
    389 ;
    390 
    391 define_option:
    392 	DEFOPT optfile_opt defopts optdepend_list
    393 					{ defoption($2, $3, $4); }
    394 ;
    395 
    396 define_flag:
    397 	DEFFLAG optfile_opt defopts optdepend_list
    398 					{ defflag($2, $3, $4, 0); }
    399 ;
    400 
    401 define_obsolete_flag:
    402 	OBSOLETE DEFFLAG optfile_opt defopts
    403 					{ defflag($3, $4, NULL, 1); }
    404 ;
    405 
    406 define_param:
    407 	DEFPARAM optfile_opt defopts optdepend_list
    408 					{ defparam($2, $3, $4, 0); }
    409 ;
    410 
    411 define_obsolete_param:
    412 	OBSOLETE DEFPARAM optfile_opt defopts
    413 					{ defparam($3, $4, NULL, 1); }
    414 ;
    415 
    416 define_device:
    417 	DEVICE devbase interface_opt depend_list
    418 					{ defdev($2, $3, $4, 0); }
    419 ;
    420 
    421 define_device_attachment:
    422 	ATTACH devbase AT atlist devattach_opt depend_list
    423 					{ defdevattach($5, $2, $4, $6); }
    424 ;
    425 
    426 define_maxpartitions:
    427 	MAXPARTITIONS int32		{ maxpartitions = $2; }
    428 ;
    429 
    430 define_maxusers:
    431 	MAXUSERS int32 int32 int32
    432 					{ setdefmaxusers($2, $3, $4); }
    433 ;
    434 
    435 define_makeoptions:
    436 	MAKEOPTIONS condmkopt_list
    437 ;
    438 
    439 define_pseudo:
    440 	/* interface_opt in DEFPSEUDO is for backwards compatibility */
    441 	DEFPSEUDO devbase interface_opt depend_list
    442 					{ defdev($2, $3, $4, 1); }
    443 ;
    444 
    445 define_pseudodev:
    446 	DEFPSEUDODEV devbase interface_opt depend_list
    447 					{ defdev($2, $3, $4, 2); }
    448 ;
    449 
    450 define_major:
    451 	MAJOR '{' majorlist '}'
    452 ;
    453 
    454 define_version:
    455 	VERSION int32		{ setversion($2); }
    456 ;
    457 
    458 /* file options: optional expression of conditions */
    459 fopts:
    460 	  /* empty */			{ $$ = NULL; }
    461 	| condexpr			{ $$ = $1; }
    462 ;
    463 
    464 /* zero or more flags for a file */
    465 fflags:
    466 	  /* empty */			{ $$ = 0; }
    467 	| fflags fflag			{ $$ = $1 | $2; }
    468 ;
    469 
    470 /* one flag for a file */
    471 fflag:
    472 	  NEEDS_COUNT			{ $$ = FI_NEEDSCOUNT; }
    473 	| NEEDS_FLAG			{ $$ = FI_NEEDSFLAG; }
    474 ;
    475 
    476 /* extra compile directive for a source file */
    477 rule:
    478 	  /* empty */			{ $$ = NULL; }
    479 	| COMPILE_WITH stringvalue	{ $$ = $2; }
    480 ;
    481 
    482 /* zero or more flags for an object file */
    483 oflags:
    484 	  /* empty */			{ $$ = 0; }
    485 	| oflags oflag			{ $$ = $1 | $2; }
    486 ;
    487 
    488 /* a single flag for an object file */
    489 oflag:
    490 	NEEDS_FLAG			{ $$ = FI_NEEDSFLAG; }
    491 ;
    492 
    493 /* char 55 */
    494 device_major_char:
    495 	  /* empty */			{ $$ = -1; }
    496 	| CHAR int32			{ $$ = $2; }
    497 ;
    498 
    499 /* block 33 */
    500 device_major_block:
    501 	  /* empty */			{ $$ = -1; }
    502 	| BLOCK int32			{ $$ = $2; }
    503 ;
    504 
    505 /* device node specification */
    506 devnodes:
    507 	  /* empty */			{ $$ = new_s("DEVNODE_DONTBOTHER"); }
    508 	| devnodetype ',' devnodeflags	{ $$ = nvcat($1, $3); }
    509 	| devnodetype			{ $$ = $1; }
    510 ;
    511 
    512 /* device nodes without flags */
    513 devnodetype:
    514 	  SINGLE			{ $$ = new_s("DEVNODE_SINGLE"); }
    515 	| VECTOR '=' devnode_dims  { $$ = nvcat(new_s("DEVNODE_VECTOR"), $3); }
    516 ;
    517 
    518 /* dimensions (?) */
    519 devnode_dims:
    520 	  NUMBER			{ $$ = new_i($1.val); }
    521 	| NUMBER ':' NUMBER		{
    522 		struct nvlist *__nv1, *__nv2;
    523 
    524 		__nv1 = new_i($1.val);
    525 		__nv2 = new_i($3.val);
    526 		$$ = nvcat(__nv1, __nv2);
    527 	  }
    528 ;
    529 
    530 /* flags for device nodes */
    531 devnodeflags:
    532 	LINKZERO			{ $$ = new_s("DEVNODE_FLAG_LINKZERO");}
    533 ;
    534 
    535 /* one or more file system names */
    536 deffses:
    537 	  deffs				{ $$ = new_n($1); }
    538 	| deffses deffs			{ $$ = new_nx($2, $1); }
    539 ;
    540 
    541 /* a single file system name */
    542 deffs:
    543 	WORD				{ $$ = $1; }
    544 ;
    545 
    546 /* optional locator specification */
    547 interface_opt:
    548 	  /* empty */			{ $$ = NULL; }
    549 	| '{' '}'			{ $$ = present_loclist(NULL); }
    550 	| '{' loclist '}'		{ $$ = present_loclist($2); }
    551 ;
    552 
    553 /*
    554  * loclist order matters, must use right recursion
    555  * XXX wot?
    556  */
    557 
    558 /* list of locator definitions */
    559 loclist:
    560 	  locdef			{ $$ = $1; }
    561 	| locdef ',' loclist		{ $$ = $1; app($1, $3); }
    562 ;
    563 
    564 /*
    565  * "[ WORD locdefault ]" syntax may be unnecessary...
    566  */
    567 
    568 /* one locator definition */
    569 locdef:
    570 	  locname locdefault 		{ $$ = MK3(loc, $1, $2, 0); }
    571 	| locname			{ $$ = MK3(loc, $1, NULL, 0); }
    572 	| '[' locname locdefault ']'	{ $$ = MK3(loc, $2, $3, 1); }
    573 	| locname '[' int32 ']'	{ $$ = locarray($1, $3, NULL, 0); }
    574 	| locname '[' int32 ']' locdefaults
    575 					{ $$ = locarray($1, $3, $5, 0); }
    576 	| '[' locname '[' int32 ']' locdefaults ']'
    577 					{ $$ = locarray($2, $4, $6, 1); }
    578 ;
    579 
    580 /* locator name */
    581 locname:
    582 	  WORD				{ $$ = $1; }
    583 	| QSTRING			{ $$ = $1; }
    584 ;
    585 
    586 /* locator default value */
    587 locdefault:
    588 	'=' value			{ $$ = $2; }
    589 ;
    590 
    591 /* multiple locator default values */
    592 locdefaults:
    593 	'=' '{' values '}'		{ $$ = $3; }
    594 ;
    595 
    596 /* list of depends, may be empty */
    597 depend_list:
    598 	  /* empty */			{ $$ = NULL; }
    599 	| ':' depends			{ $$ = $2; }
    600 ;
    601 
    602 /* one or more depend items */
    603 depends:
    604 	  depend			{ $$ = MK2(attrlist, NULL, $1); }
    605 	| depends ',' depend		{ $$ = MK2(attrlist, $1, $3); }
    606 ;
    607 
    608 /* one depend item (which is an attribute) */
    609 depend:
    610 	WORD				{ $$ = refattr($1); }
    611 ;
    612 
    613 /* list of option depends, may be empty */
    614 optdepend_list:
    615 	  /* empty */			{ $$ = NULL; }
    616 	| ':' optdepends		{ $$ = $2; }
    617 ;
    618 
    619 /* a list of option dependencies */
    620 optdepends:
    621 	  optdepend			{ $$ = new_n($1); }
    622 	| optdepends ',' optdepend	{ $$ = new_nx($3, $1); }
    623 ;
    624 
    625 /* one option depend, which is an option name */
    626 optdepend:
    627 	WORD				{ $$ = $1; }
    628 ;
    629 
    630 
    631 /* list of places to attach: attach blah at ... */
    632 atlist:
    633 	  atname			{ $$ = new_n($1); }
    634 	| atlist ',' atname		{ $$ = new_nx($3, $1); }
    635 ;
    636 
    637 /* a place to attach a device */
    638 atname:
    639 	  WORD				{ $$ = $1; }
    640 	| ROOT				{ $$ = NULL; }
    641 ;
    642 
    643 /* one or more defined options */
    644 defopts:
    645 	  defopt			{ $$ = $1; }
    646 	| defopts defopt		{ $$ = defoptlist_append($2, $1); }
    647 ;
    648 
    649 /* one defined option */
    650 defopt:
    651 	  WORD				{ $$ = MK3(defoptlist, $1, NULL, NULL); }
    652 	| WORD '=' value		{ $$ = MK3(defoptlist, $1, $3, NULL); }
    653 	| WORD COLONEQ value		{ $$ = MK3(defoptlist, $1, NULL, $3); }
    654 	| WORD '=' value COLONEQ value	{ $$ = MK3(defoptlist, $1, $3, $5); }
    655 ;
    656 
    657 /* list of conditional makeoptions */
    658 condmkopt_list:
    659 	  condmkoption
    660 	| condmkopt_list ',' condmkoption
    661 ;
    662 
    663 /* one conditional make option */
    664 condmkoption:
    665 	condexpr mkvarname PLUSEQ value	{ appendcondmkoption($1, $2, $4); }
    666 ;
    667 
    668 /* device name */
    669 devbase:
    670 	WORD				{ $$ = getdevbase($1); }
    671 ;
    672 
    673 /* optional attachment: with foo */
    674 devattach_opt:
    675 	  /* empty */			{ $$ = NULL; }
    676 	| WITH WORD			{ $$ = getdevattach($2); }
    677 ;
    678 
    679 /* list of major numbers */
    680 /* XXX why is this right-recursive? */
    681 majorlist:
    682 	  majordef
    683 	| majorlist ',' majordef
    684 ;
    685 
    686 /* one major number */
    687 majordef:
    688 	devbase '=' int32		{ setmajor($1, $3); }
    689 ;
    690 
    691 int32:
    692 	NUMBER	{
    693 		if ($1.val > INT_MAX || $1.val < INT_MIN)
    694 			cfgerror("overflow %" PRId64, $1.val);
    695 		else
    696 			$$ = (int32_t)$1.val;
    697 	}
    698 ;
    699 
    700 /************************************************************/
    701 
    702 /*
    703  * The selection grammar.
    704  */
    705 
    706 /* Complete selection part: all std.* files plus selected config. */
    707 selection_part:
    708 	selections
    709 ;
    710 
    711 /* Zero or more config items. Trap errors. */
    712 selections:
    713 	  /* empty */
    714 	| selections '\n'
    715 	| selections selection '\n'	{ wrap_continue(); }
    716 	| selections error '\n'		{ wrap_cleanup(); }
    717 ;
    718 
    719 /* One config item. */
    720 selection:
    721 	  definition
    722 	| select_attr
    723 	| select_no_attr
    724 	| select_no_filesystems
    725 	| select_filesystems
    726 	| select_no_makeoptions
    727 	| select_makeoptions
    728 	| select_no_options
    729 	| select_options
    730 	| select_maxusers
    731 	| select_ident
    732 	| select_no_ident
    733 	| select_config
    734 	| select_no_config
    735 	| select_no_pseudodev
    736 	| select_pseudodev
    737 	| select_pseudoroot
    738 	| select_no_device_instance_attachment
    739 	| select_no_device_attachment
    740 	| select_no_device_instance
    741 	| select_device_instance
    742 ;
    743 
    744 select_attr:
    745 	SELECT WORD			{ addattr($2); }
    746 ;
    747 
    748 select_no_attr:
    749 	no SELECT WORD			{ delattr($3, $1); }
    750 ;
    751 
    752 select_no_filesystems:
    753 	no FILE_SYSTEM { nowarn = $1; } no_fs_list { nowarn = 0; }
    754 ;
    755 
    756 select_filesystems:
    757 	FILE_SYSTEM fs_list
    758 ;
    759 
    760 select_no_makeoptions:
    761 	no MAKEOPTIONS { nowarn = $1; } no_mkopt_list { nowarn = 0; }
    762 ;
    763 
    764 select_makeoptions:
    765 	MAKEOPTIONS mkopt_list
    766 ;
    767 
    768 select_no_options:
    769 	no OPTIONS { nowarn = $1; } no_opt_list { nowarn = 0; }
    770 ;
    771 
    772 select_options:
    773 	OPTIONS opt_list
    774 ;
    775 
    776 select_maxusers:
    777 	MAXUSERS int32			{ setmaxusers($2); }
    778 ;
    779 
    780 select_ident:
    781 	IDENT stringvalue		{ setident($2); }
    782 ;
    783 
    784 select_no_ident:
    785 	no IDENT			{ setident(NULL); }
    786 ;
    787 
    788 select_config:
    789 	CONFIG conf root_spec sysparam_list
    790 					{ addconf(&conf); }
    791 ;
    792 
    793 select_no_config:
    794 	no CONFIG WORD			{ delconf($3, $1); }
    795 ;
    796 
    797 select_no_pseudodev:
    798 	no PSEUDO_DEVICE WORD		{ delpseudo($3, $1); }
    799 ;
    800 
    801 select_pseudodev:
    802 	PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); }
    803 ;
    804 
    805 select_pseudoroot:
    806 	PSEUDO_ROOT device_instance	{ addpseudoroot($2); }
    807 ;
    808 
    809 select_no_device_instance_attachment:
    810 	no device_instance AT attachment
    811 					{ deldevi($2, $4, $1); }
    812 ;
    813 
    814 select_no_device_attachment:
    815 	no DEVICE AT attachment		{ deldeva($4, $1); }
    816 ;
    817 
    818 select_no_device_instance:
    819 	no device_instance		{ deldev($2, $1); }
    820 ;
    821 
    822 select_device_instance:
    823 	device_instance AT attachment locators device_flags
    824 					{ adddev($1, $3, $4, $5); }
    825 ;
    826 
    827 /* list of filesystems */
    828 fs_list:
    829 	  fsoption
    830 	| fs_list ',' fsoption
    831 ;
    832 
    833 /* one filesystem */
    834 fsoption:
    835 	WORD				{ addfsoption($1); }
    836 ;
    837 
    838 /* list of filesystems that had NO in front */
    839 no_fs_list:
    840 	  no_fsoption
    841 	| no_fs_list ',' no_fsoption
    842 ;
    843 
    844 /* one filesystem that had NO in front */
    845 no_fsoption:
    846 	WORD				{ delfsoption($1, nowarn); }
    847 ;
    848 
    849 /* list of make options */
    850 /* XXX why is this right-recursive? */
    851 mkopt_list:
    852 	  mkoption
    853 	| mkopt_list ',' mkoption
    854 ;
    855 
    856 /* one make option */
    857 mkoption:
    858 	  mkvarname '=' value		{ addmkoption($1, $3); }
    859 	| mkvarname PLUSEQ value	{ appendmkoption($1, $3); }
    860 ;
    861 
    862 /* list of make options that had NO in front */
    863 no_mkopt_list:
    864 	  no_mkoption
    865 	| no_mkopt_list ',' no_mkoption
    866 ;
    867 
    868 /* one make option that had NO in front */
    869 /* XXX shouldn't this be mkvarname rather than WORD? */
    870 no_mkoption:
    871 	WORD				{ delmkoption($1, nowarn); }
    872 ;
    873 
    874 /* list of options */
    875 opt_list:
    876 	  option
    877 	| opt_list ',' option
    878 ;
    879 
    880 /* one option */
    881 option:
    882 	  WORD				{ addoption($1, NULL); }
    883 	| WORD '=' value		{ addoption($1, $3); }
    884 ;
    885 
    886 /* list of options that had NO in front */
    887 no_opt_list:
    888 	  no_option
    889 	| no_opt_list ',' no_option
    890 ;
    891 
    892 /* one option that had NO in front */
    893 no_option:
    894 	WORD				{ deloption($1, nowarn); }
    895 ;
    896 
    897 /* the name in "config name root on ..." */
    898 conf:
    899 	WORD				{
    900 		conf.cf_name = $1;
    901 		conf.cf_where.w_srcline = currentline();
    902 		conf.cf_fstype = NULL;
    903 		conf.cf_root = NULL;
    904 		conf.cf_dump = NULL;
    905 	}
    906 ;
    907 
    908 /* root fs specification */
    909 root_spec:
    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); }
    912 ;
    913 
    914 /* device for root fs or dump */
    915 dev_spec:
    916 	  '?'				{ $$ = new_spi(intern("?"),
    917 					    NULL,
    918 					    (long long)NODEV); }
    919 	| QSTRING			{ $$ = new_spi($1,
    920 					    __UNCONST("spec"),
    921 					    (long long)NODEV); }
    922 	| WORD				{ $$ = new_spi($1,
    923 					    NULL,
    924 					    (long long)NODEV); }
    925 	| major_minor			{ $$ = new_si(NULL, $1); }
    926 ;
    927 
    928 /* major and minor device number */
    929 major_minor:
    930 	MAJOR NUMBER MINOR NUMBER	{ $$ = (int64_t)makedev($2.val, $4.val); }
    931 ;
    932 
    933 /* filesystem type for root fs specification */
    934 fs_spec:
    935 	  TYPE '?'		   { setfstype(&conf.cf_fstype, intern("?")); }
    936 	| TYPE WORD			{ setfstype(&conf.cf_fstype, $2); }
    937 ;
    938 
    939 /* zero or more additional system parameters */
    940 sysparam_list:
    941 	  /* empty */
    942 	| sysparam_list sysparam
    943 ;
    944 
    945 /* one additional system parameter (there's only one: dumps) */
    946 sysparam:
    947 	DUMPS on_opt dev_spec	       { setconf(&conf.cf_dump, "dumps", $3); }
    948 ;
    949 
    950 /* number of pseudo devices to configure (which is optional) */
    951 npseudo:
    952 	  /* empty */			{ $$ = 1; }
    953 	| int32				{ $$ = $1; }
    954 ;
    955 
    956 /* name of a device to configure */
    957 device_instance:
    958 	  WORD				{ $$ = $1; }
    959 	| WORD '*'			{ $$ = starref($1); }
    960 ;
    961 
    962 /* name of a device to configure an attachment to */
    963 attachment:
    964 	  ROOT				{ $$ = NULL; }
    965 	| WORD				{ $$ = $1; }
    966 	| WORD '?'			{ $$ = wildref($1); }
    967 ;
    968 
    969 /* zero or more locators */
    970 locators:
    971 	  /* empty */			{ $$ = NULL; }
    972 	| locators locator		{ $$ = $2; app($2, $1); }
    973 ;
    974 
    975 /* one locator */
    976 locator:
    977 	  WORD '?'			{ $$ = MK3(loc, $1, NULL, 0); }
    978 	| WORD values			{ $$ = namelocvals($1, $2); }
    979 ;
    980 
    981 /* optional device flags */
    982 device_flags:
    983 	  /* empty */			{ $$ = 0; }
    984 	| FLAGS int32			{ $$ = $2; }
    985 ;
    986 
    987 /************************************************************/
    988 
    989 /*
    990  * conditions
    991  */
    992 
    993 
    994 /*
    995  * order of options is important, must use right recursion
    996  *
    997  * dholland 20120310: wut?
    998  */
    999 
   1000 /* expression of conditions */
   1001 condexpr:
   1002 	cond_or_expr
   1003 ;
   1004 
   1005 cond_or_expr:
   1006 	  cond_and_expr
   1007 	| cond_or_expr '|' cond_and_expr	{ $$ = MKF2(cx, or, $1, $3); }
   1008 ;
   1009 
   1010 cond_and_expr:
   1011 	  cond_prefix_expr
   1012 	| cond_and_expr '&' cond_prefix_expr	{ $$ = MKF2(cx, and, $1, $3); }
   1013 ;
   1014 
   1015 cond_prefix_expr:
   1016 	  cond_base_expr
   1017 /* XXX notyet - need to strengthen downstream first */
   1018 /*	| '!' cond_prefix_expr			{ $$ = MKF1(cx, not, $2); } */
   1019 ;
   1020 
   1021 cond_base_expr:
   1022 	  condatom			{ $$ = $1; }
   1023 	| '!' condatom			{ $$ = MKF1(cx, not, $2); }
   1024 	| '(' condexpr ')'		{ $$ = $2; }
   1025 ;
   1026 
   1027 /* basic element of config element expression: a config element */
   1028 condatom:
   1029 	WORD				{ $$ = MKF1(cx, atom, $1); }
   1030 ;
   1031 
   1032 /************************************************************/
   1033 
   1034 /*
   1035  * Various nonterminals shared between the grammars.
   1036  */
   1037 
   1038 /* variable name for make option */
   1039 mkvarname:
   1040 	  QSTRING			{ $$ = $1; }
   1041 	| WORD				{ $$ = $1; }
   1042 ;
   1043 
   1044 /* optional file for an option */
   1045 optfile_opt:
   1046 	  /* empty */			{ $$ = NULL; }
   1047 	| filename			{ $$ = $1; }
   1048 ;
   1049 
   1050 /* filename. */
   1051 filename:
   1052 	  QSTRING			{ $$ = $1; }
   1053 	| PATHNAME			{ $$ = $1; }
   1054 ;
   1055 
   1056 /* constant value */
   1057 value:
   1058 	  QSTRING			{ $$ = $1; }
   1059 	| WORD				{ $$ = $1; }
   1060 	| EMPTYSTRING			{ $$ = $1; }
   1061 	| signed_number			{
   1062 		char bf[40];
   1063 
   1064 		(void)snprintf(bf, sizeof(bf), FORMAT($1), (long long)$1.val);
   1065 		$$ = intern(bf);
   1066 	  }
   1067 ;
   1068 
   1069 /* constant value that is a string */
   1070 stringvalue:
   1071 	  QSTRING			{ $$ = $1; }
   1072 	| WORD				{ $$ = $1; }
   1073 ;
   1074 
   1075 /* comma-separated list of values */
   1076 /* XXX why right-recursive? */
   1077 values:
   1078 	  value				{ $$ = MKF2(loc, val, $1, NULL); }
   1079 	| value ',' values		{ $$ = MKF2(loc, val, $1, $3); }
   1080 ;
   1081 
   1082 /* possibly negative number */
   1083 signed_number:
   1084 	  NUMBER			{ $$ = $1; }
   1085 	| '-' NUMBER			{ $$.fmt = $2.fmt; $$.val = -$2.val; }
   1086 ;
   1087 
   1088 /* optional ON keyword */
   1089 on_opt:
   1090 	  /* empty */
   1091 	| ON
   1092 ;
   1093 
   1094 %%
   1095 
   1096 void
   1097 yyerror(const char *s)
   1098 {
   1099 
   1100 	cfgerror("%s", s);
   1101 }
   1102 
   1103 /************************************************************/
   1104 
   1105 /*
   1106  * Wrap allocations that live on the parser stack so that we can free
   1107  * them again on error instead of leaking.
   1108  */
   1109 
   1110 #define MAX_WRAP 1000
   1111 
   1112 struct wrap_entry {
   1113 	void *ptr;
   1114 	unsigned typecode;
   1115 };
   1116 
   1117 static struct wrap_entry wrapstack[MAX_WRAP];
   1118 static unsigned wrap_depth;
   1119 
   1120 /*
   1121  * Remember pointer PTR with type-code CODE.
   1122  */
   1123 static void
   1124 wrap_alloc(void *ptr, unsigned code)
   1125 {
   1126 	unsigned pos;
   1127 
   1128 	if (wrap_depth >= MAX_WRAP) {
   1129 		panic("allocation wrapper stack overflow");
   1130 	}
   1131 	pos = wrap_depth++;
   1132 	wrapstack[pos].ptr = ptr;
   1133 	wrapstack[pos].typecode = code;
   1134 }
   1135 
   1136 /*
   1137  * We succeeded; commit to keeping everything that's been allocated so
   1138  * far and clear the stack.
   1139  */
   1140 static void
   1141 wrap_continue(void)
   1142 {
   1143 	wrap_depth = 0;
   1144 }
   1145 
   1146 /*
   1147  * We failed; destroy all the objects allocated.
   1148  */
   1149 static void
   1150 wrap_cleanup(void)
   1151 {
   1152 	unsigned i;
   1153 
   1154 	/*
   1155 	 * Destroy each item. Note that because everything allocated
   1156 	 * is entered on the list separately, lists and trees need to
   1157 	 * have their links blanked before being destroyed. Also note
   1158 	 * that strings are interned elsewhere and not handled by this
   1159 	 * mechanism.
   1160 	 */
   1161 
   1162 	for (i=0; i<wrap_depth; i++) {
   1163 		switch (wrapstack[i].typecode) {
   1164 		    case WRAP_CODE_nvlist:
   1165 			nvfree(wrapstack[i].ptr);
   1166 			break;
   1167 		    case WRAP_CODE_defoptlist:
   1168 			{
   1169 				struct defoptlist *dl = wrapstack[i].ptr;
   1170 
   1171 				dl->dl_next = NULL;
   1172 				defoptlist_destroy(dl);
   1173 			}
   1174 			break;
   1175 		    case WRAP_CODE_loclist:
   1176 			{
   1177 				struct loclist *ll = wrapstack[i].ptr;
   1178 
   1179 				ll->ll_next = NULL;
   1180 				loclist_destroy(ll);
   1181 			}
   1182 			break;
   1183 		    case WRAP_CODE_attrlist:
   1184 			{
   1185 				struct attrlist *al = wrapstack[i].ptr;
   1186 
   1187 				al->al_next = NULL;
   1188 				al->al_this = NULL;
   1189 				attrlist_destroy(al);
   1190 			}
   1191 			break;
   1192 		    case WRAP_CODE_condexpr:
   1193 			{
   1194 				struct condexpr *cx = wrapstack[i].ptr;
   1195 
   1196 				cx->cx_type = CX_ATOM;
   1197 				cx->cx_atom = NULL;
   1198 				condexpr_destroy(cx);
   1199 			}
   1200 			break;
   1201 		    default:
   1202 			panic("invalid code %u on allocation wrapper stack",
   1203 			      wrapstack[i].typecode);
   1204 		}
   1205 	}
   1206 
   1207 	wrap_depth = 0;
   1208 }
   1209 
   1210 /*
   1211  * Instantiate the wrapper functions.
   1212  *
   1213  * Each one calls wrap_alloc to save the pointer and then returns the
   1214  * pointer again; these need to be generated with the preprocessor in
   1215  * order to be typesafe.
   1216  */
   1217 #define DEF_ALLOCWRAP(t) \
   1218 	static struct t *				\
   1219 	wrap_mk_##t(struct t *arg)			\
   1220 	{						\
   1221 		wrap_alloc(arg, WRAP_CODE_##t);		\
   1222 		return arg;				\
   1223 	}
   1224 
   1225 DEF_ALLOCWRAP(nvlist);
   1226 DEF_ALLOCWRAP(defoptlist);
   1227 DEF_ALLOCWRAP(loclist);
   1228 DEF_ALLOCWRAP(attrlist);
   1229 DEF_ALLOCWRAP(condexpr);
   1230 
   1231 /************************************************************/
   1232 
   1233 /*
   1234  * Data constructors
   1235  *
   1236  * (These are *beneath* the allocation wrappers.)
   1237  */
   1238 
   1239 static struct defoptlist *
   1240 mk_defoptlist(const char *name, const char *val, const char *lintval)
   1241 {
   1242 	return defoptlist_create(name, val, lintval);
   1243 }
   1244 
   1245 static struct loclist *
   1246 mk_loc(const char *name, const char *str, long long num)
   1247 {
   1248 	return loclist_create(name, str, num);
   1249 }
   1250 
   1251 static struct loclist *
   1252 mk_loc_val(const char *str, struct loclist *next)
   1253 {
   1254 	struct loclist *ll;
   1255 
   1256 	ll = mk_loc(NULL, str, 0);
   1257 	ll->ll_next = next;
   1258 	return ll;
   1259 }
   1260 
   1261 static struct attrlist *
   1262 mk_attrlist(struct attrlist *next, struct attr *a)
   1263 {
   1264 	return attrlist_cons(next, a);
   1265 }
   1266 
   1267 static struct condexpr *
   1268 mk_cx_atom(const char *s)
   1269 {
   1270 	struct condexpr *cx;
   1271 
   1272 	cx = condexpr_create(CX_ATOM);
   1273 	cx->cx_atom = s;
   1274 	return cx;
   1275 }
   1276 
   1277 static struct condexpr *
   1278 mk_cx_not(struct condexpr *sub)
   1279 {
   1280 	struct condexpr *cx;
   1281 
   1282 	cx = condexpr_create(CX_NOT);
   1283 	cx->cx_not = sub;
   1284 	return cx;
   1285 }
   1286 
   1287 static struct condexpr *
   1288 mk_cx_and(struct condexpr *left, struct condexpr *right)
   1289 {
   1290 	struct condexpr *cx;
   1291 
   1292 	cx = condexpr_create(CX_AND);
   1293 	cx->cx_and.left = left;
   1294 	cx->cx_and.right = right;
   1295 	return cx;
   1296 }
   1297 
   1298 static struct condexpr *
   1299 mk_cx_or(struct condexpr *left, struct condexpr *right)
   1300 {
   1301 	struct condexpr *cx;
   1302 
   1303 	cx = condexpr_create(CX_OR);
   1304 	cx->cx_or.left = left;
   1305 	cx->cx_or.right = right;
   1306 	return cx;
   1307 }
   1308 
   1309 /************************************************************/
   1310 
   1311 static void
   1312 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
   1313 	int isioconf)
   1314 {
   1315 	char buf[MAXPATHLEN];
   1316 	struct nvlist *nv;
   1317 
   1318 	if (isioconf) {
   1319 		if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
   1320 			exit(1);
   1321 		ioconfname = mch;
   1322 		return;
   1323 	}
   1324 
   1325 	machine = mch;
   1326 	machinearch = mcharch;
   1327 	machinesubarches = mchsubarches;
   1328 
   1329 	/*
   1330 	 * Define attributes for all the given names
   1331 	 */
   1332 	if (defattr(machine, NULL, NULL, 0) != 0 ||
   1333 	    (machinearch != NULL &&
   1334 	     defattr(machinearch, NULL, NULL, 0) != 0))
   1335 		exit(1);
   1336 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
   1337 		if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
   1338 			exit(1);
   1339 	}
   1340 
   1341 	/*
   1342 	 * Set up the file inclusion stack.  This empty include tells
   1343 	 * the parser there are no more device definitions coming.
   1344 	 */
   1345 	if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
   1346 		exit(1);
   1347 
   1348 	/* Include arch/${MACHINE}/conf/files.${MACHINE} */
   1349 	(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
   1350 	    machine, machine);
   1351 	if (include(buf, ENDFILE, 0, 0) != 0)
   1352 		exit(1);
   1353 
   1354 	/* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
   1355 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
   1356 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
   1357 		    nv->nv_name, nv->nv_name);
   1358 		if (include(buf, ENDFILE, 0, 0) != 0)
   1359 			exit(1);
   1360 	}
   1361 
   1362 	/* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
   1363 	if (machinearch != NULL)
   1364 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
   1365 		    machinearch, machinearch);
   1366 	else
   1367 		strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
   1368 	if (include(buf, ENDFILE, 0, 0) != 0)
   1369 		exit(1);
   1370 
   1371 	/*
   1372 	 * Include the global conf/files.  As the last thing
   1373 	 * pushed on the stack, it will be processed first.
   1374 	 */
   1375 	if (include("conf/files", ENDFILE, 0, 0) != 0)
   1376 		exit(1);
   1377 
   1378 	oktopackage = 1;
   1379 }
   1380 
   1381 static void
   1382 check_maxpart(void)
   1383 {
   1384 
   1385 	if (maxpartitions <= 0 && ioconfname == NULL) {
   1386 		stop("cannot proceed without maxpartitions specifier");
   1387 	}
   1388 }
   1389 
   1390 static void
   1391 check_version(void)
   1392 {
   1393 	/*
   1394 	 * In essence, version is 0 and is not supported anymore
   1395 	 */
   1396 	if (version < CONFIG_MINVERSION)
   1397 		stop("your sources are out of date -- please update.");
   1398 }
   1399 
   1400 /*
   1401  * Prepend a blank entry to the locator definitions so the code in
   1402  * sem.c can distinguish "empty locator list" from "no locator list".
   1403  * XXX gross.
   1404  */
   1405 static struct loclist *
   1406 present_loclist(struct loclist *ll)
   1407 {
   1408 	struct loclist *ret;
   1409 
   1410 	ret = MK3(loc, "", NULL, 0);
   1411 	ret->ll_next = ll;
   1412 	return ret;
   1413 }
   1414 
   1415 static void
   1416 app(struct loclist *p, struct loclist *q)
   1417 {
   1418 	while (p->ll_next)
   1419 		p = p->ll_next;
   1420 	p->ll_next = q;
   1421 }
   1422 
   1423 static struct loclist *
   1424 locarray(const char *name, int count, struct loclist *adefs, int opt)
   1425 {
   1426 	struct loclist *defs = adefs;
   1427 	struct loclist **p;
   1428 	char buf[200];
   1429 	int i;
   1430 
   1431 	if (count <= 0) {
   1432 		fprintf(stderr, "config: array with <= 0 size: %s\n", name);
   1433 		exit(1);
   1434 	}
   1435 	p = &defs;
   1436 	for(i = 0; i < count; i++) {
   1437 		if (*p == NULL)
   1438 			*p = MK3(loc, NULL, "0", 0);
   1439 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
   1440 		(*p)->ll_name = i == 0 ? name : intern(buf);
   1441 		(*p)->ll_num = i > 0 || opt;
   1442 		p = &(*p)->ll_next;
   1443 	}
   1444 	*p = 0;
   1445 	return defs;
   1446 }
   1447 
   1448 
   1449 static struct loclist *
   1450 namelocvals(const char *name, struct loclist *vals)
   1451 {
   1452 	struct loclist *p;
   1453 	char buf[200];
   1454 	int i;
   1455 
   1456 	for (i = 0, p = vals; p; i++, p = p->ll_next) {
   1457 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
   1458 		p->ll_name = i == 0 ? name : intern(buf);
   1459 	}
   1460 	return vals;
   1461 }
   1462 
   1463