Release 6
[unix-history] / usr / src / usr.bin / ex / ex_vmain.c
index b26df64..2b0aa10 100644 (file)
@@ -1,5 +1,14 @@
-/* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_vmain.c  7.1     %G%";
+/*-
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ex_vmain.c 7.12 (Berkeley) %G%";
+#endif /* not lint */
+
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -19,7 +28,7 @@ vmain()
        register int c, cnt, i;
        char esave[TUBECOLS];
        char *oglobp;
        register int c, cnt, i;
        char esave[TUBECOLS];
        char *oglobp;
-       char d;
+       short d;
        line *addr;
        int ind, nlput;
        int shouldpo = 0;
        line *addr;
        int ind, nlput;
        int shouldpo = 0;
@@ -71,7 +80,7 @@ vmain()
                                ignore(peekkey());
                        holdupd = 0;
 /*
                                ignore(peekkey());
                        holdupd = 0;
 /*
-                       if (LINE(0) < ZERO) {
+                       if (LINE(0) < ex_ZERO) {
                                vclear();
                                vcnt = 0;
                                i = 3;
                                vclear();
                                vcnt = 0;
                                i = 3;
@@ -184,9 +193,9 @@ reread:
                 *              will probably foul this up, but nobody has
                 *              one of them.
                 */
                 *              will probably foul this up, but nobody has
                 *              one of them.
                 */
-               case CTRL(l):
-               case CTRL(r):
-                       if (c == CTRL(l) || (KR && *KR==CTRL(l))) {
+               case CTRL('l'):
+               case CTRL('r'):
+                       if (c == CTRL('l') || (KR && *KR==CTRL('l'))) {
                                vclear();
                                vdirty(0, vcnt);
                        }
                                vclear();
                                vdirty(0, vcnt);
                        }
@@ -292,10 +301,10 @@ reread:
                 *              redrawn almost as it was.  In this case
                 *              one should simply move the cursor.
                 */
                 *              redrawn almost as it was.  In this case
                 *              one should simply move the cursor.
                 */
-               case CTRL(u):
+               case CTRL('u'):
                        if (hadcnt)
                        if (hadcnt)
-                               vSCROLL = cnt;
-                       cnt = vSCROLL;
+                               ex_vSCROLL = cnt;
+                       cnt = ex_vSCROLL;
                        if (state == VISUAL)
                                ind = vcline, cnt += ind;
                        else
                        if (state == VISUAL)
                                ind = vcline, cnt += ind;
                        else
@@ -308,14 +317,14 @@ reread:
                /*
                 * ^D           Scroll down.  Like scroll up.
                 */
                /*
                 * ^D           Scroll down.  Like scroll up.
                 */
