svn commit: trunk/busybox: archival coreutils include libbb network etc...

vda at busybox.net vda at busybox.net
Sat Feb 17 18:11:46 UTC 2007


Author: vda
Date: 2007-02-17 10:11:45 -0800 (Sat, 17 Feb 2007)
New Revision: 17919

Log:
sort: fix multiple -k (was ignoring all except last)


Modified:
   trunk/busybox/archival/tar.c
   trunk/busybox/coreutils/od_bloaty.c
   trunk/busybox/coreutils/sort.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/llist.c
   trunk/busybox/networking/wget.c
   trunk/busybox/procps/ps.c
   trunk/busybox/testsuite/sort.tests


Changeset:
Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/archival/tar.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -864,7 +864,7 @@
 		llist_add_to(&tar_handle->accept, argv[optind]);
 		optind++;
 	}
-	tar_handle->accept = rev_llist(tar_handle->accept);
+	tar_handle->accept = llist_rev(tar_handle->accept);
 
 	if (tar_handle->accept || tar_handle->reject)
 		tar_handle->filter = filter_accept_reject_list;

Modified: trunk/busybox/coreutils/od_bloaty.c
===================================================================
--- trunk/busybox/coreutils/od_bloaty.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/coreutils/od_bloaty.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -1312,7 +1312,7 @@
 	if (opt & OPT_l) decode_format_string("d4");
 	if (opt & OPT_o) decode_format_string("o2");
 	//if (opt & OPT_t)...
-	lst_t = rev_llist(lst_t);
+	lst_t = llist_rev(lst_t);
 	while (lst_t) {
 		decode_format_string(lst_t->data);
 		lst_t = lst_t->link;

Modified: trunk/busybox/coreutils/sort.c
===================================================================
--- trunk/busybox/coreutils/sort.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/coreutils/sort.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -276,7 +276,8 @@
 {
 	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 @@
 
 	/* 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 @@
 		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 @@
 			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 @@
 				str_k++;
 			}
 		}
+		/* leaking lst_k... */
+		lst_k = lst_k->link;
 	}
 #endif
 	/* global b strips leading and trailing spaces */

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/include/libbb.h	2007-02-17 18:11:45 UTC (rev 17919)
@@ -473,7 +473,7 @@
 extern void llist_add_to_end(llist_t **list_head, void *data);
 extern void *llist_pop(llist_t **elm);
 extern void llist_free(llist_t *elm, void (*freeit)(void *data));
-extern llist_t* rev_llist(llist_t *list);
+extern llist_t* llist_rev(llist_t *list);
 
 enum {
 	LOGMODE_NONE = 0,

Modified: trunk/busybox/libbb/llist.c
===================================================================
--- trunk/busybox/libbb/llist.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/libbb/llist.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -74,7 +74,7 @@
 
 /* Reverse list order. Useful since getopt32 saves option params
  * in reverse order */
-llist_t *rev_llist(llist_t * list)
+llist_t *llist_rev(llist_t * list)
 {
 	llist_t *new = NULL;
 

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/networking/wget.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -157,7 +157,7 @@
 	if (headers_llist) {
 		int size = 1;
 		char *cp;
-		llist_t *ll = headers_llist = rev_llist(headers_llist);
+		llist_t *ll = headers_llist = llist_rev(headers_llist);
 		while (ll) {
 			size += strlen(ll->data) + 2;
 			ll = ll->link;

Modified: trunk/busybox/procps/ps.c
===================================================================
--- trunk/busybox/procps/ps.c	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/procps/ps.c	2007-02-17 18:11:45 UTC (rev 17919)
@@ -253,7 +253,7 @@
 	opt_complementary = "o::";
 	getopt32(argc, argv, "o:aAdefl", &opt_o);
 	if (opt_o) {
-		opt_o = rev_llist(opt_o);
+		opt_o = llist_rev(opt_o);
 		do {
 			parse_o(opt_o->data);
 			opt_o = opt_o->link;

Modified: trunk/busybox/testsuite/sort.tests
===================================================================
--- trunk/busybox/testsuite/sort.tests	2007-02-17 17:55:45 UTC (rev 17918)
+++ trunk/busybox/testsuite/sort.tests	2007-02-17 18:11:45 UTC (rev 17919)
@@ -66,6 +66,16 @@
 egg	1	2	papyrus
 " "$data" ""
 
+testing "sort key range with two -k options" "sort -k 2,2n -k 1,1r input" "\
+d 2
+b 2
+c 3
+" "\
+c 3
+b 2
+d 2
+" ""
+
 testing "sort with non-default leading delim 1" "sort -n -k2 -t/ input" "\
 /a/2
 /b/1




More information about the busybox-cvs mailing list