diff options
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/sort.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index c24b62681..b39297a26 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -85,16 +85,7 @@ | |||
| 85 | 85 | ||
| 86 | #include "libbb.h" | 86 | #include "libbb.h" |
| 87 | 87 | ||
| 88 | /* This is a NOEXEC applet. Be very careful! */ | ||
| 89 | |||
| 90 | |||
| 91 | /* | ||
| 92 | sort [-m][-o output][-bdfinru][-t char][-k keydef]... [file...] | ||
| 93 | sort -c [-bdfinru][-t char][-k keydef][file] | ||
| 94 | */ | ||
| 95 | |||
| 96 | /* These are sort types */ | 88 | /* These are sort types */ |
| 97 | #define OPT_STR "ngMucszbrdfimS:T:o:k:*t:" | ||
| 98 | enum { | 89 | enum { |
| 99 | FLAG_n = 1, /* Numeric sort */ | 90 | FLAG_n = 1, /* Numeric sort */ |
| 100 | FLAG_g = 2, /* Sort using strtod() */ | 91 | FLAG_g = 2, /* Sort using strtod() */ |
| @@ -120,6 +111,15 @@ enum { | |||
| 120 | FLAG_no_tie_break = 0x40000000, | 111 | FLAG_no_tie_break = 0x40000000, |
| 121 | }; | 112 | }; |
| 122 | 113 | ||
| 114 | static const char sort_opt_str[] ALIGN1 = "^" | ||
| 115 | "ngMucszbrdfimS:T:o:k:*t:" | ||
| 116 | "\0" "o--o:t--t"/*-t, -o: at most one of each*/; | ||
| 117 | /* | ||
| 118 | * OPT_STR must not be string literal, needs to have stable address: | ||
| 119 | * code uses "strchr(OPT_STR,c) - OPT_STR" idiom. | ||
| 120 | */ | ||
| 121 | #define OPT_STR (sort_opt_str + 1) | ||
| 122 | |||
| 123 | #if ENABLE_FEATURE_SORT_BIG | 123 | #if ENABLE_FEATURE_SORT_BIG |
| 124 | static char key_separator; | 124 | static char key_separator; |
| 125 | 125 | ||
| @@ -129,6 +129,10 @@ static struct sort_key { | |||
| 129 | unsigned flags; | 129 | unsigned flags; |
| 130 | } *key_list; | 130 | } *key_list; |
| 131 | 131 | ||
| 132 | |||
| 133 | /* This is a NOEXEC applet. Be very careful! */ | ||
| 134 | |||
| 135 | |||
| 132 | static char *get_key(char *str, struct sort_key *key, int flags) | 136 | static char *get_key(char *str, struct sort_key *key, int flags) |
| 133 | { | 137 | { |
| 134 | int start = start; /* for compiler */ | 138 | int start = start; /* for compiler */ |
| @@ -404,9 +408,8 @@ int sort_main(int argc UNUSED_PARAM, char **argv) | |||
| 404 | xfunc_error_retval = 2; | 408 | xfunc_error_retval = 2; |
| 405 | 409 | ||
| 406 | /* Parse command line options */ | 410 | /* Parse command line options */ |
| 407 | opts = getopt32(argv, "^" | 411 | opts = getopt32(argv, |
| 408 | OPT_STR | 412 | sort_opt_str, |
| 409 | "\0" "o--o:t--t"/*-t, -o: at most one of each*/, | ||
| 410 | &str_ignored, &str_ignored, &str_o, &lst_k, &str_t | 413 | &str_ignored, &str_ignored, &str_o, &lst_k, &str_t |
| 411 | ); | 414 | ); |
| 412 | /* global b strips leading and trailing spaces */ | 415 | /* global b strips leading and trailing spaces */ |
