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