]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_termcap.c
ncurses 5.0
[ncurses.git] / ncurses / tinfo / lib_termcap.c
similarity index 68%
rename from ncurses/lib_termcap.c
rename to ncurses/tinfo/lib_termcap.c
index d8dcf3e9193c415f0060d0b6ec79cb771bea401c..8238b368eea3e581a2e6b23bda576ea9434e8005 100644 (file)
 #include <tic.h>
 
 #define __INTERNAL_CAPS_VISIBLE
-#include <term.h>
+#include <term_entry.h>
 
-MODULE_ID("$Id: lib_termcap.c,v 1.17 1998/02/11 12:13:54 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.29 1999/09/05 01:06:43 tom Exp $")
 
 /*
    some of the code in here was contributed by:
    Magnus Bengtsson, d6mbeng@dtek.chalmers.se
 */
 
-char PC;
 char *UP;
 char *BC;
-short ospeed;
 
 /***************************************************************************
  *
@@ -69,86 +67,26 @@ short ospeed;
 int tgetent(char *bufp GCC_UNUSED, const char *name)
 {
 int errcode;
-#if defined(TERMIOS)
-speed_t speed;
-#endif
-
-       T(("calling tgetent"));
-       setupterm(name, STDOUT_FILENO, &errcode);
-
-       if (errcode != 1)
-               return(errcode);
-
-       if (cursor_left)
-           if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
-               backspace_if_not_bs = cursor_left;
-
-       /* we're required to export these */
-       if (pad_char != NULL)
-               PC = pad_char[0];
-       if (cursor_up != NULL)
-               UP = cursor_up;
-       if (backspace_if_not_bs != NULL)
-               BC = backspace_if_not_bs;
-#if defined(TERMIOS)
-       /*
-        * Back-convert to the funny speed encoding used by the old BSD
-        * curses library.  Method suggested by Andrey Chernov
-        * <ache@astral.msk.su>
-        */
-       if ((speed = cfgetospeed(&cur_term->Nttyb)) < 1)
-           ospeed = 1;         /* assume lowest non-hangup speed */
-       else
-       {
-               const speed_t *sp;
-               static const speed_t speeds[] = {
-#ifdef B115200
-                       B115200,
-#endif
-#ifdef B57600
-                       B57600,
-#endif
-#ifdef B38400
-                       B38400,
-#else
-#ifdef EXTB
-                       EXTB,
-#endif
-#endif /* B38400 */
-#ifdef B19200
-                       B19200,
-#else
-#ifdef EXTA
-                       EXTA,
-#endif
-#endif /* B19200 */
-                       B9600,
-                       B4800,
-                       B2400,
-                       B1800,
-                       B1200,
-                       B600,
-                       B300,
-                       B200,
-                       B150,
-                       B134,
-                       B110,
-                       B75,
-                       B50,
-                       B0,
-               };
-#define MAXSPEED       SIZEOF(speeds)
-
-               for (sp = speeds; sp < speeds + MAXSPEED; sp++) {
-                       if (sp[0] <= speed) {
-                               break;
-                       }
-               }
-               ospeed = MAXSPEED - (sp - speeds);
-       }
-#else
-       ospeed = cur_term->Nttyb.sg_ospeed;
-#endif
+
+       T((T_CALLED("tgetent()")));
+
+       setupterm((NCURSES_CONST char *)name, STDOUT_FILENO, &errcode);
+
+       if (errcode == 1) {
+
+               if (cursor_left)
+                   if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
+                       backspace_if_not_bs = cursor_left;
+
+               /* we're required to export these */
+               if (pad_char != NULL)
+                       PC = pad_char[0];
+               if (cursor_up != NULL)
+                       UP = cursor_up;
+               if (backspace_if_not_bs != NULL)
+                       BC = backspace_if_not_bs;
+
+               (void) baudrate();      /* sets ospeed as a side-effect */
 
 /* LINT_PREPRO
 #if 0*/
@@ -156,7 +94,8 @@ speed_t speed;
 /* LINT_PREPRO
 #endif*/
 
-       return errcode;
+       }
+       returnCode(errcode);
 }
 
 /***************************************************************************
@@ -168,17 +107,22 @@ speed_t speed;
  *
  ***************************************************************************/
 
