Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: vanishing history solved!
- X-seq: zsh-workers 16890
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxxxxx>
- Subject: PATCH: vanishing history solved!
- Date: Sun, 24 Mar 2002 00:22:35 -0800 (PST)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
My recent playing around with shell syntax errors has caused me to
finally find that elusive vanishing-history bug! It turns out to be a
problem with trying to call getiparam("SAVEHIST") when errflag is true:
the value returns is always "1", not the real SAVEHIST size. When this
happens the history-saving code dutifully truncates the history file
down to one line, just like it was told to do.
To fix this, I decided to turn SAVEHIST into a special-param (just like
HISTSIZE). This means we have the current, correct value of SAVEHIST
always available as an integer, ready to use. Also note that my set
function does not allow the value to become less than 0.
Are there repercussions to adding a new special parameter? I realize
that this means that people who used to enjoy setting SAVEHIST to "foo"
or "-20" are going to be disappointed that the value now turns into "0",
but I don't really see that as a problem. Comments?
I'll wait for positive feedback before checking this into CVS.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
--- Src/hist.c 22 Feb 2002 20:40:29 -0000 1.43
+++ Src/hist.c 24 Mar 2002 08:08:51 -0000
@@ -101,6 +101,11 @@
/**/
int histsiz;
+/* desired history-file size (in lines) */
+
+/**/
+int savehistsiz;
+
/* if = 1, we have performed history substitution on the current line *
* if = 2, we have used the 'p' modifier */
@@ -922,7 +927,7 @@
if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
static int max_unique_ct = 0;
if (!keep_going)
- max_unique_ct = getiparam("SAVEHIST");
+ max_unique_ct = savehistsiz;
do {
if (max_unique_ct-- <= 0 || he == hist_ring) {
max_unique_ct = 0;
@@ -1984,10 +1989,9 @@
FILE *out;
Histent he;
int xcurhist = curhist - !!(histactive & HA_ACTIVE);
- int savehist = getiparam("SAVEHIST");
int extended_history = isset(EXTENDEDHISTORY);
- if (!interact || savehist <= 0 || !hist_ring
+ if (!interact || savehistsiz <= 0 || !hist_ring
|| (!fn && !(fn = getsparam("HISTFILE"))))
return;
if (writeflags & HFILE_FAST) {
@@ -1998,7 +2002,7 @@
}
if (!he || !lockhistfile(fn, 0))
return;
- if (histfile_linect > savehist + savehist / 5)
+ if (histfile_linect > savehistsiz + savehistsiz / 5)
writeflags &= ~HFILE_FAST;
}
else {
@@ -2079,7 +2083,7 @@
hist_ring = NULL;
curhist = histlinect = 0;
- histsiz = savehist;
+ histsiz = savehistsiz;
histactive = 0;
createhisttable(); /* sets histtab */
Index: Src/params.c
--- Src/params.c 12 Feb 2002 19:32:57 -0000 1.62
+++ Src/params.c 24 Mar 2002 08:08:52 -0000
@@ -140,6 +140,7 @@
IPDEF1("EGID", egidgetfn, egidsetfn, PM_DONTIMPORT | PM_RESTRICTED),
IPDEF1("HISTSIZE", histsizegetfn, histsizesetfn, PM_RESTRICTED),
IPDEF1("RANDOM", randomgetfn, randomsetfn, 0),
+IPDEF1("SAVEHIST", savehistsizegetfn, savehistsizesetfn, PM_RESTRICTED),
IPDEF1("SECONDS", secondsgetfn, secondssetfn, 0),
IPDEF1("UID", uidgetfn, uidsetfn, PM_DONTIMPORT | PM_RESTRICTED),
IPDEF1("EUID", euidgetfn, euidsetfn, PM_DONTIMPORT | PM_RESTRICTED),
@@ -2913,6 +2914,25 @@
if ((histsiz = v) < 1)
histsiz = 1;
resizehistents();
+}
+
+/* Function to get value for special parameter `SAVEHIST' */
+
+/**/
+zlong
+savehistsizegetfn(Param pm)
+{
+ return savehistsiz;
+}
+
+/* Function to set value of special parameter `SAVEHIST' */
+
+/**/
+void
+savehistsizesetfn(Param pm, zlong v)
+{
+ if ((savehistsiz = v) < 0)
+ savehistsiz = 0;
}
/* Function to get value for special parameter `ERRNO' */
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Messages sorted by:
Reverse Date,
Date,
Thread,
Author