Home | History | Annotate | Line # | Download | only in config
gram.y revision 1.30
      1   1.1   thorpej %{
      2  1.30  dholland /*	$NetBSD: gram.y,v 1.30 2012/03/11 02:56:25 dholland Exp $	*/
      3   1.1   thorpej 
      4   1.1   thorpej /*
      5   1.1   thorpej  * Copyright (c) 1992, 1993
      6   1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
      7   1.1   thorpej  *
      8   1.1   thorpej  * This software was developed by the Computer Systems Engineering group
      9   1.1   thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     10   1.1   thorpej  * contributed to Berkeley.
     11   1.1   thorpej  *
     12   1.1   thorpej  * All advertising materials mentioning features or use of this software
     13   1.1   thorpej  * must display the following acknowledgement:
     14   1.1   thorpej  *	This product includes software developed by the University of
     15   1.1   thorpej  *	California, Lawrence Berkeley Laboratories.
     16   1.1   thorpej  *
     17   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     18   1.1   thorpej  * modification, are permitted provided that the following conditions
     19   1.1   thorpej  * are met:
     20   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     21   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     22   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     23   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     24   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     25   1.1   thorpej  * 3. Neither the name of the University nor the names of its contributors
     26   1.1   thorpej  *    may be used to endorse or promote products derived from this software
     27   1.1   thorpej  *    without specific prior written permission.
     28   1.1   thorpej  *
     29   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39   1.1   thorpej  * SUCH DAMAGE.
     40   1.1   thorpej  *
     41   1.1   thorpej  *	from: @(#)gram.y	8.1 (Berkeley) 6/6/93
     42   1.1   thorpej  */
     43   1.1   thorpej 
     44   1.1   thorpej #include <sys/types.h>
     45   1.1   thorpej #include <sys/param.h>
     46   1.1   thorpej #include <ctype.h>
     47   1.1   thorpej #include <stdio.h>
     48   1.1   thorpej #include <stdlib.h>
     49   1.1   thorpej #include <string.h>
     50   1.1   thorpej #include <errno.h>
     51   1.1   thorpej #include "defs.h"
     52   1.1   thorpej #include "sem.h"
     53   1.1   thorpej 
     54   1.1   thorpej #define	FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
     55   1.1   thorpej     ((n).fmt == 16) ? "0x%llx" : "%lld")
     56   1.1   thorpej 
     57  1.13  christos #define	stop(s)	cfgerror(s), exit(1)
     58   1.1   thorpej 
     59   1.1   thorpej static	struct	config conf;	/* at most one active at a time */
     60   1.1   thorpej 
     61   1.1   thorpej /* the following is used to recover nvlist space after errors */
     62   1.1   thorpej static	struct	nvlist *alloc[1000];
     63   1.1   thorpej static	int	adepth;
     64   1.1   thorpej #define	new0(n,s,p,i,x)	(alloc[adepth++] = newnv(n, s, p, i, x))
     65   1.1   thorpej #define	new_n(n)	new0(n, NULL, NULL, 0, NULL)
     66   1.1   thorpej #define	new_nx(n, x)	new0(n, NULL, NULL, 0, x)
     67   1.1   thorpej #define	new_ns(n, s)	new0(n, s, NULL, 0, NULL)
     68   1.1   thorpej #define	new_si(s, i)	new0(NULL, s, NULL, i, NULL)
     69   1.1   thorpej #define	new_nsi(n,s,i)	new0(n, s, NULL, i, NULL)
     70   1.1   thorpej #define	new_np(n, p)	new0(n, NULL, p, 0, NULL)
     71   1.1   thorpej #define	new_s(s)	new0(NULL, s, NULL, 0, NULL)
     72   1.1   thorpej #define	new_p(p)	new0(NULL, NULL, p, 0, NULL)
     73   1.1   thorpej #define	new_px(p, x)	new0(NULL, NULL, p, 0, x)
     74   1.1   thorpej #define	new_sx(s, x)	new0(NULL, s, NULL, 0, x)
     75  1.11      cube #define	new_nsx(n,s,x)	new0(n, s, NULL, 0, x)
     76  1.24     pooka #define	new_i(i)	new0(NULL, NULL, NULL, i, NULL)
     77   1.1   thorpej 
     78   1.1   thorpej #define	fx_atom(s)	new0(s, NULL, NULL, FX_ATOM, NULL)
     79   1.1   thorpej #define	fx_not(e)	new0(NULL, NULL, NULL, FX_NOT, e)
     80   1.1   thorpej #define	fx_and(e1, e2)	new0(NULL, NULL, e1, FX_AND, e2)
     81   1.1   thorpej #define	fx_or(e1, e2)	new0(NULL, NULL, e1, FX_OR, e2)
     82   1.1   thorpej 
     83   1.1   thorpej static	void	cleanup(void);
     84  1.20     pooka static	void	setmachine(const char *, const char *, struct nvlist *, int);
     85   1.1   thorpej static	void	check_maxpart(void);
     86   1.1   thorpej 
     87   1.1   thorpej static	void	app(struct nvlist *, struct nvlist *);
     88   1.1   thorpej 
     89   1.1   thorpej static	struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
     90   1.1   thorpej static	struct nvlist *mk_ns(const char *, struct nvlist *);
     91   1.1   thorpej 
     92   1.1   thorpej %}
     93   1.1   thorpej 
     94   1.1   thorpej %union {
     95   1.1   thorpej 	struct	attr *attr;
     96   1.1   thorpej 	struct	devbase *devb;
     97   1.1   thorpej 	struct	deva *deva;
     98   1.1   thorpej 	struct	nvlist *list;
     99   1.1   thorpej 	const char *str;
    100   1.1   thorpej 	struct	numconst num;
    101   1.1   thorpej 	int64_t	val;
    102   1.1   thorpej }
    103   1.1   thorpej 
    104   1.1   thorpej %token	AND AT ATTACH
    105   1.1   thorpej %token	BLOCK BUILD
    106  1.11      cube %token	CHAR COLONEQ COMPILE_WITH CONFIG
    107  1.16  drochner %token	DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
    108  1.16  drochner %token	DEVICE DEVCLASS DUMPS DEVICE_MAJOR
    109   1.1   thorpej %token	ENDFILE
    110   1.1   thorpej %token	XFILE FILE_SYSTEM FLAGS
    111  1.20     pooka %token	IDENT IOCONF
    112  1.24     pooka %token	LINKZERO
    113   1.1   thorpej %token	XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
    114   1.1   thorpej %token	NEEDS_COUNT NEEDS_FLAG NO
    115   1.6      cube %token	XOBJECT OBSOLETE ON OPTIONS
    116  1.22     pooka %token	PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT
    117   1.1   thorpej %token	ROOT
    118  1.24     pooka %token	SINGLE SOURCE
    119   1.1   thorpej %token	TYPE
    120  1.24     pooka %token	VECTOR VERSION
    121   1.1   thorpej %token	WITH
    122   1.1   thorpej %token	<num> NUMBER
    123   1.8  christos %token	<str> PATHNAME QSTRING WORD EMPTYSTRING
    124   1.1   thorpej %token	ENDDEFS
    125   1.1   thorpej 
    126   1.1   thorpej %type	<list>	fopts fexpr fatom
    127  1.30  dholland %type	<list>	f_or_expr f_and_expr f_prefix_expr f_base_expr
    128   1.1   thorpej %type	<str>	fs_spec
    129   1.1   thorpej %type	<val>	fflgs fflag oflgs oflag
    130   1.1   thorpej %type	<str>	rule
    131   1.1   thorpej %type	<attr>	attr
    132   1.1   thorpej %type	<devb>	devbase
    133   1.1   thorpej %type	<deva>	devattach_opt
    134   1.1   thorpej %type	<list>	atlist interface_opt
    135   1.1   thorpej %type	<str>	atname
    136  1.28  dholland %type	<list>	loclist locdef
    137   1.1   thorpej %type	<str>	locdefault
    138   1.1   thorpej %type	<list>	values locdefaults
    139   1.1   thorpej %type	<list>	attrs_opt attrs
    140   1.1   thorpej %type	<list>	locators locator
    141   1.1   thorpej %type	<list>	dev_spec
    142   1.1   thorpej %type	<str>	device_instance
    143   1.1   thorpej %type	<str>	attachment
    144   1.1   thorpej %type	<str>	value
    145   1.1   thorpej %type	<val>	major_minor npseudo
    146   1.1   thorpej %type	<num>	signed_number
    147  1.28  dholland %type	<val>	device_flags
    148   1.1   thorpej %type	<str>	deffs
    149   1.1   thorpej %type	<list>	deffses
    150  1.10       dsl %type	<list>	defopt
    151   1.1   thorpej %type	<list>	defopts
    152   1.1   thorpej %type	<str>	optdep
    153   1.1   thorpej %type	<list>	optdeps
    154   1.1   thorpej %type	<list>	defoptdeps
    155   1.1   thorpej %type	<str>	optfile_opt
    156  1.28  dholland %type	<list>	subarches
    157   1.1   thorpej %type	<str>	filename stringvalue locname mkvarname
    158   1.1   thorpej %type	<val>	device_major_block device_major_char
    159  1.24     pooka %type	<list>	devnodes devnodetype devnodeflags devnode_dims
    160   1.1   thorpej 
    161   1.1   thorpej %%
    162   1.1   thorpej 
    163   1.1   thorpej /*
    164  1.25  dholland  * A complete configuration consists of both the configuration part (a
    165  1.25  dholland  * kernel config such as GENERIC or SKYNET, plus also the various
    166  1.25  dholland  * std.* files), which selects the material to be in the kernel, and
    167  1.25  dholland  * also the definition part (files, files.*, etc.) that declares what
    168  1.25  dholland  * material is available to be placed in kernels.
    169  1.25  dholland  *
    170  1.25  dholland  * The two parts have almost entirely separate syntaxes. This grammar
    171  1.25  dholland  * covers both of them. When config is run on a kernel configuration
    172  1.25  dholland  * file, the std.* file for the port is included explicitly. The
    173  1.25  dholland  * files.* files are included implicitly when the std.* file declares
    174  1.25  dholland  * the machine type.
    175  1.25  dholland  *
    176  1.25  dholland  * The machine spec, which brings in the definition part, must appear
    177  1.25  dholland  * before all configuration material except for the "topthings"; these
    178  1.25  dholland  * are the "source" and "build" declarations that tell config where
    179  1.25  dholland  * things are. These are not used by default.
    180  1.25  dholland  *
    181  1.25  dholland  * A previous version of this comment contained the following text:
    182  1.25  dholland  *
    183  1.25  dholland  *       Note that we do not have sufficient keywords to enforce any
    184  1.25  dholland  *       order between elements of "topthings" without introducing
    185  1.25  dholland  *       shift/reduce conflicts.  Instead, check order requirements in
    186  1.25  dholland  *       the C code.
    187  1.25  dholland  *
    188  1.25  dholland  * As of March 2012 this comment makes no sense, as there are only two
    189  1.25  dholland  * topthings and no reason for them to be forcibly ordered.
    190  1.25  dholland  * Furthermore, the statement about conflicts is false.
    191   1.1   thorpej  */
    192  1.25  dholland 
    193  1.25  dholland /* Complete configuration. */
    194  1.28  dholland configuration:
    195  1.28  dholland 	topthings machine_spec definition_part configuration_part
    196  1.26  dholland ;
    197   1.1   thorpej 
    198  1.25  dholland /* Sequence of zero or more topthings. */
    199   1.1   thorpej topthings:
    200  1.26  dholland 	  /* empty */
    201  1.26  dholland 	| topthings topthing
    202  1.26  dholland ;
    203   1.1   thorpej 
    204  1.25  dholland /* Directory specification. */
    205   1.1   thorpej topthing:
    206  1.27  dholland 	                  '\n'
    207  1.27  dholland 	| SOURCE filename '\n'		{ if (!srcdir) srcdir = $2; }
    208  1.26  dholland 	| BUILD  filename '\n'		{ if (!builddir) builddir = $2; }
    209  1.26  dholland ;
    210   1.1   thorpej 
    211  1.25  dholland /* "machine foo" from std.whatever */
    212   1.1   thorpej machine_spec:
    213  1.26  dholland 	  XMACHINE WORD '\n'			{ setmachine($2,NULL,NULL,0); }
    214  1.28  dholland 	| XMACHINE WORD WORD '\n'		{ setmachine($2,$3,NULL,0); }
    215  1.28  dholland 	| XMACHINE WORD WORD subarches '\n'	{ setmachine($2,$3,$4,0); }
    216  1.26  dholland 	| IOCONF WORD '\n'			{ setmachine($2,NULL,NULL,1); }
    217  1.26  dholland 	| error { stop("cannot proceed without machine or ioconf specifier"); }
    218  1.26  dholland ;
    219   1.1   thorpej 
    220  1.28  dholland /* One or more sub-arches. */
    221   1.1   thorpej subarches:
    222  1.27  dholland 	  WORD				{ $$ = new_n($1); }
    223  1.27  dholland 	| subarches WORD		{ $$ = new_nx($2, $1); }
    224  1.26  dholland ;
    225   1.1   thorpej 
    226  1.25  dholland /************************************************************/
    227  1.25  dholland 
    228   1.1   thorpej /*
    229   1.1   thorpej  * The machine definitions grammar.
    230   1.1   thorpej  */
    231  1.25  dholland 
    232  1.25  dholland /* Complete definition part: the contents of all files.* files. */
    233  1.28  dholland definition_part:
    234  1.28  dholland 	definitions ENDDEFS		{ check_maxpart(); check_version(); }
    235  1.26  dholland ;
    236   1.1   thorpej 
    237  1.28  dholland /* Zero or more definitions. Trap errors. */
    238  1.28  dholland definitions:
    239  1.28  dholland 	  /* empty */
    240  1.28  dholland 	| definitions '\n'
    241  1.28  dholland 	| definitions definition '\n'	{ adepth = 0; }
    242  1.28  dholland 	| definitions error '\n'	{ cleanup(); }
    243  1.28  dholland 	| definitions ENDFILE		{ enddefs(); checkfiles(); }
    244  1.26  dholland ;
    245   1.1   thorpej 
    246  1.25  dholland /* A single definition. */
    247  1.28  dholland definition:
    248  1.26  dholland 	  file
    249  1.26  dholland 	| object
    250  1.26  dholland 	| device_major			{ do_devsw = 1; }
    251  1.26  dholland 	| prefix
    252  1.26  dholland 	| DEVCLASS WORD			{ (void)defattr($2, NULL, NULL, 1); }
    253  1.26  dholland 	| DEFFS deffses defoptdeps	{ deffilesystem($2, $3); }
    254  1.26  dholland 	| DEFINE WORD interface_opt attrs_opt
    255  1.26  dholland 					{ (void)defattr($2, $3, $4, 0); }
    256  1.26  dholland 	| DEFOPT optfile_opt defopts defoptdeps
    257  1.26  dholland 					{ defoption($2, $3, $4); }
    258  1.26  dholland 	| DEFFLAG optfile_opt defopts defoptdeps
    259  1.26  dholland 					{ defflag($2, $3, $4, 0); }
    260  1.26  dholland 	| OBSOLETE DEFFLAG optfile_opt defopts
    261  1.26  dholland 					{ defflag($3, $4, NULL, 1); }
    262  1.26  dholland 	| DEFPARAM optfile_opt defopts defoptdeps
    263  1.26  dholland 					{ defparam($2, $3, $4, 0); }
    264  1.26  dholland 	| OBSOLETE DEFPARAM optfile_opt defopts
    265  1.26  dholland 					{ defparam($3, $4, NULL, 1); }
    266  1.26  dholland 	| DEVICE devbase interface_opt attrs_opt
    267  1.26  dholland 					{ defdev($2, $3, $4, 0); }
    268  1.26  dholland 	| ATTACH devbase AT atlist devattach_opt attrs_opt
    269  1.26  dholland 					{ defdevattach($5, $2, $4, $6); }
    270  1.26  dholland 	| MAXPARTITIONS NUMBER		{ maxpartitions = $2.val; }
    271  1.26  dholland 	| MAXUSERS NUMBER NUMBER NUMBER
    272  1.26  dholland 				    { setdefmaxusers($2.val, $3.val, $4.val); }
    273  1.26  dholland 	| MAKEOPTIONS condmkopt_list
    274  1.17  drochner 	/* interface_opt in DEFPSEUDO is for backwards compatibility */
    275  1.26  dholland 	| DEFPSEUDO devbase interface_opt attrs_opt
    276  1.26  dholland 					{ defdev($2, $3, $4, 1); }
    277  1.26  dholland 	| DEFPSEUDODEV devbase interface_opt attrs_opt
    278  1.26  dholland 					{ defdev($2, $3, $4, 2); }
    279  1.26  dholland 	| MAJOR '{' majorlist '}'
    280  1.26  dholland 	| VERSION NUMBER		{ setversion($2.val); }
    281  1.26  dholland ;
    282   1.1   thorpej 
    283  1.29  dholland /* source file: file foo/bar.c bar|baz needs-flag compile-with blah */
    284  1.29  dholland file:
    285  1.29  dholland 	XFILE filename fopts fflgs rule	{ addfile($2, $3, $4, $5); }
    286  1.26  dholland ;
    287   1.1   thorpej 
    288  1.29  dholland /* file options: optional expression of config elements */
    289  1.29  dholland fopts:
    290  1.29  dholland 	  /* empty */			{ $$ = NULL; }
    291  1.29  dholland 	| fexpr				{ $$ = $1; }
    292  1.26  dholland ;
    293   1.1   thorpej 
    294  1.29  dholland /* zero or more flags for a file */
    295  1.29  dholland fflgs:
    296  1.29  dholland 	  /* empty */			{ $$ = 0; }
    297  1.29  dholland 	| fflgs fflag			{ $$ = $1 | $2; }
    298  1.26  dholland ;
    299   1.1   thorpej 
    300  1.29  dholland /* one flag for a file */
    301  1.29  dholland fflag:
    302  1.29  dholland 	  NEEDS_COUNT			{ $$ = FI_NEEDSCOUNT; }
    303  1.29  dholland 	| NEEDS_FLAG			{ $$ = FI_NEEDSFLAG; }
    304  1.26  dholland ;
    305   1.1   thorpej 
    306  1.29  dholland /* extra compile directive for a source file */
    307  1.29  dholland rule:
    308  1.26  dholland 	  /* empty */			{ $$ = NULL; }
    309  1.29  dholland 	| COMPILE_WITH stringvalue	{ $$ = $2; }
    310  1.29  dholland ;
    311  1.29  dholland 
    312  1.29  dholland /* object file: object zot.o foo|zot needs-flag */
    313  1.29  dholland object:
    314  1.29  dholland 	XOBJECT filename fopts oflgs	{ addobject($2, $3, $4); }
    315  1.29  dholland ;
    316  1.29  dholland 
    317  1.29  dholland /* zero or more flags for an object file */
    318  1.29  dholland oflgs:
    319  1.29  dholland 	  /* empty */			{ $$ = 0; }
    320  1.29  dholland 	| oflgs oflag			{ $$ = $1 | $2; }
    321  1.29  dholland ;
    322  1.29  dholland 
    323  1.29  dholland /* a single flag for an object file */
    324  1.29  dholland oflag:
    325  1.29  dholland 	NEEDS_FLAG			{ $$ = OI_NEEDSFLAG; }
    326  1.29  dholland ;
    327  1.29  dholland 
    328  1.29  dholland /* device major declaration */
    329  1.29  dholland device_major:
    330  1.29  dholland 	DEVICE_MAJOR WORD device_major_char device_major_block fopts devnodes
    331  1.29  dholland 					{ adddevm($2, $3, $4, $5, $6); }
    332  1.29  dholland ;
    333  1.29  dholland 
    334  1.29  dholland /* char 55 */
    335  1.29  dholland device_major_char:
    336  1.29  dholland 	  /* empty */			{ $$ = -1; }
    337  1.29  dholland 	| CHAR NUMBER			{ $$ = $2.val; }
    338  1.26  dholland ;
    339   1.1   thorpej 
    340  1.29  dholland /* block 33 */
    341  1.29  dholland device_major_block:
    342  1.29  dholland 	  /* empty */			{ $$ = -1; }
    343  1.29  dholland 	| BLOCK NUMBER			{ $$ = $2.val; }
    344  1.26  dholland ;
    345   1.1   thorpej 
    346  1.29  dholland /* device node specification */
    347  1.29  dholland devnodes:
    348  1.29  dholland 	  /* empty */			{ $$ = new_s("DEVNODE_DONTBOTHER"); }
    349  1.29  dholland 	| devnodetype ',' devnodeflags	{ $$ = nvcat($1, $3); }
    350  1.29  dholland 	| devnodetype			{ $$ = $1; }
    351  1.26  dholland ;
    352   1.1   thorpej 
    353  1.29  dholland /* device nodes without flags */
    354  1.29  dholland devnodetype:
    355  1.29  dholland 	  SINGLE			{ $$ = new_s("DEVNODE_SINGLE"); }
    356  1.29  dholland 	| VECTOR '=' devnode_dims  { $$ = nvcat(new_s("DEVNODE_VECTOR"), $3); }
    357  1.26  dholland ;
    358   1.1   thorpej 
    359  1.29  dholland /* dimensions (?) */
    360  1.29  dholland devnode_dims:
    361  1.29  dholland 	  NUMBER			{ $$ = new_i($1.val); }
    362  1.29  dholland 	| NUMBER ':' NUMBER		{
    363  1.29  dholland 		struct nvlist *__nv1, *__nv2;
    364  1.26  dholland 
    365  1.29  dholland 		__nv1 = new_i($1.val);
    366  1.29  dholland 		__nv2 = new_i($3.val);
    367  1.29  dholland 		$$ = nvcat(__nv1, __nv2);
    368  1.26  dholland 	  }
    369  1.29  dholland ;
    370  1.29  dholland 
    371  1.29  dholland /* flags for device nodes */
    372  1.29  dholland devnodeflags:
    373  1.29  dholland 	LINKZERO			{ $$ = new_s("DEVNODE_FLAG_LINKZERO");}
    374  1.29  dholland ;
    375  1.26  dholland 
    376  1.29  dholland /* prefix delimiter */
    377  1.29  dholland prefix:
    378  1.29  dholland 	  PREFIX filename		{ prefix_push($2); }
    379  1.29  dholland 	| PREFIX			{ prefix_pop(); }
    380  1.26  dholland ;
    381   1.1   thorpej 
    382  1.29  dholland /* one or more file system names */
    383  1.29  dholland deffses:
    384  1.29  dholland 	  deffs				{ $$ = new_n($1); }
    385  1.29  dholland 	| deffses deffs			{ $$ = new_nx($2, $1); }
    386  1.26  dholland ;
    387   1.1   thorpej 
    388  1.29  dholland /* a single file system name */
    389  1.29  dholland deffs:
    390  1.29  dholland 	WORD				{ $$ = $1; }
    391  1.26  dholland ;
    392   1.1   thorpej 
    393  1.28  dholland /* optional locator specification */
    394   1.1   thorpej interface_opt:
    395  1.26  dholland 	  /* empty */			{ $$ = NULL; }
    396  1.28  dholland 	| '{' '}'			{ $$ = new_nx("", NULL); }
    397  1.28  dholland 	| '{' loclist '}'		{ $$ = new_nx("", $2); }
    398  1.26  dholland ;
    399   1.1   thorpej 
    400  1.25  dholland /*
    401  1.25  dholland  * loclist order matters, must use right recursion
    402  1.25  dholland  * XXX wot?
    403  1.25  dholland  */
    404  1.25  dholland 
    405  1.25  dholland /* list of locator definitions */
    406   1.1   thorpej loclist:
    407  1.26  dholland 	  locdef			{ $$ = $1; }
    408  1.26  dholland 	| locdef ',' loclist		{ $$ = $1; app($1, $3); }
    409  1.26  dholland ;
    410   1.1   thorpej 
    411  1.25  dholland /*
    412  1.25  dholland  * "[ WORD locdefault ]" syntax may be unnecessary...
    413  1.25  dholland  */
    414  1.25  dholland 
    415  1.25  dholland /* one locator definition */
    416   1.1   thorpej locdef:
    417  1.26  dholland 	  locname locdefault 		{ $$ = new_nsi($1, $2, 0); }
    418  1.26  dholland 	| locname			{ $$ = new_nsi($1, NULL, 0); }
    419  1.26  dholland 	| '[' locname locdefault ']'	{ $$ = new_nsi($2, $3, 1); }
    420  1.26  dholland 	| locname '[' NUMBER ']'	{ $$ = mk_nsis($1, $3.val, NULL, 0); }
    421  1.26  dholland 	| locname '[' NUMBER ']' locdefaults
    422  1.26  dholland 					{ $$ = mk_nsis($1, $3.val, $5, 0); }
    423  1.26  dholland 	| '[' locname '[' NUMBER ']' locdefaults ']'
    424  1.26  dholland 					{ $$ = mk_nsis($2, $4.val, $6, 1); }
    425  1.26  dholland ;
    426   1.1   thorpej 
    427  1.25  dholland /* locator name */
    428   1.1   thorpej locname:
    429  1.26  dholland 	  WORD				{ $$ = $1; }
    430  1.26  dholland 	| QSTRING			{ $$ = $1; }
    431  1.26  dholland ;
    432   1.1   thorpej 
    433  1.25  dholland /* locator default value */
    434   1.1   thorpej locdefault:
    435  1.26  dholland 	'=' value			{ $$ = $2; }
    436  1.26  dholland ;
    437   1.1   thorpej 
    438  1.25  dholland /* multiple locator default values */
    439   1.1   thorpej locdefaults:
    440  1.26  dholland 	'=' '{' values '}'		{ $$ = $3; }
    441  1.26  dholland ;
    442   1.1   thorpej 
    443  1.29  dholland /* optional attributes */
    444  1.29  dholland attrs_opt:
    445  1.26  dholland 	  /* empty */			{ $$ = NULL; }
    446  1.29  dholland 	| ':' attrs			{ $$ = $2; }
    447  1.29  dholland ;
    448  1.29  dholland 
    449  1.29  dholland /* one or more attributes */
    450  1.29  dholland attrs:
    451  1.29  dholland 	  attr				{ $$ = new_p($1); }
    452  1.29  dholland 	| attrs ',' attr		{ $$ = new_px($3, $1); }
    453  1.29  dholland ;
    454  1.29  dholland 
    455  1.29  dholland /* one attribute */
    456  1.29  dholland attr:
    457  1.29  dholland 	WORD				{ $$ = getattr($1); }
    458  1.29  dholland ;
    459  1.29  dholland 
    460  1.29  dholland /* list of places to attach: attach blah at ... */
    461  1.29  dholland atlist:
    462  1.29  dholland 	  atname			{ $$ = new_n($1); }
    463  1.29  dholland 	| atlist ',' atname		{ $$ = new_nx($3, $1); }
    464  1.29  dholland ;
    465  1.29  dholland 
    466  1.29  dholland /* a place to attach a device */
    467  1.29  dholland atname:
    468  1.29  dholland 	  WORD				{ $$ = $1; }
    469  1.29  dholland 	| ROOT				{ $$ = NULL; }
    470  1.26  dholland ;
    471   1.1   thorpej 
    472  1.29  dholland /* one or more defined options */
    473  1.29  dholland defopts:
    474  1.29  dholland 	  defopt			{ $$ = $1; }
    475  1.29  dholland 	| defopts defopt		{ $$ = nvcat($2, $1); }
    476  1.26  dholland ;
    477   1.1   thorpej 
    478  1.29  dholland /* one defined option */
    479  1.29  dholland defopt:
    480  1.29  dholland 	  WORD				{ $$ = new_n($1); }
    481  1.29  dholland 	| WORD '=' value		{ $$ = new_ns($1, $3); }
    482  1.29  dholland 	| WORD COLONEQ value		{
    483  1.29  dholland 		struct nvlist *__nv = new_n($1);
    484  1.29  dholland 
    485  1.29  dholland 		$$ = new_nsx("", $3, __nv);
    486  1.29  dholland 	  }
    487  1.29  dholland 	| WORD '=' value COLONEQ value	{
    488  1.29  dholland 		struct nvlist *__nv = new_n($1);
    489  1.26  dholland 
    490  1.29  dholland 		$$ = new_nsx("", $5, __nv);
    491  1.26  dholland 	  }
    492  1.26  dholland ;
    493   1.1   thorpej 
    494  1.29  dholland /* option dependencies (read as "defopt deps") which are optional */
    495  1.29  dholland defoptdeps:
    496  1.29  dholland 	  /* empty */			{ $$ = NULL; }
    497  1.29  dholland 	| ':' optdeps			{ $$ = $2; }
    498  1.29  dholland ;
    499  1.29  dholland 
    500  1.29  dholland /* a list of option dependencies */
    501  1.29  dholland optdeps:
    502  1.29  dholland 	  optdep			{ $$ = new_n($1); }
    503  1.29  dholland 	| optdeps ',' optdep		{ $$ = new_nx($3, $1); }
    504  1.26  dholland ;
    505   1.1   thorpej 
    506  1.29  dholland /* one option dependence */
    507  1.29  dholland optdep:
    508  1.29  dholland 	WORD				{ $$ = $1; }
    509  1.26  dholland ;
    510   1.1   thorpej 
    511  1.29  dholland /* list of conditional makeoptions */
    512  1.29  dholland condmkopt_list:
    513  1.29  dholland 	  condmkoption
    514  1.29  dholland 	| condmkopt_list ',' condmkoption
    515  1.26  dholland ;
    516   1.1   thorpej 
    517  1.29  dholland /* one conditional make option */
    518  1.29  dholland condmkoption:
    519  1.29  dholland 	fexpr mkvarname PLUSEQ value	{ appendcondmkoption($1, $2, $4); }
    520  1.26  dholland ;
    521   1.1   thorpej 
    522  1.29  dholland /* device name */
    523  1.29  dholland devbase:
    524  1.29  dholland 	WORD				{ $$ = getdevbase($1); }
    525  1.26  dholland ;
    526   1.1   thorpej 
    527  1.29  dholland /* optional attachment: with foo */
    528  1.29  dholland devattach_opt:
    529  1.29  dholland 	  /* empty */			{ $$ = NULL; }
    530  1.29  dholland 	| WITH WORD			{ $$ = getdevattach($2); }
    531  1.26  dholland ;
    532   1.1   thorpej 
    533  1.25  dholland /* list of major numbers */
    534  1.25  dholland /* XXX why is this right-recursive? */
    535   1.1   thorpej majorlist:
    536  1.26  dholland 	  majordef
    537  1.26  dholland 	| majorlist ',' majordef
    538  1.26  dholland ;
    539   1.1   thorpej 
    540  1.25  dholland /* one major number */
    541   1.1   thorpej majordef:
    542  1.26  dholland 	devbase '=' NUMBER		{ setmajor($1, $3.val); }
    543  1.26  dholland ;
    544   1.1   thorpej 
    545  1.25  dholland /************************************************************/
    546   1.1   thorpej 
    547   1.1   thorpej /*
    548   1.1   thorpej  * The configuration grammar.
    549   1.1   thorpej  */
    550  1.25  dholland 
    551  1.25  dholland /* Complete configuration part: all std.* files plus selected config. */
    552  1.28  dholland configuration_part:
    553  1.28  dholland 	config_items
    554  1.26  dholland ;
    555   1.1   thorpej 
    556  1.28  dholland /* Zero or more config items. Trap errors. */
    557  1.28  dholland config_items:
    558  1.28  dholland 	  /* empty */
    559  1.28  dholland 	| config_items '\n'
    560  1.28  dholland 	| config_items config_item '\n'	{ adepth = 0; }
    561  1.28  dholland 	| config_items error '\n'	{ cleanup(); }
    562  1.26  dholland ;
    563   1.1   thorpej 
    564  1.25  dholland /* One config item. */
    565  1.28  dholland config_item:
    566  1.28  dholland 	  definition
    567  1.26  dholland 	| NO FILE_SYSTEM no_fs_list
    568  1.26  dholland 	| FILE_SYSTEM fs_list
    569  1.26  dholland 	| NO MAKEOPTIONS no_mkopt_list
    570  1.26  dholland 	| MAKEOPTIONS mkopt_list
    571  1.26  dholland 	| NO OPTIONS no_opt_list
    572  1.26  dholland 	| OPTIONS opt_list
    573  1.26  dholland 	| MAXUSERS NUMBER		{ setmaxusers($2.val); }
    574  1.26  dholland 	| IDENT stringvalue		{ setident($2); }
    575  1.26  dholland 	| CONFIG conf root_spec sysparam_list
    576  1.26  dholland 					{ addconf(&conf); }
    577  1.26  dholland 	| NO CONFIG WORD		{ delconf($3); }
    578  1.26  dholland 	| NO PSEUDO_DEVICE WORD		{ delpseudo($3); }
    579  1.26  dholland 	| PSEUDO_DEVICE WORD npseudo	{ addpseudo($2, $3); }
    580  1.26  dholland 	| PSEUDO_ROOT device_instance	{ addpseudoroot($2); }
    581  1.26  dholland 	| NO device_instance AT attachment
    582  1.26  dholland 					{ deldevi($2, $4); }
    583  1.26  dholland 	| NO DEVICE AT attachment	{ deldeva($4); }
    584  1.26  dholland 	| NO device_instance		{ deldev($2); }
    585  1.28  dholland 	| device_instance AT attachment locators device_flags
    586  1.26  dholland 					{ adddev($1, $3, $4, $5); }
    587  1.26  dholland ;
    588   1.1   thorpej 
    589  1.25  dholland /* list of filesystems */
    590   1.1   thorpej fs_list:
    591  1.26  dholland 	  fsoption
    592  1.26  dholland 	| fs_list ',' fsoption
    593  1.26  dholland ;
    594   1.1   thorpej 
    595  1.25  dholland /* one filesystem */
    596   1.1   thorpej fsoption:
    597  1.26  dholland 	WORD				{ addfsoption($1); }
    598  1.26  dholland ;
    599   1.1   thorpej 
    600  1.25  dholland /* list of filesystems that had NO in front */
    601   1.1   thorpej no_fs_list:
    602  1.26  dholland 	  no_fsoption
    603  1.26  dholland 	| no_fs_list ',' no_fsoption
    604  1.26  dholland ;
    605   1.1   thorpej 
    606  1.25  dholland /* one filesystem that had NO in front */
    607   1.1   thorpej no_fsoption:
    608  1.26  dholland 	WORD				{ delfsoption($1); }
    609  1.26  dholland ;
    610   1.1   thorpej 
    611  1.25  dholland /* list of make options */
    612  1.25  dholland /* XXX why is this right-recursive? */
    613   1.1   thorpej mkopt_list:
    614  1.26  dholland 	  mkoption
    615  1.26  dholland 	| mkopt_list ',' mkoption
    616  1.26  dholland ;
    617   1.1   thorpej 
    618  1.25  dholland /* one make option */
    619   1.1   thorpej mkoption:
    620  1.26  dholland 	  mkvarname '=' value		{ addmkoption($1, $3); }
    621  1.26  dholland 	| mkvarname PLUSEQ value	{ appendmkoption($1, $3); }
    622  1.26  dholland ;
    623   1.1   thorpej 
    624  1.25  dholland /* list of make options that had NO in front */
    625   1.1   thorpej no_mkopt_list:
    626  1.26  dholland 	  no_mkoption
    627  1.26  dholland 	| no_mkopt_list ',' no_mkoption
    628  1.26  dholland ;
    629   1.1   thorpej 
    630  1.25  dholland /* one make option that had NO in front */
    631  1.29  dholland /* XXX shouldn't this be mkvarname rather than WORD? */
    632   1.1   thorpej no_mkoption:
    633   1.1   thorpej 	WORD				{ delmkoption($1); }
    634  1.26  dholland ;
    635   1.1   thorpej 
    636  1.25  dholland /* list of options */
    637   1.1   thorpej opt_list:
    638  1.26  dholland 	  option
    639  1.26  dholland 	| opt_list ',' option
    640  1.26  dholland ;
    641   1.1   thorpej 
    642  1.25  dholland /* one option */
    643   1.1   thorpej option:
    644  1.26  dholland 	  WORD				{ addoption($1, NULL); }
    645  1.26  dholland 	| WORD '=' value		{ addoption($1, $3); }
    646  1.26  dholland ;
    647   1.1   thorpej 
    648  1.25  dholland /* list of options that had NO in front */
    649   1.1   thorpej no_opt_list:
    650  1.26  dholland 	  no_option
    651  1.26  dholland 	| no_opt_list ',' no_option
    652  1.26  dholland ;
    653   1.1   thorpej 
    654  1.25  dholland /* one option that had NO in front */
    655   1.1   thorpej no_option:
    656  1.26  dholland 	WORD				{ deloption($1); }
    657  1.26  dholland ;
    658   1.1   thorpej 
    659  1.25  dholland /* the name in "config name root on ..." */
    660   1.1   thorpej conf:
    661  1.26  dholland 	WORD				{
    662  1.26  dholland 		conf.cf_name = $1;
    663  1.26  dholland 		conf.cf_lineno = currentline();
    664  1.26  dholland 		conf.cf_fstype = NULL;
    665  1.26  dholland 		conf.cf_root = NULL;
    666  1.26  dholland 		conf.cf_dump = NULL;
    667  1.26  dholland 	}
    668  1.26  dholland ;
    669   1.1   thorpej 
    670  1.25  dholland /* root fs specification */
    671   1.1   thorpej root_spec:
    672  1.28  dholland 	  ROOT on_opt dev_spec		{ setconf(&conf.cf_root, "root", $3); }
    673  1.28  dholland 	| ROOT on_opt dev_spec fs_spec	{ setconf(&conf.cf_root, "root", $3); }
    674  1.26  dholland ;
    675   1.1   thorpej 
    676  1.29  dholland /* device for root fs or dump */
    677  1.29  dholland dev_spec:
    678  1.29  dholland 	  '?'				{ $$ = new_si(intern("?"), NODEV); }
    679  1.29  dholland 	| WORD				{ $$ = new_si($1, NODEV); }
    680  1.29  dholland 	| major_minor			{ $$ = new_si(NULL, $1); }
    681  1.29  dholland ;
    682  1.29  dholland 
    683  1.29  dholland /* major and minor device number */
    684  1.29  dholland major_minor:
    685  1.29  dholland 	MAJOR NUMBER MINOR NUMBER	{ $$ = makedev($2.val, $4.val); }
    686  1.29  dholland ;
    687  1.29  dholland 
    688  1.25  dholland /* filesystem type for root fs specification */
    689   1.1   thorpej fs_spec:
    690  1.28  dholland 	  TYPE '?'		   { setfstype(&conf.cf_fstype, intern("?")); }
    691  1.28  dholland 	| TYPE WORD			{ setfstype(&conf.cf_fstype, $2); }
    692  1.26  dholland ;
    693   1.1   thorpej 
    694  1.25  dholland /* zero or more additional system parameters */
    695   1.1   thorpej sysparam_list:
    696  1.26  dholland 	  /* empty */
    697  1.26  dholland 	| sysparam_list sysparam
    698  1.26  dholland ;
    699   1.1   thorpej 
    700  1.25  dholland /* one additional system parameter (there's only one: dumps) */
    701   1.1   thorpej sysparam:
    702  1.26  dholland 	DUMPS on_opt dev_spec	       { setconf(&conf.cf_dump, "dumps", $3); }
    703  1.26  dholland ;
    704   1.1   thorpej 
    705  1.25  dholland /* number of pseudo devices to configure (which is optional) */
    706   1.1   thorpej npseudo:
    707  1.26  dholland 	  /* empty */			{ $$ = 1; }
    708  1.26  dholland 	| NUMBER			{ $$ = $1.val; }
    709  1.26  dholland ;
    710   1.1   thorpej 
    711  1.25  dholland /* name of a device to configure */
    712   1.1   thorpej device_instance:
    713  1.26  dholland 	  WORD				{ $$ = $1; }
    714  1.26  dholland 	| WORD '*'			{ $$ = starref($1); }
    715  1.26  dholland ;
    716   1.1   thorpej 
    717  1.25  dholland /* name of a device to configure an attachment to */
    718   1.1   thorpej attachment:
    719  1.26  dholland 	  ROOT				{ $$ = NULL; }
    720  1.26  dholland 	| WORD				{ $$ = $1; }
    721  1.26  dholland 	| WORD '?'			{ $$ = wildref($1); }
    722  1.26  dholland ;
    723   1.1   thorpej 
    724  1.25  dholland /* zero or more locators */
    725   1.1   thorpej locators:
    726  1.26  dholland 	  /* empty */			{ $$ = NULL; }
    727  1.26  dholland 	| locators locator		{ $$ = $2; app($2, $1); }
    728  1.26  dholland ;
    729   1.1   thorpej 
    730  1.25  dholland /* one locator */
    731   1.1   thorpej locator:
    732  1.26  dholland 	  WORD '?'			{ $$ = new_ns($1, NULL); }
    733  1.26  dholland 	| WORD values			{ $$ = mk_ns($1, $2); }
    734  1.26  dholland ;
    735   1.1   thorpej 
    736  1.25  dholland /* optional device flags */
    737  1.28  dholland device_flags:
    738  1.26  dholland 	  /* empty */			{ $$ = 0; }
    739  1.26  dholland 	| FLAGS NUMBER			{ $$ = $2.val; }
    740  1.26  dholland ;
    741   1.1   thorpej 
    742  1.29  dholland /************************************************************/
    743  1.29  dholland 
    744  1.29  dholland /*
    745  1.29  dholland  * dependency logic
    746  1.29  dholland  */
    747  1.29  dholland 
    748  1.29  dholland 
    749  1.29  dholland /*
    750  1.29  dholland  * order of options is important, must use right recursion
    751  1.29  dholland  *
    752  1.29  dholland  * dholland 20120310: wut?
    753  1.29  dholland  */
    754  1.29  dholland 
    755  1.29  dholland /* expression of config elements */
    756  1.29  dholland fexpr:
    757  1.30  dholland 	f_or_expr
    758  1.30  dholland ;
    759  1.30  dholland 
    760  1.30  dholland f_or_expr:
    761  1.30  dholland 	  f_and_expr
    762  1.30  dholland 	| f_or_expr '|' f_and_expr	{ $$ = fx_or($1, $3); }
    763  1.30  dholland ;
    764  1.30  dholland 
    765  1.30  dholland f_and_expr:
    766  1.30  dholland 	  f_prefix_expr
    767  1.30  dholland 	| f_and_expr '&' f_prefix_expr	{ $$ = fx_and($1, $3); }
    768  1.30  dholland ;
    769  1.30  dholland 
    770  1.30  dholland f_prefix_expr:
    771  1.30  dholland 	  f_base_expr
    772  1.30  dholland /* XXX notyet - need to strengthen downstream first */
    773  1.30  dholland /*	| '!' f_prefix_expr		{ $$ = fx_not($2); } */
    774  1.30  dholland ;
    775  1.30  dholland 
    776  1.30  dholland f_base_expr:
    777  1.29  dholland 	  fatom				{ $$ = $1; }
    778  1.29  dholland 	| '!' fatom			{ $$ = fx_not($2); }
    779  1.29  dholland 	| '(' fexpr ')'			{ $$ = $2; }
    780  1.29  dholland ;
    781  1.29  dholland 
    782  1.29  dholland /* basic element of config element expression: a config element */
    783  1.29  dholland fatom:
    784  1.29  dholland 	WORD				{ $$ = fx_atom($1); }
    785  1.29  dholland ;
    786  1.29  dholland 
    787  1.29  dholland /************************************************************/
    788  1.29  dholland 
    789  1.29  dholland /*
    790  1.29  dholland  * Various nonterminals shared between the grammars.
    791  1.29  dholland  */
    792  1.29  dholland 
    793  1.29  dholland /* variable name for make option */
    794  1.29  dholland mkvarname:
    795  1.29  dholland 	  QSTRING			{ $$ = $1; }
    796  1.29  dholland 	| WORD				{ $$ = $1; }
    797  1.29  dholland ;
    798  1.29  dholland 
    799  1.29  dholland /* optional file for an option */
    800  1.29  dholland optfile_opt:
    801  1.29  dholland 	  /* empty */			{ $$ = NULL; }
    802  1.29  dholland 	| filename			{ $$ = $1; }
    803  1.29  dholland ;
    804  1.29  dholland 
    805  1.29  dholland /* filename. */
    806  1.29  dholland filename:
    807  1.29  dholland 	  QSTRING			{ $$ = $1; }
    808  1.29  dholland 	| PATHNAME			{ $$ = $1; }
    809  1.29  dholland ;
    810  1.29  dholland 
    811  1.29  dholland /* constant value */
    812  1.29  dholland value:
    813  1.29  dholland 	  QSTRING			{ $$ = $1; }
    814  1.29  dholland 	| WORD				{ $$ = $1; }
    815  1.29  dholland 	| EMPTYSTRING			{ $$ = $1; }
    816  1.29  dholland 	| signed_number			{
    817  1.29  dholland 		char bf[40];
    818  1.29  dholland 
    819  1.29  dholland 		(void)snprintf(bf, sizeof(bf), FORMAT($1), (long long)$1.val);
    820  1.29  dholland 		$$ = intern(bf);
    821  1.29  dholland 	  }
    822  1.29  dholland ;
    823  1.29  dholland 
    824  1.29  dholland /* constant value that is a string */
    825  1.29  dholland stringvalue:
    826  1.29  dholland 	  QSTRING			{ $$ = $1; }
    827  1.29  dholland 	| WORD				{ $$ = $1; }
    828  1.29  dholland ;
    829  1.29  dholland 
    830  1.29  dholland /* comma-separated list of values */
    831  1.29  dholland /* XXX why right-recursive? */
    832  1.29  dholland values:
    833  1.29  dholland 	  value				{ $$ = new_s($1); }
    834  1.29  dholland 	| value ',' values		{ $$ = new_sx($1, $3); }
    835  1.29  dholland ;
    836  1.29  dholland 
    837  1.29  dholland /* possibly negative number */
    838  1.29  dholland signed_number:
    839  1.29  dholland 	  NUMBER			{ $$ = $1; }
    840  1.29  dholland 	| '-' NUMBER			{ $$.fmt = $2.fmt; $$.val = -$2.val; }
    841  1.29  dholland ;
    842  1.29  dholland 
    843  1.29  dholland /* optional ON keyword */
    844  1.29  dholland on_opt:
    845  1.29  dholland 	  /* empty */
    846  1.29  dholland 	| ON
    847  1.29  dholland ;
    848  1.29  dholland 
    849   1.1   thorpej %%
    850   1.1   thorpej 
    851   1.1   thorpej void
    852   1.1   thorpej yyerror(const char *s)
    853   1.1   thorpej {
    854   1.1   thorpej 
    855  1.13  christos 	cfgerror("%s", s);
    856   1.1   thorpej }
    857   1.1   thorpej 
    858   1.1   thorpej /*
    859   1.1   thorpej  * Cleanup procedure after syntax error: release any nvlists
    860   1.1   thorpej  * allocated during parsing the current line.
    861   1.1   thorpej  */
    862   1.1   thorpej static void
    863   1.1   thorpej cleanup(void)
    864   1.1   thorpej {
    865   1.1   thorpej 	struct nvlist **np;
    866   1.1   thorpej 	int i;
    867   1.1   thorpej 
    868   1.1   thorpej 	for (np = alloc, i = adepth; --i >= 0; np++)
    869   1.1   thorpej 		nvfree(*np);
    870   1.1   thorpej 	adepth = 0;
    871   1.1   thorpej }
    872   1.1   thorpej 
    873   1.1   thorpej static void
    874  1.20     pooka setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
    875  1.20     pooka 	int isioconf)
    876   1.1   thorpej {
    877   1.1   thorpej 	char buf[MAXPATHLEN];
    878   1.1   thorpej 	struct nvlist *nv;
    879   1.1   thorpej 
    880  1.20     pooka 	if (isioconf) {
    881  1.23     pooka 		fprintf(stderr, "WARNING: ioconf is an experimental feature\n");
    882  1.20     pooka 		if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
    883  1.20     pooka 			exit(1);
    884  1.20     pooka 		ioconfname = mch;
    885  1.20     pooka 		return;
    886  1.20     pooka 	}
    887  1.20     pooka 
    888   1.1   thorpej 	machine = mch;
    889   1.1   thorpej 	machinearch = mcharch;
    890   1.1   thorpej 	machinesubarches = mchsubarches;
    891   1.1   thorpej 
    892   1.1   thorpej 	/*
    893  1.14      cube 	 * Define attributes for all the given names
    894  1.14      cube 	 */
    895  1.15      cube 	if (defattr(machine, NULL, NULL, 0) != 0 ||
    896  1.15      cube 	    (machinearch != NULL &&
    897  1.15      cube 	     defattr(machinearch, NULL, NULL, 0) != 0))
    898  1.14      cube 		exit(1);
    899  1.14      cube 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
    900  1.14      cube 		if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
    901  1.14      cube 			exit(1);
    902  1.14      cube 	}
    903  1.14      cube 
    904  1.14      cube 	/*
    905   1.1   thorpej 	 * Set up the file inclusion stack.  This empty include tells
    906   1.1   thorpej 	 * the parser there are no more device definitions coming.
    907   1.1   thorpej 	 */
    908  1.20     pooka 	if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
    909   1.1   thorpej 		exit(1);
    910   1.1   thorpej 
    911   1.1   thorpej 	/* Include arch/${MACHINE}/conf/files.${MACHINE} */
    912   1.1   thorpej 	(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    913   1.1   thorpej 	    machine, machine);
    914   1.1   thorpej 	if (include(buf, ENDFILE, 0, 0) != 0)
    915   1.1   thorpej 		exit(1);
    916   1.1   thorpej 
    917   1.1   thorpej 	/* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
    918   1.1   thorpej 	for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
    919   1.1   thorpej 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    920   1.1   thorpej 		    nv->nv_name, nv->nv_name);
    921   1.1   thorpej 		if (include(buf, ENDFILE, 0, 0) != 0)
    922   1.1   thorpej 			exit(1);
    923   1.1   thorpej 	}
    924   1.1   thorpej 
    925   1.1   thorpej 	/* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
    926   1.1   thorpej 	if (machinearch != NULL)
    927   1.1   thorpej 		(void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
    928   1.1   thorpej 		    machinearch, machinearch);
    929   1.1   thorpej 	else
    930   1.1   thorpej 		strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
    931   1.1   thorpej 	if (include(buf, ENDFILE, 0, 0) != 0)
    932   1.1   thorpej 		exit(1);
    933   1.1   thorpej 
    934   1.1   thorpej 	/*
    935   1.1   thorpej 	 * Include the global conf/files.  As the last thing
    936   1.1   thorpej 	 * pushed on the stack, it will be processed first.
    937   1.1   thorpej 	 */
    938   1.1   thorpej 	if (include("conf/files", ENDFILE, 0, 0) != 0)
    939   1.1   thorpej 		exit(1);
    940   1.2    martin 
    941   1.2    martin 	oktopackage = 1;
    942   1.1   thorpej }
    943   1.1   thorpej 
    944   1.1   thorpej static void
    945   1.1   thorpej check_maxpart(void)
    946   1.1   thorpej {
    947   1.1   thorpej 
    948  1.20     pooka 	if (maxpartitions <= 0 && ioconfname == NULL) {
    949   1.1   thorpej 		stop("cannot proceed without maxpartitions specifier");
    950   1.1   thorpej 	}
    951   1.1   thorpej }
    952   1.1   thorpej 
    953   1.1   thorpej static void
    954   1.4      cube check_version(void)
    955   1.4      cube {
    956   1.4      cube 	/*
    957   1.4      cube 	 * In essence, version is 0 and is not supported anymore
    958   1.4      cube 	 */
    959   1.4      cube 	if (version < CONFIG_MINVERSION)
    960   1.4      cube 		stop("your sources are out of date -- please update.");
    961   1.4      cube }
    962   1.4      cube 
    963   1.4      cube static void
    964   1.1   thorpej app(struct nvlist *p, struct nvlist *q)
    965   1.1   thorpej {
    966   1.1   thorpej 	while (p->nv_next)
    967   1.1   thorpej 		p = p->nv_next;
    968   1.1   thorpej 	p->nv_next = q;
    969   1.1   thorpej }
    970   1.1   thorpej 
    971   1.1   thorpej static struct nvlist *
    972   1.1   thorpej mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
    973   1.1   thorpej {
    974   1.1   thorpej 	struct nvlist *defs = adefs;
    975   1.1   thorpej 	struct nvlist **p;
    976   1.1   thorpej 	char buf[200];
    977   1.1   thorpej 	int i;
    978   1.1   thorpej 
    979   1.1   thorpej 	if (count <= 0) {
    980   1.1   thorpej 		fprintf(stderr, "config: array with <= 0 size: %s\n", name);
    981   1.1   thorpej 		exit(1);
    982   1.1   thorpej 	}
    983   1.1   thorpej 	p = &defs;
    984   1.1   thorpej 	for(i = 0; i < count; i++) {
    985   1.1   thorpej 		if (*p == NULL)
    986   1.1   thorpej 			*p = new_s("0");
    987   1.1   thorpej 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
    988   1.1   thorpej 		(*p)->nv_name = i == 0 ? name : intern(buf);
    989  1.18  christos 		(*p)->nv_num = i > 0 || opt;
    990   1.1   thorpej 		p = &(*p)->nv_next;
    991   1.1   thorpej 	}
    992   1.1   thorpej 	*p = 0;
    993   1.1   thorpej 	return defs;
    994   1.1   thorpej }
    995   1.1   thorpej 
    996   1.1   thorpej 
    997   1.1   thorpej static struct nvlist *
    998   1.1   thorpej mk_ns(const char *name, struct nvlist *vals)
    999   1.1   thorpej {
   1000   1.1   thorpej 	struct nvlist *p;
   1001   1.1   thorpej 	char buf[200];
   1002   1.1   thorpej 	int i;
   1003   1.1   thorpej 
   1004   1.1   thorpej 	for(i = 0, p = vals; p; i++, p = p->nv_next) {
   1005   1.1   thorpej 		snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
   1006   1.1   thorpej 		p->nv_name = i == 0 ? name : intern(buf);
   1007   1.1   thorpej 	}
   1008   1.1   thorpej 	return vals;
   1009   1.1   thorpej }
   1010   1.1   thorpej 
   1011