- Avoid adding devices multiple times to the device list.
- Avoid adding options multiple times to the option list. Based on a patch by: Matt Emmerton <matt@gsicomp.on.ca>
This commit is contained in:
parent
22025511b4
commit
8ee64886ef
@ -343,13 +343,33 @@ newfile(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add a device to the list of devices
|
* Find a device in the list of devices.
|
||||||
|
*/
|
||||||
|
static struct device *
|
||||||
|
finddev(char *name)
|
||||||
|
{
|
||||||
|
struct device *dp;
|
||||||
|
|
||||||
|
STAILQ_FOREACH(dp, &dtab, d_next)
|
||||||
|
if (eq(dp->d_name, name))
|
||||||
|
return (dp);
|
||||||
|
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a device to the list of devices.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
newdev(char *name)
|
newdev(char *name)
|
||||||
{
|
{
|
||||||
struct device *np;
|
struct device *np;
|
||||||
|
|
||||||
|
if (finddev(name)) {
|
||||||
|
printf("WARNING: duplicate device `%s' encountered.\n", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
np = (struct device *) malloc(sizeof *np);
|
np = (struct device *) malloc(sizeof *np);
|
||||||
memset(np, 0, sizeof(*np));
|
memset(np, 0, sizeof(*np));
|
||||||
np->d_name = name;
|
np->d_name = name;
|
||||||
@ -357,31 +377,49 @@ newdev(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* remove a device from the list of devices
|
* Remove a device from the list of devices.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
rmdev(char *name)
|
rmdev(char *name)
|
||||||
{
|
{
|
||||||
struct device *dp, *rmdp;
|
struct device *dp;
|
||||||
|
|
||||||
STAILQ_FOREACH(dp, &dtab, d_next) {
|
dp = finddev(name);
|
||||||
if (eq(dp->d_name, name)) {
|
if (dp != NULL) {
|
||||||
rmdp = dp;
|
STAILQ_REMOVE(&dtab, dp, device, d_next);
|
||||||
dp = STAILQ_NEXT(dp, d_next);
|
free(dp->d_name);
|
||||||
STAILQ_REMOVE(&dtab, rmdp, device, d_next);
|
free(dp);
|
||||||
free(rmdp->d_name);
|
|
||||||
free(rmdp);
|
|
||||||
if (dp == NULL)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find an option in the list of options.
|
||||||
|
*/
|
||||||
|
static struct opt *
|
||||||
|
findopt(struct opt_head *list, char *name)
|
||||||
|
{
|
||||||
|
struct opt *op;
|
||||||
|
|
||||||
|
SLIST_FOREACH(op, list, op_next)
|
||||||
|
if (eq(op->op_name, name))
|
||||||
|
return (op);
|
||||||
|
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add an option to the list of options.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
newopt(struct opt_head *list, char *name, char *value)
|
newopt(struct opt_head *list, char *name, char *value)
|
||||||
{
|
{
|
||||||
struct opt *op;
|
struct opt *op;
|
||||||
|
|
||||||
|
if (findopt(list, name)) {
|
||||||
|
printf("WARNING: duplicate option `%s' encountered.\n", name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
op = (struct opt *)malloc(sizeof (struct opt));
|
op = (struct opt *)malloc(sizeof (struct opt));
|
||||||
memset(op, 0, sizeof(*op));
|
memset(op, 0, sizeof(*op));
|
||||||
op->op_name = name;
|
op->op_name = name;
|
||||||
@ -390,22 +428,20 @@ newopt(struct opt_head *list, char *name, char *value)
|
|||||||
SLIST_INSERT_HEAD(list, op, op_next);
|
SLIST_INSERT_HEAD(list, op, op_next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Remove an option from the list of options.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
rmopt(struct opt_head *list, char *name)
|
rmopt(struct opt_head *list, char *name)
|
||||||
{
|
{
|
||||||
struct opt *op, *rmop;
|
struct opt *op;
|
||||||
|
|
||||||
SLIST_FOREACH(op, list, op_next) {
|
op = findopt(list, name);
|
||||||
if (eq(op->op_name, name)) {
|
if (op != NULL) {
|
||||||
rmop = op;
|
SLIST_REMOVE(list, op, opt, op_next);
|
||||||
op = SLIST_NEXT(op, op_next);
|
free(op->op_name);
|
||||||
SLIST_REMOVE(list, rmop, opt, op_next);
|
if (op->op_value != NULL)
|
||||||
free(rmop->op_name);
|
free(op->op_value);
|
||||||
if (rmop->op_value != NULL)
|
free(op);
|
||||||
free(rmop->op_value);
|
|
||||||
free(rmop);
|
|
||||||
if (op == NULL)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ read_file(char *fname)
|
|||||||
struct device *dp;
|
struct device *dp;
|
||||||
struct opt *op;
|
struct opt *op;
|
||||||
char *wd, *this, *compilewith, *depends, *clean, *warning;
|
char *wd, *this, *compilewith, *depends, *clean, *warning;
|
||||||
int compile, match, nreqs, devfound, std, filetype,
|
int compile, match, nreqs, std, filetype,
|
||||||
imp_rule, no_obj, before_depend, mandatory, nowerror;
|
imp_rule, no_obj, before_depend, mandatory, nowerror;
|
||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
@ -465,14 +465,11 @@ read_file(char *fname)
|
|||||||
nowerror = 1;
|
nowerror = 1;
|
||||||
goto nextparam;
|
goto nextparam;
|
||||||
}
|
}
|
||||||
devfound = 0; /* XXX duplicate device entries */
|
|
||||||
STAILQ_FOREACH(dp, &dtab, d_next)
|
STAILQ_FOREACH(dp, &dtab, d_next)
|
||||||
if (eq(dp->d_name, wd)) {
|
if (eq(dp->d_name, wd)) {
|
||||||
dp->d_done |= DEVDONE;
|
dp->d_done |= DEVDONE;
|
||||||
devfound = 1;
|
goto nextparam;
|
||||||
}
|
}
|
||||||
if (devfound)
|
|
||||||
goto nextparam;
|
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
printf("%s: mandatory device \"%s\" not found\n",
|
printf("%s: mandatory device \"%s\" not found\n",
|
||||||
fname, wd);
|
fname, wd);
|
||||||
|
Loading…
Reference in New Issue
Block a user