* PATCH: ancient history bug
@ 2015-03-26 20:23 Peter Stephenson
2015-03-27 10:16 ` Peter Stephenson
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2015-03-26 20:23 UTC (permalink / raw)
To: Zsh hackers list
Adding some further history tests (which I'll get back to tomorrow), I
found this bug. It's probably been there since I factored out the
input code from the history code --- predating the CVS archive. So
!-history can't be *that* popular:
% print This is a mystery
This is a mystery
% print !:3-$
print a mystery
a mystery
% print !:1-$
print a
a
Oops: the last word has gone. Now you see it, now you
This is more fallout from the fact that aliases and history expansions
are handled in similar ways. When ungetting a character we need to take
care when going back up the expansion stack to discriminate --- if we
hit the end of the word in an alias, we'll think we don't need to mark
it as a word for the history.
pws
diff --git a/Src/input.c b/Src/input.c
index 30970a0..4a5bf89 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -56,8 +56,9 @@
* inpop(), which effectively flushes any unread input as well as restoring
* the previous input state.
*
- * The internal flag INP_ALCONT shows that the stack element was pushed
- * by an alias expansion; it should not be needed elsewhere.
+ * The internal flags INP_ALCONT and INP_HISTCONT show that the stack
+ * element was pushed by an alias or history expansion; they should not
+ * be needed elsewhere.
*
* The global variable inalmore is set to indicate aliases should
* continue to be expanded because the last alias expansion ended
@@ -446,7 +447,8 @@ inungetc(int c)
* we may need to restore an alias popped from the stack.
* Note this may be a dummy (history expansion) entry.
*/
- if (inbufptr == inbufpush && inbufflags & INP_ALCONT) {
+ if (inbufptr == inbufpush &&
+ (inbufflags & (INP_ALCONT|INP_HISTCONT))) {
/*
* Go back up the stack over all entries which were alias
* expansions and were pushed with nothing remaining to read.
@@ -455,8 +457,12 @@ inungetc(int c)
if (instacktop->alias)
instacktop->alias->inuse = 1;
instacktop++;
- } while ((instacktop->flags & INP_ALCONT) && !instacktop->bufleft);
- inbufflags = INP_CONT|INP_ALIAS;
+ } while ((instacktop->flags & (INP_ALCONT|INP_HISTCONT))
+ && !instacktop->bufleft);
+ if (inbufflags & INP_HISTCONT)
+ inbufflags = INP_CONT|INP_ALIAS|INP_HIST;
+ else
+ inbufflags = INP_CONT|INP_ALIAS;
inbufleft = 0;
inbuf = inbufptr = "";
}
@@ -522,7 +528,7 @@ inpush(char *str, int flags, Alias inalias)
instacktop->bufptr = inbufptr;
instacktop->bufleft = inbufleft;
instacktop->bufct = inbufct;
- inbufflags &= ~INP_ALCONT;
+ inbufflags &= ~(INP_ALCONT|INP_HISTCONT);
if (flags & (INP_ALIAS|INP_HIST)) {
/*
* Text is expansion for history or alias, so continue
@@ -531,7 +537,10 @@ inpush(char *str, int flags, Alias inalias)
* and mark alias as in use.
*/
flags |= INP_CONT|INP_ALIAS;
- instacktop->flags = inbufflags | INP_ALCONT;
+ if (flags & INP_HIST)
+ instacktop->flags = inbufflags | INP_HISTCONT;
+ else
+ instacktop->flags = inbufflags | INP_ALCONT;
if ((instacktop->alias = inalias))
inalias->inuse = 1;
} else {
@@ -570,7 +579,7 @@ static void
inpoptop(void)
{
if (!lexstop) {
- inbufflags &= ~INP_ALCONT;
+ inbufflags &= ~(INP_ALCONT|INP_HISTCONT);
while (inbufptr > inbuf) {
inbufptr--;
inbufct++;
@@ -598,7 +607,7 @@ inpoptop(void)
inbufct = instacktop->bufct;
inbufflags = instacktop->flags;
- if (!(inbufflags & INP_ALCONT))
+ if (!(inbufflags & (INP_ALCONT|INP_HISTCONT)))
return;
if (instacktop->alias) {
diff --git a/Src/zsh.h b/Src/zsh.h
index 403e8d3..486ad80 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -411,8 +411,9 @@ enum {
#define INP_HIST (1<<2) /* expanding history */
#define INP_CONT (1<<3) /* continue onto previously stacked input */
#define INP_ALCONT (1<<4) /* stack is continued from alias expn. */
-#define INP_LINENO (1<<5) /* update line number */
-#define INP_APPEND (1<<6) /* Append new lines to allow backup */
+#define INP_HISTCONT (1<<5) /* stack is continued from history expn. */
+#define INP_LINENO (1<<6) /* update line number */
+#define INP_APPEND (1<<7) /* Append new lines to allow backup */
/* Flags for metafy */
#define META_REALLOC 0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: ancient history bug
2015-03-26 20:23 PATCH: ancient history bug Peter Stephenson
@ 2015-03-27 10:16 ` Peter Stephenson
0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2015-03-27 10:16 UTC (permalink / raw)
To: Zsh hackers list
On Thu, 26 Mar 2015 20:23:21 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> Adding some further history tests (which I'll get back to tomorrow),
There should be more but this tests for the bug I fixed.
pws
diff --git a/Test/W01history.ztst b/Test/W01history.ztst
index cfc248c..6ef9b11 100644
--- a/Test/W01history.ztst
+++ b/Test/W01history.ztst
@@ -7,6 +7,47 @@
%test
$ZTST_testdir/../Src/zsh -fis <<<'
+ print one two three four five six seven eight nine ten
+ print !:$ !:10 !:9 !:1 !:0
+ print one two three four five six seven eight nine ten
+ print !:0-$ !:1-2
+ ' 2>/dev/null
+0:History word references
+>one two three four five six seven eight nine ten
+>ten ten nine one print
+>one two three four five six seven eight nine ten
+>print one two three four five six seven eight nine ten one two
+
+ $ZTST_testdir/../Src/zsh -fis <<<'
+ print line one of an arbitrary series
+ print issue two for some mystery sequence
+ print !-1:5-$
+ print !1:2
+ print !2:2
+ print !-3:1-$
+ ' 2>/dev/null
+0:History line numbering
+>line one of an arbitrary series
+>issue two for some mystery sequence
+>mystery sequence
+>one
+>two
+>mystery sequence
+
+ $ZTST_testdir/../Src/zsh -fis <<<'
+ print All metaphor, Malachi, stilts and all
+ print !1:2:s/,/\\\\?/ !1:2:s/m/shm/:s/,/\!/
+ print !1:2:&
+ print -l !1:2-3:gs/a/o/
+ ' 2>/dev/null
+0:History substitution
+>All metaphor, Malachi, stilts and all
+>metaphor? shmetaphor!
+>metaphor!
+>metophor,
+>Molochi,
+
+ $ZTST_testdir/../Src/zsh -fis <<<'
echo foo bar
echo $(!!) again
echo more $( !! )' 2>/dev/null
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-27 10:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 20:23 PATCH: ancient history bug Peter Stephenson
2015-03-27 10:16 ` 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).