Add -o option (POSIX.1-2001) to uudecode(1). Deprecate the -p option

(which allows one to redirect output to stdout); `-o /dev/stdout' is
recommended instead.

Submitted by:	Joseph Mallett <jmallett@xMach.org>
MFC after:	2 weeks
This commit is contained in:
mike 2002-01-27 18:21:23 +00:00
parent 9fdf88975b
commit 7e26e18582
2 changed files with 44 additions and 6 deletions

View File

@ -63,7 +63,8 @@ static const char rcsid[] =
#include <unistd.h>
const char *filename;
int cflag, iflag, pflag, sflag;
char *outfile;
int cflag, iflag, oflag, pflag, sflag;
static void usage __P((void));
int decode __P((void));
@ -76,18 +77,32 @@ main(argc, argv)
{
int rval, ch;
while ((ch = getopt(argc, argv, "cips")) != -1) {
while ((ch = getopt(argc, argv, "cio:ps")) != -1) {
switch(ch) {
case 'c':
if (oflag)
usage();
cflag = 1; /* multiple uudecode'd files */
break;
case 'i':
iflag = 1; /* ask before override files */
break;
case 'o':
if (cflag || pflag || sflag)
usage();
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();
warnx("-p is deprecated, use `-o /dev/stdout' instead.");
pflag = 1; /* print output to stdout */
break;
case 's':
if (oflag)
usage();
sflag = 1; /* do not strip pathnames for output */
break;
default:
@ -158,7 +173,14 @@ decode2(flag)
} while (strncmp(buf, "begin ", 6) ||
fnmatch("begin [0-7]* *", buf, 0));
(void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
if (oflag) {
(void)sscanf(buf, "begin %o ", &mode);
if (strlcpy(buf, outfile, sizeof(buf)) >= sizeof(buf)) {
warnx("%s: filename too long", outfile);
return (1);
}
} else
(void)sscanf(buf, "begin %o %[^\n\r]", &mode, buf);
if (!sflag && !pflag) {
strncpy(buffn, buf, sizeof(buffn));
@ -287,5 +309,6 @@ static void
usage()
{
(void)fprintf(stderr, "usage: uudecode [-cips] [file ...]\n");
(void)fprintf(stderr, "usage: uudecode [-i] -o output_file [file]\n");
exit(1);
}

View File

@ -32,7 +32,7 @@
.\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
.Dd June 6, 1993
.Dd January 27, 2002
.Dt UUENCODE 1
.Os
.Sh NAME
@ -46,6 +46,10 @@
.Nm uudecode
.Op Fl cips
.Op Ar
.Nm uudecode
.Op Fl i
.Fl o Ar output_file
.Op file
.Sh DESCRIPTION
.Nm Uuencode
and
@ -72,8 +76,11 @@ for use by
transforms
.Em uuencoded
files (or by default, the standard input) into the original form.
The resulting file is named
The resulting file is named either
.Ar name
or (depending on options passed to
.Nm uudecode )
.Ar output_file
and will have the mode of the original file except that setuid
and execute bits are not retained.
.Nm Uudecode
@ -88,10 +95,18 @@ Decode more than one uuencode'd file from
if possible.
.It Fl i
Do not overwrite files.
.It Fl o Ar output_file
Output to
.Ar output_file
instead of
.Ar name .
.It Fl p
Decode
.Ar file
and write output to standard output.
(This option is deprecated in favor of
.Fl o Ar /dev/stdout
\&.)
.It Fl s
Do not strip output pathname to base filename.
By default
@ -124,7 +139,7 @@ The following example extract a compress'ed tar
archive from your mailbox
.Pp
.Bd -literal -offset indent -compact
uudecode -p < $MAIL | zcat | tar xfv -
uudecode -o /dev/stdout < $MAIL | zcat | tar xfv -
.Ed
.Sh SEE ALSO
.Xr basename 1 ,