-int tgetflag(const char *id)
+int tgetflag(NCURSES_CONST char *id)
 {
 int i;
 
-       T(("tgetflag: %s", id));
+       T((T_CALLED("tgetflag(%s)"), id));
        if (cur_term != 0) {
-               for (i = 0; i < BOOLCOUNT; i++)
-                       if (!strcmp(id, boolcodes[i]))
-                               return cur_term->type.Booleans[i];
+           TERMTYPE *tp = &(cur_term->type);
+           for_each_boolean(i, tp) {
+               const char *capname = ExtBoolname(tp, i, boolcodes);
+               if (!strncmp(id, capname, 2)) {
+                   /* setupterm forces invalid booleans to false */
+                   returnCode(tp->Booleans[i]);
+               }
+           }
        }
-       return ERR;
+       returnCode(0);  /* Solaris does this */
 }
 
 /***************************************************************************
@@ -190,17 +134,23 @@ int i;
  *
  ***************************************************************************/
 
-int tgetnum(const char *id)
+int tgetnum(NCURSES_CONST char *id)
 {
 int i;
 
-       T(("tgetnum: %s", id));
+       T((T_CALLED("tgetnum(%s)"), id));
        if (cur_term != 0) {
-               for (i = 0; i < NUMCOUNT; i++)
-                       if (!strcmp(id, numcodes[i]))
-                               return cur_term->type.Numbers[i];
+           TERMTYPE *tp = &(cur_term->type);
+           for_each_number(i, tp) {
+               const char *capname = ExtNumname(tp, i, numcodes);
+               if (!strncmp(id, capname, 2)) {
+                   if (!VALID_NUMERIC(tp->Numbers[i]))
+                       return -1;
+                   returnCode(tp->Numbers[i]);
+               }
+           }
        }
-       return ERR;
+       returnCode(ERR);
 }
 
 /***************************************************************************
@@ -212,21 +162,30 @@ int i;
  *
  ***************************************************************************/
 
-char *tgetstr(const char *id, char **area GCC_UNUSED)
+char *tgetstr(NCURSES_CONST char *id, char **area)
 {
 int i;
 
-       T(("tgetstr: %s", id));
+       T((T_CALLED("tgetstr(%s,%p)"), id, area));
        if (cur_term != 0) {
-               for (i = 0; i < STRCOUNT; i++) {
-                       T(("trying %s", strcodes[i]));
-                       if (!strcmp(id, strcodes[i])) {
-                               T(("found match : %s", cur_term->type.Strings[i]));
-                               return cur_term->type.Strings[i];
-                       }
+           TERMTYPE *tp = &(cur_term->type);
+           for_each_string(i, tp) {
+               const char *capname = ExtStrname(tp, i, strcodes);
+               T(("trying %s", capname));
+               if (!strncmp(id, capname, 2)) {
+                   T(("found match : %s", _nc_visbuf(tp->Strings[i])));
+                   /* setupterm forces cancelled strings to null */
+                   if (area != 0
+                    && *area != 0
+                    && VALID_STRING(tp->Strings[i])) {
+                       (void) strcpy(*area, tp->Strings[i]);
+                       *area += strlen(*area) + 1;
+                   }
+                   returnPtr(tp->Strings[i]);
                }
+           }
        }
-       return NULL;
+       returnPtr(NULL);
 }
 
 /*
@@ -240,5 +199,6 @@ int i;
 
 char *tgoto(const char *string, int x, int y)
 {
-       return(tparm(string, y, x));
+       T((T_CALLED("tgoto(%s,%d,%d)"), string, x, y));
+       returnPtr(tparm((NCURSES_CONST char *)string, y, x));
 }