gram.y revision 1.16 1 %{
2 /* $NetBSD: gram.y,v 1.16 2008/06/10 12:35:32 drochner Exp $ */
3
4 /*
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This software was developed by the Computer Systems Engineering group
9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 * contributed to Berkeley.
11 *
12 * All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by the University of
15 * California, Lawrence Berkeley Laboratories.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * from: @(#)gram.y 8.1 (Berkeley) 6/6/93
42 */
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <ctype.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <errno.h>
51 #include "defs.h"
52 #include "sem.h"
53
54 #define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
55 ((n).fmt == 16) ? "0x%llx" : "%lld")
56
57 #define stop(s) cfgerror(s), exit(1)
58
59 static struct config conf; /* at most one active at a time */
60
61 /* the following is used to recover nvlist space after errors */
62 static struct nvlist *alloc[1000];
63 static int adepth;
64 #define new0(n,s,p,i,x) (alloc[adepth++] = newnv(n, s, p, i, x))
65 #define new_n(n) new0(n, NULL, NULL, 0, NULL)
66 #define new_nx(n, x) new0(n, NULL, NULL, 0, x)
67 #define new_ns(n, s) new0(n, s, NULL, 0, NULL)
68 #define new_si(s, i) new0(NULL, s, NULL, i, NULL)
69 #define new_nsi(n,s,i) new0(n, s, NULL, i, NULL)
70 #define new_np(n, p) new0(n, NULL, p, 0, NULL)
71 #define new_s(s) new0(NULL, s, NULL, 0, NULL)
72 #define new_p(p) new0(NULL, NULL, p, 0, NULL)
73 #define new_px(p, x) new0(NULL, NULL, p, 0, x)
74 #define new_sx(s, x) new0(NULL, s, NULL, 0, x)
75 #define new_nsx(n,s,x) new0(n, s, NULL, 0, x)
76
77 #define fx_atom(s) new0(s, NULL, NULL, FX_ATOM, NULL)
78 #define fx_not(e) new0(NULL, NULL, NULL, FX_NOT, e)
79 #define fx_and(e1, e2) new0(NULL, NULL, e1, FX_AND, e2)
80 #define fx_or(e1, e2) new0(NULL, NULL, e1, FX_OR, e2)
81
82 static void cleanup(void);
83 static void setmachine(const char *, const char *, struct nvlist *);
84 static void check_maxpart(void);
85
86 static void app(struct nvlist *, struct nvlist *);
87
88 static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
89 static struct nvlist *mk_ns(const char *, struct nvlist *);
90
91 %}
92
93 %union {
94 struct attr *attr;
95 struct devbase *devb;
96 struct deva *deva;
97 struct nvlist *list;
98 const char *str;
99 struct numconst num;
100 int64_t val;
101 }
102
103 %token AND AT ATTACH
104 %token BLOCK BUILD
105 %token CHAR COLONEQ COMPILE_WITH CONFIG
106 %token DEFFS DEFINE DEFOPT DEFPARAM DEFFLAG DEFPSEUDO DEFPSEUDODEV
107 %token DEVICE DEVCLASS DUMPS DEVICE_MAJOR
108 %token ENDFILE
109 %token XFILE FILE_SYSTEM FLAGS
110 %token IDENT
111 %token XMACHINE MAJOR MAKEOPTIONS MAXUSERS MAXPARTITIONS MINOR
112 %token NEEDS_COUNT NEEDS_FLAG NO
113 %token XOBJECT OBSOLETE ON OPTIONS
114 %token PACKAGE PLUSEQ PREFIX PSEUDO_DEVICE
115 %token ROOT
116 %token SOURCE
117 %token TYPE
118 %token VERSION
119 %token WITH
120 %token <num> NUMBER
121 %token <str> PATHNAME QSTRING WORD EMPTYSTRING
122 %token ENDDEFS
123
124 %left '|'
125 %left '&'
126
127 %type <list> fopts fexpr fatom
128 %type <str> fs_spec
129 %type <val> fflgs fflag oflgs oflag
130 %type <str> rule
131 %type <attr> attr
132 %type <devb> devbase
133 %type <deva> devattach_opt
134 %type <list> atlist interface_opt
135 %type <str> atname
136 %type <list> loclist_opt loclist locdef
137 %type <str> locdefault
138 %type <list> values locdefaults
139 %type <list> attrs_opt attrs
140 %type <list> locators locator
141 %type <list> dev_spec
142 %type <str> device_instance
143 %type <str> attachment
144 %type <str> value
145 %type <val> major_minor npseudo
146 %type <num> signed_number
147 %type <val> flags_opt
148 %type <str> deffs
149 %type <list> deffses
150 %type <str> fsoptfile_opt
151 %type <list> defopt
152 %type <list> defopts
153 %type <str> optdep
154 %type <list> optdeps
155 %type <list> defoptdeps
156 %type <str> optfile_opt
157 %type <list> subarches_opt subarches
158 %type <str> filename stringvalue locname mkvarname
159 %type <val> device_major_block device_major_char
160
161 %%
162
163 /*
164 * A configuration consists of a machine type, followed by the machine
165 * definition files (via the include() mechanism), followed by the
166 * configuration specification(s) proper. In effect, this is two
167 * separate grammars, with some shared terminals and nonterminals.
168 * Note that we do not have sufficient keywords to enforce any order
169 * between elements of "topthings" without introducing shift/reduce
170 * conflicts. Instead, check order requirements in the C code.
171 */
172 Configuration:
173 topthings /* dirspecs, include "std.arch" */
174 machine_spec /* "machine foo" from machine descr. */
175 dev_defs ENDDEFS /* all machine definition files */
176 { check_maxpart(); check_version(); }
177 specs; /* rest of machine description */
178
179 topthings:
180 topthings topthing |
181 /* empty */;
182
183 topthing:
184 SOURCE filename '\n' { if (!srcdir) srcdir = $2; } |
185 BUILD filename '\n' { if (!builddir) builddir = $2; } |
186 '\n';
187
188 machine_spec:
189 XMACHINE WORD '\n' { setmachine($2,NULL,NULL); } |
190 XMACHINE WORD WORD subarches_opt '\n' { setmachine($2,$3,$4); } |
191 error { stop("cannot proceed without machine specifier"); };
192
193 subarches_opt:
194 subarches |
195 /* empty */ { $$ = NULL; };
196
197 subarches:
198 subarches WORD { $$ = new_nx($2, $1); } |
199 WORD { $$ = new_n($1); };
200
201 /*
202 * Various nonterminals shared between the grammars.
203 */
204 file:
205 XFILE filename fopts fflgs rule { addfile($2, $3, $4, $5); };
206
207 object:
208 XOBJECT filename fopts oflgs { addobject($2, $3, $4); };
209
210 device_major:
211 DEVICE_MAJOR WORD device_major_char device_major_block fopts
212 { adddevm($2, $3, $4, $5); };
213
214 device_major_block:
215 BLOCK NUMBER { $$ = $2.val; } |
216 /* empty */ { $$ = -1; };
217
218 device_major_char:
219 CHAR NUMBER { $$ = $2.val; } |
220 /* empty */ { $$ = -1; };
221
222 /* order of options is important, must use right recursion */
223 fopts:
224 fexpr { $$ = $1; } |
225 /* empty */ { $$ = NULL; };
226
227 fexpr:
228 fatom { $$ = $1; } |
229 '!' fatom { $$ = fx_not($2); } |
230 fexpr '&' fexpr { $$ = fx_and($1, $3); } |
231 fexpr '|' fexpr { $$ = fx_or($1, $3); } |
232 '(' fexpr ')' { $$ = $2; };
233
234 fatom:
235 WORD { $$ = fx_atom($1); };
236
237 fflgs:
238 fflgs fflag { $$ = $1 | $2; } |
239 /* empty */ { $$ = 0; };
240
241 fflag:
242 NEEDS_COUNT { $$ = FI_NEEDSCOUNT; } |
243 NEEDS_FLAG { $$ = FI_NEEDSFLAG; };
244
245 oflgs:
246 oflgs oflag { $$ = $1 | $2; } |
247 /* empty */ { $$ = 0; };
248
249 oflag:
250 NEEDS_FLAG { $$ = OI_NEEDSFLAG; };
251
252 rule:
253 COMPILE_WITH stringvalue { $$ = $2; } |
254 /* empty */ { $$ = NULL; };
255
256 prefix:
257 PREFIX filename { prefix_push($2); } |
258 PREFIX { prefix_pop(); };
259
260 /*
261 * The machine definitions grammar.
262 */
263 dev_defs:
264 dev_defs dev_def |
265 dev_defs ENDFILE { enddefs(); checkfiles(); } |
266 /* empty */;
267
268 dev_def:
269 one_def '\n' { adepth = 0; } |
270 '\n' |
271 error '\n' { cleanup(); };
272
273 one_def:
274 file |
275 object |
276 device_major { do_devsw = 1; } |
277 prefix |
278 DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); } |
279 DEFFS fsoptfile_opt deffses defoptdeps
280 { deffilesystem($2, $3, $4); } |
281 DEFINE WORD interface_opt attrs_opt
282 { (void)defattr($2, $3, $4, 0); } |
283 DEFOPT optfile_opt defopts defoptdeps
284 { defoption($2, $3, $4); } |
285 DEFFLAG optfile_opt defopts defoptdeps
286 { defflag($2, $3, $4, 0); } |
287 OBSOLETE DEFFLAG optfile_opt defopts
288 { defflag($3, $4, NULL, 1); } |
289 DEFPARAM optfile_opt defopts defoptdeps
290 { defparam($2, $3, $4, 0); } |
291 OBSOLETE DEFPARAM optfile_opt defopts
292 { defparam($3, $4, NULL, 1); } |
293 DEVICE devbase interface_opt attrs_opt
294 { defdev($2, $3, $4, 0); } |
295 ATTACH devbase AT atlist devattach_opt attrs_opt
296 { defdevattach($5, $2, $4, $6); } |
297 MAXPARTITIONS NUMBER { maxpartitions = $2.val; } |
298 MAXUSERS NUMBER NUMBER NUMBER { setdefmaxusers($2.val, $3.val, $4.val); } |
299 MAKEOPTIONS condmkopt_list |
300 DEFPSEUDO devbase interface_opt attrs_opt
301 { defdev($2, $3, $4, 1); } |
302 DEFPSEUDODEV devbase interface_opt attrs_opt
303 { defdev($2, $3, $4, 2); } |
304 MAJOR '{' majorlist '}' |
305 VERSION NUMBER { setversion($2.val); };
306
307 atlist:
308 atlist ',' atname { $$ = new_nx($3, $1); } |
309 atname { $$ = new_n($1); };
310
311 atname:
312 WORD { $$ = $1; } |
313 ROOT { $$ = NULL; };
314
315 deffses:
316 deffses deffs { $$ = new_nx($2, $1); } |
317 deffs { $$ = new_n($1); };
318
319 deffs:
320 WORD { $$ = $1; };
321
322 defoptdeps:
323 ':' optdeps { $$ = $2; } |
324 /* empty */ { $$ = NULL; };
325
326 optdeps:
327 optdeps ',' optdep { $$ = new_nx($3, $1); } |
328 optdep { $$ = new_n($1); };
329
330 optdep:
331 WORD { $$ = $1; };
332
333 defopts:
334 defopts defopt { $$ = nvcat($2, $1); } |
335 defopt { $$ = $1; };
336
337 defopt:
338 WORD { $$ = new_n($1); } |
339 WORD '=' value { $$ = new_ns($1, $3); } |
340 WORD COLONEQ value {
341 struct nvlist *__nv =
342 new_n($1);
343 $$ = new_nsx("", $3, __nv);
344 } |
345 WORD '=' value COLONEQ value {
346 struct nvlist *__nv =
347 new_n($1);
348 $$ = new_nsx("", $5, __nv);
349 };
350
351 devbase:
352 WORD { $$ = getdevbase($1); };
353
354 devattach_opt:
355 WITH WORD { $$ = getdevattach($2); } |
356 /* empty */ { $$ = NULL; };
357
358 interface_opt:
359 '{' loclist_opt '}' { $$ = new_nx("", $2); } |
360 /* empty */ { $$ = NULL; };
361
362 loclist_opt:
363 loclist { $$ = $1; } |
364 /* empty */ { $$ = NULL; };
365
366 /* loclist order matters, must use right recursion */
367 loclist:
368 locdef ',' loclist { $$ = $1; app($1, $3); } |
369 locdef { $$ = $1; };
370
371 /* "[ WORD locdefault ]" syntax may be unnecessary... */
372 locdef:
373 locname locdefault { $$ = new_nsi($1, $2, 0); } |
374 locname { $$ = new_nsi($1, NULL, 0); } |
375 '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); } |
376 locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); } |
377 locname '[' NUMBER ']' locdefaults
378 { $$ = mk_nsis($1, $3.val, $5, 0); } |
379 '[' locname '[' NUMBER ']' locdefaults ']'
380 { $$ = mk_nsis($2, $4.val, $6, 1); };
381
382 locname:
383 WORD { $$ = $1; } |
384 QSTRING { $$ = $1; };
385
386 locdefault:
387 '=' value { $$ = $2; };
388
389 locdefaults:
390 '=' '{' values '}' { $$ = $3; };
391
392 fsoptfile_opt:
393 filename { $$ = $1; } |
394 /* empty */ { $$ = NULL; };
395
396 optfile_opt:
397 filename { $$ = $1; } |
398 /* empty */ { $$ = NULL; };
399
400 filename:
401 QSTRING { $$ = $1; } |
402 PATHNAME { $$ = $1; };
403
404 value:
405 QSTRING { $$ = $1; } |
406 WORD { $$ = $1; } |
407 EMPTYSTRING { $$ = $1; } |
408 signed_number { char bf[40];
409 (void)snprintf(bf, sizeof(bf),
410 FORMAT($1), (long long)$1.val);
411 $$ = intern(bf); };
412
413 stringvalue:
414 QSTRING { $$ = $1; } |
415 WORD { $$ = $1; };
416
417 values:
418 value ',' values { $$ = new_sx($1, $3); } |
419 value { $$ = new_s($1); };
420
421 signed_number:
422 NUMBER { $$ = $1; } |
423 '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; };
424
425 attrs_opt:
426 ':' attrs { $$ = $2; } |
427 /* empty */ { $$ = NULL; };
428
429 attrs:
430 attrs ',' attr { $$ = new_px($3, $1); } |
431 attr { $$ = new_p($1); };
432
433 attr:
434 WORD { $$ = getattr($1); };
435
436 majorlist:
437 majorlist ',' majordef |
438 majordef;
439
440 majordef:
441 devbase '=' NUMBER { setmajor($1, $3.val); };
442
443
444 /*
445 * The configuration grammar.
446 */
447 specs:
448 specs spec |
449 /* empty */;
450
451 spec:
452 config_spec '\n' { adepth = 0; } |
453 '\n' |
454 error '\n' { cleanup(); };
455
456 config_spec:
457 one_def |
458 NO FILE_SYSTEM no_fs_list |
459 FILE_SYSTEM fs_list |
460 NO MAKEOPTIONS no_mkopt_list |
461 MAKEOPTIONS mkopt_list |
462 NO OPTIONS no_opt_list |
463 OPTIONS opt_list |
464 MAXUSERS NUMBER { setmaxusers($2.val); } |
465 IDENT stringvalue { setident($2); } |
466 CONFIG conf root_spec sysparam_list
467 { addconf(&conf); } |
468 NO CONFIG WORD { delconf($3); } |
469 NO PSEUDO_DEVICE WORD { delpseudo($3); } |
470 PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); } |
471 NO device_instance AT attachment
472 { deldevi($2, $4); } |
473 NO DEVICE AT attachment { deldeva($4); } |
474 NO device_instance { deldev($2); } |
475 device_instance AT attachment locators flags_opt
476 { adddev($1, $3, $4, $5); };
477
478 fs_list:
479 fs_list ',' fsoption |
480 fsoption;
481
482 fsoption:
483 WORD { addfsoption($1); };
484
485 no_fs_list:
486 no_fs_list ',' no_fsoption |
487 no_fsoption;
488
489 no_fsoption:
490 WORD { delfsoption($1); };
491
492 mkopt_list:
493 mkopt_list ',' mkoption |
494 mkoption;
495
496 mkvarname:
497 QSTRING { $$ = $1; } |
498 WORD { $$ = $1; };
499
500 mkoption:
501 mkvarname '=' value { addmkoption($1, $3); } |
502 mkvarname PLUSEQ value { appendmkoption($1, $3); };
503
504 condmkopt_list:
505 condmkopt_list ',' condmkoption |
506 condmkoption;
507
508 condmkoption:
509 WORD mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); };
510
511 no_mkopt_list:
512 no_mkopt_list ',' no_mkoption |
513 no_mkoption;
514
515 no_mkoption:
516 WORD { delmkoption($1); }
517
518 opt_list:
519 opt_list ',' option |
520 option;
521
522 option:
523 WORD { addoption($1, NULL); } |
524 WORD '=' value { addoption($1, $3); };
525
526 no_opt_list:
527 no_opt_list ',' no_option |
528 no_option;
529
530 no_option:
531 WORD { deloption($1); };
532
533 conf:
534 WORD { conf.cf_name = $1;
535 conf.cf_lineno = currentline();
536 conf.cf_fstype = NULL;
537 conf.cf_root = NULL;
538 conf.cf_dump = NULL; };
539
540 root_spec:
541 ROOT on_opt dev_spec fs_spec_opt
542 { setconf(&conf.cf_root, "root", $3); };
543
544 fs_spec_opt:
545 TYPE fs_spec { setfstype(&conf.cf_fstype, $2); } |
546 /* empty */;
547
548 fs_spec:
549 '?' { $$ = intern("?"); } |
550 WORD { $$ = $1; };
551
552 sysparam_list:
553 sysparam_list sysparam |
554 /* empty */;
555
556 sysparam:
557 DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); };
558
559 dev_spec:
560 '?' { $$ = new_si(intern("?"), NODEV); } |
561 WORD { $$ = new_si($1, NODEV); } |
562 major_minor { $$ = new_si(NULL, $1); };
563
564 major_minor:
565 MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); };
566
567 on_opt:
568 ON | /* empty */;
569
570 npseudo:
571 NUMBER { $$ = $1.val; } |
572 /* empty */ { $$ = 1; };
573
574 device_instance:
575 WORD '*' { $$ = starref($1); } |
576 WORD { $$ = $1; };
577
578 attachment:
579 ROOT { $$ = NULL; } |
580 WORD '?' { $$ = wildref($1); } |
581 WORD { $$ = $1; };
582
583 locators:
584 locators locator { $$ = $2; app($2, $1); } |
585 /* empty */ { $$ = NULL; };
586
587 locator:
588 WORD values { $$ = mk_ns($1, $2); } |
589 WORD '?' { $$ = new_ns($1, NULL); };
590
591 flags_opt:
592 FLAGS NUMBER { $$ = $2.val; } |
593 /* empty */ { $$ = 0; };
594
595 %%
596
597 void
598 yyerror(const char *s)
599 {
600
601 cfgerror("%s", s);
602 }
603
604 /*
605 * Cleanup procedure after syntax error: release any nvlists
606 * allocated during parsing the current line.
607 */
608 static void
609 cleanup(void)
610 {
611 struct nvlist **np;
612 int i;
613
614 for (np = alloc, i = adepth; --i >= 0; np++)
615 nvfree(*np);
616 adepth = 0;
617 }
618
619 static void
620 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
621 {
622 char buf[MAXPATHLEN];
623 struct nvlist *nv;
624
625 machine = mch;
626 machinearch = mcharch;
627 machinesubarches = mchsubarches;
628
629 /*
630 * Define attributes for all the given names
631 */
632 if (defattr(machine, NULL, NULL, 0) != 0 ||
633 (machinearch != NULL &&
634 defattr(machinearch, NULL, NULL, 0) != 0))
635 exit(1);
636 for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
637 if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
638 exit(1);
639 }
640
641 /*
642 * Set up the file inclusion stack. This empty include tells
643 * the parser there are no more device definitions coming.
644 */
645 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
646 if (include(buf, ENDDEFS, 0, 0) != 0)
647 exit(1);
648
649 /* Include arch/${MACHINE}/conf/files.${MACHINE} */
650 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
651 machine, machine);
652 if (include(buf, ENDFILE, 0, 0) != 0)
653 exit(1);
654
655 /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
656 for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
657 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
658 nv->nv_name, nv->nv_name);
659 if (include(buf, ENDFILE, 0, 0) != 0)
660 exit(1);
661 }
662
663 /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
664 if (machinearch != NULL)
665 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
666 machinearch, machinearch);
667 else
668 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
669 if (include(buf, ENDFILE, 0, 0) != 0)
670 exit(1);
671
672 /*
673 * Include the global conf/files. As the last thing
674 * pushed on the stack, it will be processed first.
675 */
676 if (include("conf/files", ENDFILE, 0, 0) != 0)
677 exit(1);
678
679 oktopackage = 1;
680 }
681
682 static void
683 check_maxpart(void)
684 {
685
686 if (maxpartitions <= 0) {
687 stop("cannot proceed without maxpartitions specifier");
688 }
689 }
690
691 static void
692 check_version(void)
693 {
694 /*
695 * In essence, version is 0 and is not supported anymore
696 */
697 if (version < CONFIG_MINVERSION)
698 stop("your sources are out of date -- please update.");
699 }
700
701 static void
702 app(struct nvlist *p, struct nvlist *q)
703 {
704 while (p->nv_next)
705 p = p->nv_next;
706 p->nv_next = q;
707 }
708
709 static struct nvlist *
710 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
711 {
712 struct nvlist *defs = adefs;
713 struct nvlist **p;
714 char buf[200];
715 int i;
716
717 if (count <= 0) {
718 fprintf(stderr, "config: array with <= 0 size: %s\n", name);
719 exit(1);
720 }
721 p = &defs;
722 for(i = 0; i < count; i++) {
723 if (*p == NULL)
724 *p = new_s("0");
725 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
726 (*p)->nv_name = i == 0 ? name : intern(buf);
727 (*p)->nv_int = i > 0 || opt;
728 p = &(*p)->nv_next;
729 }
730 *p = 0;
731 return defs;
732 }
733
734
735 static struct nvlist *
736 mk_ns(const char *name, struct nvlist *vals)
737 {
738 struct nvlist *p;
739 char buf[200];
740 int i;
741
742 for(i = 0, p = vals; p; i++, p = p->nv_next) {
743 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
744 p->nv_name = i == 0 ? name : intern(buf);
745 }
746 return vals;
747 }
748
749