gram.y revision 1.26 1 1.1 thorpej %{
2 1.26 dholland /* $NetBSD: gram.y,v 1.26 2012/03/11 00:57:44 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.1 thorpej /* the following is used to recover nvlist space after errors */
62 1.1 thorpej static struct nvlist *alloc[1000];
63 1.1 thorpej static int adepth;
64 1.1 thorpej #define new0(n,s,p,i,x) (alloc[adepth++] = newnv(n, s, p, i, x))
65 1.1 thorpej #define new_n(n) new0(n, NULL, NULL, 0, NULL)
66 1.1 thorpej #define new_nx(n, x) new0(n, NULL, NULL, 0, x)
67 1.1 thorpej #define new_ns(n, s) new0(n, s, NULL, 0, NULL)
68 1.1 thorpej #define new_si(s, i) new0(NULL, s, NULL, i, NULL)
69 1.1 thorpej #define new_nsi(n,s,i) new0(n, s, NULL, i, NULL)
70 1.1 thorpej #define new_np(n, p) new0(n, NULL, p, 0, NULL)
71 1.1 thorpej #define new_s(s) new0(NULL, s, NULL, 0, NULL)
72 1.1 thorpej #define new_p(p) new0(NULL, NULL, p, 0, NULL)
73 1.1 thorpej #define new_px(p, x) new0(NULL, NULL, p, 0, x)
74 1.1 thorpej #define new_sx(s, x) new0(NULL, s, NULL, 0, x)
75 1.11 cube #define new_nsx(n,s,x) new0(n, s, NULL, 0, x)
76 1.24 pooka #define new_i(i) new0(NULL, NULL, NULL, i, NULL)
77 1.1 thorpej
78 1.1 thorpej #define fx_atom(s) new0(s, NULL, NULL, FX_ATOM, NULL)
79 1.1 thorpej #define fx_not(e) new0(NULL, NULL, NULL, FX_NOT, e)
80 1.1 thorpej #define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2)
81 1.1 thorpej #define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2)
82 1.1 thorpej
83 1.1 thorpej static void cleanup(void);
84 1.20 pooka static void setmachine(const char *, const char *, struct nvlist *, int);
85 1.1 thorpej static void check_maxpart(void);
86 1.1 thorpej
87 1.1 thorpej static void app(struct nvlist *, struct nvlist *);
88 1.1 thorpej
89 1.1 thorpej static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
90 1.1 thorpej static struct nvlist *mk_ns(const char *, struct nvlist *);
91 1.1 thorpej
92 1.1 thorpej %}
93 1.1 thorpej
94 1.1 thorpej %union {
95 1.1 thorpej struct attr *attr;
96 1.1 thorpej struct devbase *devb;
97 1.1 thorpej struct deva *deva;
98 1.1 thorpej struct nvlist *list;
99 1.1 thorpej const char *str;
100 1.1 thorpej struct numconst num;
101 1.1 thorpej int64_t val;
102 1.1 thorpej }
103 1.1 thorpej
104 1.1 thorpej %token AND AT ATTACH
105 1.1 thorpej %token BLOCK BUILD
106 1.11 cube %token CHAR COLONEQ COMPILE_WITH CONFIG
107 1.16 drochner %token DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
108 1.16 drochner %token DEVICE DEVCLASS DUMPS DEVICE_MAJOR
109 1.1 thorpej %token ENDFILE
110 1.1 thorpej %token XFILE FILE_SYSTEM FLAGS
111 1.20 pooka %token IDENT IOCONF
112 1.24 pooka %token LINKZERO
113 1.1 thorpej %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
114 1.1 thorpej %token NEEDS_COUNT NEEDS_FLAG NO
115 1.6 cube %token XOBJECT OBSOLETE ON OPTIONS
116 1.22 pooka %token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE PSEUDO_ROOT
117 1.1 thorpej %token ROOT
118 1.24 pooka %token SINGLE SOURCE
119 1.1 thorpej %token TYPE
120 1.24 pooka %token VECTOR VERSION
121 1.1 thorpej %token WITH
122 1.1 thorpej %token <num> NUMBER
123 1.8 christos %token <str> PATHNAME QSTRING WORD EMPTYSTRING
124 1.1 thorpej %token ENDDEFS
125 1.1 thorpej
126 1.1 thorpej %left '|'
127 1.1 thorpej %left '&'
128 1.1 thorpej
129 1.1 thorpej %type <list> fopts fexpr fatom
130 1.1 thorpej %type <str> fs_spec
131 1.1 thorpej %type <val> fflgs fflag oflgs oflag
132 1.1 thorpej %type <str> rule
133 1.1 thorpej %type <attr> attr
134 1.1 thorpej %type <devb> devbase
135 1.1 thorpej %type <deva> devattach_opt
136 1.1 thorpej %type <list> atlist interface_opt
137 1.1 thorpej %type <str> atname
138 1.1 thorpej %type <list> loclist_opt loclist locdef
139 1.1 thorpej %type <str> locdefault
140 1.1 thorpej %type <list> values locdefaults
141 1.1 thorpej %type <list> attrs_opt attrs
142 1.1 thorpej %type <list> locators locator
143 1.1 thorpej %type <list> dev_spec
144 1.1 thorpej %type <str> device_instance
145 1.1 thorpej %type <str> attachment
146 1.1 thorpej %type <str> value
147 1.1 thorpej %type <val> major_minor npseudo
148 1.1 thorpej %type <num> signed_number
149 1.1 thorpej %type <val> flags_opt
150 1.1 thorpej %type <str> deffs
151 1.1 thorpej %type <list> deffses
152 1.10 dsl %type <list> defopt
153 1.1 thorpej %type <list> defopts
154 1.1 thorpej %type <str> optdep
155 1.1 thorpej %type <list> optdeps
156 1.1 thorpej %type <list> defoptdeps
157 1.1 thorpej %type <str> optfile_opt
158 1.1 thorpej %type <list> subarches_opt subarches
159 1.1 thorpej %type <str> filename stringvalue locname mkvarname
160 1.1 thorpej %type <val> device_major_block device_major_char
161 1.24 pooka %type <list> devnodes devnodetype devnodeflags devnode_dims
162 1.1 thorpej
163 1.1 thorpej %%
164 1.1 thorpej
165 1.1 thorpej /*
166 1.25 dholland * A complete configuration consists of both the configuration part (a
167 1.25 dholland * kernel config such as GENERIC or SKYNET, plus also the various
168 1.25 dholland * std.* files), which selects the material to be in the kernel, and
169 1.25 dholland * also the definition part (files, files.*, etc.) that declares what
170 1.25 dholland * material is available to be placed in kernels.
171 1.25 dholland *
172 1.25 dholland * The two parts have almost entirely separate syntaxes. This grammar
173 1.25 dholland * covers both of them. When config is run on a kernel configuration
174 1.25 dholland * file, the std.* file for the port is included explicitly. The
175 1.25 dholland * files.* files are included implicitly when the std.* file declares
176 1.25 dholland * the machine type.
177 1.25 dholland *
178 1.25 dholland * The machine spec, which brings in the definition part, must appear
179 1.25 dholland * before all configuration material except for the "topthings"; these
180 1.25 dholland * are the "source" and "build" declarations that tell config where
181 1.25 dholland * things are. These are not used by default.
182 1.25 dholland *
183 1.25 dholland * A previous version of this comment contained the following text:
184 1.25 dholland *
185 1.25 dholland * Note that we do not have sufficient keywords to enforce any
186 1.25 dholland * order between elements of "topthings" without introducing
187 1.25 dholland * shift/reduce conflicts. Instead, check order requirements in
188 1.25 dholland * the C code.
189 1.25 dholland *
190 1.25 dholland * As of March 2012 this comment makes no sense, as there are only two
191 1.25 dholland * topthings and no reason for them to be forcibly ordered.
192 1.25 dholland * Furthermore, the statement about conflicts is false.
193 1.1 thorpej */
194 1.25 dholland
195 1.25 dholland /* Complete configuration. */
196 1.1 thorpej Configuration:
197 1.25 dholland topthings
198 1.26 dholland machine_spec dev_defs ENDDEFS
199 1.26 dholland { check_maxpart(); check_version(); }
200 1.26 dholland specs
201 1.26 dholland ;
202 1.1 thorpej
203 1.25 dholland /* Sequence of zero or more topthings. */
204 1.1 thorpej topthings:
205 1.26 dholland /* empty */
206 1.26 dholland | topthings topthing
207 1.26 dholland ;
208 1.1 thorpej
209 1.25 dholland /* Directory specification. */
210 1.1 thorpej topthing:
211 1.26 dholland SOURCE filename '\n' { if (!srcdir) srcdir = $2; }
212 1.26 dholland | BUILD filename '\n' { if (!builddir) builddir = $2; }
213 1.26 dholland | '\n'
214 1.26 dholland ;
215 1.1 thorpej
216 1.25 dholland /* "machine foo" from std.whatever */
217 1.1 thorpej machine_spec:
218 1.26 dholland XMACHINE WORD '\n' { setmachine($2,NULL,NULL,0); }
219 1.26 dholland | XMACHINE WORD WORD subarches_opt '\n' { setmachine($2,$3,$4,0); }
220 1.26 dholland | IOCONF WORD '\n' { setmachine($2,NULL,NULL,1); }
221 1.26 dholland | error { stop("cannot proceed without machine or ioconf specifier"); }
222 1.26 dholland ;
223 1.1 thorpej
224 1.25 dholland /* Optional subarches. */
225 1.1 thorpej subarches_opt:
226 1.26 dholland /* empty */ { $$ = NULL; }
227 1.26 dholland | subarches
228 1.26 dholland ;
229 1.1 thorpej
230 1.25 dholland /* Subarches declaration. */
231 1.1 thorpej subarches:
232 1.26 dholland subarches WORD { $$ = new_nx($2, $1); }
233 1.26 dholland | WORD { $$ = new_n($1); }
234 1.26 dholland ;
235 1.1 thorpej
236 1.25 dholland /************************************************************/
237 1.25 dholland
238 1.1 thorpej /*
239 1.1 thorpej * Various nonterminals shared between the grammars.
240 1.25 dholland * (Note: that's a lie, pending some reorg)
241 1.1 thorpej */
242 1.25 dholland
243 1.25 dholland /* source file: file foo/bar.c bar|baz needs-flag compile-with blah */
244 1.1 thorpej file:
245 1.26 dholland XFILE filename fopts fflgs rule { addfile($2, $3, $4, $5); }
246 1.26 dholland ;
247 1.1 thorpej
248 1.25 dholland /* object file: object zot.o foo|zot needs-flag */
249 1.1 thorpej object:
250 1.26 dholland XOBJECT filename fopts oflgs { addobject($2, $3, $4); }
251 1.26 dholland ;
252 1.1 thorpej
253 1.25 dholland /* device major declaration */
254 1.1 thorpej device_major:
255 1.24 pooka DEVICE_MAJOR WORD device_major_char device_major_block fopts devnodes
256 1.26 dholland { adddevm($2, $3, $4, $5, $6); }
257 1.26 dholland ;
258 1.26 dholland
259 1.25 dholland /* block 33 */
260 1.1 thorpej device_major_block:
261 1.26 dholland /* empty */ { $$ = -1; }
262 1.26 dholland | BLOCK NUMBER { $$ = $2.val; }
263 1.26 dholland ;
264 1.1 thorpej
265 1.25 dholland /* char 55 */
266 1.1 thorpej device_major_char:
267 1.26 dholland /* empty */ { $$ = -1; }
268 1.26 dholland | CHAR NUMBER { $$ = $2.val; }
269 1.26 dholland ;
270 1.1 thorpej
271 1.25 dholland /*
272 1.25 dholland * order of options is important, must use right recursion
273 1.25 dholland *
274 1.25 dholland * dholland 20120310: wut?
275 1.25 dholland */
276 1.25 dholland
277 1.25 dholland /* file options: optional expression of config elements */
278 1.1 thorpej fopts:
279 1.26 dholland /* empty */ { $$ = NULL; }
280 1.26 dholland | fexpr { $$ = $1; }
281 1.26 dholland ;
282 1.1 thorpej
283 1.25 dholland /* expression of config elements */
284 1.25 dholland /* XXX this should use a real expression grammar */
285 1.1 thorpej fexpr:
286 1.26 dholland fatom { $$ = $1; }
287 1.26 dholland | '!' fatom { $$ = fx_not($2); }
288 1.26 dholland | fexpr '&' fexpr { $$ = fx_and($1, $3); }
289 1.26 dholland | fexpr '|' fexpr { $$ = fx_or($1, $3); }
290 1.26 dholland | '(' fexpr ')' { $$ = $2; }
291 1.26 dholland ;
292 1.1 thorpej
293 1.25 dholland /* basic element of config element expression: a config element */
294 1.1 thorpej fatom:
295 1.26 dholland WORD { $$ = fx_atom($1); }
296 1.26 dholland ;
297 1.1 thorpej
298 1.25 dholland /* zero or more flags for a file */
299 1.1 thorpej fflgs:
300 1.26 dholland /* empty */ { $$ = 0; }
301 1.26 dholland | fflgs fflag { $$ = $1 | $2; }
302 1.26 dholland ;
303 1.1 thorpej
304 1.25 dholland /* one flag for a file */
305 1.1 thorpej fflag:
306 1.26 dholland NEEDS_COUNT { $$ = FI_NEEDSCOUNT; }
307 1.26 dholland | NEEDS_FLAG { $$ = FI_NEEDSFLAG; }
308 1.26 dholland ;
309 1.1 thorpej
310 1.25 dholland /* device node specification */
311 1.24 pooka devnodes:
312 1.26 dholland /* empty */ { $$ = new_s("DEVNODE_DONTBOTHER"); }
313 1.26 dholland | devnodetype ',' devnodeflags { $$ = nvcat($1, $3); }
314 1.26 dholland | devnodetype { $$ = $1; }
315 1.26 dholland ;
316 1.24 pooka
317 1.25 dholland /* device nodes without flags */
318 1.24 pooka devnodetype:
319 1.26 dholland SINGLE { $$ = new_s("DEVNODE_SINGLE"); }
320 1.26 dholland | VECTOR '=' devnode_dims { $$ = nvcat(new_s("DEVNODE_VECTOR"), $3); }
321 1.26 dholland ;
322 1.24 pooka
323 1.25 dholland /* dimensions (?) */
324 1.24 pooka devnode_dims:
325 1.26 dholland NUMBER { $$ = new_i($1.val); }
326 1.26 dholland | NUMBER ':' NUMBER {
327 1.26 dholland struct nvlist *__nv1, *__nv2;
328 1.26 dholland
329 1.26 dholland __nv1 = new_i($1.val);
330 1.26 dholland __nv2 = new_i($3.val);
331 1.26 dholland $$ = nvcat(__nv1, __nv2);
332 1.26 dholland }
333 1.26 dholland ;
334 1.24 pooka
335 1.25 dholland /* flags for device nodes */
336 1.24 pooka devnodeflags:
337 1.26 dholland LINKZERO { $$ = new_s("DEVNODE_FLAG_LINKZERO");}
338 1.26 dholland ;
339 1.25 dholland
340 1.25 dholland /* zero or more flags for an object file */
341 1.1 thorpej oflgs:
342 1.26 dholland /* empty */ { $$ = 0; }
343 1.26 dholland | oflgs oflag { $$ = $1 | $2; }
344 1.26 dholland ;
345 1.1 thorpej
346 1.25 dholland /* a single flag for an object file */
347 1.1 thorpej oflag:
348 1.26 dholland NEEDS_FLAG { $$ = OI_NEEDSFLAG; }
349 1.26 dholland ;
350 1.1 thorpej
351 1.25 dholland /* extra compile directive for a source file */
352 1.1 thorpej rule:
353 1.26 dholland /* empty */ { $$ = NULL; }
354 1.26 dholland | COMPILE_WITH stringvalue { $$ = $2; }
355 1.26 dholland ;
356 1.1 thorpej
357 1.25 dholland /* prefix delimiter */
358 1.1 thorpej prefix:
359 1.26 dholland PREFIX filename { prefix_push($2); }
360 1.26 dholland | PREFIX { prefix_pop(); }
361 1.26 dholland ;
362 1.1 thorpej
363 1.25 dholland /************************************************************/
364 1.25 dholland
365 1.1 thorpej /*
366 1.1 thorpej * The machine definitions grammar.
367 1.1 thorpej */
368 1.25 dholland
369 1.25 dholland /* Complete definition part: the contents of all files.* files. */
370 1.1 thorpej dev_defs:
371 1.26 dholland /* empty */
372 1.26 dholland | dev_defs dev_def
373 1.26 dholland | dev_defs ENDFILE { enddefs(); checkfiles(); }
374 1.26 dholland ;
375 1.1 thorpej
376 1.25 dholland /* A single definition, or a blank line. Trap errors. */
377 1.1 thorpej dev_def:
378 1.26 dholland '\n'
379 1.26 dholland | one_def '\n' { adepth = 0; }
380 1.26 dholland | error '\n' { cleanup(); }
381 1.26 dholland ;
382 1.1 thorpej
383 1.25 dholland /* A single definition. */
384 1.1 thorpej one_def:
385 1.26 dholland file
386 1.26 dholland | object
387 1.26 dholland | device_major { do_devsw = 1; }
388 1.26 dholland | prefix
389 1.26 dholland | DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); }
390 1.26 dholland | DEFFS deffses defoptdeps { deffilesystem($2, $3); }
391 1.26 dholland | DEFINE WORD interface_opt attrs_opt
392 1.26 dholland { (void)defattr($2, $3, $4, 0); }
393 1.26 dholland | DEFOPT optfile_opt defopts defoptdeps
394 1.26 dholland { defoption($2, $3, $4); }
395 1.26 dholland | DEFFLAG optfile_opt defopts defoptdeps
396 1.26 dholland { defflag($2, $3, $4, 0); }
397 1.26 dholland | OBSOLETE DEFFLAG optfile_opt defopts
398 1.26 dholland { defflag($3, $4, NULL, 1); }
399 1.26 dholland | DEFPARAM optfile_opt defopts defoptdeps
400 1.26 dholland { defparam($2, $3, $4, 0); }
401 1.26 dholland | OBSOLETE DEFPARAM optfile_opt defopts
402 1.26 dholland { defparam($3, $4, NULL, 1); }
403 1.26 dholland | DEVICE devbase interface_opt attrs_opt
404 1.26 dholland { defdev($2, $3, $4, 0); }
405 1.26 dholland | ATTACH devbase AT atlist devattach_opt attrs_opt
406 1.26 dholland { defdevattach($5, $2, $4, $6); }
407 1.26 dholland | MAXPARTITIONS NUMBER { maxpartitions = $2.val; }
408 1.26 dholland | MAXUSERS NUMBER NUMBER NUMBER
409 1.26 dholland { setdefmaxusers($2.val, $3.val, $4.val); }
410 1.26 dholland | MAKEOPTIONS condmkopt_list
411 1.17 drochner /* interface_opt in DEFPSEUDO is for backwards compatibility */
412 1.26 dholland | DEFPSEUDO devbase interface_opt attrs_opt
413 1.26 dholland { defdev($2, $3, $4, 1); }
414 1.26 dholland | DEFPSEUDODEV devbase interface_opt attrs_opt
415 1.26 dholland { defdev($2, $3, $4, 2); }
416 1.26 dholland | MAJOR '{' majorlist '}'
417 1.26 dholland | VERSION NUMBER { setversion($2.val); }
418 1.26 dholland ;
419 1.1 thorpej
420 1.25 dholland /* list of places to attach: attach blah at ... */
421 1.1 thorpej atlist:
422 1.26 dholland atname { $$ = new_n($1); }
423 1.26 dholland | atlist ',' atname { $$ = new_nx($3, $1); }
424 1.26 dholland ;
425 1.1 thorpej
426 1.25 dholland /* a place to attach a device */
427 1.1 thorpej atname:
428 1.26 dholland WORD { $$ = $1; }
429 1.26 dholland | ROOT { $$ = NULL; }
430 1.26 dholland ;
431 1.1 thorpej
432 1.25 dholland /* one or more file system names */
433 1.1 thorpej deffses:
434 1.26 dholland deffs { $$ = new_n($1); }
435 1.26 dholland | deffses deffs { $$ = new_nx($2, $1); }
436 1.26 dholland ;
437 1.1 thorpej
438 1.25 dholland /* a single file system name */
439 1.1 thorpej deffs:
440 1.26 dholland WORD { $$ = $1; }
441 1.26 dholland ;
442 1.1 thorpej
443 1.25 dholland /* option dependencies (read as "defopt deps") which are optional */
444 1.1 thorpej defoptdeps:
445 1.26 dholland /* empty */ { $$ = NULL; }
446 1.26 dholland | ':' optdeps { $$ = $2; }
447 1.26 dholland ;
448 1.1 thorpej
449 1.25 dholland /* a list of option dependencies */
450 1.1 thorpej optdeps:
451 1.26 dholland optdep { $$ = new_n($1); }
452 1.26 dholland | optdeps ',' optdep { $$ = new_nx($3, $1); }
453 1.26 dholland ;
454 1.1 thorpej
455 1.25 dholland /* one option dependence */
456 1.1 thorpej optdep:
457 1.26 dholland WORD { $$ = $1; }
458 1.26 dholland ;
459 1.1 thorpej
460 1.25 dholland /* one or more defined options */
461 1.1 thorpej defopts:
462 1.26 dholland defopt { $$ = $1; }
463 1.26 dholland | defopts defopt { $$ = nvcat($2, $1); }
464 1.26 dholland ;
465 1.1 thorpej
466 1.25 dholland /* one defined option */
467 1.1 thorpej defopt:
468 1.26 dholland WORD { $$ = new_n($1); }
469 1.26 dholland | WORD '=' value { $$ = new_ns($1, $3); }
470 1.26 dholland | WORD COLONEQ value {
471 1.26 dholland struct nvlist *__nv = new_n($1);
472 1.26 dholland
473 1.26 dholland $$ = new_nsx("", $3, __nv);
474 1.26 dholland }
475 1.26 dholland | WORD '=' value COLONEQ value {
476 1.26 dholland struct nvlist *__nv = new_n($1);
477 1.26 dholland
478 1.26 dholland $$ = new_nsx("", $5, __nv);
479 1.26 dholland }
480 1.26 dholland ;
481 1.1 thorpej
482 1.25 dholland /* device name */
483 1.1 thorpej devbase:
484 1.26 dholland WORD { $$ = getdevbase($1); }
485 1.26 dholland ;
486 1.1 thorpej
487 1.25 dholland /* optional attachment: with foo */
488 1.1 thorpej devattach_opt:
489 1.26 dholland /* empty */ { $$ = NULL; }
490 1.26 dholland | WITH WORD { $$ = getdevattach($2); }
491 1.26 dholland ;
492 1.1 thorpej
493 1.25 dholland /* optional locator specification in braces */
494 1.1 thorpej interface_opt:
495 1.26 dholland /* empty */ { $$ = NULL; }
496 1.26 dholland | '{' loclist_opt '}' { $$ = new_nx("", $2); }
497 1.26 dholland ;
498 1.1 thorpej
499 1.25 dholland /* optional locator specification without braces */
500 1.1 thorpej loclist_opt:
501 1.26 dholland /* empty */ { $$ = NULL; }
502 1.26 dholland | loclist { $$ = $1; }
503 1.26 dholland ;
504 1.1 thorpej
505 1.25 dholland /*
506 1.25 dholland * loclist order matters, must use right recursion
507 1.25 dholland * XXX wot?
508 1.25 dholland */
509 1.25 dholland
510 1.25 dholland /* list of locator definitions */
511 1.1 thorpej loclist:
512 1.26 dholland locdef { $$ = $1; }
513 1.26 dholland | locdef ',' loclist { $$ = $1; app($1, $3); }
514 1.26 dholland ;
515 1.1 thorpej
516 1.25 dholland /*
517 1.25 dholland * "[ WORD locdefault ]" syntax may be unnecessary...
518 1.25 dholland */
519 1.25 dholland
520 1.25 dholland /* one locator definition */
521 1.1 thorpej locdef:
522 1.26 dholland locname locdefault { $$ = new_nsi($1, $2, 0); }
523 1.26 dholland | locname { $$ = new_nsi($1, NULL, 0); }
524 1.26 dholland | '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); }
525 1.26 dholland | locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); }
526 1.26 dholland | locname '[' NUMBER ']' locdefaults
527 1.26 dholland { $$ = mk_nsis($1, $3.val, $5, 0); }
528 1.26 dholland | '[' locname '[' NUMBER ']' locdefaults ']'
529 1.26 dholland { $$ = mk_nsis($2, $4.val, $6, 1); }
530 1.26 dholland ;
531 1.1 thorpej
532 1.25 dholland /* locator name */
533 1.1 thorpej locname:
534 1.26 dholland WORD { $$ = $1; }
535 1.26 dholland | QSTRING { $$ = $1; }
536 1.26 dholland ;
537 1.1 thorpej
538 1.25 dholland /* locator default value */
539 1.1 thorpej locdefault:
540 1.26 dholland '=' value { $$ = $2; }
541 1.26 dholland ;
542 1.1 thorpej
543 1.25 dholland /* multiple locator default values */
544 1.1 thorpej locdefaults:
545 1.26 dholland '=' '{' values '}' { $$ = $3; }
546 1.26 dholland ;
547 1.1 thorpej
548 1.25 dholland /* optional file for an option */
549 1.1 thorpej optfile_opt:
550 1.26 dholland /* empty */ { $$ = NULL; }
551 1.26 dholland | filename { $$ = $1; }
552 1.26 dholland ;
553 1.1 thorpej
554 1.25 dholland /* filename. */
555 1.1 thorpej filename:
556 1.26 dholland QSTRING { $$ = $1; }
557 1.26 dholland | PATHNAME { $$ = $1; }
558 1.26 dholland ;
559 1.1 thorpej
560 1.25 dholland /* constant value */
561 1.1 thorpej value:
562 1.26 dholland QSTRING { $$ = $1; }
563 1.26 dholland | WORD { $$ = $1; }
564 1.26 dholland | EMPTYSTRING { $$ = $1; }
565 1.26 dholland | signed_number {
566 1.26 dholland char bf[40];
567 1.26 dholland
568 1.26 dholland (void)snprintf(bf, sizeof(bf), FORMAT($1), (long long)$1.val);
569 1.26 dholland $$ = intern(bf);
570 1.26 dholland }
571 1.26 dholland ;
572 1.1 thorpej
573 1.25 dholland /* constant value that is a string */
574 1.1 thorpej stringvalue:
575 1.26 dholland QSTRING { $$ = $1; }
576 1.26 dholland | WORD { $$ = $1; }
577 1.26 dholland ;
578 1.1 thorpej
579 1.25 dholland /* comma-separated list of values */
580 1.26 dholland /* XXX why right-recursive? */
581 1.1 thorpej values:
582 1.26 dholland value { $$ = new_s($1); }
583 1.26 dholland | value ',' values { $$ = new_sx($1, $3); }
584 1.26 dholland ;
585 1.1 thorpej
586 1.25 dholland /* possibly negative number */
587 1.1 thorpej signed_number:
588 1.26 dholland NUMBER { $$ = $1; }
589 1.26 dholland | '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; }
590 1.26 dholland ;
591 1.1 thorpej
592 1.25 dholland /* optional attributes */
593 1.1 thorpej attrs_opt:
594 1.26 dholland /* empty */ { $$ = NULL; }
595 1.26 dholland | ':' attrs { $$ = $2; }
596 1.26 dholland ;
597 1.1 thorpej
598 1.25 dholland /* one or more attributes */
599 1.1 thorpej attrs:
600 1.26 dholland attr { $$ = new_p($1); }
601 1.26 dholland | attrs ',' attr { $$ = new_px($3, $1); }
602 1.26 dholland ;
603 1.1 thorpej
604 1.25 dholland /* one attribute */
605 1.1 thorpej attr:
606 1.26 dholland WORD { $$ = getattr($1); }
607 1.26 dholland ;
608 1.1 thorpej
609 1.25 dholland /* list of major numbers */
610 1.25 dholland /* XXX why is this right-recursive? */
611 1.1 thorpej majorlist:
612 1.26 dholland majordef
613 1.26 dholland | majorlist ',' majordef
614 1.26 dholland ;
615 1.1 thorpej
616 1.25 dholland /* one major number */
617 1.1 thorpej majordef:
618 1.26 dholland devbase '=' NUMBER { setmajor($1, $3.val); }
619 1.26 dholland ;
620 1.1 thorpej
621 1.25 dholland /************************************************************/
622 1.1 thorpej
623 1.1 thorpej /*
624 1.1 thorpej * The configuration grammar.
625 1.1 thorpej */
626 1.25 dholland
627 1.25 dholland /* Complete configuration part: all std.* files plus selected config. */
628 1.1 thorpej specs:
629 1.26 dholland /* empty */
630 1.26 dholland | specs spec
631 1.26 dholland ;
632 1.1 thorpej
633 1.25 dholland /* One config item, or a blank line. Trap errors. */
634 1.1 thorpej spec:
635 1.26 dholland '\n'
636 1.26 dholland | config_spec '\n' { adepth = 0; }
637 1.26 dholland | error '\n' { cleanup(); }
638 1.26 dholland ;
639 1.1 thorpej
640 1.25 dholland /* One config item. */
641 1.1 thorpej config_spec:
642 1.26 dholland one_def
643 1.26 dholland | NO FILE_SYSTEM no_fs_list
644 1.26 dholland | FILE_SYSTEM fs_list
645 1.26 dholland | NO MAKEOPTIONS no_mkopt_list
646 1.26 dholland | MAKEOPTIONS mkopt_list
647 1.26 dholland | NO OPTIONS no_opt_list
648 1.26 dholland | OPTIONS opt_list
649 1.26 dholland | MAXUSERS NUMBER { setmaxusers($2.val); }
650 1.26 dholland | IDENT stringvalue { setident($2); }
651 1.26 dholland | CONFIG conf root_spec sysparam_list
652 1.26 dholland { addconf(&conf); }
653 1.26 dholland | NO CONFIG WORD { delconf($3); }
654 1.26 dholland | NO PSEUDO_DEVICE WORD { delpseudo($3); }
655 1.26 dholland | PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); }
656 1.26 dholland | PSEUDO_ROOT device_instance { addpseudoroot($2); }
657 1.26 dholland | NO device_instance AT attachment
658 1.26 dholland { deldevi($2, $4); }
659 1.26 dholland | NO DEVICE AT attachment { deldeva($4); }
660 1.26 dholland | NO device_instance { deldev($2); }
661 1.26 dholland | device_instance AT attachment locators flags_opt
662 1.26 dholland { adddev($1, $3, $4, $5); }
663 1.26 dholland ;
664 1.1 thorpej
665 1.25 dholland /* list of filesystems */
666 1.1 thorpej fs_list:
667 1.26 dholland fsoption
668 1.26 dholland | fs_list ',' fsoption
669 1.26 dholland ;
670 1.1 thorpej
671 1.25 dholland /* one filesystem */
672 1.1 thorpej fsoption:
673 1.26 dholland WORD { addfsoption($1); }
674 1.26 dholland ;
675 1.1 thorpej
676 1.25 dholland /* list of filesystems that had NO in front */
677 1.1 thorpej no_fs_list:
678 1.26 dholland no_fsoption
679 1.26 dholland | no_fs_list ',' no_fsoption
680 1.26 dholland ;
681 1.1 thorpej
682 1.25 dholland /* one filesystem that had NO in front */
683 1.1 thorpej no_fsoption:
684 1.26 dholland WORD { delfsoption($1); }
685 1.26 dholland ;
686 1.1 thorpej
687 1.25 dholland /* list of make options */
688 1.25 dholland /* XXX why is this right-recursive? */
689 1.1 thorpej mkopt_list:
690 1.26 dholland mkoption
691 1.26 dholland | mkopt_list ',' mkoption
692 1.26 dholland ;
693 1.1 thorpej
694 1.25 dholland /* variable name for make option */
695 1.1 thorpej mkvarname:
696 1.26 dholland QSTRING { $$ = $1; }
697 1.26 dholland | WORD { $$ = $1; }
698 1.26 dholland ;
699 1.1 thorpej
700 1.25 dholland /* one make option */
701 1.1 thorpej mkoption:
702 1.26 dholland mkvarname '=' value { addmkoption($1, $3); }
703 1.26 dholland | mkvarname PLUSEQ value { appendmkoption($1, $3); }
704 1.26 dholland ;
705 1.1 thorpej
706 1.25 dholland /* list of conditional makeoptions */
707 1.1 thorpej condmkopt_list:
708 1.26 dholland condmkoption
709 1.26 dholland | condmkopt_list ',' condmkoption
710 1.26 dholland ;
711 1.1 thorpej
712 1.25 dholland /* one conditional make option */
713 1.1 thorpej condmkoption:
714 1.26 dholland fexpr mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); }
715 1.26 dholland ;
716 1.1 thorpej
717 1.25 dholland /* list of make options that had NO in front */
718 1.1 thorpej no_mkopt_list:
719 1.26 dholland no_mkoption
720 1.26 dholland | no_mkopt_list ',' no_mkoption
721 1.26 dholland ;
722 1.1 thorpej
723 1.25 dholland /* one make option that had NO in front */
724 1.1 thorpej no_mkoption:
725 1.1 thorpej WORD { delmkoption($1); }
726 1.26 dholland ;
727 1.1 thorpej
728 1.25 dholland /* list of options */
729 1.1 thorpej opt_list:
730 1.26 dholland option
731 1.26 dholland | opt_list ',' option
732 1.26 dholland ;
733 1.1 thorpej
734 1.25 dholland /* one option */
735 1.1 thorpej option:
736 1.26 dholland WORD { addoption($1, NULL); }
737 1.26 dholland | WORD '=' value { addoption($1, $3); }
738 1.26 dholland ;
739 1.1 thorpej
740 1.25 dholland /* list of options that had NO in front */
741 1.1 thorpej no_opt_list:
742 1.26 dholland no_option
743 1.26 dholland | no_opt_list ',' no_option
744 1.26 dholland ;
745 1.1 thorpej
746 1.25 dholland /* one option that had NO in front */
747 1.1 thorpej no_option:
748 1.26 dholland WORD { deloption($1); }
749 1.26 dholland ;
750 1.1 thorpej
751 1.25 dholland /* the name in "config name root on ..." */
752 1.1 thorpej conf:
753 1.26 dholland WORD {
754 1.26 dholland conf.cf_name = $1;
755 1.26 dholland conf.cf_lineno = currentline();
756 1.26 dholland conf.cf_fstype = NULL;
757 1.26 dholland conf.cf_root = NULL;
758 1.26 dholland conf.cf_dump = NULL;
759 1.26 dholland }
760 1.26 dholland ;
761 1.1 thorpej
762 1.25 dholland /* root fs specification */
763 1.1 thorpej root_spec:
764 1.1 thorpej ROOT on_opt dev_spec fs_spec_opt
765 1.26 dholland { setconf(&conf.cf_root, "root", $3); }
766 1.26 dholland ;
767 1.1 thorpej
768 1.25 dholland /* filesystem type for root fs specification */
769 1.1 thorpej fs_spec_opt:
770 1.26 dholland /* empty */
771 1.26 dholland | TYPE fs_spec { setfstype(&conf.cf_fstype, $2); }
772 1.26 dholland ;
773 1.1 thorpej
774 1.25 dholland /* filesystem name for root fs specification */
775 1.1 thorpej fs_spec:
776 1.26 dholland '?' { $$ = intern("?"); }
777 1.26 dholland | WORD { $$ = $1; }
778 1.26 dholland ;
779 1.1 thorpej
780 1.25 dholland /* zero or more additional system parameters */
781 1.1 thorpej sysparam_list:
782 1.26 dholland /* empty */
783 1.26 dholland | sysparam_list sysparam
784 1.26 dholland ;
785 1.1 thorpej
786 1.25 dholland /* one additional system parameter (there's only one: dumps) */
787 1.1 thorpej sysparam:
788 1.26 dholland DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); }
789 1.26 dholland ;
790 1.1 thorpej
791 1.25 dholland /* device for root fs or dump */
792 1.1 thorpej dev_spec:
793 1.26 dholland '?' { $$ = new_si(intern("?"), NODEV); }
794 1.26 dholland | WORD { $$ = new_si($1, NODEV); }
795 1.26 dholland | major_minor { $$ = new_si(NULL, $1); }
796 1.26 dholland ;
797 1.1 thorpej
798 1.25 dholland /* major and minor device number */
799 1.1 thorpej major_minor:
800 1.26 dholland MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); }
801 1.26 dholland ;
802 1.1 thorpej
803 1.25 dholland /* optional ON keyword */
804 1.1 thorpej on_opt:
805 1.26 dholland /* empty */
806 1.26 dholland | ON
807 1.26 dholland ;
808 1.1 thorpej
809 1.25 dholland /* number of pseudo devices to configure (which is optional) */
810 1.1 thorpej npseudo:
811 1.26 dholland /* empty */ { $$ = 1; }
812 1.26 dholland | NUMBER { $$ = $1.val; }
813 1.26 dholland ;
814 1.1 thorpej
815 1.25 dholland /* name of a device to configure */
816 1.1 thorpej device_instance:
817 1.26 dholland WORD { $$ = $1; }
818 1.26 dholland | WORD '*' { $$ = starref($1); }
819 1.26 dholland ;
820 1.1 thorpej
821 1.25 dholland /* name of a device to configure an attachment to */
822 1.1 thorpej attachment:
823 1.26 dholland ROOT { $$ = NULL; }
824 1.26 dholland | WORD { $$ = $1; }
825 1.26 dholland | WORD '?' { $$ = wildref($1); }
826 1.26 dholland ;
827 1.1 thorpej
828 1.25 dholland /* zero or more locators */
829 1.1 thorpej locators:
830 1.26 dholland /* empty */ { $$ = NULL; }
831 1.26 dholland | locators locator { $$ = $2; app($2, $1); }
832 1.26 dholland ;
833 1.1 thorpej
834 1.25 dholland /* one locator */
835 1.1 thorpej locator:
836 1.26 dholland WORD '?' { $$ = new_ns($1, NULL); }
837 1.26 dholland | WORD values { $$ = mk_ns($1, $2); }
838 1.26 dholland ;
839 1.1 thorpej
840 1.25 dholland /* optional device flags */
841 1.1 thorpej flags_opt:
842 1.26 dholland /* empty */ { $$ = 0; }
843 1.26 dholland | FLAGS NUMBER { $$ = $2.val; }
844 1.26 dholland ;
845 1.1 thorpej
846 1.1 thorpej %%
847 1.1 thorpej
848 1.1 thorpej void
849 1.1 thorpej yyerror(const char *s)
850 1.1 thorpej {
851 1.1 thorpej
852 1.13 christos cfgerror("%s", s);
853 1.1 thorpej }
854 1.1 thorpej
855 1.1 thorpej /*
856 1.1 thorpej * Cleanup procedure after syntax error: release any nvlists
857 1.1 thorpej * allocated during parsing the current line.
858 1.1 thorpej */
859 1.1 thorpej static void
860 1.1 thorpej cleanup(void)
861 1.1 thorpej {
862 1.1 thorpej struct nvlist **np;
863 1.1 thorpej int i;
864 1.1 thorpej
865 1.1 thorpej for (np = alloc, i = adepth; --i >= 0; np++)
866 1.1 thorpej nvfree(*np);
867 1.1 thorpej adepth = 0;
868 1.1 thorpej }
869 1.1 thorpej
870 1.1 thorpej static void
871 1.20 pooka setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches,
872 1.20 pooka int isioconf)
873 1.1 thorpej {
874 1.1 thorpej char buf[MAXPATHLEN];
875 1.1 thorpej struct nvlist *nv;
876 1.1 thorpej
877 1.20 pooka if (isioconf) {
878 1.23 pooka fprintf(stderr, "WARNING: ioconf is an experimental feature\n");
879 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
880 1.20 pooka exit(1);
881 1.20 pooka ioconfname = mch;
882 1.20 pooka return;
883 1.20 pooka }
884 1.20 pooka
885 1.1 thorpej machine = mch;
886 1.1 thorpej machinearch = mcharch;
887 1.1 thorpej machinesubarches = mchsubarches;
888 1.1 thorpej
889 1.1 thorpej /*
890 1.14 cube * Define attributes for all the given names
891 1.14 cube */
892 1.15 cube if (defattr(machine, NULL, NULL, 0) != 0 ||
893 1.15 cube (machinearch != NULL &&
894 1.15 cube defattr(machinearch, NULL, NULL, 0) != 0))
895 1.14 cube exit(1);
896 1.14 cube for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
897 1.14 cube if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
898 1.14 cube exit(1);
899 1.14 cube }
900 1.14 cube
901 1.14 cube /*
902 1.1 thorpej * Set up the file inclusion stack. This empty include tells
903 1.1 thorpej * the parser there are no more device definitions coming.
904 1.1 thorpej */
905 1.20 pooka if (include(_PATH_DEVNULL, ENDDEFS, 0, 0) != 0)
906 1.1 thorpej exit(1);
907 1.1 thorpej
908 1.1 thorpej /* Include arch/${MACHINE}/conf/files.${MACHINE} */
909 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
910 1.1 thorpej machine, machine);
911 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
912 1.1 thorpej exit(1);
913 1.1 thorpej
914 1.1 thorpej /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
915 1.1 thorpej for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
916 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
917 1.1 thorpej nv->nv_name, nv->nv_name);
918 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
919 1.1 thorpej exit(1);
920 1.1 thorpej }
921 1.1 thorpej
922 1.1 thorpej /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
923 1.1 thorpej if (machinearch != NULL)
924 1.1 thorpej (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
925 1.1 thorpej machinearch, machinearch);
926 1.1 thorpej else
927 1.1 thorpej strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
928 1.1 thorpej if (include(buf, ENDFILE, 0, 0) != 0)
929 1.1 thorpej exit(1);
930 1.1 thorpej
931 1.1 thorpej /*
932 1.1 thorpej * Include the global conf/files. As the last thing
933 1.1 thorpej * pushed on the stack, it will be processed first.
934 1.1 thorpej */
935 1.1 thorpej if (include("conf/files", ENDFILE, 0, 0) != 0)
936 1.1 thorpej exit(1);
937 1.2 martin
938 1.2 martin oktopackage = 1;
939 1.1 thorpej }
940 1.1 thorpej
941 1.1 thorpej static void
942 1.1 thorpej check_maxpart(void)
943 1.1 thorpej {
944 1.1 thorpej
945 1.20 pooka if (maxpartitions <= 0 && ioconfname == NULL) {
946 1.1 thorpej stop("cannot proceed without maxpartitions specifier");
947 1.1 thorpej }
948 1.1 thorpej }
949 1.1 thorpej
950 1.1 thorpej static void
951 1.4 cube check_version(void)
952 1.4 cube {
953 1.4 cube /*
954 1.4 cube * In essence, version is 0 and is not supported anymore
955 1.4 cube */
956 1.4 cube if (version < CONFIG_MINVERSION)
957 1.4 cube stop("your sources are out of date -- please update.");
958 1.4 cube }
959 1.4 cube
960 1.4 cube static void
961 1.1 thorpej app(struct nvlist *p, struct nvlist *q)
962 1.1 thorpej {
963 1.1 thorpej while (p->nv_next)
964 1.1 thorpej p = p->nv_next;
965 1.1 thorpej p->nv_next = q;
966 1.1 thorpej }
967 1.1 thorpej
968 1.1 thorpej static struct nvlist *
969 1.1 thorpej mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
970 1.1 thorpej {
971 1.1 thorpej struct nvlist *defs = adefs;
972 1.1 thorpej struct nvlist **p;
973 1.1 thorpej char buf[200];
974 1.1 thorpej int i;
975 1.1 thorpej
976 1.1 thorpej if (count <= 0) {
977 1.1 thorpej fprintf(stderr, "config: array with <= 0 size: %s\n", name);
978 1.1 thorpej exit(1);
979 1.1 thorpej }
980 1.1 thorpej p = &defs;
981 1.1 thorpej for(i = 0; i < count; i++) {
982 1.1 thorpej if (*p == NULL)
983 1.1 thorpej *p = new_s("0");
984 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
985 1.1 thorpej (*p)->nv_name = i == 0 ? name : intern(buf);
986 1.18 christos (*p)->nv_num = i > 0 || opt;
987 1.1 thorpej p = &(*p)->nv_next;
988 1.1 thorpej }
989 1.1 thorpej *p = 0;
990 1.1 thorpej return defs;
991 1.1 thorpej }
992 1.1 thorpej
993 1.1 thorpej
994 1.1 thorpej static struct nvlist *
995 1.1 thorpej mk_ns(const char *name, struct nvlist *vals)
996 1.1 thorpej {
997 1.1 thorpej struct nvlist *p;
998 1.1 thorpej char buf[200];
999 1.1 thorpej int i;
1000 1.1 thorpej
1001 1.1 thorpej for(i = 0, p = vals; p; i++, p = p->nv_next) {
1002 1.1 thorpej snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
1003 1.1 thorpej p->nv_name = i == 0 ? name : intern(buf);
1004 1.1 thorpej }
1005 1.1 thorpej return vals;
1006 1.1 thorpej }
1007 1.1 thorpej
1008