zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayne@clari.net>
To: Zsh hackers list <zsh-workers@math.gatech.edu>
Subject: Re: hist_strip_spaces
Date: Tue, 13 Aug 1996 02:22:41 -0700	[thread overview]
Message-ID: <199608130922.CAA05976@bebop.clari.net> (raw)
In-Reply-To: wayne's message of Mon, 12 Aug 1996 14:13:49 -0700. <199608122113.OAA03985@bebop.clari.net>

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---


  reply	other threads:[~1996-08-13  9:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-12 12:56 histignoredups done properly Peter Stephenson
1996-08-12 19:17 ` hist_strip_spaces (was Re: histignoredups done properly) Wayne Davison
1996-08-12 21:13   ` hist_strip_spaces Wayne Davison
1996-08-13  9:22     ` Wayne Davison [this message]
1996-08-13  5:48   ` hist_strip_spaces (was Re: histignoredups done properly) Andrej Borsenkow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199608130922.CAA05976@bebop.clari.net \
    --to=wayne@clari.net \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).