[hackers] [sbase] uudecode: Style fix || sin

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:47 +0100 (CET)

commit 7768918d6a0d1a0b026a962963ca1ef619d05a37
Author: sin <sin_AT_2f30.org>
Date: Fri Feb 13 11:19:19 2015 +0000

    uudecode: Style fix

diff --git a/uudecode.c b/uudecode.c
index 305b521..adc48f4 100644
--- a/uudecode.c
+++ b/uudecode.c
_AT_@ -11,80 +11,9 @@
 #include "text.h"
 #include "util.h"
 
-static void uudecodeb64(FILE *, FILE *);
-static void uudecode(FILE *, FILE *);
-static void parseheader(FILE *, const char *, char **, mode_t *, char **);
-static FILE *parsefile(const char *);
-
-static void
-usage(void)
-{
- eprintf("usage: %s [-m] [-o output] [file]\n", argv0);
-}
-
 static int mflag = 0;
 static int oflag = 0;
 
-int
-main(int argc, char *argv[])
-{
- FILE *fp = NULL, *nfp = NULL;
- char *fname, *header;
- const char *ifname;
- mode_t mode = 0;
- void (*d) (FILE *, FILE *) = NULL;
- char *ofname = NULL;
-
- ARGBEGIN {
- case 'm':
- mflag = 1; /* accepted but unused (autodetect file type) */
- break;
- case 'o':
- oflag = 1;
- ofname = EARGF(usage());
- break;
- default:
- usage();
- } ARGEND;
-
- if (argc > 1)
- usage();
-
- if (argc == 0) {
- fp = stdin;
- ifname = "<stdin>";
- } else {
- if (!(fp = fopen(argv[0], "r")))
- eprintf("fopen %s:", argv[0]);
- ifname = argv[0];
- }
-
- parseheader(fp, ifname, &header, &mode, &fname);
-
- if (!strncmp(header, "begin", sizeof("begin")))
- d = uudecode;
- else if (!strncmp(header, "begin-base64", sizeof("begin-base64")))
- d = uudecodeb64;
- else
- eprintf("unknown header %s:", header);
-
- if (oflag)
- fname = ofname;
- if (!(nfp = parsefile(fname)))
- eprintf("fopen %s:", fname);
-
- d(fp, nfp);
-
- if (nfp != stdout && chmod(fname, mode) < 0)
- eprintf("chmod %s:", fname);
- if (fp)
- fclose(fp);
- if (nfp)
- fclose(nfp);
-
- return 0;
-}
-
 static FILE *
 parsefile(const char *fname)
 {
_AT_@ -142,6 +71,7 @@ parseheader(FILE *fp, const char *s, char **header, mode_t *mode,
         if (n > 0)
                 *fname = q;
 }
+
 static const char b64dt[] = {
         -1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
         -1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,
_AT_@ -286,3 +216,69 @@ uudecode(FILE *fp, FILE *outfp)
                 eprintf("invalid uudecode footer \"end\" not found\n");
         free(bufb);
 }
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-m] [-o output] [file]\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *fp = NULL, *nfp = NULL;
+ char *fname, *header;
+ const char *ifname;
+ mode_t mode = 0;
+ void (*d) (FILE *, FILE *) = NULL;
+ char *ofname = NULL;
+
+ ARGBEGIN {
+ case 'm':
+ mflag = 1; /* accepted but unused (autodetect file type) */
+ break;
+ case 'o':
+ oflag = 1;
+ ofname = EARGF(usage());
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc > 1)
+ usage();
+
+ if (argc == 0) {
+ fp = stdin;
+ ifname = "<stdin>";
+ } else {
+ if (!(fp = fopen(argv[0], "r")))
+ eprintf("fopen %s:", argv[0]);
+ ifname = argv[0];
+ }
+
+ parseheader(fp, ifname, &header, &mode, &fname);
+
+ if (!strncmp(header, "begin", sizeof("begin")))
+ d = uudecode;
+ else if (!strncmp(header, "begin-base64", sizeof("begin-base64")))
+ d = uudecodeb64;
+ else
+ eprintf("unknown header %s:", header);
+
+ if (oflag)
+ fname = ofname;
+ if (!(nfp = parsefile(fname)))
+ eprintf("fopen %s:", fname);
+
+ d(fp, nfp);
+
+ if (nfp != stdout && chmod(fname, mode) < 0)
+ eprintf("chmod %s:", fname);
+ if (fp)
+ fclose(fp);
+ if (nfp)
+ fclose(nfp);
+
+ return 0;
+}
Received on Tue Mar 24 2015 - 23:53:47 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:10:03 CET