xref: /xnu-10063.121.3/SETUP/config/parser.y (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions  * Mach Operating System
3*2c2f96dcSApple OSS Distributions  * Copyright (c) 1990 Carnegie-Mellon University
4*2c2f96dcSApple OSS Distributions  * Copyright (c) 1989 Carnegie-Mellon University
5*2c2f96dcSApple OSS Distributions  * Copyright (c) 1988 Carnegie-Mellon University
6*2c2f96dcSApple OSS Distributions  * Copyright (c) 1987 Carnegie-Mellon University
7*2c2f96dcSApple OSS Distributions  * All rights reserved.  The CMU software License Agreement specifies
8*2c2f96dcSApple OSS Distributions  * the terms and conditions for use and redistribution.
9*2c2f96dcSApple OSS Distributions  */
10*2c2f96dcSApple OSS Distributions 
11*2c2f96dcSApple OSS Distributions /*
12*2c2f96dcSApple OSS Distributions  * Copyright (c) 1988 Regents of the University of California.
13*2c2f96dcSApple OSS Distributions  * All rights reserved.
14*2c2f96dcSApple OSS Distributions  *
15*2c2f96dcSApple OSS Distributions  * Redistribution and use in source and binary forms are permitted
16*2c2f96dcSApple OSS Distributions  * provided that the above copyright notice and this paragraph are
17*2c2f96dcSApple OSS Distributions  * duplicated in all such forms and that any documentation,
18*2c2f96dcSApple OSS Distributions  * advertising materials, and other materials related to such
19*2c2f96dcSApple OSS Distributions  * distribution and use acknowledge that the software was developed
20*2c2f96dcSApple OSS Distributions  * by the University of California, Berkeley.  The name of the
21*2c2f96dcSApple OSS Distributions  * University may not be used to endorse or promote products derived
22*2c2f96dcSApple OSS Distributions  * from this software without specific prior written permission.
23*2c2f96dcSApple OSS Distributions  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24*2c2f96dcSApple OSS Distributions  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25*2c2f96dcSApple OSS Distributions  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26*2c2f96dcSApple OSS Distributions  *
27*2c2f96dcSApple OSS Distributions  *	@(#)config.y	5.8 (Berkeley) 6/18/88
28*2c2f96dcSApple OSS Distributions  */
29*2c2f96dcSApple OSS Distributions 
30*2c2f96dcSApple OSS Distributions %union {
31*2c2f96dcSApple OSS Distributions 	char	*str;
32*2c2f96dcSApple OSS Distributions 	int	val;
33*2c2f96dcSApple OSS Distributions 	struct	file_list *file;
34*2c2f96dcSApple OSS Distributions 	struct	idlst *lst;
35*2c2f96dcSApple OSS Distributions }
36*2c2f96dcSApple OSS Distributions 
37*2c2f96dcSApple OSS Distributions %token	BUILDDIR
38*2c2f96dcSApple OSS Distributions %token	COMMA
39*2c2f96dcSApple OSS Distributions %token	EQUALS
40*2c2f96dcSApple OSS Distributions %token	INIT
41*2c2f96dcSApple OSS Distributions %token	MACHINE
42*2c2f96dcSApple OSS Distributions %token	OBJECTDIR
43*2c2f96dcSApple OSS Distributions %token	OPTIONS
44*2c2f96dcSApple OSS Distributions %token	MAKEOPTIONS
45*2c2f96dcSApple OSS Distributions %token	PSEUDO_DEVICE
46*2c2f96dcSApple OSS Distributions %token	SEMICOLON
47*2c2f96dcSApple OSS Distributions %token	SOURCEDIR
48*2c2f96dcSApple OSS Distributions %token	TRACE
49*2c2f96dcSApple OSS Distributions 
50*2c2f96dcSApple OSS Distributions %token	<str>	ID
51*2c2f96dcSApple OSS Distributions %token	<val>	NUMBER
52*2c2f96dcSApple OSS Distributions 
53*2c2f96dcSApple OSS Distributions %type	<str>	Save_id
54*2c2f96dcSApple OSS Distributions %type	<str>	Opt_value
55*2c2f96dcSApple OSS Distributions %type	<str>	Dev
56*2c2f96dcSApple OSS Distributions 
57*2c2f96dcSApple OSS Distributions %{
58*2c2f96dcSApple OSS Distributions 
59*2c2f96dcSApple OSS Distributions #include "config.h"
60*2c2f96dcSApple OSS Distributions #include <ctype.h>
61*2c2f96dcSApple OSS Distributions #include <stdio.h>
62*2c2f96dcSApple OSS Distributions 
63*2c2f96dcSApple OSS Distributions struct	device cur;
64*2c2f96dcSApple OSS Distributions struct	device *curp = 0;
65*2c2f96dcSApple OSS Distributions char	*temp_id;
66*2c2f96dcSApple OSS Distributions char	*val_id;
67*2c2f96dcSApple OSS Distributions /* char	*malloc(); */
68*2c2f96dcSApple OSS Distributions 
69*2c2f96dcSApple OSS Distributions int yylex(void);
70*2c2f96dcSApple OSS Distributions 
71*2c2f96dcSApple OSS Distributions void deverror(const char *systemname, const char *devtype);
72*2c2f96dcSApple OSS Distributions 
73*2c2f96dcSApple OSS Distributions %}
74*2c2f96dcSApple OSS Distributions %%
75*2c2f96dcSApple OSS Distributions Configuration:
76*2c2f96dcSApple OSS Distributions 	Many_specs
77*2c2f96dcSApple OSS Distributions 		;
78*2c2f96dcSApple OSS Distributions 
79*2c2f96dcSApple OSS Distributions Many_specs:
80*2c2f96dcSApple OSS Distributions 	Many_specs Spec
81*2c2f96dcSApple OSS Distributions 		|
82*2c2f96dcSApple OSS Distributions 	/* lambda */
83*2c2f96dcSApple OSS Distributions 		;
84*2c2f96dcSApple OSS Distributions 
85*2c2f96dcSApple OSS Distributions Spec:
86*2c2f96dcSApple OSS Distributions 	Device_spec SEMICOLON
87*2c2f96dcSApple OSS Distributions 	      { newdev(&cur); } |
88*2c2f96dcSApple OSS Distributions 	Config_spec SEMICOLON
89*2c2f96dcSApple OSS Distributions 		|
90*2c2f96dcSApple OSS Distributions 	TRACE SEMICOLON
91*2c2f96dcSApple OSS Distributions 	      { do_trace = !do_trace; } |
92*2c2f96dcSApple OSS Distributions 	SEMICOLON
93*2c2f96dcSApple OSS Distributions 		|
94*2c2f96dcSApple OSS Distributions 	error SEMICOLON
95*2c2f96dcSApple OSS Distributions 		;
96*2c2f96dcSApple OSS Distributions 
97*2c2f96dcSApple OSS Distributions Config_spec:
98*2c2f96dcSApple OSS Distributions 	MACHINE Save_id
99*2c2f96dcSApple OSS Distributions 		{ machinename = ns($2); }
100*2c2f96dcSApple OSS Distributions 		|
101*2c2f96dcSApple OSS Distributions 	OPTIONS Opt_list
102*2c2f96dcSApple OSS Distributions 		|
103*2c2f96dcSApple OSS Distributions 	MAKEOPTIONS Mkopt_list
104*2c2f96dcSApple OSS Distributions 		|
105*2c2f96dcSApple OSS Distributions 	BUILDDIR Save_id
106*2c2f96dcSApple OSS Distributions 		{ build_directory = ns($2); }
107*2c2f96dcSApple OSS Distributions 		|
108*2c2f96dcSApple OSS Distributions 	OBJECTDIR Save_id
109*2c2f96dcSApple OSS Distributions 		{ object_directory = ns($2); }
110*2c2f96dcSApple OSS Distributions 		|
111*2c2f96dcSApple OSS Distributions 	SOURCEDIR Save_id
112*2c2f96dcSApple OSS Distributions 		{ source_directory = ns($2); }
113*2c2f96dcSApple OSS Distributions 		;
114*2c2f96dcSApple OSS Distributions 
115*2c2f96dcSApple OSS Distributions 
116*2c2f96dcSApple OSS Distributions Opt_list:
117*2c2f96dcSApple OSS Distributions 	Opt_list COMMA Option
118*2c2f96dcSApple OSS Distributions 		|
119*2c2f96dcSApple OSS Distributions 	Option
120*2c2f96dcSApple OSS Distributions 		;
121*2c2f96dcSApple OSS Distributions 
122*2c2f96dcSApple OSS Distributions Option:
123*2c2f96dcSApple OSS Distributions 	Save_id
124*2c2f96dcSApple OSS Distributions 	      {
125*2c2f96dcSApple OSS Distributions 		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
126*2c2f96dcSApple OSS Distributions 		op->op_name = ns($1);
127*2c2f96dcSApple OSS Distributions 		op->op_next = (struct opt *) 0;
128*2c2f96dcSApple OSS Distributions 		op->op_value = 0;
129*2c2f96dcSApple OSS Distributions 		if (opt == (struct opt *) 0)
130*2c2f96dcSApple OSS Distributions 			opt = op;
131*2c2f96dcSApple OSS Distributions 		else
132*2c2f96dcSApple OSS Distributions 			opt_tail->op_next = op;
133*2c2f96dcSApple OSS Distributions 		opt_tail = op;
134*2c2f96dcSApple OSS Distributions 		free(temp_id);
135*2c2f96dcSApple OSS Distributions 	      } |
136*2c2f96dcSApple OSS Distributions 	Save_id EQUALS Opt_value
137*2c2f96dcSApple OSS Distributions 	      {
138*2c2f96dcSApple OSS Distributions 		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
139*2c2f96dcSApple OSS Distributions 		op->op_name = ns($1);
140*2c2f96dcSApple OSS Distributions 		op->op_next = (struct opt *) 0;
141*2c2f96dcSApple OSS Distributions 		op->op_value = ns($3);
142*2c2f96dcSApple OSS Distributions 		if (opt == (struct opt *) 0)
143*2c2f96dcSApple OSS Distributions 			opt = op;
144*2c2f96dcSApple OSS Distributions 		else
145*2c2f96dcSApple OSS Distributions 			opt_tail->op_next = op;
146*2c2f96dcSApple OSS Distributions 		opt_tail = op;
147*2c2f96dcSApple OSS Distributions 		free(temp_id);
148*2c2f96dcSApple OSS Distributions 		if (val_id)
149*2c2f96dcSApple OSS Distributions 			free(val_id);
150*2c2f96dcSApple OSS Distributions 	      } ;
151*2c2f96dcSApple OSS Distributions 
152*2c2f96dcSApple OSS Distributions Opt_value:
153*2c2f96dcSApple OSS Distributions 	ID
154*2c2f96dcSApple OSS Distributions 	      { $$ = val_id = ns($1); } |
155*2c2f96dcSApple OSS Distributions 	NUMBER
156*2c2f96dcSApple OSS Distributions 	      { char nb[16];
157*2c2f96dcSApple OSS Distributions 	          (void) sprintf(nb, "%u", $1);
158*2c2f96dcSApple OSS Distributions 	      	  $$ = val_id = ns(nb);
159*2c2f96dcSApple OSS Distributions 	      } |
160*2c2f96dcSApple OSS Distributions 	/* lambda from MIPS -- WHY */
161*2c2f96dcSApple OSS Distributions 	      { $$ = val_id = ns(""); }
162*2c2f96dcSApple OSS Distributions 	      ;
163*2c2f96dcSApple OSS Distributions 
164*2c2f96dcSApple OSS Distributions Save_id:
165*2c2f96dcSApple OSS Distributions 	ID
166*2c2f96dcSApple OSS Distributions 	      { $$ = temp_id = ns($1); }
167*2c2f96dcSApple OSS Distributions 	;
168*2c2f96dcSApple OSS Distributions 
169*2c2f96dcSApple OSS Distributions Mkopt_list:
170*2c2f96dcSApple OSS Distributions 	Mkopt_list COMMA Mkoption
171*2c2f96dcSApple OSS Distributions 		|
172*2c2f96dcSApple OSS Distributions 	Mkoption
173*2c2f96dcSApple OSS Distributions 		;
174*2c2f96dcSApple OSS Distributions 
175*2c2f96dcSApple OSS Distributions Mkoption:
176*2c2f96dcSApple OSS Distributions 	Save_id
177*2c2f96dcSApple OSS Distributions 	      {
178*2c2f96dcSApple OSS Distributions 		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
179*2c2f96dcSApple OSS Distributions 		op->op_name = ns($1);
180*2c2f96dcSApple OSS Distributions 		op->op_next =  (struct opt *) 0;
181*2c2f96dcSApple OSS Distributions 		op->op_value = 0;
182*2c2f96dcSApple OSS Distributions 		mkopt = op;
183*2c2f96dcSApple OSS Distributions 		free(temp_id);
184*2c2f96dcSApple OSS Distributions 	      } |
185*2c2f96dcSApple OSS Distributions 	Save_id EQUALS Opt_value
186*2c2f96dcSApple OSS Distributions 	      {
187*2c2f96dcSApple OSS Distributions 		struct opt *op = (struct opt *)malloc(sizeof (struct opt));
188*2c2f96dcSApple OSS Distributions 		op->op_name = ns($1);
189*2c2f96dcSApple OSS Distributions 		op->op_next =  (struct opt *) 0;
190*2c2f96dcSApple OSS Distributions 		op->op_value = ns($3);
191*2c2f96dcSApple OSS Distributions 		if (mkopt == (struct opt *) 0)
192*2c2f96dcSApple OSS Distributions 			mkopt = op;
193*2c2f96dcSApple OSS Distributions 		else
194*2c2f96dcSApple OSS Distributions 			mkopt_tail->op_next = op;
195*2c2f96dcSApple OSS Distributions 		mkopt_tail = op;
196*2c2f96dcSApple OSS Distributions 		free(temp_id);
197*2c2f96dcSApple OSS Distributions 		if (val_id)
198*2c2f96dcSApple OSS Distributions 			free(val_id);
199*2c2f96dcSApple OSS Distributions 	      } ;
200*2c2f96dcSApple OSS Distributions 
201*2c2f96dcSApple OSS Distributions Dev:
202*2c2f96dcSApple OSS Distributions 	ID
203*2c2f96dcSApple OSS Distributions 	      { $$ = ns($1); }
204*2c2f96dcSApple OSS Distributions 	;
205*2c2f96dcSApple OSS Distributions 
206*2c2f96dcSApple OSS Distributions Device_spec:
207*2c2f96dcSApple OSS Distributions 	PSEUDO_DEVICE Init_dev Dev
208*2c2f96dcSApple OSS Distributions 	      {
209*2c2f96dcSApple OSS Distributions 		cur.d_name = $3;
210*2c2f96dcSApple OSS Distributions 		cur.d_type = PSEUDO_DEVICE;
211*2c2f96dcSApple OSS Distributions 		} |
212*2c2f96dcSApple OSS Distributions 	PSEUDO_DEVICE Init_dev Dev NUMBER
213*2c2f96dcSApple OSS Distributions 	      {
214*2c2f96dcSApple OSS Distributions 		cur.d_name = $3;
215*2c2f96dcSApple OSS Distributions 		cur.d_type = PSEUDO_DEVICE;
216*2c2f96dcSApple OSS Distributions 		cur.d_slave = $4;
217*2c2f96dcSApple OSS Distributions 		} |
218*2c2f96dcSApple OSS Distributions 	PSEUDO_DEVICE Init_dev Dev INIT ID
219*2c2f96dcSApple OSS Distributions 	      {
220*2c2f96dcSApple OSS Distributions 		cur.d_name = $3;
221*2c2f96dcSApple OSS Distributions 		cur.d_type = PSEUDO_DEVICE;
222*2c2f96dcSApple OSS Distributions 		cur.d_init = ns($5);
223*2c2f96dcSApple OSS Distributions 		} |
224*2c2f96dcSApple OSS Distributions 	PSEUDO_DEVICE Init_dev Dev NUMBER INIT ID
225*2c2f96dcSApple OSS Distributions 	      {
226*2c2f96dcSApple OSS Distributions 		cur.d_name = $3;
227*2c2f96dcSApple OSS Distributions 		cur.d_type = PSEUDO_DEVICE;
228*2c2f96dcSApple OSS Distributions 		cur.d_slave = $4;
229*2c2f96dcSApple OSS Distributions 		cur.d_init = ns($6);
230*2c2f96dcSApple OSS Distributions 		};
231*2c2f96dcSApple OSS Distributions 
232*2c2f96dcSApple OSS Distributions Init_dev:
233*2c2f96dcSApple OSS Distributions 	/* lambda */
234*2c2f96dcSApple OSS Distributions 	      { init_dev(&cur); };
235*2c2f96dcSApple OSS Distributions 
236*2c2f96dcSApple OSS Distributions %%
237*2c2f96dcSApple OSS Distributions 
238*2c2f96dcSApple OSS Distributions void
239*2c2f96dcSApple OSS Distributions yyerror(const char *s)
240*2c2f96dcSApple OSS Distributions {
241*2c2f96dcSApple OSS Distributions 	fprintf(stderr, "config: line %d: %s\n", yyline, s);
242*2c2f96dcSApple OSS Distributions }
243*2c2f96dcSApple OSS Distributions 
244*2c2f96dcSApple OSS Distributions /*
245*2c2f96dcSApple OSS Distributions  * return the passed string in a new space
246*2c2f96dcSApple OSS Distributions  */
247*2c2f96dcSApple OSS Distributions char *
ns(const char * str)248*2c2f96dcSApple OSS Distributions ns(const char *str)
249*2c2f96dcSApple OSS Distributions {
250*2c2f96dcSApple OSS Distributions 	register char *cp;
251*2c2f96dcSApple OSS Distributions 
252*2c2f96dcSApple OSS Distributions 	cp = malloc((unsigned)(strlen(str)+1));
253*2c2f96dcSApple OSS Distributions 	(void) strcpy(cp, str);
254*2c2f96dcSApple OSS Distributions 	return (cp);
255*2c2f96dcSApple OSS Distributions }
256*2c2f96dcSApple OSS Distributions 
257*2c2f96dcSApple OSS Distributions /*
258*2c2f96dcSApple OSS Distributions  * add a device to the list of devices
259*2c2f96dcSApple OSS Distributions  */
260*2c2f96dcSApple OSS Distributions void
newdev(struct device * dp)261*2c2f96dcSApple OSS Distributions newdev(struct device *dp)
262*2c2f96dcSApple OSS Distributions {
263*2c2f96dcSApple OSS Distributions 	register struct device *np;
264*2c2f96dcSApple OSS Distributions 
265*2c2f96dcSApple OSS Distributions 	np = (struct device *) malloc(sizeof *np);
266*2c2f96dcSApple OSS Distributions 	*np = *dp;
267*2c2f96dcSApple OSS Distributions 	if (curp == 0)
268*2c2f96dcSApple OSS Distributions 		dtab = np;
269*2c2f96dcSApple OSS Distributions 	else
270*2c2f96dcSApple OSS Distributions 		curp->d_next = np;
271*2c2f96dcSApple OSS Distributions 	curp = np;
272*2c2f96dcSApple OSS Distributions 	curp->d_next = 0;
273*2c2f96dcSApple OSS Distributions }
274*2c2f96dcSApple OSS Distributions 
275*2c2f96dcSApple OSS Distributions void
init_dev(struct device * dp)276*2c2f96dcSApple OSS Distributions init_dev(struct device *dp)
277*2c2f96dcSApple OSS Distributions {
278*2c2f96dcSApple OSS Distributions 
279*2c2f96dcSApple OSS Distributions 	dp->d_name = "OHNO!!!";
280*2c2f96dcSApple OSS Distributions 	dp->d_type = PSEUDO_DEVICE;
281*2c2f96dcSApple OSS Distributions 	dp->d_flags = 0;
282*2c2f96dcSApple OSS Distributions 	dp->d_slave = UNKNOWN;
283*2c2f96dcSApple OSS Distributions 	dp->d_init = 0;
284*2c2f96dcSApple OSS Distributions }
285*2c2f96dcSApple OSS Distributions 
286*2c2f96dcSApple OSS Distributions void
deverror(const char * systemname,const char * devtype)287*2c2f96dcSApple OSS Distributions deverror(const char *systemname, const char *devtype)
288*2c2f96dcSApple OSS Distributions {
289*2c2f96dcSApple OSS Distributions 
290*2c2f96dcSApple OSS Distributions 	fprintf(stderr, "config: %s: %s device not configured\n",
291*2c2f96dcSApple OSS Distributions 		systemname, devtype);
292*2c2f96dcSApple OSS Distributions }
293