Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/config Functionality improvements:



details:   https://anonhg.NetBSD.org/src/rev/84d1aab7d0c3
branches:  trunk
changeset: 532325:84d1aab7d0c3
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Jun 05 10:56:17 2002 +0000

description:
Functionality improvements:
- Add `no' keyword, which can be used in the following ways:
        no file-system SOMEFS
        no makeoptions FOO
        no options OPT1[,OPT2[,...]]
        no pseudo-device somepseudo
  This turns off a previous file-system/makeoptions/options/pseudo-device
  entry for the same item.
  Grammar support for 'no device DEV at ATTACH' added, but not
  implemented yet.

Code changes:
- Convert many simple lists to TAILQs
- Convert prefix to SLIST
- Remove argument names from prototypes.
- Don't bother with custom alloc code for hashtables; just use emalloc()
  like everything else.
- Implement ht_remove(), to remove an entry from a hash table.
  Add removed entries to a freelist for later reuse.
- Don't selectbase() devices and pseudo-devices at definition time; instead
  do it at one pass after the config file has been parsed in fixdevis().
- Rename nvhead to nvfreelist; a more apt name...
- Minor code cleanups.

diffstat:

 usr.sbin/config/defs.h       |   66 ++++++++++---------
 usr.sbin/config/files.c      |   37 +++++-----
 usr.sbin/config/gram.y       |   43 ++++++++++--
 usr.sbin/config/hash.c       |  143 ++++++++++++++++++++----------------------
 usr.sbin/config/main.c       |  102 +++++++++++++++++++++++++++--
 usr.sbin/config/mkheaders.c  |    6 +-
 usr.sbin/config/mkioconf.c   |   13 ++-
 usr.sbin/config/mkmakefile.c |   22 +++---
 usr.sbin/config/mkswap.c     |    7 +-
 usr.sbin/config/pack.c       |   13 ++-
 usr.sbin/config/scan.l       |    3 +-
 usr.sbin/config/sem.c        |  146 ++++++++++++++++++++++++++++++------------
 usr.sbin/config/sem.h        |   24 +++---
 usr.sbin/config/util.c       |   52 +++++++-------
 14 files changed, 423 insertions(+), 254 deletions(-)

diffs (truncated from 1597 to 300 lines):

diff -r 9afce4cbc5fc -r 84d1aab7d0c3 usr.sbin/config/defs.h
--- a/usr.sbin/config/defs.h    Wed Jun 05 10:20:46 2002 +0000
+++ b/usr.sbin/config/defs.h    Wed Jun 05 10:56:17 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.3 2002/02/12 23:20:11 atatat Exp $  */
+/*     $NetBSD: defs.h,v 1.4 2002/06/05 10:56:17 lukem Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -54,6 +54,7 @@
 
 #include <sys/types.h>
 #include <sys/param.h>
+#include <sys/queue.h>
 
 #if !defined(MAKE_BOOTSTRAP) && defined(BSD)
 #include <sys/cdefs.h>
@@ -120,7 +121,7 @@
  * Kernel configurations.
  */
 struct config {
-       struct  config *cf_next;        /* linked list */
+       TAILQ_ENTRY(config) cf_next;
        const char *cf_name;            /* "vmunix" */
        int     cf_lineno;              /* source line */
        const char *cf_fstype;          /* file system type */
@@ -179,7 +180,7 @@
  */
 struct devbase {
        const char *d_name;             /* e.g., "sd" */
-       struct  devbase *d_next;        /* linked list */
+       TAILQ_ENTRY(devbase) d_next;
        int     d_isdef;                /* set once properly defined */
        int     d_ispseudo;             /* is a pseudo-device */
        int     d_major;                /* used for "root on sd0", e.g. */
@@ -194,7 +195,7 @@
 
 struct deva {
        const char *d_name;             /* name of attachment, e.g. "com_isa" */
-       struct  deva *d_next;           /* linked list */
+       TAILQ_ENTRY(deva) d_next;       /* list of all instances */
        struct  deva *d_bsame;          /* list on same base */
        int     d_isdef;                /* set once properly defined */
        struct  devbase *d_devbase;     /* the base device */
@@ -219,7 +220,7 @@
        const char *i_name;     /* e.g., "sd0" */
        int     i_unit;         /* unit from name, e.g., 0 */
        struct  devbase *i_base;/* e.g., pointer to "sd" base */
-       struct  devi *i_next;   /* list of all instances */
+       TAILQ_ENTRY(devi) i_next; /* list of all instances */
        struct  devi *i_bsame;  /* list on same base */
        struct  devi *i_asame;  /* list on same base attachment */
        struct  devi *i_alias;  /* other aliases of this instance */
@@ -260,7 +261,7 @@
  * contain counts or `need' flags; this is used in mkheaders().
  */
 struct files {
-       struct  files *fi_next; /* linked list */
+       TAILQ_ENTRY(files) fi_next;
        const char *fi_srcfile; /* the name of the "files" file that got us */
        u_short fi_srcline;     /* and the line number */
        u_char  fi_flags;       /* as below */
@@ -284,7 +285,7 @@
  * files (e.g. binary-only device drivers) to be linked in.
  */
 struct objects {
-       struct  objects *oi_next;       /* linked list */
+       TAILQ_ENTRY(objects) oi_next;
        const char *oi_srcfile; /* the name of the "objects" file that got us */
        u_short oi_srcline;     /* and the line number */
        u_char  oi_flags;       /* as below */
@@ -308,8 +309,8 @@
  * the behavior of the source path.
  */
 struct prefix {
-       struct prefix *pf_next; /* next prefix in stack */
-       const char *pf_prefix;  /* the actual prefix */
+       SLIST_ENTRY(prefix)     pf_next;        /* next prefix in stack */
+       const char              *pf_prefix;     /* the actual prefix */
 };
 
 /*
@@ -352,19 +353,19 @@
 struct hashtab *optfiletab;    /* "defopt"'d option .h files */
 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 */
-struct devi *alldevi;          /* list of all instances */
-struct devi *allpseudo;        /* list of all pseudo-devices */
-int    ndevi;                  /* number of devi's (before packing) */
-int    npseudo;                /* number of pseudo's */
+TAILQ_HEAD(, devbase)  allbases;       /* list of all devbase structures */
+TAILQ_HEAD(, deva)     alldevas;       /* list of all devbase attachments */
+TAILQ_HEAD(, config)   allcf;          /* list of configured kernels */
+TAILQ_HEAD(, devi)     alldevi,        /* list of all instances */
+                       allpseudo;      /* list of all pseudo-devices */
+int    ndevi;                          /* number of devi's (before packing) */
 
-struct files *allfiles;        /* list of all kernel source files */
-struct objects *allobjects;    /* list of all kernel object and library
-                                  files */
-struct prefix *prefixes;       /* prefix stack */
-struct prefix *allprefixes;    /* all prefixes used (after popped) */
+TAILQ_HEAD(, files)    allfiles;       /* list of all kernel source files */
+TAILQ_HEAD(, objects)  allobjects;     /* list of all kernel object and
+                                          library files */
+
+SLIST_HEAD(, prefix)   prefixes,       /* prefix stack */
+                       allprefixes;    /* all prefixes used (after popped) */
 
 struct devi **packed;          /* arrayified table for packed devi's */
 int    npacked;                /* size of packed table, <= ndevi */
@@ -391,6 +392,7 @@
 int    ht_insrep(struct hashtab *, const char *, void *, int);
 #define        ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
 #define        ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
+int    ht_remove(struct hashtab *, const char *);
 void   *ht_lookup(struct hashtab *, const char *);
 void   initintern(void);
 const char *intern(const char *);
@@ -398,18 +400,18 @@
 int    ht_enumerate(struct hashtab *, ht_callback, void *);
 
 /* main.c */
-void   addoption(const char *name, const char *value);
-void   addfsoption(const char *name);
-void   addmkoption(const char *name, const char *value);
-void   deffilesystem(const char *fname, struct nvlist *fses);
-void   defoption(const char *fname, struct nvlist *opts,
-           struct nvlist *deps);
-void   defflag(const char *fname, struct nvlist *opts,
-           struct nvlist *deps);
-void   defparam(const char *fname, struct nvlist *opts,
-           struct nvlist *deps);
+void   addoption(const char *, const char *);
+void   addfsoption(const char *);
+void   addmkoption(const char *, const char *);
+void   deffilesystem(const char *, struct nvlist *);
+void   defoption(const char *, struct nvlist *, struct nvlist *);
+void   defflag(const char *, struct nvlist *, struct nvlist *);
+void   defparam(const char *, struct nvlist *, struct nvlist *);
+void   deloption(const char *);
+void   delfsoption(const char *);
+void   delmkoption(const char *);
 int    devbase_has_instances(struct devbase *, int);
-struct nvlist * find_declared_option(const char *name);
+struct nvlist * find_declared_option(const char *);
 int    deva_has_instances(struct deva *, int);
 void   setupdirs(void);
 
diff -r 9afce4cbc5fc -r 84d1aab7d0c3 usr.sbin/config/files.c
--- a/usr.sbin/config/files.c   Wed Jun 05 10:20:46 2002 +0000
+++ b/usr.sbin/config/files.c   Wed Jun 05 10:56:17 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.14 2002/01/29 10:20:36 tv Exp $    */
+/*     $NetBSD: files.c,v 1.15 2002/06/05 10:56:18 lukem Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -62,11 +62,8 @@
 static struct hashtab *basetab;                /* file base names */
 static struct hashtab *pathtab;                /* full path names */
 
-static struct files **nextfile;
 static struct files **unchecked;
 
-static struct objects **nextobject;
-
 static int     checkaux(const char *, void *);
 static int     fixcount(const char *, void *);
 static int     fixfsel(const char *, void *);
@@ -81,9 +78,9 @@
 
        basetab = ht_new();
        pathtab = ht_new();
-       nextfile = &allfiles;
-       unchecked = &allfiles;
-       nextobject = &allobjects;
+       TAILQ_INIT(&allfiles);
+       unchecked = &TAILQ_FIRST(&allfiles);
+       TAILQ_INIT(&allobjects);
 }
 
 void
@@ -150,21 +147,20 @@
        }
        memcpy(base, tail, baselen);
        base[baselen] = 0;
