/* * Append after line a lines returned by function f. * Be careful about intermediate states to avoid scramble * if an interrupt comes in. */ int append(int (*f)(void), line *a) { register line *a1, *a2, *rdot; int nline; nline = 0; dot = a; if(FIXUNDO && !inopen && f!=getsub) { undap1 = undap2 = dot + 1; undkind = UNDCHANGE; } while ((*f)() == 0) { if (truedol >= endcore) { if (morelines() < 0) { if (FIXUNDO && f == getsub) { undap1 = addr1; undap2 = addr2 + 1; } error(catgets(catd, 1, 39, "Out of memory@- too many lines in file")); } } nline++; a1 = truedol + 1; a2 = a1 + 1; dot++; undap2++; dol++; unddol++; truedol++; for (rdot = dot; a1 > rdot;) *--a2 = *--a1; *rdot = 0; putmark(rdot); if (f == gettty) { dirtcnt++; TSYNC(); } } return (nline); }
/* * Routine to handle a change inside a macro. * Fromvis is true if we were called from a visual command (as * opposed to an ex command). This has nothing to do with being * in open/visual mode as :s/foo/bar is not fromvis. */ void vmacchng(int fromvis) { line *savedot, *savedol; char *savecursor; char *savelb; int nlines, more; /* register line *a1, *a2; */ /* char ch; */ /* DEBUG */ if (!inopen) return; if (!vmacp) vch_mac = VC_NOTINMAC; #ifdef TRACE if (trace) fprintf(trace, "vmacchng, vch_mac=%d, linebuf='%s', *dot=%o\n", vch_mac, linebuf, *dot); #endif if (vmacp && fromvis) vsave(); #ifdef TRACE if (trace) fprintf(trace, "after vsave, linebuf='%s', *dot=%o\n", linebuf, *dot); #endif switch(vch_mac) { case VC_NOCHANGE: vch_mac = VC_ONECHANGE; break; case VC_ONECHANGE: savelb = smalloc(LBSIZE); /* Save current state somewhere */ #ifdef TRACE vudump("before vmacchng hairy case"); #endif savedot = dot; savedol = dol; savecursor = cursor; CP(savelb, linebuf); nlines = dol - zero; while ((line *) endcore - truedol < nlines) morelines(); copyw(truedol+1, zero+1, nlines); truedol += nlines; #ifdef TRACE visdump("before vundo"); #endif /* Restore state as it was at beginning of macro */ vundo(0); #ifdef TRACE visdump("after vundo"); vudump("after vundo"); #endif /* Do the saveall we should have done then */ saveall(); #ifdef TRACE vudump("after saveall"); #endif /* Restore current state from where saved */ more = savedol - dol; /* amount we shift everything by */ if (more) (*(more>0 ? copywR : copyw))(savedol+1, dol+1, truedol-dol); unddol += more; truedol += more; undap2 += more; truedol -= nlines; copyw(zero+1, truedol+1, nlines); dot = savedot; dol = savedol ; cursor = savecursor; CP(linebuf, savelb); vch_mac = VC_MANYCHANGE; /* Arrange that no further undo saving happens within macro */ otchng = tchng; /* Copied this line blindly - bug? */ inopen = -1; /* no need to save since it had to be 1 or -1 before */ vundkind = VMANY; #ifdef TRACE vudump("after vmacchng"); #endif free(savelb); break; case VC_NOTINMAC: case VC_MANYCHANGE: /* Nothing to do for various reasons. */ break; } }