diff options
author | Pietro Cerutti <gahr@FreeBSD.org> | 2016-04-07 16:12:38 +0000 |
---|---|---|
committer | Pietro Cerutti <gahr@FreeBSD.org> | 2016-04-07 16:12:38 +0000 |
commit | 019a4a20e7926be6e237b9b4618c5cf4420666e1 (patch) | |
tree | e8619b65a143c28fee6dd83b7a36de80a3c40d59 /usr.bin/uuencode/uuencode.c | |
parent | f46a487807a7c9e39b88273f9aa9de9e6d91e4c6 (diff) | |
download | src-019a4a20e7926be6e237b9b4618c5cf4420666e1.tar.gz src-019a4a20e7926be6e237b9b4618c5cf4420666e1.zip |
Enhance uuencode with a -r option to produce raw output.
This matches with uudecode's -r option to decode raw data without initial and
final framing lines.
$ echo Test | uuencode -mr - | uudecode -mr
Test
Approved by: cognet
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=297678
Diffstat (limited to 'usr.bin/uuencode/uuencode.c')
-rw-r--r-- | usr.bin/uuencode/uuencode.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/usr.bin/uuencode/uuencode.c b/usr.bin/uuencode/uuencode.c index def8bcc3bcf0..500dcd3ebeaf 100644 --- a/usr.bin/uuencode/uuencode.c +++ b/usr.bin/uuencode/uuencode.c @@ -66,6 +66,7 @@ static void usage(void); static FILE *output; static int mode; +static char raw = 0; static char **av; int @@ -82,7 +83,7 @@ main(int argc, char *argv[]) if (strcmp(basename(argv[0]), "b64encode") == 0) base64 = 1; - while ((ch = getopt(argc, argv, "mo:")) != -1) { + while ((ch = getopt(argc, argv, "mo:r")) != -1) { switch (ch) { case 'm': base64 = 1; @@ -90,6 +91,9 @@ main(int argc, char *argv[]) case 'o': outfile = optarg; break; + case 'r': + raw = 1; + break; case '?': default: usage(); @@ -152,7 +156,8 @@ base64_encode(void) sequence = 0; - fprintf(output, "begin-base64 %o %s\n", mode, *av); + if (!raw) + fprintf(output, "begin-base64 %o %s\n", mode, *av); while ((n = fread(buf, 1, sizeof(buf), stdin))) { ++sequence; rv = b64_ntop(buf, n, buf2, (sizeof(buf2) / sizeof(buf2[0]))); @@ -162,7 +167,8 @@ base64_encode(void) } if (sequence % GROUPS) fprintf(output, "\n"); - fprintf(output, "====\n"); + if (!raw) + fprintf(output, "====\n"); } /* @@ -175,7 +181,8 @@ encode(void) register char *p; char buf[80]; - (void)fprintf(output, "begin %o %s\n", mode, *av); + if (!raw) + (void)fprintf(output, "begin %o %s\n", mode, *av); while ((n = fread(buf, 1, 45, stdin))) { ch = ENC(n); if (fputc(ch, output) == EOF) @@ -209,7 +216,8 @@ encode(void) } if (ferror(stdin)) errx(1, "read error"); - (void)fprintf(output, "%c\nend\n", ENC('\0')); + if (!raw) + (void)fprintf(output, "%c\nend\n", ENC('\0')); } static void |