changed INDEX operator to handle multiple subscript arrays correctly
[unix-history] / usr / src / usr.bin / ex / ex_vput.c
index cadd33a..a3e0f78 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/* Copyright (c) 1981 Regents of the University of California */
+static char *sccsid = "@(#)ex_vput.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"
@@ -115,10 +116,28 @@ vclrech(didphys)
                 * since we don't really know whats out there.
                 * Vigoto might decide (incorrectly) to do nothing.
                 */
                 * since we don't really know whats out there.
                 * Vigoto might decide (incorrectly) to do nothing.
                 */
-               if (DB)
-                       vgoto(WECHO, 0), vputp(CD ? CD : CE, 1);
-               else
-                       vigoto(WECHO, 0), vclreol();
+               if (DB) {
+                       vgoto(WECHO, 0);
+                       vputp(CD ? CD : CE, 1);
+               } else {
+                       if (XT) {
+                               /*
+                                * This code basically handles the t1061
+                                * where positioning at (0, 0) won't work
+                                * because the terminal won't let you put
+                                * the cursor on it's magic cookie.
+                                *
+                                * Should probably be XS above, or even a
+                                * new X? glitch, but right now t1061 is the
+                                * only terminal with XT.
+                                */
+                               vgoto(WECHO, 0);
+                               vputp(DL, 1);
+                       } else {
+                               vigoto(WECHO, 0);
+                               vclreol();
+                       }
+               }
                splitw = 0;
                didphys = 1;
        }
                splitw = 0;
                didphys = 1;
        }
