From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-request@euclid.skiles.gatech.edu Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.6/8.7.3) with ESMTP id KAA10378 for ; Fri, 22 Nov 1996 10:09:20 +1100 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id SAA21109; Thu, 21 Nov 1996 18:02:02 -0500 (EST) Resent-Date: Thu, 21 Nov 1996 18:02:02 -0500 (EST) Message-Id: <199611212302.PAA28359@bebop.clari.net> To: zsh-workers@math.gatech.edu Subject: Patch to add HIST_REDUCE_BLANKS Date: Thu, 21 Nov 1996 15:02:21 -0800 From: Wayne Davison Resent-Message-ID: <"qe0lC3.0.l95.gzDbo"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2446 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Here's a more modern version of my patch to remove superfluous blanks from the history lines (and never any significant blanks, like those in quotes). The previous version used the option HIST_STRIP_SPACES, but I thought that the name HIST_REDUCE_BLANKS would be better so that what is used in this patch. This is relative to zsh-3.1.0-test3. ..wayne.. ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- Index: Src/globals.h @@ -740,6 +740,7 @@ {"histignoredups", 'h', 0, 0}, {"histignorespace", 'g', 0, 0}, {"histnostore", 0, 0, 0}, + {"histreduceblanks", 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 @@ -636,6 +636,32 @@ return 0; } +/**/ +void +histreduceblanks(void) +{ + int i, len, pos, needblank; + + for (i = 0, len = 0; i < chwordpos; i += 2) { + len += chwords[i+1] - chwords[i] + + (i > 0 && chwords[i] > chwords[i-1]); + } + if (chline[len] == '\0') + return; + + for (i = 0, pos = 0; i < chwordpos; i += 2) { + len = chwords[i+1] - chwords[i]; + needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]); + if (pos != chwords[i]) { + memcpy(chline + pos, chline + chwords[i], len + needblank); + chwords[i] = pos; + chwords[i+1] = chwords[i] + len; + } + pos += len + needblank; + } + chline[pos] = '\0'; +} + /* say we're done using the history mechanism */ /**/ @@ -706,6 +732,9 @@ curhistent->ftim = 0L; curhistent->flags = 0; if (save) { + /* strip superfluous blanks, if desired */ + if (isset(HISTREDUCEBLANKS)) + histreduceblanks(); if (save == 2) { /* Don't duplicate history entry, but use the current rather than * the previous one, in case minor changes were made to it. Index: Src/zsh.h @@ -1107,6 +1107,7 @@ HISTIGNOREDUPS, HISTIGNORESPACE, HISTNOSTORE, + HISTREDUCEBLANKS, HISTVERIFY, HUP, IGNOREBRACES, ---8<------8<------8<------8<---cut here--->8------>8------>8------>8---