sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 695940d50c33820a5821f9519c14c9f7443a3960
parent 160709734c6b0ad937d65159e9e723a488c0fc5c
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat,  7 Mar 2015 14:02:04 +0100

uniq: style put main at bottom

Diffstat:
uniq.c | 118++++++++++++++++++++++++++++++++++++++-----------------------------------------
1 file changed, 57 insertions(+), 61 deletions(-)

diff --git a/uniq.c b/uniq.c @@ -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; @@ -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) { @@ -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; +}