cleanups, add manual page
[unix-history] / usr / src / usr.bin / ex / ex_v.c
index 00ef0fa..175fe88 100644 (file)
@@ -1,4 +1,13 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)ex_v.c      7.9 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_re.h"
 #include "ex_tty.h"
 #include "ex.h"
 #include "ex_re.h"
 #include "ex_tty.h"
  *             absolute motions, contextual displays, line depth determination
  */
 
  *             absolute motions, contextual displays, line depth determination
  */
 
+jmp_buf venv;
+int    winch();
+
 /*
  * Enter open mode
  */
 /*
  * Enter open mode
  */
+#ifdef u370
+char   atube[TUBESIZE+LBSIZE];
+#endif
 oop()
 {
        register char *ic;
 oop()
 {
        register char *ic;
+#ifndef u370
        char atube[TUBESIZE + LBSIZE];
        char atube[TUBESIZE + LBSIZE];
-       register ttymode f;
+#endif
+       ttymode f;      /* mjm: was register */
 
 
+       if (setjmp(venv)) {
+               setsize();
+               initev = (char *)0;
+               inopen = 0;
+               addr1 = addr2 = dot;
+       }
+#ifdef SIGWINCH
+       (void)signal(SIGWINCH, winch);
+#endif
        ovbeg();
        if (peekchar() == '/') {
        ovbeg();
        if (peekchar() == '/') {
-               ignore(compile(getchar(), 1));
+               ignore(compile(ex_getchar(), 1));
                savere(scanre);
                if (execute(0, dot) == 0)
                        error("Fail|Pattern not found on addressed line");
                savere(scanre);
                if (execute(0, dot) == 0)
                        error("Fail|Pattern not found on addressed line");
@@ -111,6 +137,9 @@ oop()
                vclean();
        Command = "open";
        ovend(f);
                vclean();
        Command = "open";
        ovend(f);
+#ifdef SIGWINCH
+       (void)signal(SIGWINCH, SIG_DFL);
+#endif
 }
 
 ovbeg()
 }
 
 ovbeg()
@@ -152,8 +181,10 @@ ovend(f)
 vop()
 {
        register int c;
 vop()
 {
        register int c;
+#ifndef u370
        char atube[TUBESIZE + LBSIZE];
        char atube[TUBESIZE + LBSIZE];
-       register ttymode f;
+#endif
+       ttymode f;      /* mjm: was register */
 
        if (!CA && UP == NOSTR) {
                if (initev) {
 
        if (!CA && UP == NOSTR) {
                if (initev) {
@@ -180,11 +211,20 @@ toopen:
                        goto toopen;
                error("Visual requires scrolling");
        }
                        goto toopen;
                error("Visual requires scrolling");
        }
+       if (setjmp(venv)) {
+               setsize();
+               initev = (char *)0;
+               inopen = 0;
+               addr1 = addr2 = dot;
+       }
+#ifdef SIGWINCH
+       (void)signal(SIGWINCH, winch);
+#endif
        ovbeg();
        bastate = VISUAL;
        c = 0;
        if (any(peekchar(), "+-^."))
        ovbeg();
        bastate = VISUAL;
        c = 0;
        if (any(peekchar(), "+-^."))
-               c = getchar();
+               c = ex_getchar();
        pastwh();
        vsetsiz(isdigit(peekchar()) ? getnum() : value(WINDOW));
        setwind();
        pastwh();
        vsetsiz(isdigit(peekchar()) ? getnum() : value(WINDOW));
        setwind();
@@ -202,6 +242,9 @@ toopen:
        vmain();
        Command = "visual";
        ovend(f);
        vmain();
        Command = "visual";
        ovend(f);
+#ifdef SIGWINCH
+       (void)signal(SIGWINCH, SIG_DFL);
+#endif
 }
 
 /*
 }
 
 /*
@@ -217,7 +260,7 @@ fixzero()
 
                vdoappend("");
                if (!ochng)
 
                vdoappend("");
                if (!ochng)
-                       sync();
+                       ex_sync();
                addr1 = addr2 = one;
        } else if (addr2 == zero)
                addr2 = one;
                addr1 = addr2 = one;
        } else if (addr2 == zero)
                addr2 = one;
@@ -284,7 +327,7 @@ setwind()
 
        case HARDOPEN:
                basWTOP = WTOP = WBOT = WECHO = 0;
 
        case HARDOPEN:
                basWTOP = WTOP = WBOT = WECHO = 0;
-               ZERO = 0;
+               ex_ZERO = 0;
                holdcm++;
                break;
 
                holdcm++;
                break;
 
@@ -293,10 +336,10 @@ setwind()
                /* fall into */
 
        case VISUAL:
                /* fall into */
 
        case VISUAL:
-               ZERO = LINES - TUBESIZE / WCOLS;
-               if (ZERO < 0)
-                       ZERO = 0;
-               if (ZERO > basWTOP)
+               ex_ZERO = LINES - TUBESIZE / WCOLS;
+               if (ex_ZERO < 0)
+                       ex_ZERO = 0;
+               if (ex_ZERO > basWTOP)
                        error("Screen too large for internal buffer");
                WTOP = basWTOP; WBOT = LINES - 2; WECHO = LINES - 1;
                break;
                        error("Screen too large for internal buffer");
                WTOP = basWTOP; WBOT = LINES - 2; WECHO = LINES - 1;
                break;
@@ -319,12 +362,12 @@ vok(atube)
                serror("Don't know enough about your terminal to use %s", Command);
        if (WCOLS > TUBECOLS)
                error("Terminal too wide");
                serror("Don't know enough about your terminal to use %s", Command);
        if (WCOLS > TUBECOLS)
                error("Terminal too wide");
-       if (WLINES >= TUBELINES || WCOLS * (WECHO - ZERO + 1) > TUBESIZE)
+       if (WLINES >= TUBELINES || WCOLS * (WECHO - ex_ZERO + 1) > TUBESIZE)
                error("Screen too large");
 
        vtube0 = atube;
                error("Screen too large");
 
        vtube0 = atube;
-       vclrbyte(atube, WCOLS * (WECHO - ZERO + 1));
-       for (i = 0; i < ZERO; i++)
+       vclrbyte(atube, WCOLS * (WECHO - ex_ZERO + 1));
+       for (i = 0; i < ex_ZERO; i++)
                vtube[i] = (char *) 0;
        for (; i <= WECHO; i++)
                vtube[i] = atube, atube += WCOLS;
                vtube[i] = (char *) 0;
        for (; i <= WECHO; i++)
                vtube[i] = atube, atube += WCOLS;
@@ -342,21 +385,27 @@ vok(atube)
        splitw = 0;
        doomed = 0;
        holdupd = 0;
        splitw = 0;
        doomed = 0;
        holdupd = 0;
-       Peekkey = 0;
+       Peek_key = 0;
        vcnt = vcline = 0;
        vcnt = vcline = 0;
-       if (vSCROLL == 0)
-               vSCROLL = (value(WINDOW)+1)/2;  /* round up so dft=6,11 */
+       if (ex_vSCROLL == 0)
+               ex_vSCROLL = (value(WINDOW)+1)/2; /* round up so dft=6,11 */
 }
 
 #ifdef CBREAK
 vintr()
 {
 }
 
 #ifdef CBREAK
 vintr()
 {
+       extern jmp_buf readbuf;
+       extern int doingread;
 
        signal(SIGINT, vintr);
        if (vcatch)
                onintr();
        ungetkey(ATTN);
        draino();
 
        signal(SIGINT, vintr);
        if (vcatch)
                onintr();
        ungetkey(ATTN);
        draino();
+       if (doingread) {
+               doingread = 0;
+               longjmp(readbuf, 1);
+       }
 }
 #endif
 
 }
 #endif
 
@@ -379,3 +428,12 @@ vsetsiz(size)
        basWTOP = b;
        basWLINES = WBOT - b + 1;
 }
        basWTOP = b;
        basWLINES = WBOT - b + 1;
 }
+
+#ifdef SIGWINCH
+winch()
+{
+       vsave();
+       ignore(setty(normf));
+       longjmp(venv, 1);
+}
+#endif