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