Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: hist_strip_spaces



One last(?) problem with my too-hurried patch -- it sometimes adds
spaces between tokens that don't need them (like ';' and '>').  This
diff takes care of it.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
@@ -652,12 +652,14 @@
 void
 histstrip(Histent he)
 {
-    int i, len;
+    int i, len, needspace;
     int limit = he->nwords*2;
     char *str, *s;
 
-    for (i = 0, len = he->nwords-1; i < limit; i += 2)
-	len += he->words[i+1] - he->words[i];
+    for (i = 0, len = 0; i < limit; i += 2) {
+	len += he->words[i+1] - he->words[i]
+	     + (i > 0 && he->words[i] > he->words[i-1]);
+    }
     if (he->text[len] == '\0')
 	return;
 
@@ -665,13 +667,13 @@
 
     for (i = 0, s = str; i < limit; i += 2) {
 	len = he->words[i+1] - he->words[i];
-	memcpy(s, he->text + he->words[i], len);
+	needspace = (i < limit-2 && he->words[i+2] > he->words[i+1]);
+	memcpy(s, he->text + he->words[i], len + needspace);
 	he->words[i] = s - str;
 	he->words[i+1] = he->words[i] + len;
-	s += len;
-	*s++ = ' ';
+	s += len + needspace;
     }
-    s[-1] = '\0';
+    *s = '\0';
 
     if (he->text != chline)
 	zsfree(he->text);
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



Messages sorted by: Reverse Date, Date, Thread, Author