Home | History | Annotate | Line # | Download | only in config
gram.y revision 1.9
      1 %{
      2 /*	$NetBSD: gram.y,v 1.9 2006/08/30 10:12:25 matt 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	<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 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			{ $$ = new_nx($2, $1); } |
    332 	defopt				{ $$ = new_n($1); };
    333 
    334 defopt:
    335 	WORD				{ $$ = $1; };
    336 
    337 devbase:
    338 	WORD				{ $$ = getdevbase($1); };
    339 
    340 devattach_opt:
    341 	WITH WORD			{ $$ = getdevattach($2); } |
    342 	/* empty */			{ $$ = NULL; };
    343 
    344 interface_opt:
    345 	'{' loclist_opt '}'		{ $$ = new_nx("", $2); } |
    346 	/* empty */			{ $$ = NULL; };
    347 
    348 loclist_opt:
    349 	loclist				{ $$ = $1; } |
    350 	/* empty */			{ $$ = NULL; };
    351 
    352 /* loclist order matters, must use right recursion */
    353 loclist:
    354 	locdef ',' loclist		{ $$ = $1; app($1, $3); } |
    355 	locdef				{ $$ = $1; };
    356 
    357 /* "[ WORD locdefault ]" syntax may be unnecessary... */
    358 locdef:
    359 	locname locdefault 		{ $$ = new_nsi($1, $2, 0); } |
    360 	locname				{ $$ = new_nsi($1, NULL, 0); } |
    361 	'[' locname locdefault ']'	{ $$ = new_nsi($2, $3, 1); } |
    362 	locname '[' NUMBER ']'		{ $$ = mk_nsis($1, $3.val, NULL, 0); } |
    363 	locname '[' NUMBER ']' locdefaults
    364 					{ $$ = mk_nsis($1, $3.val, $5, 0); } |
    365 	'[' locname '[' NUMBER ']' locdefaults ']'
    366 					{ $$ = mk_nsis($2, $4.val, $6, 1); };
    367 
    368 locname:
    369 	WORD				{ $$ = $1; } |
    370 	QSTRING				{ $$ = $1; };
    371 
    372 locdefault:
    373 	'=' value			{ $$ = $2; };
    374 
    375 locdefaults:
    376 	'=' '{' values '}'		{ $$ = $3; };
    377 
    378 fsoptfile_opt:
    379 	filename			{ $$ = $1; } |
    380 	/* empty */			{ $$ = NULL; };
    381 
    382 optfile_opt:
    383 	filename			{ $$ = $1; } |
    384 	/* empty */			{ $$ = NULL; };
    385 
    386 filename:
    387 	QSTRING				{ $$ = $1; } |
    388 	PATHNAME			{ $$ = $1; };
    389 
    390 value:
    391 	QSTRING				{ $$ = $1; } |
    392 	WORD				{ $$ = $1; } |
    393 	EMPTYSTRING			{ $$ = $1; } |
    394 	signed_number			{ char bf[40];
    395 					  (void)snprintf(bf, sizeof(bf),
    396 					      FORMAT($1), (long long)$1.val);
    397 					  $$ = intern(bf); };
    398 
    399 stringvalue:
    400 	QSTRING				{ $$ = $1; } |
    401 	WORD				{ $$ = $1; };
    402 
    403 values:
    404 	value ',' values		{ $$ = new_sx($1, $3); } |
    405 	value				{ $$ = new_s($1); };
    406 
    407 signed_number:
    408 	NUMBER				{ $$ = $1; } |
    409 	'-' NUMBER			{ $$.fmt = $2.fmt; $$.val = -$2.val; };
    410 
    411 attrs_opt:
    412 	':' attrs			{ $$ = $2; } |
    413 	/* empty */			{ $$ = NULL; };
    414 
    415 attrs:
    416 	attrs ',' attr			{ $$ = new_px($3, $1); } |
    417 	attr				{ $$ = new_p($1); };
    418 
    419 attr:
    420 	WORD				{ $$ = getattr($1); };
    421 
    422 majorlist:
    423 	majorlist ',' majordef |
    424 	majordef;
    425 
    426 majordef:
    427 	devbase '=' NUMBER		{ setmajor($1, $3.val); };
    428 
    429 
    430 /*
    431  * The configuration grammar.
    432  */
    433 specs:
    434 	specs spec |
    435 	/* empty */;
    436 
    437 spec:
    438 	config_spec '\n'		{ adepth = 0; } |
    439 	'\n' |
    440 	error '\n'			{ cleanup(); };
    441 
    442 config_spec:
    443 	one_def |
    444 	NO FILE_SYSTEM no_fs_list |
    445 	FILE_SYSTEM fs_list |
    446 	NO MAKEOPTIONS no_mkopt_list |
    447 	MAKEOPTIONS mkopt_list |
    448 	NO OPTIONS no_opt_list |
    449 	OPTIONS opt_list |
    450 	MAXUSERS NUMBER			{ setmaxusers($2.val); } |
    451 	IDENT stringvalue		{ setident($2); } |
    452 	CONFIG conf root_spec sysparam_list
    453 					{ addconf(&conf); } |
    454 	NO CONFIG WORD			{ delconf($3); } |
    455 	NO PSEUDO_DEVICE WORD		{ delpseudo($3); } |
    456 	PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); } |
    457 	NO device_instance AT attachment
    458 					{ deldevi($2, $4); } |
    459 	NO DEVICE AT attachment		{ deldeva($4); } |
    460 	NO device_instance		{ deldev($2); } |
    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 	oktopackage = 1;
    654 }
    655 
    656 static void
    657 check_maxpart(void)
    658 {
    659 
    660 	if (maxpartitions <= 0) {
    661 		stop("cannot proceed without maxpartitions specifier");
    662 	}
    663 }
    664 
    665 static void
    666 check_version(void)
    667 {
    668 	/*
    669 	 * In essence, version is 0 and is not supported anymore
    670 	 */
    671 	if (version < CONFIG_MINVERSION)
    672 		stop("your sources are out of date -- please update.");
    673 }
    674 
    675 static void
    676 app(struct nvlist *p, struct nvlist *q)
    677 {
    678 	while (p->nv_next)
    679 		p = p->nv_next;
    680 	p->nv_next = q;
    681 }
    682 
    683 static struct nvlist *
    684 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
    685 {
    686 	struct nvlist *defs = adefs;
    687 	struct nvlist **p;
    688 	char buf[200];
    689 	int i;
    690 
    691 	if (count <= 0) {
    692 		fprintf(stderr, "config: array with <= 0 size: %s\n", name);
    693 		exit(1);
    694 	}
    695 	p = &defs;
    696 	for(i = 0; i < count; i++) {
    697 		if (*p == NULL)
    698 			*p = new_s("0");
    699 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    700 		(*p)->nv_name = i == 0 ? name : intern(buf);
    701 		(*p)->nv_int = i > 0 || opt;
    702 		p = &(*p)->nv_next;
    703 	}
    704 	*p = 0;
    705 	return defs;
    706 }
    707 
    708 
    709 static struct nvlist *
    710 mk_ns(const char *name, struct nvlist *vals)
    711 {
    712 	struct nvlist *p;
    713 	char buf[200];
    714 	int i;
    715 
    716 	for(i = 0, p = vals; p; i++, p = p->nv_next) {
    717 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    718 		p->nv_name = i == 0 ? name : intern(buf);
    719 	}
    720 	return vals;
    721 }
    722 
    723