aboutsummaryrefslogtreecommitdiff
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
parentec27feb04589d46233802f686559fb5f532fb2df (diff)
downloadbusybox-w32-54cf511ce1286ce46f04e4cead085b4af829f179.tar.gz
busybox-w32-54cf511ce1286ce46f04e4cead085b4af829f179.tar.bz2
busybox-w32-54cf511ce1286ce46f04e4cead085b4af829f179.zip
sort: fix multiple -k (was ignoring all except last)
-rw-r--r--archival/tar.c2
-rw-r--r--coreutils/od_bloaty.c2
-rw-r--r--coreutils/sort.c14
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/llist.c2
-rw-r--r--networking/wget.c2
-rw-r--r--procps/ps.c2
-rwxr-xr-xtestsuite/sort.tests10
8 files changed, 26 insertions, 10 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 57da0b6b8..1cdae296d 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -864,7 +864,7 @@ int tar_main(int argc, char **argv)
864 llist_add_to(&tar_handle->accept, argv[optind]); 864 llist_add_to(&tar_handle->accept, argv[optind]);
865 optind++; 865 optind++;
866 } 866 }
867 tar_handle->accept = rev_llist(tar_handle->accept); 867 tar_handle->accept = llist_rev(tar_handle->accept);
868 868
869 if (tar_handle->accept || tar_handle->reject) 869 if (tar_handle->accept || tar_handle->reject)
870 tar_handle->filter = filter_accept_reject_list; 870 tar_handle->filter = filter_accept_reject_list;
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index f060c0ace..c69470a14 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -1312,7 +1312,7 @@ int od_main(int argc, char **argv)
1312 if (opt & OPT_l) decode_format_string("d4"); 1312 if (opt & OPT_l) decode_format_string("d4");
1313 if (opt & OPT_o) decode_format_string("o2"); 1313 if (opt & OPT_o) decode_format_string("o2");
1314 //if (opt & OPT_t)... 1314 //if (opt & OPT_t)...
1315 lst_t = rev_llist(lst_t); 1315 lst_t = llist_rev(lst_t);
1316 while (lst_t) { 1316 while (lst_t) {
1317 decode_format_string(lst_t->data); 1317 decode_format_string(lst_t->data);
1318 lst_t = lst_t->link; 1318 lst_t = lst_t->link;
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)
276{ 276{
277 FILE *fp, *outfile = stdout; 277 FILE *fp, *outfile = stdout;
278 char *line, **lines = NULL; 278 char *line, **lines = NULL;
279 char *str_ignored, *str_o, *str_k, *str_t; 279 char *str_ignored, *str_o, *str_t;
280 llist_t *lst_k = NULL;
280 int i, flag; 281 int i, flag;
281 int linecount = 0; 282 int linecount = 0;
282 283
@@ -284,8 +285,9 @@ int sort_main(int argc, char **argv)
284 285
285 /* Parse command line options */ 286 /* Parse command line options */
286 /* -o and -t can be given at most once */ 287 /* -o and -t can be given at most once */
287 opt_complementary = "?:o--o:t--t"; 288 opt_complementary = "?:o--o:t--t:" /* -t, -o: maximum one of each */
288 getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &str_k, &str_t); 289 "k::"; /* -k takes list */
290 getopt32(argc, argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
289#if ENABLE_FEATURE_SORT_BIG 291#if ENABLE_FEATURE_SORT_BIG
290 if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w"); 292 if (option_mask32 & FLAG_o) outfile = xfopen(str_o, "w");
291 if (option_mask32 & FLAG_t) { 293 if (option_mask32 & FLAG_t) {
@@ -294,7 +296,8 @@ int sort_main(int argc, char **argv)
294 key_separator = str_t[0]; 296 key_separator = str_t[0];
295 } 297 }
296 /* parse sort key */ 298 /* parse sort key */
297 if (option_mask32 & FLAG_k) { 299 lst_k = llist_rev(lst_k);
300 while (lst_k) {
298 enum { 301 enum {
299 FLAG_allowed_for_k = 302 FLAG_allowed_for_k =
300 FLAG_n | /* Numeric sort */ 303 FLAG_n | /* Numeric sort */
@@ -308,6 +311,7 @@ int sort_main(int argc, char **argv)
308 0 311 0
309 }; 312 };
310 struct sort_key *key = add_key(); 313 struct sort_key *key = add_key();
314 char *str_k = lst_k->data;
311 const char *temp2; 315 const char *temp2;
312 316
313 i = 0; /* i==0 before comma, 1 after (-k3,6) */ 317 i = 0; /* i==0 before comma, 1 after (-k3,6) */
@@ -337,6 +341,8 @@ int sort_main(int argc, char **argv)
337 str_k++; 341 str_k++;
338 } 342 }
339 } 343 }
344 /* leaking lst_k... */
345 lst_k = lst_k->link;
340 } 346 }
341#endif 347#endif
342 /* global b strips leading and trailing spaces */ 348 /* global b strips leading and trailing spaces */
diff --git a/include/libbb.h b/include/libbb.h
index 09e8a57d2..a32e6154c 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -473,7 +473,7 @@ extern void llist_add_to(llist_t **old_head, void *data);
473extern void llist_add_to_end(llist_t **list_head, void *data); 473extern void llist_add_to_end(llist_t **list_head, void *data);
474extern void *llist_pop(llist_t **elm); 474extern void *llist_pop(llist_t **elm);
475extern void llist_free(llist_t *elm, void (*freeit)(void *data)); 475extern void llist_free(llist_t *elm, void (*freeit)(void *data));
476extern llist_t* rev_llist(llist_t *list); 476extern llist_t* llist_rev(llist_t *list);
477 477
478enum { 478enum {
479 LOGMODE_NONE = 0, 479 LOGMODE_NONE = 0,
diff --git a/libbb/llist.c b/libbb/llist.c
index 63c77fa9e..0a5978a26 100644
--- a/libbb/llist.c
+++ b/libbb/llist.c
@@ -74,7 +74,7 @@ void llist_free(llist_t * elm, void (*freeit) (void *data))
74 74
75/* Reverse list order. Useful since getopt32 saves option params 75/* Reverse list order. Useful since getopt32 saves option params
76 * in reverse order */ 76 * in reverse order */
77llist_t *rev_llist(llist_t * list) 77llist_t *llist_rev(llist_t * list)
78{ 78{
79 llist_t *new = NULL; 79 llist_t *new = NULL;
80 80
diff --git a/networking/wget.c b/networking/wget.c
index e649ccdda..db222156b 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -157,7 +157,7 @@ int wget_main(int argc, char **argv)
157 if (headers_llist) { 157 if (headers_llist) {
158 int size = 1; 158 int size = 1;
159 char *cp; 159 char *cp;
160 llist_t *ll = headers_llist = rev_llist(headers_llist); 160 llist_t *ll = headers_llist = llist_rev(headers_llist);
161 while (ll) { 161 while (ll) {
162 size += strlen(ll->data) + 2; 162 size += strlen(ll->data) + 2;
163 ll = ll->link; 163 ll = ll->link;
diff --git a/procps/ps.c b/procps/ps.c
index a9da807a5..c06d333cd 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -253,7 +253,7 @@ int ps_main(int argc, char **argv)
253 opt_complementary = "o::"; 253 opt_complementary = "o::";
254 getopt32(argc, argv, "o:aAdefl", &opt_o); 254 getopt32(argc, argv, "o:aAdefl", &opt_o);
255 if (opt_o) { 255 if (opt_o) {
256 opt_o = rev_llist(opt_o); 256 opt_o = llist_rev(opt_o);
257 do { 257 do {
258 parse_o(opt_o->data); 258 parse_o(opt_o->data);
259 opt_o = opt_o->link; 259 opt_o = opt_o->link;
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
index df5f7c7dd..1db7870d4 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -66,6 +66,16 @@ testing "sort key range with multiple options" "sort -k2,3rn input" \
66egg 1 2 papyrus 66egg 1 2 papyrus
67" "$data" "" 67" "$data" ""
68 68
69testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
70d 2
71b 2
72c 3
73" "\
74c 3
75b 2
76d 2
77" ""
78
69testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\ 79testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
70/a/2 80/a/2
71/b/1 81/b/1