=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/re_search.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/mg/re_search.c 2000/02/29 01:44:33 1.3 +++ src/usr.bin/mg/re_search.c 2000/02/29 16:00:23 1.4 @@ -411,17 +411,18 @@ while (clp != (curbp->b_linep)) { re_match[0].rm_so = 0; - re_match[0].rm_eo = tbo; + re_match[0].rm_eo = llength(clp); lastmatch.rm_so = -1; /* Keep searching until we don't match any longer. Assumes a non-match - does not modify the re_match array. + does not modify the re_match array. We have to do this + character-by-character after the first match since POSIX regexps don't + give you a way to do reverse matches. */ - while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND)) { + while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND) && + re_match[0].rm_so < tbo) { memcpy(&lastmatch, &re_match[0], sizeof(regmatch_t)); - if (re_match[0].rm_eo >= tbo) - break; - re_match[0].rm_so = re_match[0].rm_eo; - re_match[0].rm_eo = tbo; + re_match[0].rm_so++; + re_match[0].rm_eo = llength(clp); } if (lastmatch.rm_so == -1) {