simplify nvlist creation slightly; change newnv() to take another arg: next

This commit is contained in:
cgd 1996-03-17 11:50:09 +00:00
parent 9d4db41a9f
commit 50b3b61ea3
5 changed files with 30 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: config.h,v 1.21 1996/03/17 06:29:21 cgd Exp $ */
/* $NetBSD: config.h,v 1.22 1996/03/17 11:50:09 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
@ -307,6 +307,7 @@ char *path __P((const char *));
void error __P((const char *, ...)); /* immediate errs */
void xerror __P((const char *, int, const char *, ...)); /* delayed errs */
__dead void panic __P((const char *, ...));
struct nvlist *newnv __P((const char *, const char *, void *, int));
struct nvlist *newnv __P((const char *, const char *, void *, int,
struct nvlist *));
void nvfree __P((struct nvlist *));
void nvfreel __P((struct nvlist *));

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.5 1996/03/17 05:19:33 cgd Exp $ */
/* $NetBSD: gram.y,v 1.6 1996/03/17 11:50:11 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
@ -68,14 +68,16 @@ static struct config conf; /* at most one active at a time */
/* the following is used to recover nvlist space after errors */
static struct nvlist *alloc[1000];
static int adepth;
#define new0(n,s,p,i) (alloc[adepth++] = newnv(n, s, p, i))
#define new_n(n) new0(n, NULL, NULL, 0)
#define new_ns(n, s) new0(n, s, NULL, 0)
#define new_si(s, i) new0(NULL, s, NULL, i)
#define new_nsi(n,s,i) new0(n, s, NULL, i)
#define new_np(n, p) new0(n, NULL, p, 0)
#define new_s(s) new0(NULL, s, NULL, 0)
#define new_p(p) new0(NULL, NULL, p, 0)
#define new0(n,s,p,i,x) (alloc[adepth++] = newnv(n, s, p, i, x))
#define new_n(n) new0(n, NULL, NULL, 0, NULL)
#define new_nx(n, x) new0(n, NULL, NULL, 0, x)
#define new_ns(n, s) new0(n, s, NULL, 0, NULL)
#define new_si(s, i) new0(NULL, s, NULL, i, NULL)
#define new_nsi(n,s,i) new0(n, s, NULL, i, NULL)
#define new_np(n, p) new0(n, NULL, p, 0, NULL)
#define new_s(s) new0(NULL, s, NULL, 0, NULL)
#define new_p(p) new0(NULL, NULL, p, 0, NULL)
#define new_px(p, x) new0(NULL, NULL, p, 0, x)
static void cleanup __P((void));
static void setmachine __P((const char *, const char *));
@ -165,7 +167,7 @@ file:
/* order of options is important, must use right recursion */
fopts:
WORD fopts = { ($$ = new_n($1))->nv_next = $2; } |
WORD fopts = { $$ = new_nx($1, $2); } |
/* empty */ = { $$ = NULL; };
fflgs:
@ -205,7 +207,7 @@ one_def:
MAJOR '{' majorlist '}';
atlist:
atlist ',' atname = { ($$ = new_n($3))->nv_next = $1; } |
atlist ',' atname = { $$ = new_nx($3, $1); } |
atname = { $$ = new_n($1); };
atname:
@ -218,7 +220,7 @@ veclist_opt:
/* veclist order matters, must use right recursion */
veclist:
WORD veclist = { ($$ = new_n($1))->nv_next = $2; } |
WORD veclist = { $$ = new_nx($1, $2); } |
WORD = { $$ = new_n($1); };
devbase:
@ -229,7 +231,7 @@ devattach_opt:
/* empty */ = { $$ = NULL; };
interface_opt:
'{' loclist_opt '}' = { ($$ = new_n(""))->nv_next = $2; } |
'{' loclist_opt '}' = { $$ = new_nx("", $2); } |
/* empty */ = { $$ = NULL; };
loclist_opt:
@ -265,7 +267,7 @@ attrs_opt:
/* empty */ = { $$ = NULL; };
attrs:
attrs ',' attr = { ($$ = new_p($3))->nv_next = $1; } |
attrs ',' attr = { $$ = new_px($3, $1); } |
attr = { $$ = new_p($1); };
attr:

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.16 1996/03/17 07:05:50 cgd Exp $ */
/* $NetBSD: main.c,v 1.17 1996/03/17 11:50:13 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
@ -322,7 +322,7 @@ do_option(ht, nppp, name, value, type)
register struct nvlist *nv;
/* assume it will work */
nv = newnv(name, value, NULL, 0);
nv = newnv(name, value, NULL, 0, NULL);
if (ht_insert(ht, name, nv) == 0) {
**nppp = nv;
*nppp = &nv->nv_next;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sem.c,v 1.6 1996/03/17 07:05:58 cgd Exp $ */
/* $NetBSD: sem.c,v 1.7 1996/03/17 11:50:14 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
@ -242,8 +242,7 @@ addtoattr(l, dev)
{
register struct nvlist *n;
n = newnv(NULL, NULL, dev, 0);
n->nv_next = l;
n = newnv(NULL, NULL, dev, 0, l);
return (n);
}
@ -281,9 +280,8 @@ defdev(dev, ispseudo, loclist, attrs)
loclist = NULL; /* defattr disposes of them for us */
if (defattr(dev->d_name, nv))
goto bad;
nv = newnv(dev->d_name, NULL, getattr(dev->d_name), 0);
nv->nv_next = attrs;
attrs = nv;
attrs = newnv(dev->d_name, NULL, getattr(dev->d_name), 0,
attrs);
}
/* Committed! Set up fields. */
@ -567,7 +565,7 @@ resolve(nvp, name, what, dflt, part)
min = (minor(dflt->nv_int) / maxpartitions) + part;
d = makedev(maj, min);
}
*nvp = nv = newnv(NULL, NULL, NULL, d);
*nvp = nv = newnv(NULL, NULL, NULL, d, NULL);
}
if (nv->nv_int != NODEV) {
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.3 1996/03/17 06:29:42 cgd Exp $ */
/* $NetBSD: util.c,v 1.4 1996/03/17 11:50:16 cgd Exp $ */
/*
* Copyright (c) 1992, 1993
@ -119,10 +119,11 @@ path(file)
static struct nvlist *nvhead;
struct nvlist *
newnv(name, str, ptr, i)
newnv(name, str, ptr, i, next)
const char *name, *str;
void *ptr;
int i;
struct nvlist *next;
{
register struct nvlist *nv;
@ -130,7 +131,7 @@ newnv(name, str, ptr, i)
nv = emalloc(sizeof(*nv));
else
nvhead = nv->nv_next;
nv->nv_next = NULL;
nv->nv_next = next;
nv->nv_name = name;
if (ptr == NULL)
nv->nv_str = str;