From c1f61844c36e418273555752390fe62cd6b3f3e2 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 22 Feb 2001 03:40:50 +0000 Subject: 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. --- usr.sbin/config/config.h | 1 - usr.sbin/config/config.y | 84 ++++++++++++++++----------------------------- usr.sbin/config/mkoptions.c | 8 ++--- 3 files changed, 33 insertions(+), 60 deletions(-) (limited to 'usr.sbin') 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++; } -- cgit v1.1