Release 6
[unix-history] / usr / src / usr.bin / ex / ex_vmain.c
index 7ddd96a..2b0aa10 100644 (file)
@@ -1,5 +1,14 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_vmain.c  4.2 %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;
@@ -61,6 +70,7 @@ vmain()
                vglobp = 0;
                vreg = 0;
                hold = 0;
                vglobp = 0;
                vreg = 0;
                hold = 0;
+               seenprompt = 1;
                wcursor = 0;
                Xhadcnt = hadcnt = 0;
                Xcnt = cnt = 1;
                wcursor = 0;
                Xhadcnt = hadcnt = 0;
                Xcnt = cnt = 1;
@@ -70,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;
@@ -146,8 +156,10 @@ reread:
                                ungetkey(c);
                                goto looptop;
                        }
                                ungetkey(c);
                                goto looptop;
                        }
-                       if (!value(REMAP))
+                       if (!value(REMAP)) {
+                               c = op;
                                break;
                                break;
+                       }
                        if (++maphopcnt > 256)
                                error("Infinite macro loop");
                } while (c != op);
                        if (++maphopcnt > 256)
                                error("Infinite macro loop");
                } while (c != op);
@@ -181,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);
                        }
@@ -289,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
@@ -305,24 +317,36 @@ 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)
                        if (hadcnt)
-                               vSCROLL = cnt;
-                       cnt = vSCROLL;
+                               ex_vSCROLL = cnt;
+                       cnt = ex_vSCROLL;
                        if (state == VISUAL)
                                ind = vcnt - vcline - 1, cnt += ind;
                        else
                                ind = 0;
                        vmoving = 0;
                        vdown(cnt, ind, 1);
                        if (state == VISUAL)
                                ind = vcnt - vcline - 1, cnt += ind;
                        else
                                ind = 0;
                        vmoving = 0;
                        vdown(cnt, ind, 1);
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "before vnline in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol));
+#endif
                        vnline(NOSTR);
                        vnline(NOSTR);
+#ifdef TRACE
+               if (trace)
+                       fprintf(trace, "after vnline in ^D, dot=%d, wdot=%d, dol=%d\n", lineno(dot), lineno(wdot), lineno(dol));
+#endif
                        continue;
 
                /*
                 * ^E           Glitch the screen down (one) line.
                 *              Cursor left on same line in file.
                 */
                        continue;
 
                /*
                 * ^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)
@@ -337,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)
@@ -386,10 +410,12 @@ 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) {
                        vsave();
                        if (vcnt > 2) {
-                               dot += (vcnt - vcline) - 2 + (cnt-1)*basWLINES;
+                               addr = dot + (vcnt - vcline) - 2 + (cnt-1)*basWLINES;
+                               forbid(addr > dol);
+                               dot = addr;
                                vcnt = vcline = 0;
                        }
                        vzop(0, 0, '+');
                                vcnt = vcline = 0;
                        }
                        vzop(0, 0, '+');
@@ -399,10 +425,12 @@ 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) {
-                               dot -= vcline - 2 + (cnt-1)*basWLINES;
+                               addr = dot - vcline + 2 - (cnt-1)*basWLINES;
+                               forbid (addr <= zero);
+                               dot = addr;
                                vcnt = vcline = 0;
                        }
                        vzop(0, 0, '^');
                                vcnt = vcline = 0;
                        }
                        vzop(0, 0, '^');
@@ -490,8 +518,8 @@ reread:
                 */
                case 'O':
                case 'o':
                 */
                case 'O':
                case 'o':
-                       voOpen(c, cnt);
                        vmacchng(1);
                        vmacchng(1);
+                       voOpen(c, cnt);
                        continue;
 
                /*
                        continue;
 
                /*
@@ -513,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 */
@@ -538,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;
@@ -802,24 +830,12 @@ pfixup:
                        continue;
 
                /*
                        continue;
 
                /*
-                * ^^           Return to previous context.  Like a 't
-                *              if that mark is set since tag sets that
-                *              mark if it stays in same file.  Else
-                *              like a :e #, and thus can be used after a
+                * ^^           Return to previous file.
+                *              Like a :e #, and thus can be used after a
                 *              "No Write" diagnostic.
                 *              "No Write" diagnostic.
-                *
-                *              Note: this doesn't correspond with documentation
-                *              Is this comment misleading?
                 */
                 */
-               case CTRL(^):
-                       if (hadcnt)
-                               vsetsiz(cnt);
-                       addr = getmark('t');
-                       if (addr != 0) {
-                               markit(addr);
-                               vupdown(addr - dot, NOSTR);
-                               continue;
-                       }
+               case CTRL('^'):
+                       forbid (hadcnt);
                        vsave();
                        ckaw();
                        oglobp = globp;
                        vsave();
                        ckaw();
                        oglobp = globp;
@@ -833,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";
@@ -853,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:
@@ -861,13 +877,14 @@ gogo:
                        vsave();
                        goto doinit;
 
                        vsave();
                        goto doinit;
 
-#ifdef TIOCLGET
+#ifdef SIGTSTP
                /*
                 * ^Z:  suspend editor session and temporarily return
                /*
                 * ^Z:  suspend editor session and temporarily return
-                *      to shell.  Only works on Berkeley tty driver.
+                *      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";
@@ -879,8 +896,7 @@ gogo:
                 *              execute it in command mode.
                 */
                case ':':
                 *              execute it in command mode.
                 */
                case ':':
-                       if (hadcnt)
-                               vsetsiz(cnt);
+                       forbid (hadcnt);
                        vsave();
                        i = tchng;
                        addr = dot;
                        vsave();
                        i = tchng;
                        addr = dot;
@@ -921,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
@@ -939,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;
 
@@ -949,7 +965,7 @@ doinit:
                         */
                        if (dot == zero) {
                                fixzero();
                         */
                        if (dot == zero) {
                                fixzero();
-                               sync();
+                               ex_sync();
                        }
                        splitw = 0;
 
                        }
                        splitw = 0;
 
@@ -957,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:
                        /*
@@ -981,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;
@@ -1083,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:
@@ -1115,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;
        }
 }