improved vt100 interface. also uses parm termcap entries.
authorMark Horton <mark@ucbvax.Berkeley.EDU>
Thu, 10 Sep 1981 05:25:58 +0000 (21:25 -0800)
committerMark Horton <mark@ucbvax.Berkeley.EDU>
Thu, 10 Sep 1981 05:25:58 +0000 (21:25 -0800)
SCCS-vsn: usr.bin/ex/ex_cmds.c 7.4
SCCS-vsn: usr.bin/ex/ex_tty.c 7.4
SCCS-vsn: usr.bin/ex/ex_tty.h 7.3
SCCS-vsn: usr.bin/ex/ex_vadj.c 7.4
SCCS-vsn: usr.bin/ex/ex_put.c 7.4

usr/src/usr.bin/ex/ex_cmds.c
usr/src/usr.bin/ex/ex_put.c
usr/src/usr.bin/ex/ex_tty.c
usr/src/usr.bin/ex/ex_tty.h
usr/src/usr.bin/ex/ex_vadj.c

index ac4f821..52961e6 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1981 Regents of the University of California */
 /* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_cmds.c   7.3     %G%";
+static char *sccsid = "@(#)ex_cmds.c   7.4     %G%";
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
index 1c8a7fa..c517f32 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1981 Regents of the University of California */
 /* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_put.c    7.3     %G%";
+static char *sccsid = "@(#)ex_put.c    7.4     %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -562,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) {
+                       /* 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) {
+                       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 (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)
@@ -624,25 +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(i & QUOTE)           /* mjm: no sign extension on 3B */
-                       i = ' ';
-               if (insmode && ND)
-                       tputs(ND, 0, plodput);
-               else
-                       plodput(i);
-               outcol++;
+               j = destcol - outcol;
+               if (j > costRP) {
+                       /*
+                        * 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;
        }
index 766da06..9f0e764 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1981 Regents of the University of California */
 /* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_tty.c    7.3     %G%";
+static char *sccsid = "@(#)ex_tty.c    7.4     %G%";
 #include "ex.h"
 #include "ex_tty.h"
 
 #include "ex.h"
 #include "ex_tty.h"
 
@@ -38,10 +38,11 @@ gettmode()
 
 char *xPC;
 char **sstrs[] = {
 
 char *xPC;
 char **sstrs[] = {
-       &AL, &BC, &BT, &CD, &CE, &CL, &CM, &xCR, &DC, &DL, &DM, &DO, &ED, &EI,
-       &F0, &F1, &F2, &F3, &F4, &F5, &F6, &F7, &F8, &F9,
+       &AL, &BC, &BT, &CD, &CE, &CL, &CM, &xCR, &CS, &DC, &DL, &DM, &DO,
+       &ED, &EI, &F0, &F1, &F2, &F3, &F4, &F5, &F6, &F7, &F8, &F9,
        &HO, &IC, &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, &LL, &ND, &xNL,
        &HO, &IC, &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU, &LL, &ND, &xNL,
-       &xPC, &SE, &SF, &SO, &SR, &TA, &TE, &TI, &UP, &VA, &VB, &VD, &VS, &VE
+       &xPC, &RC, &SC, &SE, &SF, &SO, &SR, &TA, &TE, &TI, &UP, &VB, &VS, &VE,
+       &AL_PARM, &DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM
 };
 bool *sflags[] = {
        &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI, &NC, &NS, &OS, &UL,
 };
 bool *sflags[] = {
        &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI, &NC, &NS, &OS, &UL,
@@ -92,8 +93,9 @@ setterm(type)
        /*
         * Handle funny termcap capabilities
         */
        /*
         * Handle funny termcap capabilities
         */
-       if (VA) AL="";
-       if (VD) DL="";
+       if (CS && SC && RC) AL=DL="";
+       if (AL_PARM && AL==NULL) AL="";
+       if (DL_PARM && DL==NULL) DL="";
        if (IC && IM==NULL) IM="";
        if (IC && EI==NULL) EI="";
 
        if (IC && IM==NULL) IM="";
        if (IC && EI==NULL) EI="";
 
@@ -132,6 +134,9 @@ setterm(type)
                CA = 1, costCM = cost(tgoto(CM, 8, 10));
        costSR = cost(SR);
        costAL = cost(AL);
                CA = 1, costCM = cost(tgoto(CM, 8, 10));
        costSR = cost(SR);
        costAL = cost(AL);
+       costDP = cost(tgoto(DOWN_PARM, 10, 10));
+       costLP = cost(tgoto(LEFT_PARM, 10, 10));
+       costRP = cost(tgoto(RIGHT_PARM, 10, 10));
        PC = xPC ? xPC[0] : 0;
        aoftspace = tspace;
        CP(ttytype, longname(ltcbuf, type));
        PC = xPC ? xPC[0] : 0;
        aoftspace = tspace;
        CP(ttytype, longname(ltcbuf, type));
@@ -160,7 +165,7 @@ zap()
                *(*fp++) = tgetflag(namp);
                namp += 2;
        } while (*namp);
                *(*fp++) = tgetflag(namp);
                namp += 2;
        } while (*namp);
-       namp = "albcbtcdceclcmcrdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcsesfsosrtatetiupvavbvdvsve";
+       namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullndnlpcrcscsesfsosrtatetiupvbvsveALDLUPDOLERI";
        sp = sstrs;
        do {
                *(*sp++) = tgetstr(namp, &aoftspace);
        sp = sstrs;
        do {
                *(*sp++) = tgetstr(namp, &aoftspace);
@@ -214,7 +219,7 @@ char *str;
 {
        int countnum();
 
 {
        int countnum();
 
-       if (str == NULL)
+       if (str == NULL || *str=='O')   /* OOPS */
                return 10000;   /* infinity */
        costnum = 0;
        tputs(str, LINES, countnum);
                return 10000;   /* infinity */
        costnum = 0;
        tputs(str, LINES, countnum);
index 4fc7437..cd5157f 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1981 Regents of the University of California */
 /* Copyright (c) 1981 Regents of the University of California */
-/* sccs id:    @(#)ex_tty.h    7.2     %G%  */
+/* sccs id:    @(#)ex_tty.h    7.3     %G%  */
 /*
  * Capabilities from termcap
  *
 /*
  * Capabilities from termcap
  *
@@ -30,17 +30,21 @@ var char    tspace[256];    /* Space for capability strings */
 var    char    *aoftspace;     /* Address of tspace for relocation */
 
 var    char    *AL;            /* P* Add new blank line */
 var    char    *aoftspace;     /* Address of tspace for relocation */
 
 var    char    *AL;            /* P* Add new blank line */
+var    char    *AL_PARM;       /* P* Add n new blank lines */
 extern char    *BC;            /*    Back cursor */
 var    char    *BT;            /* P  Back tab */
 var    char    *CD;            /* P* Clear to end of display */
 var    char    *CE;            /* P  Clear to end of line */
 var    char    *CL;            /* P* Clear screen */
 extern char    *BC;            /*    Back cursor */
 var    char    *BT;            /* P  Back tab */
 var    char    *CD;            /* P* Clear to end of display */
 var    char    *CE;            /* P  Clear to end of line */
 var    char    *CL;            /* P* Clear screen */
-var    char    *CM;            /* P  Cursor motion */
+var    char    *CM;            /* PG Cursor motion */
+var    char    *CS;            /* PG Change scrolling region (vt100) */
 var    char    *xCR;           /* P  Carriage return */
 var    char    *DC;            /* P* Delete character */
 var    char    *DL;            /* P* Delete line sequence */
 var    char    *xCR;           /* P  Carriage return */
 var    char    *DC;            /* P* Delete character */
 var    char    *DL;            /* P* Delete line sequence */
+var    char    *DL_PARM;       /* P* Delete n lines */
 var    char    *DM;            /*    Delete mode (enter)  */
 var    char    *DO;            /*    Down line sequence */
 var    char    *DM;            /*    Delete mode (enter)  */
 var    char    *DO;            /*    Down line sequence */
+var    char    *DOWN_PARM;     /*    Down n lines */
 var    char    *ED;            /*    End delete mode */
 var    char    *EI;            /*    End insert mode */
 var    char    *F0,*F1,*F2,*F3,*F4,*F5,*F6,*F7,*F8,*F9;
 var    char    *ED;            /*    End delete mode */
 var    char    *EI;            /*    End insert mode */
 var    char    *F0,*F1,*F2,*F3,*F4,*F5,*F6,*F7,*F8,*F9;
@@ -56,10 +60,14 @@ var char    *KL;            /*    Keypad left arrow */
 var    char    *KR;            /*    Keypad right arrow */
 var    char    *KS;            /*    Keypad start xmitting */
 var    char    *KU;            /*    Keypad up arrow */
 var    char    *KR;            /*    Keypad right arrow */
 var    char    *KS;            /*    Keypad start xmitting */
 var    char    *KU;            /*    Keypad up arrow */
+var    char    *LEFT_PARM;     /*    Left n chars */
 var    char    *LL;            /*    Quick to last line, column 0 */
 var    char    *ND;            /*    Non-destructive space */
 var    char    *LL;            /*    Quick to last line, column 0 */
 var    char    *ND;            /*    Non-destructive space */
+var    char    *RIGHT_PARM;    /*    Right n spaces */
 var    char    *xNL;           /*    Line feed (new line) */
 extern char    PC;             /*    Pad character */
 var    char    *xNL;           /*    Line feed (new line) */
 extern char    PC;             /*    Pad character */
+var    char    *RC;            /*    Restore cursor from last SC */
+var    char    *SC;            /*    Save cursor */
 var    char    *SE;            /*    Standout end (may leave space) */
 var    char    *SF;            /* P  Scroll forwards */
 var    char    *SO;            /*    Stand out begin (may leave space) */
 var    char    *SE;            /*    Standout end (may leave space) */
 var    char    *SF;            /* P  Scroll forwards */
 var    char    *SO;            /*    Stand out begin (may leave space) */
@@ -68,6 +76,7 @@ var   char    *TA;            /* P  Tab (other than ^I or with padding) */
 var    char    *TE;            /*    Terminal end sequence */
 var    char    *TI;            /*    Terminal initial sequence */
 extern char    *UP;            /*    Upline */
 var    char    *TE;            /*    Terminal end sequence */
 var    char    *TI;            /*    Terminal initial sequence */
 extern char    *UP;            /*    Upline */
+var    char    *UP_PARM;       /*    Up n lines */
 var    char    *VB;            /*    Visible bell */
 var    char    *VE;            /*    Visual end sequence */
 var    char    *VS;            /*    Visual start sequence */
 var    char    *VB;            /*    Visible bell */
 var    char    *VE;            /*    Visual end sequence */
 var    char    *VS;            /*    Visual start sequence */
@@ -89,7 +98,6 @@ var   bool    UL;             /* Underlining works even though !os */
 var    bool    XB;             /* Beehive (no escape key, simulate with f1) */
 var    bool    XN;             /* A newline gets eaten after wrap (concept) */
 var    bool    XT;             /* Tabs are destructive */
 var    bool    XB;             /* Beehive (no escape key, simulate with f1) */
 var    bool    XN;             /* A newline gets eaten after wrap (concept) */
 var    bool    XT;             /* Tabs are destructive */
-var    bool    XV;             /* VT100 - run AL and DL through tgoto */
 var    bool    XX;             /* Tektronix 4025 insert line */
        /* X? is reserved for severely nauseous glitches */
        /* If there are enough of these we may need bit masks! */
 var    bool    XX;             /* Tektronix 4025 insert line */
        /* X? is reserved for severely nauseous glitches */
        /* If there are enough of these we may need bit masks! */
@@ -147,8 +155,11 @@ var        bool    normtty;        /* Have to restore normal mode from normf */
 ttymode ostart(), setty(), unixex();
 
 var    short   costCM; /* # chars to output a typical CM, with padding etc. */
 ttymode ostart(), setty(), unixex();
 
 var    short   costCM; /* # chars to output a typical CM, with padding etc. */
-var    short   costSR; /* likewise */
-var    short   costAL;
+var    short   costSR; /* likewise for scroll reverse */
+var    short   costAL; /* likewise for insert line */
+var    short   costDP; /* likewise for DOWN_PARM */
+var    short   costLP; /* likewise for LEFT_PARM */
+var    short   costRP; /* likewise for RIGHT_PARM */
 
 #ifdef VMUNIX
 # define MAXNOMACS     128     /* max number of macros of each kind */
 
 #ifdef VMUNIX
 # define MAXNOMACS     128     /* max number of macros of each kind */
index 6e40d60..5b09819 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (c) 1981 Regents of the University of California */
 /* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_vadj.c   7.3     %G%";
+static char *sccsid = "@(#)ex_vadj.c   7.4     %G%";
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -256,18 +256,28 @@ vinslin(p, cnt, l)
                 * Use insert line.
                 */
                vgoto(p, 0);
                 * Use insert line.
                 */
                vgoto(p, 0);
-               if (VA)
-                       vputp(tgoto(VA, 0, p), WECHO + 1 - p);
-               else
+               if (AL_PARM && (cnt>1 || *AL==0)) {
+                       /* insert cnt lines.  Should do @'s too. */
+                       vputp(tgoto(AL_PARM, p, cnt), WECHO+1-p);
+               }
+               else if (CS && *AL==0) {
+                       /* vt100 change scrolling region to fake AL */
+                       vputp(SC, 1);
+                       vputp(tgoto(CS, LINES-1,p), 1);
+                       vputp(RC, 1);   /* CS homes stupid cursor */
+                       for (i=cnt; i>0; i--)
+                               vputp(SR, 1);   /* should do @'s */
+                       vputp(tgoto(CS, LINES-1,0), 1);
+                       vputp(RC, 1);   /* Once again put it back */
+               }
+               else {
                        vputp(AL, WECHO + 1 - p);
                        vputp(AL, WECHO + 1 - p);
-               for (i = cnt - 1; i > 0; i--) {
-                       vgoto(outline+1, 0);
-                       if (VA)
-                               vputp(tgoto(VA, 0, outline), WECHO + 1 - outline);
-                       else
+                       for (i = cnt - 1; i > 0; i--) {
+                               vgoto(outline+1, 0);
                                vputp(AL, WECHO + 1 - outline);
                                vputp(AL, WECHO + 1 - outline);
-                       if ((hold & HOLDAT) == 0)
-                               putchar('@');
+                               if ((hold & HOLDAT) == 0)
+                                       putchar('@');
+                       }
                }
                vadjAL(p, cnt);
        } else
                }
                vadjAL(p, cnt);
        } else
@@ -726,11 +736,23 @@ vdellin(p, cnt, l)
         * and physical internal data structures.
         */
        vgoto(p, 0);
         * and physical internal data structures.
         */
        vgoto(p, 0);
-       for (i = 0; i < cnt; i++)
-               if (VD)
-                       vputp(tgoto(VD, 0, p), WECHO - p);
-               else
+       if (DL_PARM && (cnt>1 || *DL==0)) {
+               vputp(tgoto(DL_PARM, p, cnt), WECHO-p);
+       }
+       else if (CS && *DL==0) {
+               /* vt100: fake DL by changing scrolling region */
+               vputp(SC, 1);   /* Save since CS homes stupid cursor */
+               vputp(tgoto(CS, LINES-1, p), 1);
+               vputp(tgoto(CM, 0, 23), 1);     /* Go to lower left corner */
+               for (i=0; i<cnt; i++)           /* .. and scroll cnt times */
+                       putchar('\n');          /* should check NL too */
+               vputp(tgoto(CS, LINES-1, 0), 1);/* restore scrolling region */
+               vputp(RC, 1);                   /* put cursor back */
+       }
+       else {
+               for (i = 0; i < cnt; i++)
                        vputp(DL, WECHO - p);
                        vputp(DL, WECHO - p);
+       }
        vadjDL(p, cnt);
        vcloseup(l, cnt);
 }
        vadjDL(p, cnt);
        vcloseup(l, cnt);
 }