diff options
Diffstat (limited to 'Src/hist.c')
-rw-r--r-- | Src/hist.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/Src/hist.c b/Src/hist.c index 5fc40bd67..4c1039b67 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -87,6 +87,9 @@ mod_export zlong curhist; /**/ struct histent curline; +/***/ +int curline_linked; + /* current line count of allocated history entries */ /**/ @@ -261,6 +264,9 @@ hist_context_save(struct hist_stack *hs, int toplevel) */ hs->cstack = cmdstack; hs->csp = cmdsp; + hs->curline_linked = curline_linked; + + unlinkcurline(); stophist = 0; chline = NULL; @@ -300,6 +306,9 @@ hist_context_restore(const struct hist_stack *hs, int toplevel) zfree(cmdstack, CMDSTACKSZ); cmdstack = hs->cstack; cmdsp = hs->csp; + unlinkcurline(); + if (hs->curline_linked) + linkcurline(); } /* @@ -653,6 +662,7 @@ histsubchar(int c) (c == '}' || c == ';' || c == '\'' || c == '"' || c == '`')) { /* Neither event nor word designator, no expansion */ safeinungetc(c); + unqueue_signals(); return bangchar; } *ptr = 0; @@ -989,6 +999,7 @@ nohwe(void) /* these functions handle adding/removing curline to/from the hist_ring */ +/**/ static void linkcurline(void) { @@ -1001,11 +1012,15 @@ linkcurline(void) hist_ring = &curline; } curline.histnum = ++curhist; + curline_linked = 1; } +/**/ static void unlinkcurline(void) { + if (!curline_linked) + return; curline.up->down = curline.down; curline.down->up = curline.up; if (hist_ring == &curline) { @@ -1015,6 +1030,7 @@ unlinkcurline(void) hist_ring = curline.up; } curhist--; + curline_linked = 0; } /* initialize the history mechanism */ @@ -1034,10 +1050,11 @@ hbegin(int dohist) stophist = (!interact || unset(SHINSTDIN)) ? 2 : 0; else stophist = 0; + DPUTS(chline != NULL, "chline set at start of history"); /* * pws: We used to test for "|| (inbufflags & INP_ALIAS)" * in this test, but at this point we don't have input - * set up up so this can trigger unnecessarily. + * set up so this can trigger unnecessarily. * I don't see how the test at this point could ever be * useful, since we only get here when we're initialising * the history mechanism, before we've done any input. @@ -1291,11 +1308,10 @@ putoldhistentryontop(short keep_going) Histent prepnexthistent(void) { - Histent he; - int curline_in_ring = hist_ring == &curline; + Histent he; + int relink_curline = curline_linked; - if (curline_in_ring) - unlinkcurline(); + unlinkcurline(); if (hist_ring && hist_ring->node.flags & HIST_TMPSTORE) { curhist--; freehistnode(&hist_ring->node); @@ -1319,7 +1335,7 @@ prepnexthistent(void) he = hist_ring; } he->histnum = ++curhist; - if (curline_in_ring) + if (relink_curline) linkcurline(); return he; } @@ -1394,8 +1410,7 @@ hend(Eprog prog) queue_signals(); if (histdone & HISTFLAG_SETTY) settyinfo(&shttyinfo); - if (!(histactive & HA_NOINC)) - unlinkcurline(); + unlinkcurline(); if (histactive & HA_NOINC) { zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); @@ -1417,7 +1432,7 @@ hend(Eprog prog) DPUTS(hptr < chline, "History end pointer off start of line"); *hptr = '\0'; } - { + if (*chline) { LinkList hookargs = newlinklist(); int save_errflag = errflag; errflag = 0; @@ -1426,6 +1441,7 @@ hend(Eprog prog) addlinknode(hookargs, chline); callhookfunc("zshaddhistory", hookargs, 1, &hookret); + errflag &= ~ERRFLAG_ERROR; errflag |= save_errflag; } /* For history sharing, lock history file once for both read and write */ @@ -1842,7 +1858,7 @@ chrealpath(char **junkptr) # ifdef REALPATH_ACCEPTS_NULL char *lastpos, *nonreal, *real; # else - char *lastpos, *nonreal, pathbuf[PATH_MAX]; + char *lastpos, *nonreal, pathbuf[PATH_MAX+1]; char *real = pathbuf; # endif #endif @@ -3622,7 +3638,7 @@ int pushhiststack(char *hf, zlong hs, zlong shs, int level) { struct histsave *h; - int curline_in_ring = (histactive & HA_ACTIVE) && hist_ring == &curline; + int relink_curline = curline_linked; if (histsave_stack_pos == histsave_stack_size) { histsave_stack_size += 5; @@ -3630,8 +3646,7 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level) histsave_stack_size * sizeof (struct histsave)); } - if (curline_in_ring) - unlinkcurline(); + unlinkcurline(); h = &histsave_stack[histsave_stack_pos++]; @@ -3666,7 +3681,7 @@ pushhiststack(char *hf, zlong hs, zlong shs, int level) savehistsiz = shs; inithist(); /* sets histtab */ - if (curline_in_ring) + if (relink_curline) linkcurline(); return histsave_stack_pos; @@ -3678,13 +3693,12 @@ int pophiststack(void) { struct histsave *h; - int curline_in_ring = (histactive & HA_ACTIVE) && hist_ring == &curline; + int relink_curline = curline_linked; if (histsave_stack_pos == 0) return 0; - if (curline_in_ring) - unlinkcurline(); + unlinkcurline(); deletehashtable(histtab); zsfree(lasthist.text); @@ -3707,7 +3721,7 @@ pophiststack(void) histsiz = h->histsiz; savehistsiz = h->savehistsiz; - if (curline_in_ring) + if (relink_curline) linkcurline(); return histsave_stack_pos + 1; |