X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fsort.c;h=a1625fc9cdb30a6d332ba023ef901ff6abac172d;hb=1b49c25e0a719ec3051eafa2329e68012c815abb;hp=4407b71055a79c8be33f803b266e9a47e2994657;hpb=0ef64bdb40c54681e8dd5ab8df42ac88e4ab1d4a;p=oweals%2Fbusybox.git diff --git a/coreutils/sort.c b/coreutils/sort.c index 4407b7105..a1625fc9c 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c @@ -12,6 +12,53 @@ * http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html */ +//usage:#define sort_trivial_usage +//usage: "[-nru" +//usage: IF_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR") +//usage: "] [FILE]..." +//usage:#define sort_full_usage "\n\n" +//usage: "Sort lines of text\n" +//usage: IF_FEATURE_SORT_BIG( +//usage: "\n -b Ignore leading blanks" +//usage: "\n -c Check whether input is sorted" +//usage: "\n -d Dictionary order (blank or alphanumeric only)" +//usage: "\n -f Ignore case" +//usage: "\n -g General numerical sort" +//usage: "\n -i Ignore unprintable characters" +//usage: "\n -k Sort key" +//usage: "\n -M Sort month" +//usage: ) +//usage: "\n -n Sort numbers" +//usage: IF_FEATURE_SORT_BIG( +//usage: "\n -o Output to file" +//usage: "\n -k Sort by key" +//usage: "\n -t CHAR Key separator" +//usage: ) +//usage: "\n -r Reverse sort order" +//usage: IF_FEATURE_SORT_BIG( +//usage: "\n -s Stable (don't sort ties alphabetically)" +//usage: ) +//usage: "\n -u Suppress duplicate lines" +//usage: IF_FEATURE_SORT_BIG( +//usage: "\n -z Lines are terminated by NUL, not newline" +//usage: "\n -mST Ignored for GNU compatibility") +//usage: +//usage:#define sort_example_usage +//usage: "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" +//usage: "a\n" +//usage: "b\n" +//usage: "c\n" +//usage: "d\n" +//usage: "e\n" +//usage: "f\n" +//usage: IF_FEATURE_SORT_BIG( +//usage: "$ echo -e \"c 3\\nb 2\\nd 2\" | $SORT -k 2,2n -k 1,1r\n" +//usage: "d 2\n" +//usage: "b 2\n" +//usage: "c 3\n" +//usage: ) +//usage: "" + #include "libbb.h" /* This is a NOEXEC applet. Be very careful! */ @@ -52,8 +99,8 @@ enum { static char key_separator; static struct sort_key { - struct sort_key *next_key; /* linked list */ - unsigned range[4]; /* start word, start char, end word, end char */ + struct sort_key *next_key; /* linked list */ + unsigned range[4]; /* start word, start char, end word, end char */ unsigned flags; } *key_list; @@ -172,7 +219,7 @@ static int compare_keys(const void *xarg, const void *yarg) y = get_key(*(char **)yarg, key, flags); #else /* This curly bracket serves no purpose but to match the nesting - level of the for () loop we're not using */ + * level of the for () loop we're not using */ { x = *(char **)xarg; y = *(char **)yarg; @@ -412,7 +459,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv) #if ENABLE_FEATURE_SORT_BIG /* Open output file _after_ we read all input ones */ if (option_mask32 & FLAG_o) - xmove_fd(xopen3(str_o, O_WRONLY, 0666), STDOUT_FILENO); + xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO); #endif flag = (option_mask32 & FLAG_z) ? '\0' : '\n'; for (i = 0; i < linecount; i++)