zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: History tidy up
Date: Fri, 26 Sep 1997 17:48:54 +0200	[thread overview]
Message-ID: <199709261548.RAA10809@hydra.ifh.de> (raw)

Following on from yesterday's patch for fc, here's a minor but useful
tidy up to the history code which gets rid of the need for the
delayrem clutter in bin_fc().  Instead, removing a history entry when
the history is not already active (this only ever happened in fc
anyway) is delayed until the history code is next activated.
(Strickly speaking, the entry is marked as empty, but the counter is
not altered; this is sensible because hbegin() is in any case
responsible for keeping the counter right.)

Altering the history code usually leads to off-by-one errors somewhere
or other, but I couldn't see any.  I'd be happy for anyone not to take
my word for it.

One other additional fix:  testing for (histactive & HA_ACTIVE) is
more sensible than just testing for histactive.

*** Src/builtin.c.rh	Fri Sep 26 16:55:05 1997
--- Src/builtin.c	Fri Sep 26 17:38:55 1997
***************
*** 914,920 ****
  int
  bin_fc(char *nam, char **argv, char *ops, int func)
  {
!     int first = -1, last = -1, retval, delayrem, minflag = 0;
      char *s;
      struct asgment *asgf = NULL, *asgl = NULL;
      Comp com = NULL;
--- 914,920 ----
  int
  bin_fc(char *nam, char **argv, char *ops, int func)
  {
!     int first = -1, last = -1, retval, minflag = 0;
      char *s;
      struct asgment *asgf = NULL, *asgl = NULL;
      Comp com = NULL;
***************
*** 933,942 ****
  	    return 1;
  	}
      }
-     delayrem = 0;
-     if (!(ops['l'] && unset(HISTNOSTORE)) &&
- 	!(ops['R'] || ops['W'] || ops['A']))
- 	delayrem = 1;
      if (ops['R']) {
  	/* read history from a file */
  	readhistfile(*argv ? *argv : getsparam("HISTFILE"), 1);
--- 933,938 ----
***************
*** 954,959 ****
--- 950,957 ----
  		     (ops['I'] ? 3 : 1));
  	return 0;
      }
+     if (!(ops['l'] && unset(HISTNOSTORE)))
+ 	remhist();
      /* put foo=bar type arguments into the substitution list */
      while (*argv && equalsplit(*argv, &s)) {
  	Asgment a = (Asgment) alloc(sizeof *a);
***************
*** 972,1000 ****
      if (*argv) {
  	minflag = **argv == '-';
  	first = fcgetcomm(*argv);
! 	if (first == -1) {
! 	    if (delayrem)
! 		remhist();
  	    return 1;
- 	}
  	argv++;
      }
      /* interpret and check second history line specifier */
      if (*argv) {
  	last = fcgetcomm(*argv);
! 	if (last == -1) {
! 	    if (delayrem)
! 		remhist();
  	    return 1;
- 	}
  	argv++;
      }
      /* There is a maximum of two history specifiers.  At least, there *
       * will be as long as the history list is one-dimensional.        */
      if (*argv) {
  	zwarnnam("fc", "too many arguments", NULL, 0);
- 	if (delayrem)
- 	    remhist();
  	return 1;
      }
      /* default values of first and last, and range checking */
--- 970,990 ----
      if (*argv) {
  	minflag = **argv == '-';
  	first = fcgetcomm(*argv);
! 	if (first == -1)
  	    return 1;
  	argv++;
      }
      /* interpret and check second history line specifier */
      if (*argv) {
  	last = fcgetcomm(*argv);
! 	if (last == -1)
  	    return 1;
  	argv++;
      }
      /* There is a maximum of two history specifiers.  At least, there *
       * will be as long as the history list is one-dimensional.        */
      if (*argv) {
  	zwarnnam("fc", "too many arguments", NULL, 0);
  	return 1;
      }
      /* default values of first and last, and range checking */
***************
*** 1036,1044 ****
  		    if (stuff(fil))
  			zwarnnam("fc", "%e: %s", s, errno);
  		    else {
- 			if (delayrem)
- 			    remhist();
- 			delayrem = 0;
  			loop(0,1);
  			retval = lastval;
  		    }
--- 1026,1031 ----
***************
*** 1046,1053 ****
  	}
  	unlink(fil);
      }
-     if (delayrem)
- 	remhist();
      return retval;
  }
  
--- 1033,1038 ----
*** Src/hist.c.rh	Mon Jun  2 08:51:12 1997
--- Src/hist.c	Fri Sep 26 16:56:41 1997
***************
*** 565,570 ****
--- 565,572 ----
      chwords = zalloc((chwordlen = 16)*sizeof(short));
      chwordpos = 0;
  
+     if (histactive & HA_JUNKED)
+ 	curhist--;
      curhistent = gethistent(curhist);
      if (!curhistent->ftim)
  	curhistent->ftim = time(NULL);
***************
*** 744,750 ****
  	    zsfree(he->text);
  	    he->text = NULL;
  	    histactive |= HA_JUNKED;
! 	    curhist--;
  	}
      } else
  	histactive |= HA_NOSTORE;
--- 746,752 ----
  	    zsfree(he->text);
  	    he->text = NULL;
  	    histactive |= HA_JUNKED;
! 	    /* curhist-- is delayed until the next hbegin() */
  	}
      } else
  	histactive |= HA_NOSTORE;
***************
*** 1481,1487 ****
      else
  	out = fdopen(open(unmeta(s), O_CREAT | O_WRONLY | O_TRUNC, 0600), "w");
      if (out) {
! 	for (; ev <= curhist - !!histactive; ev++) {
  	    ent = gethistent(ev);
  	    if (app & 2) {
  		if (ent->flags & HIST_OLD)
--- 1483,1489 ----
      else
  	out = fdopen(open(unmeta(s), O_CREAT | O_WRONLY | O_TRUNC, 0600), "w");
      if (out) {
! 	for (; ev <= curhist - !!(histactive & HA_ACTIVE); ev++) {
  	    ent = gethistent(ev);
  	    if (app & 2) {
  		if (ent->flags & HIST_OLD)

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


                 reply	other threads:[~1997-09-26 16:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=199709261548.RAA10809@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).