mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-12-08 06:21:40 +01:00
back out 15266
This commit is contained in:
parent
a45ff6cdb7
commit
40e17d980f
3 changed files with 14 additions and 59 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
2001-07-06 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* Back out 15266: it was right before, I was looking at it
|
||||||
|
back to front.
|
||||||
|
|
||||||
2001-07-06 Bart Schaefer <schaefer@zsh.org>
|
2001-07-06 Bart Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
* 15271: Src/Modules/pcre.mdd: Default to dynamic linkage only, as
|
* 15271: Src/Modules/pcre.mdd: Default to dynamic linkage only, as
|
||||||
|
|
|
||||||
|
|
@ -793,8 +793,7 @@ flag, or with tt(${)...tt(/)...tt(}) (only the var(expr)th match is
|
||||||
substituted) or tt(${)...tt(//)...tt(}) (all matches from the
|
substituted) or tt(${)...tt(//)...tt(}) (all matches from the
|
||||||
var(expr)th on are substituted). The var(expr)th match is counted
|
var(expr)th on are substituted). The var(expr)th match is counted
|
||||||
such that there is either one or zero matches from each starting
|
such that there is either one or zero matches from each starting
|
||||||
position in the string when scanning forwards, or to each finishing
|
position in the string, although for global substitution matches
|
||||||
position when scanning backwards, although for global substitution matches
|
|
||||||
overlapping previous replacements are ignored.
|
overlapping previous replacements are ignored.
|
||||||
)
|
)
|
||||||
item(tt(M))(
|
item(tt(M))(
|
||||||
|
|
|
||||||
65
Src/glob.c
65
Src/glob.c
|
|
@ -2068,7 +2068,7 @@ set_pat_end(Patprog p, char null_me)
|
||||||
static int
|
static int
|
||||||
igetmatch(char **sp, Patprog p, int fl, int n, char *replstr)
|
igetmatch(char **sp, Patprog p, int fl, int n, char *replstr)
|
||||||
{
|
{
|
||||||
char *s = *sp, *t, sav, *furthestend, *longeststart, *lastend;
|
char *s = *sp, *t, sav;
|
||||||
int i, l = strlen(*sp), ml = ztrlen(*sp), matched = 1;
|
int i, l = strlen(*sp), ml = ztrlen(*sp), matched = 1;
|
||||||
|
|
||||||
repllist = NULL;
|
repllist = NULL;
|
||||||
|
|
@ -2243,17 +2243,19 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr)
|
||||||
*sp = get_match_ret(*sp, l, l, fl, replstr);
|
*sp = get_match_ret(*sp, l, l, fl, replstr);
|
||||||
patoffset = 0;
|
patoffset = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} /* fall through */
|
||||||
|
case (SUB_END|SUB_LONG|SUB_SUBSTR):
|
||||||
|
/* Longest/shortest at end, matching substrings. */
|
||||||
patoffset--;
|
patoffset--;
|
||||||
for (t = s + l - 1; t >= s; t--, patoffset--) {
|
for (t = s + l - 1; t >= s; t--, patoffset--) {
|
||||||
if (t > s && t[-1] == Meta)
|
if (t > s && t[-1] == Meta)
|
||||||
t--;
|
t--;
|
||||||
set_pat_start(p, t-s);
|
set_pat_start(p, t-s);
|
||||||
if (pattry(p, t) && patinput > t && !--n) {
|
if (pattry(p, t) && patinput > t && !--n) {
|
||||||
/* Found a match from this point */
|
/* Found the longest match */
|
||||||
char *mpos = patinput, *ptr;
|
char *mpos = patinput;
|
||||||
if (!(p->flags & PAT_PURES)) {
|
if (!(fl & SUB_LONG) && !(p->flags & PAT_PURES)) {
|
||||||
/* See if there's a shorter to anywhere */
|
char *ptr;
|
||||||
for (ptr = t; ptr < mpos; METAINC(ptr)) {
|
for (ptr = t; ptr < mpos; METAINC(ptr)) {
|
||||||
sav = *ptr;
|
sav = *ptr;
|
||||||
set_pat_end(p, sav);
|
set_pat_end(p, sav);
|
||||||
|
|
@ -2280,57 +2282,6 @@ igetmatch(char **sp, Patprog p, int fl, int n, char *replstr)
|
||||||
}
|
}
|
||||||
patoffset = 0;
|
patoffset = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (SUB_END|SUB_LONG|SUB_SUBSTR):
|
|
||||||
/*
|
|
||||||
* Longest at end, matching substrings. Scan up from
|
|
||||||
* start, remembering the furthest we got. The
|
|
||||||
* longest string to reach that point wins.
|
|
||||||
*/
|
|
||||||
furthestend = longeststart = lastend = NULL;
|
|
||||||
sav = '\0';
|
|
||||||
while (n) {
|
|
||||||
int l2 = strlen(s);
|
|
||||||
for (i = 0, t = s; i <= l2; i++, t++, patoffset++) {
|
|
||||||
set_pat_start(p, t-s);
|
|
||||||
if (pattry(p, t)) {
|
|
||||||
if (!furthestend ||
|
|
||||||
patinput - t > furthestend - longeststart) {
|
|
||||||
furthestend = patinput;
|
|
||||||
longeststart = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*t == Meta)
|
|
||||||
t++, i++;
|
|
||||||
}
|
|
||||||
if (furthestend) {
|
|
||||||
if (lastend) {
|
|
||||||
*lastend = sav;
|
|
||||||
lastend = NULL;
|
|
||||||
}
|
|
||||||
if (--n && furthestend > s) {
|
|
||||||
lastend = (furthestend > s+1 && furthestend[-2]
|
|
||||||
== Meta) ? furthestend-2 : furthestend-1;
|
|
||||||
sav = *lastend;
|
|
||||||
set_pat_end(p, sav);
|
|
||||||
*lastend = '\0';
|
|
||||||
furthestend = NULL;
|
|
||||||
patoffset = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (lastend)
|
|
||||||
*lastend = sav;
|
|
||||||
if (!n) {
|
|
||||||
*sp = get_match_ret(*sp, longeststart-s, furthestend-s, fl,
|
|
||||||
replstr);
|
|
||||||
patoffset = 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
patoffset = 0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue