Allow deffs to take dependencies like defflag and defopt

This commit is contained in:
matt 2006-08-30 10:12:25 +00:00
parent 944592a2ee
commit 4a82747a8f
3 changed files with 50 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.11 2006/06/04 13:52:27 cube Exp $ */
/* $NetBSD: defs.h,v 1.12 2006/08/30 10:12:25 matt Exp $ */
/*
* Copyright (c) 1992, 1993
@ -482,7 +482,7 @@ void addfsoption(const char *);
void addmkoption(const char *, const char *);
void appendmkoption(const char *, const char *);
void appendcondmkoption(const char *, const char *, const char *);
void deffilesystem(const char *, struct nvlist *);
void deffilesystem(const char *, struct nvlist *, struct nvlist *);
void defoption(const char *, struct nvlist *, struct nvlist *);
void defflag(const char *, struct nvlist *, struct nvlist *, int);
void defparam(const char *, struct nvlist *, struct nvlist *, int);

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.8 2006/08/26 18:17:13 christos Exp $ */
/* $NetBSD: gram.y,v 1.9 2006/08/30 10:12:25 matt Exp $ */
/*
* Copyright (c) 1992, 1993
@ -275,7 +275,8 @@ one_def:
device_major { do_devsw = 1; } |
prefix |
DEVCLASS WORD { (void)defattr($2, NULL, NULL, 1); } |
DEFFS fsoptfile_opt deffses { deffilesystem($2, $3); } |
DEFFS fsoptfile_opt deffses defoptdeps
{ deffilesystem($2, $3, $4); } |
DEFINE WORD interface_opt attrs_opt
{ (void)defattr($2, $3, $4, 0); } |
DEFOPT optfile_opt defopts defoptdeps

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.14 2006/08/26 18:17:13 christos Exp $ */
/* $NetBSD: main.c,v 1.15 2006/08/30 10:12:25 matt Exp $ */
/*
* Copyright (c) 1992, 1993
@ -448,6 +448,15 @@ dependopts(void)
}
}
}
for (nv = fsoptions; nv != NULL; nv = nv->nv_next) {
if ((opt = find_declared_option(nv->nv_name)) != NULL) {
for (opt = opt->nv_ptr; opt != NULL;
opt = opt->nv_next) {
do_depend(opt);
}
}
}
}
static void
@ -544,6 +553,36 @@ stop(void)
exit(1);
}
static void
add_dependencies(struct nvlist *nv, struct nvlist *deps)
{
struct nvlist *dep;
struct attr *a;
/* Use nv_ptr to link any other options that are implied. */
nv->nv_ptr = deps;
for (dep = deps; dep != NULL; dep = dep->nv_next) {
/*
* If the dependency is an attribute, it must not
* be an interface attribute. Otherwise, it must
* be a previously declared option.
*/
if ((a = ht_lookup(attrtab, dep->nv_name)) != NULL) {
if (a->a_iattr)
error("option `%s' dependency `%s' "
"is an interface attribute",
nv->nv_name, a->a_name);
} else if (OPT_OBSOLETE(dep->nv_name)) {
error("option `%s' dependency `%s' "
"is obsolete", nv->nv_name, dep->nv_name);
} else if (find_declared_option(dep->nv_name) == NULL) {
error("option `%s' dependency `%s' "
"is an unknown option",
nv->nv_name, dep->nv_name);
}
}
}
/*
* Define one or more file systems. If file system options file name is
* specified, a preprocessor #define for that file system will be placed
@ -551,7 +590,7 @@ stop(void)
* Otherwise, no preprocessor #defines will be generated.
*/
void
deffilesystem(const char *fname, struct nvlist *fses)
deffilesystem(const char *fname, struct nvlist *fses, struct nvlist *deps)
{
struct nvlist *nv;
@ -590,6 +629,8 @@ deffilesystem(const char *fname, struct nvlist *fses)
return;
}
}
add_dependencies(nv, deps);
}
}
@ -647,7 +688,7 @@ void
defopt(struct hashtab *ht, const char *fname, struct nvlist *opts,
struct nvlist *deps, int obs)
{
struct nvlist *nv, *nextnv, *oldnv, *dep;
struct nvlist *nv, *nextnv, *oldnv;
struct attr *a;
const char *name;
char buf[500];
@ -689,28 +730,7 @@ defopt(struct hashtab *ht, const char *fname, struct nvlist *opts,
name = fname;
}
/* Use nv_ptr to link any other options that are implied. */
nv->nv_ptr = deps;
for (dep = deps; dep != NULL; dep = dep->nv_next) {
/*
* If the dependency is an attribute, it must not
* be an interface attribute. Otherwise, it must
* be a previously declared option.
*/
if ((a = ht_lookup(attrtab, dep->nv_name)) != NULL) {
if (a->a_iattr)
error("option `%s' dependency `%s' "
"is an interface attribute",
nv->nv_name, a->a_name);
} else if (OPT_OBSOLETE(dep->nv_name)) {
error("option `%s' dependency `%s' "
"is obsolete", nv->nv_name, dep->nv_name);
} else if (find_declared_option(dep->nv_name) == NULL) {
error("option `%s' dependency `%s' "
"is an unknown option",
nv->nv_name, dep->nv_name);
}
}
add_dependencies(nv, deps);
/*
* Remove this option from the parameter list before adding