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