zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Zsh Workers <zsh-workers@sunsite.dk>
Subject: PATCH: vanishing history solved!
Date: Sun, 24 Mar 2002 00:22:35 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.33L2.0203232347090.20227-100000@phong.blorf.net> (raw)

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


             reply	other threads:[~2002-03-24 15:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-24  8:22 Wayne Davison [this message]
2002-03-24 19:04 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33L2.0203232347090.20227-100000@phong.blorf.net \
    --to=wayned@users.sourceforge.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).