summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-02-22 03:40:50 +0000
committerpeter <peter@FreeBSD.org>2001-02-22 03:40:50 +0000
commitc1f61844c36e418273555752390fe62cd6b3f3e2 (patch)
tree7169f7f4ade09e281e4b7287b5842ed199d17d66 /usr.sbin
parentbfd047a3c936c2ea237d09f71e53f3b02aae1497 (diff)
downloadFreeBSD-src-c1f61844c36e418273555752390fe62cd6b3f3e2.zip
FreeBSD-src-c1f61844c36e418273555752390fe62cd6b3f3e2.tar.gz
Collect together a handful of copies of the option generator code into a
single newopt(char *name, char *value) function. Change newdev() to do the same thing rather than depending on the evil 'cur' device hack.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/config/config.h1
-rw-r--r--usr.sbin/config/config.y84
-rw-r--r--usr.sbin/config/mkoptions.c8
3 files changed, 33 insertions, 60 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h
index 594480e..3beda71 100644
--- a/usr.sbin/config/config.h
+++ b/usr.sbin/config/config.h
@@ -113,7 +113,6 @@ struct cputype {
struct opt {
char *op_name;
char *op_value;
- int op_line; /* line number for error-reporting */
int op_ownfile; /* true = own file, false = makefile */
struct opt *op_next;
} *opt, *mkopt;
diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y
index d6247be..5ddfb9b 100644
--- a/usr.sbin/config/config.y
+++ b/usr.sbin/config/config.y
@@ -70,7 +70,6 @@
#include "config.h"
-static struct device cur;
static struct device *curp = 0;
struct device *dtab;
@@ -110,7 +109,7 @@ Many_specs:
Spec:
Device_spec SEMICOLON
- = { newdev(&cur); } |
+ |
Config_spec SEMICOLON
|
SEMICOLON
@@ -160,14 +159,7 @@ System_spec:
System_id:
Save_id
= {
- struct opt *op = (struct opt *)malloc(sizeof (struct opt));
- memset(op, 0, sizeof(*op));
- op->op_name = ns("KERNEL");
- op->op_ownfile = 0;
- op->op_next = mkopt;
- op->op_value = $1;
- op->op_line = yyline + 1;
- mkopt = op;
+ newopt(ns("KERNEL"), $1);
};
System_parameter_list:
@@ -184,30 +176,15 @@ Opt_list:
Option:
Save_id
= {
- struct opt *op = (struct opt *)malloc(sizeof (struct opt));
char *s;
- memset(op, 0, sizeof(*op));
- op->op_name = $1;
- op->op_next = opt;
- op->op_value = 0;
- /*
- * op->op_line is 1-based; yyline is 0-based but is now 1
- * larger than when `Save_id' was lexed.
- */
- op->op_line = yyline;
- opt = op;
- if ((s = strchr(op->op_name, '=')))
+
+ newopt($1, NULL);
+ if ((s = strchr($1, '=')))
errx(1, "line %d: The `=' in options should not be quoted", yyline);
} |
Save_id EQUALS Opt_value
= {
- struct opt *op = (struct opt *)malloc(sizeof (struct opt));
- memset(op, 0, sizeof(*op));
- op->op_name = $1;
- op->op_next = opt;
- op->op_value = $3;
- op->op_line = yyline + 1;
- opt = op;
+ newopt($1, $3);
} ;
Opt_value:
@@ -238,10 +215,8 @@ Mkoption:
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
op->op_name = $1;
- op->op_ownfile = 0; /* for now */
- op->op_next = mkopt;
op->op_value = $3;
- op->op_line = yyline + 1;
+ op->op_next = mkopt;
mkopt = op;
} ;
@@ -253,30 +228,16 @@ Dev:
Device_spec:
DEVICE Dev
= {
- struct opt *op = (struct opt *)malloc(sizeof (struct opt));
- memset(op, 0, sizeof(*op));
- op->op_name = devopt($2);
- op->op_next = opt;
- op->op_value = ns("1");
- op->op_line = yyline;
- opt = op;
+ newopt(devopt($2), ns("1"));
/* and the device part */
- cur.d_name = $2;
- cur.d_count = UNKNOWN;
+ newdev($2, UNKNOWN);
} |
DEVICE Dev NUMBER
= {
- struct opt *op = (struct opt *)malloc(sizeof (struct opt));
- memset(op, 0, sizeof(*op));
- op->op_name = devopt($2);
- op->op_next = opt;
- op->op_value = ns("1");
- op->op_line = yyline;
- opt = op;
+ newopt(devopt($2), ns("1"));
/* and the device part */
- cur.d_name = $2;
- cur.d_count = $3;
- if (cur.d_count == 0)
+ newdev($2, $3);
+ if ($3 == 0)
errx(1, "line %d: devices with zero units are not likely to be correct", yyline);
} ;
@@ -293,15 +254,14 @@ yyerror(const char *s)
* add a device to the list of devices
*/
static void
-newdev(struct device *dp)
+newdev(char *name, int count)
{
struct device *np;
np = (struct device *) malloc(sizeof *np);
memset(np, 0, sizeof(*np));
- *np = *dp;
- np->d_name = dp->d_name;
- np->d_count = dp->d_count;
+ np->d_name = name;
+ np->d_count = count;
np->d_next = 0;
if (curp == 0)
dtab = np;
@@ -309,3 +269,17 @@ newdev(struct device *dp)
curp->d_next = np;
curp = np;
}
+
+static void
+newopt(char *name, char *value)
+{
+ struct opt *op;
+
+ op = (struct opt *)malloc(sizeof (struct opt));
+ memset(op, 0, sizeof(*op));
+ op->op_name = name;
+ op->op_ownfile = 0;
+ op->op_value = value;
+ op->op_next = opt;
+ opt = op;
+}
diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c
index 1b8b332..4cfa098 100644
--- a/usr.sbin/config/mkoptions.c
+++ b/usr.sbin/config/mkoptions.c
@@ -103,8 +103,8 @@ options(void)
do_option(ol->o_name);
for (op = opt; op; op = op->op_next) {
if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) {
- printf("%s:%d: unknown option \"%s\"\n",
- PREFIX, op->op_line, op->op_name);
+ printf("%s: unknown option \"%s\"\n",
+ PREFIX, op->op_name);
exit(1);
}
}
@@ -141,8 +141,8 @@ do_option(char *name)
value = ns("1");
if (oldvalue != NULL && !eq(value, oldvalue))
printf(
- "%s:%d: option \"%s\" redefined from %s to %s\n",
- PREFIX, op->op_line, op->op_name, oldvalue,
+ "%s: option \"%s\" redefined from %s to %s\n",
+ PREFIX, op->op_name, oldvalue,
value);
op->op_ownfile++;
}
OpenPOWER on IntegriCloud