Module Name: src
Committed By: uebayasi
Date: Fri Oct 10 07:48:51 UTC 2014
Modified Files:
src/usr.bin/config: main.c sem.c sem.h
Log Message:
Implicitly define attribute for options.
To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/config/main.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/config/sem.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/config/sem.h
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/main.c
diff -u src/usr.bin/config/main.c:1.59 src/usr.bin/config/main.c:1.60
--- src/usr.bin/config/main.c:1.59 Fri Oct 10 07:08:26 2014
+++ src/usr.bin/config/main.c Fri Oct 10 07:48:50 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.59 2014/10/10 07:08:26 uebayasi Exp $ */
+/* $NetBSD: main.c,v 1.60 2014/10/10 07:48:50 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -875,6 +875,13 @@ defopt(struct dlhash *ht, const char *fn
olddl = olddl->dl_next;
olddl->dl_next = dl;
}
+
+ /*
+ * Implicit attribute definition for option.
+ */
+ const char *n;
+ n = strtolower(dl->dl_name);
+ refattr(n);
}
}
Index: src/usr.bin/config/sem.c
diff -u src/usr.bin/config/sem.c:1.51 src/usr.bin/config/sem.c:1.52
--- src/usr.bin/config/sem.c:1.51 Fri Oct 10 07:08:26 2014
+++ src/usr.bin/config/sem.c Fri Oct 10 07:48:50 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.51 2014/10/10 07:08:26 uebayasi Exp $ */
+/* $NetBSD: sem.c,v 1.52 2014/10/10 07:48:50 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -236,12 +236,13 @@ defattr(const char *name, struct loclist
}
}
- a = mkattr(name);
- if (a == NULL) {
+ if (getrefattr(name, &a)) {
cfgerror("attribute `%s' already defined", name);
loclist_destroy(locs);
return (1);
}
+ if (a == NULL)
+ a = mkattr(name);
a->a_deps = deps;
expandattr(a, NULL);
@@ -674,6 +675,28 @@ refattr(const char *name)
(void)mkattr(name);
}
+int
+getrefattr(const char *name, struct attr **ra)
+{
+ struct attr *a;
+
+ a = ht_lookup(attrtab, name);
+ if (a == NULL) {
+ *ra = NULL;
+ return (0);
+ }
+ /*
+ * Check if the existing attr is only referenced, not really defined.
+ */
+ if (a->a_deps == NULL &&
+ a->a_iattr == 0 &&
+ a->a_devclass == 0) {
+ *ra = a;
+ return (0);
+ }
+ return (1);
+}
+
/*
* Recursively expand an attribute and its dependencies, checking for
* cycles, and invoking a callback for each attribute found.
Index: src/usr.bin/config/sem.h
diff -u src/usr.bin/config/sem.h:1.12 src/usr.bin/config/sem.h:1.13
--- src/usr.bin/config/sem.h:1.12 Fri Oct 10 06:59:38 2014
+++ src/usr.bin/config/sem.h Fri Oct 10 07:48:50 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.h,v 1.12 2014/10/10 06:59:38 uebayasi Exp $ */
+/* $NetBSD: sem.h,v 1.13 2014/10/10 07:48:50 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -58,6 +58,7 @@ struct deva *getdevattach(const char
struct attr *mkattr(const char *);
struct attr *getattr(const char *);
void refattr(const char *);
+int getrefattr(const char *, struct attr **);
void expandattr(struct attr *, void (*)(struct attr *));
void selectattr(struct attr *);
void setmajor(struct devbase *, int);