@@ -399,11 +418,11 @@ vgoto(y, x)
  */
 vgotab()
 {
  */
 vgotab()
 {
-       register int i = (LINE(vcline) - destline) * WCOLS + destcol;
+       register int i = tabcol(destcol, value(TABSTOP)) - destcol;
 
        do
                (*Outchar)(QUOTE);
 
        do
                (*Outchar)(QUOTE);
-       while (++i % value(TABSTOP));
+       while (--i);
 }
 
 /*
 }
 
 /*
@@ -443,7 +462,7 @@ vmaktop(p, cp)
        register int i;
        char temp[TUBECOLS];
 
        register int i;
        char temp[TUBECOLS];
 
-       if (vtube[p] == cp)
+       if (p < 0 || vtube[p] == cp)
                return;
        for (i = ZERO; i <= WECHO; i++)
                if (vtube[i] == cp) {
                return;
        for (i = ZERO; i <= WECHO; i++)
                if (vtube[i] == cp) {
@@ -465,7 +484,7 @@ vmaktop(p, cp)
  * to make life simpler.
  */
 vinschar(c)
  * to make life simpler.
  */
 vinschar(c)
-       char c;
+       int c;          /* mjm: char --> int */
 {
        register int i;
        register char *tp;
 {
        register int i;
        register char *tp;
@@ -542,7 +561,7 @@ vinschar(c)
                 * use QUOTE here since we really need to print blanks.
                 * QUOTE|' ' is the representation of this.
                 */
                 * use QUOTE here since we really need to print blanks.
                 * QUOTE|' ' is the representation of this.
                 */
-               inssiz = value(TABSTOP) - inscol % value(TABSTOP);
+               inssiz = tabcol(inscol, value(TABSTOP)) - inscol;
                c = ' ' | QUOTE;
        } else
                inssiz = 1;
                c = ' ' | QUOTE;
        } else
                inssiz = 1;
@@ -618,7 +637,7 @@ vinschar(c)
                 * line is now deeper.  We then do the shift
                 * implied by the insertion.
                 */
                 * line is now deeper.  We then do the shift
                 * implied by the insertion.
                 */
-               if (inssiz >= doomed + value(TABSTOP) - tabstart % value(TABSTOP)) {
+               if (inssiz >= doomed + tabcol(tabstart, value(TABSTOP)) - tabstart) {
                        if (IN)
                                vrigid();
                        vneedpos(value(TABSTOP));
                        if (IN)
                                vrigid();
                        vneedpos(value(TABSTOP));
@@ -696,9 +715,10 @@ vnpins(dosync)
                e = vglitchup(vcline, d);
                vigoto(e, 0); vclreol();
                if (dosync) {
                e = vglitchup(vcline, d);
                vigoto(e, 0); vclreol();
                if (dosync) {
+                       int (*Ooutchar)() = Outchar;
                        Outchar = vputchar;
                        vsync(e + 1);
                        Outchar = vputchar;
                        vsync(e + 1);
-                       Outchar = vinschar;
+                       Outchar = Ooutchar;
                }
        } else {
                vup1();
                }
        } else {
                vup1();
@@ -767,9 +787,12 @@ vishft()
                        goim();
                        up = tp + j * WCOLS - shft;
                        i = shft;
                        goim();
                        up = tp + j * WCOLS - shft;
                        i = shft;
-                       do
-                               vputchar(*up++);
-                       while (--i);
+                       do {
+                               if (*up)
+                                       vputchar(*up++);
+                               else
+                                       break;
+                       } while (--i);
                }
                vigotoCL(tabstart);
                i = shft - (inssiz - doomed);
                }
                vigotoCL(tabstart);
                i = shft - (inssiz - doomed);
@@ -806,7 +829,7 @@ vishft()
  * Now do the insert of the characters (finally).
  */
 viin(c)
  * Now do the insert of the characters (finally).
  */
 viin(c)
-       char c;
+       int c;          /* mjm: char --> int */
 {
        register char *tp, *up;
        register int i, j;
 {
        register char *tp, *up;
        register int i, j;
@@ -1029,9 +1052,9 @@ vputchar(c)
        if (trace)
                tracec(c);
 #endif
        if (trace)
                tracec(c);
 #endif
-       /* Patch to fix problem of >79 chars on echo line: don't echo extras */
+       /* Fix problem of >79 chars on echo line. */
        if (destcol >= WCOLS-1 && splitw && destline == WECHO)
        if (destcol >= WCOLS-1 && splitw && destline == WECHO)
-               return;
+               pofix();
        if (destcol >= WCOLS) {
                destline += destcol / WCOLS;
                destcol %= WCOLS;
        if (destcol >= WCOLS) {
                destline += destcol / WCOLS;
                destcol %= WCOLS;
@@ -1174,9 +1197,13 @@ def:
                 * CONCEPT braindamage in early models:  after a wraparound
                 * the next newline is eaten.  It's hungry so we just
                 * feed it now rather than worrying about it.
                 * CONCEPT braindamage in early models:  after a wraparound
                 * the next newline is eaten.  It's hungry so we just
                 * feed it now rather than worrying about it.
+                * Fixed to use return linefeed to work right
+                * on vt100/tab132 as well as concept.
                 */
                 */
-               if (XN && outcol % WCOLS == 0)
+               if (XN && outcol % WCOLS == 0) {
+                       vputc('\r');
                        vputc('\n');
                        vputc('\n');
+               }
        }
 }
 
        }
 }
 
@@ -1302,13 +1329,15 @@ tvliny()
 }
 
 tracec(c)
 }
 
 tracec(c)
-       char c;
+       int c;          /* mjm: char --> int */
 {
 
        if (!techoin)
                trubble = 1;
        if (c == ESCAPE)
                fprintf(trace, "$");
 {
 
        if (!techoin)
                trubble = 1;
        if (c == ESCAPE)
                fprintf(trace, "$");
+       else if (c & QUOTE)     /* mjm: for 3B (no sign extension) */
+               fprintf(trace, "~%c", ctlof(c&TRIM));
        else if (c < ' ' || c == DELETE)
                fprintf(trace, "^%c", ctlof(c));
        else
        else if (c < ' ' || c == DELETE)
                fprintf(trace, "^%c", ctlof(c));
        else