Use a function pointer in uuencode(1)

This simplifies the code a lot.
This commit is contained in:
FRIGN 2015-05-19 17:59:58 +02:00 committed by sin
parent 9a074144c9
commit 9304b84c92

View File

@ -6,8 +6,6 @@
#include "util.h" #include "util.h"
static int mflag = 0;
static unsigned int static unsigned int
b64e(unsigned char b[2]) b64e(unsigned char b[2])
{ {
@ -103,10 +101,11 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
FILE *fp = NULL; FILE *fp = NULL;
void (*uuencode_f)(FILE *, const char *, const char *) = uuencode;
ARGBEGIN { ARGBEGIN {
case 'm': case 'm':
mflag = 1; uuencode_f = uuencodeb64;
break; break;
default: default:
usage(); usage();
@ -116,17 +115,11 @@ main(int argc, char *argv[])
usage(); usage();
if (argc == 1 || !strcmp(argv[0], "-")) { if (argc == 1 || !strcmp(argv[0], "-")) {
if (mflag) uuencode_f(stdin, argv[0], "<stdin>");
uuencodeb64(stdin, argv[0], "<stdin>");
else
uuencode(stdin, argv[0], "<stdin>");
} else { } else {
if (!(fp = fopen(argv[0], "r"))) if (!(fp = fopen(argv[0], "r")))
eprintf("fopen %s:", argv[0]); eprintf("fopen %s:", argv[0]);
if (mflag) uuencode_f(fp, argv[1], argv[0]);
uuencodeb64(fp, argv[1], argv[0]);
else
uuencode(fp, argv[1], argv[0]);
} }
return !!((fp && fshut(fp, argv[0])) + fshut(stdin, "<stdin>") + return !!((fp && fshut(fp, argv[0])) + fshut(stdin, "<stdin>") +