From 1c5ef3d323ddde4737d89ed23f6e66d3e2089419 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 8 Mar 2004 03:22:46 +0000 Subject: [PATCH] Config cleanup part 1/3: Remove old style C cruft and cleanup some variable names. Submitted-by: Chris Pressey --- usr.sbin/config/config.y | 21 ++++++------- usr.sbin/config/lang.l | 6 ++-- usr.sbin/config/main.c | 61 ++++++++++++++++--------------------- usr.sbin/config/mkoptions.c | 6 ++-- 4 files changed, 43 insertions(+), 51 deletions(-) diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index bbfa4d2efb..a92cb9b64c 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -83,7 +83,7 @@ * * @(#)config.y 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/config.y,v 1.42.2.1 2001/01/23 00:09:32 peter Exp $ - * $DragonFly: src/usr.sbin/config/config.y,v 1.7 2004/03/04 20:44:49 eirikn Exp $ + * $DragonFly: src/usr.sbin/config/config.y,v 1.8 2004/03/08 03:22:46 dillon Exp $ */ #include @@ -145,7 +145,7 @@ Config_spec: struct cputype *cp; cp = (struct cputype *)malloc(sizeof(struct cputype)); - memset(cp, 0, sizeof(*cp)); + bzero(cp, sizeof(*cp)); cp->cpu_name = $2; cp->cpu_next = cputype; cputype = cp; @@ -174,7 +174,7 @@ System_id: struct opt *op; op = (struct opt *)malloc(sizeof(struct opt)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = ns("KERNEL"); op->op_ownfile = 0; op->op_next = mkopt; @@ -233,10 +233,9 @@ Option: Save_id = { struct opt *op; - char *s; op = (struct opt *)malloc(sizeof(struct opt)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = $1; op->op_next = opt; op->op_value = 0; @@ -246,7 +245,7 @@ Option: */ op->op_line = yyline; opt = op; - if ((s = strchr(op->op_name, '='))) + if (strchr(op->op_name, '=') != NULL) errx(1, "line %d: The `=' in options should not be quoted", yyline); } | Save_id EQUALS Opt_value @@ -254,7 +253,7 @@ Option: struct opt *op; op = (struct opt *)malloc(sizeof(struct opt)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = $1; op->op_next = opt; op->op_value = $3; @@ -290,7 +289,7 @@ Mkoption: struct opt *op; op = (struct opt *)malloc(sizeof(struct opt)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = $1; op->op_ownfile = 0; /* for now */ op->op_next = mkopt; @@ -429,7 +428,7 @@ newdev(struct device *dp) } } np = (struct device *)malloc(sizeof(*np)); - memset(np, 0, sizeof(*np)); + bzero(np, sizeof(*np)); *np = *dp; np->d_next = NULL; if (curp == NULL) @@ -486,8 +485,8 @@ init_dev(struct device *dp) dp->d_conn = 0; dp->d_disabled = 0; dp->d_flags = 0; - dp->d_bus = dp->d_lun = dp->d_target = dp->d_drive = dp->d_unit = \ - dp->d_count = UNKNOWN; + dp->d_bus = dp->d_lun = dp->d_target = dp->d_drive = dp->d_unit = + dp->d_count = UNKNOWN; dp->d_port = NULL; dp->d_portn = -1; dp->d_irq = -1; diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index fef434f17c..d3e4c44b85 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -33,7 +33,7 @@ * * @(#)lang.l 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/lang.l,v 1.27 1999/11/09 07:20:22 peter Exp $ - * $DragonFly: src/usr.sbin/config/lang.l,v 1.6 2004/03/04 20:44:49 eirikn Exp $ + * $DragonFly: src/usr.sbin/config/lang.l,v 1.7 2004/03/08 03:22:46 dillon Exp $ */ #include @@ -98,7 +98,7 @@ ID [A-Za-z_][-A-Za-z_0-9]* if ((i = kw_lookup(yytext)) == -1) { yylval.str = strdup(yytext); - return ID; + return(ID); } return(i); } @@ -206,6 +206,6 @@ hex(char *str) { int num; - (void)sscanf(str+2, "%x", &num); + (void)sscanf(str + 2, "%x", &num); return(num); } diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index be4d428fa1..4e866b26e8 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/main.c,v 1.37.2.3 2001/06/13 00:25:53 cg Exp $ - * $DragonFly: src/usr.sbin/config/main.c,v 1.10 2004/03/04 20:44:49 eirikn Exp $ + * $DragonFly: src/usr.sbin/config/main.c,v 1.11 2004/03/08 03:22:46 dillon Exp $ */ #include @@ -76,11 +76,13 @@ static void usage(void); * system given a description of the desired system. */ int -main(int argc, char **argv) +main(int argc, char *argv[]) { struct stat buf; - int ch, len; + int ch, len, i; char *p; + char linksrc[64], linkdest[MAXPATHLEN]; + static char *emus[] = { "linux", "svr4" }; while ((ch = getopt(argc, argv, "d:gprn")) != -1) switch (ch) { @@ -158,57 +160,48 @@ main(int argc, char **argv) exit(1); } newbus_ioconf(); + /* * make symbolic links in compilation directory * for "sys" (to make genassym.c work along with #include ) * and similarly for "machine". */ - { - char xxx[MAXPATHLEN]; if (*srcdir == '\0') - (void)snprintf(xxx, sizeof(xxx), "../../%s/include", + snprintf(linkdest, sizeof(linkdest), "../../%s/include", machinename); else - (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", + snprintf(linkdest, sizeof(linkdest), "%s/%s/include", srcdir, machinename); - (void)symlink(xxx, path("machine")); - } + symlink(linkdest, path("machine")); /* * XXX check directory structure for architecture subdirectories and * create the symlinks automatically XXX */ - { - char xxx[MAXPATHLEN]; if (*srcdir == '\0') - (void)snprintf(xxx, sizeof(xxx), "../../../../../net/i4b/include/%s", + snprintf(linkdest, sizeof(linkdest), + "../../../../../net/i4b/include/%s", machinename); else - (void)snprintf(xxx, sizeof(xxx), "%s/net/i4b/include/%s", + snprintf(linkdest, sizeof(linkdest), "%s/net/i4b/include/%s", srcdir, machinename); - (void)mkdir(path("net"), 0755); - (void)mkdir(path("net/i4b"), 0755); - (void)mkdir(path("net/i4b/include"), 0755); - (void)symlink(xxx, path("net/i4b/include/machine")); - } + mkdir(path("net"), 0755); + mkdir(path("net/i4b"), 0755); + mkdir(path("net/i4b/include"), 0755); + symlink(linkdest, path("net/i4b/include/machine")); - { - static char *ary[] = { "linux", "svr4" }; - char xxx[MAXPATHLEN]; - char yyy[64]; - int i; - - for (i = 0; i < sizeof(ary) / sizeof(ary[0]); ++i) { + for (i = 0; i < sizeof(emus) / sizeof(emus[0]); ++i) { if (*srcdir == 0) { - snprintf(xxx, sizeof(xxx), "../../emulation/%s/%s", - ary[i], machinename); + snprintf(linkdest, sizeof(linkdest), + "../../emulation/%s/%s", + emus[i], machinename); } else { - snprintf(xxx, sizeof(xxx), "%s/emulation/%s/%s", - srcdir, ary[i], machinename); + snprintf(linkdest, sizeof(linkdest), + "%s/emulation/%s/%s", + srcdir, emus[i], machinename); } - snprintf(yyy, sizeof(yyy), "arch_%s", ary[i]); - symlink(xxx, path(yyy)); - } + snprintf(linksrc, sizeof(linksrc), "arch_%s", emus[i]); + symlink(linkdest, path(linksrc)); } options(); /* make options .h files */ @@ -216,7 +209,7 @@ main(int argc, char **argv) headers(); /* make a lot of .h files */ configfile(); /* put config file into kernel*/ printf("Kernel build directory is %s\n", p); - exit(0); + exit(EX_OK); } /* @@ -305,7 +298,7 @@ begin: break; if (ch == EOF) return((char *)EOF); - if (ch == '\\'){ + if (ch == '\\') { escaped_nl = 1; goto begin; } diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c index 8f0a31d3d1..6c391553c8 100644 --- a/usr.sbin/config/mkoptions.c +++ b/usr.sbin/config/mkoptions.c @@ -33,7 +33,7 @@ * * @(#)mkheaders.c 8.1 (Berkeley) 6/6/93 * $FreeBSD: src/usr.sbin/config/mkoptions.c,v 1.17.2.3 2001/12/13 19:18:01 dillon Exp $ - * $DragonFly: src/usr.sbin/config/mkoptions.c,v 1.9 2004/03/05 08:03:31 dillon Exp $ + * $DragonFly: src/usr.sbin/config/mkoptions.c,v 1.10 2004/03/08 03:22:46 dillon Exp $ */ /* @@ -64,7 +64,7 @@ options(void) /* Fake the cpu types as options. */ for (cp = cputype; cp != NULL; cp = cp->cpu_next) { op = (struct opt *)malloc(sizeof(*op)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = ns(cp->cpu_name); op->op_next = opt; opt = op; @@ -82,7 +82,7 @@ options(void) /* Fake MAXUSERS as an option. */ op = (struct opt *)malloc(sizeof(*op)); - memset(op, 0, sizeof(*op)); + bzero(op, sizeof(*op)); op->op_name = "MAXUSERS"; snprintf(buf, sizeof(buf), "%d", maxusers); op->op_value = ns(buf); -- 2.41.0