diff options
-rw-r--r-- | toys/posix/sort.c | 24 | ||||
-rw-r--r-- | toys/posix/xargs.c | 24 |
2 files changed, 21 insertions, 27 deletions
diff --git a/toys/posix/sort.c b/toys/posix/sort.c index 1cb5b191..a2784cdb 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -62,10 +62,9 @@ config SORT_FLOAT #include "toys.h" GLOBALS( - char *key_separator; - struct arg_list *raw_keys; - char *outfile; - char *ignore1, ignore2; // GNU compatability NOPs for -S and -T. + char *t; + struct arg_list *k; + char *o, *T, S; void *key_list; int linecount; @@ -109,13 +108,12 @@ static char *get_key_data(char *str, struct sort_key *key, int flags) for (i=1; i < key->range[2*j]+j; i++) { // Skip leading blanks - if (str[end] && !TT.key_separator) - while (isspace(str[end])) end++; + if (str[end] && !TT.t) while (isspace(str[end])) end++; // Skip body of key for (; str[end]; end++) { - if (TT.key_separator) { - if (str[end]==*TT.key_separator) { + if (TT.t) { + if (str[end]==*TT.t) { end++; break; } @@ -127,7 +125,7 @@ static char *get_key_data(char *str, struct sort_key *key, int flags) } // Key with explicit separator starts after the separator - if (TT.key_separator && str[start]==*TT.key_separator) start++; + if (TT.t && str[start]==*TT.t) start++; // Strip leading and trailing whitespace if necessary if (flags&FLAG_b) while (isspace(str[start])) start++; @@ -305,14 +303,14 @@ void sort_main(void) int idx, fd = 1; // Open output file if necessary. - if (CFG_SORT_BIG && TT.outfile) - fd = xcreate(TT.outfile, O_CREAT|O_TRUNC|O_WRONLY, 0666); + if (CFG_SORT_BIG && TT.o) + fd = xcreate(TT.o, O_CREAT|O_TRUNC|O_WRONLY, 0666); // Parse -k sort keys. - if (CFG_SORT_BIG && TT.raw_keys) { + if (CFG_SORT_BIG && TT.k) { struct arg_list *arg; - for (arg = TT.raw_keys; arg; arg = arg->next) { + for (arg = TT.k; arg; arg = arg->next) { struct sort_key *key = add_key(); char *temp; int flag; diff --git a/toys/posix/xargs.c b/toys/posix/xargs.c index cac143cc..aaa0ac79 100644 --- a/toys/posix/xargs.c +++ b/toys/posix/xargs.c @@ -41,11 +41,8 @@ config XARGS_PEDANTIC #include "toys.h" GLOBALS( - long max_bytes; - long max_entries; - long L; - char *eofstr; - char *I; + long s, n, L; + char *E, *I; long entries, bytes; char delim; @@ -57,7 +54,7 @@ GLOBALS( // Returning NULL means need more data. // Returning char * means hit data limits, start of data left over // Returning 1 means hit data limits, but consumed all data -// Returning 2 means hit -E eofstr +// Returning 2 means hit -E STR static char *handle_entries(char *data, char **entry) { @@ -73,7 +70,7 @@ static char *handle_entries(char *data, char **entry) s++; } - if (TT.max_entries && TT.entries >= TT.max_entries) + if (TT.n && TT.entries >= TT.n) return *s ? s : (char *)1; if (!*s) break; @@ -82,13 +79,13 @@ static char *handle_entries(char *data, char **entry) TT.bytes += sizeof(char *); for (;;) { - if (++TT.bytes >= TT.max_bytes && TT.max_bytes) return save; + if (++TT.bytes >= TT.s && TT.s) return save; if (!*s || isspace(*s)) break; s++; } - if (TT.eofstr) { + if (TT.E) { int len = s-save; - if (len == strlen(TT.eofstr) && !strncmp(save, TT.eofstr, len)) + if (len == strlen(TT.E) && !strncmp(save, TT.E, len)) return (char *)2; } if (entry) entry[TT.entries] = save; @@ -98,8 +95,8 @@ static char *handle_entries(char *data, char **entry) // -0 support } else { TT.bytes += sizeof(char *)+strlen(data)+1; - if (TT.max_bytes && TT.bytes >= TT.max_bytes) return data; - if (TT.max_entries && TT.entries >= TT.max_entries) return data; + if (TT.s && TT.bytes >= TT.s) return data; + if (TT.n && TT.entries >= TT.n) return data; if (entry) entry[TT.entries] = data; TT.entries++; } @@ -121,8 +118,7 @@ void xargs_main(void) // and command line arguments and still be able to invoke another utility", // though obviously that's not really something you can guarantee. posix_max_bytes = sysconf(_SC_ARG_MAX) - environ_bytes() - 2048; - if (TT.max_bytes == 0 || TT.max_bytes > posix_max_bytes) - TT.max_bytes = posix_max_bytes; + if (!TT.s || TT.s > posix_max_bytes) TT.s = posix_max_bytes; if (!(toys.optflags & FLAG_0)) TT.delim = '\n'; |