Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config Split plain/interface/devclass attribute init...
details: https://anonhg.NetBSD.org/src/rev/8357cffdc7fc
branches: trunk
changeset: 332807:8357cffdc7fc
user: uebayasi <uebayasi%NetBSD.org@localhost>
date: Fri Oct 10 06:13:30 2014 +0000
description:
Split plain/interface/devclass attribute initializers.
diffstat:
usr.bin/config/gram.y | 6 +-
usr.bin/config/sem.c | 113 ++++++++++++++++++++++++++++++++-----------------
usr.bin/config/sem.h | 5 +-
3 files changed, 80 insertions(+), 44 deletions(-)
diffs (199 lines):
diff -r 111db783b1af -r 8357cffdc7fc usr.bin/config/gram.y
--- a/usr.bin/config/gram.y Fri Oct 10 05:27:28 2014 +0000
+++ b/usr.bin/config/gram.y Fri Oct 10 06:13:30 2014 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: gram.y,v 1.41 2014/10/09 09:39:24 uebayasi Exp $ */
+/* $NetBSD: gram.y,v 1.42 2014/10/10 06:13:30 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -356,7 +356,7 @@
;
define_devclass:
- DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); }
+ DEVCLASS WORD { (void)defdevclass($2, NULL, NULL, 1); }
;
define_filesystems:
@@ -365,7 +365,7 @@
define_attribute:
DEFINE WORD interface_opt depend_list
- { (void)defattr($2, $3, $4, 0); }
+ { (void)defattr0($2, $3, $4, 0); }
;
define_option:
diff -r 111db783b1af -r 8357cffdc7fc usr.bin/config/sem.c
--- a/usr.bin/config/sem.c Fri Oct 10 05:27:28 2014 +0000
+++ b/usr.bin/config/sem.c Fri Oct 10 06:13:30 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.48 2014/10/10 05:27:28 uebayasi Exp $ */
+/* $NetBSD: sem.c,v 1.49 2014/10/10 06:13:30 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -204,19 +204,24 @@
* all locator lists include a dummy head node, which we discard here.
*/
int
+defattr0(const char *name, struct loclist *locs, struct attrlist *deps,
+ int devclass)
+{
+
+ if (locs != NULL)
+ return defiattr(name, locs, deps, devclass);
+ else if (devclass)
+ return defdevclass(name, locs, deps, devclass);
+ else
+ return defattr(name, locs, deps, devclass);
+}
+
+int
defattr(const char *name, struct loclist *locs, struct attrlist *deps,
int devclass)
{
struct attr *a, *dep;
struct attrlist *al;
- struct loclist *ll;
- int len;
-
- if (locs != NULL && devclass)
- panic("defattr(%s): locators and devclass", name);
-
- if (deps != NULL && devclass)
- panic("defattr(%s): dependencies and devclass", name);
/*
* If this attribute depends on any others, make sure none of
@@ -243,41 +248,69 @@
a->a_deps = deps;
a->a_expanding = 0;
TAILQ_INIT(&a->a_files);
+ expandattr(a, NULL);
- /* "interface attribute" initialization */
- if (locs != NULL) {
- a->a_iattr = 1;
- /* unwrap */
- a->a_locs = locs->ll_next;
- locs->ll_next = NULL;
- loclist_destroy(locs);
- len = 0;
- for (ll = a->a_locs; ll != NULL; ll = ll->ll_next)
- len++;
- a->a_loclen = len;
- }
+ return (0);
+}
+
+/* "interface attribute" initialization */
+int
+defiattr(const char *name, struct loclist *locs, struct attrlist *deps,
+ int devclass)
+{
+ struct attr *a;
+ int len;
+ struct loclist *ll;
+
+ if (devclass)
+ panic("defattr(%s): locators and devclass", name);
+
+ if (defattr(name, locs, deps, devclass) != 0)
+ return (1);
- /* "device class" initialization */
- if (devclass) {
- char classenum[256], *cp;
- int errored = 0;
+ a = getattr(name);
+ a->a_iattr = 1;
+ /* unwrap */
+ a->a_locs = locs->ll_next;
+ locs->ll_next = NULL;
+ loclist_destroy(locs);
+ len = 0;
+ for (ll = a->a_locs; ll != NULL; ll = ll->ll_next)
+ len++;
+ a->a_loclen = len;
+ if (deps)
+ CFGDBG(2, "attr `%s' iface with deps", a->a_name);
+ return (0);
+}
- (void)snprintf(classenum, sizeof(classenum), "DV_%s", name);
- for (cp = classenum + 3; *cp; cp++) {
- if (!errored &&
- (!isalnum((unsigned char)*cp) ||
- (isalpha((unsigned char)*cp) && !islower((unsigned char)*cp)))) {
- cfgerror("device class names must be "
- "lower-case alphanumeric characters");
- errored = 1;
- }
- *cp = toupper((unsigned char)*cp);
+/* "device class" initialization */
+int
+defdevclass(const char *name, struct loclist *locs, struct attrlist *deps,
+ int devclass)
+{
+ struct attr *a;
+ char classenum[256], *cp;
+ int errored = 0;
+
+ if (deps)
+ panic("defattr(%s): dependencies and devclass", name);
+
+ if (defattr(name, locs, deps, devclass) != 0)
+ return (1);
+
+ a = getattr(name);
+ (void)snprintf(classenum, sizeof(classenum), "DV_%s", name);
+ for (cp = classenum + 3; *cp; cp++) {
+ if (!errored &&
+ (!isalnum((unsigned char)*cp) ||
+ (isalpha((unsigned char)*cp) && !islower((unsigned char)*cp)))) {
+ cfgerror("device class names must be "
+ "lower-case alphanumeric characters");
+ errored = 1;
}
- a->a_devclass = intern(classenum);
+ *cp = toupper((unsigned char)*cp);
}
-
- /* Expand the attribute to check for cycles in the graph. */
- expandattr(a, NULL);
+ a->a_devclass = intern(classenum);
return (0);
}
@@ -360,7 +393,7 @@
if (loclist != NULL) {
ll = loclist;
loclist = NULL; /* defattr disposes of them for us */
- if (defattr(dev->d_name, ll, NULL, 0))
+ if (defiattr(dev->d_name, ll, NULL, 0))
goto bad;
attrs = attrlist_cons(attrs, getattr(dev->d_name));
/* This used to be stored but was never used */
diff -r 111db783b1af -r 8357cffdc7fc usr.bin/config/sem.h
--- a/usr.bin/config/sem.h Fri Oct 10 05:27:28 2014 +0000
+++ b/usr.bin/config/sem.h Fri Oct 10 06:13:30 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.h,v 1.10 2012/03/11 21:16:08 dholland Exp $ */
+/* $NetBSD: sem.h,v 1.11 2014/10/10 06:13:30 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -46,7 +46,10 @@
void setdefmaxusers(int, int, int);
void setmaxusers(int);
void setident(const char *);
+int defattr0(const char *, struct loclist *, struct attrlist *, int);
int defattr(const char *, struct loclist *, struct attrlist *, int);
+int defiattr(const char *, struct loclist *, struct attrlist *, int);
+int defdevclass(const char *, struct loclist *, struct attrlist *, int);
void defdev(struct devbase *, struct loclist *, struct attrlist *, int);
void defdevattach(struct deva *, struct devbase *, struct nvlist *,
struct attrlist *);
Home |
Main Index |
Thread Index |
Old Index