zsh-workers
 help / color / mirror / code / Atom feed
* History tidy up
@ 1997-09-26 15:48 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 1997-09-26 15:48 UTC (permalink / raw)
  To: Zsh hackers list

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-09-26 16:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-26 15:48 History tidy up Peter Stephenson

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