Home | History | Annotate | Line # | Download | only in config
gram.y revision 1.17
      1 %{
      2 /*	$NetBSD: gram.y,v 1.17 2008/06/10 18:11:31 drochner 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/types.h>
     45 #include <sys/param.h>
     46 #include <ctype.h>
     47 #include <stdio.h>
     48 #include <stdlib.h>
     49 #include <string.h>
     50 #include <errno.h>
     51 #include "defs.h"
     52 #include "sem.h"
     53 
     54 #define	FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
     55     ((n).fmt == 16) ? "0x%llx" : "%lld")
     56 
     57 #define	stop(s)	cfgerror(s), exit(1)
     58 
     59 static	struct	config conf;	/* at most one active at a time */
     60 
     61 /* the following is used to recover nvlist space after errors */
     62 static	struct	nvlist *alloc[1000];
     63 static	int	adepth;
     64 #define	new0(n,s,p,i,x)	(alloc[adepth++] = newnv(n, s, p, i, x))
     65 #define	new_n(n)	new0(n, NULL, NULL, 0, NULL)
     66 #define	new_nx(n, x)	new0(n, NULL, NULL, 0, x)
     67 #define	new_ns(n, s)	new0(n, s, NULL, 0, NULL)
     68 #define	new_si(s, i)	new0(NULL, s, NULL, i, NULL)
     69 #define	new_nsi(n,s,i)	new0(n, s, NULL, i, NULL)
     70 #define	new_np(n, p)	new0(n, NULL, p, 0, NULL)
     71 #define	new_s(s)	new0(NULL, s, NULL, 0, NULL)
     72 #define	new_p(p)	new0(NULL, NULL, p, 0, NULL)
     73 #define	new_px(p, x)	new0(NULL, NULL, p, 0, x)
     74 #define	new_sx(s, x)	new0(NULL, s, NULL, 0, x)
     75 #define	new_nsx(n,s,x)	new0(n, s, NULL, 0, x)
     76 
     77 #define	fx_atom(s)	new0(s, NULL, NULL, FX_ATOM, NULL)
     78 #define	fx_not(e)	new0(NULL, NULL, NULL, FX_NOT, e)
     79 #define	fx_and(e1, e2)	new0(NULL, NULL, e1, FX_AND, e2)
     80 #define	fx_or(e1, e2)	new0(NULL, NULL, e1, FX_OR, e2)
     81 
     82 static	void	cleanup(void);
     83 static	void	setmachine(const char *, const char *, struct nvlist *);
     84 static	void	check_maxpart(void);
     85 
     86 static	void	app(struct nvlist *, struct nvlist *);
     87 
     88 static	struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
     89 static	struct nvlist *mk_ns(const char *, struct nvlist *);
     90 
     91 %}
     92 
     93 %union {
     94 	struct	attr *attr;
     95 	struct	devbase *devb;
     96 	struct	deva *deva;
     97 	struct	nvlist *list;
     98 	const char *str;
     99 	struct	numconst num;
    100 	int64_t	val;
    101 }
    102 
    103 %token	AND AT ATTACH
    104 %token	BLOCK BUILD
    105 %token	CHAR COLONEQ COMPILE_WITH CONFIG
    106 %token	DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
    107 %token	DEVICE DEVCLASS DUMPS DEVICE_MAJOR
    108 %token	ENDFILE
    109 %token	XFILE FILE_SYSTEM FLAGS
    110 %token	IDENT
    111 %token	XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
    112 %token	NEEDS_COUNT NEEDS_FLAG NO
    113 %token	XOBJECT OBSOLETE ON OPTIONS
    114 %token	PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE
    115 %token	ROOT
    116 %token	SOURCE
    117 %token	TYPE
    118 %token	VERSION
    119 %token	WITH
    120 %token	<num> NUMBER
    121 %token	<str> PATHNAME QSTRING WORD EMPTYSTRING
    122 %token	ENDDEFS
    123 
    124 %left '|'
    125 %left '&'
    126 
    127 %type	<list>	fopts fexpr fatom
    128 %type	<str>	fs_spec
    129 %type	<val>	fflgs fflag oflgs oflag
    130 %type	<str>	rule
    131 %type	<attr>	attr
    132 %type	<devb>	devbase
    133 %type	<deva>	devattach_opt
    134 %type	<list>	atlist interface_opt
    135 %type	<str>	atname
    136 %type	<list>	loclist_opt loclist locdef
    137 %type	<str>	locdefault
    138 %type	<list>	values locdefaults
    139 %type	<list>	attrs_opt attrs
    140 %type	<list>	locators locator
    141 %type	<list>	dev_spec
    142 %type	<str>	device_instance
    143 %type	<str>	attachment
    144 %type	<str>	value
    145 %type	<val>	major_minor npseudo
    146 %type	<num>	signed_number
    147 %type	<val>	flags_opt
    148 %type	<str>	deffs
    149 %type	<list>	deffses
    150 %type	<str>	fsoptfile_opt
    151 %type	<list>	defopt
    152 %type	<list>	defopts
    153 %type	<str>	optdep
    154 %type	<list>	optdeps
    155 %type	<list>	defoptdeps
    156 %type	<str>	optfile_opt
    157 %type	<list>	subarches_opt subarches
    158 %type	<str>	filename stringvalue locname mkvarname
    159 %type	<val>	device_major_block device_major_char
    160 
    161 %%
    162 
    163 /*
    164  * A configuration consists of a machine type, followed by the machine
    165  * definition files (via the include() mechanism), followed by the
    166  * configuration specification(s) proper.  In effect, this is two
    167  * separate grammars, with some shared terminals and nonterminals.
    168  * Note that we do not have sufficient keywords to enforce any order
    169  * between elements of "topthings" without introducing shift/reduce
    170  * conflicts.  Instead, check order requirements in the C code.
    171  */
    172 Configuration:
    173 	topthings			/* dirspecs, include "std.arch" */
    174 	machine_spec			/* "machine foo" from machine descr. */
    175 	dev_defs ENDDEFS		/* all machine definition files */
    176 					{ check_maxpart(); check_version(); }
    177 	specs;				/* rest of machine description */
    178 
    179 topthings:
    180 	topthings topthing |
    181 	/* empty */;
    182 
    183 topthing:
    184 	SOURCE filename '\n'		{ if (!srcdir) srcdir = $2; } |
    185 	BUILD  filename '\n'		{ if (!builddir) builddir = $2; } |
    186 	'\n';
    187 
    188 machine_spec:
    189 	XMACHINE WORD '\n'		{ setmachine($2,NULL,NULL); } |
    190 	XMACHINE WORD WORD subarches_opt '\n'	{ setmachine($2,$3,$4); } |
    191 	error { stop("cannot proceed without machine specifier"); };
    192 
    193 subarches_opt:
    194 	subarches			|
    195 	/* empty */			{ $$ = NULL; };
    196 
    197 subarches:
    198 	subarches WORD			{ $$ = new_nx($2, $1); } |
    199 	WORD				{ $$ = new_n($1); };
    200 
    201 /*
    202  * Various nonterminals shared between the grammars.
    203  */
    204 file:
    205 	XFILE filename fopts fflgs rule	{ addfile($2, $3, $4, $5); };
    206 
    207 object:
    208 	XOBJECT filename fopts oflgs	{ addobject($2, $3, $4); };
    209 
    210 device_major:
    211 	DEVICE_MAJOR WORD device_major_char device_major_block fopts
    212 					{ adddevm($2, $3, $4, $5); };
    213 
    214 device_major_block:
    215 	BLOCK NUMBER			{ $$ = $2.val; } |
    216 	/* empty */			{ $$ = -1; };
    217 
    218 device_major_char:
    219 	CHAR NUMBER			{ $$ = $2.val; } |
    220 	/* empty */			{ $$ = -1; };
    221 
    222 /* order of options is important, must use right recursion */
    223 fopts:
    224 	fexpr				{ $$ = $1; } |
    225 	/* empty */			{ $$ = NULL; };
    226 
    227 fexpr:
    228 	fatom				{ $$ = $1; } |
    229 	'!' fatom			{ $$ = fx_not($2); } |
    230 	fexpr '&' fexpr			{ $$ = fx_and($1, $3); } |
    231 	fexpr '|' fexpr			{ $$ = fx_or($1, $3); } |
    232 	'(' fexpr ')'			{ $$ = $2; };
    233 
    234 fatom:
    235 	WORD				{ $$ = fx_atom($1); };
    236 
    237 fflgs:
    238 	fflgs fflag			{ $$ = $1 | $2; } |
    239 	/* empty */			{ $$ = 0; };
    240 
    241 fflag:
    242 	NEEDS_COUNT			{ $$ = FI_NEEDSCOUNT; } |
    243 	NEEDS_FLAG			{ $$ = FI_NEEDSFLAG; };
    244 
    245 oflgs:
    246 	oflgs oflag			{ $$ = $1 | $2; } |
    247 	/* empty */			{ $$ = 0; };
    248 
    249 oflag:
    250 	NEEDS_FLAG			{ $$ = OI_NEEDSFLAG; };
    251 
    252 rule:
    253 	COMPILE_WITH stringvalue	{ $$ = $2; } |
    254 	/* empty */			{ $$ = NULL; };
    255 
    256 prefix:
    257 	PREFIX filename			{ prefix_push($2); } |
    258 	PREFIX				{ prefix_pop(); };
    259 
    260 /*
    261  * The machine definitions grammar.
    262  */
    263 dev_defs:
    264 	dev_defs dev_def |
    265 	dev_defs ENDFILE		{ enddefs(); checkfiles(); } |
    266 	/* empty */;
    267 
    268 dev_def:
    269 	one_def '\n'			{ adepth = 0; } |
    270 	'\n' |
    271 	error '\n'			{ cleanup(); };
    272 
    273 one_def:
    274 	file |
    275 	object |
    276 	device_major			{ do_devsw = 1; } |
    277 	prefix |
    278 	DEVCLASS WORD			{ (void)defattr($2, NULL, NULL, 1); } |
    279 	DEFFS fsoptfile_opt deffses defoptdeps
    280 					{ deffilesystem($2, $3, $4); } |
    281 	DEFINE WORD interface_opt attrs_opt
    282 					{ (void)defattr($2, $3, $4, 0); } |
    283 	DEFOPT optfile_opt defopts defoptdeps
    284 					{ defoption($2, $3, $4); } |
    285 	DEFFLAG optfile_opt defopts defoptdeps
    286 					{ defflag($2, $3, $4, 0); } |
    287 	OBSOLETE DEFFLAG optfile_opt defopts
    288 					{ defflag($3, $4, NULL, 1); } |
    289 	DEFPARAM optfile_opt defopts defoptdeps
    290 					{ defparam($2, $3, $4, 0); } |
    291 	OBSOLETE DEFPARAM optfile_opt defopts
    292 					{ defparam($3, $4, NULL, 1); } |
    293 	DEVICE devbase interface_opt attrs_opt
    294 					{ defdev($2, $3, $4, 0); } |
    295 	ATTACH devbase AT atlist devattach_opt attrs_opt
    296 					{ defdevattach($5, $2, $4, $6); } |
    297 	MAXPARTITIONS NUMBER		{ maxpartitions = $2.val; } |
    298 	MAXUSERS NUMBER NUMBER NUMBER	{ setdefmaxusers($2.val, $3.val, $4.val); } |
    299 	MAKEOPTIONS condmkopt_list |
    300 	/* interface_opt in DEFPSEUDO is for backwards compatibility */
    301 	DEFPSEUDO devbase interface_opt attrs_opt
    302 					{ defdev($2, $3, $4, 1); } |
    303 	DEFPSEUDODEV devbase interface_opt attrs_opt
    304 					{ defdev($2, $3, $4, 2); } |
    305 	MAJOR '{' majorlist '}' |
    306 	VERSION NUMBER			{ setversion($2.val); };
    307 
    308 atlist:
    309 	atlist ',' atname		{ $$ = new_nx($3, $1); } |
    310 	atname				{ $$ = new_n($1); };
    311 
    312 atname:
    313 	WORD				{ $$ = $1; } |
    314 	ROOT				{ $$ = NULL; };
    315 
    316 deffses:
    317 	deffses deffs			{ $$ = new_nx($2, $1); } |
    318 	deffs				{ $$ = new_n($1); };
    319 
    320 deffs:
    321 	WORD				{ $$ = $1; };
    322 
    323 defoptdeps:
    324 	':' optdeps			{ $$ = $2; } |
    325 	/* empty */			{ $$ = NULL; };
    326 
    327 optdeps:
    328 	optdeps ',' optdep		{ $$ = new_nx($3, $1); } |
    329 	optdep				{ $$ = new_n($1); };
    330 
    331 optdep:
    332 	WORD				{ $$ = $1; };
    333 
    334 defopts:
    335 	defopts defopt			{ $$ = nvcat($2, $1); } |
    336 	defopt				{ $$ = $1; };
    337 
    338 defopt:
    339 	WORD				{ $$ = new_n($1); } |
    340 	WORD '=' value			{ $$ = new_ns($1, $3); } |
    341 	WORD COLONEQ value		{
    342 						struct nvlist *__nv =
    343 						    new_n($1);
    344 						$$ = new_nsx("", $3, __nv);
    345 					} |
    346 	WORD '=' value COLONEQ value	{
    347 						struct nvlist *__nv =
    348 						    new_n($1);
    349 						$$ = new_nsx("", $5, __nv);
    350 					};
    351 
    352 devbase:
    353 	WORD				{ $$ = getdevbase($1); };
    354 
    355 devattach_opt:
    356 	WITH WORD			{ $$ = getdevattach($2); } |
    357 	/* empty */			{ $$ = NULL; };
    358 
    359 interface_opt:
    360 	'{' loclist_opt '}'		{ $$ = new_nx("", $2); } |
    361 	/* empty */			{ $$ = NULL; };
    362 
    363 loclist_opt:
    364 	loclist				{ $$ = $1; } |
    365 	/* empty */			{ $$ = NULL; };
    366 
    367 /* loclist order matters, must use right recursion */
    368 loclist:
    369 	locdef ',' loclist		{ $$ = $1; app($1, $3); } |
    370 	locdef				{ $$ = $1; };
    371 
    372 /* "[ WORD locdefault ]" syntax may be unnecessary... */
    373 locdef:
    374 	locname locdefault 		{ $$ = new_nsi($1, $2, 0); } |
    375 	locname				{ $$ = new_nsi($1, NULL, 0); } |
    376 	'[' locname locdefault ']'	{ $$ = new_nsi($2, $3, 1); } |
    377 	locname '[' NUMBER ']'		{ $$ = mk_nsis($1, $3.val, NULL, 0); } |
    378 	locname '[' NUMBER ']' locdefaults
    379 					{ $$ = mk_nsis($1, $3.val, $5, 0); } |
    380 	'[' locname '[' NUMBER ']' locdefaults ']'
    381 					{ $$ = mk_nsis($2, $4.val, $6, 1); };
    382 
    383 locname:
    384 	WORD				{ $$ = $1; } |
    385 	QSTRING				{ $$ = $1; };
    386 
    387 locdefault:
    388 	'=' value			{ $$ = $2; };
    389 
    390 locdefaults:
    391 	'=' '{' values '}'		{ $$ = $3; };
    392 
    393 fsoptfile_opt:
    394 	filename			{ $$ = $1; } |
    395 	/* empty */			{ $$ = NULL; };
    396 
    397 optfile_opt:
    398 	filename			{ $$ = $1; } |
    399 	/* empty */			{ $$ = NULL; };
    400 
    401 filename:
    402 	QSTRING				{ $$ = $1; } |
    403 	PATHNAME			{ $$ = $1; };
    404 
    405 value:
    406 	QSTRING				{ $$ = $1; } |
    407 	WORD				{ $$ = $1; } |
    408 	EMPTYSTRING			{ $$ = $1; } |
    409 	signed_number			{ char bf[40];
    410 					  (void)snprintf(bf, sizeof(bf),
    411 					      FORMAT($1), (long long)$1.val);
    412 					  $$ = intern(bf); };
    413 
    414 stringvalue:
    415 	QSTRING				{ $$ = $1; } |
    416 	WORD				{ $$ = $1; };
    417 
    418 values:
    419 	value ',' values		{ $$ = new_sx($1, $3); } |
    420 	value				{ $$ = new_s($1); };
    421 
    422 signed_number:
    423 	NUMBER				{ $$ = $1; } |
    424 	'-' NUMBER			{ $$.fmt = $2.fmt; $$.val = -$2.val; };
    425 
    426 attrs_opt:
    427 	':' attrs			{ $$ = $2; } |
    428 	/* empty */			{ $$ = NULL; };
    429 
    430 attrs:
    431 	attrs ',' attr			{ $$ = new_px($3, $1); } |
    432 	attr				{ $$ = new_p($1); };
    433 
    434 attr:
    435 	WORD				{ $$ = getattr($1); };
    436 
    437 majorlist:
    438 	majorlist ',' majordef |
    439 	majordef;
    440 
    441 majordef:
    442 	devbase '=' NUMBER		{ setmajor($1, $3.val); };
    443 
    444 
    445 /*
    446  * The configuration grammar.
    447  */
    448 specs:
    449 	specs spec |
    450 	/* empty */;
    451 
    452 spec:
    453 	config_spec '\n'		{ adepth = 0; } |
    454 	'\n' |
    455 	error '\n'			{ cleanup(); };
    456 
    457 config_spec:
    458 	one_def |
    459 	NO FILE_SYSTEM no_fs_list |
    460 	FILE_SYSTEM fs_list |
    461 	NO MAKEOPTIONS no_mkopt_list |
    462 	MAKEOPTIONS mkopt_list |
    463 	NO OPTIONS no_opt_list |
    464 	OPTIONS opt_list |
    465 	MAXUSERS NUMBER			{ setmaxusers($2.val); } |
    466 	IDENT stringvalue		{ setident($2); } |
    467 	CONFIG conf root_spec sysparam_list
    468 					{ addconf(&conf); } |
    469 	NO CONFIG WORD			{ delconf($3); } |
    470 	NO PSEUDO_DEVICE WORD		{ delpseudo($3); } |
    471 	PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); } |
    472 	NO device_instance AT attachment
    473 					{ deldevi($2, $4); } |
    474 	NO DEVICE AT attachment		{ deldeva($4); } |
    475 	NO device_instance		{ deldev($2); } |
    476 	device_instance AT attachment locators flags_opt
    477 					{ adddev($1, $3, $4, $5); };
    478 
    479 fs_list:
    480 	fs_list ',' fsoption |
    481 	fsoption;
    482 
    483 fsoption:
    484 	WORD				{ addfsoption($1); };
    485 
    486 no_fs_list:
    487 	no_fs_list ',' no_fsoption |
    488 	no_fsoption;
    489 
    490 no_fsoption:
    491 	WORD				{ delfsoption($1); };
    492 
    493 mkopt_list:
    494 	mkopt_list ',' mkoption |
    495 	mkoption;
    496 
    497 mkvarname:
    498 	QSTRING				{ $$ = $1; } |
    499 	WORD				{ $$ = $1; };
    500 
    501 mkoption:
    502 	mkvarname '=' value		{ addmkoption($1, $3); } |
    503 	mkvarname PLUSEQ value		{ appendmkoption($1, $3); };
    504 
    505 condmkopt_list:
    506 	condmkopt_list ',' condmkoption |
    507 	condmkoption;
    508 
    509 condmkoption:
    510 	WORD mkvarname PLUSEQ value	{ appendcondmkoption($1, $2, $4); };
    511 
    512 no_mkopt_list:
    513 	no_mkopt_list ',' no_mkoption |
    514 	no_mkoption;
    515 
    516 no_mkoption:
    517 	WORD				{ delmkoption($1); }
    518 
    519 opt_list:
    520 	opt_list ',' option |
    521 	option;
    522 
    523 option:
    524 	WORD				{ addoption($1, NULL); } |
    525 	WORD '=' value			{ addoption($1, $3); };
    526 
    527 no_opt_list:
    528 	no_opt_list ',' no_option |
    529 	no_option;
    530 
    531 no_option:
    532 	WORD				{ deloption($1); };
    533 
    534 conf:
    535 	WORD				{ conf.cf_name = $1;
    536 					    conf.cf_lineno = currentline();
    537 					    conf.cf_fstype = NULL;
    538 					    conf.cf_root = NULL;
    539 					    conf.cf_dump = NULL; };
    540 
    541 root_spec:
    542 	ROOT on_opt dev_spec fs_spec_opt
    543 				{ setconf(&conf.cf_root, "root", $3); };
    544 
    545 fs_spec_opt:
    546 	TYPE fs_spec		{ setfstype(&conf.cf_fstype, $2); } |
    547 	/* empty */;
    548 
    549 fs_spec:
    550 	'?'				{ $$ = intern("?"); } |
    551 	WORD				{ $$ = $1; };
    552 
    553 sysparam_list:
    554 	sysparam_list sysparam |
    555 	/* empty */;
    556 
    557 sysparam:
    558 	DUMPS on_opt dev_spec	 { setconf(&conf.cf_dump, "dumps", $3); };
    559 
    560 dev_spec:
    561 	'?'				{ $$ = new_si(intern("?"), NODEV); } |
    562 	WORD				{ $$ = new_si($1, NODEV); } |
    563 	major_minor			{ $$ = new_si(NULL, $1); };
    564 
    565 major_minor:
    566 	MAJOR NUMBER MINOR NUMBER	{ $$ = makedev($2.val, $4.val); };
    567 
    568 on_opt:
    569 	ON | /* empty */;
    570 
    571 npseudo:
    572 	NUMBER				{ $$ = $1.val; } |
    573 	/* empty */			{ $$ = 1; };
    574 
    575 device_instance:
    576 	WORD '*'			{ $$ = starref($1); } |
    577 	WORD				{ $$ = $1; };
    578 
    579 attachment:
    580 	ROOT				{ $$ = NULL; } |
    581 	WORD '?'			{ $$ = wildref($1); } |
    582 	WORD				{ $$ = $1; };
    583 
    584 locators:
    585 	locators locator		{ $$ = $2; app($2, $1); } |
    586 	/* empty */			{ $$ = NULL; };
    587 
    588 locator:
    589 	WORD values			{ $$ = mk_ns($1, $2); } |
    590 	WORD '?'			{ $$ = new_ns($1, NULL); };
    591 
    592 flags_opt:
    593 	FLAGS NUMBER			{ $$ = $2.val; } |
    594 	/* empty */			{ $$ = 0; };
    595 
    596 %%
    597 
    598 void
    599 yyerror(const char *s)
    600 {
    601 
    602 	cfgerror("%s", s);
    603 }
    604 
    605 /*
    606  * Cleanup procedure after syntax error: release any nvlists
    607  * allocated during parsing the current line.
    608  */
    609 static void
    610 cleanup(void)
    611 {
    612 	struct nvlist **np;
    613 	int i;
    614 
    615 	for (np = alloc, i = adepth; --i >= 0; np++)
    616 		nvfree(*np);
    617 	adepth = 0;
    618 }
    619 
    620 static void
    621 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
    622 {
    623 	char buf[MAXPATHLEN];
    624 	struct nvlist *nv;
    625 
    626 	machine = mch;
    627 	machinearch = mcharch;
    628 	machinesubarches = mchsubarches;
    629 
    630 	/*
    631 	 * Define attributes for all the given names
    632 	 */
    633 	if (defattr(machine, NULL, NULL, 0) != 0 ||
    634 	    (machinearch != NULL &&
    635 	     defattr(machinearch, NULL, NULL, 0) != 0))
    636 		exit(1);
    637 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
    638 		if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
    639 			exit(1);
    640 	}
    641 
    642 	/*
    643 	 * Set up the file inclusion stack.  This empty include tells
    644 	 * the parser there are no more device definitions coming.
    645 	 */
    646 	strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
    647 	if (include(buf, ENDDEFS, 0, 0) != 0)
    648 		exit(1);
    649 
    650 	/* Include arch/${MACHINE}/conf/files.${MACHINE} */
    651 	(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    652 	    machine, machine);
    653 	if (include(buf, ENDFILE, 0, 0) != 0)
    654 		exit(1);
    655 
    656 	/* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
    657 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
    658 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    659 		    nv->nv_name, nv->nv_name);
    660 		if (include(buf, ENDFILE, 0, 0) != 0)
    661 			exit(1);
    662 	}
    663 
    664 	/* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
    665 	if (machinearch != NULL)
    666 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    667 		    machinearch, machinearch);
    668 	else
    669 		strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
    670 	if (include(buf, ENDFILE, 0, 0) != 0)
    671 		exit(1);
    672 
    673 	/*
    674 	 * Include the global conf/files.  As the last thing
    675 	 * pushed on the stack, it will be processed first.
    676 	 */
    677 	if (include("conf/files", ENDFILE, 0, 0) != 0)
    678 		exit(1);
    679 
    680 	oktopackage = 1;
    681 }
    682 
    683 static void
    684 check_maxpart(void)
    685 {
    686 
    687 	if (maxpartitions <= 0) {
    688 		stop("cannot proceed without maxpartitions specifier");
    689 	}
    690 }
    691 
    692 static void
    693 check_version(void)
    694 {
    695 	/*
    696 	 * In essence, version is 0 and is not supported anymore
    697 	 */
    698 	if (version < CONFIG_MINVERSION)
    699 		stop("your sources are out of date -- please update.");
    700 }
    701 
    702 static void
    703 app(struct nvlist *p, struct nvlist *q)
    704 {
    705 	while (p->nv_next)
    706 		p = p->nv_next;
    707 	p->nv_next = q;
    708 }
    709 
    710 static struct nvlist *
    711 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
    712 {
    713 	struct nvlist *defs = adefs;
    714 	struct nvlist **p;
    715 	char buf[200];
    716 	int i;
    717 
    718 	if (count <= 0) {
    719 		fprintf(stderr, "config: array with <= 0 size: %s\n", name);
    720 		exit(1);
    721 	}
    722 	p = &defs;
    723 	for(i = 0; i < count; i++) {
    724 		if (*p == NULL)
    725 			*p = new_s("0");
    726 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    727 		(*p)->nv_name = i == 0 ? name : intern(buf);
    728 		(*p)->nv_int = i > 0 || opt;
    729 		p = &(*p)->nv_next;
    730 	}
    731 	*p = 0;
    732 	return defs;
    733 }
    734 
    735 
    736 static struct nvlist *
    737 mk_ns(const char *name, struct nvlist *vals)
    738 {
    739 	struct nvlist *p;
    740 	char buf[200];
    741 	int i;
    742 
    743 	for(i = 0, p = vals; p; i++, p = p->nv_next) {
    744 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    745 		p->nv_name = i == 0 ? name : intern(buf);
    746 	}
    747 	return vals;
    748 }
    749 
    750