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