date and time created 83/02/11 15:44:54 by rrh
[unix-history] / usr / src / usr.bin / ex / ex_vmain.c
index 7ddd96a..f999f0b 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_vmain.c  4.2 %G%";
+/* Copyright (c) 1981 Regents of the University of California */
+static char *sccsid = "@(#)ex_vmain.c  7.2     %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -19,7 +19,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 +61,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;
@@ -146,8 +147,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);
@@ -306,6 +309,10 @@ reread:
                 * ^D           Scroll down.  Like scroll up.
                 */
                case CTRL(d):
                 * ^D           Scroll down.  Like scroll up.
                 */
                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)
                                vSCROLL = cnt;
                        cnt = vSCROLL;
                        if (hadcnt)
                                vSCROLL = cnt;
                        cnt = vSCROLL;
@@ -315,7 +322,15 @@ reread:
                                ind = 0;
                        vmoving = 0;
                        vdown(cnt, ind, 1);
                                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;
 
                /*
                        continue;
 
                /*
@@ -389,7 +404,9 @@ reread:
                case CTRL(f):
                        vsave();
                        if (vcnt > 2) {
                case CTRL(f):
                        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, '+');
@@ -402,7 +419,9 @@ reread:
                case CTRL(b):
                        vsave();
                        if (one + vcline != dot && vcnt > 2) {
                case CTRL(b):
                        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 +509,8 @@ reread:
                 */
                case 'O':
                case 'o':
                 */
                case 'O':
                case 'o':
-                       voOpen(c, cnt);
                        vmacchng(1);
                        vmacchng(1);
+                       voOpen(c, cnt);
                        continue;
 
                /*
                        continue;
 
                /*
@@ -802,24 +821,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(^):
                 */
                case CTRL(^):
-                       if (hadcnt)
-                               vsetsiz(cnt);
-                       addr = getmark('t');
-                       if (addr != 0) {
-                               markit(addr);
-                               vupdown(addr - dot, NOSTR);
-                               continue;
-                       }
+                       forbid (hadcnt);
                        vsave();
                        ckaw();
                        oglobp = globp;
                        vsave();
                        ckaw();
                        oglobp = globp;
@@ -861,10 +868,11 @@ 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 || !ldisc);
@@ -879,8 +887,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;