From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (root@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.5/8.7.3) with ESMTP id FAA05073 for ; Tue, 13 Aug 1996 05:53:20 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id PAA10965; Mon, 12 Aug 1996 15:20:49 -0400 (EDT) Resent-Date: Mon, 12 Aug 1996 15:20:49 -0400 (EDT) Message-Id: <199608121917.MAA03396@bebop.clari.net> To: Peter Stephenson Cc: Zsh hackers list Subject: hist_strip_spaces (was Re: histignoredups done properly) In-reply-to: pws's message of Mon, 12 Aug 1996 14:56:14 +0200. <199608121256.OAA02157@hydra.ifh.de> Date: Mon, 12 Aug 1996 12:17:53 -0700 From: Wayne Davison Resent-Message-ID: <"F_XSo3.0.Dh2.BGu3o"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1952 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Peter Stephenson writes: > This fixes histignoredups so that only lines which are really > different are stored; insignificant changes in whitespace are not > treated as differences. Nice change. I was working on something similar over the weekend: the removal of insignificant spaces from history lines. Since I think my change complements your patch, I've based this diff on previously applying your histignoredups patch. Since it may be that not everyone will want this, I made it depend on a new option, HIST_STRIP_SPACES. I haven't modified the documentation yet, however. Note that since the histstrip() routine may change curhistent->text, I had to change the cleanup code that frees chline. The new code has the additional benefit of being much clearer in what it is trying to do (it took me a while to figure out what the old code was for). ..wayne.. ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- Index: Src/globals.h @@ -720,6 +720,7 @@ {"histignoredups", 'h', 0, 0}, {"histignorespace", 'g', 0, 0}, {"histnostore", 0, 0, 0}, + {"histstripspaces", 0, 0, 0}, {"histverify", 0, 0, 0}, {"hup", 0, 0, OPT_EMULATE|OPT_ZSH}, {"ignorebraces", 'I', 0, OPT_EMULATE|OPT_SH}, Index: Src/hist.c @@ -648,6 +648,36 @@ return 0; } +/**/ +void +histstrip(Histent he) +{ + int i, len; + 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]; + if (len == he->words[limit-1]) + return; + + str = zalloc(len+1); + + 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); + he->words[i] = s - str; + he->words[i+1] = he->words[i] + len; + s += len; + *s++ = ' '; + } + s[-1] = '\0'; + + if (he->text != chline) + zsfree(he->text); + he->text = str; +} + /* say we're done using the history mechanism */ /**/ @@ -694,7 +724,7 @@ chwordpos -= 2; he = gethistent(curhist - 1); if (isset(HISTIGNOREDUPS) && he->text && !histcmp(he)) - save = 2; + save = isset(HISTSTRIPSPACES)? 0 : 2; } } if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) { @@ -737,16 +767,13 @@ memcpy(curhistent->words, chwords, curhistent->nwords*2*sizeof(short)); } + if (isset(HISTSTRIPSPACES)) + histstrip(curhistent); } else remhist(); - if (chline && !curhistent->text) - zfree(chline, hlinesz); - if (curhistent->text) { - char *s = ztrdup(curhistent->text); - - zfree(curhistent->text, hlinesz); - curhistent->text = s; - } + if (curhistent->text == chline) + curhistent->text = ztrdup(chline); + zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); chline = NULL; return !(flag & HISTFLAG_NOEXEC || errflag); Index: Src/zsh.h @@ -1102,6 +1102,7 @@ HISTIGNOREDUPS, HISTIGNORESPACE, HISTNOSTORE, + HISTSTRIPSPACES, HISTVERIFY, HUP, IGNOREBRACES, ---8<------8<------8<------8<---cut here--->8------>8------>8------>8---