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