Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.bin / config / gram.y
bloba9f6de68dfb0445ba9848ad22ef62056f70b92dd
1 %{
2 /* $NetBSD: gram.y,v 1.18 2008/12/28 01:23:46 christos Exp $ */
4 /*
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
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.
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.
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.
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.
41 * from: @(#)gram.y 8.1 (Berkeley) 6/6/93
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"
54 #define FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
55 ((n).fmt == 16) ? "0x%llx" : "%lld")
57 #define stop(s) cfgerror(s), exit(1)
59 static struct config conf; /* at most one active at a time */
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)
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)
82 static void cleanup(void);
83 static void setmachine(const char *, const char *, struct nvlist *);
84 static void check_maxpart(void);
86 static void app(struct nvlist *, struct nvlist *);
88 static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
89 static struct nvlist *mk_ns(const char *, struct nvlist *);
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;
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
124 %left '|'
125 %left '&'
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
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.
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 */
179 topthings:
180 topthings topthing |
181 /* empty */;
183 topthing:
184 SOURCE filename '\n' { if (!srcdir) srcdir = $2; } |
185 BUILD filename '\n' { if (!builddir) builddir = $2; } |
186 '\n';
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"); };
193 subarches_opt:
194 subarches |
195 /* empty */ { $$ = NULL; };
197 subarches:
198 subarches WORD { $$ = new_nx($2, $1); } |
199 WORD { $$ = new_n($1); };
202 * Various nonterminals shared between the grammars.
204 file:
205 XFILE filename fopts fflgs rule { addfile($2, $3, $4, $5); };
207 object:
208 XOBJECT filename fopts oflgs { addobject($2, $3, $4); };
210 device_major:
211 DEVICE_MAJOR WORD device_major_char device_major_block fopts
212 { adddevm($2, $3, $4, $5); };
214 device_major_block:
215 BLOCK NUMBER { $$ = $2.val; } |
216 /* empty */ { $$ = -1; };
218 device_major_char:
219 CHAR NUMBER { $$ = $2.val; } |
220 /* empty */ { $$ = -1; };
222 /* order of options is important, must use right recursion */
223 fopts:
224 fexpr { $$ = $1; } |
225 /* empty */ { $$ = NULL; };
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; };
234 fatom:
235 WORD { $$ = fx_atom($1); };
237 fflgs:
238 fflgs fflag { $$ = $1 | $2; } |
239 /* empty */ { $$ = 0; };
241 fflag:
242 NEEDS_COUNT { $$ = FI_NEEDSCOUNT; } |
243 NEEDS_FLAG { $$ = FI_NEEDSFLAG; };
245 oflgs:
246 oflgs oflag { $$ = $1 | $2; } |
247 /* empty */ { $$ = 0; };
249 oflag:
250 NEEDS_FLAG { $$ = OI_NEEDSFLAG; };
252 rule:
253 COMPILE_WITH stringvalue { $$ = $2; } |
254 /* empty */ { $$ = NULL; };
256 prefix:
257 PREFIX filename { prefix_push($2); } |
258 PREFIX { prefix_pop(); };
261 * The machine definitions grammar.
263 dev_defs:
264 dev_defs dev_def |
265 dev_defs ENDFILE { enddefs(); checkfiles(); } |
266 /* empty */;
268 dev_def:
269 one_def '\n' { adepth = 0; } |
270 '\n' |
271 error '\n' { cleanup(); };
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 /* interface_opt in DEFPSEUDO is for backwards compatibility */
301 DEFPSEUDO devbase interface_opt attrs_opt
302 { defdev($2, $3, $4, 1); } |
303 DEFPSEUDODEV devbase interface_opt attrs_opt
304 { defdev($2, $3, $4, 2); } |
305 MAJOR '{' majorlist '}' |
306 VERSION NUMBER { setversion($2.val); };
308 atlist:
309 atlist ',' atname { $$ = new_nx($3, $1); } |
310 atname { $$ = new_n($1); };
312 atname:
313 WORD { $$ = $1; } |
314 ROOT { $$ = NULL; };
316 deffses:
317 deffses deffs { $$ = new_nx($2, $1); } |
318 deffs { $$ = new_n($1); };
320 deffs:
321 WORD { $$ = $1; };
323 defoptdeps:
324 ':' optdeps { $$ = $2; } |
325 /* empty */ { $$ = NULL; };
327 optdeps:
328 optdeps ',' optdep { $$ = new_nx($3, $1); } |
329 optdep { $$ = new_n($1); };
331 optdep:
332 WORD { $$ = $1; };
334 defopts:
335 defopts defopt { $$ = nvcat($2, $1); } |
336 defopt { $$ = $1; };
338 defopt:
339 WORD { $$ = new_n($1); } |
340 WORD '=' value { $$ = new_ns($1, $3); } |
341 WORD COLONEQ value {
342 struct nvlist *__nv =
343 new_n($1);
344 $$ = new_nsx("", $3, __nv);
346 WORD '=' value COLONEQ value {
347 struct nvlist *__nv =
348 new_n($1);
349 $$ = new_nsx("", $5, __nv);
352 devbase:
353 WORD { $$ = getdevbase($1); };
355 devattach_opt:
356 WITH WORD { $$ = getdevattach($2); } |
357 /* empty */ { $$ = NULL; };
359 interface_opt:
360 '{' loclist_opt '}' { $$ = new_nx("", $2); } |
361 /* empty */ { $$ = NULL; };
363 loclist_opt:
364 loclist { $$ = $1; } |
365 /* empty */ { $$ = NULL; };
367 /* loclist order matters, must use right recursion */
368 loclist:
369 locdef ',' loclist { $$ = $1; app($1, $3); } |
370 locdef { $$ = $1; };
372 /* "[ WORD locdefault ]" syntax may be unnecessary... */
373 locdef:
374 locname locdefault { $$ = new_nsi($1, $2, 0); } |
375 locname { $$ = new_nsi($1, NULL, 0); } |
376 '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); } |
377 locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); } |
378 locname '[' NUMBER ']' locdefaults
379 { $$ = mk_nsis($1, $3.val, $5, 0); } |
380 '[' locname '[' NUMBER ']' locdefaults ']'
381 { $$ = mk_nsis($2, $4.val, $6, 1); };
383 locname:
384 WORD { $$ = $1; } |
385 QSTRING { $$ = $1; };
387 locdefault:
388 '=' value { $$ = $2; };
390 locdefaults:
391 '=' '{' values '}' { $$ = $3; };
393 fsoptfile_opt:
394 filename { $$ = $1; } |
395 /* empty */ { $$ = NULL; };
397 optfile_opt:
398 filename { $$ = $1; } |
399 /* empty */ { $$ = NULL; };
401 filename:
402 QSTRING { $$ = $1; } |
403 PATHNAME { $$ = $1; };
405 value:
406 QSTRING { $$ = $1; } |
407 WORD { $$ = $1; } |
408 EMPTYSTRING { $$ = $1; } |
409 signed_number { char bf[40];
410 (void)snprintf(bf, sizeof(bf),
411 FORMAT($1), (long long)$1.val);
412 $$ = intern(bf); };
414 stringvalue:
415 QSTRING { $$ = $1; } |
416 WORD { $$ = $1; };
418 values:
419 value ',' values { $$ = new_sx($1, $3); } |
420 value { $$ = new_s($1); };
422 signed_number:
423 NUMBER { $$ = $1; } |
424 '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; };
426 attrs_opt:
427 ':' attrs { $$ = $2; } |
428 /* empty */ { $$ = NULL; };
430 attrs:
431 attrs ',' attr { $$ = new_px($3, $1); } |
432 attr { $$ = new_p($1); };
434 attr:
435 WORD { $$ = getattr($1); };
437 majorlist:
438 majorlist ',' majordef |
439 majordef;
441 majordef:
442 devbase '=' NUMBER { setmajor($1, $3.val); };
446 * The configuration grammar.
448 specs:
449 specs spec |
450 /* empty */;
452 spec:
453 config_spec '\n' { adepth = 0; } |
454 '\n' |
455 error '\n' { cleanup(); };
457 config_spec:
458 one_def |
459 NO FILE_SYSTEM no_fs_list |
460 FILE_SYSTEM fs_list |
461 NO MAKEOPTIONS no_mkopt_list |
462 MAKEOPTIONS mkopt_list |
463 NO OPTIONS no_opt_list |
464 OPTIONS opt_list |
465 MAXUSERS NUMBER { setmaxusers($2.val); } |
466 IDENT stringvalue { setident($2); } |
467 CONFIG conf root_spec sysparam_list
468 { addconf(&conf); } |
469 NO CONFIG WORD { delconf($3); } |
470 NO PSEUDO_DEVICE WORD { delpseudo($3); } |
471 PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); } |
472 NO device_instance AT attachment
473 { deldevi($2, $4); } |
474 NO DEVICE AT attachment { deldeva($4); } |
475 NO device_instance { deldev($2); } |
476 device_instance AT attachment locators flags_opt
477 { adddev($1, $3, $4, $5); };
479 fs_list:
480 fs_list ',' fsoption |
481 fsoption;
483 fsoption:
484 WORD { addfsoption($1); };
486 no_fs_list:
487 no_fs_list ',' no_fsoption |
488 no_fsoption;
490 no_fsoption:
491 WORD { delfsoption($1); };
493 mkopt_list:
494 mkopt_list ',' mkoption |
495 mkoption;
497 mkvarname:
498 QSTRING { $$ = $1; } |
499 WORD { $$ = $1; };
501 mkoption:
502 mkvarname '=' value { addmkoption($1, $3); } |
503 mkvarname PLUSEQ value { appendmkoption($1, $3); };
505 condmkopt_list:
506 condmkopt_list ',' condmkoption |
507 condmkoption;
509 condmkoption:
510 fexpr mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); };
512 no_mkopt_list:
513 no_mkopt_list ',' no_mkoption |
514 no_mkoption;
516 no_mkoption:
517 WORD { delmkoption($1); }
519 opt_list:
520 opt_list ',' option |
521 option;
523 option:
524 WORD { addoption($1, NULL); } |
525 WORD '=' value { addoption($1, $3); };
527 no_opt_list:
528 no_opt_list ',' no_option |
529 no_option;
531 no_option:
532 WORD { deloption($1); };
534 conf:
535 WORD { conf.cf_name = $1;
536 conf.cf_lineno = currentline();
537 conf.cf_fstype = NULL;
538 conf.cf_root = NULL;
539 conf.cf_dump = NULL; };
541 root_spec:
542 ROOT on_opt dev_spec fs_spec_opt
543 { setconf(&conf.cf_root, "root", $3); };
545 fs_spec_opt:
546 TYPE fs_spec { setfstype(&conf.cf_fstype, $2); } |
547 /* empty */;
549 fs_spec:
550 '?' { $$ = intern("?"); } |
551 WORD { $$ = $1; };
553 sysparam_list:
554 sysparam_list sysparam |
555 /* empty */;
557 sysparam:
558 DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); };
560 dev_spec:
561 '?' { $$ = new_si(intern("?"), NODEV); } |
562 WORD { $$ = new_si($1, NODEV); } |
563 major_minor { $$ = new_si(NULL, $1); };
565 major_minor:
566 MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); };
568 on_opt:
569 ON | /* empty */;
571 npseudo:
572 NUMBER { $$ = $1.val; } |
573 /* empty */ { $$ = 1; };
575 device_instance:
576 WORD '*' { $$ = starref($1); } |
577 WORD { $$ = $1; };
579 attachment:
580 ROOT { $$ = NULL; } |
581 WORD '?' { $$ = wildref($1); } |
582 WORD { $$ = $1; };
584 locators:
585 locators locator { $$ = $2; app($2, $1); } |
586 /* empty */ { $$ = NULL; };
588 locator:
589 WORD values { $$ = mk_ns($1, $2); } |
590 WORD '?' { $$ = new_ns($1, NULL); };
592 flags_opt:
593 FLAGS NUMBER { $$ = $2.val; } |
594 /* empty */ { $$ = 0; };
598 void
599 yyerror(const char *s)
602 cfgerror("%s", s);
606 * Cleanup procedure after syntax error: release any nvlists
607 * allocated during parsing the current line.
609 static void
610 cleanup(void)
612 struct nvlist **np;
613 int i;
615 for (np = alloc, i = adepth; --i >= 0; np++)
616 nvfree(*np);
617 adepth = 0;
620 static void
621 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
623 char buf[MAXPATHLEN];
624 struct nvlist *nv;
626 machine = mch;
627 machinearch = mcharch;
628 machinesubarches = mchsubarches;
631 * Define attributes for all the given names
633 if (defattr(machine, NULL, NULL, 0) != 0 ||
634 (machinearch != NULL &&
635 defattr(machinearch, NULL, NULL, 0) != 0))
636 exit(1);
637 for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
638 if (defattr(nv->nv_name, NULL, NULL, 0) != 0)
639 exit(1);
643 * Set up the file inclusion stack. This empty include tells
644 * the parser there are no more device definitions coming.
646 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
647 if (include(buf, ENDDEFS, 0, 0) != 0)
648 exit(1);
650 /* Include arch/${MACHINE}/conf/files.${MACHINE} */
651 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
652 machine, machine);
653 if (include(buf, ENDFILE, 0, 0) != 0)
654 exit(1);
656 /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
657 for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
658 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
659 nv->nv_name, nv->nv_name);
660 if (include(buf, ENDFILE, 0, 0) != 0)
661 exit(1);
664 /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
665 if (machinearch != NULL)
666 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
667 machinearch, machinearch);
668 else
669 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
670 if (include(buf, ENDFILE, 0, 0) != 0)
671 exit(1);
674 * Include the global conf/files. As the last thing
675 * pushed on the stack, it will be processed first.
677 if (include("conf/files", ENDFILE, 0, 0) != 0)
678 exit(1);
680 oktopackage = 1;
683 static void
684 check_maxpart(void)
687 if (maxpartitions <= 0) {
688 stop("cannot proceed without maxpartitions specifier");
692 static void
693 check_version(void)
696 * In essence, version is 0 and is not supported anymore
698 if (version < CONFIG_MINVERSION)
699 stop("your sources are out of date -- please update.");
702 static void
703 app(struct nvlist *p, struct nvlist *q)
705 while (p->nv_next)
706 p = p->nv_next;
707 p->nv_next = q;
710 static struct nvlist *
711 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
713 struct nvlist *defs = adefs;
714 struct nvlist **p;
715 char buf[200];
716 int i;
718 if (count <= 0) {
719 fprintf(stderr, "config: array with <= 0 size: %s\n", name);
720 exit(1);
722 p = &defs;
723 for(i = 0; i < count; i++) {
724 if (*p == NULL)
725 *p = new_s("0");
726 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
727 (*p)->nv_name = i == 0 ? name : intern(buf);
728 (*p)->nv_num = i > 0 || opt;
729 p = &(*p)->nv_next;
731 *p = 0;
732 return defs;
736 static struct nvlist *
737 mk_ns(const char *name, struct nvlist *vals)
739 struct nvlist *p;
740 char buf[200];
741 int i;
743 for(i = 0, p = vals; p; i++, p = p->nv_next) {
744 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
745 p->nv_name = i == 0 ? name : intern(buf);
747 return vals;