diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1997-08-07 10:22:28 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1997-08-07 10:22:28 +0000 |
commit | b67e43dd2278ca8b74e101b183394a9ecd6d27bb (patch) | |
tree | 20b2ec585464392c046d363f8c9a2fe29e8db5c5 /usr.sbin | |
parent | ec124f7a05558ad9de99cbeeb806a7b270b22ce8 (diff) |
cf_locnames support, from NetBSD (jtk, according to the RCSids).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/config/config.h | 8 | ||||
-rw-r--r-- | usr.sbin/config/hash.c | 28 | ||||
-rw-r--r-- | usr.sbin/config/mkheaders.c | 132 | ||||
-rw-r--r-- | usr.sbin/config/mkioconf.c | 46 | ||||
-rw-r--r-- | usr.sbin/config/sem.c | 5 |
5 files changed, 204 insertions, 15 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 252e054f438..36e5a1ff488 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -1,5 +1,5 @@ -/* $OpenBSD: config.h,v 1.9 1997/07/25 20:12:10 mickey Exp $ */ -/* $NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej Exp $ */ +/* $OpenBSD: config.h,v 1.10 1997/08/07 10:22:24 downsj Exp $ */ +/* $NetBSD: config.h,v 1.31 1997/03/14 00:14:09 jtk Exp $ */ /* * Copyright (c) 1992, 1993 @@ -285,6 +285,8 @@ struct hashtab *selecttab; /* selects things that are "optional foo" */ struct hashtab *needcnttab; /* retains names marked "needs-count" */ struct hashtab *opttab; /* table of configured options */ struct hashtab *defopttab; /* options that have been "defopt"'d */ +struct hashtab *attrtab; /* attributes (locators, etc.) */ + struct devbase *allbases; /* list of all devbase structures */ struct deva *alldevas; /* list of all devbase attachment structures */ struct config *allcf; /* list of configured kernels */ @@ -321,6 +323,8 @@ int ht_insrep __P((struct hashtab *, const char *, void *, int)); void *ht_lookup __P((struct hashtab *, const char *)); void initintern __P((void)); const char *intern __P((const char *)); +typedef int (*ht_callback) __P((const char *, void *, void *)); +int ht_enumerate __P((struct hashtab *, ht_callback, void *)); /* main.c */ void addoption __P((const char *name, const char *value)); diff --git a/usr.sbin/config/hash.c b/usr.sbin/config/hash.c index bdff477855a..661cfea2d92 100644 --- a/usr.sbin/config/hash.c +++ b/usr.sbin/config/hash.c @@ -1,5 +1,5 @@ -/* $OpenBSD: hash.c,v 1.4 1997/01/18 02:24:15 briggs Exp $ */ -/* $NetBSD: hash.c,v 1.4 1996/11/07 22:59:43 gwr Exp $ */ +/* $OpenBSD: hash.c,v 1.5 1997/08/07 10:22:25 downsj Exp $ */ +/* $NetBSD: hash.c,v 1.5 1997/03/14 00:14:12 jtk Exp $ */ /* * Copyright (c) 1992, 1993 @@ -293,3 +293,27 @@ ht_lookup(ht, nam) return (hp->h_value); return (NULL); } + +/* + * first parameter to callback is the entry name from the hash table + * second parameter is the value from the hash table + * third argument is passed through from the "arg" parameter to ht_enumerate() + */ + +int +ht_enumerate(ht, cbfunc, arg) + struct hashtab *ht; + ht_callback cbfunc; + void *arg; +{ + struct hashent *hp, **hpp; + register u_int i; + int rval = 0; + + for (i = 0; i < ht->ht_size; i++) { + hpp = &ht->ht_tab[i]; + for (; (hp = *hpp) != NULL; hpp = &hp->h_next) + rval += (*cbfunc)(hp->h_name, hp->h_value, arg); + } + return rval; +} diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c index 2f2b61487af..902c17ca79d 100644 --- a/usr.sbin/config/mkheaders.c +++ b/usr.sbin/config/mkheaders.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mkheaders.c,v 1.6 1997/07/06 04:07:10 downsj Exp $ */ -/* $NetBSD: mkheaders.c,v 1.12 1997/02/02 21:12:34 thorpej Exp $ */ +/* $OpenBSD: mkheaders.c,v 1.7 1997/08/07 10:22:26 downsj Exp $ */ +/* $NetBSD: mkheaders.c,v 1.15 1997/07/18 11:27:37 jtk Exp $ */ /* * Copyright (c) 1992, 1993 @@ -54,10 +54,13 @@ #include "config.h" static int emitcnt __P((struct nvlist *)); +static int emitlocs __P((void)); static int emitopt __P((struct nvlist *)); static int err __P((const char *, char *, FILE *)); +static int locators_print __P((const char *, void *, void *)); static char *cntname __P((const char *)); + /* * Make headers containing counts, as needed. */ @@ -79,6 +82,9 @@ mkheaders() if (emitopt(nv)) return (1); + if (emitlocs()) + return (1); + return (0); } @@ -183,6 +189,128 @@ writeit: return (0); } +/* + * A callback function for walking the attribute hash table. + * Emit CPP definitions of manifest constants for the locators on the + * "name" attribute node (passed as the "value" parameter). + */ +static int +locators_print(name, value, arg) + const char *name; + void *value; + void *arg; +{ + struct attr *a; + register struct nvlist *nv; + register int i; + char *locdup, *namedup; + register char *cp; + FILE *fp = arg; + + a = value; + if (a->a_locs) { + if (strchr(name, ' ') != NULL || strchr(name, '\t') != NULL) + /* + * name contains a space; we can't generate + * usable defines, so ignore it. + */ + return 0; + locdup = strdup(name); + for (cp = locdup; *cp; cp++) + if (islower(*cp)) + *cp = toupper(*cp); + if (fprintf(fp, "extern const char *%scf_locnames[];\n", + name) < 0) + return 1; + 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) + /* + * name contains a space; we can't generate + * usable defines, so ignore it. + */ + continue; + namedup = strdup(nv->nv_name); + for (cp = namedup; *cp; cp++) + if (islower(*cp)) + *cp = toupper(*cp); + if (fprintf(fp, "#define %sCF_%s %d\n", + locdup, namedup, i) < 0) + return 1; + if (nv->nv_str && + fprintf(fp, + "#define %sCF_%s_DEFAULT %s\n", + locdup, namedup, nv->nv_str) < 0) + return 1; + free(namedup); + } + free(locdup); + } + return 0; +} + +/* + * Build the "locators.h" file with manifest constants for all potential + * locators in the configuration. Do this by enumerating the attribute + * hash table and emitting all the locators for each attribute. + */ +static int +emitlocs() +{ + struct nvlist *option; + char nbuf[BUFSIZ], obuf[BUFSIZ]; + char *tfname, *nfname; + const char *n; + int count, rval; + FILE *tfp = NULL, *nfp = NULL; + + tfname = "tmp_locators.h"; + if ((tfp = fopen(tfname, "w")) == NULL) { + (void)fprintf(stderr, "config: cannot write %s: %s\n", + tfname, strerror(errno)); + return (1); + } + + rval = ht_enumerate(attrtab, locators_print, tfp); + if (fclose(tfp) == EOF) + return(err("clos", tfname, NULL)); + + if ((tfp = fopen(tfname, "r")) == NULL) + goto moveit; + + /* + * Compare the new file to the old. + */ + nfname = "locators.h"; + if ((nfp = fopen(nfname, "r")) == NULL) + goto moveit; + + while (fgets(obuf, sizeof(obuf), tfp) != NULL) { + if (fgets(nbuf, sizeof(nbuf), nfp) == NULL) + goto moveit; + + if (strcmp(obuf, nbuf) != 0) + goto moveit; + } + (void) fclose(nfp); + (void) fclose(tfp); + if (remove(tfname) == -1) + return(err("remov", tfname, NULL)); + return (0); + +moveit: + /* + * They're different, or the file doesn't exist. + */ + if (nfp) + (void) fclose(nfp); + if (tfp) + (void) fclose(tfp); + if (rename(tfname, nfname) == -1) + return(err("renam", tfname, NULL)); + return (0); +} + static int err(what, fname, fp) const char *what; diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c index a2988b003c0..8913ff725f8 100644 --- a/usr.sbin/config/mkioconf.c +++ b/usr.sbin/config/mkioconf.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mkioconf.c,v 1.10 1997/07/06 04:07:11 downsj Exp $ */ -/* $NetBSD: mkioconf.c,v 1.41 1996/11/11 14:18:49 mycroft Exp $ */ +/* $OpenBSD: mkioconf.c,v 1.11 1997/08/07 10:22:26 downsj Exp $ */ +/* $NetBSD: mkioconf.c,v 1.43 1997/03/14 22:54:08 jtk Exp $ */ /* * Copyright (c) 1992, 1993 @@ -55,6 +55,7 @@ /* * Make ioconf.c. */ +static int cf_locnames_print __P((const char *, void *, void *)); static int cforder __P((const void *, const void *)); static int emitcfdata __P((FILE *)); static int emitexterns __P((FILE *)); @@ -175,6 +176,34 @@ emitexterns(fp) return (0); } +/* + * Emit an initialized array of character strings describing this + * attribute's locators. + */ +static int +cf_locnames_print(name, value, arg) + const char *name; + void *value; + void *arg; +{ + struct attr *a; + register struct nvlist *nv; + FILE *fp = arg; + + a = value; + if (a->a_locs) { + if (fprintf(fp, "const char *%scf_locnames[] = { ", name) < 0) + return (1); + for (nv = a->a_locs; nv; nv = nv->nv_next) { + if (fprintf(fp, "\"%s\", ", nv->nv_name) < 0) + return (1); + } + if (fprintf(fp, "NULL};\n") < 0) + return (1); + } + return 0; +} + static int emitloc(fp) register FILE *fp; @@ -187,7 +216,10 @@ static int loc[%d] = {", locators.used) < 0) for (i = 0; i < locators.used; i++) if (fprintf(fp, "%s%s,", SEP(i, 8), locators.vec[i]) < 0) return (1); - return (fprintf(fp, "\n};\n") < 0); + if (fprintf(fp, + "\n};\n\nconst char *nullcf_locnames[] = {NULL};\n") < 0) + return (1); + return ht_enumerate(attrtab, cf_locnames_print, fp); } static int nlocnames, maxlocnames = 8; @@ -355,7 +387,8 @@ emitcfdata(fp) #define DSTR FSTATE_DSTAR\n\ \n\ struct cfdata cfdata[] = {\n\ - /* attachment driver unit state loc flags parents nm ivstubs */\n") < 0) + /* attachment driver unit state loc flags parents nm ivstubs\n\ + locnames */\n") < 0) return (1); for (p = packed; (i = *p) != NULL; p++) { /* the description */ @@ -403,11 +436,12 @@ struct cfdata cfdata[] = {\n\ } else loc = "loc"; if (fprintf(fp, "\ - {&%s_ca,%s&%s_cd,%s%2d, %s, %7s, %#4x, pv+%2d, %d, %s%d},\n", + {&%s_ca,%s&%s_cd,%s%2d, %s, %7s, %#4x, pv+%2d, %d, %s%d,\n\ + %scf_locnames},\n", attachment, strlen(attachment) < 6 ? "\t\t" : "\t", basename, strlen(basename) < 3 ? "\t\t" : "\t", unit, state, loc, i->i_cfflags, i->i_pvoff, i->i_locnami, - vs, v) < 0) + vs, v, a->a_locs ? a->a_name : "null") < 0) return (1); } if (fprintf(fp, " {0},\n {0},\n {0},\n {0},\n") < 0) diff --git a/usr.sbin/config/sem.c b/usr.sbin/config/sem.c index 94e667140d2..9f958f45b92 100644 --- a/usr.sbin/config/sem.c +++ b/usr.sbin/config/sem.c @@ -1,5 +1,5 @@ -/* $OpenBSD: sem.c,v 1.9 1997/01/18 02:24:19 briggs Exp $ */ -/* $NetBSD: sem.c,v 1.10 1996/11/11 23:40:11 gwr Exp $ */ +/* $OpenBSD: sem.c,v 1.10 1997/08/07 10:22:27 downsj Exp $ */ +/* $NetBSD: sem.c,v 1.14 1997/03/14 20:43:05 leo Exp $ */ /* * Copyright (c) 1992, 1993 @@ -63,7 +63,6 @@ const char *s_generic; const char *s_nfs; static const char *s_qmark; -static struct hashtab *attrtab; /* for attribute lookup */ static struct hashtab *cfhashtab; /* for config lookup */ static struct hashtab *devitab; /* etc */ |