-       fi->fi_next = NULL;
        fi->fi_srcfile = yyfile;
        fi->fi_srcline = currentline();
        fi->fi_flags = flags;
        fi->fi_path = path;
        fi->fi_tail = tail;
        fi->fi_base = intern(base);
-       fi->fi_prefix = (prefixes != NULL) ? prefixes->pf_prefix : NULL;
+       fi->fi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
+                       SLIST_FIRST(&prefixes)->pf_prefix;
        fi->fi_optx = optx;
        fi->fi_optf = NULL;
        fi->fi_mkrule = rule;
-       *nextfile = fi;
-       nextfile = &fi->fi_next;
+       TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
        return;
-bad:
+ bad:
        expr_free(optx);
 }
 
@@ -186,16 +182,15 @@
                xerror(oi->oi_srcfile, oi->oi_srcline,
                    "here is the original definition");
        } 
-       oi->oi_next = NULL;
        oi->oi_srcfile = yyfile;
        oi->oi_srcline = currentline();
        oi->oi_flags = flags;
        oi->oi_path = path;
-       oi->oi_prefix = (prefixes != NULL) ? prefixes->pf_prefix : NULL;
+       oi->oi_prefix = SLIST_EMPTY(&prefixes) ? NULL :
+                       SLIST_FIRST(&prefixes)->pf_prefix;
        oi->oi_optx = optx;
        oi->oi_optf = NULL;
