[hackers] [sbase] Use a function pointer in uuencode(1) || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 21 May 2015 16:43:43 +0200 (CEST)

commit 9304b84c927586892928fe2ce95fa2ee94f53eba
Author: FRIGN <dev_AT_frign.de>
Date: Tue May 19 17:59:58 2015 +0200

    Use a function pointer in uuencode(1)
    
    This simplifies the code a lot.

diff --git a/uuencode.c b/uuencode.c
index fdde3d2..b4332e4 100644
--- a/uuencode.c
+++ b/uuencode.c
_AT_@ -6,8 +6,6 @@
 
 #include "util.h"
 
-static int mflag = 0;
-
 static unsigned int
 b64e(unsigned char b[2])
 {
_AT_@ -103,10 +101,11 @@ int
 main(int argc, char *argv[])
 {
         FILE *fp = NULL;
+ void (*uuencode_f)(FILE *, const char *, const char *) = uuencode;
 
         ARGBEGIN {
         case 'm':
- mflag = 1;
+ uuencode_f = uuencodeb64;
                 break;
         default:
                 usage();
_AT_@ -116,17 +115,11 @@ main(int argc, char *argv[])
                 usage();
 
         if (argc == 1 || !strcmp(argv[0], "-")) {
- if (mflag)
- uuencodeb64(stdin, argv[0], "<stdin>");
- else
- uuencode(stdin, argv[0], "<stdin>");
+ uuencode_f(stdin, argv[0], "<stdin>");
         } else {
                 if (!(fp = fopen(argv[0], "r")))
                         eprintf("fopen %s:", argv[0]);
- if (mflag)
- uuencodeb64(fp, argv[1], argv[0]);
- else
- uuencode(fp, argv[1], argv[0]);
+ uuencode_f(fp, argv[1], argv[0]);
         }
 
         return !!((fp && fshut(fp, argv[0])) + fshut(stdin, "<stdin>") +
Received on Thu May 21 2015 - 16:43:43 CEST

This archive was generated by hypermail 2.3.0 : Thu May 21 2015 - 16:48:11 CEST