Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: 3.0.6-pre-4: whitespace-ignoring strcmp for history
- X-seq: zsh-workers 6476
- From: Wayne Davison <wayne@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- Subject: PATCH: 3.0.6-pre-4: whitespace-ignoring strcmp for history
- Date: Sat, 5 Jun 1999 14:01:43 -0700 (PDT)
- Cc: zsh-workers@xxxxxxxxxxxxxx
- In-reply-to: <990605171123.ZM8632@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Here's a minor improvement for 3.0.6-pre-4:
When the histcmp() function is comparing a line that wasn't lexed,
it now ignores whitespace differences (I took my whitespace-ignoring
strcmp() code from my recent history changes and integrated it into
the histcmp() function).
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
--- zsh-3.0.6-pre-4/Src/hist.c	Sat Jun  5 12:41:11 1999
+++ ./Src/hist.c	Sat Jun  5 12:46:31 1999
@@ -592,11 +592,30 @@
     int kword, lword;
     int nwords = chwordpos/2;
 
-    /* If the history entry came from a file, the words were not
-     * divided by the lexer so we have to resort to strcmp.
+    /* If the history entry came from a file, the words were not divided by
+     * the lexer so we have to resort to a whitespace-ignoring compare.
      */
-    if (he->flags & HIST_READ)
-	return strcmp(he->text, chline);
+    if (he->flags & HIST_READ) {
+	char *str1 = he->text, *str2 = chline;
+
+	while (inblank(*str1)) str1++;
+	while (inblank(*str2)) str2++;
+	while (*str1 && *str2) {
+	    if (inblank(*str1)) {
+		if (!inblank(*str2))
+		    break;
+		do str1++; while (inblank(*str1));
+		do str2++; while (inblank(*str2));
+	    }
+	    else {
+		if (*str1 != *str2)
+		    break;
+		str1++;
+		str2++;
+	    }
+	}
+	return *str1 - *str2;
+    }
 
     if (nwords != he->nwords)
 	return 1;
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Messages sorted by:
Reverse Date,
Date,
Thread,
Author