From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19959 invoked from network); 9 Jan 1997 09:36:00 -0000 Received: from euclid.skiles.gatech.edu (list@130.207.146.50) by coral.primenet.com.au with SMTP; 9 Jan 1997 09:36:00 -0000 Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id EAA15732; Thu, 9 Jan 1997 04:28:49 -0500 (EST) Resent-Date: Thu, 9 Jan 1997 04:28:49 -0500 (EST) Message-Id: <199701090929.KAA10712@hydra.ifh.de> To: zsh-workers@math.gatech.edu Subject: Re: !cmd doesn't work in 3.0.3-test3 In-reply-to: "Vinnie Shelton"'s message of "Thu, 09 Jan 1997 01:02:17 MET." <199701090602.BAA29171@spacely.icd.teradyne.com> Date: Thu, 09 Jan 1997 10:29:51 +0100 From: Peter Stephenson Resent-Message-ID: <"K1pM63.0.lr3.GfBro"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2755 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Vinnie Shelton wrote: > When I backed out Peter's patch (article 2748), !cmd worked again. > > !cmd no longer completes is 3.03.0.3-test3. Yes, I didn't handle multiple histories on top of one another properly: curhist got incremented too many times. I've also improved readability with some #define's for histactive. (In my defence, for some weird reason it worked OK after running my own initialisation files.) *** Src/hist.c.hist1 Wed Jan 8 14:58:02 1997 --- Src/hist.c Thu Jan 9 10:18:41 1997 *************** *** 32,50 **** #include "zsh.h" /* ! * Note on histactive: bit 0 says the history mechanism is active; ! * bit 1 says junk the line being processed by the history ! * when finished with it if (histactive & 1); bit 2 says we have already ! * junked a line when !(histactive & 1). ! * ! * Note on curhist: with !(histactive & 1), this points to the ! * last line actually added to the history list. With (histactive & 1), * the line does not get added to the list until hend(), if at all. * However, curhist is incremented to reflect the current line anyway. * Thus if the line is not added to the list, curhist must be * decremented in hend(). */ extern int cs, ll; /* Array of word beginnings and endings in current history line. */ --- 32,51 ---- #include "zsh.h" /* ! * Note on curhist: with history active, this points to the ! * last line actually added to the history list. With history inactive, * the line does not get added to the list until hend(), if at all. * However, curhist is incremented to reflect the current line anyway. * Thus if the line is not added to the list, curhist must be * decremented in hend(). */ + /* Bits of histactive variable */ + #define HA_ACTIVE (1<<0) /* History mechanism is active */ + #define HA_NOSTORE (1<<1) /* Don't store the line when finished */ + #define HA_JUNKED (1<<2) /* Last history line was already junked */ + #define HA_NOINC (1<<3) /* Don't store, curhist not incremented */ + extern int cs, ll; /* Array of word beginnings and endings in current history line. */ *************** *** 597,607 **** if (interact && isset(SHINSTDIN) && !strin) { attachtty(mypgrp); defev = curhist; ! histactive = 1; } else ! histactive = 3; ! ! curhist++; } /* say we're done using the history mechanism */ --- 598,607 ---- if (interact && isset(SHINSTDIN) && !strin) { attachtty(mypgrp); defev = curhist; ! histactive = HA_ACTIVE; ! curhist++; } else ! histactive = HA_NOINC; } /* say we're done using the history mechanism */ *************** *** 614,624 **** Histent he; DPUTS(!chline, "BUG: chline is NULL in hend()"); ! if (histactive & 2) { zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); chline = NULL; ! curhist--; histactive = 0; return 1; } --- 614,625 ---- Histent he; DPUTS(!chline, "BUG: chline is NULL in hend()"); ! if (histactive & (HA_NOSTORE|HA_NOINC)) { zfree(chline, hlinesz); zfree(chwords, chwordlen*sizeof(short)); chline = NULL; ! if (!(histactive & HA_NOINC)) ! curhist--; histactive = 0; return 1; } *************** *** 697,713 **** void remhist(void) { ! if (!(histactive & 1)) { ! if (!(histactive & 4)) { /* make sure this doesn't show up when we do firsthist() */ Histent he = gethistent(curhist); zsfree(he->text); he->text = NULL; ! histactive |= 4; curhist--; } } else ! histactive |= 2; } /* Gives current expansion word if not last word before chwordpos. */ --- 698,714 ---- void remhist(void) { ! if (!(histactive & HA_ACTIVE)) { ! if (!(histactive & HA_JUNKED)) { /* make sure this doesn't show up when we do firsthist() */ Histent he = gethistent(curhist); zsfree(he->text); he->text = NULL; ! histactive |= HA_JUNKED; curhist--; } } else ! histactive |= HA_NOSTORE; } /* Gives current expansion word if not last word before chwordpos. */ *************** *** 1074,1080 **** if (ev < firsthist() || ev > curhist) return NULL; ! if (ev == curhist && (histactive & 1)) { /* The current history line has not been stored. Build it up * from other variables. */ --- 1075,1081 ---- if (ev < firsthist() || ev > curhist) return NULL; ! if (ev == curhist && (histactive & HA_ACTIVE)) { /* The current history line has not been stored. Build it up * from other variables. */ -- 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, 15735 Zeuthen, Germany.