aboutsummaryrefslogtreecommitdiff
path: root/coreutils/sort.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-17 18:11:45 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-02-17 18:11:45 +0000
commit8aea7ebb51f7d0b978900de01e2fb3b171497129 (patch)
treea43331e67e2472f7a8c415aee09ce17137d734a6 /coreutils/sort.c
parentd01c2739ee04c79a8da5fb68ef889d862e747921 (diff)
downloadbusybox-w32-8aea7ebb51f7d0b978900de01e2fb3b171497129.tar.gz
busybox-w32-8aea7ebb51f7d0b978900de01e2fb3b171497129.tar.bz2
busybox-w32-8aea7ebb51f7d0b978900de01e2fb3b171497129.zip
sort: fix multiple -k (was ignoring all except last)
git-svn-id: svn://busybox.net/trunk/busybox@17919 69ca8d6d-28ef-0310-b511-8ec308f3f277
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)
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 */