[hackers] [sbase] uniq: style put main at bottom || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sun, 8 Mar 2015 12:50:38 +0100 (CET)

commit 810ec984fc6439a838fdcf45a42d555a7a7d87d4
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat Mar 7 14:02:04 2015 +0100

    uniq: style put main at bottom

diff --git a/uniq.c b/uniq.c
index c63b54d..b200154 100644
--- a/uniq.c
+++ b/uniq.c
_AT_@ -6,10 +6,6 @@
 
 #include "util.h"
 
-static void uniqline(FILE *, char *);
-static void uniq(FILE *, FILE *);
-static void uniqfinish(FILE *);
-
 static const char *countfmt = "";
 static int dflag = 0;
 static int uflag = 0;
_AT_@ -20,63 +16,6 @@ static char *prevline = NULL;
 static char *prevoffset = NULL;
 static long prevlinecount = 0;
 
-static void
-usage(void)
-{
- eprintf("usage: %s [-c] [-d | -u] [-f fields] [-s chars]"
- " [input [output]]\n", argv0);
-}
-
-int
-main(int argc, char *argv[])
-{
- FILE *fp = stdin, *ofp = stdout;
-
- ARGBEGIN {
- case 'c':
- countfmt = "%7ld ";
- break;
- case 'd':
- dflag = 1;
- break;
- case 'u':
- uflag = 1;
- break;
- case 'f':
- fskip = estrtonum(EARGF(usage()), 0, INT_MAX);
- break;
- case 's':
- sskip = estrtonum(EARGF(usage()), 0, INT_MAX);
- break;
- default:
- usage();
- } ARGEND;
-
- if (argc > 2)
- usage();
-
- if (argc == 0) {
- uniq(stdin, stdout);
- } else if (argc >= 1) {
- if (strcmp(argv[0], "-") && !(fp = fopen(argv[0], "r")))
- eprintf("fopen %s:", argv[0]);
- if (argc == 2) {
- if (strcmp(argv[1], "-") &&
- !(ofp = fopen(argv[1], "w")))
- eprintf("fopen %s:", argv[1]);
- }
- uniq(fp, ofp);
- if (fp != stdin)
- fclose(fp);
- } else
- usage();
- uniqfinish(ofp);
- if (ofp != stdout)
- fclose(ofp);
-
- return 0;
-}
-
 static char *
 uniqskip(char *l)
 {
_AT_@ -139,3 +78,60 @@ uniqfinish(FILE *ofp)
 {
         uniqline(ofp, NULL);
 }
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-c] [-d | -u] [-f fields] [-s chars]"
+ " [input [output]]\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *fp = stdin, *ofp = stdout;
+
+ ARGBEGIN {
+ case 'c':
+ countfmt = "%7ld ";
+ break;
+ case 'd':
+ dflag = 1;
+ break;
+ case 'u':
+ uflag = 1;
+ break;
+ case 'f':
+ fskip = estrtonum(EARGF(usage()), 0, INT_MAX);
+ break;
+ case 's':
+ sskip = estrtonum(EARGF(usage()), 0, INT_MAX);
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc > 2)
+ usage();
+
+ if (argc == 0) {
+ uniq(stdin, stdout);
+ } else if (argc >= 1) {
+ if (strcmp(argv[0], "-") && !(fp = fopen(argv[0], "r")))
+ eprintf("fopen %s:", argv[0]);
+ if (argc == 2) {
+ if (strcmp(argv[1], "-") &&
+ !(ofp = fopen(argv[1], "w")))
+ eprintf("fopen %s:", argv[1]);
+ }
+ uniq(fp, ofp);
+ if (fp != stdin)
+ fclose(fp);
+ } else
+ usage();
+ uniqfinish(ofp);
+ if (ofp != stdout)
+ fclose(ofp);
+
+ return 0;
+}
Received on Sun Mar 08 2015 - 12:50:38 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 08 2015 - 13:00:16 CET