diff options
author | Jason Downs <downsj@cvs.openbsd.org> | 1997-07-06 03:54:07 +0000 |
---|---|---|
committer | Jason Downs <downsj@cvs.openbsd.org> | 1997-07-06 03:54:07 +0000 |
commit | 23edd72b858f60176cbb3ec7ebd8ab078ecc823c (patch) | |
tree | 1406d7074bf99c30869e74f5e3e7c9921f315d68 /usr.sbin | |
parent | a392bf7c2557809c971d9fcc9e2dd5dbd7665470 (diff) |
Add defopt support, from NetBSD; thorpej (I think, I don't have the commit
message).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/config/config.h | 9 | ||||
-rw-r--r-- | usr.sbin/config/gram.y | 9 | ||||
-rw-r--r-- | usr.sbin/config/main.c | 40 | ||||
-rw-r--r-- | usr.sbin/config/mkheaders.c | 70 | ||||
-rw-r--r-- | usr.sbin/config/mkmakefile.c | 6 | ||||
-rw-r--r-- | usr.sbin/config/scan.l | 5 |
6 files changed, 122 insertions, 17 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index e97dc9c6d45..79c6bd62053 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -1,5 +1,5 @@ -/* $OpenBSD: config.h,v 1.7 1997/01/18 02:24:13 briggs Exp $ */ -/* $NetBSD: config.h,v 1.28 1996/11/11 23:40:09 gwr Exp $ */ +/* $OpenBSD: config.h,v 1.8 1997/07/06 03:54:04 downsj Exp $ */ +/* $NetBSD: config.h,v 1.30 1997/02/02 21:12:30 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -277,12 +277,14 @@ int maxmaxusers; /* default "maxusers" parameter */ int maxusers; /* configuration's "maxusers" parameter */ int maxpartitions; /* configuration's "maxpartitions" parameter */ struct nvlist *options; /* options */ +struct nvlist *defoptions; /* "defopt"'d options */ struct nvlist *mkoptions; /* makeoptions */ struct hashtab *devbasetab; /* devbase lookup */ struct hashtab *devatab; /* devbase attachment lookup */ 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 devbase *allbases; /* list of all devbase structures */ struct deva *alldevas; /* list of all devbase attachment structures */ struct config *allcf; /* list of configured kernels */ @@ -323,6 +325,7 @@ const char *intern __P((const char *)); /* main.c */ void addoption __P((const char *name, const char *value)); void addmkoption __P((const char *name, const char *value)); +void defoption __P((const char *name)); int devbase_has_instances __P((struct devbase *, int)); int deva_has_instances __P((struct deva *, int)); void setupdirs __P((void)); diff --git a/usr.sbin/config/gram.y b/usr.sbin/config/gram.y index 1f98ff9a992..eeb0c8c56ba 100644 --- a/usr.sbin/config/gram.y +++ b/usr.sbin/config/gram.y @@ -1,6 +1,6 @@ %{ -/* $OpenBSD: gram.y,v 1.7 1997/01/18 02:24:14 briggs Exp $ */ -/* $NetBSD: gram.y,v 1.12 1996/11/11 23:54:17 gwr Exp $ */ +/* $OpenBSD: gram.y,v 1.8 1997/07/06 03:54:04 downsj Exp $ */ +/* $NetBSD: gram.y,v 1.14 1997/02/02 21:12:32 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -100,8 +100,8 @@ static void check_maxpart __P((void)); int val; } -%token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEVICE DISABLE DUMPS -%token ENDFILE XFILE FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS MAXUSERS +%token AND AT ATTACH BUILD COMPILE_WITH CONFIG DEFINE DEFOPT DEVICE DISABLE +%token DUMPS ENDFILE XFILE FLAGS INCLUDE XMACHINE MAJOR MAKEOPTIONS MAXUSERS %token MAXPARTITIONS MINOR ON OPTIONS PSEUDO_DEVICE ROOT SOURCE SWAP WITH %token NEEDS_COUNT NEEDS_FLAG %token <val> NUMBER @@ -221,6 +221,7 @@ one_def: file | include | DEFINE WORD interface_opt { (void)defattr($2, $3); } | + DEFOPT WORD { defoption($2); } | DEVICE devbase interface_opt attrs_opt { defdev($2, 0, $3, $4); } | ATTACH devbase AT atlist devattach_opt attrs_opt diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index ada1a03ce6c..dbc9c7ae811 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.13 1997/04/14 02:24:04 deraadt Exp $ */ -/* $NetBSD: main.c,v 1.18 1996/08/31 20:58:20 mycroft Exp $ */ +/* $OpenBSD: main.c,v 1.14 1997/07/06 03:54:05 downsj Exp $ */ +/* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -68,9 +68,9 @@ int yyparse __P((void)); extern char *optarg; extern int optind; -static struct hashtab *opttab; static struct hashtab *mkopttab; static struct nvlist **nextopt; +static struct nvlist **nextdefopt; static struct nvlist **nextmkopt; static __dead void stop __P((void)); @@ -166,8 +166,10 @@ usage: needcnttab = ht_new(); opttab = ht_new(); mkopttab = ht_new(); + defopttab = ht_new(); nextopt = &options; nextmkopt = &mkoptions; + nextdefopt = &defoptions; /* * Handle profiling (must do this before we try to create any @@ -279,6 +281,38 @@ stop() } /* + * Define a standard option, for which a header file will be generated. + */ +void +defoption(name) + const char *name; +{ + register const char *n; + register char *p, c; + char low[500]; + + /* + * Convert to lower case. The header file name will be + * in lower case, so we store the lower case version in + * the hash table to detect option name collisions. The + * original string will be stored in the nvlist for use + * in the header file. + */ + for (n = name, p = low; (c = *n) != '\0'; n++) + *p++ = isupper(c) ? tolower(c) : c; + *p = 0; + + n = intern(low); + (void)do_option(defopttab, &nextdefopt, n, name, "defopt"); + + /* + * Insert a verbatum copy of the option name, as well, + * to speed lookups when creating the Makefile. + */ + (void)ht_insert(defopttab, name, (void *)name); +} + +/* * Add an option from "options FOO". Note that this selects things that * are "optional foo". */ diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c index eb327da7a17..18e532deca4 100644 --- a/usr.sbin/config/mkheaders.c +++ b/usr.sbin/config/mkheaders.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mkheaders.c,v 1.4 1996/10/23 22:37:54 niklas Exp $ */ -/* $NetBSD: mkheaders.c,v 1.11 1996/08/31 20:58:22 mycroft Exp $ */ +/* $OpenBSD: mkheaders.c,v 1.5 1997/07/06 03:54:05 downsj Exp $ */ +/* $NetBSD: mkheaders.c,v 1.12 1997/02/02 21:12:34 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -54,6 +54,7 @@ #include "config.h" static int emitcnt __P((struct nvlist *)); +static int emitopt __P((struct nvlist *)); static int err __P((const char *, char *, FILE *)); static char *cntname __P((const char *)); @@ -64,6 +65,7 @@ int mkheaders() { register struct files *fi; + register struct nvlist *nv; for (fi = allfiles; fi != NULL; fi = fi->fi_next) { if (fi->fi_flags & FI_HIDDEN) @@ -72,6 +74,11 @@ mkheaders() emitcnt(fi->fi_optf)) return (1); } + + for (nv = defoptions; nv != NULL; nv = nv->nv_next) + if (emitopt(nv)) + return (1); + return (0); } @@ -120,6 +127,64 @@ writeit: } static int +emitopt(nv) + struct nvlist *nv; +{ + struct nvlist *option; + char new_contents[BUFSIZ], buf[BUFSIZ]; + char fname[BUFSIZ], *p, c; + const char *n; + int nlines; + FILE *fp; + + /* + * Generate the new contents of the file. + */ + p = new_contents; + if ((option = ht_lookup(opttab, nv->nv_str)) == NULL) + p += sprintf(p, "/* option `%s' not defined */\n", + nv->nv_str); + else { + p += sprintf(p, "#define\t%s", option->nv_name); + if (option->nv_str != NULL) + p += sprintf(p, "\t%s", option->nv_str); + p += sprintf(p, "\n"); + } + + /* + * Compare the new file to the old. + */ + sprintf(fname, "opt_%s.h", nv->nv_name); + if ((fp = fopen(fname, "r")) == NULL) + goto writeit; + nlines = 0; + while (fgets(buf, sizeof(buf), fp) != NULL) { + if (++nlines != 1 || + strcmp(buf, new_contents) != 0) + goto writeit; + } + if (ferror(fp)) + return (err("read", fname, fp)); + (void)fclose(fp); + if (nlines == 1) + return (0); +writeit: + /* + * They're different, or the file doesn't exist. + */ + if ((fp = fopen(fname, "w")) == NULL) { + (void)fprintf(stderr, "config: cannot write %s: %s\n", + fname, strerror(errno)); + return (1); + } + if (fprintf(fp, "%s", new_contents) < 0) + return (err("writ", fname, fp)); + if (fclose(fp)) + return (err("writ", fname, fp)); + return (0); +} + +static int err(what, fname, fp) const char *what; char *fname; @@ -130,7 +195,6 @@ err(what, fname, fp) what, fname, strerror(errno)); if (fp) (void)fclose(fp); - free(fname); return (1); } diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index c6278971a22..a5b34ee6c18 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mkmakefile.c,v 1.5 1996/10/23 22:37:56 niklas Exp $ */ -/* $NetBSD: mkmakefile.c,v 1.32 1996/09/23 05:04:23 ghudson Exp $ */ +/* $OpenBSD: mkmakefile.c,v 1.6 1997/07/06 03:54:06 downsj Exp $ */ +/* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -185,6 +185,8 @@ emitdefs(fp) return (1); sp = ""; for (nv = options; nv != NULL; nv = nv->nv_next) { + if (ht_lookup(defopttab, nv->nv_name) != NULL) + continue; if (fprintf(fp, "%s-D%s", sp, nv->nv_name) < 0) return 1; if (nv->nv_str) diff --git a/usr.sbin/config/scan.l b/usr.sbin/config/scan.l index b5779841ea7..147190e89dc 100644 --- a/usr.sbin/config/scan.l +++ b/usr.sbin/config/scan.l @@ -1,6 +1,6 @@ %{ -/* $OpenBSD: scan.l,v 1.7 1997/01/18 02:24:18 briggs Exp $ */ -/* $NetBSD: scan.l,v 1.11 1996/11/13 18:42:18 gwr Exp $ */ +/* $OpenBSD: scan.l,v 1.8 1997/07/06 03:54:06 downsj Exp $ */ +/* $NetBSD: scan.l,v 1.13 1997/02/02 21:12:37 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -90,6 +90,7 @@ build return BUILD; compile-with return COMPILE_WITH; config return CONFIG; define return DEFINE; +defopt return DEFOPT; device return DEVICE; disable return DISABLE; dumps return DUMPS; |