date and time created 83/02/11 15:45:08 by rrh
[unix-history] / usr / src / usr.bin / ex / ex_put.c
index 74fbb42..ceeaf0d 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_put.c    7.7     %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -195,7 +196,7 @@ slobber(c)
  * message so we don't have to keep it in data space.
  */
 static char linb[66];
  * message so we don't have to keep it in data space.
  */
 static char linb[66];
-static char *linp = linb;
+char *linp = linb;
 
 /*
  * Phadnl records when we have already had a complete line ending with \n.
 
 /*
  * Phadnl records when we have already had a complete line ending with \n.
@@ -299,7 +300,7 @@ flush1()
                                        outcol++;
                                        destcol++;
                                        if (XN && outcol % COLUMNS == 0)
                                        outcol++;
                                        destcol++;
                                        if (XN && outcol % COLUMNS == 0)
-                                               putch('\n');
+                                               putch('\r'), putch('\n');
                                }
                                c = *lp++;
                                if (c <= ' ')
                                }
                                c = *lp++;
                                if (c <= ' ')
@@ -561,59 +562,93 @@ plod(cnt)
                outcol = 0;
        }
 dontcr:
                outcol = 0;
        }
 dontcr:
+       /* Move down, if necessary, until we are at the desired line */
        while (outline < destline) {
        while (outline < destline) {
-               outline++;
-               if (xNL && pfast)
-                       tputs(xNL, 0, plodput);
-               else
-                       plodput('\n');
+               j = destline - outline;
+               if (j > costDP && DOWN_PARM) {
+                       /* Win big on Tek 4025 */
+                       tputs(tgoto(DOWN_PARM, 0, j), j, plodput);
+                       outline += j;
+               }
+               else {
+                       outline++;
+                       if (xNL && pfast)
+                               tputs(xNL, 0, plodput);
+                       else
+                               plodput('\n');
+               }
                if (plodcnt < 0)
                        goto out;
                if (NONL || pfast == 0)
                        outcol = 0;
        }
        if (BT)
                if (plodcnt < 0)
                        goto out;
                if (NONL || pfast == 0)
                        outcol = 0;
        }
        if (BT)
-               k = strlen(BT);
+               k = strlen(BT); /* should probably be cost(BT) and moved out */
+       /* Move left, if necessary, to desired column */
        while (outcol > destcol) {
                if (plodcnt < 0)
                        goto out;
        while (outcol > destcol) {
                if (plodcnt < 0)
                        goto out;
-/*
                if (BT && !insmode && outcol - destcol > 4+k) {
                        tputs(BT, 0, plodput);
                        outcol--;
                if (BT && !insmode && outcol - destcol > 4+k) {
                        tputs(BT, 0, plodput);
                        outcol--;
-                       outcol &= ~7;
+                       outcol -= outcol % value(HARDTABS); /* outcol &= ~7; */
                        continue;
                }
                        continue;
                }
-*/
-               outcol--;
-               if (BC)
-                       tputs(BC, 0, plodput);
-               else
-                       plodput('\b');
+               j = outcol - destcol;
+               if (j > costLP && LEFT_PARM) {
+                       tputs(tgoto(LEFT_PARM, 0, j), j, plodput);
+                       outcol -= j;
+               }
+               else {
+                       outcol--;
+                       if (BC)
+                               tputs(BC, 0, plodput);
+                       else
+                               plodput('\b');
+               }
        }
        }
+       /* Move up, if necessary, to desired row */
        while (outline > destline) {
        while (outline > destline) {
-               outline--;
-               tputs(UP, 0, plodput);
+               j = outline - destline;
+               if (UP_PARM && j > 1) {
+                       /* Win big on Tek 4025 */
+                       tputs(tgoto(UP_PARM, 0, j), j, plodput);
+                       outline -= j;
+               }
+               else {
+                       outline--;
+                       tputs(UP, 0, plodput);
+               }
                if (plodcnt < 0)
                        goto out;
        }
                if (plodcnt < 0)
                        goto out;
        }
