Date: Sun, 15 Jul 2001 04:36:42 -0700 From: Dima Dorfman <dima@unixfreak.org> To: audit@freebsd.org Subject: queue(3) patch for config(8) Message-ID: <20010715113642.C42CC3E2F@bazooka.unixfreak.org>
next in thread | raw e-mail | index | archive | help
Attached is a patch which converts config(8) to use the queue(3) API.
Please review.
Index: config.h
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/config.h,v
retrieving revision 1.49
diff -u -r1.49 config.h
--- config.h 2001/07/12 02:08:51 1.49
+++ config.h 2001/07/15 11:35:25
@@ -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;
+ TAILQ_ENTRY(file_list) f_list;
char *f_fn; /* the name */
int f_type; /* type or count */
u_char f_flags; /* see below */
@@ -52,6 +53,8 @@
char *f_needs;
char *f_warn; /* warning message */
};
+TAILQ_HEAD(file_list_headt, file_list);
+extern struct file_list_headt ftab_head;
/*
* Types.
@@ -74,12 +77,14 @@
#define ISDUP 16
struct device {
+ TAILQ_ENTRY(device) d_list;
int d_done; /* processed */
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 */
};
+TAILQ_HEAD(device_headt, device);
+extern struct device_headt dtab_head;
struct config {
char *s_sysname;
@@ -99,9 +104,11 @@
* These and the options (below) are put in the C flags in the makefile.
*/
struct cputype {
+ LIST_ENTRY(cputype) cpu_list;
char *cpu_name;
- struct cputype *cpu_next;
-} *cputype;
+};
+LIST_HEAD(cputype_headt, cputype);
+extern struct cputype_headt cputype_head;
/*
* A set of options may also be specified which are like CPU types,
@@ -109,17 +116,20 @@
* A separate set of options may be defined for make-style options.
*/
struct opt {
+ LIST_ENTRY(opt) op_list;
char *op_name;
char *op_value;
int op_ownfile; /* true = own file, false = makefile */
- struct opt *op_next;
-} *opt, *mkopt;
+};
+LIST_HEAD(opt_headt, opt);
+extern struct opt_headt opt_head, mkopt_head;
struct opt_list {
+ LIST_ENTRY(opt_list) o_list;
char *o_name;
char *o_file;
- struct opt_list *o_next;
} *otab;
+LIST_HEAD(opt_list_headt, opt_list);
extern char *ident;
extern char *hints;
@@ -138,13 +148,9 @@
void makefile(void);
void headers(void);
-extern struct device *dtab;
-
extern char errbuf[80];
extern int yyline;
extern const char *yyfile;
-
-extern struct file_list *ftab;
extern int profiling;
extern int debugging;
Index: config.y
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/config.y,v
retrieving revision 1.55
diff -u -r1.55 config.y
--- config.y 2001/07/12 02:08:51 1.55
+++ config.y 2001/07/15 11:35:25
@@ -71,15 +71,13 @@
#include "config.h"
-static struct device *curp = 0;
-
-struct device *dtab;
+struct device_headt dtab_head;
char *ident;
char *hints;
int hintmode;
int yyline;
const char *yyfile;
-struct file_list *ftab;
+struct file_list_headt ftab_head;
char errbuf[80];
int maxusers;
@@ -130,8 +128,7 @@
(struct cputype *)malloc(sizeof (struct cputype));
memset(cp, 0, sizeof(*cp));
cp->cpu_name = $2;
- cp->cpu_next = cputype;
- cputype = cp;
+ LIST_INSERT_HEAD(&cputype_head, cp, cpu_list);
} |
OPTIONS Opt_list
|
@@ -163,7 +160,7 @@
System_id:
Save_id
- = { newopt(&mkopt, ns("KERNEL"), $1); };
+ = { newopt(&mkopt_head, ns("KERNEL"), $1); };
System_parameter_list:
System_parameter_list ID
@@ -181,14 +178,14 @@
= {
char *s;
- newopt(&opt, $1, NULL);
+ newopt(&opt_head, $1, NULL);
if ((s = strchr($1, '=')))
errx(1, "%s:%d: The `=' in options should not be "
"quoted", yyfile, yyline);
} |
Save_id EQUALS Opt_value
= {
- newopt(&opt, $1, $3);
+ newopt(&opt_head, $1, $3);
} ;
Opt_value:
@@ -215,7 +212,7 @@
Mkoption:
Save_id EQUALS Opt_value
- = { newopt(&mkopt, $1, $3); } ;
+ = { newopt(&mkopt_head, $1, $3); } ;
Dev:
ID
@@ -225,13 +222,13 @@
Device_spec:
DEVICE Dev
= {
- newopt(&opt, devopt($2), ns("1"));
+ newopt(&opt_head, devopt($2), ns("1"));
/* and the device part */
newdev($2, UNKNOWN);
} |
DEVICE Dev NUMBER
= {
- newopt(&opt, devopt($2), ns("1"));
+ newopt(&opt_head, devopt($2), ns("1"));
/* and the device part */
newdev($2, $3);
if ($3 == 0)
@@ -260,16 +257,11 @@
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;
+ TAILQ_INSERT_TAIL(&dtab_head, np, d_list);
}
static void
-newopt(struct opt **list, char *name, char *value)
+newopt(struct opt_headt *headp, char *name, char *value)
{
struct opt *op;
@@ -278,6 +270,5 @@
op->op_name = name;
op->op_ownfile = 0;
op->op_value = value;
- op->op_next = *list;
- *list = op;
+ LIST_INSERT_HEAD(headp, op, op_list);
}
Index: main.c
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/main.c,v
retrieving revision 1.53
diff -u -r1.53 main.c
--- main.c 2001/07/12 02:08:51 1.53
+++ main.c 2001/07/15 11:35:25
@@ -143,7 +143,7 @@
else if ((buf.st_mode & S_IFMT) != S_IFDIR)
errx(2, "%s isn't a directory", p);
- dtab = NULL;
+ TAILQ_INIT(&dtab_head);
yyfile = *argv;
if (yyparse())
exit(3);
@@ -421,7 +421,7 @@
remember("y.tab.h");
remember("setdefs.h");
- for (fl = ftab; fl != NULL; fl = fl->f_next)
+ TAILQ_FOREACH(fl, &ftab_head, f_list)
remember(fl->f_fn);
/*
Index: mkheaders.c
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/mkheaders.c,v
retrieving revision 1.22
diff -u -r1.22 mkheaders.c
--- mkheaders.c 2001/01/31 11:18:49 1.22
+++ mkheaders.c 2001/07/15 11:35:25
@@ -62,10 +62,10 @@
struct device *dp;
int match;
- for (fl = ftab; fl != 0; fl = fl->f_next) {
+ TAILQ_FOREACH(fl, &ftab_head, f_list) {
if (fl->f_needs != 0) {
match = 0;
- for (dp = dtab; dp != 0; dp = dp->d_next) {
+ TAILQ_FOREACH(dp, &dtab_head, d_list) {
if (eq(dp->d_name, fl->f_needs)) {
match++;
dp->d_done |= DEVDONE;
@@ -75,7 +75,7 @@
do_header(fl->f_needs, match);
}
}
- for (dp = dtab; dp != 0; dp = dp->d_next) {
+ TAILQ_FOREACH(dp, &dtab_head, d_list) {
if (!(dp->d_done & DEVDONE))
errx(1, "Error: device \"%s\" is unknown",
dp->d_name);
@@ -86,7 +86,8 @@
do_header(char *dev, int match)
{
char *file, *name, *inw;
- struct file_list *fl, *fl_head, *tflp;
+ struct file_list *fl;
+ struct file_list_headt localfl_head;
struct device *dp;
FILE *inf, *outf;
int inc, oldcount;
@@ -97,7 +98,8 @@
* and "hicount" will be the highest unit declared. do_header()
* must use this higher of these values.
*/
- for (hicount = count = 0, dp = dtab; dp != 0; dp = dp->d_next) {
+ hicount = count = 0;
+ TAILQ_FOREACH(dp, &dtab_head, d_list) {
if (eq(dp->d_name, dev)) {
count =
dp->d_count != UNKNOWN ? dp->d_count : 1;
@@ -119,7 +121,7 @@
(void) fclose(outf);
return;
}
- fl_head = NULL;
+ TAILQ_INIT(&localfl_head);
for (;;) {
char *cp;
if ((inw = get_word(inf)) == 0 || inw == (char *)EOF)
@@ -142,13 +144,13 @@
bzero(fl, sizeof(*fl));
fl->f_fn = inw; /* malloced */
fl->f_type = inc;
- fl->f_next = fl_head;
- fl_head = fl;
+ TAILQ_INSERT_HEAD(&localfl_head, fl, f_list);
}
(void) fclose(inf);
if (count == oldcount) {
- for (fl = fl_head; fl != NULL; fl = tflp) {
- tflp = fl->f_next;
+ while (!TAILQ_EMPTY(&localfl_head)) {
+ fl = TAILQ_FIRST(&localfl_head);
+ TAILQ_REMOVE(&localfl_head, fl, f_list);
free(fl->f_fn);
free(fl);
}
@@ -159,16 +161,16 @@
bzero(fl, sizeof(*fl));
fl->f_fn = ns(name);
fl->f_type = count;
- fl->f_next = fl_head;
- fl_head = fl;
+ TAILQ_INSERT_HEAD(&localfl_head, fl, f_list);
}
outf = fopen(file, "w");
if (outf == 0)
err(1, "%s", file);
- for (fl = fl_head; fl != NULL; fl = tflp) {
+ while (!TAILQ_EMPTY(&localfl_head)) {
+ fl = TAILQ_FIRST(&localfl_head);
+ TAILQ_REMOVE(&localfl_head, fl, f_list);
fprintf(outf,
"#define %s %u\n", fl->f_fn, count ? fl->f_type : 0);
- tflp = fl->f_next;
free(fl->f_fn);
free(fl);
}
Index: mkmakefile.c
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/mkmakefile.c,v
retrieving revision 1.68
diff -u -r1.68 mkmakefile.c
--- mkmakefile.c 2001/02/28 02:53:32 1.68
+++ mkmakefile.c 2001/07/15 11:35:25
@@ -69,8 +69,6 @@
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 @@
{
struct file_list *fp;
- for (fp = ftab ; fp != 0; fp = fp->f_next) {
+ TAILQ_FOREACH(fp, &ftab_head, f_list) {
if (eq(fp->f_fn, file))
return (fp);
}
@@ -105,11 +103,7 @@
fp = (struct file_list *) malloc(sizeof *fp);
bzero(fp, sizeof *fp);
- if (fcur == 0)
- fcur = ftab = fp;
- else
- fcur->f_next = fp;
- fcur = fp;
+ TAILQ_INSERT_TAIL(&ftab_head, fp, f_list);
return (fp);
}
@@ -142,12 +136,12 @@
if (profiling)
fprintf(ofp, " -DGPROF");
- if (cputype == 0) {
+ if (LIST_EMPTY(&cputype_head)) {
printf("cpu type must be specified\n");
exit(1);
}
fprintf(ofp, "\n");
- for (op = mkopt; op; op = op->op_next)
+ LIST_FOREACH(op, &mkopt_head, op_list)
fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
if (debugging)
fprintf(ofp, "DEBUG=-g\n");
@@ -254,7 +248,7 @@
/*
* Read in the information about files used in making the system.
- * Store it in the ftab linked list.
+ * Store it in the ftab_head list.
*/
static void
read_files(void)
@@ -268,7 +262,7 @@
int nreqs, first = 1, isdup, std, filetype,
imp_rule, no_obj, needcount, before_depend, mandatory;
- ftab = 0;
+ TAILQ_INIT(&ftab_head);
if (ident == NULL) {
printf("no ident line specified\n");
exit(1);
@@ -428,7 +422,7 @@
needs = ns(wd);
if (isdup)
goto invis;
- for (dp = dtab; dp != 0; dp = dp->d_next)
+ TAILQ_FOREACH(dp, &dtab_head, d_list)
if (eq(dp->d_name, wd)) {
if (std && dp->d_count <= 0)
dp->d_count = 1;
@@ -444,7 +438,7 @@
this, wd);
exit(1);
}
- for (op = opt; op != 0; op = op->op_next)
+ LIST_FOREACH(op, &opt_head, op_list)
if (op->op_value == 0 && opteq(op->op_name, wd)) {
if (nreqs == 1) {
free(needs);
@@ -531,7 +525,7 @@
fputs("BEFORE_DEPEND=", fp);
lpos = 15;
- for (tp = ftab; tp; tp = tp->f_next)
+ TAILQ_FOREACH(tp, &ftab_head, f_list)
if (tp->f_flags & BEFORE_DEPEND) {
len = strlen(tp->f_fn);
if ((len = 3 + len) + lpos > 72) {
@@ -557,7 +551,7 @@
fprintf(fp, "OBJS=");
lpos = 6;
- for (tp = ftab; tp != 0; tp = tp->f_next) {
+ TAILQ_FOREACH(tp, &ftab_head, f_list) {
if (tp->f_type == INVISIBLE || tp->f_flags & NO_OBJ)
continue;
sp = tail(tp->f_fn);
@@ -593,7 +587,7 @@
fprintf(fp, "%sFILES=", SUFF);
lpos = 8;
- for (tp = ftab; tp; tp = tp->f_next)
+ TAILQ_FOREACH(tp, &ftab_head, f_list)
if (tp->f_type != INVISIBLE && tp->f_type != NODEPEND) {
len = strlen(tp->f_fn);
if (tp->f_fn[len - slen - 1] != '.')
@@ -636,7 +630,7 @@
struct file_list *ftp;
char *compilewith;
- for (ftp = ftab; ftp != 0; ftp = ftp->f_next) {
+ TAILQ_FOREACH(ftp, &ftab_head, f_list) {
if (ftp->f_type == INVISIBLE)
continue;
if (ftp->f_warn)
@@ -702,7 +696,7 @@
fputs("CLEAN=", fp);
lpos = 7;
- for (tp = ftab; tp; tp = tp->f_next)
+ TAILQ_FOREACH(tp, &ftab_head, f_list)
if (tp->f_clean) {
len = strlen(tp->f_clean);
if (len + lpos > 72) {
Index: mkoptions.c
===================================================================
RCS file: /stl/src/FreeBSD/src/usr.sbin/config/mkoptions.c,v
retrieving revision 1.28
diff -u -r1.28 mkoptions.c
--- mkoptions.c 2001/02/28 02:07:47 1.28
+++ mkoptions.c 2001/07/15 11:35:25
@@ -52,6 +52,11 @@
#include "config.h"
#include "y.tab.h"
+struct cputype_headt cputype_head = LIST_HEAD_INITIALIZER(cputype_head);
+struct opt_headt opt_head = LIST_HEAD_INITIALIZER(opt_head);
+struct opt_headt mkopt_head = LIST_HEAD_INITIALIZER(mkopt_head);
+struct opt_list_headt otab_head = LIST_HEAD_INITIALIZER(otab_head);
+
static struct users {
int u_default;
int u_min;
@@ -72,12 +77,11 @@
struct opt *op;
/* Fake the cpu types as options. */
- for (cp = cputype; cp != NULL; cp = cp->cpu_next) {
+ LIST_FOREACH(cp, &cputype_head, cpu_list) {
op = (struct opt *)malloc(sizeof(*op));
memset(op, 0, sizeof(*op));
op->op_name = ns(cp->cpu_name);
- op->op_next = opt;
- opt = op;
+ LIST_INSERT_HEAD(&opt_head, op, op_list);
}
if (maxusers == 0) {
@@ -95,13 +99,12 @@
op->op_name = ns("MAXUSERS");
snprintf(buf, sizeof(buf), "%d", maxusers);
op->op_value = ns(buf);
- op->op_next = opt;
- opt = op;
+ LIST_INSERT_HEAD(&opt_head, op, op_list);
read_options();
- for (ol = otab; ol != 0; ol = ol->o_next)
+ LIST_FOREACH(ol, &otab_head, o_list)
do_option(ol->o_name);
- for (op = opt; op; op = op->op_next) {
+ LIST_FOREACH(op, &opt_head, op_list) {
if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
printf("%s: unknown option \"%s\"\n",
PREFIX, op->op_name);
@@ -120,7 +123,8 @@
char *file, *inw;
const char *basefile;
struct opt_list *ol;
- struct opt *op, *op_head, *topp;
+ struct opt *op;
+ struct opt_headt localopt_head;
FILE *inf, *outf;
char *value;
char *oldvalue;
@@ -133,7 +137,7 @@
* Check to see if the option was specified..
*/
value = NULL;
- for (op = opt; op; op = op->op_next) {
+ LIST_FOREACH(op, &opt_head, op_list) {
if (eq(name, op->op_name)) {
oldvalue = value;
value = op->op_value;
@@ -164,13 +168,13 @@
return;
}
basefile = "";
- for (ol = otab; ol != 0; ol = ol->o_next)
+ LIST_FOREACH(ol, &otab_head, o_list)
if (eq(name, ol->o_name)) {
basefile = ol->o_file;
break;
}
oldvalue = NULL;
- op_head = NULL;
+ LIST_INIT(&localopt_head);
seen = 0;
tidy = 0;
for (;;) {
@@ -194,7 +198,7 @@
invalue = value;
seen++;
}
- for (ol = otab; ol != 0; ol = ol->o_next)
+ LIST_FOREACH(ol, &otab_head, o_list)
if (eq(inw, ol->o_name))
break;
if (!eq(inw, name) && !ol) {
@@ -210,8 +214,7 @@
bzero(op, sizeof(*op));
op->op_name = inw;
op->op_value = invalue;
- op->op_next = op_head;
- op_head = op;
+ LIST_INSERT_HEAD(&localopt_head, op, op_list);
}
/* EOL? */
@@ -221,9 +224,10 @@
}
(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;
+ (value && oldvalue && eq(value, oldvalue)))) {
+ while (!LIST_EMPTY(&localopt_head)) {
+ op = LIST_FIRST(&localopt_head);
+ LIST_REMOVE(op, op_list);
free(op->op_name);
free(op->op_value);
free(op);
@@ -237,20 +241,20 @@
bzero(op, sizeof(*op));
op->op_name = ns(name);
op->op_value = value ? ns(value) : NULL;
- op->op_next = op_head;
- op_head = op;
+ LIST_INSERT_HEAD(&localopt_head, op, op_list);
}
outf = fopen(file, "w");
if (outf == 0)
err(1, "%s", file);
- for (op = op_head; op != NULL; op = topp) {
+ while (!LIST_EMPTY(&localopt_head)) {
+ op = LIST_FIRST(&localopt_head);
+ LIST_REMOVE(op, op_list);
/* 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;
free(op->op_name);
free(op->op_value);
free(op);
@@ -271,7 +275,7 @@
/* "cannot happen"? the otab list should be complete.. */
(void) strlcpy(nbuf, "options.h", sizeof(nbuf));
- for (po = otab ; po != 0; po = po->o_next) {
+ LIST_FOREACH(po, &otab_head, o_list) {
if (eq(po->o_name, name)) {
strlcpy(nbuf, po->o_file, sizeof(nbuf));
break;
@@ -341,7 +345,7 @@
}
val = ns(val);
- for (po = otab ; po != 0; po = po->o_next) {
+ LIST_FOREACH(po, &otab_head, o_list) {
if (eq(po->o_name, this)) {
printf("%s: Duplicate option %s.\n",
fname, this);
@@ -353,8 +357,7 @@
bzero(po, sizeof(*po));
po->o_name = this;
po->o_file = val;
- po->o_next = otab;
- otab = po;
+ LIST_INSERT_HEAD(&otab_head, po, o_list);
goto next;
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010715113642.C42CC3E2F>
