diff options
author | wosch <wosch@FreeBSD.org> | 1996-10-21 22:02:30 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-10-21 22:02:30 +0000 |
commit | ff1e30c98bbdb6496e3a24cf583b3cdcc9787324 (patch) | |
tree | 8f5d697674f556148e569ede31479b0876e051ae | |
parent | d7c6b63ef755212365d02ff2ce3e53b1cfe57b59 (diff) | |
download | FreeBSD-src-ff1e30c98bbdb6496e3a24cf583b3cdcc9787324.zip FreeBSD-src-ff1e30c98bbdb6496e3a24cf583b3cdcc9787324.tar.gz |
New options for uudecode
-p Decode file and write output to standard output.
-c Decode more than one uuencode'd file from file if possible.
-rw-r--r-- | usr.bin/uudecode/uudecode.c | 63 | ||||
-rw-r--r-- | usr.bin/uuencode/uuencode.1 | 28 |
2 files changed, 86 insertions, 5 deletions
diff --git a/usr.bin/uudecode/uudecode.c b/usr.bin/uudecode/uudecode.c index e481353..3112b9f 100644 --- a/usr.bin/uudecode/uudecode.c +++ b/usr.bin/uudecode/uudecode.c @@ -53,8 +53,16 @@ static char sccsid[] = "@(#)uudecode.c 8.2 (Berkeley) 4/2/94"; #include <pwd.h> #include <stdio.h> #include <string.h> +#include <stdlib.h> char *filename; +int cflag, pflag; + +void usage __P((void)); +int decode __P((void)); +int decode2 __P((int)); + +extern int optind; int main(argc, argv) @@ -62,9 +70,25 @@ main(argc, argv) char *argv[]; { extern int errno; - int rval; + int rval, ch; + + while ((ch = getopt(argc, argv, "cp")) != EOF) { + switch(ch) { + case 'c': + cflag = 1; /* multiple uudecode'd files */ + break; + case 'p': + pflag = 1; /* print output to stdout */ + break; + default: + (void)usage(); + } + } + argc -= optind; + argv += optind; - if (*++argv) { + + if (*argv) { rval = 0; do { if (!freopen(filename = *argv, "r", stdin)) { @@ -82,7 +106,28 @@ main(argc, argv) exit(rval); } -decode() +int +decode () +{ + int flag; + + /* decode only one file per input stream */ + if (!cflag) + return(decode2(0)); + + /* multiple uudecode'd files */ + for (flag = 0; ; flag++) + if (decode2(flag)) + return(1); + else if (feof(stdin)) + break; + + return(0); +} + +int +decode2(flag) + int flag; { extern int errno; struct passwd *pw; @@ -91,9 +136,13 @@ decode() int mode, n1; char buf[MAXPATHLEN]; + /* search for header line */ do { if (!fgets(buf, sizeof(buf), stdin)) { + if (flag) /* no error */ + return(0); + (void)fprintf(stderr, "uudecode: %s: no \"begin\" line\n", filename); return(1); @@ -127,7 +176,10 @@ decode() } /* create output file, set mode */ - if (!freopen(buf, "w", stdout) || + if (pflag) + ; /* print to stdout */ + + else if (!freopen(buf, "w", stdout) || fchmod(fileno(stdout), mode&0666)) { (void)fprintf(stderr, "uudecode: %s: %s: %s\n", buf, filename, strerror(errno)); @@ -180,8 +232,9 @@ decode() return(0); } +void usage() { - (void)fprintf(stderr, "usage: uudecode [file ...]\n"); + (void)fprintf(stderr, "usage: uudecode [-cp] [file ...]\n"); exit(1); } diff --git a/usr.bin/uuencode/uuencode.1 b/usr.bin/uuencode/uuencode.1 index 338cbf0..3dd1e68 100644 --- a/usr.bin/uuencode/uuencode.1 +++ b/usr.bin/uuencode/uuencode.1 @@ -30,6 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)uuencode.1 8.1 (Berkeley) 6/6/93 +.\" $Id$ .\" .Dd June 6, 1993 .Dt UUENCODE 1 @@ -43,6 +44,7 @@ .Op Ar file .Ar name .Nm uudecode +.Op Fl cp .Op Ar file ... .Sh DESCRIPTION .Nm Uuencode @@ -76,6 +78,18 @@ and will have the mode of the original file except that setuid and execute bits are not retained. .Nm Uudecode ignores any leading and trailing lines. +.Pp +The following options are available for +.Nm uudecode : +.Bl -tag -width ident +.It Fl c +Decode more than one uuencode'd file from +.Ar file +if possible. +.It Fl p +Decode +.Ar file +and write output to standard output. .Sh EXAMPLES The following example packages up a source tree, compresses it, uuencodes it and mails it to a user on another system. @@ -89,6 +103,20 @@ tree. tar cf \- src_tree \&| compress \&| uuencode src_tree.tar.Z \&| mail sys1!sys2!user .Ed + +The following example unpack all uuencode'd +files from your mailbox into your current working directory. +.Pp +.Bd -literal -offset indent -compact +uudecode -c < $MAIL +.Ed + +The following example extract a compress'ed tar +archive from your mailbox +.Pp +.Bd -literal -offset indent -compact +uudecode -p < $MAIL | zcat | tar xfv - +.Ed .Sh SEE ALSO .Xr compress 1 , .Xr mail 1 , |