Home | History | Annotate | Line # | Download | only in config
gram.y revision 1.10
      1 %{
      2 /*	$NetBSD: gram.y,v 1.10 2006/09/04 06:45:14 dsl 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 OBSOLETE 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 EMPTYSTRING
    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	<list>	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 defoptdeps
    279 					{ deffilesystem($2, $3, $4); } |
    280 	DEFINE WORD interface_opt attrs_opt
    281 					{ (void)defattr($2, $3, $4, 0); } |
    282 	DEFOPT optfile_opt defopts defoptdeps
    283 					{ defoption($2, $3, $4); } |
    284 	DEFFLAG optfile_opt defopts defoptdeps
    285 					{ defflag($2, $3, $4, 0); } |
    286 	OBSOLETE DEFFLAG optfile_opt defopts
    287 					{ defflag($3, $4, NULL, 1); } |
    288 	DEFPARAM optfile_opt defopts defoptdeps
    289 					{ defparam($2, $3, $4, 0); } |
    290 	OBSOLETE DEFPARAM optfile_opt defopts
    291 					{ defparam($3, $4, NULL, 1); } |
    292 	DEVICE devbase interface_opt attrs_opt
    293 					{ defdev($2, $3, $4, 0); } |
    294 	ATTACH devbase AT atlist devattach_opt attrs_opt
    295 					{ defdevattach($5, $2, $4, $6); } |
    296 	MAXPARTITIONS NUMBER		{ maxpartitions = $2.val; } |
    297 	MAXUSERS NUMBER NUMBER NUMBER	{ setdefmaxusers($2.val, $3.val, $4.val); } |
    298 	MAKEOPTIONS condmkopt_list |
    299 	DEFPSEUDO devbase interface_opt attrs_opt
    300 					{ defdev($2, $3, $4, 1); } |
    301 	MAJOR '{' majorlist '}' |
    302 	VERSION NUMBER			{ setversion($2.val); };
    303 
    304 atlist:
    305 	atlist ',' atname		{ $$ = new_nx($3, $1); } |
    306 	atname				{ $$ = new_n($1); };
    307 
    308 atname:
    309 	WORD				{ $$ = $1; } |
    310 	ROOT				{ $$ = NULL; };
    311 
    312 deffses:
    313 	deffses deffs			{ $$ = new_nx($2, $1); } |
    314 	deffs				{ $$ = new_n($1); };
    315 
    316 deffs:
    317 	WORD				{ $$ = $1; };
    318 
    319 defoptdeps:
    320 	':' optdeps			{ $$ = $2; } |
    321 	/* empty */			{ $$ = NULL; };
    322 
    323 optdeps:
    324 	optdeps ',' optdep		{ $$ = new_nx($3, $1); } |
    325 	optdep				{ $$ = new_n($1); };
    326 
    327 optdep:
    328 	WORD				{ $$ = $1; };
    329 
    330 defopts:
    331 	defopts defopt			{ $2->nv_next = $1; $$ = $2; } |
    332 	defopt				{ $$ = $1; };
    333 
    334 defopt:
    335 	WORD				{ $$ = new_n($1); } | ;
    336 	WORD '=' value			{ $$ = new_ns($1, $3); };
    337 
    338 devbase:
    339 	WORD				{ $$ = getdevbase($1); };
    340 
    341 devattach_opt:
    342 	WITH WORD			{ $$ = getdevattach($2); } |
    343 	/* empty */			{ $$ = NULL; };
    344 
    345 interface_opt:
    346 	'{' loclist_opt '}'		{ $$ = new_nx("", $2); } |
    347 	/* empty */			{ $$ = NULL; };
    348 
    349 loclist_opt:
    350 	loclist				{ $$ = $1; } |
    351 	/* empty */			{ $$ = NULL; };
    352 
    353 /* loclist order matters, must use right recursion */
    354 loclist:
    355 	locdef ',' loclist		{ $$ = $1; app($1, $3); } |
    356 	locdef				{ $$ = $1; };
    357 
    358 /* "[ WORD locdefault ]" syntax may be unnecessary... */
    359 locdef:
    360 	locname locdefault 		{ $$ = new_nsi($1, $2, 0); } |
    361 	locname				{ $$ = new_nsi($1, NULL, 0); } |
    362 	'[' locname locdefault ']'	{ $$ = new_nsi($2, $3, 1); } |
    363 	locname '[' NUMBER ']'		{ $$ = mk_nsis($1, $3.val, NULL, 0); } |
    364 	locname '[' NUMBER ']' locdefaults
    365 					{ $$ = mk_nsis($1, $3.val, $5, 0); } |
    366 	'[' locname '[' NUMBER ']' locdefaults ']'
    367 					{ $$ = mk_nsis($2, $4.val, $6, 1); };
    368 
    369 locname:
    370 	WORD				{ $$ = $1; } |
    371 	QSTRING				{ $$ = $1; };
    372 
    373 locdefault:
    374 	'=' value			{ $$ = $2; };
    375 
    376 locdefaults:
    377 	'=' '{' values '}'		{ $$ = $3; };
    378 
    379 fsoptfile_opt:
    380 	filename			{ $$ = $1; } |
    381 	/* empty */			{ $$ = NULL; };
    382 
    383 optfile_opt:
    384 	filename			{ $$ = $1; } |
    385 	/* empty */			{ $$ = NULL; };
    386 
    387 filename:
    388 	QSTRING				{ $$ = $1; } |
    389 	PATHNAME			{ $$ = $1; };
    390 
    391 value:
    392 	QSTRING				{ $$ = $1; } |
    393 	WORD				{ $$ = $1; } |
    394 	EMPTYSTRING			{ $$ = $1; } |
    395 	signed_number			{ char bf[40];
    396 					  (void)snprintf(bf, sizeof(bf),
    397 					      FORMAT($1), (long long)$1.val);
    398 					  $$ = intern(bf); };
    399 
    400 stringvalue:
    401 	QSTRING				{ $$ = $1; } |
    402 	WORD				{ $$ = $1; };
    403 
    404 values:
    405 	value ',' values		{ $$ = new_sx($1, $3); } |
    406 	value				{ $$ = new_s($1); };
    407 
    408 signed_number:
    409 	NUMBER				{ $$ = $1; } |
    410 	'-' NUMBER			{ $$.fmt = $2.fmt; $$.val = -$2.val; };
    411 
    412 attrs_opt:
    413 	':' attrs			{ $$ = $2; } |
    414 	/* empty */			{ $$ = NULL; };
    415 
    416 attrs:
    417 	attrs ',' attr			{ $$ = new_px($3, $1); } |
    418 	attr				{ $$ = new_p($1); };
    419 
    420 attr:
    421 	WORD				{ $$ = getattr($1); };
    422 
    423 majorlist:
    424 	majorlist ',' majordef |
    425 	majordef;
    426 
    427 majordef:
    428 	devbase '=' NUMBER		{ setmajor($1, $3.val); };
    429 
    430 
    431 /*
    432  * The configuration grammar.
    433  */
    434 specs:
    435 	specs spec |
    436 	/* empty */;
    437 
    438 spec:
    439 	config_spec '\n'		{ adepth = 0; } |
    440 	'\n' |
    441 	error '\n'			{ cleanup(); };
    442 
    443 config_spec:
    444 	one_def |
    445 	NO FILE_SYSTEM no_fs_list |
    446 	FILE_SYSTEM fs_list |
    447 	NO MAKEOPTIONS no_mkopt_list |
    448 	MAKEOPTIONS mkopt_list |
    449 	NO OPTIONS no_opt_list |
    450 	OPTIONS opt_list |
    451 	MAXUSERS NUMBER			{ setmaxusers($2.val); } |
    452 	IDENT stringvalue		{ setident($2); } |
    453 	CONFIG conf root_spec sysparam_list
    454 					{ addconf(&conf); } |
    455 	NO CONFIG WORD			{ delconf($3); } |
    456 	NO PSEUDO_DEVICE WORD		{ delpseudo($3); } |
    457 	PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); } |
    458 	NO device_instance AT attachment
    459 					{ deldevi($2, $4); } |
    460 	NO DEVICE AT attachment		{ deldeva($4); } |
    461 	NO device_instance		{ deldev($2); } |
    462 	device_instance AT attachment locators flags_opt
    463 					{ adddev($1, $3, $4, $5); };
    464 
    465 fs_list:
    466 	fs_list ',' fsoption |
    467 	fsoption;
    468 
    469 fsoption:
    470 	WORD				{ addfsoption($1); };
    471 
    472 no_fs_list:
    473 	no_fs_list ',' no_fsoption |
    474 	no_fsoption;
    475 
    476 no_fsoption:
    477 	WORD				{ delfsoption($1); };
    478 
    479 mkopt_list:
    480 	mkopt_list ',' mkoption |
    481 	mkoption;
    482 
    483 mkvarname:
    484 	QSTRING				{ $$ = $1; } |
    485 	WORD				{ $$ = $1; };
    486 
    487 mkoption:
    488 	mkvarname '=' value		{ addmkoption($1, $3); } |
    489 	mkvarname PLUSEQ value		{ appendmkoption($1, $3); };
    490 
    491 condmkopt_list:
    492 	condmkopt_list ',' condmkoption |
    493 	condmkoption;
    494 
    495 condmkoption:
    496 	WORD mkvarname PLUSEQ value	{ appendcondmkoption($1, $2, $4); };
    497 
    498 no_mkopt_list:
    499 	no_mkopt_list ',' no_mkoption |
    500 	no_mkoption;
    501 
    502 no_mkoption:
    503 	WORD				{ delmkoption($1); }
    504 
    505 opt_list:
    506 	opt_list ',' option |
    507 	option;
    508 
    509 option:
    510 	WORD				{ addoption($1, NULL); } |
    511 	WORD '=' value			{ addoption($1, $3); };
    512 
    513 no_opt_list:
    514 	no_opt_list ',' no_option |
    515 	no_option;
    516 
    517 no_option:
    518 	WORD				{ deloption($1); };
    519 
    520 conf:
    521 	WORD				{ conf.cf_name = $1;
    522 					    conf.cf_lineno = currentline();
    523 					    conf.cf_fstype = NULL;
    524 					    conf.cf_root = NULL;
    525 					    conf.cf_dump = NULL; };
    526 
    527 root_spec:
    528 	ROOT on_opt dev_spec fs_spec_opt
    529 				{ setconf(&conf.cf_root, "root", $3); };
    530 
    531 fs_spec_opt:
    532 	TYPE fs_spec		{ setfstype(&conf.cf_fstype, $2); } |
    533 	/* empty */;
    534 
    535 fs_spec:
    536 	'?'				{ $$ = intern("?"); } |
    537 	WORD				{ $$ = $1; };
    538 
    539 sysparam_list:
    540 	sysparam_list sysparam |
    541 	/* empty */;
    542 
    543 sysparam:
    544 	DUMPS on_opt dev_spec	 { setconf(&conf.cf_dump, "dumps", $3); };
    545 
    546 dev_spec:
    547 	'?'				{ $$ = new_si(intern("?"), NODEV); } |
    548 	WORD				{ $$ = new_si($1, NODEV); } |
    549 	major_minor			{ $$ = new_si(NULL, $1); };
    550 
    551 major_minor:
    552 	MAJOR NUMBER MINOR NUMBER	{ $$ = makedev($2.val, $4.val); };
    553 
    554 on_opt:
    555 	ON | /* empty */;
    556 
    557 npseudo:
    558 	NUMBER				{ $$ = $1.val; } |
    559 	/* empty */			{ $$ = 1; };
    560 
    561 device_instance:
    562 	WORD '*'			{ $$ = starref($1); } |
    563 	WORD				{ $$ = $1; };
    564 
    565 attachment:
    566 	ROOT				{ $$ = NULL; } |
    567 	WORD '?'			{ $$ = wildref($1); } |
    568 	WORD				{ $$ = $1; };
    569 
    570 locators:
    571 	locators locator		{ $$ = $2; app($2, $1); } |
    572 	/* empty */			{ $$ = NULL; };
    573 
    574 locator:
    575 	WORD values			{ $$ = mk_ns($1, $2); } |
    576 	WORD '?'			{ $$ = new_ns($1, NULL); };
    577 
    578 flags_opt:
    579 	FLAGS NUMBER			{ $$ = $2.val; } |
    580 	/* empty */			{ $$ = 0; };
    581 
    582 %%
    583 
    584 void
    585 yyerror(const char *s)
    586 {
    587 
    588 	error("%s", s);
    589 }
    590 
    591 /*
    592  * Cleanup procedure after syntax error: release any nvlists
    593  * allocated during parsing the current line.
    594  */
    595 static void
    596 cleanup(void)
    597 {
    598 	struct nvlist **np;
    599 	int i;
    600 
    601 	for (np = alloc, i = adepth; --i >= 0; np++)
    602 		nvfree(*np);
    603 	adepth = 0;
    604 }
    605 
    606 static void
    607 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
    608 {
    609 	char buf[MAXPATHLEN];
    610 	struct nvlist *nv;
    611 
    612 	machine = mch;
    613 	machinearch = mcharch;
    614 	machinesubarches = mchsubarches;
    615 
    616 	/*
    617 	 * Set up the file inclusion stack.  This empty include tells
    618 	 * the parser there are no more device definitions coming.
    619 	 */
    620 	strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
    621 	if (include(buf, ENDDEFS, 0, 0) != 0)
    622 		exit(1);
    623 
    624 	/* Include arch/${MACHINE}/conf/files.${MACHINE} */
    625 	(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    626 	    machine, machine);
    627 	if (include(buf, ENDFILE, 0, 0) != 0)
    628 		exit(1);
    629 
    630 	/* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
    631 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
    632 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    633 		    nv->nv_name, nv->nv_name);
    634 		if (include(buf, ENDFILE, 0, 0) != 0)
    635 			exit(1);
    636 	}
    637 
    638 	/* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
    639 	if (machinearch != NULL)
    640 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    641 		    machinearch, machinearch);
    642 	else
    643 		strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
    644 	if (include(buf, ENDFILE, 0, 0) != 0)
    645 		exit(1);
    646 
    647 	/*
    648 	 * Include the global conf/files.  As the last thing
    649 	 * pushed on the stack, it will be processed first.
    650 	 */
    651 	if (include("conf/files", ENDFILE, 0, 0) != 0)
    652 		exit(1);
    653 
    654 	oktopackage = 1;
    655 }
    656 
    657 static void
    658 check_maxpart(void)
    659 {
    660 
    661 	if (maxpartitions <= 0) {
    662 		stop("cannot proceed without maxpartitions specifier");
    663 	}
    664 }
    665 
    666 static void
    667 check_version(void)
    668 {
    669 	/*
    670 	 * In essence, version is 0 and is not supported anymore
    671 	 */
    672 	if (version < CONFIG_MINVERSION)
    673 		stop("your sources are out of date -- please update.");
    674 }
    675 
    676 static void
    677 app(struct nvlist *p, struct nvlist *q)
    678 {
    679 	while (p->nv_next)
    680 		p = p->nv_next;
    681 	p->nv_next = q;
    682 }
    683 
    684 static struct nvlist *
    685 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
    686 {
    687 	struct nvlist *defs = adefs;
    688 	struct nvlist **p;
    689 	char buf[200];
    690 	int i;
    691 
    692 	if (count <= 0) {
    693 		fprintf(stderr, "config: array with <= 0 size: %s\n", name);
    694 		exit(1);
    695 	}
    696 	p = &defs;
    697 	for(i = 0; i < count; i++) {
    698 		if (*p == NULL)
    699 			*p = new_s("0");
    700 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    701 		(*p)->nv_name = i == 0 ? name : intern(buf);
    702 		(*p)->nv_int = i > 0 || opt;
    703 		p = &(*p)->nv_next;
    704 	}
    705 	*p = 0;
    706 	return defs;
    707 }
    708 
    709 
    710 static struct nvlist *
    711 mk_ns(const char *name, struct nvlist *vals)
    712 {
    713 	struct nvlist *p;
    714 	char buf[200];
    715 	int i;
    716 
    717 	for(i = 0, p = vals; p; i++, p = p->nv_next) {
    718 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    719 		p->nv_name = i == 0 ? name : intern(buf);
    720 	}
    721 	return vals;
    722 }
    723 
    724