1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-13 14:40:22 +00:00

Fix some problems that affect multiple file inclusion. Bruce found

this bug and submitted these patches to dunstan@.  He sent them to me
to test, and I discovered they were needed for the atmel kernel config
files.  Since we were playing with them in the terminal room after the
developer's summit today, I thought I'd go ahead and commit them to
allow those folks that now have atmel hardware (thanks Andre) a chance
to try it out w/o my help.  Since dunstan@ is asleep right now, risk
stepping on his toes a little by going ahead and committing this
change.

Submitted by: dunstan@, bde@
Tested by: bde@
This commit is contained in:
Warner Losh 2007-05-17 04:53:52 +00:00
parent 7db977fb07
commit c1f4dd9355
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169647
3 changed files with 26 additions and 73 deletions

View File

@ -177,7 +177,7 @@ void headers(void);
void cfgfile_add(const char *); void cfgfile_add(const char *);
void cfgfile_removeall(void); void cfgfile_removeall(void);
extern STAILQ_HEAD(device_head, device) dtab, rmdtab; extern STAILQ_HEAD(device_head, device) dtab;
extern char errbuf[80]; extern char errbuf[80];
extern int yyline; extern int yyline;

View File

@ -78,7 +78,7 @@
#include "config.h" #include "config.h"
struct device_head dtab, rmdtab; struct device_head dtab;
char *ident; char *ident;
char *env; char *env;
int envmode; int envmode;
@ -105,9 +105,6 @@ devopt(char *dev)
return ret; return ret;
} }
static void rmoptall(struct opt_head *list, struct opt_head *torem);
static void rmdevall(struct device_head *dh, struct device_head *torem);
%} %}
%% %%
Configuration: Configuration:
@ -177,7 +174,7 @@ Config_spec:
OPTIONS Opt_list OPTIONS Opt_list
| |
NOOPTION Save_id NOOPTION Save_id
= { rmopt_schedule(&rmopts, $2); } | = { rmopt_schedule(&opt, $2); } |
MAKEOPTIONS Mkopt_list MAKEOPTIONS Mkopt_list
| |
NOMAKEOPTION Save_id NOMAKEOPTION Save_id
@ -305,10 +302,10 @@ NoDevice:
= { = {
char *s = devopt($1); char *s = devopt($1);
rmopt_schedule(&rmopts, s); rmopt_schedule(&opt, s);
free(s); free(s);
/* and the device part */ /* and the device part */
rmdev_schedule(&rmdtab, $1); rmdev_schedule(&dtab, $1);
} ; } ;
%% %%
@ -323,17 +320,14 @@ yyerror(const char *s)
int int
yywrap(void) yywrap(void)
{ {
if (found_defaults) {
if (found_defaults == 0 && incignore == 0) { if (freopen(PREFIX, "r", stdin) == NULL)
if (freopen("DEFAULTS", "r", stdin) == NULL) err(2, "%s", PREFIX);
return 1; yyfile = PREFIX;
yyfile = "DEFAULTS";
yyline = 0; yyline = 0;
found_defaults = 1; found_defaults = 0;
return 0; return 0;
} }
rmoptall(&opt, &rmopts);
rmdevall(&dtab, &rmdtab);
return 1; return 1;
} }
@ -391,29 +385,10 @@ rmdev_schedule(struct device_head *dh, char *name)
{ {
struct device *dp; struct device *dp;
dp = calloc(1, sizeof(struct device)); dp = finddev(dh, name);
dp->d_name = strdup(name); if (dp != NULL) {
assert(dp->d_name != NULL); STAILQ_REMOVE(dh, dp, device, d_next);
STAILQ_INSERT_HEAD(dh, dp, d_next); free(dp->d_name);
}
/*
* Take care a devices previously scheduled for removal.
*/
static void
rmdevall(struct device_head *dh, struct device_head *torem)
{
struct device *dp, *rdp;
while (!STAILQ_EMPTY(torem)) {
dp = STAILQ_FIRST(torem);
STAILQ_REMOVE_HEAD(torem, d_next);
rdp = finddev(dh, dp->d_name);
if (rdp != NULL) {
STAILQ_REMOVE(dh, rdp, device, d_next);
free(rdp->d_name);
free(rdp);
}
free(dp); free(dp);
} }
} }
@ -469,31 +444,10 @@ rmopt_schedule(struct opt_head *list, char *name)
{ {
struct opt *op; struct opt *op;
op = calloc(1, sizeof(*op)); op = findopt(list, name);
op->op_name = ns(name); if (op != NULL) {
SLIST_INSERT_HEAD(list, op, op_next); SLIST_REMOVE(list, op, opt, op_next);
} free(op->op_name);
/*
* Remove all options that were scheduled for removal.
*/
static void
rmoptall(struct opt_head *list, struct opt_head *torem)
{
struct opt *op, *rop;
op = rop = NULL;
while (!SLIST_EMPTY(torem)) {
op = SLIST_FIRST(torem);
SLIST_REMOVE_HEAD(torem, op_next);
rop = findopt(list, op->op_name);
if (rop != NULL) {
SLIST_REMOVE(list, rop, opt, op_next);
free(rop->op_name);
if (rop->op_value != NULL)
free(rop->op_value);
free(rop);
}
free(op); free(op);
} }
} }

View File

@ -150,14 +150,14 @@ main(int argc, char **argv)
usage(); usage();
PREFIX = *argv; PREFIX = *argv;
/* if (freopen("DEFAULTS", "r", stdin) != NULL) {
* We mark lack of DEFAULTS here. Once we hit EOF in PREFIX, yywrap() found_defaults = 1;
* will try to bring DEFAULTS to the playground, if this exists. yyfile = "DEFAULTS";
*/ } else {
found_defaults = 0;
if (freopen(PREFIX, "r", stdin) == NULL) if (freopen(PREFIX, "r", stdin) == NULL)
err(2, "%s", PREFIX); err(2, "%s", PREFIX);
yyfile = PREFIX; yyfile = PREFIX;
}
if (*destdir != '\0') { if (*destdir != '\0') {
len = strlen(destdir); len = strlen(destdir);
while (len > 1 && destdir[len - 1] == '/') while (len > 1 && destdir[len - 1] == '/')
@ -184,7 +184,6 @@ main(int argc, char **argv)
STAILQ_INIT(&fntab); STAILQ_INIT(&fntab);
STAILQ_INIT(&ftab); STAILQ_INIT(&ftab);
STAILQ_INIT(&hints); STAILQ_INIT(&hints);
STAILQ_INIT(&rmdtab);
if (yyparse()) if (yyparse())
exit(3); exit(3);