zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: vanishing history solved!
@ 2002-03-24  8:22 Wayne Davison
  2002-03-24 19:04 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Wayne Davison @ 2002-03-24  8:22 UTC (permalink / raw)
  To: Zsh Workers

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---


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PATCH: vanishing history solved!
  2002-03-24  8:22 PATCH: vanishing history solved! Wayne Davison
@ 2002-03-24 19:04 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2002-03-24 19:04 UTC (permalink / raw)
  To: Zsh Workers

On Mar 24, 12:22am, Wayne Davison wrote:
} 
} I'll wait for positive feedback before checking this into CVS.

Consider this positive feedback.  There were other bugs that I fixed
a while ago, related to fetching that parameter's value from the history
code; I think it should always have been a special.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-03-24 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-24  8:22 PATCH: vanishing history solved! Wayne Davison
2002-03-24 19:04 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).