gram.y revision 1.6 1 %{
2 /* $NetBSD: gram.y,v 1.6 2006/05/25 22:28:38 cube 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 EMPTY
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 defopts { defflag(NULL, $3, NULL, 1); } |
286 DEFPARAM optfile_opt defopts defoptdeps
287 { defparam($2, $3, $4, 0); } |
288 OBSOLETE DEFPARAM defopts { defparam(NULL, $3, NULL, 1); } |
289 DEVICE devbase interface_opt attrs_opt
290 { defdev($2, $3, $4, 0); } |
291 ATTACH devbase AT atlist devattach_opt attrs_opt
292 { defdevattach($5, $2, $4, $6); } |
293 MAXPARTITIONS NUMBER { maxpartitions = $2.val; } |
294 MAXUSERS NUMBER NUMBER NUMBER { setdefmaxusers($2.val, $3.val, $4.val); } |
295 MAKEOPTIONS condmkopt_list |
296 DEFPSEUDO devbase interface_opt attrs_opt
297 { defdev($2, $3, $4, 1); } |
298 MAJOR '{' majorlist '}' |
299 VERSION NUMBER { setversion($2.val); };
300
301 atlist:
302 atlist ',' atname { $$ = new_nx($3, $1); } |
303 atname { $$ = new_n($1); };
304
305 atname:
306 WORD { $$ = $1; } |
307 ROOT { $$ = NULL; };
308
309 deffses:
310 deffses deffs { $$ = new_nx($2, $1); } |
311 deffs { $$ = new_n($1); };
312
313 deffs:
314 WORD { $$ = $1; };
315
316 defoptdeps:
317 ':' optdeps { $$ = $2; } |
318 /* empty */ { $$ = NULL; };
319
320 optdeps:
321 optdeps ',' optdep { $$ = new_nx($3, $1); } |
322 optdep { $$ = new_n($1); };
323
324 optdep:
325 WORD { $$ = $1; };
326
327 defopts:
328 defopts defopt { $$ = new_nx($2, $1); } |
329 defopt { $$ = new_n($1); };
330
331 defopt:
332 WORD { $$ = $1; };
333
334 devbase:
335 WORD { $$ = getdevbase($1); };
336
337 devattach_opt:
338 WITH WORD { $$ = getdevattach($2); } |
339 /* empty */ { $$ = NULL; };
340
341 interface_opt:
342 '{' loclist_opt '}' { $$ = new_nx("", $2); } |
343 /* empty */ { $$ = NULL; };
344
345 loclist_opt:
346 loclist { $$ = $1; } |
347 /* empty */ { $$ = NULL; };
348
349 /* loclist order matters, must use right recursion */
350 loclist:
351 locdef ',' loclist { $$ = $1; app($1, $3); } |
352 locdef { $$ = $1; };
353
354 /* "[ WORD locdefault ]" syntax may be unnecessary... */
355 locdef:
356 locname locdefault { $$ = new_nsi($1, $2, 0); } |
357 locname { $$ = new_nsi($1, NULL, 0); } |
358 '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); } |
359 locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); } |
360 locname '[' NUMBER ']' locdefaults
361 { $$ = mk_nsis($1, $3.val, $5, 0); } |
362 '[' locname '[' NUMBER ']' locdefaults ']'
363 { $$ = mk_nsis($2, $4.val, $6, 1); };
364
365 locname:
366 WORD { $$ = $1; } |
367 QSTRING { $$ = $1; };
368
369 locdefault:
370 '=' value { $$ = $2; };
371
372 locdefaults:
373 '=' '{' values '}' { $$ = $3; };
374
375 fsoptfile_opt:
376 filename { $$ = $1; } |
377 /* empty */ { $$ = NULL; };
378
379 optfile_opt:
380 filename { $$ = $1; } |
381 /* empty */ { $$ = NULL; };
382
383 filename:
384 QSTRING { $$ = $1; } |
385 PATHNAME { $$ = $1; };
386
387 value:
388 QSTRING { $$ = $1; } |
389 WORD { $$ = $1; } |
390 EMPTY { $$ = $1; } |
391 signed_number { char bf[40];
392 (void)snprintf(bf, sizeof(bf),
393 FORMAT($1), (long long)$1.val);
394 $$ = intern(bf); };
395
396 stringvalue:
397 QSTRING { $$ = $1; } |
398 WORD { $$ = $1; };
399
400 values:
401 value ',' values { $$ = new_sx($1, $3); } |
402 value { $$ = new_s($1); };
403
404 signed_number:
405 NUMBER { $$ = $1; } |
406 '-' NUMBER { $$.fmt = $2.fmt; $$.val = -$2.val; };
407
408 attrs_opt:
409 ':' attrs { $$ = $2; } |
410 /* empty */ { $$ = NULL; };
411
412 attrs:
413 attrs ',' attr { $$ = new_px($3, $1); } |
414 attr { $$ = new_p($1); };
415
416 attr:
417 WORD { $$ = getattr($1); };
418
419 majorlist:
420 majorlist ',' majordef |
421 majordef;
422
423 majordef:
424 devbase '=' NUMBER { setmajor($1, $3.val); };
425
426
427 /*
428 * The configuration grammar.
429 */
430 specs:
431 specs spec |
432 /* empty */;
433
434 spec:
435 config_spec '\n' { adepth = 0; } |
436 '\n' |
437 error '\n' { cleanup(); };
438
439 config_spec:
440 one_def |
441 NO FILE_SYSTEM no_fs_list |
442 FILE_SYSTEM fs_list |
443 NO MAKEOPTIONS no_mkopt_list |
444 MAKEOPTIONS mkopt_list |
445 NO OPTIONS no_opt_list |
446 OPTIONS opt_list |
447 MAXUSERS NUMBER { setmaxusers($2.val); } |
448 IDENT stringvalue { setident($2); } |
449 CONFIG conf root_spec sysparam_list
450 { addconf(&conf); } |
451 NO CONFIG WORD { delconf($3); } |
452 NO PSEUDO_DEVICE WORD { delpseudo($3); } |
453 PSEUDO_DEVICE WORD npseudo { addpseudo($2, $3); } |
454 NO device_instance AT attachment
455 { deldevi($2, $4); } |
456 NO DEVICE AT attachment { deldeva($4); } |
457 NO device_instance { deldev($2); } |
458 device_instance AT attachment locators flags_opt
459 { adddev($1, $3, $4, $5); };
460
461 fs_list:
462 fs_list ',' fsoption |
463 fsoption;
464
465 fsoption:
466 WORD { addfsoption($1); };
467
468 no_fs_list:
469 no_fs_list ',' no_fsoption |
470 no_fsoption;
471
472 no_fsoption:
473 WORD { delfsoption($1); };
474
475 mkopt_list:
476 mkopt_list ',' mkoption |
477 mkoption;
478
479 mkvarname:
480 QSTRING { $$ = $1; } |
481 WORD { $$ = $1; };
482
483 mkoption:
484 mkvarname '=' value { addmkoption($1, $3); } |
485 mkvarname PLUSEQ value { appendmkoption($1, $3); };
486
487 condmkopt_list:
488 condmkopt_list ',' condmkoption |
489 condmkoption;
490
491 condmkoption:
492 WORD mkvarname PLUSEQ value { appendcondmkoption($1, $2, $4); };
493
494 no_mkopt_list:
495 no_mkopt_list ',' no_mkoption |
496 no_mkoption;
497
498 no_mkoption:
499 WORD { delmkoption($1); }
500
501 opt_list:
502 opt_list ',' option |
503 option;
504
505 option:
506 WORD { addoption($1, NULL); } |
507 WORD '=' value { addoption($1, $3); };
508
509 no_opt_list:
510 no_opt_list ',' no_option |
511 no_option;
512
513 no_option:
514 WORD { deloption($1); };
515
516 conf:
517 WORD { conf.cf_name = $1;
518 conf.cf_lineno = currentline();
519 conf.cf_fstype = NULL;
520 conf.cf_root = NULL;
521 conf.cf_dump = NULL; };
522
523 root_spec:
524 ROOT on_opt dev_spec fs_spec_opt
525 { setconf(&conf.cf_root, "root", $3); };
526
527 fs_spec_opt:
528 TYPE fs_spec { setfstype(&conf.cf_fstype, $2); } |
529 /* empty */;
530
531 fs_spec:
532 '?' { $$ = intern("?"); } |
533 WORD { $$ = $1; };
534
535 sysparam_list:
536 sysparam_list sysparam |
537 /* empty */;
538
539 sysparam:
540 DUMPS on_opt dev_spec { setconf(&conf.cf_dump, "dumps", $3); };
541
542 dev_spec:
543 '?' { $$ = new_si(intern("?"), NODEV); } |
544 WORD { $$ = new_si($1, NODEV); } |
545 major_minor { $$ = new_si(NULL, $1); };
546
547 major_minor:
548 MAJOR NUMBER MINOR NUMBER { $$ = makedev($2.val, $4.val); };
549
550 on_opt:
551 ON | /* empty */;
552
553 npseudo:
554 NUMBER { $$ = $1.val; } |
555 /* empty */ { $$ = 1; };
556
557 device_instance:
558 WORD '*' { $$ = starref($1); } |
559 WORD { $$ = $1; };
560
561 attachment:
562 ROOT { $$ = NULL; } |
563 WORD '?' { $$ = wildref($1); } |
564 WORD { $$ = $1; };
565
566 locators:
567 locators locator { $$ = $2; app($2, $1); } |
568 /* empty */ { $$ = NULL; };
569
570 locator:
571 WORD values { $$ = mk_ns($1, $2); } |
572 WORD '?' { $$ = new_ns($1, NULL); };
573
574 flags_opt:
575 FLAGS NUMBER { $$ = $2.val; } |
576 /* empty */ { $$ = 0; };
577
578 %%
579
580 void
581 yyerror(const char *s)
582 {
583
584 error("%s", s);
585 }
586
587 /*
588 * Cleanup procedure after syntax error: release any nvlists
589 * allocated during parsing the current line.
590 */
591 static void
592 cleanup(void)
593 {
594 struct nvlist **np;
595 int i;
596
597 for (np = alloc, i = adepth; --i >= 0; np++)
598 nvfree(*np);
599 adepth = 0;
600 }
601
602 static void
603 setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
604 {
605 char buf[MAXPATHLEN];
606 struct nvlist *nv;
607
608 machine = mch;
609 machinearch = mcharch;
610 machinesubarches = mchsubarches;
611
612 /*
613 * Set up the file inclusion stack. This empty include tells
614 * the parser there are no more device definitions coming.
615 */
616 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
617 if (include(buf, ENDDEFS, 0, 0) != 0)
618 exit(1);
619
620 /* Include arch/${MACHINE}/conf/files.${MACHINE} */
621 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
622 machine, machine);
623 if (include(buf, ENDFILE, 0, 0) != 0)
624 exit(1);
625
626 /* Include any arch/${MACHINE_SUBARCH}/conf/files.${MACHINE_SUBARCH} */
627 for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
628 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
629 nv->nv_name, nv->nv_name);
630 if (include(buf, ENDFILE, 0, 0) != 0)
631 exit(1);
632 }
633
634 /* Include any arch/${MACHINE_ARCH}/conf/files.${MACHINE_ARCH} */
635 if (machinearch != NULL)
636 (void)snprintf(buf, sizeof(buf), "arch/%s/conf/files.%s",
637 machinearch, machinearch);
638 else
639 strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
640 if (include(buf, ENDFILE, 0, 0) != 0)
641 exit(1);
642
643 /*
644 * Include the global conf/files. As the last thing
645 * pushed on the stack, it will be processed first.
646 */
647 if (include("conf/files", ENDFILE, 0, 0) != 0)
648 exit(1);
649
650 oktopackage = 1;
651 }
652
653 static void
654 check_maxpart(void)
655 {
656
657 if (maxpartitions <= 0) {
658 stop("cannot proceed without maxpartitions specifier");
659 }
660 }
661
662 static void
663 check_version(void)
664 {
665 /*
666 * In essence, version is 0 and is not supported anymore
667 */
668 if (version < CONFIG_MINVERSION)
669 stop("your sources are out of date -- please update.");
670 }
671
672 static void
673 app(struct nvlist *p, struct nvlist *q)
674 {
675 while (p->nv_next)
676 p = p->nv_next;
677 p->nv_next = q;
678 }
679
680 static struct nvlist *
681 mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
682 {
683 struct nvlist *defs = adefs;
684 struct nvlist **p;
685 char buf[200];
686 int i;
687
688 if (count <= 0) {
689 fprintf(stderr, "config: array with <= 0 size: %s\n", name);
690 exit(1);
691 }
692 p = &defs;
693 for(i = 0; i < count; i++) {
694 if (*p == NULL)
695 *p = new_s("0");
696 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
697 (*p)->nv_name = i == 0 ? name : intern(buf);
698 (*p)->nv_int = i > 0 || opt;
699 p = &(*p)->nv_next;
700 }
701 *p = 0;
702 return defs;
703 }
704
705
706 static struct nvlist *
707 mk_ns(const char *name, struct nvlist *vals)
708 {
709 struct nvlist *p;
710 char buf[200];
711 int i;
712
713 for(i = 0, p = vals; p; i++, p = p->nv_next) {
714 snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
715 p->nv_name = i == 0 ? name : intern(buf);
716 }
717 return vals;
718 }
719
720