From dbf8dc76927d83283b1cbb488f59e7e9d26c58f4 Mon Sep 17 00:00:00 2001 From: sobrado Date: Sun, 27 Jul 2008 13:15:31 +0000 Subject: [PATCH] an enum specifier is more elegant than a set of #defines; storing the program mode variable (pmode) as a global let us have a more consistent prototype for usage(). changes suggested by pyr@. ok pyr@ --- usr.bin/compress/compress.h | 13 ++++++------- usr.bin/compress/main.c | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/usr.bin/compress/compress.h b/usr.bin/compress/compress.h index 3a7b635b715..c086a6fe134 100644 --- a/usr.bin/compress/compress.h +++ b/usr.bin/compress/compress.h @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.h,v 1.9 2008/07/05 21:00:38 sobrado Exp $ */ +/* $OpenBSD: compress.h,v 1.10 2008/07/27 13:15:31 sobrado Exp $ */ /* * Copyright (c) 1997 Michael Shalayeff @@ -43,12 +43,11 @@ struct z_info { */ #define Z_BUFSIZE 16384 -/* - * program modes - */ -#define MODE_COMP 0 -#define MODE_DECOMP 1 -#define MODE_CAT 2 +enum program_mode { + MODE_COMP, + MODE_DECOMP, + MODE_CAT +} pmode; /* * exit codes for compress diff --git a/usr.bin/compress/main.c b/usr.bin/compress/main.c index 022a6f9ea1f..ed3f8a07314 100644 --- a/usr.bin/compress/main.c +++ b/usr.bin/compress/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.72 2008/07/05 21:00:38 sobrado Exp $ */ +/* $OpenBSD: main.c,v 1.73 2008/07/27 13:15:31 sobrado Exp $ */ #ifndef SMALL static const char copyright[] = @@ -36,7 +36,7 @@ static const char license[] = #endif /* SMALL */ #ifndef SMALL -static const char main_rcsid[] = "$OpenBSD: main.c,v 1.72 2008/07/05 21:00:38 sobrado Exp $"; +static const char main_rcsid[] = "$OpenBSD: main.c,v 1.73 2008/07/27 13:15:31 sobrado Exp $"; #endif #include @@ -93,7 +93,7 @@ const struct compressor null_method = #endif /* SMALL */ int permission(const char *); -__dead void usage(int, int); +__dead void usage(int); int docompress(const char *, char *, const struct compressor *, int, struct stat *); int dodecompress(const char *, char *, const struct compressor *, @@ -139,14 +139,14 @@ main(int argc, char *argv[]) char *p, *infile; char outfile[MAXPATHLEN], _infile[MAXPATHLEN], suffix[16]; char *nargv[512]; /* some estimate based on ARG_MAX */ - int bits, ch, error, i, rc, cflag, oflag, mode; + int bits, ch, error, i, rc, cflag, oflag; static const char *optstr[3] = { "123456789ab:cdfghlLnNOo:qrS:tvV", "cfhlNno:qrtv", "fghqr" }; - bits = cflag = oflag = mode = 0; + bits = cflag = oflag = 0; storename = -1; p = __progname; if (p[0] == 'g') { @@ -161,15 +161,16 @@ main(int argc, char *argv[]) #endif /* SMALL */ decomp = 0; + pmode = MODE_COMP; if (!strcmp(p, "zcat")) { decomp++; cflag = 1; - mode = MODE_CAT; + pmode = MODE_CAT; } else { if (p[0] == 'u' && p[1] == 'n') { p += 2; decomp++; - mode = MODE_DECOMP; + pmode = MODE_DECOMP; } if (strcmp(p, "zip") && @@ -196,7 +197,7 @@ main(int argc, char *argv[]) argv = nargv; } - while ((ch = getopt_long(argc, argv, optstr[mode], longopts, NULL)) != -1) + while ((ch = getopt_long(argc, argv, optstr[pmode], longopts, NULL)) != -1) switch(ch) { case '1': case '2': @@ -295,10 +296,10 @@ main(int argc, char *argv[]) break; case 'h': - usage(0, mode); + usage(0); break; default: - usage(1, mode); + usage(1); } argc -= optind; argv += optind; @@ -893,9 +894,9 @@ verbose_info(const char *file, off_t compressed, off_t uncompressed, } __dead void -usage(int status, int mode) +usage(int status) { - switch (mode) { + switch (pmode) { case MODE_COMP: fprintf(stderr, "usage: %s [-123456789cdfghLlNnOqrtVv] " "[-b bits] [-o filename] [-S suffix]\n" -- 2.20.1