xref: /freebsd/usr.sbin/config/config.y (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
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 *curp = 0;
74 
75 struct  device *dtab;
76 char	*ident;
77 char	*hints;
78 int	hintmode;
79 int	yyline;
80 struct  file_list *ftab;
81 char	errbuf[80];
82 int	maxusers;
83 
84 #define ns(s)	strdup(s)
85 
86 static void yyerror(const char *s);
87 
88 static char *
89 devopt(char *dev)
90 {
91 	char *ret = malloc(strlen(dev) + 5);
92 
93 	sprintf(ret, "DEV_%s", dev);
94 	raisestr(ret);
95 	return ret;
96 }
97 
98 %}
99 %%
100 Configuration:
101 	Many_specs
102 		;
103 
104 Many_specs:
105 	Many_specs Spec
106 		|
107 	/* lambda */
108 		;
109 
110 Spec:
111 	Device_spec SEMICOLON
112 		|
113 	Config_spec SEMICOLON
114 		|
115 	SEMICOLON
116 		|
117 	error SEMICOLON
118 		;
119 
120 Config_spec:
121 	ARCH Save_id
122 	    = {
123 		machinename = $2;
124 	      } |
125 	CPU Save_id
126 	      = {
127 		struct cputype *cp =
128 		    (struct cputype *)malloc(sizeof (struct cputype));
129 		memset(cp, 0, sizeof(*cp));
130 		cp->cpu_name = $2;
131 		cp->cpu_next = cputype;
132 		cputype = cp;
133 	      } |
134 	OPTIONS Opt_list
135 		|
136 	MAKEOPTIONS Mkopt_list
137 		|
138 	IDENT ID
139 	      = { ident = $2; } |
140 	System_spec
141 		|
142 	MAXUSERS NUMBER
143 	      = { maxusers = $2; } |
144 	PROFILE NUMBER
145 	      = { profiling = $2; } |
146 	HINTS ID
147 	      = {
148 		      hints = $2;
149 		      hintmode = 1;
150 		};
151 
152 System_spec:
153 	CONFIG System_id System_parameter_list
154 	  = { errx(1, "line %d: root/dump/swap specifications obsolete", yyline);}
155 	  |
156 	CONFIG System_id
157 	  ;
158 
159 System_id:
160 	Save_id
161 	      = { newopt(&mkopt, ns("KERNEL"), $1); };
162 
163 System_parameter_list:
164 	  System_parameter_list ID
165 	| ID
166 	;
167 
168 Opt_list:
169 	Opt_list COMMA Option
170 		|
171 	Option
172 		;
173 
174 Option:
175 	Save_id
176 	      = {
177 		char *s;
178 
179 		newopt(&opt, $1, NULL);
180 		if ((s = strchr($1, '=')))
181 			errx(1, "line %d: The `=' in options should not be quoted", yyline);
182 	      } |
183 	Save_id EQUALS Opt_value
184 	      = {
185 		newopt(&opt, $1, $3);
186 	      } ;
187 
188 Opt_value:
189 	ID
190 		= { $$ = $1; } |
191 	NUMBER
192 		= {
193 			char buf[80];
194 
195 			(void) snprintf(buf, sizeof(buf), "%d", $1);
196 			$$ = ns(buf);
197 		} ;
198 
199 Save_id:
200 	ID
201 	      = { $$ = $1; }
202 	;
203 
204 Mkopt_list:
205 	Mkopt_list COMMA Mkoption
206 		|
207 	Mkoption
208 		;
209 
210 Mkoption:
211 	Save_id EQUALS Opt_value
212 	      = { newopt(&mkopt, $1, $3); } ;
213 
214 Dev:
215 	ID
216 	      = { $$ = $1; }
217 	;
218 
219 Device_spec:
220 	DEVICE Dev
221 	      = {
222 		newopt(&opt, devopt($2), ns("1"));
223 		/* and the device part */
224 		newdev($2, UNKNOWN);
225 		} |
226 	DEVICE Dev NUMBER
227 	      = {
228 		newopt(&opt, devopt($2), ns("1"));
229 		/* and the device part */
230 		newdev($2, $3);
231 		if ($3 == 0)
232 			errx(1, "line %d: devices with zero units are not likely to be correct", yyline);
233 		} ;
234 
235 %%
236 
237 static void
238 yyerror(const char *s)
239 {
240 
241 	errx(1, "line %d: %s", yyline + 1, s);
242 }
243 
244 /*
245  * add a device to the list of devices
246  */
247 static void
248 newdev(char *name, int count)
249 {
250 	struct device *np;
251 
252 	np = (struct device *) malloc(sizeof *np);
253 	memset(np, 0, sizeof(*np));
254 	np->d_name = name;
255 	np->d_count = count;
256 	np->d_next = 0;
257 	if (curp == 0)
258 		dtab = np;
259 	else
260 		curp->d_next = np;
261 	curp = np;
262 }
263 
264 static void
265 newopt(struct opt **list, char *name, char *value)
266 {
267 	struct opt *op;
268 
269 	op = (struct opt *)malloc(sizeof (struct opt));
270 	memset(op, 0, sizeof(*op));
271 	op->op_name = name;
272 	op->op_ownfile = 0;
273 	op->op_value = value;
274 	op->op_next = *list;
275 	*list = op;
276 }
277