mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
38983: Make transpose-words handle numeric arguments sensibly
This commit is contained in:
parent
68e14c41f2
commit
b2be8e1b6e
2 changed files with 57 additions and 40 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2016-08-12 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* Han Pingtian: 38983: Src/Zle/zle_word.c: make transpose-words
|
||||||
|
handle numeric arguments sensibly.
|
||||||
|
|
||||||
2016-08-12 Barton E. Schaefer <schaefer@zsh.org>
|
2016-08-12 Barton E. Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
* 39028: Src/subst.c, Test/D04parameter.ztst: more join/split
|
* 39028: Src/subst.c, Test/D04parameter.ztst: more join/split
|
||||||
|
|
|
@ -678,16 +678,17 @@ killword(char **args)
|
||||||
int
|
int
|
||||||
transposewords(UNUSED(char **args))
|
transposewords(UNUSED(char **args))
|
||||||
{
|
{
|
||||||
int p1, p2, p3, p4, len, x = zlecs, pos;
|
int p1, p2, p3, p4, pt, len, x = zlecs, pos;
|
||||||
ZLE_STRING_T temp, pp;
|
ZLE_STRING_T temp, pp;
|
||||||
int n = zmult;
|
int n = zmult;
|
||||||
int neg = n < 0, ocs = zlecs;
|
int neg = n < 0, ocs = zlecs;
|
||||||
|
|
||||||
if (neg)
|
if (neg)
|
||||||
n = -n;
|
n = -n;
|
||||||
while (n--) {
|
|
||||||
while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
|
while (x != zlell && zleline[x] != ZWC('\n') && !ZC_iword(zleline[x]))
|
||||||
INCPOS(x);
|
INCPOS(x);
|
||||||
|
|
||||||
if (x == zlell || zleline[x] == ZWC('\n')) {
|
if (x == zlell || zleline[x] == ZWC('\n')) {
|
||||||
x = zlecs;
|
x = zlecs;
|
||||||
while (x) {
|
while (x) {
|
||||||
|
@ -706,8 +707,10 @@ transposewords(UNUSED(char **args))
|
||||||
if (zleline[pos] == ZWC('\n'))
|
if (zleline[pos] == ZWC('\n'))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
|
for (p4 = x; p4 != zlell && ZC_iword(zleline[p4]); INCPOS(p4))
|
||||||
;
|
;
|
||||||
|
|
||||||
for (p3 = p4; p3; ) {
|
for (p3 = p4; p3; ) {
|
||||||
pos = p3;
|
pos = p3;
|
||||||
DECPOS(pos);
|
DECPOS(pos);
|
||||||
|
@ -715,9 +718,14 @@ transposewords(UNUSED(char **args))
|
||||||
break;
|
break;
|
||||||
p3 = pos;
|
p3 = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p3)
|
if (!p3)
|
||||||
return 1;
|
return 1;
|
||||||
for (p2 = p3; p2; ) {
|
|
||||||
|
pt = p3;
|
||||||
|
|
||||||
|
while (n--) {
|
||||||
|
for (p2 = pt; p2; ) {
|
||||||
pos = p2;
|
pos = p2;
|
||||||
DECPOS(pos);
|
DECPOS(pos);
|
||||||
if (ZC_iword(zleline[pos]))
|
if (ZC_iword(zleline[pos]))
|
||||||
|
@ -733,6 +741,9 @@ transposewords(UNUSED(char **args))
|
||||||
break;
|
break;
|
||||||
p1 = pos;
|
p1 = pos;
|
||||||
}
|
}
|
||||||
|
pt = p1;
|
||||||
|
}
|
||||||
|
|
||||||
pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
|
pp = temp = (ZLE_STRING_T)zhalloc((p4 - p1)*ZLE_CHAR_SIZE);
|
||||||
len = p4 - p3;
|
len = p4 - p3;
|
||||||
ZS_memcpy(pp, zleline + p3, len);
|
ZS_memcpy(pp, zleline + p3, len);
|
||||||
|
@ -744,9 +755,10 @@ transposewords(UNUSED(char **args))
|
||||||
|
|
||||||
ZS_memcpy(zleline + p1, temp, p4 - p1);
|
ZS_memcpy(zleline + p1, temp, p4 - p1);
|
||||||
|
|
||||||
zlecs = p4;
|
|
||||||
}
|
|
||||||
if (neg)
|
if (neg)
|
||||||
zlecs = ocs;
|
zlecs = ocs;
|
||||||
|
else
|
||||||
|
zlecs = p4;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue