aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sort.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-17 18:11:45 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-17 18:11:45 +0000
commit54cf511ce1286ce46f04e4cead085b4af829f179 (patch)
treea43331e67e2472f7a8c415aee09ce17137d734a6 /coreutils/sort.c
parentec27feb04589d46233802f686559fb5f532fb2df (diff)
downloadbusybox-54cf511ce1286ce46f04e4cead085b4af829f179.tar.gz
sort: fix multiple -k (was ignoring all except last)
Diffstat (limited to 'coreutils/sort.c')
-rw-r--r--coreutils/sort.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c
index e2c7b1dbf..311d0cb9c 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -276,7 +276,8 @@ int sort_main(int argc, char **argv)
{
FILE *fp, *outfile = stdout;
char *line, **lines = NULL;
- char *str_ignored, *str_o, *str_k, *str_t;
+ char *str_ignored, *str_o, *str_t;
+ llist_t *lst_k = NULL;
int i, flag;
int linecount = 0;
@@ -284,8 +285,9 @@ int sort_main(int argc, char **argv)
/* Parse command line options */
/* -o and -t can be given at most once */
- opt_complementary = "?:o--o:t--t";
- getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &str_k, &str_t);
+ opt_complementary = "?:o--o:t--t:" /* -t, -o: maximum one of each */
+ "k::"; /* -k takes list */
+ getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
#if ENABLE_FEATURE_SORT_BIG
if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w");
if (option_mask32 & FLAG_t) {
@@ -294,7 +296,8 @@ int sort_main(int argc, char **argv)
key_separator = str_t[0];
}
/* parse sort key */
- if (option_mask32 & FLAG_k) {
+ lst_k = llist_rev(lst_k);
+ while (lst_k) {
enum {
FLAG_allowed_for_k =
FLAG_n | /* Numeric sort */
@@ -308,6 +311,7 @@ int sort_main(int argc, char **argv)
0
};
struct sort_key *key = add_key();
+ char *str_k = lst_k->data;
const char *temp2;
i = 0; /* i==0 before comma, 1 after (-k3,6) */
@@ -337,6 +341,8 @@ int sort_main(int argc, char **argv)
str_k++;
}
}
+ /* leaking lst_k... */
+ lst_k = lst_k->link;
}
#endif
/* global b strips leading and trailing spaces */