diff options
author | Ruslan Ermilov <ru@FreeBSD.org> | 2003-02-15 02:26:13 +0000 |
---|---|---|
committer | Ruslan Ermilov <ru@FreeBSD.org> | 2003-02-15 02:26:13 +0000 |
commit | 292dd8a87fab114f1a8e6861bd847d60b63dc7c6 (patch) | |
tree | f5f37ddbfda92d8dbbefdfa8b4c16d6dfee8d174 /usr.sbin | |
parent | a89fcf28435133aae9494ae19550390eb87e9f77 (diff) | |
download | src-292dd8a87fab114f1a8e6861bd847d60b63dc7c6.tar.gz src-292dd8a87fab114f1a8e6861bd847d60b63dc7c6.zip |
Convert to using <sys/queue.h> macros.
Notes
Notes:
svn path=/head/; revision=110895
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/config/config.h | 27 | ||||
-rw-r--r-- | usr.sbin/config/config.y | 21 | ||||
-rw-r--r-- | usr.sbin/config/main.c | 5 | ||||
-rw-r--r-- | usr.sbin/config/mkheaders.c | 30 | ||||
-rw-r--r-- | usr.sbin/config/mkmakefile.c | 30 | ||||
-rw-r--r-- | usr.sbin/config/mkoptions.c | 48 |
6 files changed, 76 insertions, 85 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index 02df87938a0a..2e93acff18bf 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -38,11 +38,12 @@ * Config. */ #include <sys/types.h> +#include <sys/queue.h> #include <stdlib.h> #include <string.h> struct file_list { - struct file_list *f_next; + STAILQ_ENTRY(file_list) f_next; char *f_fn; /* the name */ int f_type; /* type or count */ u_char f_flags; /* see below */ @@ -79,7 +80,7 @@ struct device { char *d_name; /* name of device (e.g. rk11) */ int d_count; /* device count */ #define UNKNOWN -2 /* -2 means not set yet */ - struct device *d_next; /* Next one in list */ + STAILQ_ENTRY(device) d_next; /* Next one in list */ }; struct config { @@ -101,8 +102,10 @@ char *machinename; */ struct cputype { char *cpu_name; - struct cputype *cpu_next; -} *cputype; + SLIST_ENTRY(cputype) cpu_next; +}; + +SLIST_HEAD(, cputype) cputype; /* * A set of options may also be specified which are like CPU types, @@ -113,14 +116,18 @@ struct opt { char *op_name; char *op_value; int op_ownfile; /* true = own file, false = makefile */ - struct opt *op_next; -} *opt, *mkopt; + SLIST_ENTRY(opt) op_next; +}; + +SLIST_HEAD(opt_head, opt) opt, mkopt; struct opt_list { char *o_name; char *o_file; - struct opt_list *o_next; -} *otab; + SLIST_ENTRY(opt_list) o_next; +}; + +SLIST_HEAD(, opt_list) otab; extern char *ident; extern char *env; @@ -141,13 +148,13 @@ void options(void); void makefile(void); void headers(void); -extern struct device *dtab; +extern STAILQ_HEAD(device_head, device) dtab; extern char errbuf[80]; extern int yyline; extern const char *yyfile; -extern struct file_list *ftab; +extern STAILQ_HEAD(file_list_head, file_list) ftab; extern int profiling; extern int debugging; diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index b1f5f2b47e5d..c30171f9c204 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -72,9 +72,7 @@ #include "config.h" -static struct device *curp = 0; - -struct device *dtab; +struct device_head dtab; char *ident; char *env; int envmode; @@ -82,7 +80,7 @@ char *hints; int hintmode; int yyline; const char *yyfile; -struct file_list *ftab; +struct file_list_head ftab; char errbuf[80]; int maxusers; @@ -133,8 +131,7 @@ Config_spec: (struct cputype *)malloc(sizeof (struct cputype)); memset(cp, 0, sizeof(*cp)); cp->cpu_name = $2; - cp->cpu_next = cputype; - cputype = cp; + SLIST_INSERT_HEAD(&cputype, cp, cpu_next); } | OPTIONS Opt_list | @@ -268,16 +265,11 @@ newdev(char *name, int count) memset(np, 0, sizeof(*np)); np->d_name = name; np->d_count = count; - np->d_next = 0; - if (curp == 0) - dtab = np; - else - curp->d_next = np; - curp = np; + STAILQ_INSERT_TAIL(&dtab, np, d_next); } static void -newopt(struct opt **list, char *name, char *value) +newopt(struct opt_head *list, char *name, char *value) { struct opt *op; @@ -286,6 +278,5 @@ newopt(struct opt **list, char *name, char *value) op->op_name = name; op->op_ownfile = 0; op->op_value = value; - op->op_next = *list; - *list = op; + SLIST_INSERT_HEAD(list, op, op_next); } diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index e6e3eb0714a8..9e9848c5b85b 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -144,7 +144,8 @@ main(int argc, char **argv) else if ((buf.st_mode & S_IFMT) != S_IFDIR) errx(2, "%s isn't a directory", p); - dtab = NULL; + STAILQ_INIT(&dtab); + SLIST_INIT(&cputype); yyfile = *argv; if (yyparse()) exit(3); @@ -420,7 +421,7 @@ cleanheaders(char *p) remember("y.tab.h"); remember("setdefs.h"); - for (fl = ftab; fl != NULL; fl = fl->f_next) + STAILQ_FOREACH(fl, &ftab, f_next) remember(fl->f_fn); /* diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c index 72e1a40bc02a..e8b8934e28eb 100644 --- a/usr.sbin/config/mkheaders.c +++ b/usr.sbin/config/mkheaders.c @@ -64,10 +64,10 @@ headers(void) int errors; errors = 0; - for (fl = ftab; fl != 0; fl = fl->f_next) { + STAILQ_FOREACH(fl, &ftab, f_next) { if (fl->f_needs != 0) { match = 0; - for (dp = dtab; dp != 0; dp = dp->d_next) { + STAILQ_FOREACH(dp, &dtab, d_next) { if (eq(dp->d_name, fl->f_needs)) { match++; dp->d_done |= DEVDONE; @@ -77,7 +77,7 @@ headers(void) errors += do_header(fl->f_needs, match); } } - for (dp = dtab; dp != 0; dp = dp->d_next) { + STAILQ_FOREACH(dp, &dtab, d_next) { if (!(dp->d_done & DEVDONE)) { warnx("Error: device \"%s\" is unknown", dp->d_name); @@ -86,7 +86,7 @@ headers(void) if (dp->d_count == UNKNOWN) continue; match = 0; - for (fl = ftab; fl != 0; fl = fl->f_next) { + STAILQ_FOREACH(fl, &ftab, f_next) { if (fl->f_needs == 0) continue; if ((fl->f_flags & NEED_COUNT) == 0) @@ -110,7 +110,8 @@ static int do_header(char *dev, int match) { char *file, *name, *inw; - struct file_list *fl, *fl_head, *tflp; + struct file_list *fl, *tflp; + struct file_list_head fl_head; struct device *dp; FILE *inf, *outf; int inc, oldcount; @@ -123,7 +124,8 @@ do_header(char *dev, int match) * must use this higher of these values. */ errors = 0; - for (hicount = count = 0, dp = dtab; dp != 0; dp = dp->d_next) { + hicount = count = 0; + STAILQ_FOREACH(dp, &dtab, d_next) { if (eq(dp->d_name, dev)) { if (dp->d_count == UNKNOWN) { warnx("Device \"%s\" requires a count", dev); @@ -148,7 +150,7 @@ do_header(char *dev, int match) (void) fclose(outf); return 0; } - fl_head = NULL; + STAILQ_INIT(&fl_head); for (;;) { char *cp; if ((inw = get_word(inf)) == 0 || inw == (char *)EOF) @@ -171,13 +173,12 @@ do_header(char *dev, int match) bzero(fl, sizeof(*fl)); fl->f_fn = inw; /* malloced */ fl->f_type = inc; - fl->f_next = fl_head; - fl_head = fl; + STAILQ_INSERT_HEAD(&fl_head, fl, f_next); } (void) fclose(inf); if (count == oldcount) { - for (fl = fl_head; fl != NULL; fl = tflp) { - tflp = fl->f_next; + for (fl = STAILQ_FIRST(&fl_head); fl != NULL; fl = tflp) { + tflp = STAILQ_NEXT(fl, f_next); free(fl->f_fn); free(fl); } @@ -188,16 +189,15 @@ do_header(char *dev, int match) bzero(fl, sizeof(*fl)); fl->f_fn = ns(name); fl->f_type = count; - fl->f_next = fl_head; - fl_head = fl; + STAILQ_INSERT_HEAD(&fl_head, fl, f_next); } outf = fopen(file, "w"); if (outf == 0) err(1, "%s", file); - for (fl = fl_head; fl != NULL; fl = tflp) { + for (fl = STAILQ_FIRST(&fl_head); fl != NULL; fl = tflp) { fprintf(outf, "#define %s %u\n", fl->f_fn, count ? fl->f_type : 0); - tflp = fl->f_next; + tflp = STAILQ_NEXT(fl, f_next); free(fl->f_fn); free(fl); } diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index 6d3818630425..2e4cb03e6b67 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -69,8 +69,6 @@ static const char rcsid[] = wd = word; \ } -static struct file_list *fcur; - static char *tail(char *); static void do_clean(FILE *); static void do_rules(FILE *); @@ -88,7 +86,7 @@ fl_lookup(char *file) { struct file_list *fp; - for (fp = ftab ; fp != 0; fp = fp->f_next) { + STAILQ_FOREACH(fp, &ftab, f_next) { if (eq(fp->f_fn, file)) return (fp); } @@ -105,11 +103,7 @@ new_fent(void) fp = (struct file_list *) malloc(sizeof *fp); bzero(fp, sizeof *fp); - if (fcur == 0) - fcur = ftab = fp; - else - fcur->f_next = fp; - fcur = fp; + STAILQ_INSERT_TAIL(&ftab, fp, f_next); return (fp); } @@ -136,7 +130,7 @@ makefile(void) err(1, "%s", line); /* XXX this check seems to be misplaced. */ - if (cputype == 0) { + if (SLIST_EMPTY(&cputype)) { printf("cpu type must be specified\n"); exit(1); } @@ -145,7 +139,7 @@ makefile(void) if (ofp == 0) err(1, "%s", path("Makefile.new")); fprintf(ofp, "KERN_IDENT=%s\n", raisestr(ident)); - for (op = mkopt; op; op = op->op_next) + SLIST_FOREACH(op, &mkopt, op_next) fprintf(ofp, "%s=%s\n", op->op_name, op->op_value); if (debugging) fprintf(ofp, "DEBUG=-g\n"); @@ -315,7 +309,7 @@ read_files(void) int nreqs, first = 1, isdup, std, filetype, imp_rule, no_obj, needcount, before_depend, mandatory, nowerror; - ftab = 0; + STAILQ_INIT(&ftab); if (ident == NULL) { printf("no ident line specified\n"); exit(1); @@ -480,7 +474,7 @@ nextparam: needs = ns(wd); if (isdup) goto invis; - for (dp = dtab; dp != 0; dp = dp->d_next) + STAILQ_FOREACH(dp, &dtab, d_next) if (eq(dp->d_name, wd)) { if (std && dp->d_count <= 0) dp->d_count = 1; @@ -496,7 +490,7 @@ nextparam: this, wd); exit(1); } - for (op = opt; op != 0; op = op->op_next) + SLIST_FOREACH(op, &opt, op_next) if (op->op_value == 0 && opteq(op->op_name, wd)) { if (nreqs == 1) { free(needs); @@ -585,7 +579,7 @@ do_before_depend(FILE *fp) fputs("BEFORE_DEPEND=", fp); lpos = 15; - for (tp = ftab; tp; tp = tp->f_next) + STAILQ_FOREACH(tp, &ftab, f_next) if (tp->f_flags & BEFORE_DEPEND) { len = strlen(tp->f_fn); if ((len = 3 + len) + lpos > 72) { @@ -611,7 +605,7 @@ do_objs(FILE *fp) fprintf(fp, "OBJS="); lpos = 6; - for (tp = ftab; tp != 0; tp = tp->f_next) { + STAILQ_FOREACH(tp, &ftab, f_next) { if (tp->f_type == INVISIBLE || tp->f_flags & NO_OBJ) continue; sp = tail(tp->f_fn); @@ -647,7 +641,7 @@ do_xxfiles(char *tag, FILE *fp) fprintf(fp, "%sFILES=", SUFF); lpos = 8; - for (tp = ftab; tp; tp = tp->f_next) + STAILQ_FOREACH(tp, &ftab, f_next) if (tp->f_type != INVISIBLE && tp->f_type != NODEPEND) { len = strlen(tp->f_fn); if (tp->f_fn[len - slen - 1] != '.') @@ -690,7 +684,7 @@ do_rules(FILE *f) struct file_list *ftp; char *compilewith; - for (ftp = ftab; ftp != 0; ftp = ftp->f_next) { + STAILQ_FOREACH(ftp, &ftab, f_next) { if (ftp->f_type == INVISIBLE) continue; if (ftp->f_warn) @@ -757,7 +751,7 @@ do_clean(FILE *fp) fputs("CLEAN=", fp); lpos = 7; - for (tp = ftab; tp; tp = tp->f_next) + STAILQ_FOREACH(tp, &ftab, f_next) if (tp->f_clean) { len = strlen(tp->f_clean); if (len + lpos > 72) { diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c index 77f6168eceb4..9d6f15d920a6 100644 --- a/usr.sbin/config/mkoptions.c +++ b/usr.sbin/config/mkoptions.c @@ -72,12 +72,11 @@ options(void) struct opt *op; /* Fake the cpu types as options. */ - for (cp = cputype; cp != NULL; cp = cp->cpu_next) { + SLIST_FOREACH(cp, &cputype, cpu_next) { op = (struct opt *)malloc(sizeof(*op)); memset(op, 0, sizeof(*op)); op->op_name = ns(cp->cpu_name); - op->op_next = opt; - opt = op; + SLIST_INSERT_HEAD(&opt, op, op_next); } if (maxusers == 0) { @@ -94,13 +93,12 @@ options(void) op->op_name = ns("MAXUSERS"); snprintf(buf, sizeof(buf), "%d", maxusers); op->op_value = ns(buf); - op->op_next = opt; - opt = op; + SLIST_INSERT_HEAD(&opt, op, op_next); read_options(); - for (ol = otab; ol != 0; ol = ol->o_next) + SLIST_FOREACH(ol, &otab, o_next) do_option(ol->o_name); - for (op = opt; op; op = op->op_next) { + SLIST_FOREACH(op, &opt, op_next) { if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) { printf("%s: unknown option \"%s\"\n", PREFIX, op->op_name); @@ -119,7 +117,8 @@ do_option(char *name) char *file, *inw; const char *basefile; struct opt_list *ol; - struct opt *op, *op_head, *topp; + struct opt *op; + struct opt_head op_head; FILE *inf, *outf; char *value; char *oldvalue; @@ -132,7 +131,7 @@ do_option(char *name) * Check to see if the option was specified.. */ value = NULL; - for (op = opt; op; op = op->op_next) { + SLIST_FOREACH(op, &opt, op_next) { if (eq(name, op->op_name)) { oldvalue = value; value = op->op_value; @@ -163,13 +162,13 @@ do_option(char *name) return; } basefile = ""; - for (ol = otab; ol != 0; ol = ol->o_next) + SLIST_FOREACH(ol, &otab, o_next) if (eq(name, ol->o_name)) { basefile = ol->o_file; break; } oldvalue = NULL; - op_head = NULL; + SLIST_INIT(&op_head); seen = 0; tidy = 0; for (;;) { @@ -193,7 +192,7 @@ do_option(char *name) invalue = value; seen++; } - for (ol = otab; ol != 0; ol = ol->o_next) + SLIST_FOREACH(ol, &otab, o_next) if (eq(inw, ol->o_name)) break; if (!eq(inw, name) && !ol) { @@ -209,8 +208,7 @@ do_option(char *name) bzero(op, sizeof(*op)); op->op_name = inw; op->op_value = invalue; - op->op_next = op_head; - op_head = op; + SLIST_INSERT_HEAD(&op_head, op, op_next); } /* EOL? */ @@ -221,8 +219,9 @@ do_option(char *name) (void) fclose(inf); if (!tidy && ((value == NULL && oldvalue == NULL) || (value && oldvalue && eq(value, oldvalue)))) { - for (op = op_head; op != NULL; op = topp) { - topp = op->op_next; + while (!SLIST_EMPTY(&op_head)) { + op = SLIST_FIRST(&op_head); + SLIST_REMOVE_HEAD(&op_head, op_next); free(op->op_name); free(op->op_value); free(op); @@ -236,20 +235,20 @@ do_option(char *name) bzero(op, sizeof(*op)); op->op_name = ns(name); op->op_value = value ? ns(value) : NULL; - op->op_next = op_head; - op_head = op; + SLIST_INSERT_HEAD(&op_head, op, op_next); } outf = fopen(file, "w"); if (outf == 0) err(1, "%s", file); - for (op = op_head; op != NULL; op = topp) { + while (!SLIST_EMPTY(&op_head)) { + op = SLIST_FIRST(&op_head); /* was the option in the config file? */ if (op->op_value) { fprintf(outf, "#define %s %s\n", op->op_name, op->op_value); } - topp = op->op_next; + SLIST_REMOVE_HEAD(&op_head, op_next); free(op->op_name); free(op->op_value); free(op); @@ -270,7 +269,7 @@ tooption(char *name) /* "cannot happen"? the otab list should be complete.. */ (void) strlcpy(nbuf, "options.h", sizeof(nbuf)); - for (po = otab ; po != 0; po = po->o_next) { + SLIST_FOREACH(po, &otab, o_next) { if (eq(po->o_name, name)) { strlcpy(nbuf, po->o_file, sizeof(nbuf)); break; @@ -294,7 +293,7 @@ read_options(void) int first = 1; char genopt[MAXPATHLEN]; - otab = 0; + SLIST_INIT(&otab); if (ident == NULL) { printf("no ident line specified\n"); exit(1); @@ -340,7 +339,7 @@ next: } val = ns(val); - for (po = otab ; po != 0; po = po->o_next) { + SLIST_FOREACH(po, &otab, o_next) { if (eq(po->o_name, this)) { printf("%s: Duplicate option %s.\n", fname, this); @@ -352,8 +351,7 @@ next: bzero(po, sizeof(*po)); po->o_name = this; po->o_file = val; - po->o_next = otab; - otab = po; + SLIST_INSERT_HEAD(&otab, po, o_next); goto next; } |