fix that as well

This commit is contained in:
tg
2009-11-21 22:32:08 +00:00
parent 6e67920bef
commit 398b5b7a60
2 changed files with 20 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.339 2009/11/21 22:30:34 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.340 2009/11/21 22:32:05 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -1361,7 +1361,7 @@ expected-stdout:
4: x . 4: x .
5: n n . 5: n n .
6: h h . 6: h h .
7: <20> <20> . 7: <20> <20> .
8: mä mä . 8: mä mä .
9: . 9: .
--- ---

26
eval.c
View File

@ -22,7 +22,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.71 2009/11/21 22:29:11 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.72 2009/11/21 22:32:08 tg Exp $");
/* /*
* string expansion * string expansion
@ -1137,7 +1137,7 @@ trimsub(char *str, char *pat, int how)
switch (how & 0xFF) { switch (how & 0xFF) {
case '#': /* shortest at beginning */ case '#': /* shortest at beginning */
for (p = str; p <= end; p++) { for (p = str; p <= end; p += utf_ptradj(p)) {
c = *p; *p = '\0'; c = *p; *p = '\0';
if (gmatchx(str, pat, false)) { if (gmatchx(str, pat, false)) {
*p = c; *p = c;
@ -1157,18 +1157,28 @@ trimsub(char *str, char *pat, int how)
} }
break; break;
case '%': /* shortest match at end */ case '%': /* shortest match at end */
for (p = end; p >= str; p--) p = end;
while (p >= str) {
if (gmatchx(p, pat, false))
goto trimsub_match;
if (UTFMODE) {
char *op = p;
while ((*--p & 0xC0) == 0x80)
;
if ((p < str) || (p + utf_ptradj(p) != op))
p = op - 1;
} else
--p;
}
break;
case '%'|0x80: /* longest match at end */
for (p = str; p <= end; p++)
if (gmatchx(p, pat, false)) { if (gmatchx(p, pat, false)) {
trimsub_match: trimsub_match:
strndupx(end, str, p - str, ATEMP); strndupx(end, str, p - str, ATEMP);
return (end); return (end);
} }
break; break;
case '%'|0x80: /* longest match at end */
for (p = str; p <= end; p++)
if (gmatchx(p, pat, false))
goto trimsub_match;
break;
} }
return (str); /* no match, return string */ return (str); /* no match, return string */