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