zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: Re: PATCH: Removing aliases from history, 2015 style
Date: Sun, 29 Mar 2015 19:38:04 +0100	[thread overview]
Message-ID: <20150329193804.300569a3@ntlworld.com> (raw)
In-Reply-To: <20150327100648.7f8d5aaa@pwslap01u.europe.root.pri>

On Fri, 27 Mar 2015 10:06:48 +0000
Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Wed, 25 Mar 2015 19:42:22 +0100
> Mikael Magnusson <mikachu@gmail.com> wrote:
> > FWIW, I don't use !-expansion at all, but who knows, maybe that'll
> > make it more likely I find the corner case.
> 
> You do use HISTLEXWORDS, however, so you might notice the following:
> it looks like I've managed to make that work less well when
> interrupted.  If I ^C during the history read I get
> 
> 
> ^CWarning: backing up wrong character.
>...
>  hist.c:3524: bad wordsplit reading history: ((print foo); print bar)
>...

Various changes here.  Backing  up the wrong character is because
sometimes we "goto brk" when there's an error; if there is, it looks
benign to return LEXERR at that point.  Note we do this from lots of
places and generally set "peek = LEXERR" but don't worry about fixing up
"c" --- but clearly "c" has become irrelevant.  So I didn't try to muck
around fixing up "c" in the case in question, which I think is a return
from cmd_or_math_sub() where we don't have a useful character.

In history, if there was an error buffering words, don't try to do the
word split.

Those two seem to fix the specific problems above.  In both cases as we
were in an inner loop and depended on the previous processing being
successful it seemed reasonable to be sensitive to both bits of
errflag.

The other two are in the history reading code.  They make it more
sensitive to interruption by stopping loops over words and lines in that
case.  Here it's specific to the interruption rather than any error.

diff --git a/Src/hist.c b/Src/hist.c
index 990e609..185d0a0 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2604,6 +2604,8 @@ readhistfile(char *fn, int err, int readflags)
 	     */
 	    if (uselex || remeta)
 		freeheap();
+	    if (errflag & ERRFLAG_INT)
+		break;
 	}
 	if (start && readflags & HFILE_USE_OPTIONS) {
 	    zsfree(lasthist.text);
@@ -3331,7 +3333,7 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
 	    got = 1;
 	    cur = num - 1;
 	}
-    } while (tok != ENDINPUT && tok != LEXERR);
+    } while (tok != ENDINPUT && tok != LEXERR && !(errflag & ERRFLAG_INT));
     if (buf && tok == LEXERR && tokstr && *tokstr) {
 	int plen;
 	untokenize((p = dupstring(tokstr)));
@@ -3408,6 +3410,8 @@ histsplitwords(char *lineptr, short **wordsp, int *nwordsp, int *nwordposp,
 
 	wordlist = bufferwords(NULL, lineptr, NULL,
 			       LEXFLAGS_COMMENTS_KEEP);
+	if (errflag)
+	    return;
 	nwords_max = 2 * countlinknodes(wordlist);
 	if (nwords_max > nwords) {
 	    *nwordsp = nwords = nwords_max;
diff --git a/Src/lex.c b/Src/lex.c
index 5fed2be..184a54b 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1345,6 +1345,8 @@ gettokstr(int c, int sub)
 	    break;
     }
   brk:
+    if (errflag)
+	return LEXERR;
     hungetc(c);
     if (unmatched)
 	zerr("unmatched %c", unmatched);


  parent reply	other threads:[~2015-03-29 18:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  1:49 capturing output of !! not working Vin Shelton
2015-03-19  2:28 ` Bart Schaefer
2015-03-19 10:57 ` Peter Stephenson
2015-03-19 12:27   ` Vin Shelton
2015-03-19 12:53     ` Peter Stephenson
2015-03-20 10:57       ` Peter Stephenson
2015-03-20 16:04         ` Bart Schaefer
2015-03-22 18:35           ` Peter Stephenson
2015-03-22 19:18             ` Peter Stephenson
2015-03-22 23:22             ` Bart Schaefer
2015-03-23 21:34               ` Peter Stephenson
2015-03-24  0:54                 ` Testing interactive features (Re: capturing output of !! not working) Bart Schaefer
2015-03-24  4:12                   ` Bart Schaefer
2015-03-24  4:45                     ` Bart Schaefer
2015-03-24 16:09                       ` Bart Schaefer
2016-05-23 14:53                         ` Mikael Magnusson
2015-03-25 15:48                 ` PATCH: Removing aliases from history, 2015 style (was " Peter Stephenson
2015-03-25 17:57                   ` PATCH: Removing aliases from history, 2015 style Peter Stephenson
2015-03-25 18:42                     ` Mikael Magnusson
2015-03-27 10:06                       ` Peter Stephenson
2015-03-27 15:25                         ` Bart Schaefer
2015-03-27 15:41                           ` Peter Stephenson
2015-03-27 17:17                             ` Bart Schaefer
2015-03-27 17:47                               ` Peter Stephenson
2015-03-29 18:38                         ` Peter Stephenson [this message]
2015-03-25 18:58                     ` Bart Schaefer
2015-03-25 19:40                   ` PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working) Bart Schaefer
2015-03-26  3:43                     ` Word breaks around aliased tokens (was Re: PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working)) Bart Schaefer
2015-03-30 18:04                       ` Daniel Shahaf
2015-03-30 20:05                         ` Mikael Magnusson
2015-03-30 18:08                       ` Daniel Shahaf
2015-03-26  9:41                     ` PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working) Peter Stephenson
2015-03-26 15:22                       ` 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=20150329193804.300569a3@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /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).