-       *nextobject = oi;
-       nextobject = &oi->oi_next;
+       TAILQ_INSERT_TAIL(&allobjects, oi, oi_next);
        return;
 }     
 
@@ -211,11 +206,13 @@
        struct files *fi, *last;
 
        last = NULL;
-       for (fi = *unchecked; fi != NULL; last = fi, fi = fi->fi_next)
+       for (fi = *unchecked; fi != NULL;
+           last = fi, fi = TAILQ_NEXT(fi, fi_next)) {
                if ((fi->fi_flags & FI_NEEDSCOUNT) != 0)
                        (void)expr_eval(fi->fi_optx, checkaux, fi);
+       }
        if (last != NULL)
-               unchecked = &last->fi_next;
+               unchecked = &TAILQ_NEXT(last, fi_next);
 }
 
 /*
@@ -250,7 +247,7 @@
        int err, sel;
 
        err = 0;
-       for (fi = allfiles; fi != NULL; fi = fi->fi_next) {
+       TAILQ_FOREACH(fi, &allfiles, fi_next) {
                /* Skip files that generated counted-device complaints. */
                if (fi->fi_flags & FI_HIDDEN)
                        continue;
@@ -310,7 +307,7 @@
        int err, sel; 
  
        err = 0;
-       for (oi = allobjects; oi != NULL; oi = oi->oi_next) {
+       TAILQ_FOREACH(oi, &allobjects, oi_next) {
                /* Optional: see if it is to be included. */
                if (oi->oi_optx != NULL) {
                        flathead = NULL;
diff -r 9afce4cbc5fc -r 84d1aab7d0c3 usr.sbin/config/gram.y
--- a/usr.sbin/config/gram.y    Wed Jun 05 10:20:46 2002 +0000
+++ b/usr.sbin/config/gram.y    Wed Jun 05 10:56:17 2002 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.32 2002/01/29 10:20:37 tv Exp $     */
+/*     $NetBSD: gram.y,v 1.33 2002/06/05 10:56:18 lukem Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -105,7 +105,7 @@
 %token DEFPARAM DEFFLAG DEFPSEUDO DEVICE DEVCLASS DUMPS ENDFILE XFILE XOBJECT
 %token FILE_SYSTEM FLAGS IDENT INCLUDE XMACHINE MAJOR MAKEOPTIONS
 %token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PREFIX PSEUDO_DEVICE ROOT
-%token SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG
+%token SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG NO
 %token <val> NUMBER
 %token <str> PATHNAME WORD EMPTY
 %token ENDDEFS
@@ -388,17 +388,37 @@
 
 config_spec:
        one_def |
+       NO FILE_SYSTEM no_fs_list |
        FILE_SYSTEM fs_list |
+       NO MAKEOPTIONS no_mkopt_list |
+       MAKEOPTIONS mkopt_list |
+       NO OPTIONS no_opt_list |
        OPTIONS opt_list |
-       MAKEOPTIONS mkopt_list |
        MAXUSERS NUMBER                 { setmaxusers($2); } |
        IDENT WORD                      { setident($2); } |
        CONFIG conf root_spec sysparam_list
                                        { addconf(&conf); } |



Home | Main Index | Thread Index | Old Index