diff options
author | Igor Sobrado <sobrado@cvs.openbsd.org> | 2008-07-05 20:59:43 +0000 |
---|---|---|
committer | Igor Sobrado <sobrado@cvs.openbsd.org> | 2008-07-05 20:59:43 +0000 |
commit | b6b1220e381f37313983becedd054f288b95ba47 (patch) | |
tree | f48b3593160d67cd530f93e32b3ce915b7f7d5fa /usr.bin | |
parent | 44763bd82d4330d4f0221de9ea65e0aee7e2ff8e (diff) |
each utility must have its own usage and its own set of options;
b64encode and b64decode are equivalent to running uuencode and uudecode
respectively with the -m flag specified, so this flag should not be
available in these utilities; while here, fix synopsis.
based on millert's diff for compress/gzip.
ok millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/uudecode/uudecode.c | 57 | ||||
-rw-r--r-- | usr.bin/uuencode/uuencode.1 | 6 | ||||
-rw-r--r-- | usr.bin/uuencode/uuencode.c | 46 |
3 files changed, 75 insertions, 34 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c index 11b26076ca0..cbe70add09c 100644 --- a/usr.bin/uudecode/uudecode.c +++ b/usr.bin/uudecode/uudecode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uudecode.c,v 1.14 2004/04/09 22:54:02 millert Exp $ */ +/* $OpenBSD: uudecode.c,v 1.15 2008/07/05 20:59:42 sobrado Exp $ */ /* $FreeBSD: uudecode.c,v 1.49 2003/05/03 19:44:46 obrien Exp $ */ /*- @@ -40,7 +40,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; #endif -static const char rcsid[] = "$OpenBSD: uudecode.c,v 1.14 2004/04/09 22:54:02 millert Exp $"; +static const char rcsid[] = "$OpenBSD: uudecode.c,v 1.15 2008/07/05 20:59:42 sobrado Exp $"; #endif /* not lint */ /* @@ -69,27 +69,41 @@ static const char *infile, *outfile; static FILE *infp, *outfp; static int base64, cflag, iflag, oflag, pflag, rflag, sflag; -static void usage(void); +static void usage(int); static int decode(void); static int decode2(void); static int uu_decode(void); static int base64_decode(void); +/* + * program modes + */ +#define MODE_DECODE 0 +#define MODE_B64DECODE 1 + int main(int argc, char *argv[]) { - int rval, ch; + int rval, ch, mode; extern char *__progname; + static const char *optstr[2] = { + "cimo:prs", + "cio:prs" + }; - if (strcmp(__progname, "b64decode") == 0) + mode = 0; + + if (strcmp(__progname, "b64decode") == 0) { base64 = 1; + mode = MODE_B64DECODE; + } setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "cimo:prs")) != -1) { + while ((ch = getopt(argc, argv, optstr[mode])) != -1) { switch(ch) { case 'c': if (oflag || rflag) - usage(); + usage(mode); cflag = 1; /* multiple uudecode'd files */ break; case 'i': @@ -100,28 +114,28 @@ main(int argc, char *argv[]) break; case 'o': if (cflag || pflag || rflag || sflag) - usage(); + usage(mode); oflag = 1; /* output to the specified file */ sflag = 1; /* do not strip pathnames for output */ outfile = optarg; /* set the output filename */ break; case 'p': if (oflag) - usage(); + usage(mode); pflag = 1; /* print output to stdout */ break; case 'r': if (cflag || oflag) - usage(); + usage(mode); rflag = 1; /* decode raw data */ break; case 's': if (oflag) - usage(); + usage(mode); sflag = 1; /* do not strip pathnames for output */ break; default: - usage(); + usage(mode); } } argc -= optind; @@ -436,12 +450,19 @@ base64_decode(void) } static void -usage(void) +usage(int mode) { - (void)fprintf(stderr, - "usage: uudecode [-cimprs] [file ...]\n" - " uudecode [-i] -o output_file [file]\n" - " b64decode [-cimprs] [file ...]\n" - " b64decode [-i] -o output_file [file]\n"); + switch (mode) { + case MODE_DECODE: + (void)fprintf(stderr, + "usage: uudecode [-cimprs] [file ...]\n" + " uudecode [-i] -o output_file [file]\n"); + break; + case MODE_B64DECODE: + (void)fprintf(stderr, + "usage: b64decode [-ciprs] [file ...]\n" + " b64decode [-i] -o output_file [file]\n"); + break; + } exit(1); } diff --git a/usr.bin/uuencode/uuencode.1 b/usr.bin/uuencode/uuencode.1 index 4df67a76913..5ff4ca04efd 100644 --- a/usr.bin/uuencode/uuencode.1 +++ b/usr.bin/uuencode/uuencode.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: uuencode.1,v 1.18 2007/05/31 19:20:19 jmc Exp $ +.\" $OpenBSD: uuencode.1,v 1.19 2008/07/05 20:59:42 sobrado Exp $ .\" $FreeBSD: uuencode.1,v 1.26 2003/03/18 14:24:47 fanf Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 @@ -31,7 +31,7 @@ .\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: July 5 2008 $ .Dt UUENCODE 1 .Os .Sh NAME @@ -52,6 +52,8 @@ .Nm uudecode .Op Fl i .Fl o Ar output_file +.Op Ar file +.Pp .Nm b64encode .Op Fl o Ar output_file .Op Ar file diff --git a/usr.bin/uuencode/uuencode.c b/usr.bin/uuencode/uuencode.c index 4bedc535796..414c9dbf43d 100644 --- a/usr.bin/uuencode/uuencode.c +++ b/usr.bin/uuencode/uuencode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uuencode.c,v 1.7 2004/04/09 22:54:02 millert Exp $ */ +/* $OpenBSD: uuencode.c,v 1.8 2008/07/05 20:59:42 sobrado Exp $ */ /* $FreeBSD: uuencode.c,v 1.18 2004/01/22 07:23:35 grehan Exp $ */ /*- @@ -40,7 +40,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)uuencode.c 8.2 (Berkeley) 4/2/94"; #endif -static const char rcsid[] = "$OpenBSD: uuencode.c,v 1.7 2004/04/09 22:54:02 millert Exp $"; +static const char rcsid[] = "$OpenBSD: uuencode.c,v 1.8 2008/07/05 20:59:42 sobrado Exp $"; #endif /* not lint */ /* @@ -63,29 +63,40 @@ static const char rcsid[] = "$OpenBSD: uuencode.c,v 1.7 2004/04/09 22:54:02 mill void encode(void); void base64_encode(void); -static void usage(void); +static void usage(int); FILE *output; int mode; char **av; +/* + * program modes + */ +#define MODE_ENCODE 0 +#define MODE_B64ENCODE 1 + int main(int argc, char *argv[]) { struct stat sb; - int base64; - int ch; + int base64, ch, mode; char *outfile; extern char *__progname; + static const char *optstr[2] = { + "mo:", + "o:" + }; - base64 = 0; + base64 = mode = 0; outfile = NULL; - if (strcmp(__progname, "b64encode") == 0) + if (strcmp(__progname, "b64encode") == 0) { base64 = 1; + mode = MODE_B64ENCODE; + } setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "mo:")) != -1) { + while ((ch = getopt(argc, argv, optstr[mode])) != -1) { switch (ch) { case 'm': base64 = 1; @@ -95,7 +106,7 @@ main(int argc, char *argv[]) break; case '?': default: - usage(); + usage(mode); } } argv += optind; @@ -115,7 +126,7 @@ main(int argc, char *argv[]) break; case 0: default: - usage(); + usage(mode); } av = argv; @@ -216,10 +227,17 @@ encode(void) } static void -usage(void) +usage(int mode) { - (void)fprintf(stderr, - "usage: uuencode [-m] [-o outfile] [infile] remotefile\n" - " b64encode [-o outfile] [infile] remotefile\n"); + switch (mode) { + case MODE_ENCODE: + (void)fprintf(stderr, + "usage: uuencode [-m] [-o output_file] [file] name\n"); + break; + case MODE_B64ENCODE: + (void)fprintf(stderr, + "usage: b64encode [-o output_file] [file] name\n"); + break; + } exit(1); } |