1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-04 06:14:50 +01:00

31750: fix for HISTREDUCEBLANKS option.

Don't truncate line after marked words if there's more
non-white-space text, which is probably comments.
This commit is contained in:
Peter Stephenson 2013-07-24 15:54:55 +01:00
parent 31c5c7bb11
commit e282fd8ecb
2 changed files with 33 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2013-07-24 Peter Stephenson <p.stephenson@samsung.com>
* Src/hist.c: 31570: with HIST_REDUCE_BLANKS don't truncate
the line after the last word if there's more non-white-space
text (probably a comment but we don't assume that).
2013-07-22 Peter Stephenson <p.w.stephenson@ntlworld.com>
* unposted: Src/lex.c: correct previous commit: should call

View file

@ -927,7 +927,8 @@ hbegin(int dohist)
void
histreduceblanks(void)
{
int i, len, pos, needblank, spacecount = 0;
int i, len, pos, needblank, spacecount = 0, trunc_ok;
char *lastptr, *ptr;
if (isset(HISTIGNORESPACE))
while (chline[spacecount] == ' ') spacecount++;
@ -939,6 +940,12 @@ histreduceblanks(void)
if (chline[len] == '\0')
return;
/* Remember where the delimited words end */
if (chwordpos)
lastptr = chline + chwords[chwordpos-1];
else
lastptr = chline;
for (i = 0, pos = spacecount; i < chwordpos; i += 2) {
len = chwords[i+1] - chwords[i];
needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
@ -949,7 +956,25 @@ histreduceblanks(void)
}
pos += len + needblank;
}
chline[pos] = '\0';
/*
* A terminating comment isn't recorded as a word.
* Only truncate the line if just whitespace remains.
*/
trunc_ok = 1;
for (ptr = lastptr; *ptr; ptr++) {
if (!inblank(*ptr)) {
trunc_ok = 0;
break;
}
}
if (trunc_ok) {
chline[pos] = '\0';
} else {
ptr = chline + pos;
while ((*ptr++ = *lastptr++))
;
}
}
/**/