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