/* push a deleted line onto the undo stack. */ void toss_to_undo(LINE *lp) { LINE *next; LINE *prev; int fc; TRACE2((T_CALLED "toss_to_undo(%p)\n", lp)); if (needundocleanup) preundocleanup(); pushline(lp, BACKSTK(curbp)); next = lforw(lp); /* need to save a dot -- either the next line or the previous one */ if (next == buf_head(curbp)) { prev = lback(lp); FORWDOT(curbp).l = prev; fc = firstchar(prev); if (fc < 0) /* all white */ FORWDOT(curbp).o = llength(prev) - 1; else FORWDOT(curbp).o = fc; } else { FORWDOT(curbp).l = next; fc = firstchar(next); if (fc < 0) /* all white */ FORWDOT(curbp).o = b_left_margin(curbp); else FORWDOT(curbp).o = fc; } dumpuline(lp); return2Void(); }
/* * scanner -- Search for a pattern in either direction. can optionally * wrap around end of buffer. */ int scanner( regexp * exp, /* the compiled expression */ int direct, /* up or down */ int wrapok, /* ok to wrap around end of buffer? */ int *wrappedp) { MARK curpos; int found; int wrapped = FALSE; int leftmargin = b_left_margin(curbp); TRACE((T_CALLED "scanner %s %s\n", ((direct == FORWARD) ? "forward" : "backward"), (wrapok ? "wrapok" : "nowrapok"))); if (!exp) { mlforce("BUG: null exp"); returnCode(FALSE); } /* Set starting search position to current position */ curpos = DOT; if (curpos.o < leftmargin) curpos.o = leftmargin; /* Scan each character until we hit the scan boundary */ for_ever { int startoff, srchlim; if (interrupted()) { if (wrappedp) *wrappedp = wrapped; returnCode(ABORT); } if (sameline(curpos, scanboundpos)) { if (scanbound_is_header) { /* if we're on the header, nothing can match */ found = FALSE; srchlim = leftmargin; } else { if (direct == FORWARD) { if (wrapped) { startoff = curpos.o; srchlim = scanboundpos.o; } else { startoff = curpos.o; srchlim = ((scanboundpos.o > startoff) ? scanboundpos.o : llength(curpos.l)); } } else { if (wrapped) { startoff = scanboundpos.o; srchlim = llength(curpos.l); } else { startoff = leftmargin; srchlim = scanboundpos.o + 1; } } found = lregexec(exp, curpos.l, startoff, srchlim); } } else { if (direct == FORWARD) { startoff = curpos.o; srchlim = llength(curpos.l); } else { startoff = leftmargin; srchlim = curpos.o + 1; if (srchlim > llength(curpos.l)) srchlim = llength(curpos.l); } found = lregexec(exp, curpos.l, startoff, srchlim); } if (found) { char *txt = lvalue(curpos.l); char *got = exp->startp[0]; C_NUM next; C_NUM last = curpos.o; if (direct == REVERSE) { /* find the last one */ int end = FALSE; char *tst = 0; last++; while (testit(curpos.l, exp, &end, srchlim)) { got = exp->startp[0]; /* guard against infinite loop: "?$" * or "?.*" */ if (tst == got) break; tst = got; } if (end) last++; if (!lregexec(exp, curpos.l, (int) (got - txt), srchlim)) { mlforce("BUG: prev. match no good"); returnCode(FALSE); } } else if (llength(curpos.l) <= leftmargin || last < llength(curpos.l)) { last--; } next = (C_NUM) (got - txt); if (next != last) { DOT.l = curpos.l; DOT.o = next; curwp->w_flag |= WFMOVE; /* flag that we have moved */ if (wrappedp) *wrappedp = wrapped; #if OPT_TRACE trace_mark("...scanner", &DOT, curbp); #endif returnCode(TRUE); } } else { if (sameline(curpos, scanboundpos) && (!wrapok || wrapped)) break; } if (direct == FORWARD) { curpos.l = lforw(curpos.l); } else { curpos.l = lback(curpos.l); } if (is_header_line(curpos, curbp)) { wrapped = TRUE; if (sameline(curpos, scanboundpos) && (!wrapok || wrapped)) break; if (direct == FORWARD) curpos.l = lforw(curpos.l); else curpos.l = lback(curpos.l); } if (direct == FORWARD) { curpos.o = leftmargin; } else { if ((curpos.o = llength(curpos.l) - 1) < leftmargin) curpos.o = leftmargin; } } if (wrappedp) *wrappedp = wrapped; returnCode(FALSE); /* We could not find a match. */ }