Release 6
[unix-history] / usr / src / usr.bin / ex / ex_vops.c
index fc03b25..7537cb2 100644 (file)
@@ -1,5 +1,3 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_vops.c   6.3 %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -29,7 +27,7 @@ static char *sccsid = "@(#)ex_vops.c  6.3 %G%";
 char   *vUA1, *vUA2;
 char   *vUD1, *vUD2;
 
 char   *vUA1, *vUA2;
 char   *vUD1, *vUD2;
 
-vUndo()
+ex_vUndo()
 {
 
        /*
 {
 
        /*
@@ -144,7 +142,7 @@ bool show;  /* if true update the screen */
                vprepins();
                temp[vUA2 - linebuf] = 0;
                for (cp = &temp[vUA1 - linebuf]; *cp;)
                vprepins();
                temp[vUA2 - linebuf] = 0;
                for (cp = &temp[vUA1 - linebuf]; *cp;)
-                       putchar(*cp++);
+                       ex_putchar(*cp++);
                Outchar = OO; hold = oldhold;
                endim();
                physdc(cindent(), cindent() + doomed);
                Outchar = OO; hold = oldhold;
                endim();
                physdc(cindent(), cindent() + doomed);
@@ -175,8 +173,6 @@ bool fromvis;
        char *savecursor;
        char savelb[LBSIZE];
        int nlines, more;
        char *savecursor;
        char savelb[LBSIZE];
        int nlines, more;
-       register line *a1, *a2;
-       char ch;        /* DEBUG */
        int copyw(), copywR();
 
        if (!inopen)
        int copyw(), copywR();
 
        if (!inopen)
@@ -206,7 +202,13 @@ bool fromvis;
                CP(savelb, linebuf);
                nlines = dol - zero;
                while ((line *) endcore - truedol < nlines)
                CP(savelb, linebuf);
                nlines = dol - zero;
                while ((line *) endcore - truedol < nlines)
-                       morelines();
+                       if (morelines() < 0) {
+                               dot = savedot;
+                               dol = savedol;
+                               cursor = savecursor;
+                               CP(linebuf, savelb);
+                               error("Out of memory@- too many lines to undo");
+                       }
                copyw(truedol+1, zero+1, nlines);
                truedol += nlines;
 
                copyw(truedol+1, zero+1, nlines);
                truedol += nlines;
 
@@ -320,7 +322,7 @@ vmove()
                        c = *cp;
                        *cp = 0;
                        hold |= HOLDDOL;
                        c = *cp;
                        *cp = 0;
                        hold |= HOLDDOL;
-                       vreopen(WTOP, lineDOT(), vcline);
+                       ignore(vreopen(WTOP, lineDOT(), vcline));
                        hold = oldhold;
                        *cp = c;
                } else if (wcursor > cursor) {
                        hold = oldhold;
                        *cp = c;
                } else if (wcursor > cursor) {
@@ -328,7 +330,7 @@ vmove()
                        for (cp = cursor; *cp && cp < wcursor;) {
                                register int c = *cp++ & TRIM;
 
                        for (cp = cursor; *cp && cp < wcursor;) {
                                register int c = *cp++ & TRIM;
 
-                               putchar(c ? c : ' ');
+                               ex_putchar(c ? c : ' ');
                        }
                }
        }
                        }
                }
        }
@@ -361,7 +363,7 @@ vdelete(c)
                        vputchar('@');
                }
                wdot = dot;
                        vputchar('@');
                }
                wdot = dot;
-               vremote(i, delete, 0);
+               vremote(i, ex_delete, 0);
                notenam = "delete";
                DEL[0] = 0;
                killU();
                notenam = "delete";
                DEL[0] = 0;
                killU();
@@ -390,7 +392,7 @@ vdelete(c)
        }
        physdc(column(cursor - 1), i);
        DEPTH(vcline) = 0;
        }
        physdc(column(cursor - 1), i);
        DEPTH(vcline) = 0;
-       vreopen(LINE(vcline), lineDOT(), vcline);
+       ignore(vreopen(LINE(vcline), lineDOT(), vcline));
        vsyncCL();
        vsetcurs(cp);
 }
        vsyncCL();
        vsetcurs(cp);
 }
@@ -481,7 +483,7 @@ vchange(c)
                 * case we are told to put.
                 */
                addr = dot;
                 * case we are told to put.
                 */
                addr = dot;