+       /*
+        * Now move to the right, if necessary.  We first tab to
+        * as close as we can get.
+        */
        if (GT && !insmode && destcol - outcol > 1) {
        if (GT && !insmode && destcol - outcol > 1) {
-       for (;;) {
-               i = tabcol(outcol, value(HARDTABS));
-               if (i > destcol)
-                       break;
+               /* tab to right as far as possible without passing col */
+               for (;;) {
+                       i = tabcol(outcol, value(HARDTABS));
+                       if (i > destcol)
+                               break;
                        if (TA)
                                tputs(TA, 0, plodput);
                        else
                                plodput('\t');
                        outcol = i;
                }
                        if (TA)
                                tputs(TA, 0, plodput);
                        else
                                plodput('\t');
                        outcol = i;
                }
+               /* consider another tab and then some backspaces */
                if (destcol - outcol > 4 && i < COLUMNS && (BC || BS)) {
                        if (TA)
                                tputs(TA, 0, plodput);
                        else
                                plodput('\t');
                        outcol = i;
                if (destcol - outcol > 4 && i < COLUMNS && (BC || BS)) {
                        if (TA)
                                tputs(TA, 0, plodput);
                        else
                                plodput('\t');
                        outcol = i;
+                       /*
+                        * Back up.  Don't worry about LEFT_PARM because
+                        * it's never more than 4 spaces anyway.
+                        */
                        while (outcol > destcol) {
                                outcol--;
                                if (BC)
                        while (outcol > destcol) {
                                outcol--;
                                if (BC)
@@ -623,23 +658,43 @@ dontcr:
                        }
                }
        }
                        }
                }
        }
+       /*
+        * We've tabbed as much as possible.  If we still need to go
+        * further (not exact or can't tab) space over.  This is a
+        * very common case when moving to the right with space.
+        */
        while (outcol < destcol) {
        while (outcol < destcol) {
-               /*
-                * move one char to the right.  We don't use ND space
-                * because it's better to just print the char we are
-                * moving over.  There are various exceptions, however.
-                * If !inopen, vtube contains garbage.  If the char is
-                * a null or a tab we want to print a space.  Other random
-                * chars we use space for instead, too.
-                */
-               if (!inopen || vtube[outline]==NULL ||
-                       (i=vtube[outline][outcol]) < ' ')
-                       i = ' ';
-               if (insmode && ND)
-                       tputs(ND, 0, plodput);
-               else
-                       plodput(i);
-               outcol++;
+               j = destcol - outcol;
+               if (j > costRP && RIGHT_PARM) {
+                       /*
+                        * This probably happens rarely, if at all.
+                        * It seems mainly useful for ANSI terminals
+                        * with no hardware tabs, and I don't know
+                        * of any such terminal at the moment.
+                        */
+                       tputs(tgoto(RIGHT_PARM, 0, j), j, plodput);
+                       outcol += j;
+               }
+               else {
+                       /*
+                        * move one char to the right.  We don't use ND space
+                        * because it's better to just print the char we are
+                        * moving over.  There are various exceptions, however.
+                        * If !inopen, vtube contains garbage.  If the char is
+                        * a null or a tab we want to print a space.  Other
+                        * random chars we use space for instead, too.
+                        */
+                       if (!inopen || vtube[outline]==NULL ||
+                               (i=vtube[outline][outcol]) < ' ')
+                               i = ' ';
+                       if(i & QUOTE)   /* mjm: no sign extension on 3B */
+                               i = ' ';
+                       if (insmode && ND)
+                               tputs(ND, 0, plodput);
+                       else
+                               plodput(i);
+                       outcol++;
+               }
                if (plodcnt < 0)
                        goto out;
        }
                if (plodcnt < 0)
                        goto out;
        }
