new version from arnold
authorJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 2 May 1985 08:05:13 +0000 (00:05 -0800)
committerJim Bloom <bloom@ucbvax.Berkeley.EDU>
Thu, 2 May 1985 08:05:13 +0000 (00:05 -0800)
SCCS-vsn: lib/libcurses/cr_put.c 1.5
SCCS-vsn: lib/libcurses/setterm.c 1.16
SCCS-vsn: lib/libcurses/curses.c 1.3
SCCS-vsn: lib/libcurses/delch.c 1.3
SCCS-vsn: lib/libcurses/deleteln.c 1.5
SCCS-vsn: lib/libcurses/delwin.c 1.6

usr/src/lib/libcurses/cr_put.c
usr/src/lib/libcurses/curses.c
usr/src/lib/libcurses/delch.c
usr/src/lib/libcurses/deleteln.c
usr/src/lib/libcurses/delwin.c
usr/src/lib/libcurses/setterm.c

index 7b4ccb1..cadb553 100644 (file)
@@ -11,7 +11,7 @@ int           plodput();
  * as formatting of lines (printing of control characters,
  * line numbering and the like).
  *
  * as formatting of lines (printing of control characters,
  * line numbering and the like).
  *
- * %G% (Berkeley) @(#)cr_put.c 1.5
+ * @(#)cr_put.c        1.5 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -38,16 +38,6 @@ int  ly, lx, y, x; {
        fgoto();
 }
 
        fgoto();
 }
 
