Deleted Added
full compact
45c45
< "$FreeBSD: head/usr.bin/uuencode/uuencode.c 84715 2001-10-09 11:05:27Z ru $";
---
> "$FreeBSD: head/usr.bin/uuencode/uuencode.c 91661 2002-03-05 03:27:47Z jmallett $";
53c53,54
< #include <sys/types.h>
---
> #include <sys/param.h>
> #include <sys/socket.h>
55a57,58
> #include <netinet/in.h>
>
56a60
> #include <resolv.h>
58a63
> #include <string.h>
61a67
> void base64_encode __P((void));
63a70,73
> FILE *output = stdout;
> int mode;
> char **av;
>
70c80,82
< int mode;
---
> int base64;
> char ch;
> char *outfile;
72,73c84,99
< while (getopt(argc, argv, "") != -1)
< usage();
---
> base64 = 0;
> outfile = NULL;
>
> while ((ch = getopt(argc, argv, "mo:")) != -1) {
> switch (ch) {
> case 'm':
> base64 = 1;
> break;
> case 'o':
> outfile = optarg;
> break;
> case '?':
> default:
> usage();
> }
> }
94,97c120,131
< (void)printf("begin %o %s\n", mode, *argv);
< encode();
< (void)printf("end\n");
< if (ferror(stdout))
---
> av = argv;
>
> if (outfile != NULL) {
> output = fopen(outfile, "w+");
> if (output == NULL)
> err(1, "unable to open %s for output", outfile);
> }
> if (base64)
> base64_encode();
> else
> encode();
> if (ferror(output))
106c140
< * copy from in to out, encoding as you go along.
---
> * Copy from in to out, encoding in base64 as you go along.
108a143,169
> base64_encode()
> {
> #define GROUPS 8 /* Group output chunks */
> unsigned char buf[6];
> char buf2[16];
> size_t n;
> int rv, sequence;
>
> sequence = 0;
>
> 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])));
> if (rv == -1)
> errx(1, "b64_ntop: error encoding base64");
> fprintf(output, "%s%s", buf2, (sequence % GROUPS) ? "" : "\n");
> }
> if (sequence % GROUPS)
> fprintf(output, "\n");
> fprintf(output, "====\n");
> }
>
> /*
> * Copy from in to out, encoding as you go along.
> */
> void
114a176
> (void)fprintf(output, "begin %o %s\n", mode, *av);
117c179
< if (putchar(ch) == EOF)
---
> if (fputc(ch, output) == EOF)
128c190
< if (putchar(ch) == EOF)
---
> if (fputc(ch, output) == EOF)
132c194
< if (putchar(ch) == EOF)
---
> if (fputc(ch, output) == EOF)
136c198
< if (putchar(ch) == EOF)
---
> if (fputc(ch, output) == EOF)
140c202
< if (putchar(ch) == EOF)
---
> if (fputc(ch, output) == EOF)
143c205
< if (putchar('\n') == EOF)
---
> if (fputc('\n', output) == EOF)
148,150c210
< ch = ENC('\0');
< (void)putchar(ch);
< (void)putchar('\n');
---
> (void)fprintf(output, "%c\nend\n", ENC('\0'));
156c216
< (void)fprintf(stderr,"usage: uuencode [infile] remotefile\n");
---
> (void)fprintf(stderr,"usage: uuencode [-m] [-o outfile] [infile] remotefile\n");