diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-03-05 00:19:32 +0300 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-03-05 00:19:32 +0300 |
commit | 029011b9eeaf491d00fda1d072c4c6094df96c3a (patch) | |
tree | 7c49f1fc1547a2f9cee812472f422a5c1a5c448b /coreutils/sort.c | |
parent | 7c4b2f3fe5cb6b9a5c6bd089c18279c5ce29dc21 (diff) |
A few updates (including the cp fix the Craig has been looking for)
-Erik
Diffstat (limited to 'coreutils/sort.c')
-rw-r--r-- | coreutils/sort.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 609c5e08c..e6894f6c3 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -29,7 +29,18 @@ #include <stdio.h> #include <errno.h> -static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n"; +static const char sort_usage[] = "sort [-n]" +#ifdef BB_FEATURE_SORT_REVERSE +" [-r]" +#endif +" [FILE]...\n\n"; + +#ifdef BB_FEATURE_SORT_REVERSE +#define APPLY_REVERSE(x) (reverse ? -(x) : (x)) +static int reverse = 0; +#else +#define APPLY_REVERSE(x) (x) +#endif /* typedefs _______________________________________________________________ */ @@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b) y = *doh; // fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data); - return strcmp(x->data, y->data); + return APPLY_REVERSE(strcmp(x->data, y->data)); } /* numeric order */ @@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b) xint = strtoul(x->data, NULL, 10); yint = strtoul(y->data, NULL, 10); - return (xint - yint); + return APPLY_REVERSE(xint - yint); } @@ -254,20 +265,19 @@ int sort_main(int argc, char **argv) if (argv[i][0] == '-') { opt = argv[i][1]; switch (opt) { - case 'g': - /* what's the diff between -g && -n? */ - compare = compare_numeric; - break; case 'h': usage(sort_usage); break; case 'n': - /* what's the diff between -g && -n? */ + /* numeric comparison */ compare = compare_numeric; break; +#ifdef BB_FEATURE_SORT_REVERSE case 'r': /* reverse */ + reverse = 1; break; +#endif default: fprintf(stderr, "sort: invalid option -- %c\n", opt); usage(sort_usage); @@ -310,4 +320,4 @@ int sort_main(int argc, char **argv) exit(0); } -/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */ +/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */ |