From 95a1d0ec4d79d28dac39e8c7af09a645eafd028a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 4 Dec 2018 08:26:26 -0600 Subject: Remove CFG_SORT_BIG, just always do that. --- toys/posix/sort.c | 59 ++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'toys') diff --git a/toys/posix/sort.c b/toys/posix/sort.c index a2784cdb..d4a0f4fd 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -7,27 +7,19 @@ * Deviations from POSIX: Lots. * We invented -x -USE_SORT(NEWTOY(sort, USE_SORT_FLOAT("g")USE_SORT_BIG("S:T:m" "o:k*t:xbMcszdfi") "run", TOYFLAG_USR|TOYFLAG_BIN)) +USE_SORT(NEWTOY(sort, USE_SORT_FLOAT("g")"S:T:m" "o:k*t:xbMcszdfirun", TOYFLAG_USR|TOYFLAG_BIN)) config SORT bool "sort" default y help - usage: sort [-run] [FILE...] + usage: sort [-runbcdfiMsz] [FILE...] [-k#[,#[x]] [-t X]] [-o FILE] Sort all lines of text from input files (or stdin) to stdout. -r reverse -u unique lines only -n numeric order (instead of alphabetical) - -config SORT_BIG - bool "SuSv3 options (Support -ktcsbdfiozM)" - default y - depends on SORT - help - usage: sort [-bcdfiMsz] [-k#[,#[x]] [-t X]] [-o FILE] - -b ignore leading blanks (or trailing blanks in second part of key) -c check whether input is sorted -d dictionary order (use alphanumeric and whitespace chars only) @@ -51,7 +43,7 @@ config SORT_BIG config SORT_FLOAT bool default y - depends on SORT_BIG && TOYBOX_FLOAT + depends on TOYBOX_FLOAT help usage: sort [-g] @@ -205,7 +197,7 @@ static int compare_values(int flags, char *x, char *y) if (yinf) return dy<0 ? 1 : -1; return dx>dy ? 1 : (dxnext_key) - { - flags = key->flags ? key->flags : toys.optflags; + for (key=(struct sort_key *)TT.key_list; !retval && key; key = key->next_key){ + flags = key->flags ? key->flags : toys.optflags; - // Chop out and modify key chunks, handling -dfib + // Chop out and modify key chunks, handling -dfib - x = get_key_data(xx, key, flags); - y = get_key_data(yy, key, flags); + x = get_key_data(xx, key, flags); + y = get_key_data(yy, key, flags); - retval = compare_values(flags, x, y); + retval = compare_values(flags, x, y); - // Free the copies get_key_data() made. + // Free the copies get_key_data() made. - if (x != xx) free(x); - if (y != yy) free(y); + if (x != xx) free(x); + if (y != yy) free(y); - if (retval) break; - } - } else retval = compare_values(flags, xx, yy); + if (retval) break; + } // Perform fallback sort if necessary (always case insensitive, no -f, // the point is to get a stable order even for -f sorts) - if (!retval && !(CFG_SORT_BIG && (toys.optflags&FLAG_s))) { + if (!retval && !(toys.optflags&FLAG_s)) { flags = toys.optflags; retval = strcmp(xx, yy); } @@ -276,13 +264,13 @@ static void sort_read(int fd, char *name) // Read each line from file, appending to a big array. for (;;) { - char * line = (CFG_SORT_BIG && (toys.optflags&FLAG_z)) + char * line = (toys.optflags&FLAG_z) ? get_rawline(fd, NULL, 0) : get_line(fd); if (!line) break; // handle -c here so we don't allocate more memory than necessary. - if (CFG_SORT_BIG && (toys.optflags&FLAG_c)) { + if (toys.optflags&FLAG_c) { int j = (toys.optflags&FLAG_u) ? -1 : 0; if (TT.lines && compare_keys((void *)&TT.lines, &line)>j) @@ -303,11 +291,10 @@ void sort_main(void) int idx, fd = 1; // Open output file if necessary. - if (CFG_SORT_BIG && TT.o) - fd = xcreate(TT.o, O_CREAT|O_TRUNC|O_WRONLY, 0666); + if (TT.o) fd = xcreate(TT.o, O_CREAT|O_TRUNC|O_WRONLY, 0666); // Parse -k sort keys. - if (CFG_SORT_BIG && TT.k) { + if (TT.k) { struct arg_list *arg; for (arg = TT.k; arg; arg = arg->next) { @@ -359,14 +346,14 @@ void sort_main(void) if (toys.optflags&FLAG_b) toys.optflags |= FLAG_bb; // If no keys, perform alphabetic sort over the whole line. - if (CFG_SORT_BIG && !TT.key_list) add_key()->range[0] = 1; + if (!TT.key_list) add_key()->range[0] = 1; // Open input files and read data, populating TT.lines[TT.linecount] loopfiles(toys.optargs, sort_read); // The compare (-c) logic was handled in sort_read(), // so if we got here, we're done. - if (CFG_SORT_BIG && (toys.optflags&FLAG_c)) goto exit_now; + if (toys.optflags&FLAG_c) goto exit_now; // Perform the actual sort qsort(TT.lines, TT.linecount, sizeof(char *), compare_keys); -- cgit v1.2.3