-char
-_putchar(c)
-reg char       c; {
-
-       putchar(c);
-#ifdef DEBUG
-       fprintf(outf, "_PUTCHAR(%s)\n", unctrl(c));
-#endif
-}
-
 fgoto()
 {
        reg char        *cgp;
 fgoto()
 {
        reg char        *cgp;
@@ -65,11 +55,11 @@ fgoto()
                        while (l > 0) {
                                if (_pfast)
                                        if (CR)
                        while (l > 0) {
                                if (_pfast)
                                        if (CR)
-                                               tputs(CR, 0, _putchar);
+                                               _puts(CR);
                                        else
                                                _putchar('\r');
                                if (NL)
                                        else
                                                _putchar('\r');
                                if (NL)
-                                       tputs(NL, 0, _putchar);
+                                       _puts(NL);
                                else
                                        _putchar('\n');
                                l--;
                                else
                                        _putchar('\n');
                                l--;
@@ -111,7 +101,7 @@ fgoto()
                         * Superbee description which wins better.
                         */
                        if (NL /* && !XB */ && _pfast)
                         * Superbee description which wins better.
                         */
                        if (NL /* && !XB */ && _pfast)
-                               tputs(NL, 0, _putchar);
+                               _puts(NL);
                        else
                                _putchar('\n');
                        l--;
                        else
                                _putchar('\n');
                        l--;
@@ -268,10 +258,7 @@ plod(cnt)
                else
                        plodput('\r');
                if (NC) {
                else
                        plodput('\r');
                if (NC) {
-                       if (NL)
-                               tputs(NL, 0, plodput);
-                       else
-                               plodput('\n');
+                       put_nl();
                        outline++;
                }
                outcol = 0;
                        outline++;
                }
                outcol = 0;
@@ -279,10 +266,7 @@ plod(cnt)
 dontcr:
        while (outline < destline) {
                outline++;
 dontcr:
        while (outline < destline) {
                outline++;
-               if (NL && _pfast)
-                       tputs(NL, 0, plodput);
-               else
-                       plodput('\n');
+               put_nl();
                if (plodcnt < 0)
                        goto out;
                if (NONL || _pfast == 0)
                if (plodcnt < 0)
                        goto out;
                if (NONL || _pfast == 0)
@@ -351,7 +335,7 @@ dontcr:
                        else {
                                i = curscr->_y[outline][outcol];
                                if ((i&_STANDOUT) == (curscr->_flags&_STANDOUT))
                        else {
                                i = curscr->_y[outline][outcol];
                                if ((i&_STANDOUT) == (curscr->_flags&_STANDOUT))
-                                       putchar(i);
+                                       _putchar(i);
                                else
                                        goto nondes;
                        }
                                else
                                        goto nondes;
                        }
@@ -391,3 +375,20 @@ int col, ts;
                offset = 0;
        return col + ts - (col % ts) + offset;
 }
                offset = 0;
        return col + ts - (col % ts) + offset;
 }
+
+/*
+ * put out a newline appropriately, twice if necessary (uck)
+ */
+static
+put_nl()
+{
+       if (NL)
+               tputs(NL, 0, plodput);
+       else
+               plodput('\n');
+       if (AM && XN && outcol == COLS - 1)
+               if (NL)
+                       tputs(NL, 0, plodput);
+               else
+                       plodput('\n');
+}
index dd5601b..4a31784 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Define global variables
  *
 /*
  * Define global variables
  *
- * @(#)curses.c        1.2 (Berkeley) %G%
+ * @(#)curses.c        1.3 (Berkeley) %G%
  */
 # include      "curses.h"
 
  */
 # include      "curses.h"
 
@@ -27,9 +27,18 @@ FILE *outf;                  /* debug output file                    */
 
 SGTTY  _tty;                   /* tty modes                            */
 
 
 SGTTY  _tty;                   /* tty modes                            */
 
-bool   AM, BS, CA, DA, DB, EO, GT, HZ, IN, MI, MS, NC, OS, UL, XN,
-       NONL, UPPERCASE, normtty, _pfast;
+bool   AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL, XB, XN,
+       XT, XX;
+char   *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, *DM,
+       *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, *K7, *K8,
+       *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, *KR, *KS, *KU,
+       *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, *SO, *SR, *TA, *TE,
+       *TI, *UC, *UE, *UP, *US, *VB, *VS, *VE, *AL_PARM, *DL_PARM,
+       *UP_PARM, *DOWN_PARM, *LEFT_PARM, *RIGHT_PARM;
+char   PC;
 
 
-char   *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *DC, *DL, *DM, *DO,
-       *ED, *EI, *HO, *IC, *IM, *IP, *LL, *MA, *ND, *NL, *SE, *SF,
-       *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VE, *VS, PC;
+/*
+ * From the tty modes...
+ */
+
+bool   GT, NONL, UPPERCASE, normtty, _pfast;
index 3ae3e29..c633db6 100644 (file)
@@ -4,13 +4,14 @@
  *     This routine performs an insert-char on the line, leaving
  * (_cury,_curx) unchanged.
  *
  *     This routine performs an insert-char on the line, leaving
  * (_cury,_curx) unchanged.
  *
- * @(#)delch.c 1.2 (Berkeley) %G%
+ * @(#)delch.c 1.3 (Berkeley) %G%
  */
 wdelch(win)
 reg WINDOW     *win; {
 
        reg char        *temp1, *temp2;
        reg char        *end;
  */
 wdelch(win)
 reg WINDOW     *win; {
 
        reg char        *temp1, *temp2;
        reg char        *end;
+       reg int         lch;
 
        end = &win->_y[win->_cury][win->_maxx - 1];
        temp1 = &win->_y[win->_cury][win->_curx];
 
        end = &win->_y[win->_cury][win->_maxx - 1];
        temp1 = &win->_y[win->_cury][win->_curx];
@@ -18,9 +19,6 @@ reg WINDOW    *win; {
        while (temp1 < end)
                *temp1++ = *temp2++;
        *temp1 = ' ';
        while (temp1 < end)
                *temp1++ = *temp2++;
        *temp1 = ' ';
-       win->_lastch[win->_cury] = win->_maxx - 1;
-       if (win->_firstch[win->_cury] == _NOCHANGE ||
-           win->_firstch[win->_cury] > win->_curx)
-               win->_firstch[win->_cury] = win->_curx;
+       touchline(win, win->_cury, win->_curx, win->_maxx - 1);
        return OK;
 }
        return OK;
 }
index 95354d9..9ece3d9 100644 (file)
@@ -4,22 +4,35 @@
  *     This routine deletes a line from the screen.  It leaves
  * (_cury,_curx) unchanged.
  *
  *     This routine deletes a line from the screen.  It leaves
  * (_cury,_curx) unchanged.
  *
- * %G% (Berkeley) @(#)deleteln.c       1.4
+ * @(#)deleteln.c      1.5 (Berkeley) %G%
  */
 wdeleteln(win)
  */
 wdeleteln(win)
-reg WINDOW     *win; {
-
+reg WINDOW     *win;
+{
        reg char        *temp;
        reg int         y;
        reg char        *end;
        reg char        *temp;
        reg int         y;
        reg char        *end;
+       reg int         x;
 
 
+# ifdef DEBUG
+       fprintf(outf, "DELETELN(%0.2o)\n", win);
+# endif
        temp = win->_y[win->_cury];
        for (y = win->_cury; y < win->_maxy - 1; y++) {
        temp = win->_y[win->_cury];
        for (y = win->_cury; y < win->_maxy - 1; y++) {
-               win->_y[y] = win->_y[y+1];
-               win->_firstch[y] = 0;
-               win->_lastch[y] = win->_maxx - 1;
+               if (win->_orig == NULL)
+                       win->_y[y] = win->_y[y + 1];
+               else
+                       bcopy(win->_y[y + 1], win->_y[y], win->_maxx);
+               touchline(win, y, 0, win->_maxx - 1);
        }
        }
+       if (win->_orig == NULL)
+               win->_y[y] = temp;
+       else
+               temp = win->_y[y];
        for (end = &temp[win->_maxx]; temp < end; )
                *temp++ = ' ';
        for (end = &temp[win->_maxx]; temp < end; )
                *temp++ = ' ';
-       win->_y[win->_maxy-1] = temp - win->_maxx;
+       touchline(win, win->_cury, 0, win->_maxx - 1);
+       if (win->_orig == NULL)
+               _id_subwins(win);
+       return OK;
 }
 }
index 97af8b7..9d75701 100644 (file)
@@ -3,7 +3,7 @@
 /*
  *     This routine deletes a window and releases it back to the system.
  *
 /*
  *     This routine deletes a window and releases it back to the system.
  *
- * %G% (Berkeley) @(#)delwin.c 1.5
+ * @(#)delwin.c        1.6 (Berkeley) %G%
  */
 delwin(win)
 reg WINDOW     *win; {
  */
 delwin(win)
 reg WINDOW     *win; {
@@ -17,7 +17,9 @@ reg WINDOW    *win; {
                 * all the subwindows, and the array of space as well.
                 */
                for (i = 0; i < win->_maxy && win->_y[i]; i++)
                 * all the subwindows, and the array of space as well.
                 */
                for (i = 0; i < win->_maxy && win->_y[i]; i++)
-                       cfree(win->_y[i]);
+                       free(win->_y[i]);
+               free(win->_firstch);
+               free(win->_lastch);
                wp = win->_nextp;
                while (wp != win) {
                        np = wp->_nextp;
                wp = win->_nextp;
                while (wp != win) {
                        np = wp->_nextp;
@@ -27,7 +29,7 @@ reg WINDOW    *win; {
        }
        else {
                /*
        }
        else {
                /*
-                * If we are a subwindow, take ourself out of the
+                * If we are a subwindow, take ourselves out of the
                 * list.  NOTE: if we are a subwindow, the minimum list
                 * is orig followed by this subwindow, so there are
                 * always at least two windows in the list.
                 * list.  NOTE: if we are a subwindow, the minimum list
                 * is orig followed by this subwindow, so there are
                 * always at least two windows in the list.
@@ -36,8 +38,6 @@ reg WINDOW    *win; {
                        continue;
                wp->_nextp = win->_nextp;
        }
                        continue;
                wp->_nextp = win->_nextp;
        }
-       cfree(win->_y);
-       cfree(win->_firstch);
-       cfree(win->_lastch);
-       cfree(win);
+       free(win->_y);
+       free(win);
 }
 }
index cf8f682..446ec71 100644 (file)
@@ -1,27 +1,32 @@
 /*
  * Terminal initialization routines.
  *
 /*
  * Terminal initialization routines.
  *
- * %G% (Berkeley) @(#)setterm.c        1.15
+ * @(#)setterm.c       1.16 (Berkeley) %G%
  */
 
 # include      "curses.ext"
 
  */
 
 # include      "curses.ext"
 
-static bool    *sflags[]       = {
-                       &AM, &BS, &EO, &HZ, &IN, &MI, &MS, &NC, &OS, &UL, &XN
+static bool    *sflags[] = {
+                       &AM, &BS, &DA, &DB, &EO, &HC, &HZ, &IN, &MI,
+                       &MS, &NC, &NS, &OS, &UL, &XB, &XN, &XT, &XX
                };
 
                };
 
-static char    *xPC,
-               **sstrs[]       = {
-                       &AL, &BC, &BT, &CD,  &CE, &CL, &CM, &CR, &DC,
-                       &DL, &DM, &DO, &ED,  &EI, &HO, &IC, &IM, &IP,
-                       &LL, &MA, &ND, &NL, &xPC, &SE, &SF, &SO, &SR,
-                       &TA, &TE, &TI, &UC,  &UE, &UP, &US, &VB, &VS,
-                       &VE
+static char    *_PC,
+               **sstrs[] = {
+                       &AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
+                       &DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
+                       &K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
+                       &IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
+                       &LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
+                       &SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
+                       &VB, &VS, &VE, &AL_PARM, &DL_PARM, &UP_PARM,
+                       &DOWN_PARM, &LEFT_PARM, &RIGHT_PARM,
                },
                *tgoto();
 
                },
                *tgoto();
 
-static char    tspace[256],            /* Space for capability strings */
-               *aoftspace;             /* Address of tspace for relocation */
+char           _tspace[2048];          /* Space for capability strings */
+
+static char    *aoftspace;             /* Address of _tspace for relocation */
 
 static int     destcol, destline;
 
 
 static int     destcol, destline;
 
@@ -59,7 +64,9 @@ reg char      *type; {
 
        reg int         unknown;
        static char     genbuf[1024];
 
        reg int         unknown;
        static char     genbuf[1024];
+# ifdef TIOCGWINSZ
        struct winsize win;
        struct winsize win;
+# endif
 
 # ifdef DEBUG
        fprintf(outf, "SETTERM(\"%s\")\n", type);
 
 # ifdef DEBUG
        fprintf(outf, "SETTERM(\"%s\")\n", type);
@@ -75,12 +82,14 @@ reg char    *type; {
 # ifdef DEBUG
        fprintf(outf, "SETTERM: tty = %s\n", type);
 # endif
 # ifdef DEBUG
        fprintf(outf, "SETTERM: tty = %s\n", type);
 # endif
+# ifdef TIOCGWINSZ
        if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) {
                if (LINES == 0)
                        LINES = win.ws_row;
                if (COLS == 0)
                        COLS = win.ws_col;
        }
        if (ioctl(_tty_ch, TIOCGWINSZ, &win) >= 0) {
                if (LINES == 0)
                        LINES = win.ws_row;
                if (COLS == 0)
                        COLS = win.ws_col;
        }
+# endif
 
        if (LINES == 0)
                LINES = tgetnum("li");
 
        if (LINES == 0)
                LINES = tgetnum("li");
@@ -95,57 +104,67 @@ reg char   *type; {
 # ifdef DEBUG
        fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
 # endif
 # ifdef DEBUG
        fprintf(outf, "SETTERM: LINES = %d, COLS = %d\n", LINES, COLS);
 # endif
-       aoftspace = tspace;
+       aoftspace = _tspace;
        zap();                  /* get terminal description             */
        zap();                  /* get terminal description             */
+
+       /*
+        * Handle funny termcap capabilities
+        */
+       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 (!GT) BT=NULL;       /* If we can't tab, we can't backtab either */
+
        if (tgoto(CM, destcol, destline)[0] == 'O')
                CA = FALSE, CM = 0;
        else
                CA = TRUE;
        if (tgoto(CM, destcol, destline)[0] == 'O')
                CA = FALSE, CM = 0;
        else
                CA = TRUE;
-       PC = xPC ? xPC[0] : FALSE;
-       aoftspace = tspace;
+
+       PC = _PC ? _PC[0] : FALSE;
+       aoftspace = _tspace;
        strcpy(ttytype, longname(genbuf, type));
        if (unknown)
                return ERR;
        return OK;
 }
        strcpy(ttytype, longname(genbuf, type));
        if (unknown)
                return ERR;
        return OK;
 }
+
 /*
  *     This routine gets all the terminal flags from the termcap database
  */
 /*
  *     This routine gets all the terminal flags from the termcap database
  */
-zap() {
 
 
-       reg bool        **fp;
-       reg char        *namp, ***sp;
+zap()
+{
+       register char   *namp;
+       register bool   **fp;
+       register char   ***sp;
+#ifdef DEBUG
+       register char   *cp;
+#endif
        extern char     *tgetstr();
 
        extern char     *tgetstr();
 
-       /*
-        * get boolean flags
-        */
-       namp = "ambseohzinmimsncosulxn\0\0";
-# ifdef FULLDEBUG
-       fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
-# endif
+       namp = "ambsdadbeohchzinmimsncnsosulxbxnxtxx";
        fp = sflags;
        do {
                *(*fp++) = tgetflag(namp);
        fp = sflags;
        do {
                *(*fp++) = tgetflag(namp);
-# ifdef FULLDEBUG
-               fprintf(outf, "ZAP: %.2s = %d", namp, *(*(fp - 1)));
-# endif
+#ifdef DEBUG
+               fprintf(outf, "%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
+#endif
                namp += 2;
        } while (*namp);
                namp += 2;
        } while (*namp);
-
-       /*
-        * get string values
-        */
-       namp = "albcbtcdceclcmcrdcdldmdoedeihoicimipllmandnlpcsesfsosrtatetiucueupusvbvsve";
-# ifdef FULLDEBUG
-       fprintf(outf, "ZAP: namp = \"%s\"\n", namp);
-# endif
+       namp = "albcbtcdceclcmcrcsdcdldmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscsesfsosrtatetiucueupusvbvsveALDLUPDOLERI";
        sp = sstrs;
        do {
                *(*sp++) = tgetstr(namp, &aoftspace);
        sp = sstrs;
        do {
                *(*sp++) = tgetstr(namp, &aoftspace);
-# ifdef FULLDEBUG
-               fprintf(outf, "ZAP: %.2s = \"%s\"\n", namp, *(*(sp-1)));
-# endif
+#ifdef DEBUG
+               fprintf(outf, "%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
+               if (*sp[-1] != NULL) {
+                       for (cp = *sp[-1]; *cp; cp++)
+                               fprintf(outf, "%s", unctrl(*cp));
+                       fprintf(outf, "\"\n");
+               }
+#endif
                namp += 2;
        } while (*namp);
        if (tgetnum("sg") > 0)
                namp += 2;
        } while (*namp);
        if (tgetnum("sg") > 0)