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