-               vremote(cnt, delete, 0);
+               vremote(cnt, ex_delete, 0);
                setpk();
                notenam = "delete";
                if (c != 'd')
                setpk();
                notenam = "delete";
                if (c != 'd')
@@ -499,7 +501,7 @@ vchange(c)
                 */
                vreplace(vcline, cnt, 0);
                wdot = NOLINE;
                 */
                vreplace(vcline, cnt, 0);
                wdot = NOLINE;
-               noteit(0);
+               ignore(noteit(0));
                vcline--;
                if (addr <= dol)
                        dot--;
                vcline--;
                if (addr <= dol)
                        dot--;
@@ -539,7 +541,7 @@ vchange(c)
                        vcline = 0;
                vopen(dot, i);
                vsyncCL();
                        vcline = 0;
                vopen(dot, i);
                vsyncCL();
-               noteit(1);
+               ignore(noteit(1));
                if (c != 'd') {
                        if (ind >= 0) {
                                cursor = linebuf;
                if (c != 'd') {
                        if (ind >= 0) {
                                cursor = linebuf;
@@ -582,7 +584,7 @@ smallchange:
                bleep(i, cp);
        else {
                vcursbef(wcursor);
                bleep(i, cp);
        else {
                vcursbef(wcursor);
-               putchar('$');
+               ex_putchar('$');
                i = cindent();
        }
 
                i = cindent();
        }
 
@@ -621,14 +623,20 @@ smallchange:
  * you are better off with slowopen.
  */
 voOpen(c, cnt)
  * you are better off with slowopen.
  */
 voOpen(c, cnt)
-       char c;
+       int c;  /* mjm: char --> int */
        register int cnt;
 {
        register int ind = 0, i;
        short oldhold = hold;
        register int cnt;
 {
        register int ind = 0, i;
        short oldhold = hold;
+#ifdef SIGWINCH
+       int oldmask;
+#endif
 
        if (value(SLOWOPEN) || value(REDRAW) && AL && DL)
                cnt = 1;
 
        if (value(SLOWOPEN) || value(REDRAW) && AL && DL)
                cnt = 1;
+#ifdef SIGWINCH
+       oldmask = sigblock(sigmask(SIGWINCH));
+#endif
        vsave();
        setLAST();
        if (value(AUTOINDENT))
        vsave();
        setLAST();
        if (value(AUTOINDENT))
@@ -653,8 +661,8 @@ voOpen(c, cnt)
                c = WBOT + 1;
        else {
                c = vcline < 0 ? WTOP - cnt : LINE(vcline) + DEPTH(vcline);
                c = WBOT + 1;
        else {
                c = vcline < 0 ? WTOP - cnt : LINE(vcline) + DEPTH(vcline);
-               if (c < ZERO)
-                       c = ZERO;
+               if (c < ex_ZERO)
+                       c = ex_ZERO;
                i = LINE(vcline + 1) - c;
                if (i < cnt && c <= WBOT && (!AL || !DL))
                        vinslin(c, cnt - i, vcline);
                i = LINE(vcline + 1) - c;
                if (i < cnt && c <= WBOT && (!AL || !DL))
                        vinslin(c, cnt - i, vcline);
@@ -676,6 +684,9 @@ voOpen(c, cnt)
        cursor = linebuf;
        linebuf[0] = 0;
        vappend('o', 1, ind);
        cursor = linebuf;
        linebuf[0] = 0;
        vappend('o', 1, ind);
+#ifdef SIGWINCH
+       (void)sigsetmask(oldmask);
+#endif
 }
 
 /*
 }
 
 /*
@@ -713,7 +724,8 @@ vfilter()
 {
        register line *addr;
        register int cnt;
 {
        register line *addr;
        register int cnt;
-       char *oglobp, d;
+       char *oglobp;
+       short d;
 
        if ((cnt = xdw()) < 0)
                return;
 
        if ((cnt = xdw()) < 0)
                return;
@@ -780,7 +792,7 @@ xdw()
        }
        vsave();
        setLAST();
        }
        vsave();
        setLAST();
-       if (dot > wdot) {
+       if (dot > wdot || (dot == wdot && wcursor != 0 && cursor > wcursor)) {
                register line *addr;
 
                vcline -= dot - wdot;
                register line *addr;
 
                vcline -= dot - wdot;