config.y revision 66457
1%union {
2	char	*str;
3	int	val;
4	struct	file_list *file;
5}
6
7%token	ARCH
8%token	COMMA
9%token	CONFIG
10%token	CPU
11%token	DEVICE
12%token	EQUALS
13%token	HINTS
14%token	IDENT
15%token	MAXUSERS
16%token	OPTIONS
17%token	MAKEOPTIONS
18%token	SEMICOLON
19
20%token	<str>	ID
21%token	<val>	NUMBER
22
23%type	<str>	Save_id
24%type	<str>	Opt_value
25%type	<str>	Dev
26
27%{
28
29/*
30 * Copyright (c) 1988, 1993
31 *	The Regents of the University of California.  All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 *    notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 *    notice, this list of conditions and the following disclaimer in the
40 *    documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 *    must display the following acknowledgement:
43 *	This product includes software developed by the University of
44 *	California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 *    may be used to endorse or promote products derived from this software
47 *    without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 *	@(#)config.y	8.1 (Berkeley) 6/6/93
62 * $FreeBSD: head/usr.sbin/config/config.y 66457 2000-09-29 13:36:47Z dfr $
63 */
64
65#include <ctype.h>
66#include <err.h>
67#include <stdio.h>
68#include <string.h>
69
70#include "config.h"
71
72static struct	device cur;
73static struct	device *curp = 0;
74
75struct  device *dtab;
76char	*ident;
77char	*hints;
78int	hintmode;
79int	yyline;
80struct  file_list *ftab;
81char	errbuf[80];
82int	maxusers;
83
84#define ns(s)	strdup(s)
85
86static void yyerror(char *s);
87
88
89%}
90%%
91Configuration:
92	Many_specs
93		;
94
95Many_specs:
96	Many_specs Spec
97		|
98	/* lambda */
99		;
100
101Spec:
102	Device_spec SEMICOLON
103	      = { newdev(&cur); } |
104	Config_spec SEMICOLON
105		|
106	SEMICOLON
107		|
108	error SEMICOLON
109		;
110
111Config_spec:
112	ARCH Save_id
113	    = {
114		if (!strcmp($2, "i386")) {
115			machine = MACHINE_I386;
116			machinename = "i386";
117		} else if (!strcmp($2, "pc98")) {
118			machine = MACHINE_PC98;
119			machinename = "pc98";
120		} else if (!strcmp($2, "alpha")) {
121			machine = MACHINE_ALPHA;
122			machinename = "alpha";
123		} else if (!strcmp($2, "ia64")) {
124			machine = MACHINE_IA64;
125			machinename = "ia64";
126		} else
127			yyerror("Unknown machine type");
128	      } |
129	CPU Save_id
130	      = {
131		struct cputype *cp =
132		    (struct cputype *)malloc(sizeof (struct cputype));
133		memset(cp, 0, sizeof(*cp));
134		cp->cpu_name = $2;
135		cp->cpu_next = cputype;
136		cputype = cp;
137	      } |
138	OPTIONS Opt_list
139		|
140	MAKEOPTIONS Mkopt_list
141		|
142	IDENT ID
143	      = { ident = $2; } |
144	System_spec
145		|
146	MAXUSERS NUMBER
147	      = { maxusers = $2; } |
148	HINTS ID
149	      = {
150		      hints = $2;
151		      hintmode = 1;
152		};
153
154System_spec:
155	CONFIG System_id System_parameter_list
156	  = { warnx("line %d: root/dump/swap specifications obsolete", yyline);}
157	  |
158	CONFIG System_id
159	  ;
160
161System_id:
162	Save_id
163	      = {
164		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
165		memset(op, 0, sizeof(*op));
166		op->op_name = ns("KERNEL");
167		op->op_ownfile = 0;
168		op->op_next = mkopt;
169		op->op_value = $1;
170		op->op_line = yyline + 1;
171		mkopt = op;
172	      };
173
174System_parameter_list:
175	  System_parameter_list ID
176	| ID
177	;
178
179Opt_list:
180	Opt_list COMMA Option
181		|
182	Option
183		;
184
185Option:
186	Save_id
187	      = {
188		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
189		char *s;
190		memset(op, 0, sizeof(*op));
191		op->op_name = $1;
192		op->op_next = opt;
193		op->op_value = 0;
194		/*
195		 * op->op_line is 1-based; yyline is 0-based but is now 1
196		 * larger than when `Save_id' was lexed.
197		 */
198		op->op_line = yyline;
199		opt = op;
200		if ((s = strchr(op->op_name, '='))) {
201			warnx("line %d: The `=' in options should not be quoted", yyline);
202			*s = '\0';
203			op->op_value = ns(s + 1);
204		}
205	      } |
206	Save_id EQUALS Opt_value
207	      = {
208		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
209		memset(op, 0, sizeof(*op));
210		op->op_name = $1;
211		op->op_next = opt;
212		op->op_value = $3;
213		op->op_line = yyline + 1;
214		opt = op;
215	      } ;
216
217Opt_value:
218	ID
219		= { $$ = $1; } |
220	NUMBER
221		= {
222			char buf[80];
223
224			(void) snprintf(buf, sizeof(buf), "%d", $1);
225			$$ = ns(buf);
226		} ;
227
228Save_id:
229	ID
230	      = { $$ = $1; }
231	;
232
233Mkopt_list:
234	Mkopt_list COMMA Mkoption
235		|
236	Mkoption
237		;
238
239Mkoption:
240	Save_id EQUALS Opt_value
241	      = {
242		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
243		memset(op, 0, sizeof(*op));
244		op->op_name = $1;
245		op->op_ownfile = 0;	/* for now */
246		op->op_next = mkopt;
247		op->op_value = $3;
248		op->op_line = yyline + 1;
249		mkopt = op;
250	      } ;
251
252Dev:
253	ID
254	      = { $$ = $1; }
255	;
256
257Device_spec:
258	DEVICE Dev
259	      = {
260		cur.d_type = DEVICE;
261		cur.d_name = $2;
262		cur.d_count = UNKNOWN;
263		} |
264	DEVICE Dev NUMBER
265	      = {
266		cur.d_type = DEVICE;
267		cur.d_name = $2;
268		cur.d_count = $3;
269		if (cur.d_count == 0)
270			warnx("line %d: devices with zero units are not likely to be correct", yyline);
271		} ;
272
273%%
274
275static void
276yyerror(char *s)
277{
278
279	warnx("line %d: %s", yyline + 1, s);
280}
281
282/*
283 * add a device to the list of devices
284 */
285static void
286newdev(struct device *dp)
287{
288	struct device *np;
289
290	np = (struct device *) malloc(sizeof *np);
291	memset(np, 0, sizeof(*np));
292	*np = *dp;
293	np->d_name = dp->d_name;
294	np->d_type = dp->d_type;
295	np->d_count = dp->d_count;
296	np->d_next = 0;
297	if (curp == 0)
298		dtab = np;
299	else
300		curp->d_next = np;
301	curp = np;
302}
303