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