document distributed with 4.1BSD
[unix-history] / usr / src / usr.bin / ex / ex_tty.c
index 9f0e764..8e09d25 100644 (file)
@@ -1,5 +1,13 @@
-/* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_tty.c    7.4     %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)ex_tty.c    7.10 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_tty.h"
 
 #include "ex.h"
 #include "ex_tty.h"
 
@@ -55,8 +63,7 @@ setterm(type)
        char *type;
 {
        char *tgoto();
        char *type;
 {
        char *tgoto();
-       register int unknown, i;
-       register int l;
+       register int unknown;
        char ltcbuf[TCBUFSIZE];
 
        if (type[0] == 0)
        char ltcbuf[TCBUFSIZE];
 
        if (type[0] == 0)
@@ -67,18 +74,7 @@ setterm(type)
                unknown++;
                CP(ltcbuf, "xx|dumb:");
        }
                unknown++;
                CP(ltcbuf, "xx|dumb:");
        }
-       i = LINES = tgetnum("li");
-       if (LINES <= 5)
-               LINES = 24;
-       if (LINES > TUBELINES)
-               LINES = TUBELINES;
-       l = LINES;
-       if (ospeed < B1200)
-               l = 9;  /* including the message line at the bottom */
-       else if (ospeed < B2400)
-               l = 17;
-       if (l > LINES)
-               l = LINES;
+       setsize();
        aoftspace = tspace;
        zap();
        /*
        aoftspace = tspace;
        zap();
        /*
@@ -93,11 +89,15 @@ setterm(type)
        /*
         * Handle funny termcap capabilities
         */
        /*
         * Handle funny termcap capabilities
         */
-       if (CS && SC && RC) AL=DL="";
+       if (CS && SC && RC) {
+               if (AL==NULL) AL="";
+               if (DL==NULL) DL="";
+       }
        if (AL_PARM && AL==NULL) AL="";
        if (DL_PARM && DL==NULL) DL="";
        if (IC && IM==NULL) IM="";
        if (IC && EI==NULL) EI="";
        if (AL_PARM && AL==NULL) AL="";
        if (DL_PARM && DL==NULL) DL="";
        if (IC && IM==NULL) IM="";
        if (IC && EI==NULL) EI="";
+       if (!GT) BT=NULL;       /* If we can't tab, we can't backtab either */
 
 #ifdef TIOCLGET
        /*
 
 #ifdef TIOCLGET
        /*
@@ -114,7 +114,8 @@ setterm(type)
                        sc[1] = 0;
                        if (olttyc.t_suspc == CTRL(z)) {
                                for (i=0; i<=4; i++)
                        sc[1] = 0;
                        if (olttyc.t_suspc == CTRL(z)) {
                                for (i=0; i<=4; i++)
-                                       if (arrows[i].cap[0] == CTRL(z))
+                                       if (arrows[i].cap &&
+                                           arrows[i].cap[0] == CTRL(z))
                                                addmac(sc, NULL, NULL, arrows);
                        } else
                                addmac(sc, "\32", "susp", arrows);
                                                addmac(sc, NULL, NULL, arrows);
                        } else
                                addmac(sc, "\32", "susp", arrows);
@@ -122,12 +123,6 @@ setterm(type)
        }
 #endif
 
        }
 #endif
 
-       options[WINDOW].ovalue = options[WINDOW].odefault = l - 1;
-       if (defwind) options[WINDOW].ovalue = defwind;
-       options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2);
-       COLUMNS = tgetnum("co");
-       if (COLUMNS <= 4)
-               COLUMNS = 1000;
        if (tgoto(CM, 2, 2)[0] == 'O')  /* OOPS */
                CA = 0, CM = 0;
        else
        if (tgoto(CM, 2, 2)[0] == 'O')  /* OOPS */
                CA = 0, CM = 0;
        else
@@ -140,8 +135,6 @@ setterm(type)
        PC = xPC ? xPC[0] : 0;
        aoftspace = tspace;
        CP(ttytype, longname(ltcbuf, type));
        PC = xPC ? xPC[0] : 0;
        aoftspace = tspace;
        CP(ttytype, longname(ltcbuf, type));
-       if (i <= 0)
-               LINES = 2;
        /* proper strings to change tty type */
        termreset();
        gettmode();
        /* proper strings to change tty type */
        termreset();
        gettmode();
@@ -153,6 +146,41 @@ setterm(type)
                serror("%s: Unknown terminal type", type);
 }
 
                serror("%s: Unknown terminal type", type);
 }
 
+setsize()
+{
+       register int l, i;
+       struct winsize win;
+
+       if (ioctl(0, TIOCGWINSZ, &win) < 0) {
+               i = LINES = tgetnum("li");
+               COLUMNS = tgetnum("co");
+       } else {
+               if ((LINES = winsz.ws_row = win.ws_row) == 0)
+                       LINES = tgetnum("li");
+               i = LINES;
+               if ((COLUMNS = winsz.ws_col = win.ws_col) == 0)
+                       COLUMNS = tgetnum("co");
+       }
+       if (LINES <= 5)
+               LINES = 24;
+       if (LINES > TUBELINES)
+               LINES = TUBELINES;
+       l = LINES;
+       if (ospeed < B1200)
+               l = 9;  /* including the message line at the bottom */
+       else if (ospeed < B2400)
+               l = 17;
+       if (l > LINES)
+               l = LINES;
+       if (COLUMNS <= 4)
+               COLUMNS = 1000;
+       options[WINDOW].ovalue = options[WINDOW].odefault = l - 1;
+       if (defwind) options[WINDOW].ovalue = defwind;
+       options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2);
+       if (i <= 0)
+               LINES = 2;
+}
+
 zap()
 {
        register char *namp;
 zap()
 {
        register char *namp;