Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'patch -Rp0<!$' loses the < in expansion



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.



Messages sorted by: Reverse Date, Date, Thread, Author