Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/config Implicitly define empty "attribute" for "devi...



details:   https://anonhg.NetBSD.org/src/rev/c55779b45faf
branches:  trunk
changeset: 802950:c55779b45faf
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Fri Oct 10 06:59:38 2014 +0000

description:
Implicitly define empty "attribute" for "device attachment".  Much less
troublesome than "device" and "interface attribute".

diffstat:

 usr.bin/config/sem.c |  45 ++++++++++++++++++++++++++++++++++++++-------
 usr.bin/config/sem.h |   4 +++-
 2 files changed, 41 insertions(+), 8 deletions(-)

diffs (103 lines):

diff -r d96f0e2bd48d -r c55779b45faf usr.bin/config/sem.c
--- a/usr.bin/config/sem.c      Fri Oct 10 06:13:30 2014 +0000
+++ b/usr.bin/config/sem.c      Fri Oct 10 06:59:38 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.c,v 1.49 2014/10/10 06:13:30 uebayasi Exp $        */
+/*     $NetBSD: sem.c,v 1.50 2014/10/10 06:59:38 uebayasi Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -236,23 +236,37 @@
                }
        }
 
-       a = ecalloc(1, sizeof *a);
-       if (ht_insert(attrtab, name, a)) {
-               free(a);
+       a = mkattr(name);
+       if (a == NULL) {
                cfgerror("attribute `%s' already defined", name);
                loclist_destroy(locs);
                return (1);
        }
 
-       a->a_name = name;
        a->a_deps = deps;
-       a->a_expanding = 0;
-       TAILQ_INIT(&a->a_files);
        expandattr(a, NULL);
+       CFGDBG(3, "attr `%s' defined", a->a_name);
 
        return (0);
 }
 
+struct attr *
+mkattr(const char *name)
+{
+       struct attr *a;
+
+       a = ecalloc(1, sizeof *a);
+       if (ht_insert(attrtab, name, a)) {
+               free(a);
+               return NULL;
+       }
+       a->a_name = name;
+       TAILQ_INIT(&a->a_files);
+       CFGDBG(3, "attr `%s' allocated", name);
+
+       return a;
+}
+
 /* "interface attribute" initialization */
 int
 defiattr(const char *name, struct loclist *locs, struct attrlist *deps,
@@ -543,6 +557,12 @@
        deva->d_attrs = attrs;
        deva->d_atlist = atlist;
        deva->d_devbase = dev;
+       CFGDBG(3, "deva `%s' defined", deva->d_name);
+
+       /*
+        * Implicit attribute definition.
+        */
+       refattr(deva->d_name);
 
        /*
         * Turn the `at' list into interface attributes (map each
@@ -644,6 +664,17 @@
 }
 
 /*
+ * Implicit attribute definition.
+ */
+void
+refattr(const char *name)
+{
+
+       if ((ht_lookup(attrtab, name)) == NULL)
+               (void)mkattr(name);
+}
+
+/*
  * Recursively expand an attribute and its dependencies, checking for
  * cycles, and invoking a callback for each attribute found.
  */
diff -r d96f0e2bd48d -r c55779b45faf usr.bin/config/sem.h
--- a/usr.bin/config/sem.h      Fri Oct 10 06:13:30 2014 +0000
+++ b/usr.bin/config/sem.h      Fri Oct 10 06:59:38 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sem.h,v 1.11 2014/10/10 06:13:30 uebayasi Exp $        */
+/*     $NetBSD: sem.h,v 1.12 2014/10/10 06:59:38 uebayasi Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -55,7 +55,9 @@
                             struct attrlist *);
 struct devbase *getdevbase(const char *);
 struct deva    *getdevattach(const char *);
+struct attr    *mkattr(const char *);
 struct attr    *getattr(const char *);
+void           refattr(const char *);
 void           expandattr(struct attr *, void (*)(struct attr *));
 void           selectattr(struct attr *);
 void           setmajor(struct devbase *, int);



Home | Main Index | Thread Index | Old Index