diff options
author | Igor Sobrado <sobrado@cvs.openbsd.org> | 2008-07-27 13:15:32 +0000 |
---|---|---|
committer | Igor Sobrado <sobrado@cvs.openbsd.org> | 2008-07-27 13:15:32 +0000 |
commit | fe6d48567f4f141c99d0b24747c7b00ec1ba0d07 (patch) | |
tree | 098198dd0aca54ee176e945ad1da15c2105e9b03 /usr.bin | |
parent | 26fdd7a0baaf1b8f323815c7a27bea1e8ecb226a (diff) |
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@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/compress/compress.h | 13 | ||||
-rw-r--r-- | 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 <sys/param.h> @@ -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" |