gram.y revision 1.31 1 1.1 thorpej %{
2 1.31 dholland /* $NetBSD: gram.y,v 1.31 2012/03/11 07:27:02 dholland Exp $ */
3 1.1 thorpej
4 1.1 thorpej /*
5 1.1 thorpej * Copyright (c) 1992, 1993
6 1.1 thorpej * The Regents of the University of California. All rights reserved.
7 1.1 thorpej *
8 1.1 thorpej * This software was developed by the Computer Systems Engineering group
9 1.1 thorpej * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 1.1 thorpej * contributed to Berkeley.
11 1.1 thorpej *
12 1.1 thorpej * All advertising materials mentioning features or use of this software
13 1.1 thorpej * must display the following acknowledgement:
14 1.1 thorpej * This product includes software developed by the University of
15 1.1 thorpej * California, Lawrence Berkeley Laboratories.
16 1.1 thorpej *
17 1.1 thorpej * Redistribution and use in source and binary forms, with or without
18 1.1 thorpej * modification, are permitted provided that the following conditions
19 1.1 thorpej * are met:
20 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
21 1.1 thorpej * notice, this list of conditions and the following disclaimer.
22 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
23 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
24 1.1 thorpej * documentation and/or other materials provided with the distribution.
25 1.1 thorpej * 3. Neither the name of the University nor the names of its contributors
26 1.1 thorpej * may be used to endorse or promote products derived from this software
27 1.1 thorpej * without specific prior written permission.
28 1.1 thorpej *
29 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 1.1 thorpej * SUCH DAMAGE.
40 1.1 thorpej *
41 1.1 thorpej * from: @(#)gram.y 8.1 (Berkeley) 6/6/93
42 1.1 thorpej */
43 1.1 thorpej
44 1.1 thorpej #include <sys/types.h>
45 1.1 thorpej #include <sys/param.h>
46 1.1 thorpej #include <ctype.h>
47 1.1 thorpej #include <stdio.h>
48 1.1 thorpej #include <stdlib.h>
49 1.1 thorpej #include <string.h>
50 1.1 thorpej #include <errno.h>
51 1.1 thorpej #include "defs.h"
52 1.1 thorpej #include "sem.h"
53 1.1 thorpej
54 1.1 thorpej #define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
55 1.1 thorpej ((n).fmt == 16) ? "0x%llx" : "%lld")
56 1.1 thorpej
57 1.13 christos #define stop(s) cfgerror(s), exit(1)
58 1.1 thorpej
59 1.1 thorpej static struct config conf; /* at most one active at a time */
60 1.1 thorpej
61 1.31 dholland
62 1.31 dholland /*
63 1.31 dholland * Allocation wrapper functions
64 1.31 dholland */
65 1.31 dholland static void wrap_alloc(void *ptr, unsigned code);
66 1.31 dholland static void wrap_continue(void);
67 1.31 dholland static void wrap_cleanup(void);
68 1.31 dholland
69 1.31 dholland /*
70 1.31 dholland * Allocation wrapper type codes
71 1.31 dholland */
72 1.31 dholland #define WRAP_CODE_nvlist 1
73 1.31 dholland
74 1.31 dholland /*
75 1.31 dholland * The allocation wrappers themselves
76 1.31 dholland */
77 1.31 dholland #define DECL_ALLOCWRAP(t) static struct t *wrap_mk_##t(struct t *arg)
78 1.31 dholland
79 1.31 dholland DECL_ALLOCWRAP(nvlist);
80 1.31 dholland
81 1.31 dholland /*
82 1.31 dholland * Macros for allocating new objects
83 1.31 dholland */
84 1.31 dholland
85 1.31 dholland #define new0(n,s,p,i,x) wrap_mk_nvlist(newnv(n, s, p, i, x))
86 1.1 thorpej #define new_n(n) new0(n, NULL, NULL, 0, NULL)
87 1.1 thorpej #define new_nx(n, x) new0(n, NULL, NULL, 0, x)
88 1.1 thorpej #define new_ns(n, s) new0(n, s, NULL, 0, NULL)
89 1.1 thorpej #define new_si(s, i) new0(NULL, s, NULL, i, NULL)
90 1.1 thorpej #define new_nsi(n,s,i) new0(n, s, NULL, i, NULL)
91 1.1 thorpej #define new_np(n, p) new0(n, NULL, p, 0, NULL)
92 1.1 thorpej #define new_s(s) new0(NULL, s, NULL, 0, NULL)
93 1.1 thorpej #define new_p(p) new0(NULL, NULL, p, 0, NULL)
94 1.1 thorpej #define new_px(p, x) new0(NULL, NULL, p, 0, x)
95 1.1 thorpej #define new_sx(s, x) new0(NULL, s, NULL, 0, x)
96 1.11 cube #define new_nsx(n,s,x) new0(n, s, NULL, 0, x)
97 1.24 pooka #define new_i(i) new0(NULL, NULL, NULL, i, NULL)
98 1.1 thorpej
99 1.1 thorpej #define fx_atom(s) new0(s, NULL, NULL, FX_ATOM, NULL)
100 1.1 thorpej #define fx_not(e) new0(NULL, NULL, NULL, FX_NOT, e)
101 1.1 thorpej #define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2)
102 1.1 thorpej #define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2)
103 1.1 thorpej
104 1.31 dholland /*
105 1.31 dholland * Other private functions
106 1.31 dholland */
107 1.31 dholland
108 1.20 pooka static void setmachine(const char *, const char *, struct nvlist *, int);
109 1.1 thorpej static void check_maxpart(void);
110 1.1 thorpej
111 1.1 thorpej static void app(struct nvlist *, struct nvlist *);
112 1.1 thorpej
113 1.1 thorpej static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
114 1.1 thorpej static struct nvlist *mk_ns(const char *, struct nvlist *);
115 1.1 thorpej
116 1.1 thorpej %}
117 1.1 thorpej
118 1.1 thorpej %union {
119 1.1 thorpej struct attr *attr;
120 1.1 thorpej struct devbase *devb;
121 1.1 thorpej struct deva *deva;
122 1.1 thorpej struct nvlist *list;
123 1.1 thorpej const char *str;
124 1.1 thorpej struct numconst num;
125 1.1 thorpej int64_t val;
126 1.1 thorpej }
127 1.1 thorpej
128 1.1 thorpej %token AND AT ATTACH
129 1.1 thorpej %token BLOCK BUILD
130 1.11 cube %token CHAR COLONEQ COMPILE_WITH CONFIG
131 1.16 drochner %token DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
132 1.16 drochner %token DEVICE DEVCLASS DUMPS DEVICE_MAJOR
133 1.1 thorpej %token ENDFILE
134 1.1 thorpej %token XFILE FILE_SYSTEM FLAGS
135 1.20 pooka %token IDENT IOCONF
136 1.24 pooka %token LINKZERO
137 1.1 thorpej %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
138 1.1 thorpej %token NEEDS_COUNT NEEDS_FLAG NO
139 1.6 cube %token XOBJECT OBSOLETE ON OPTIONS
140 1.22 pooka %token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT
141 1.1 thorpej %token ROOT
142 1.24 pooka %token SINGLE SOURCE
143 1.1 thorpej %token TYPE
144 1.24 pooka %token VECTOR VERSION
145 1.1 thorpej %token WITH
146 1.1 thorpej %token <num> NUMBER
147 1.8 christos %token <str> PATHNAME QSTRING WORD EMPTYSTRING
148 1.1 thorpej %token ENDDEFS
149 1.1 thorpej
150 1.1 thorpej %type <list> fopts fexpr fatom
151 1.30 dholland %type <list> f_or_expr f_and_expr f_prefix_expr f_base_expr
152 1.1 thorpej %type <str> fs_spec
153 1.1 thorpej %type <val> fflgs fflag oflgs oflag
154 1.1 thorpej %type <str> rule
155 1.1 thorpej %type <attr> attr
156 1.1 thorpej %type <devb> devbase
157 1.1 thorpej %type <deva> devattach_opt
158 1.1 thorpej %type <list> atlist interface_opt
159 1.1 thorpej %type <str> atname
160 1.28 dholland %type <list> loclist locdef
161 1.1 thorpej %type <str> locdefault
162 1.1 thorpej %type <list> values locdefaults
163 1.1 thorpej %type <list> attrs_opt attrs
164 1.1 thorpej %type <list> locators locator
165 1.1 thorpej %type <list> dev_spec
166 1.1 thorpej %type <str> device_instance
167 1.1 thorpej %type <str> attachment
168 1.1 thorpej %type <str> value
169 1.1 thorpej %type <val> major_minor npseudo
170 1.1 thorpej %type <num> signed_number
171 1.28 dholland %type <val> device_flags
172 1.1 thorpej %type <str> deffs
173 1.1 thorpej %type <list> deffses
174 1.10 dsl %type <list> defopt
175 1.1 thorpej %type <list> defopts
176 1.1 thorpej %type <str> optdep
177 1.1 thorpej %type <list> optdeps
178 1.1 thorpej %type <list> defoptdeps
179 1.1 thorpej %type <str> optfile_opt
180 1.28 dholland %type <list> subarches
181 1.1 thorpej %type <str> filename stringvalue locname mkvarname
182 1.1 thorpej %type <val> device_major_block device_major_char
183 1.24 pooka %type <list> devnodes devnodetype devnodeflags devnode_dims
184 1.1 thorpej
185 1.1 thorpej %%
186 1.1 thorpej
187 1.1 thorpej /*
188 1.25 dholland * A complete configuration consists of both the configuration part (a
189 1.25 dholland * kernel config such as GENERIC or SKYNET, plus also the various
190 1.25 dholland * std.* files), which selects the material to be in the kernel, and
191 1.25 dholland * also the definition part (files, files.*, etc.) that declares what
192 1.25 dholland * material is available to be placed in kernels.
193 1.25 dholland *
194 1.25 dholland * The two parts have almost entirely separate syntaxes. This grammar
195 1.25 dholland * covers both of them. When config is run on a kernel configuration
196 1.25 dholland * file, the std.* file for the port is included explicitly. The
197 1.25 dholland * files.* files are included implicitly when the std.* file declares
198 1.25 dholland * the machine type.
199 1.25 dholland *
200 1.25 dholland * The machine spec, which brings in the definition part, must appear
201 1.25 dholland * before all configuration material except for the "topthings"; these
202 1.25 dholland * are the "source" and "build" declarations that tell config where
203 1.25 dholland * things are. These are not used by default.
204 1.25 dholland *
205 1.25 dholland * A previous version of this comment contained the following text:
206 1.25 dholland *
207 1.25 dholland * Note that we do not have sufficient keywords to enforce any
208 1.25 dholland * order between elements of "topthings" without introducing
209 1.25 dholland * shift/reduce conflicts. Instead, check order requirements in
210 1.25 dholland * the C code.
211 1.25 dholland *
212 1.25 dholland * As of March 2012 this comment makes no sense, as there are only two
213 1.25 dholland * topthings and no reason for them to be forcibly ordered.
214 1.25 dholland * Furthermore, the statement about conflicts is false.
215 1.1 thorpej */
216 1.25 dholland
217 1.25 dholland /* Complete configuration. */
218 1.28 dholland configuration:
219 1.28 dholland topthings machine_spec definition_part configuration_part
220 1.26 dholland ;
221 1.1 thorpej
222 1.25 dholland /* Sequence of zero or more topthings. */
223 1.1 thorpej topthings:
224 1.26 dholland /* empty */
225 1.26 dholland | topthings topthing
226 1.26 dholland ;
227 1.1 thorpej
228 1.25 dholland /* Directory specification. */
229 1.1 thorpej topthing:
230 1.27 dholland '\n'
231 1.27 dholland | SOURCE filename '\n' { if (!srcdir) srcdir = $2; }
232 1.26 dholland | BUILD filename '\n' { if (!builddir) builddir = $2; }
233 1.26 dholland ;
234 1.1 thorpej
235 1.25 dholland /* "machine foo" from std.whatever */
236 1.1 thorpej machine_spec:
237 1.26 dholland XMACHINE WORD '\n' { setmachine($2,NULL,NULL,0); }
238 1.28 dholland | XMACHINE WORD WORD '\n' { setmachine($2,$3,NULL,0); }
239 1.28 dholland | XMACHINE WORD WORD subarches '\n' { setmachine($2,$3,$4,0); }
240 1.26 dholland | IOCONF WORD '\n' { setmachine($2,NULL,NULL,1); }
241 1.26 dholland | error { stop("cannot proceed without machine or ioconf specifier"); }
242 1.26 dholland ;
243 1.1 thorpej
244 1.28 dholland /* One or more sub-arches. */
245 1.1 thorpej subarches:
246 1.27 dholland WORD { $$ = new_n($1); }
247 1.27 dholland | subarches WORD { $$ = new_nx($2, $1); }
248 1.26 dholland ;
249 1.1 thorpej
250 1.25 dholland /************************************************************/
251 1.25 dholland
252 1.1 thorpej /*
253 1.1 thorpej * The machine definitions grammar.
254 1.1 thorpej */
255 1.25 dholland
256 1.25 dholland /* Complete definition part: the contents of all files.* files. */
257 1.28 dholland definition_part:
258 1.28 dholland definitions ENDDEFS { check_maxpart(); check_version(); }
259 1.26 dholland ;
260 1.1 thorpej
261 1.28 dholland /* Zero or more definitions. Trap errors. */
262 1.28 dholland definitions:
263 1.28 dholland /* empty */
264 1.28 dholland | definitions '\n'
265 1.31 dholland | definitions definition '\n' { wrap_continue(); }
266 1.31 dholland | definitions error '\n' { wrap_cleanup(); }
267 1.28 dholland | definitions ENDFILE { enddefs(); checkfiles(); }
268 1.26 dholland ;
269 1.1 thorpej
270 1.25 dholland /* A single definition. */
271 1.28 dholland definition:
272 1.26 dholland file
273 1.26 dholland | object
274 1.26 dholland | device_major { do_devsw = 1; }
275 1.26 dholland | prefix
276 1.26 dholland | DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); }
277 1.26 dholland | DEFFS deffses defoptdeps { deffilesystem($2, $3); }
278 1.26 dholland | DEFINE WORD interface_opt attrs_opt
279 1.26 dholland { (void)defattr($2, $3, $4, 0); }
280 1.26 dholland | DEFOPT optfile_opt defopts defoptdeps
281 1.26 dholland { defoption($2, $3, $4); }
282 1.26 dholland | DEFFLAG optfile_opt defopts defoptdeps
283 1.26 dholland { defflag($2, $3, $4, 0); }
284 1.26 dholland | OBSOLETE DEFFLAG optfile_opt defopts
285 1.26 dholland { defflag($3, $4, NULL, 1); }
286 1.26 dholland | DEFPARAM optfile_opt defopts defoptdeps
287 1.26 dholland { defparam($2, $3, $4, 0); }
288 1.26 dholland | OBSOLETE DEFPARAM optfile_opt defopts
289 1.26 dholland { defparam($3, $4, NULL, 1); }
290 1.26 dholland | DEVICE devbase interface_opt attrs_opt
291 1.26 dholland { defdev($2, $3, $4, 0); }
292 1.26 dholland | ATTACH devbase AT atlist devattach_opt attrs_opt
293 1.26 dholland { defdevattach($5, $2, $4, $6); }
294 1.26 dholland | MAXPARTITIONS NUMBER { maxpartitions = $2.val; }
295 1.26 dholland | MAXUSERS NUMBER NUMBER NUMBER
296 1.26 dholland { setdefmaxusers($2.val, $3.val, $4.val); }
297 1.26 dholland | MAKEOPTIONS condmkopt_list
298 1.17 drochner /* interface_opt in DEFPSEUDO is for backwards compatibility */
299 1.26 dholland | DEFPSEUDO devbase interface_opt attrs_opt
300 1.26 dholland { defdev($2, $3, $4, 1); }
301 1.26 dholland | DEFPSEUDODEV devbase interface_opt attrs_opt
302 1.26 dholland { defdev($2, $3, $4, 2); }
303 1.26 dholland | MAJOR '{' majorlist '}'
304 1.26 dholland | VERSION NUMBER { setversion($2.val); }
305 1.26 dholland ;
306 1.1 thorpej
307 1.29 dholland /* source file: file foo/bar.c bar|baz needs-flag compile-with blah */
308 1.29 dholland file:
309 1.29 dholland XFILE filename fopts fflgs rule { addfile($2, $3, $4, $5); }
310 1.26 dholland ;
311 1.1 thorpej
312 1.29 dholland /* file options: optional expression of config elements */
313 1.29 dholland fopts:
314 1.29 dholland /* empty */ { $$ = NULL; }
315 1.29 dholland | fexpr { $$ = $1; }
316 1.26 dholland ;
317 1.1 thorpej
318 1.29 dholland /* zero or more flags for a file */
319 1.29 dholland fflgs:
320 1.29 dholland /* empty */ { $$ = 0; }
321 1.29 dholland | fflgs fflag { $$ = $1 | $2; }
322 1.26 dholland ;
323 1.1 thorpej
324 1.29 dholland /* one flag for a file */
325 1.29 dholland fflag:
326 1.29 dholland NEEDS_COUNT { $$ = FI_NEEDSCOUNT; }
327 1.29 dholland | NEEDS_FLAG { $$ = FI_NEEDSFLAG; }
328 1.26 dholland ;
329 1.1 thorpej
330 1.29 dholland /* extra compile directive for a source file */
331 1.29 dholland rule:
332 1.26 dholland /* empty */ { $$ = NULL; }
333 1.29 dholland | COMPILE_WITH stringvalue { $$ = $2; }
334 1.29 dholland ;
335 1.29 dholland
336 1.29 dholland /* object file: object zot.o foo|zot needs-flag */
337 1.29 dholland object:
338 1.29 dholland XOBJECT filename fopts oflgs { addobject($2, $3, $4); }
339 1.29 dholland ;
340 1.29 dholland
341 1.29 dholland /* zero or more flags for an object file */
342 1.29 dholland oflgs:
343 1.29 dholland /* empty */ { $$ = 0; }
344 1.29 dholland | oflgs oflag { $$ = $1 | $2; }
345 1.29 dholland ;
346 1.29 dholland
347 1.29 dholland /* a single flag for an object file */
348 1.29 dholland oflag:
349 1.29 dholland NEEDS_FLAG { $$ = OI_NEEDSFLAG; }
350 1.29 dholland ;
351 1.29 dholland
352 1.29 dholland /* device major declaration */
353 1.29 dholland device_major:
354 1.29 dholland DEVICE_MAJOR WORD device_major_char device_major_block fopts devnodes
355 1.29 dholland { adddevm($2, $3, $4, $5, $6); }
356 1.29 dholland ;
357 1.29 dholland
358 1.29 dholland /* char 55 */
359 1.29 dholland device_major_char:
360 1.29 dholland /* empty */ { $$ = -1; }
361 1.29 dholland | CHAR NUMBER { $$ = $2.val; }
362 1.26 dholland ;
363 1.1 thorpej
364 1.29 dholland /* block 33 */
365 1.29 dholland device_major_block:
366 1.29 dholland /* empty */ { $$ = -1; }
367 1.29 dholland | BLOCK NUMBER { $$ = $2.val; }
368 1.26 dholland ;
369 1.1 thorpej
370 1.29 dholland /* device node specification */
371 1.29 dholland devnodes:
372 1.29 dholland /* empty */ { $$ = new_s("DEVNODE_DONTBOTHER"); }
373 1.29 dholland | devnodetype ',' devnodeflags { $$ = nvcat($1, $3); }
374 1.29 dholland | devnodetype { $$ = $1; }
375 1.26 dholland ;
376 1.1 thorpej
377 1.29 dholland /* device nodes without flags */
378 1.29 dholland devnodetype:
379 1.29 dholland SINGLE { $$ = new_s("DEVNODE_SINGLE"); }
380 1.29 dholland | VECTOR '=' devnode_dims { $$ = nvcat(new_s("DEVNODE_VECTOR"), $3); }
381 1.26 dholland ;
382 1.1 thorpej
383 1.29 dholland /* dimensions (?) */
384 1.29 dholland devnode_dims:
385 1.29 dholland NUMBER { $$ = new_i($1.val); }
386 1.29 dholland | NUMBER ':' NUMBER {
387 1.29 dholland struct nvlist *__nv1, *__nv2;
388 1.26 dholland
389 1.29 dholland __nv1 = new_i($1.val);
390 1.29 dholland __nv2 = new_i($3.val);
391 1.29 dholland $$ = nvcat(__nv1, __nv2);
392 1.26 dholland }
393 1.29 dholland ;
394 1.29 dholland
395 1.29 dholland /* flags for device nodes */
396 1.29 dholland devnodeflags:
397 1.29 dholland LINKZERO { $$ = new_s("DEVNODE_FLAG_LINKZERO");}
398 1.29 dholland ;
399 1.26 dholland
400 1.29 dholland /* prefix delimiter */
401 1.29 dholland prefix:
402 1.29 dholland PREFIX filename { prefix_push($2); }
403 1.29 dholland | PREFIX { prefix_pop(); }
404 1.26 dholland ;
405 1.1 thorpej
406 1.29 dholland /* one or more file system names */
407 1.29 dholland deffses:
408 1.29 dholland deffs { $$ = new_n($1); }
409 1.29 dholland | deffses deffs { $$ = new_nx($2, $1); }
410 1.26 dholland ;
411 1.1 thorpej
412 1.29 dholland /* a single file system name */
413 1.29 dholland deffs:
414 1.29 dholland WORD { $$ = $1; }
415 1.26 dholland ;
416 1.1 thorpej
417 1.28 dholland /* optional locator specification */
418 1.1 thorpej interface_opt:
419 1.26 dholland /* empty */ { $$ = NULL; }
420 1.28 dholland | '{' '}' { $$ = new_nx("", NULL); }
421 1.28 dholland | '{' loclist '}' { $$ = new_nx("", $2); }
422 1.26 dholland ;
423 1.1 thorpej
424 1.25 dholland /*
425 1.25 dholland * loclist order matters, must use right recursion
426 1.25 dholland * XXX wot?
427 1.25 dholland */
428 1.25 dholland
429 1.25 dholland /* list of locator definitions */
430 1.1 thorpej loclist:
431 1.26 dholland locdef { $$ = $1; }
432 1.26 dholland | locdef ',' loclist { $$ = $1; app($1, $3); }
433 1.26 dholland ;
434 1.1 thorpej
435 1.25 dholland /*
436 1.25 dholland * "[ WORD locdefault ]" syntax may be unnecessary...
437 1.25 dholland */
438 1.25 dholland
439 1.25 dholland /* one locator definition */
440 1.1 thorpej locdef:
441 1.26 dholland locname locdefault { $$ = new_nsi($1, $2, 0); }
442 1.26 dholland | locname { $$ = new_nsi($1, NULL, 0); }
443 1.26 dholland | '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); }
444 1.26 dholland | locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); }
445 1.26 dholland | locname '[' NUMBER ']' locdefaults
446 1.26 dholland { $$ = mk_nsis($1, $3.val, $5, 0); }
447 1.26 dholland | '[' locname '[' NUMBER ']' locdefaults ']'
448 1.26 dholland { $$ = mk_nsis($2, $4.val, $6, 1); }
449 1.26 dholland ;
450 1.1 thorpej
451 1.25 dholland /* locator name */
452 1.1 thorpej locname:
453 1.26 dholland WORD { $$ = $1; }
454 1.26 dholland | QSTRING { $$ = $1; }
455 1.26 dholland ;
456 1.1 thorpej
457 1.25 dholland /* locator default value */
458 1.1 thorpej locdefault:
459 1.26 dholland '=' value { $$ = $2; }
460 1.26 dholland ;
461 1.1 thorpej
462 1.25 dholland /* multiple locator default values */
463 1.1 thorpej locdefaults:
464 1.26 dholland '=' '{' values '}' { $$ = $3; }
465 1.26 dholland ;
466 1.1 thorpej
467 1.29 dholland /* optional attributes */
468 1.29 dholland attrs_opt:
469 1.26 dholland /* empty */ { $$ = NULL; }
470 1.29 dholland | ':' attrs { $$ = $2; }
471 1.29 dholland ;
472 1.29 dholland
473 1.29 dholland /* one or more attributes */
474 1.29 dholland attrs:
475 1.29 dholland attr { $$ = new_p($1); }
476 1.29 dholland | attrs ',' attr { $$ = new_px($3, $1); }
477 1.29 dholland ;
478 1.29 dholland
479 1.29 dholland /* one attribute */
480 1.29 dholland attr:
481 1.29 dholland WORD { $$ = getattr($1); }
482 1.29 dholland ;
483 1.29 dholland
484 1.29 dholland /* list of places to attach: attach blah at ... */
485 1.29 dholland atlist:
486 1.29 dholland atname { $$ = new_n($1); }
487 1.29 dholland | atlist ',' atname { $$ = new_nx($3, $1); }
488 1.29 dholland ;
489 1.29 dholland
490 1.29 dholland /* a place to attach a device */
491 1.29 dholland atname:
492 1.29 dholland WORD { $$ = $1; }
493 1.29 dholland | ROOT { $$ = NULL; }
494 1.26 dholland ;
495 1.1 thorpej
496 1.29 dholland /* one or more defined options */
497 1.29 dholland defopts:
498 1.29 dholland defopt { $$ = $1; }
499 1.29 dholland | defopts defopt { $$ = nvcat($2, $1); }
500 1.26 dholland ;
501 1.1 thorpej
502 1.29 dholland /* one defined option */
503 1.29 dholland defopt:
504 1.29 dholland WORD { $$ = new_n($1); }
505 1.29 dholland | WORD '=' value { $$ = new_ns($1, $3); }
506 1.29 dholland | WORD COLONEQ value {
507 1.29 dholland struct nvlist *__nv = new_n($1);
508 1.29 dholland
509 1.29 dholland $$ = new_nsx("", $3, __nv);
510 1.29 dholland }
511 1.29 dholland | WORD '=' value COLONEQ value {
512 1.29 dholland struct nvlist *__nv = new_n($1);
513 1.26 dholland
514 1.29 dholland $$ = new_nsx("", $5, __nv);
515 1.26 dholland }
516 1.26 dholland ;
517 1.1 thorpej
518 1.29 dholland /* option dependencies (read as "defopt deps") which are optional */
519 1.29 dholland defoptdeps:
520 1.29 dholland /* empty */ { $$ = NULL; }
521 1.29 dholland | ':' optdeps { $$ = $2; }
522 1.29 dholland ;
523 1.29 dholland
524 1.29 dholland /* a list of option dependencies */
525 1.29 dholland optdeps:
526 1.29 dholland optdep { $$ = new_n($1); }
527 1.29 dholland | optdeps ',' optdep { $$ = new_nx($3, $1); }
528 1.26 dholland ;
529 1.1 thorpej
530 1.29 dholland /* one option dependence */
531 1.29 dholland optdep:
532 1.29 dholland WORD { $$ = $1; }
533 1.26 dholland ;
534 1.1 thorpej
535 1.29 dholland /* list of conditional makeoptions */
536 1.29 dholland condmkopt_list:
537 1.29 dholland condmkoption
538 1.29 dholland | condmkopt_list ',' condmkoption
539 1.26 dholland ;
540 1.1 thorpej
541 1.29 dholland /* one conditional make option */
542 1.29 dholland condmkoption:
543 1.29 dholland fexpr mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); }
544 1.26 dholland ;
545 1.1 thorpej
546 1.29 dholland /* device name */
547 1.29 dholland devbase:
548 1.29 dholland WORD { $$ = getdevbase($1); }
549 1.26 dholland ;
550 1.1 thorpej
551 1.29 dholland /* optional attachment: with foo */
552 1.29 dholland devattach_opt:
553 1.29 dholland /* empty */ { $$ = NULL; }
554 1.29 dholland | WITH WORD { $$ = getdevattach($2); }
555 1.26 dholland ;
556 1.1 thorpej
557 1.25 dholland /* list of major numbers */
558 1.25 dholland /* XXX why is this right-recursive? */
559 1.1 thorpej majorlist:
560 1.26 dholland majordef
561 1.26 dholland | majorlist ',' majordef
562 1.26 dholland ;
563 1.1 thorpej
564 1.25 dholland /* one major number */
565 1.1 thorpej majordef:
566 1.26 dholland devbase '=' NUMBER { setmajor($1, $3.val); }
567 1.26 dholland ;
568 1.1 thorpej
569 1.25 dholland /************************************************************/
570 1.1 thorpej
571 1.1 thorpej /*
572 1.1 thorpej * The configuration grammar.
573 1.1 thorpej */
574 1.25 dholland
575 1.25 dholland /* Complete configuration part: all std.* files plus selected config. */
576 1.28 dholland configuration_part:
577 1.28 dholland config_items
578 1.26 dholland ;
579 1.1 thorpej
580 1.28 dholland /* Zero or more config items. Trap errors. */
581 1.28 dholland config_items:
582 1.28 dholland /* empty */
583 1.28 dholland | config_items '\n'
584 1.31 dholland | config_items config_item '\n' { wrap_continue(); }
585 1.31 dholland | config_items error '\n' { wrap_cleanup(); }
586 1.26 dholland ;
587 1.1 thorpej
588 1.25 dholland /* One config item. */
589 1.28 dholland config_item:
590 1.28 dholland definition
591 1.26 dholland | NO FILE_SYSTEM no_fs_list
592 1.26 dholland | FILE_SYSTEM fs_list
593 1.26 dholland | NO MAKEOPTIONS no_mkopt_list
594 1.26 dholland | MAKEOPTIONS mkopt_list
595 1.26 dholland | NO OPTIONS no_opt_list
596 1.26 dholland | OPTIONS opt_list
597 1.26 dholland | MAXUSERS NUMBER { setmaxusers($2.val); }
598 1.26 dholland | IDENT stringvalue { setident($2); }
599 1.26 dholland | CONFIG conf root_spec sysparam_list
600 1.26 dholland { addconf(&conf); }
601 1.26 dholland | NO CONFIG WORD { delconf($3); }
602 1.26 dholland | NO PSEUDO_DEVICE WORD { delpseudo($3); }
603 1.26 dholland | PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); }
604 1.26 dholland | PSEUDO_ROOT device_instance { addpseudoroot($2); }
605 1.26 dholland | NO device_instance AT attachment
606 1.26 dholland { deldevi($2, $4); }
607 1.26 dholland | NO DEVICE AT attachment { deldeva($4); }
608 1.26 dholland | NO device_instance { deldev($2); }
609 1.28 dholland | device_instance AT attachment locators device_flags
610 1.26 dholland { adddev($1, $3, $4, $5); }
611 1.26 dholland ;
612 1.1 thorpej
613 1.25 dholland /* list of filesystems */
614 1.1 thorpej fs_list:
615 1.26 dholland fsoption
616 1.26 dholland | fs_list ',' fsoption
617 1.26 dholland ;
618 1.1 thorpej
619 1.25 dholland /* one filesystem */
620 1.1 thorpej fsoption:
621 1.26 dholland WORD { addfsoption($1); }
622 1.26 dholland ;
623 1.1 thorpej
624 1.25 dholland /* list of filesystems that had NO in front */
625 1.1 thorpej no_fs_list:
626 1.26 dholland no_fsoption
627 1.26 dholland | no_fs_list ',' no_fsoption
628 1.26 dholland ;
629 1.1 thorpej
630 1.25 dholland /* one filesystem that had NO in front */
631 1.1 thorpej no_fsoption:
632 1.26 dholland WORD { delfsoption($1); }
633 1.26 dholland ;
634 1.1 thorpej
635 1.25 dholland /* list of make options */
636 1.25 dholland /* XXX why is this right-recursive? */
637 1.1 thorpej mkopt_list:
638 1.26 dholland mkoption
639 1.26 dholland | mkopt_list ',' mkoption
640 1.26 dholland ;
641 1.1 thorpej
642 1.25 dholland /* one make option */
643 1.1 thorpej mkoption:
644 1.26 dholland mkvarname '=' value { addmkoption($1, $3); }
645 1.26 dholland | mkvarname PLUSEQ value { appendmkoption($1, $3); }
646 1.26 dholland ;
647 1.1 thorpej
648 1.25 dholland /* list of make options that had NO in front */
649 1.1 thorpej no_mkopt_list:
650 1.26 dholland no_mkoption
651 1.26 dholland | no_mkopt_list ',' no_mkoption
652 1.26 dholland ;
653 1.1 thorpej
654 1.25 dholland /* one make option that had NO in front */
655 1.29 dholland /* XXX shouldn't this be mkvarname rather than WORD? */
656 1.1 thorpej no_mkoption:
657 1.1 thorpej WORD { delmkoption($1); }
658 1.26 dholland ;
659 1.1 thorpej
660 1.25 dholland /* list of options */
661 1.1 thorpej opt_list:
662 1.26 dholland option
663 1.26 dholland | opt_list ',' option
664 1.26 dholland ;
665 1.1 thorpej
666 1.25 dholland /* one option */
667 1.1 thorpej option:
668 1.26 dholland WORD { addoption($1, NULL); }
669 1.26 dholland | WORD '=' value { addoption($1, $3); }
670 1.26 dholland ;
671 1.1 thorpej
672 1.25 dholland /* list of options that had NO in front */
673 1.1 thorpej no_opt_list:
674 1.26 dholland no_option
675 1.26 dholland | no_opt_list ',' no_option
676 1.26 dholland ;
677 1.1 thorpej
678 1.25 dholland /* one option that had NO in front */
679 1.1 thorpej no_option:
680 1.26 dholland WORD { deloption($1); }
681 1.26 dholland ;
682 1.1 thorpej
683 1.25 dholland /* the name in "config name root on ..." */
684 1.1 thorpej conf:
685 1.26 dholland WORD {
686 1.26 dholland conf.cf_name = $1;
687 1.26 dholland conf.cf_lineno = currentline();
688 1.26 dholland conf.cf_fstype = NULL;
689 1.26 dholland conf.cf_root = NULL;
690 1.26 dholland conf.cf_dump = NULL;
691 1.26 dholland }
692 1.26 dholland ;
693 1.1 thorpej
694 1.25 dholland /* root fs specification */
695 1.1 thorpej root_spec:
696 1.28 dholland ROOT on_opt dev_spec { setconf(&conf.cf_root, "root", $3); }
697 1.28 dholland | ROOT on_opt dev_spec fs_spec { setconf(&conf.cf_root, "root", $3); }
698 1.26 dholland ;
699 1.1 thorpej
700 1.29 dholland /* device for root fs or dump */
701 1.29 dholland dev_spec:
702 1.29 dholland '?' { $$ = new_si(intern("?"), NODEV); }
703 1.29 dholland | WORD { $$ = new_si($1, NODEV); }
704 1.29 dholland | major_minor { $$ = new_si(NULL, $1); }
705 1.29 dholland ;
706 1.29 dholland
707 1.29 dholland /* major and minor device number */
708 1.29 dholland major_minor:
709 1.29 dholland MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); }
710 1.29 dholland ;
711 1.29 dholland
712 1.25 dholland /* filesystem type for root fs specification */
713 1.1 thorpej fs_spec:
714 1.28 dholland TYPE '?' { setfstype(&conf.cf_fstype, intern("?")); }
715 1.28 dholland | TYPE WORD { setfstype(&conf.cf_fstype, $2); }
716 1.26 dholland ;
717 1.1 thorpej
718 1.25 dholland /* zero or more additional system parameters */
719 1.1 thorpej sysparam_list:
720 1.26 dholland /* empty */
721 1.26 dholland | sysparam_list sysparam
722 1.26 dholland ;
723 1.1 thorpej
724 1.25 dholland /* one additional system parameter (there's only one: dumps) */
725 1.1 thorpej sysparam:
726 1.26 dholland DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); }
727 1.26 dholland ;
728 1.1 thorpej
729 1.25 dholland /* number of pseudo devices to configure (which is optional) */
730 1.1 thorpej npseudo:
731 1.26 dholland /* empty */ { $$ = 1; }
732 1.26 dholland | NUMBER { $$ = $1.val; }
733 1.26 dholland ;
734 1.1 thorpej
735 1.25 dholland /* name of a device to configure */
736 1.1 thorpej device_instance:
737 1.26 dholland WORD { $$ = $1; }
738 1.26 dholland | WORD '*' { $$ = starref($1); }
739 1.26 dholland ;
740 1.1 thorpej
741 1.25 dholland /* name of a device to configure an attachment to */
742 1.1 thorpej attachment:
743 1.26 dholland ROOT { $$ = NULL; }
744 1.26 dholland | WORD { $$ = $1; }
745 1.26 dholland | WORD '?' { $$ = wildref($1); }
746 1.26 dholland ;
747 1.1 thorpej
748 1.25 dholland /* zero or more locators */
749 1.1 thorpej locators:
750 1.26 dholland /* empty */ { $$ = NULL; }
751 1.26 dholland | locators locator { $$ = $2; app($2, $1); }
752 1.26 dholland ;
753 1.1 thorpej
754 1.25 dholland /* one locator */
755 1.1 thorpej locator:
756 1.26 dholland WORD '?' { $$ = new_ns($1, NULL); }
757 1.26 dholland | WORD values { $$ = mk_ns($1, $2); }
758 1.26 dholland ;
759 1.1 thorpej
760 1.25 dholland /* optional device flags */
761 1.28 dholland device_flags:
762 1.26 dholland /* empty */ { $$ = 0; }
763 1.26 dholland | FLAGS NUMBER { $$ = $2.val; }
764 1.26 dholland ;
765 1.1 thorpej
766 1.29 dholland /************************************************************/
767 1.29 dholland
768 1.29 dholland /*
769 1.29 dholland * dependency logic
770 1.29 dholland */
771 1.29 dholland
772 1.29 dholland
773 1.29 dholland /*
774 1.29 dholland * order of options is important, must use right recursion
775 1.29 dholland *
776 1.29 dholland * dholland 20120310: wut?
777 1.29 dholland */
778 1.29 dholland
779 1.29 dholland /* expression of config elements */
780 1.29 dholland fexpr:
781 1.30 dholland f_or_expr
782 1.30 dholland ;
783 1.30 dholland
784 1.30 dholland f_or_expr:
785 1.30 dholland f_and_expr
786 1.30 dholland | f_or_expr '|' f_and_expr { $$ = fx_or($1, $3); }
787 1.30 dholland ;
788 1.30 dholland
789 1.30 dholland f_and_expr:
790 1.30 dholland f_prefix_expr
791 1.30 dholland | f_and_expr '&' f_prefix_expr { $$ = fx_and($1, $3); }
792 1.30 dholland ;
793 1.30 dholland
794 1.30 dholland f_prefix_expr:
795 1.30 dholland f_base_expr
796 1.30 dholland /* XXX notyet - need to strengthen downstream first */
797 1.30 dholland /* | '!' f_prefix_expr { $$ = fx_not($2); } */
798 1.30 dholland ;
799 1.30 dholland
800 1.30 dholland f_base_expr:
801 1.29 dholland fatom { $$ = $1; }
802 1.29 dholland | '!' fatom { $$ = fx_not($2); }
803 1.29 dholland | '(' fexpr ')' { $$ = $2; }
804 1.29 dholland ;
805 1.29 dholland
806 1.29 dholland /* basic element of config element expression: a config element */
807 1.29 dholland fatom:
808 1.29 dholland WORD { $$ = fx_atom($1); }
809 1.29 dholland ;
810 1.29 dholland
811 1.29 dholland /************************************************************/
812 1.29 dholland
813 1.29 dholland /*
814 1.29 dholland * Various nonterminals shared between the grammars.
815 1.29 dholland */
816 1.29 dholland
817 1.29 dholland /* variable name for make option */
818 1.29 dholland mkvarname:
819 1.29 dholland QSTRING { $$ = $1; }
820 1.29 dholland | WORD { $$ = $1; }
821 1.29 dholland ;
822 1.29 dholland
823 1.29 dholland /* optional file for an option */
824 1.29 dholland optfile_opt:
825 1.29 dholland /* empty */ { $$ = NULL; }
826 1.29 dholland | filename { $$ = $1; }
827 1.29 dholland ;
828 1.29 dholland
829 1.29 dholland /* filename. */
830 1.29 dholland filename:
831 1.29 dholland QSTRING { $$ = $1; }
832 1.29 dholland | PATHNAME { $$ = $1; }
833 1.29 dholland ;
834 1.29 dholland
835 1.29 dholland /* constant value */
836 1.29 dholland value:
837 1.29 dholland QSTRING { $$ = $1; }
838 1.29 dholland | WORD { $$ = $1; }
839 1.29 dholland | EMPTYSTRING { $$ = $1; }
840 1.29 dholland | signed_number {
841 1.29 dholland char bf[40];
842 1.29 dholland
843 1.29 dholland (void)snprintf(bf, sizeof(bf), FORMAT($1), (long long)$1.val);
844 1.29 dholland $$ = intern(bf);
845 1.29 dholland }
846 1.29 dholland ;
847 1.29 dholland
848 1.29 dholland /* constant value that is a string */
849 1.29 dholland stringvalue:
850 1.29 dholland QSTRING { $$ = $1; }
851 1.29 dholland | WORD { $$ = $1; }
852 1.29 dholland ;
853 1.29 dholland
854 1.29 dholland /* comma-separated list of values */
855 1.29 dholland /* XXX why right-recursive? */
856 1.29 dholland values:
857 1.29 dholland value { $$ = new_s($1); }
858 1.29 dholland | value ',' values { $$ = new_sx($1, $3); }
859 1.29 dholland ;
860 1.29 dholland
861 1.29 dholland /* possibly negative number */
862 1.29 dholland signed_number:
863 1.29 dholland NUMBER { $$ = $1; }
864 1.29 dholland | '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; }
865 1.29 dholland ;
866 1.29 dholland
867 1.29 dholland /* optional ON keyword */
868 1.29 dholland on_opt:
869 1.29 dholland /* empty */
870 1.29 dholland | ON
871 1.29 dholland ;
872 1.29 dholland
873 1.1 thorpej %%
874 1.1 thorpej
875 1.1 thorpej void
876 1.1 thorpej yyerror(const char *s)
877 1.1 thorpej {
878 1.1 thorpej
879 1.13 christos cfgerror("%s", s);
880 1.1 thorpej }
881 1.1 thorpej
882 1.31 dholland /************************************************************/
883 1.31 dholland
884 1.31 dholland /*
885 1.31 dholland * Wrap allocations that live on the parser stack so that we can free
886 1.31 dholland * them again on error instead of leaking.
887 1.31 dholland */
888 1.31 dholland
889 1.31 dholland #define MAX_WRAP 1000
890 1.31 dholland
891 1.31 dholland struct wrap_entry {
892 1.31 dholland void *ptr;
893 1.31 dholland unsigned typecode;
894 1.31 dholland };
895 1.31 dholland
896 1.31 dholland static struct wrap_entry wrapstack[MAX_WRAP];
897 1.31 dholland static unsigned wrap_depth;
898 1.31 dholland
899 1.1 thorpej /*
900 1.31 dholland * Remember pointer PTR with type-code CODE.
901 1.1 thorpej */
902 1.1 thorpej static void
903 1.31 dholland wrap_alloc(void *ptr, unsigned code)
904 1.1 thorpej {
905 1.31 dholland unsigned pos;
906 1.31 dholland
907 1.31 dholland if (wrap_depth >= MAX_WRAP) {
908 1.31 dholland panic("allocation wrapper stack overflow");
909 1.31 dholland }
910 1.31 dholland pos = wrap_depth++;
911 1.31 dholland wrapstack[pos].ptr = ptr;
912 1.31 dholland wrapstack[pos].typecode = code;
913 1.31 dholland }
914 1.31 dholland
915 1.31 dholland /*
916 1.31 dholland * We succeeded; commit to keeping everything that's been allocated so
917 1.31 dholland * far and clear the stack.
918 1.31 dholland */
919 1.31 dholland static void
920 1.31 dholland wrap_continue(void)
921 1.31 dholland {
922 1.31 dholland wrap_depth = 0;
923 1.31 dholland }
924 1.31 dholland
925 1.31 dholland /*
926 1.31 dholland * We failed; destroy all the objects allocated.
927 1.31 dholland */
928 1.31 dholland static void
929 1.31 dholland wrap_cleanup(void)
930 1.31 dholland {
931 1.31 dholland unsigned i;
932 1.1 thorpej
933 1.31 dholland for (i=0; i<wrap_depth; i++) {
934 1.31 dholland switch (wrapstack[i].typecode) {
935 1.31 dholland case WRAP_CODE_nvlist:
936 1.31 dholland nvfree(wrapstack[i].ptr);
937 1.31 dholland break;
938 1.31 dholland default:
939 1.31 dholland panic("invalid code %u on allocation wrapper stack",
940 1.31 dholland wrapstack[i].typecode);
941 1.31 dholland }
942 1.31 dholland }
943 1.31 dholland wrap_depth = 0;
944 1.1 thorpej }
945 1.1 thorpej
946 1.31 dholland /*
947 1.31 dholland * Instantiate the wrapper functions.
948 1.31 dholland *
949 1.31 dholland * Each one calls wrap_alloc to save the pointer and then returns the
950 1.31 dholland * pointer again; these need to be generated with the preprocessor in
951 1.31 dholland * order to be typesafe.
952 1.31 dholland */
953 1.31 dholland #define DEF_ALLOCWRAP(t) \
954 1.31 dholland static struct t * \
955 1.31 dholland wrap_mk_##t(struct t *arg) \
956 1.31 dholland { \
957 1.31 dholland wrap_alloc(arg, WRAP_CODE_##t); \
958 1.31 dholland return arg; \
959 1.31 dholland }
960 1.31 dholland
961 1.31 dholland DEF_ALLOCWRAP(nvlist);
962 1.31 dholland
963 1.31 dholland /************************************************************/
964 1.31 dholland
965 1.1 thorpej static void
966 1.20 pooka setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
967 1.20 pooka int isioconf)
968 1.1 thorpej {
969 1.1 thorpej char buf[MAXPATHLEN];
970 1.1 thorpej struct nvlist *nv;
971 1.1 thorpej
972 1.20 pooka if (isioconf) {
973 1.23 pooka fprintf(stderr, "WARNING: ioconf is an experimental feature\n");
974 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
975 1.20 pooka exit(1);
976 1.20 pooka ioconfname = mch;
977 1.20 pooka return;
978 1.20 pooka }
979 1.20 pooka
980 1.1 thorpej machine = mch;
981 1.1 thorpej machinearch = mcharch;
982 1.1 thorpej machinesubarches = mchsubarches;
983 1.1 thorpej
984 1.1 thorpej /*
985 1.14 cube * Define attributes for all the given names
986 1.14 cube */
987 1.15 cube if (defattr(machine, NULL, NULL, 0) != 0 ||
988 1.15 cube (machinearch != NULL &&
989 1.15 cube defattr(machinearch, NULL, NULL, 0) != 0))
990 1.14 cube exit(1);
991 1.14 cube for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
992 1.14 cube if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
993 1.14 cube exit(1);
994 1.14 cube }
995 1.14 cube
996 1.14 cube /*
997 1.1 thorpej * Set up the file inclusion stack. This empty include tells
998 1.1 thorpej * the parser there are no more device definitions coming.
999 1.1 thorpej */
1000 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
1001 1.1 thorpej exit(1);
1002 1.1 thorpej
1003 1.1 thorpej /* Include arch/${MACHINE}/conf/files.${MACHINE} */
1004 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1005 1.1 thorpej machine, machine);
1006 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1007 1.1 thorpej exit(1);
1008 1.1 thorpej
1009 1.1 thorpej /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
1010 1.1 thorpej for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
1011 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1012 1.1 thorpej nv->nv_name, nv->nv_name);
1013 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1014 1.1 thorpej exit(1);
1015 1.1 thorpej }
1016 1.1 thorpej
1017 1.1 thorpej /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
1018 1.1 thorpej if (machinearch != NULL)
1019 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
1020 1.1 thorpej machinearch, machinearch);
1021 1.1 thorpej else
1022 1.1 thorpej strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
1023 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
1024 1.1 thorpej exit(1);
1025 1.1 thorpej
1026 1.1 thorpej /*
1027 1.1 thorpej * Include the global conf/files. As the last thing
1028 1.1 thorpej * pushed on the stack, it will be processed first.
1029 1.1 thorpej */
1030 1.1 thorpej if (include("conf/files", ENDFILE, 0, 0) != 0)
1031 1.1 thorpej exit(1);
1032 1.2 martin
1033 1.2 martin oktopackage = 1;
1034 1.1 thorpej }
1035 1.1 thorpej
1036 1.1 thorpej static void
1037 1.1 thorpej check_maxpart(void)
1038 1.1 thorpej {
1039 1.1 thorpej
1040 1.20 pooka if (maxpartitions <= 0 && ioconfname == NULL) {
1041 1.1 thorpej stop("cannot proceed without maxpartitions specifier");
1042 1.1 thorpej }
1043 1.1 thorpej }
1044 1.1 thorpej
1045 1.1 thorpej static void
1046 1.4 cube check_version(void)
1047 1.4 cube {
1048 1.4 cube /*
1049 1.4 cube * In essence, version is 0 and is not supported anymore
1050 1.4 cube */
1051 1.4 cube if (version < CONFIG_MINVERSION)
1052 1.4 cube stop("your sources are out of date -- please update.");
1053 1.4 cube }
1054 1.4 cube
1055 1.4 cube static void
1056 1.1 thorpej app(struct nvlist *p, struct nvlist *q)
1057 1.1 thorpej {
1058 1.1 thorpej while (p->nv_next)
1059 1.1 thorpej p = p->nv_next;
1060 1.1 thorpej p->nv_next = q;
1061 1.1 thorpej }
1062 1.1 thorpej
1063 1.1 thorpej static struct nvlist *
1064 1.1 thorpej mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
1065 1.1 thorpej {
1066 1.1 thorpej struct nvlist *defs = adefs;
1067 1.1 thorpej struct nvlist **p;
1068 1.1 thorpej char buf[200];
1069 1.1 thorpej int i;
1070 1.1 thorpej
1071 1.1 thorpej if (count <= 0) {
1072 1.1 thorpej fprintf(stderr, "config: array with <= 0 size: %s\n", name);
1073 1.1 thorpej exit(1);
1074 1.1 thorpej }
1075 1.1 thorpej p = &defs;
1076 1.1 thorpej for(i = 0; i < count; i++) {
1077 1.1 thorpej if (*p == NULL)
1078 1.1 thorpej *p = new_s("0");
1079 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
1080 1.1 thorpej (*p)->nv_name = i == 0 ? name : intern(buf);
1081 1.18 christos (*p)->nv_num = i > 0 || opt;
1082 1.1 thorpej p = &(*p)->nv_next;
1083 1.1 thorpej }
1084 1.1 thorpej *p = 0;
1085 1.1 thorpej return defs;
1086 1.1 thorpej }
1087 1.1 thorpej
1088 1.1 thorpej
1089 1.1 thorpej static struct nvlist *
1090 1.1 thorpej mk_ns(const char *name, struct nvlist *vals)
1091 1.1 thorpej {
1092 1.1 thorpej struct nvlist *p;
1093 1.1 thorpej char buf[200];
1094 1.1 thorpej int i;
1095 1.1 thorpej
1096 1.1 thorpej for(i = 0, p = vals; p; i++, p = p->nv_next) {
1097 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
1098 1.1 thorpej p->nv_name = i == 0 ? name : intern(buf);
1099 1.1 thorpej }
1100 1.1 thorpej return vals;
1101 1.1 thorpej }
1102 1.1 thorpej
1103