From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: 'patch -Rp0<!$' loses the < in expansion
Date: Tue, 16 Aug 2011 23:26:16 -0700 [thread overview]
Message-ID: <110816232616.ZM17198@torch.brasslantern.com> (raw)
In-Reply-To: <110816203630.ZM7065@torch.brasslantern.com>
On Aug 16, 8:36pm, Bart Schaefer wrote:
}
} 1358 if (hwgetword > -1) {
} 1359 /* We want to reuse the current word position */
} 1360 chwordpos = hwgetword;
} 1361 /* Start from where previous word ended, if possible */
} 1362 hptr = chline + chwords[chwordpos ? chwordpos - 1 : 0];
} 1363 }
}
} This makes me suspect that hwgetword was not incremented at some place
} where it should have been, but I don't know where -- or whether that is
} really the problem.
I just put a debug statement in there and ran "make check" and that
particular code branch is never excercised.
Immediately before that, there's this:
1350 /* end of word reached and we've already begun a word */
1351 if (hptr > chline + chwords[chwordpos-1]) {
1352 chwords[chwordpos++] = hptr - chline;
Everything is fine at this point. We've got chwords[4] pointing at "<"
and chwords[5] (which represents the end of that word) pointing at "f".
We should be ready to start the next word.
So why do we want to do the stuff at line 1360 & 1361? What is the
point of "reuse the current word position"? I suspect the answer is
up in ihwbegin():
1331 /* If we're expanding an alias, we should overwrite the expansion
1332 * in the history.
1333 */
1334 if ((inbufflags & INP_ALIAS) && !(inbufflags & INP_HIST))
1335 hwgetword = chwordpos;
1336 else
1337 hwgetword = -1;
And sure enough:
torch% alias -g foo=bar
torch% echo foo
../../zsh-4.0/Src/hist.c:1359: Re-using current word position
bar
And:
torch% : -Rp0<!$
../../zsh-4.0/Src/hist.c:1359: Re-using current word position
../../zsh-4.0/Src/hist.c:1359: Re-using current word position
: -Rp0foo
torch%
It's possible that what hwgetword should be getting reset to -1 somewhere
that it is not, but I on a few tracethroughs I can't find anyplace else
where we detect that we've transitioned lexer words in the middle of a
contiguous string without separators. So without much finesse:
--- ../zsh-forge/current/Src/hist.c 2011-08-14 11:12:30.000000000 -0700
+++ Src/hist.c 2011-08-16 23:20:35.000000000 -0700
@@ -1355,7 +1355,8 @@
(chwordlen += 32) *
sizeof(short));
}
- if (hwgetword > -1) {
+ if (hwgetword > -1 &&
+ (inbufflags & INP_ALIAS) && !(inbufflags & INP_HIST)) {
/* We want to reuse the current word position */
chwordpos = hwgetword;
/* Start from where previous word ended, if possible */
It's possible that we also want to assign hwgetword = -1 at this point,
but I think that would be wrong in a recursively-expanding alias.
next prev parent reply other threads:[~2011-08-17 6:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-16 9:46 Daniel Shahaf
2011-08-17 3:36 ` Bart Schaefer
2011-08-17 6:26 ` Bart Schaefer [this message]
2011-08-18 8:37 ` Peter Stephenson
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=110816232616.ZM17198@torch.brasslantern.com \
--to=schaefer@brasslantern.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).