Clean some code that became obfuscated over the years:

Don't keep duplicate files in the files list just to
mark the device as "known" later.  XXX: Since the
device list isn't unique (there can be two "device foo"
directives, as this the case with LINT+DEFAULTS), we
have to traverse it all to mark all copies of the same
device as "used", but this is not worse than it was.
This commit is contained in:
Ruslan Ermilov 2005-11-25 22:25:34 +00:00
parent 26664f807c
commit 61ede7eeac
3 changed files with 19 additions and 59 deletions

View File

@ -46,7 +46,6 @@ struct file_list {
char *f_compilewith; /* special make rule if present */
char *f_depends; /* additional dependancies */
char *f_clean; /* File list to add to clean rule */
char *f_needs;
char *f_warn; /* warning message */
};
@ -59,7 +58,6 @@ struct files_name {
* Types.
*/
#define NORMAL 1
#define INVISIBLE 2
#define PROFILING 3
#define NODEPEND 4
#define LOCAL 5
@ -72,7 +70,6 @@ struct files_name {
#define NO_IMPLCT_RULE 1
#define NO_OBJ 2
#define BEFORE_DEPEND 4
#define ISDUP 8
#define NOWERROR 16
struct device {

View File

@ -50,23 +50,10 @@ static const char rcsid[] =
void
headers(void)
{
struct file_list *fl;
struct device *dp;
int match;
int errors;
errors = 0;
STAILQ_FOREACH(fl, &ftab, f_next) {
if (fl->f_needs != 0) {
match = 0;
STAILQ_FOREACH(dp, &dtab, d_next) {
if (eq(dp->d_name, fl->f_needs)) {
match++;
dp->d_done |= DEVDONE;
}
}
}
}
STAILQ_FOREACH(dp, &dtab, d_next) {
if (!(dp->d_done & DEVDONE)) {
warnx("Error: device \"%s\" is unknown",

View File

@ -293,11 +293,11 @@ static void
read_file(char *fname)
{
FILE *fp;
struct file_list *tp, *pf;
struct file_list *tp;
struct device *dp;
struct opt *op;
char *wd, *this, *needs, *compilewith, *depends, *clean, *warning;
int nreqs, isdup, std, filetype,
char *wd, *this, *compilewith, *depends, *clean, *warning;
int nreqs, devfound, std, filetype,
imp_rule, no_obj, before_depend, mandatory, nowerror;
fp = fopen(fname, "r");
@ -331,17 +331,12 @@ read_file(char *fname)
fname, this);
exit(1);
}
if ((pf = fl_lookup(this)) && (pf->f_type != INVISIBLE || pf->f_flags))
isdup = ISDUP;
else
isdup = 0;
tp = 0;
tp = fl_lookup(this);
nreqs = 0;
compilewith = 0;
depends = 0;
clean = 0;
warning = 0;
needs = 0;
std = mandatory = 0;
imp_rule = 0;
no_obj = 0;
@ -365,7 +360,7 @@ read_file(char *fname)
nextparam:
next_word(fp, wd);
if (wd == 0) {
if (isdup)
if (tp != NULL)
goto next;
goto doneparam;
}
@ -443,13 +438,16 @@ read_file(char *fname)
nowerror = 1;
goto nextparam;
}
if (needs == 0 && nreqs == 1)
needs = ns(wd);
if (isdup)
goto invis;
devfound = 0; /* XXX duplicate device entries */
STAILQ_FOREACH(dp, &dtab, d_next)
if (eq(dp->d_name, wd))
goto nextparam;
if (eq(dp->d_name, wd)) {
dp->d_done |= DEVDONE;
devfound = 1;
}
if (devfound)
goto nextparam;
if (tp != NULL)
goto skip;
if (mandatory) {
printf("%s: mandatory device \"%s\" not found\n",
fname, wd);
@ -461,26 +459,11 @@ read_file(char *fname)
exit(1);
}
SLIST_FOREACH(op, &opt, op_next)
if (op->op_value == 0 && opteq(op->op_name, wd)) {
if (nreqs == 1) {
free(needs);
needs = 0;
}
if (op->op_value == 0 && opteq(op->op_name, wd))
goto nextparam;
}
invis:
skip:
while ((wd = get_word(fp)) != 0)
;
if (tp == 0)
tp = new_fent();
tp->f_fn = this;
tp->f_type = INVISIBLE;
tp->f_needs = needs;
tp->f_flags |= isdup;
tp->f_compilewith = compilewith;
tp->f_depends = depends;
tp->f_clean = clean;
tp->f_warn = warning;
goto next;
doneparam:
@ -497,11 +480,9 @@ read_file(char *fname)
}
if (filetype == PROFILING && profiling == 0)
goto next;
if (tp == 0)
tp = new_fent();
tp = new_fent();
tp->f_fn = this;
tp->f_type = filetype;
tp->f_flags &= ~ISDUP;
if (imp_rule)
tp->f_flags |= NO_IMPLCT_RULE;
if (no_obj)
@ -510,13 +491,10 @@ read_file(char *fname)
tp->f_flags |= BEFORE_DEPEND;
if (nowerror)
tp->f_flags |= NOWERROR;
tp->f_needs = needs;
tp->f_compilewith = compilewith;
tp->f_depends = depends;
tp->f_clean = clean;
tp->f_warn = warning;
if (pf && pf->f_type == INVISIBLE)
pf->f_flags |= ISDUP; /* mark as duplicate */
goto next;
}
@ -599,7 +577,7 @@ do_objs(FILE *fp)
fprintf(fp, "OBJS=");
lpos = 6;
STAILQ_FOREACH(tp, &ftab, f_next) {
if (tp->f_type == INVISIBLE || tp->f_flags & NO_OBJ)
if (tp->f_flags & NO_OBJ)
continue;
sp = tail(tp->f_fn);
cp = sp + (len = strlen(sp)) - 1;
@ -635,7 +613,7 @@ do_xxfiles(char *tag, FILE *fp)
fprintf(fp, "%sFILES=", SUFF);
lpos = 8;
STAILQ_FOREACH(tp, &ftab, f_next)
if (tp->f_type != INVISIBLE && tp->f_type != NODEPEND) {
if (tp->f_type != NODEPEND) {
len = strlen(tp->f_fn);
if (tp->f_fn[len - slen - 1] != '.')
continue;
@ -678,8 +656,6 @@ do_rules(FILE *f)
char *compilewith;
STAILQ_FOREACH(ftp, &ftab, f_next) {
if (ftp->f_type == INVISIBLE)
continue;
if (ftp->f_warn)
printf("WARNING: %s\n", ftp->f_warn);
cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1;