-               case CTRL(d):
+               case CTRL('d'):
 #ifdef TRACE
                if (trace)
                        fprintf(trace, "before vdown in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol));
 #endif
                        if (hadcnt)
 #ifdef TRACE
                if (trace)
                        fprintf(trace, "before vdown in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol));
 #endif
                        if (hadcnt)
-                               vSCROLL = cnt;
-                       cnt = vSCROLL;
+                               ex_vSCROLL = cnt;
+                       cnt = ex_vSCROLL;
                        if (state == VISUAL)
                                ind = vcnt - vcline - 1, cnt += ind;
                        else
                        if (state == VISUAL)
                                ind = vcnt - vcline - 1, cnt += ind;
                        else
@@ -337,7 +346,7 @@ reread:
                 * ^E           Glitch the screen down (one) line.
                 *              Cursor left on same line in file.
                 */
                 * ^E           Glitch the screen down (one) line.
                 *              Cursor left on same line in file.
                 */
-               case CTRL(e):
+               case CTRL('e'):
                        if (state != VISUAL)
                                continue;
                        if (!hadcnt)
                        if (state != VISUAL)
                                continue;
                        if (!hadcnt)
@@ -352,7 +361,7 @@ reread:
                /*
                 * ^Y           Like ^E but up
                 */
                /*
                 * ^Y           Like ^E but up
                 */
-               case CTRL(y):
+               case CTRL('y'):
                        if (state != VISUAL)
                                continue;
                        if (!hadcnt)
                        if (state != VISUAL)
                                continue;
                        if (!hadcnt)
@@ -401,7 +410,7 @@ reread:
                 * ^F           Window forwards, with 2 lines of continuity.
                 *              Count repeats.
                 */
                 * ^F           Window forwards, with 2 lines of continuity.
                 *              Count repeats.
                 */
-               case CTRL(f):
+               case CTRL('f'):
                        vsave();
                        if (vcnt > 2) {
                                addr = dot + (vcnt - vcline) - 2 + (cnt-1)*basWLINES;
                        vsave();
                        if (vcnt > 2) {
                                addr = dot + (vcnt - vcline) - 2 + (cnt-1)*basWLINES;
@@ -416,10 +425,10 @@ reread:
                 * ^B           Window backwards, with 2 lines of continuity.
                 *              Inverse of ^F.
                 */
                 * ^B           Window backwards, with 2 lines of continuity.
                 *              Inverse of ^F.
                 */
-               case CTRL(b):
+               case CTRL('b'):
                        vsave();
                        if (one + vcline != dot && vcnt > 2) {
                        vsave();
                        if (one + vcline != dot && vcnt > 2) {
-                               addr = dot - vcline - 2 + (cnt-1)*basWLINES;
+                               addr = dot - vcline + 2 - (cnt-1)*basWLINES;
                                forbid (addr <= zero);
                                dot = addr;
                                vcnt = vcline = 0;
                                forbid (addr <= zero);
                                dot = addr;
                                vcnt = vcline = 0;
@@ -532,7 +541,7 @@ reread:
                                setLAST();
                                mbuf[0] = 'r';
                                mbuf[1] = *cursor;
                                setLAST();
                                mbuf[0] = 'r';
                                mbuf[1] = *cursor;
-                               mbuf[2] = cursor[1]==0 ? 0 : ' ';
+                               mbuf[2] = cursor[1]==0 ? 0 : 'l';
                                mbuf[3] = 0;
                                if (isalpha(mbuf[1]))
                                        mbuf[1] ^= ' '; /* toggle the case */
                                mbuf[3] = 0;
                                if (isalpha(mbuf[1]))
                                        mbuf[1] ^= ' '; /* toggle the case */
@@ -557,7 +566,7 @@ appnd:
                case 'a':
                        if (*cursor) {
                                if (state == HARDOPEN)
                case 'a':
                        if (*cursor) {
                                if (state == HARDOPEN)
-                                       putchar(*cursor);
+                                       ex_putchar(*cursor);
                                cursor++;
                        }
                        goto insrt;
                                cursor++;
                        }
                        goto insrt;
@@ -825,7 +834,7 @@ pfixup:
                 *              Like a :e #, and thus can be used after a
                 *              "No Write" diagnostic.
                 */
                 *              Like a :e #, and thus can be used after a
                 *              "No Write" diagnostic.
                 */
-               case CTRL(^):
+               case CTRL('^'):
                        forbid (hadcnt);
                        vsave();
                        ckaw();
                        forbid (hadcnt);
                        vsave();
                        ckaw();
@@ -840,7 +849,7 @@ pfixup:
                 * ^]           Takes word after cursor as tag, and then does
                 *              tag command.  Read ``go right to''.
                 */
                 * ^]           Takes word after cursor as tag, and then does
                 *              tag command.  Read ``go right to''.
                 */
-               case CTRL(]):
+               case CTRL(']'):
                        grabtag();
                        oglobp = globp;
                        globp = "tag";
                        grabtag();
                        oglobp = globp;
                        globp = "tag";
@@ -860,7 +869,7 @@ pfixup:
                 *
                 * BUG:         Was ^S but doesn't work in cbreak mode
                 */
                 *
                 * BUG:         Was ^S but doesn't work in cbreak mode
                 */
-               case CTRL(g):
+               case CTRL('g'):
                        oglobp = globp;
                        globp = "file";
 gogo:
                        oglobp = globp;
                        globp = "file";
 gogo:
@@ -874,8 +883,8 @@ gogo:
                 *      to shell.  Only works with Berkeley/IIASA process
                 *      control in kernel.
                 */
                 *      to shell.  Only works with Berkeley/IIASA process
                 *      control in kernel.
                 */
-               case CTRL(z):
-                       forbid(dosusp == 0 || !ldisc);
+               case CTRL('z'):
+                       forbid(dosusp == 0);
                        vsave();
                        oglobp = globp;
                        globp = "stop";
                        vsave();
                        oglobp = globp;
                        globp = "stop";
@@ -928,7 +937,7 @@ doinit:
                                onumber = value(NUMBER);
                                olist = value(LIST);
                                OPline = Pline;
                                onumber = value(NUMBER);
                                olist = value(LIST);
                                OPline = Pline;
-                               OPutchar = Putchar;
+                               OPutchar = Put_char;
 #ifndef CBREAK
                                vcook();
 #endif
 #ifndef CBREAK
                                vcook();
 #endif
@@ -946,7 +955,7 @@ doinit:
                        ENDCATCH
                        fixol();
                        Pline = OPline;
                        ENDCATCH
                        fixol();
                        Pline = OPline;
-                       Putchar = OPutchar;
+                       Put_char = OPutchar;
                        ungetchar(d);
                        globp = oglobp;
 
                        ungetchar(d);
                        globp = oglobp;
 
@@ -956,7 +965,7 @@ doinit:
                         */
                        if (dot == zero) {
                                fixzero();
                         */
                        if (dot == zero) {
                                fixzero();
-                               sync();
+                               ex_sync();
                        }
                        splitw = 0;
 
                        }
                        splitw = 0;
 
@@ -964,9 +973,9 @@ doinit:
                         * Special case: did list/number options change?
                         */
                        if (onumber != value(NUMBER))
                         * Special case: did list/number options change?
                         */
                        if (onumber != value(NUMBER))
-                               setnumb(value(NUMBER));
+                               ignorf(setnumb(value(NUMBER)));
                        if (olist != value(LIST))
                        if (olist != value(LIST))
-                               setlist(value(LIST));
+                               ignorf(setlist(value(LIST)));
 
 fixup:
                        /*
 
 fixup:
                        /*
@@ -988,7 +997,7 @@ fixup:
                         * If we are about to do another :, hold off
                         * updating of screen.
                         */
                         * If we are about to do another :, hold off
                         * updating of screen.
                         */
-                       if (vcnt < 0 && Peekkey == ':') {
+                       if (vcnt < 0 && Peek_key == ':') {
                                getDOT();
                                shouldpo = 1;
                                continue;
                                getDOT();
                                shouldpo = 1;
                                continue;
@@ -1090,7 +1099,7 @@ fixup:
                 * U            restore current line to initial state.
                 */
                case 'U':
                 * U            restore current line to initial state.
                 */
                case 'U':
-                       vUndo();
+                       ex_vUndo();
                        continue;
 
 fonfon:
                        continue;
 
 fonfon:
@@ -1122,7 +1131,11 @@ grabtag()
                        if (dp < &lasttag[sizeof lasttag - 2])
                                *dp++ = *cp;
                        cp++;
                        if (dp < &lasttag[sizeof lasttag - 2])
                                *dp++ = *cp;
                        cp++;
-               } while (isalpha(*cp) || isdigit(*cp) || *cp == '_');
+               } while (isalpha(*cp) || isdigit(*cp) || *cp == '_'
+#ifdef LISPCODE
+                       || (value(LISP) && *cp == '-')
+#endif LISPCODE
+                       );
                *dp++ = 0;
        }
 }
                *dp++ = 0;
        }
 }