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