From b4c5de44f991022843f3a2f100240bc34ee77d88 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 18 Jul 2000 07:55:13 +0000 Subject: [PATCH] + Got rid of the spaceflag variable. + Make sure that the curline.histnum variable is accurate at the end of our history processing, even if we read in some foreign history and/or if we replaced the prior line because it was a duplicate of the current one. This enables the history (fc -l) command to work properly, even if the current command was HIST_NO_SPACE-ed away. + Don't allow remhist() to remove the last line in the history if we didn't store the current command. --- Src/hist.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Src/hist.c b/Src/hist.c index 83f661c9b..28175c3f3 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -55,12 +55,7 @@ void (*addtoline) _((int)); /**/ mod_export int stophist; - -/* this line began with a space, so junk it if HISTIGNORESPACE is on */ - -/**/ -int spaceflag; - + /* if != 0, we are expanding the current line */ /**/ @@ -741,7 +736,7 @@ mod_export void hbegin(int dohist) { isfirstln = isfirstch = 1; - errflag = histdone = spaceflag = 0; + errflag = histdone = 0; stophist = (!dohist || !interact || unset(SHINSTDIN)) ? 2 : 0; if (stophist == 2 || (inbufflags & INP_ALIAS)) { chline = hptr = NULL; @@ -976,8 +971,10 @@ hend(void) && (hist_ignore_all_dups = isset(HISTIGNOREALLDUPS)) != 0) histremovedups(); /* For history sharing, lock history file once for both read and write */ - if (isset(SHAREHISTORY) && lockhistfile(hf, 0)) + if (isset(SHAREHISTORY) && lockhistfile(hf, 0)) { readhistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST); + curline.histnum = curhist+1; + } flag = histdone; histdone = 0; if (hptr < chline + 1) @@ -990,8 +987,7 @@ hend(void) } else save = 0; } - if (!*chline || !strcmp(chline, "\n") || - (isset(HISTIGNORESPACE) && spaceflag)) + if (chwordpos <= 2 || (isset(HISTIGNORESPACE) && *chline == ' ')) save = 0; } if (flag & (HISTFLAG_DONE | HISTFLAG_RECALL)) { @@ -1038,6 +1034,7 @@ hend(void) */ keepflags = he->flags & HIST_OLD; /* Avoid re-saving */ freehistdata(he, 0); + curline.histnum = curhist; } else { keepflags = 0; he = prepnexthistent(); @@ -1073,7 +1070,7 @@ remhist(void) if (hist_ring == &curline) return; if (!(histactive & HA_ACTIVE)) { - if (!(histactive & HA_JUNKED)) { + if (!(histactive & HA_JUNKED) && curline.histnum == curhist) { freehistnode((HashNode)hist_ring); histactive |= HA_JUNKED; /* curhist-- is delayed until the next hbegin() */