=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mg/re_search.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- src/usr.bin/mg/re_search.c 2000/02/28 23:45:21 1.2 +++ src/usr.bin/mg/re_search.c 2000/02/29 01:44:33 1.3 @@ -390,7 +390,7 @@ register LINE *clp; register int tbo; - int error, startpos; + regmatch_t lastmatch; char m[1]; clp = curwp->w_dotp; @@ -410,15 +410,25 @@ while (clp != (curbp->b_linep)) { - re_match[0].rm_so = tbo; - re_match[0].rm_eo = llength(clp); - /* XXX - does not search backwards! */ - error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND); + re_match[0].rm_so = 0; + re_match[0].rm_eo = tbo; + lastmatch.rm_so = -1; + /* Keep searching until we don't match any longer. Assumes a non-match + does not modify the re_match array. + */ + while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND)) { + 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; + } - if (error) { + if (lastmatch.rm_so == -1) { clp = lback(clp); tbo = llength(clp); } else { + memcpy(&re_match[0], &lastmatch, sizeof(regmatch_t)); curwp->w_doto = re_match[0].rm_so; curwp->w_dotp = clp; curwp->w_flag |= WFMOVE;