@@ -734,6 +789,10 @@ putch(c)
        int c;
 {
 
        int c;
 {
 
+#ifdef OLD3BTTY                /* mjm */
+       if(c == '\n')   /* mjm: Fake "\n\r" for '\n' til fix in 3B firmware */
+               putch('\r');    /* mjm: vi does "stty -icanon" => -onlcr !! */
+#endif
        *obp++ = c & 0177;
        if (obp >= &obuf[sizeof obuf])
                flusho();
        *obp++ = c & 0177;
        if (obp >= &obuf[sizeof obuf])
                flusho();
@@ -856,7 +915,7 @@ ostart()
        tty = normf;
        tty.c_iflag &= ~ICRNL;
        tty.c_lflag &= ~(ECHO|ICANON);
        tty = normf;
        tty.c_iflag &= ~ICRNL;
        tty.c_lflag &= ~(ECHO|ICANON);
-       tty.c_oflag &= ~TAB3;
+       tty.c_oflag &= ~(TAB3|ONLCR);
        tty.c_cc[VMIN] = 1;
        tty.c_cc[VTIME] = 1;
        ttcharoff();
        tty.c_cc[VMIN] = 1;
        tty.c_cc[VTIME] = 1;
        ttcharoff();
@@ -872,8 +931,33 @@ tostart()
 {
        putpad(VS);
        putpad(KS);
 {
        putpad(VS);
        putpad(KS);
-       if (!value(MESG))
-               chmod(ttynbuf, 0611);   /* 11 = urgent only allowed */
+       if (!value(MESG)) {
+               if (ttynbuf[0] == 0) {
+                       register char *tn;
+                       if ((tn=ttyname(2)) == NULL &&
+                           (tn=ttyname(1)) == NULL &&
+                           (tn=ttyname(0)) == NULL)
+                               ttynbuf[0] = 1;
+                       else
+                               strcpy(ttynbuf, tn);
+               }
+               if (ttynbuf[0] != 1) {
+                       struct stat sbuf;
+                       stat(ttynbuf, &sbuf);
+                       ttymesg = sbuf.st_mode & 0777;
+                       chmod(ttynbuf,
+#ifdef UCBV7
+       /*
+        * This applies to the UCB V7 Pdp-11 system with the
+        * -u write option only.
+        */
+                                       0611    /* 11 = urgent only allowed */
+#else
+                                       0600
+#endif
+                                               );
+               }
+       }
 }
 
 /*
 }
 
 /*
@@ -927,7 +1011,7 @@ ostop(f)
 #ifndef USG3TTY
        pfast = (f & CRMOD) == 0;
 #else
 #ifndef USG3TTY
        pfast = (f & CRMOD) == 0;
 #else
-       pfast = (f.c_oflag & OCRNL) == 0;
+       pfast = (f.c_oflag & ONLCR) == 0;
 #endif
        termreset(), fgoto(), flusho();
        normal(f);
 #endif
        termreset(), fgoto(), flusho();
        normal(f);
@@ -939,7 +1023,7 @@ tostop()
 {
        putpad(VE);
        putpad(KE);
 {
        putpad(VE);
        putpad(KE);
-       if (!value(MESG))
+       if (!value(MESG) && ttynbuf[0]>1)
                chmod(ttynbuf, ttymesg);
 }
 
                chmod(ttynbuf, ttymesg);
 }
 
@@ -1013,8 +1097,6 @@ setty(f)
 gTTY(i)
        int i;
 {
 gTTY(i)
        int i;
 {
-       char *tn;
-       struct stat sbuf;
 
 #ifndef USG3TTY
        ignore(gtty(i, &tty));
 
 #ifndef USG3TTY
        ignore(gtty(i, &tty));
@@ -1022,18 +1104,13 @@ gTTY(i)
        ioctl(i, TIOCGETC, &ottyc);
        nttyc = ottyc;
 # endif
        ioctl(i, TIOCGETC, &ottyc);
        nttyc = ottyc;
 # endif
-# ifdef TIOCLGET
+# ifdef TIOCGLTC
        ioctl(i, TIOCGLTC, &olttyc);
        nlttyc = olttyc;
 # endif
 #else
        ioctl(i, TCGETA, &tty);
 #endif
        ioctl(i, TIOCGLTC, &olttyc);
        nlttyc = olttyc;
 # endif
 #else
        ioctl(i, TCGETA, &tty);
 #endif
-       if ((tn=ttyname(0)) == NULL && (tn=ttyname(1)) == NULL && (tn=ttyname(2)) == NULL)
-               tn = "/dev/tty";
-       strcpy(ttynbuf, tn);
-       stat(ttynbuf, &sbuf);
-       ttymesg = sbuf.st_mode & 0777;
 }
 
 /*
 }
 
 /*
@@ -1063,7 +1140,7 @@ sTTY(i)
        /* Update the other random chars while we're at it. */
        ioctl(i, TIOCSETC, &nttyc);
 # endif
        /* Update the other random chars while we're at it. */
        ioctl(i, TIOCSETC, &nttyc);
 # endif
-# ifdef TIOCLGET
+# ifdef TIOCSLTC
        ioctl(i, TIOCSLTC, &nlttyc);
 # endif
 
        ioctl(i, TIOCSLTC, &nlttyc);
 # endif
 
@@ -1081,39 +1158,3 @@ noonl()
 
        putchar(Outchar != termchar ? ' ' : '\n');
 }
 
        putchar(Outchar != termchar ? ' ' : '\n');
 }
-
-#ifdef TIOCLGET
-/*
- * We have just gotten a susp.  Suspend and prepare to resume.
- */
-onsusp()
-{
-       ttymode f;
-
-       f = setty(normf);
-       vnfl();
-       putpad(TE);
-       flush();
-
-       signal(SIGTSTP, SIG_DFL);
-       kill(0, SIGTSTP);
-
-       /* the pc stops here */
-
-       signal(SIGTSTP, onsusp);
-       vcontin(0);
-       setty(f);
-       if (!inopen)
-               error(0);
-       else {
-               if (vcnt < 0) {
-                       vcnt = -vcnt;
-                       if (state == VISUAL)
-                               vclear();
-                       else if (state == CRTOPEN)
-                               vcnt = 0;
-               }
-               vdirty(0, LINES);
-               vrepaint(cursor);
-       }
-}