[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#373704: Wrong patch



Package: busybox
Version: 1:1.1.3-3
Followup-For: Bug #373704

Sorry, I send the wrong patch last night.

MfG
	Goswin

-- System Information:
Debian Release: 4.0
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-frosties
Locale: LANG=C, LC_CTYPE=de_DE (charmap=ISO-8859-1)

Versions of packages busybox depends on:
ii  libc6                        2.3.6.ds1-9 GNU C Library: Shared libraries

busybox recommends no packages.

-- no debconf information
diff -u busybox-1.1.3/debian/changelog busybox-1.1.3/debian/changelog
--- busybox-1.1.3/debian/changelog
+++ busybox-1.1.3/debian/changelog
@@ -1,3 +1,15 @@
+busybox (1:1.1.3-3a0.mrvn.2) unstable; urgency=low
+
+  * fix more sort
+
+ -- Goswin von Brederlow <mrvn@frosties>  Mon, 15 Jan 2007 00:03:02 +0100
+
+busybox (1:1.1.3-3a0.mrvn.1) unstable; urgency=low
+
+  * Fix sort issues to behave like coreutils sort.
+
+ -- Goswin von Brederlow <mrvn@frosties>  Sat, 13 Jan 2007 18:26:58 +0100
+
 busybox (1:1.1.3-3) unstable; urgency=low
 
   * debian/control:
diff -u busybox-1.1.3/coreutils/sort.c busybox-1.1.3/coreutils/sort.c
--- busybox-1.1.3/coreutils/sort.c
+++ busybox-1.1.3/coreutils/sort.c
@@ -58,50 +58,60 @@
 
 static char *get_key(char *str, struct sort_key *key, int flags)
 {
-	int start=0,end,len,i,j;
-
+	int start=0,end,len,i,j,r3=0;
 	/* Special case whole string, so we don't have to make a copy */
 	if(key->range[0]==1 && !key->range[1] && !key->range[2] && !key->range[3]
-		&& !(flags&(FLAG_b&FLAG_d&FLAG_f&FLAG_i&FLAG_bb))) return str;
+		&& !(flags&(FLAG_b|FLAG_d|FLAG_f|FLAG_i|FLAG_bb))) return str;
 	/* Find start of key on first pass, end on second pass*/
 	len=strlen(str);
 
+	/* key->range[3] == 0 means before the next key starts */
+	if (!key->range[3]) r3=1;
+
+	/* Find start of key */
 	for(j=0;j<2;j++) {
 		if(!key->range[2*j]) end=len;
 		/* Loop through fields */
 		else {
 			end=0;
-			for(i=1;i<key->range[2*j]+j;i++) {
-				/* Skip leading blanks or first separator */
-				if(str[end]) {
-					if(!key_separator && isspace(str[end]))
-						while(isspace(str[end])) end++;
-				}
-				/* Skip body of key */
-				for(;str[end];end++) {
+			for(i=1;i<key->range[2*j]+j*r3;i++) {
+				/* Skip leading blanks */
+				if(str[end] && !key_separator)
+				    while(isspace(str[end])) end++;
+				/* Skip body of key and separator */
+				while(str[end]) {
 					if(key_separator) {
-						if(str[end]==key_separator) break;
-					} else if(isspace(str[end])) break;
+						if(str[end++]==key_separator) break;
+					} else {
+						if(isspace(str[end])) break;
+						end++;
+					}
 				}
 			}
 		}
 		if(!j) start=end;
 	}
-	/* Key with explicit separator starts after separator */
-	if(key_separator && str[start]==key_separator) start++;
+	/* key->range[3] == 0 means before the next key starts */
+	/* rewind the separator */
+	if(key_separator && !key->range[3] && str[end]) end--;
 	/* Strip leading whitespace if necessary */
-	if(flags&FLAG_b) while(isspace(str[start])) start++;
-	/* Strip trailing whitespace if necessary */
-	if(flags&FLAG_bb) while(end>start && isspace(str[end-1])) end--;
+	if(flags&FLAG_b) {
+		while(isspace(str[start])) start++;
+		/* key end with offset also strips leading spaces */
+		if(key->range[3]) while(isspace(str[end])) end++;
+	}
 	/* Handle offsets on start and end */
 	if(key->range[3]) {
-		end+=key->range[3]-1;
+		end+=key->range[3];
 		if(end>len) end=len;
 	}
 	if(key->range[1]) {
 		start+=key->range[1]-1;
 		if(start>len) start=len;
 	}
+	/* Strip trailing whitespace if necessary */
+	/* FIXME: not sure about this one. Needs testing with -kx,y.z */
+	if(flags&FLAG_bb) while(end>start && isspace(str[end-1])) end--;
 	/* Make the copy */
 	if(end<start) end=start;
 	str=bb_xstrndup(str+start,end-start);

Reply to: