Module Name: src
Committed By: dholland
Date: Sun Mar 11 21:16:08 UTC 2012
Modified Files:
src/usr.bin/config: defs.h gram.y lint.c mkheaders.c mkioconf.c sem.c
sem.h util.c
Log Message:
Move locator lists to their own data structure. This can use more tidying;
it is not clear to me at the moment what the "string" and "num" values
pushed around in locator lists are supposed to actually mean.
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/config/defs.h
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/config/gram.y
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/config/lint.c src/usr.bin/config/sem.h
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/config/mkheaders.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/config/mkioconf.c
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/config/sem.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/config/util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/config/defs.h
diff -u src/usr.bin/config/defs.h:1.39 src/usr.bin/config/defs.h:1.40
--- src/usr.bin/config/defs.h:1.39 Sun Mar 11 08:21:53 2012
+++ src/usr.bin/config/defs.h Sun Mar 11 21:16:07 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.39 2012/03/11 08:21:53 dholland Exp $ */
+/* $NetBSD: defs.h,v 1.40 2012/03/11 21:16:07 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -157,7 +157,7 @@ struct attr {
const char *a_name; /* name of this attribute */
int a_iattr; /* true => allows children */
const char *a_devclass; /* device class described */
- struct nvlist *a_locs; /* locators required */
+ struct loclist *a_locs; /* locators required */
int a_loclen; /* length of above list */
struct nvlist *a_devs; /* children */
struct nvlist *a_refs; /* parents */
@@ -174,6 +174,20 @@ struct attrlist {
};
/*
+ * List of locators. (Either definitions or uses...)
+ *
+ * XXX it would be nice if someone could clarify wtf ll_string and ll_num
+ * are actually holding. (This stuff was previously stored in a very ad
+ * hoc fashion, and the code is far from clear.)
+ */
+struct loclist {
+ const char *ll_name;
+ const char *ll_string;
+ long long ll_num;
+ struct loclist *ll_next;
+};
+
+/*
* Parent specification. Multiple device instances may share a
* given parent spec. Parent specs are emitted only if there are
* device instances which actually reference it.
@@ -604,6 +618,8 @@ struct attrlist *attrlist_create(void);
struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
void attrlist_destroy(struct attrlist *);
void attrlist_destroyall(struct attrlist *);
+struct loclist *loclist_create(const char *, const char *, long long);
+void loclist_destroy(struct loclist *);
struct condexpr *condexpr_create(enum condexpr_types);
void condexpr_destroy(struct condexpr *);
Index: src/usr.bin/config/gram.y
diff -u src/usr.bin/config/gram.y:1.35 src/usr.bin/config/gram.y:1.36
--- src/usr.bin/config/gram.y:1.35 Sun Mar 11 19:27:26 2012
+++ src/usr.bin/config/gram.y Sun Mar 11 21:16:08 2012
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: gram.y,v 1.35 2012/03/11 19:27:26 dholland Exp $ */
+/* $NetBSD: gram.y,v 1.36 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -70,8 +70,9 @@ static void wrap_cleanup(void);
* Allocation wrapper type codes
*/
#define WRAP_CODE_nvlist 1
-#define WRAP_CODE_attrlist 2
-#define WRAP_CODE_condexpr 3
+#define WRAP_CODE_loclist 2
+#define WRAP_CODE_attrlist 3
+#define WRAP_CODE_condexpr 4
/*
* The allocation wrappers themselves
@@ -79,10 +80,12 @@ static void wrap_cleanup(void);
#define DECL_ALLOCWRAP(t) static struct t *wrap_mk_##t(struct t *arg)
DECL_ALLOCWRAP(nvlist);
+DECL_ALLOCWRAP(loclist);
DECL_ALLOCWRAP(attrlist);
DECL_ALLOCWRAP(condexpr);
/* allow shorter names */
+#define wrap_mk_loc(p) wrap_mk_loclist(p)
#define wrap_mk_cx(p) wrap_mk_condexpr(p)
/*
@@ -108,6 +111,7 @@ DECL_ALLOCWRAP(condexpr);
#define MK0(t) wrap_mk_##t(mk_##t())
#define MK1(t, a0) wrap_mk_##t(mk_##t(a0))
#define MK2(t, a0, a1) wrap_mk_##t(mk_##t(a0, a1))
+#define MK3(t, a0, a1, a2) wrap_mk_##t(mk_##t(a0, a1, a2))
#define MKF0(t, f) wrap_mk_##t(mk_##t##_##f())
#define MKF1(t, f, a0) wrap_mk_##t(mk_##t##_##f(a0))
@@ -117,6 +121,8 @@ DECL_ALLOCWRAP(condexpr);
* Data constructors
*/
+static struct loclist *mk_loc(const char *, const char *, long long);
+static struct loclist *mk_loc_val(const char *, struct loclist *);
static struct attrlist *mk_attrlist(struct attrlist *, struct attr *);
static struct condexpr *mk_cx_atom(const char *);
static struct condexpr *mk_cx_not(struct condexpr *);
@@ -130,10 +136,10 @@ static struct condexpr *mk_cx_or(struct
static void setmachine(const char *, const char *, struct nvlist *, int);
static void check_maxpart(void);
-static void app(struct nvlist *, struct nvlist *);
-
-static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
-static struct nvlist *mk_ns(const char *, struct nvlist *);
+static struct loclist *present_loclist(struct loclist *ll);
+static void app(struct loclist *, struct loclist *);
+static struct loclist *locarray(const char *, int, struct loclist *, int);
+static struct loclist *namelocvals(const char *, struct loclist *);
%}
@@ -142,6 +148,7 @@ static struct nvlist *mk_ns(const char *
struct devbase *devb;
struct deva *deva;
struct nvlist *list;
+ struct loclist *loclist;
struct attrlist *attrlist;
struct condexpr *condexpr;
const char *str;
@@ -180,13 +187,14 @@ static struct nvlist *mk_ns(const char *
%type <attr> depend
%type <devb> devbase
%type <deva> devattach_opt
-%type <list> atlist interface_opt
+%type <list> atlist
+%type <loclist> interface_opt
%type <str> atname
-%type <list> loclist locdef
+%type <loclist> loclist locdef
%type <str> locdefault
-%type <list> values locdefaults
+%type <loclist> values locdefaults
%type <attrlist> depend_list depends
-%type <list> locators locator
+%type <loclist> locators locator
%type <list> dev_spec
%type <str> device_instance
%type <str> attachment
@@ -442,8 +450,8 @@ deffs:
/* optional locator specification */
interface_opt:
/* empty */ { $$ = NULL; }
- | '{' '}' { $$ = new_nx("", NULL); }
- | '{' loclist '}' { $$ = new_nx("", $2); }
+ | '{' '}' { $$ = present_loclist(NULL); }
+ | '{' loclist '}' { $$ = present_loclist($2); }
;
/*
@@ -463,14 +471,14 @@ loclist:
/* one locator definition */
locdef:
- locname locdefault { $$ = new_nsi($1, $2, 0); }
- | locname { $$ = new_nsi($1, NULL, 0); }
- | '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); }
- | locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); }
+ locname locdefault { $$ = MK3(loc, $1, $2, 0); }
+ | locname { $$ = MK3(loc, $1, NULL, 0); }
+ | '[' locname locdefault ']' { $$ = MK3(loc, $2, $3, 1); }
+ | locname '[' NUMBER ']' { $$ = locarray($1, $3.val, NULL, 0); }
| locname '[' NUMBER ']' locdefaults
- { $$ = mk_nsis($1, $3.val, $5, 0); }
+ { $$ = locarray($1, $3.val, $5, 0); }
| '[' locname '[' NUMBER ']' locdefaults ']'
- { $$ = mk_nsis($2, $4.val, $6, 1); }
+ { $$ = locarray($2, $4.val, $6, 1); }
;
/* locator name */
@@ -779,8 +787,8 @@ locators:
/* one locator */
locator:
- WORD '?' { $$ = new_ns($1, NULL); }
- | WORD values { $$ = mk_ns($1, $2); }
+ WORD '?' { $$ = MK3(loc, $1, NULL, 0); }
+ | WORD values { $$ = namelocvals($1, $2); }
;
/* optional device flags */
@@ -880,8 +888,8 @@ stringvalue:
/* comma-separated list of values */
/* XXX why right-recursive? */
values:
- value { $$ = new_s($1); }
- | value ',' values { $$ = new_sx($1, $3); }
+ value { $$ = MKF2(loc, val, $1, NULL); }
+ | value ',' values { $$ = MKF2(loc, val, $1, $3); }
;
/* possibly negative number */
@@ -956,24 +964,45 @@ wrap_cleanup(void)
{
unsigned i;
+ /*
+ * Destroy each item. Note that because everything allocated
+ * is entered on the list separately, lists and trees need to
+ * have their links blanked before being destroyed. Also note
+ * that strings are interned elsewhere and not handled by this
+ * mechanism.
+ */
+
for (i=0; i<wrap_depth; i++) {
switch (wrapstack[i].typecode) {
case WRAP_CODE_nvlist:
nvfree(wrapstack[i].ptr);
break;
+ case WRAP_CODE_loclist:
+ {
+ struct loclist *ll = wrapstack[i].ptr;
+
+ ll->ll_next = NULL;
+ loclist_destroy(ll);
+ }
+ break;
case WRAP_CODE_attrlist:
{
struct attrlist *al = wrapstack[i].ptr;
- /*
- * Contents got wrapped separately;
- * just blank it out to destroy.
- */
al->al_next = NULL;
al->al_this = NULL;
attrlist_destroy(al);
}
break;
+ case WRAP_CODE_condexpr:
+ {
+ struct condexpr *cx = wrapstack[i].ptr;
+
+ cx->cx_type = CX_ATOM;
+ cx->cx_atom = NULL;
+ condexpr_destroy(cx);
+ }
+ break;
default:
panic("invalid code %u on allocation wrapper stack",
wrapstack[i].typecode);
@@ -999,6 +1028,7 @@ wrap_cleanup(void)
}
DEF_ALLOCWRAP(nvlist);
+DEF_ALLOCWRAP(loclist);
DEF_ALLOCWRAP(attrlist);
DEF_ALLOCWRAP(condexpr);
@@ -1006,8 +1036,26 @@ DEF_ALLOCWRAP(condexpr);
/*
* Data constructors
+ *
+ * (These are *beneath* the allocation wrappers.)
*/
+static struct loclist *
+mk_loc(const char *name, const char *str, long long num)
+{
+ return loclist_create(name, str, num);
+}
+
+static struct loclist *
+mk_loc_val(const char *str, struct loclist *next)
+{
+ struct loclist *ll;
+
+ ll = mk_loc(NULL, str, 0);
+ ll->ll_next = next;
+ return ll;
+}
+
static struct attrlist *
mk_attrlist(struct attrlist *next, struct attr *a)
{
@@ -1148,19 +1196,34 @@ check_version(void)
stop("your sources are out of date -- please update.");
}
+/*
+ * Prepend a blank entry to the locator definitions so the code in
+ * sem.c can distinguish "empty locator list" from "no locator list".
+ * XXX gross.
+ */
+static struct loclist *
+present_loclist(struct loclist *ll)
+{
+ struct loclist *ret;
+
+ ret = MK3(loc, "", NULL, 0);
+ ret->ll_next = ll;
+ return ret;
+}
+
static void
-app(struct nvlist *p, struct nvlist *q)
+app(struct loclist *p, struct loclist *q)
{
- while (p->nv_next)
- p = p->nv_next;
- p->nv_next = q;
+ while (p->ll_next)
+ p = p->ll_next;
+ p->ll_next = q;
}
-static struct nvlist *
-mk_nsis(const char *name, int count, struct nvlist *adefs, int opt)
+static struct loclist *
+locarray(const char *name, int count, struct loclist *adefs, int opt)
{
- struct nvlist *defs = adefs;
- struct nvlist **p;
+ struct loclist *defs = adefs;
+ struct loclist **p;
char buf[200];
int i;
@@ -1171,27 +1234,27 @@ mk_nsis(const char *name, int count, str
p = &defs;
for(i = 0; i < count; i++) {
if (*p == NULL)
- *p = new_s("0");
+ *p = MK3(loc, NULL, "0", 0);
snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
- (*p)->nv_name = i == 0 ? name : intern(buf);
- (*p)->nv_num = i > 0 || opt;
- p = &(*p)->nv_next;
+ (*p)->ll_name = i == 0 ? name : intern(buf);
+ (*p)->ll_num = i > 0 || opt;
+ p = &(*p)->ll_next;
}
*p = 0;
return defs;
}
-static struct nvlist *
-mk_ns(const char *name, struct nvlist *vals)
+static struct loclist *
+namelocvals(const char *name, struct loclist *vals)
{
- struct nvlist *p;
+ struct loclist *p;
char buf[200];
int i;
- for(i = 0, p = vals; p; i++, p = p->nv_next) {
+ for (i = 0, p = vals; p; i++, p = p->ll_next) {
snprintf(buf, sizeof(buf), "%s%c%d", name, ARRCHR, i);
- p->nv_name = i == 0 ? name : intern(buf);
+ p->ll_name = i == 0 ? name : intern(buf);
}
return vals;
}
Index: src/usr.bin/config/lint.c
diff -u src/usr.bin/config/lint.c:1.9 src/usr.bin/config/lint.c:1.10
--- src/usr.bin/config/lint.c:1.9 Sun Mar 11 07:32:41 2012
+++ src/usr.bin/config/lint.c Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.c,v 1.9 2012/03/11 07:32:41 dholland Exp $ */
+/* $NetBSD: lint.c,v 1.10 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 2007 The NetBSD Foundation.
@@ -101,7 +101,8 @@ emit_options()
static void
do_emit_instances(struct devbase *d, struct attr *at)
{
- struct nvlist *nv, *nv1;
+ struct nvlist *nv1;
+ struct loclist *ll;
struct attrlist *al;
struct attr *a;
struct deva *da;
@@ -130,10 +131,10 @@ do_emit_instances(struct devbase *d, str
else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
printf("%s0\tat\t%s?", d->d_name, at->a_name);
- for (nv = at->a_locs; nv != NULL; nv = nv->nv_next) {
- if (nv->nv_num == 0)
- printf(" %s %c", nv->nv_name,
- nv->nv_str ? '?' : '0');
+ for (ll = at->a_locs; ll != NULL; ll = ll->ll_next) {
+ if (ll->ll_num == 0)
+ printf(" %s %c", ll->ll_name,
+ ll->ll_string ? '?' : '0');
}
printf("\n");
Index: src/usr.bin/config/sem.h
diff -u src/usr.bin/config/sem.h:1.9 src/usr.bin/config/sem.h:1.10
--- src/usr.bin/config/sem.h:1.9 Sun Mar 11 08:21:53 2012
+++ src/usr.bin/config/sem.h Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.h,v 1.9 2012/03/11 08:21:53 dholland Exp $ */
+/* $NetBSD: sem.h,v 1.10 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -46,8 +46,8 @@ void setversion(int);
void setdefmaxusers(int, int, int);
void setmaxusers(int);
void setident(const char *);
-int defattr(const char *, struct nvlist *, struct attrlist *, int);
-void defdev(struct devbase *, struct nvlist *, struct attrlist *, int);
+int defattr(const char *, struct loclist *, struct attrlist *, int);
+void defdev(struct devbase *, struct loclist *, struct attrlist *, int);
void defdevattach(struct deva *, struct devbase *, struct nvlist *,
struct attrlist *);
struct devbase *getdevbase(const char *);
@@ -60,7 +60,7 @@ void addconf(struct config *);
void setconf(struct nvlist **, const char *, struct nvlist *);
void delconf(const char *);
void setfstype(const char **, const char *);
-void adddev(const char *, const char *, struct nvlist *, int);
+void adddev(const char *, const char *, struct loclist *, int);
void deldevi(const char *, const char *);
void deldeva(const char *);
void deldev(const char *);
Index: src/usr.bin/config/mkheaders.c
diff -u src/usr.bin/config/mkheaders.c:1.18 src/usr.bin/config/mkheaders.c:1.19
--- src/usr.bin/config/mkheaders.c:1.18 Mon Mar 22 14:40:54 2010
+++ src/usr.bin/config/mkheaders.c Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: mkheaders.c,v 1.18 2010/03/22 14:40:54 pooka Exp $ */
+/* $NetBSD: mkheaders.c,v 1.19 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -298,7 +298,7 @@ static int
locators_print(const char *name, void *value, void *arg)
{
struct attr *a;
- struct nvlist *nv;
+ struct loclist *ll;
int i;
char *locdup, *namedup;
char *cp;
@@ -316,24 +316,24 @@ locators_print(const char *name, void *v
for (cp = locdup; *cp; cp++)
if (islower((unsigned char)*cp))
*cp = toupper((unsigned char)*cp);
- for (i = 0, nv = a->a_locs; nv; nv = nv->nv_next, i++) {
- if (strchr(nv->nv_name, ' ') != NULL ||
- strchr(nv->nv_name, '\t') != NULL)
+ for (i = 0, ll = a->a_locs; ll; ll = ll->ll_next, i++) {
+ if (strchr(ll->ll_name, ' ') != NULL ||
+ strchr(ll->ll_name, '\t') != NULL)
/*
* name contains a space; we can't generate
* usable defines, so ignore it.
*/
continue;
- namedup = estrdup(nv->nv_name);
+ namedup = estrdup(ll->ll_name);
for (cp = namedup; *cp; cp++)
if (islower((unsigned char)*cp))
*cp = toupper((unsigned char)*cp);
else if (*cp == ARRCHR)
*cp = '_';
fprintf(fp, "#define %sCF_%s %d\n", locdup, namedup, i);
- if (nv->nv_str != NULL)
+ if (ll->ll_string != NULL)
fprintf(fp, "#define %sCF_%s_DEFAULT %s\n",
- locdup, namedup, nv->nv_str);
+ locdup, namedup, ll->ll_string);
free(namedup);
}
/* assert(i == a->a_loclen) */
Index: src/usr.bin/config/mkioconf.c
diff -u src/usr.bin/config/mkioconf.c:1.20 src/usr.bin/config/mkioconf.c:1.21
--- src/usr.bin/config/mkioconf.c:1.20 Sun Mar 11 07:32:41 2012
+++ src/usr.bin/config/mkioconf.c Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: mkioconf.c,v 1.20 2012/03/11 07:32:41 dholland Exp $ */
+/* $NetBSD: mkioconf.c,v 1.21 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -168,7 +168,7 @@ static int
cf_locators_print(const char *name, void *value, void *arg)
{
struct attr *a;
- struct nvlist *nv;
+ struct loclist *ll;
FILE *fp = arg;
a = value;
@@ -180,11 +180,11 @@ cf_locators_print(const char *name, void
"static const struct cfiattrdata %scf_iattrdata = {\n",
name);
fprintf(fp, "\t\"%s\", %d,\n\t{\n", name, a->a_loclen);
- for (nv = a->a_locs; nv; nv = nv->nv_next)
+ for (ll = a->a_locs; ll; ll = ll->ll_next)
fprintf(fp, "\t\t{ \"%s\", \"%s\", %s },\n",
- nv->nv_name,
- (nv->nv_str ? nv->nv_str : "NULL"),
- (nv->nv_str ? nv->nv_str : "0"));
+ ll->ll_name,
+ (ll->ll_string ? ll->ll_string : "NULL"),
+ (ll->ll_string ? ll->ll_string : "0"));
fprintf(fp, "\t}\n};\n");
} else {
fprintf(fp,
@@ -363,7 +363,7 @@ emitcfdata(FILE *fp)
struct pspec *ps;
int unit, v;
const char *state, *basename, *attachment;
- struct nvlist *nv;
+ struct loclist *ll;
struct attr *a;
const char *loc;
char locbuf[20];
@@ -394,16 +394,16 @@ emitcfdata(FILE *fp)
}
a = ps->p_iattr;
- for (nv = a->a_locs, v = 0; nv != NULL;
- nv = nv->nv_next, v++) {
- if (ARRNAME(nv->nv_name, lastname)) {
+ for (ll = a->a_locs, v = 0; ll != NULL;
+ ll = ll->ll_next, v++) {
+ if (ARRNAME(ll->ll_name, lastname)) {
fprintf(fp, " %s %s",
- nv->nv_name, i->i_locs[v]);
+ ll->ll_name, i->i_locs[v]);
} else {
fprintf(fp, " %s %s",
- nv->nv_name,
+ ll->ll_name,
i->i_locs[v]);
- lastname = nv->nv_name;
+ lastname = ll->ll_name;
}
}
} else {
Index: src/usr.bin/config/sem.c
diff -u src/usr.bin/config/sem.c:1.40 src/usr.bin/config/sem.c:1.41
--- src/usr.bin/config/sem.c:1.40 Sun Mar 11 08:21:53 2012
+++ src/usr.bin/config/sem.c Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.40 2012/03/11 08:21:53 dholland Exp $ */
+/* $NetBSD: sem.c,v 1.41 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -82,7 +82,7 @@ static const char *concat(const char *,
static char *extend(char *, const char *);
static int split(const char *, size_t, char *, size_t, int *);
static void selectbase(struct devbase *, struct deva *);
-static const char **fixloc(const char *, struct attr *, struct nvlist *);
+static const char **fixloc(const char *, struct attr *, struct loclist *);
static const char *makedevstr(devmajor_t, devminor_t);
static const char *major2name(devmajor_t);
static devmajor_t dev2major(struct devbase *);
@@ -194,12 +194,12 @@ setident(const char *i)
* all locator lists include a dummy head node, which we discard here.
*/
int
-defattr(const char *name, struct nvlist *locs, struct attrlist *deps,
+defattr(const char *name, struct loclist *locs, struct attrlist *deps,
int devclass)
{
struct attr *a, *dep;
struct attrlist *al;
- struct nvlist *nv;
+ struct loclist *ll;
int len;
if (locs != NULL && devclass)
@@ -225,15 +225,17 @@ defattr(const char *name, struct nvlist
if (ht_insert(attrtab, name, a)) {
free(a);
cfgerror("attribute `%s' already defined", name);
- nvfreel(locs);
+ loclist_destroy(locs);
return (1);
}
a->a_name = name;
if (locs != NULL) {
a->a_iattr = 1;
- a->a_locs = locs->nv_next;
- nvfree(locs);
+ /* unwrap */
+ a->a_locs = locs->ll_next;
+ locs->ll_next = NULL;
+ loclist_destroy(locs);
} else {
a->a_iattr = 0;
a->a_locs = NULL;
@@ -257,7 +259,7 @@ defattr(const char *name, struct nvlist
} else
a->a_devclass = NULL;
len = 0;
- for (nv = a->a_locs; nv != NULL; nv = nv->nv_next)
+ for (ll = a->a_locs; ll != NULL; ll = ll->ll_next)
len++;
a->a_loclen = len;
a->a_devs = NULL;
@@ -322,10 +324,10 @@ addtoattr(struct nvlist *l, struct devba
* attribute and/or refer to existing attributes.
*/
void
-defdev(struct devbase *dev, struct nvlist *loclist, struct attrlist *attrs,
+defdev(struct devbase *dev, struct loclist *loclist, struct attrlist *attrs,
int ispseudo)
{
- struct nvlist *nv;
+ struct loclist *ll;
struct attrlist *al;
struct attr *a;
@@ -347,9 +349,9 @@ defdev(struct devbase *dev, struct nvlis
* (where you can plug in a foo-bus extender to a foo-bus).
*/
if (loclist != NULL) {
- nv = loclist;
+ ll = loclist;
loclist = NULL; /* defattr disposes of them for us */
- if (defattr(dev->d_name, nv, NULL, 0))
+ if (defattr(dev->d_name, ll, NULL, 0))
goto bad;
attrs = attrlist_cons(attrs, getattr(dev->d_name));
/* This used to be stored but was never used */
@@ -407,7 +409,7 @@ defdev(struct devbase *dev, struct nvlis
}
return;
bad:
- nvfreel(loclist);
+ loclist_destroy(loclist);
attrlist_destroyall(attrs);
}
@@ -936,7 +938,7 @@ newdevi(const char *name, int unit, stru
* another device instead) plus unit number.
*/
void
-adddev(const char *name, const char *at, struct nvlist *loclist, int flags)
+adddev(const char *name, const char *at, struct loclist *loclist, int flags)
{
struct devi *i; /* the new instance */
struct pspec *p; /* and its pspec */
@@ -1076,7 +1078,7 @@ adddev(const char *name, const char *at,
/* all done, fall into ... */
bad:
- nvfreel(loclist);
+ loclist_destroy(loclist);
return;
}
@@ -1818,9 +1820,9 @@ extend(char *p, const char *name)
* given as "?" and have defaults. Return 0 on success.
*/
static const char **
-fixloc(const char *name, struct attr *attr, struct nvlist *got)
+fixloc(const char *name, struct attr *attr, struct loclist *got)
{
- struct nvlist *m, *n;
+ struct loclist *m, *n;
int ord;
const char **lp;
int nmissing, nextra, nnodefault;
@@ -1837,23 +1839,23 @@ fixloc(const char *name, struct attr *at
lp = nullvec;
else
lp = emalloc((attr->a_loclen + 1) * sizeof(const char *));
- for (n = got; n != NULL; n = n->nv_next)
- n->nv_num = -1;
+ for (n = got; n != NULL; n = n->ll_next)
+ n->ll_num = -1;
nmissing = 0;
mp = missing;
/* yes, this is O(mn), but m and n should be small */
- for (ord = 0, m = attr->a_locs; m != NULL; m = m->nv_next, ord++) {
- for (n = got; n != NULL; n = n->nv_next) {
- if (n->nv_name == m->nv_name) {
- n->nv_num = ord;
+ for (ord = 0, m = attr->a_locs; m != NULL; m = m->ll_next, ord++) {
+ for (n = got; n != NULL; n = n->ll_next) {
+ if (n->ll_name == m->ll_name) {
+ n->ll_num = ord;
break;
}
}
- if (n == NULL && m->nv_num == 0) {
+ if (n == NULL && m->ll_num == 0) {
nmissing++;
- mp = extend(mp, m->nv_name);
+ mp = extend(mp, m->ll_name);
}
- lp[ord] = m->nv_str;
+ lp[ord] = m->ll_string;
}
if (ord != attr->a_loclen)
panic("fixloc");
@@ -1862,17 +1864,17 @@ fixloc(const char *name, struct attr *at
ep = extra;
nnodefault = 0;
ndp = nodefault;
- for (n = got; n != NULL; n = n->nv_next) {
- if (n->nv_num >= 0) {
- if (n->nv_str != NULL)
- lp[n->nv_num] = n->nv_str;
- else if (lp[n->nv_num] == NULL) {
+ for (n = got; n != NULL; n = n->ll_next) {
+ if (n->ll_num >= 0) {
+ if (n->ll_string != NULL)
+ lp[n->ll_num] = n->ll_string;
+ else if (lp[n->ll_num] == NULL) {
nnodefault++;
- ndp = extend(ndp, n->nv_name);
+ ndp = extend(ndp, n->ll_name);
}
} else {
nextra++;
- ep = extend(ep, n->nv_name);
+ ep = extend(ep, n->ll_name);
}
}
if (nextra) {
Index: src/usr.bin/config/util.c
diff -u src/usr.bin/config/util.c:1.12 src/usr.bin/config/util.c:1.13
--- src/usr.bin/config/util.c:1.12 Sun Mar 11 20:02:55 2012
+++ src/usr.bin/config/util.c Sun Mar 11 21:16:08 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.12 2012/03/11 20:02:55 dholland Exp $ */
+/* $NetBSD: util.c,v 1.13 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -205,6 +205,36 @@ nvcat(struct nvlist *nv1, struct nvlist
}
/*
+ * Locator lists
+ */
+
+struct loclist *
+loclist_create(const char *name, const char *string, long long num)
+{
+ struct loclist *ll;
+
+ ll = emalloc(sizeof(*ll));
+ ll->ll_name = name;
+ ll->ll_string = string;
+ ll->ll_num = num;
+ ll->ll_next = NULL;
+ return ll;
+}
+
+void
+loclist_destroy(struct loclist *ll)
+{
+ struct loclist *next;
+
+ while (ll != NULL) {
+ next = ll->ll_next;
+ ll->ll_next = NULL;
+ free(ll);
+ ll = next;
+ }
+}
+
+/*
* Attribute lists
*/