PROC scrollforward(int curr) { do { writeline(LINES-1, 0, pend+1); strput("\n"); pend = fseekeol(pend+1); ptop = fseekeol(ptop)+1; } while (pend < curr); }
PROC refresh(int y,int x,int start,int endd, bool rest) { int sp; #if ST /* turn the cursor off */ asm(" clr.l -(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif sp = start; while (sp <= endd) { writeline(y, x, sp); sp = 1+fseekeol(sp); y++; x = 0; } if (rest && sp >= bufmax) while (y<LINES-1) { /* fill screen with ~ */ mvcur(y, 0); printch('~'); strput(CE); y++; } #if ST /* turn the cursor back on */ asm(" clr.w -(sp) "); asm(" move.w #1,-(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif }
PROC writeline(int y,int x,int start) { int endd,oxp; unsigned int size; char buf[MAXCOLS+1]; unsigned int bi = 0; endd = fseekeol(start); if (start==0 || core[start-1] == EOL) mvcur(y, 0); else mvcur(y, x); oxp = curpos.x; while (start < endd && curpos.x < COLS) { size = format(&buf[bi],core[start++]); bi += size; curpos.x += size; } if (list) { buf[bi++] = '$'; curpos.x++; } size = min(bi,COLS-oxp); if (size > 0) { zwrite(buf, size); } if (curpos.x < COLS) strput(CE); }
PROC join(int count) { bool ok; int lp, first; if (lend < bufmax) { /* are we in the buffer? */ disp = lend; /* start redraw here */ newc = lend; do { /* join until.. */ first = lend; lp = skipws(1+first); ok = delete_to_undo(&undo, 1+first, lp-(1+first)); if (ok) { ok = move_to_undo(&undo, first, 1); core[first] = ' '; /* spaces between lines */ } count--; lend = fseekeol(first); } while (ok && count > 0); endY = MAGICNUMBER; newend = lend; if (!ok) error(); } else error(); }
PROC findfwd(char *pattern, int start, int endp) /* look for a regular expression forward */ { int ep; while (start < endp) { ep = fseekeol(start); if ((start = REmatch(pattern, start, ep)) <= ep) return start; } return ERR; }
int PROC nextline(bool advance, int dest, int count) { if (advance) do { dest = fseekeol(dest) + 1; count--; } while (count>0 && dest<bufmax); else do { dest = bseekeol(dest) - 1; count--; } while (count>0 && dest>=0); return(dest); }
PROC adjuster(bool sleft, int endd, int sw) { bool noerror; int np, ts, ip, ss, adjp, DLEnum; if (sw == -1) sw = shiftwidth; if (sleft) sw = -sw; curr = bseekeol(curr); ip = curr; noerror = TRUE; do { DLEnum = sw + findDLE(ip, &np, bufmax,0); if (DLEnum >= 0 && DLEnum <= COLS && core[np] != EOL && np < bufmax) { ts = DLEnum / tabsize; ss = DLEnum % tabsize; adjp = ts+ss+ip; if (np-adjp < 0) { /* expand the buf */ moveright(&core[np], &core[adjp], bufmax-np); insert_to_undo(&undo, adjp, adjp - np); } else delete_to_undo(&undo, adjp, np - adjp); endd += (adjp-np); noerror = move_to_undo(&undo, ip, ts+ss); fillchar(&core[ip], ts, TAB); fillchar(&core[ip+ts], ss, 32); } else if (np > ip) { /* remove the indent code */ noerror = delete_to_undo(&undo, ip, np-ip); endd += (ip - np); } ip = 1 + fseekeol(ip); } while (noerror && ip < endd); if (!noerror) error(); newc = skipws(curr); disp = curr; newend = endd; endY = setY(min(newend, pend)); }