From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4189 invoked from network); 26 Sep 1997 16:03:32 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 26 Sep 1997 16:03:32 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id LAA19842; Fri, 26 Sep 1997 11:48:23 -0400 (EDT) Resent-Date: Fri, 26 Sep 1997 11:48:23 -0400 (EDT) Message-Id: <199709261548.RAA10809@hydra.ifh.de> To: zsh-workers@math.gatech.edu (Zsh hackers list) Subject: History tidy up Date: Fri, 26 Sep 1997 17:48:54 +0200 From: Peter Stephenson Resent-Message-ID: <"xgskH.0.zr4.7bzAq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3531 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 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.