]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_termcap.c
ncurses 5.7 - patch 20090606
[ncurses.git] / ncurses / tinfo / lib_termcap.c
index 4c0097db5a3358cc94b9066d9b061403673bb2dc..af4d8f84bb83c95b5ace405a733c00b0999c4460 100644 (file)
@@ -30,6 +30,7 @@
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
  *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                                                 *
  *                                                                          *
  * some of the code in here was contributed by:                             *
  * Magnus Bengtsson, d6mbeng@dtek.chalmers.se (Nov'93)                      *
 #include <term_entry.h>
 
 #ifndef CUR
-#define CUR SP_TERMTYPE 
+#define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_termcap.c,v 1.65 2009/05/10 00:48:29 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.67 2009/05/30 20:05:20 tom Exp $")
 
 NCURSES_EXPORT_VAR(char *) UP = 0;
 NCURSES_EXPORT_VAR(char *) BC = 0;
@@ -80,19 +81,28 @@ NCURSES_EXPORT_VAR(char *) BC = 0;
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetent(char *bufp, const char *name)
+NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
 {
-#if NCURSES_SP_FUNCS
-    SCREEN *sp = CURRENT_SCREEN;
-#endif
-    int errcode;
+    int errcode = ERR;
     int n;
     bool found_cache = FALSE;
+#ifdef USE_TERM_DRIVER
+    TERMINAL *termp = 0;
+#endif
 
     START_TRACE();
     T((T_CALLED("tgetent()")));
 
+#ifdef USE_TERM_DRIVER
+    _nc_setupterm_ex(&termp, (NCURSES_CONST char *) name,
+                    STDOUT_FILENO, &errcode, TRUE);
+
+    if (termp == 0 ||
+       !((TERMINAL_CONTROL_BLOCK *) termp)->drv->isTerminfo)
+       return (errcode);
+#else
     _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE);
+#endif
 
     /*
      * In general we cannot tell if the fixed sgr0 is still used by the
@@ -116,9 +126,9 @@ tgetent(char *bufp, const char *name)
            /*
             * Also free the terminfo data that we loaded (much bigger leak).
             */
-           if (LAST_TRM != 0 && LAST_TRM != cur_term) {
+           if (LAST_TRM != 0 && LAST_TRM != TerminalOf(SP_PARM)) {
                TERMINAL *trm = LAST_TRM;
-               del_curterm(LAST_TRM);
+               NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx LAST_TRM);
                for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
                    if (LAST_TRM == trm)
                        LAST_TRM = 0;
@@ -138,7 +148,7 @@ tgetent(char *bufp, const char *name)
        }
        CacheInx = best;
     }
-    LAST_TRM = cur_term;
+    LAST_TRM = TerminalOf(SP_PARM);
     LAST_SEQ = ++CacheSeq;
 
     PC = 0;
@@ -160,7 +170,7 @@ tgetent(char *bufp, const char *name)
        if (backspace_if_not_bs != NULL)
            BC = backspace_if_not_bs;
 
-       if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) {
+       if ((FIX_SGR0 = _nc_trim_sgr0(&(TerminalOf(SP_PARM)->type))) != 0) {
            if (!strcmp(FIX_SGR0, exit_attribute_mode)) {
                if (FIX_SGR0 != exit_attribute_mode) {
                    free(FIX_SGR0);
@@ -171,8 +181,8 @@ tgetent(char *bufp, const char *name)
        LAST_BUF = bufp;
        LAST_USE = TRUE;
 
-       SetNoPadding(SP);
-       (void) baudrate();      /* sets ospeed as a side-effect */
+       SetNoPadding(SP_PARM);
+       (void) NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG);      /* sets ospeed as a side-effect */
 
 /* LINT_PREPRO
 #if 0*/
@@ -184,6 +194,14 @@ tgetent(char *bufp, const char *name)
     returnCode(errcode);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetent(char *bufp, const char *name)
+{
+    return NCURSES_SP_NAME(tgetent) (CURRENT_SCREEN, bufp, name);
+}
+#endif
+
 /***************************************************************************
  *
  * tgetflag(str)
@@ -194,13 +212,13 @@ tgetent(char *bufp, const char *name)
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetflag(NCURSES_CONST char *id)
+NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
     unsigned i;
 
-    T((T_CALLED("tgetflag(%s)"), id));
-    if (cur_term != 0) {
-       TERMTYPE *tp = &(cur_term->type);
+    T((T_CALLED("tgetflag(%p, %s)"), SP_PARM, id));
+    if (HasTInfoTerminal(SP_PARM)) {
+       TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
        for_each_boolean(i, tp) {
            const char *capname = ExtBoolname(tp, i, boolcodes);
            if (!strncmp(id, capname, 2)) {
@@ -212,6 +230,14 @@ tgetflag(NCURSES_CONST char *id)
     returnCode(0);             /* Solaris does this */
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetflag(NCURSES_CONST char *id)
+{
+    return NCURSES_SP_NAME(tgetflag) (CURRENT_SCREEN, id);
+}
+#endif
+
 /***************************************************************************
  *
  * tgetnum(str)
@@ -222,13 +248,13 @@ tgetflag(NCURSES_CONST char *id)
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetnum(NCURSES_CONST char *id)
+NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
     unsigned i;
 
-    T((T_CALLED("tgetnum(%s)"), id));
-    if (cur_term != 0) {
-       TERMTYPE *tp = &(cur_term->type);
+    T((T_CALLED("tgetnum(%p, %s)"), SP_PARM, id));
+    if (HasTInfoTerminal(SP_PARM)) {
+       TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
        for_each_number(i, tp) {
            const char *capname = ExtNumname(tp, i, numcodes);
            if (!strncmp(id, capname, 2)) {
@@ -241,6 +267,14 @@ tgetnum(NCURSES_CONST char *id)
     returnCode(ABSENT_NUMERIC);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
+tgetnum(NCURSES_CONST char *id)
+{
+    return NCURSES_SP_NAME(tgetnum) (CURRENT_SCREEN, id);
+}
+#endif
+
 /***************************************************************************
  *
  * tgetstr(str, area)
@@ -251,17 +285,14 @@ tgetnum(NCURSES_CONST char *id)
  ***************************************************************************/
 
 NCURSES_EXPORT(char *)
-tgetstr(NCURSES_CONST char *id, char **area)
+NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area)
 {
-#if NCURSES_SP_FUNCS
-    SCREEN *sp = CURRENT_SCREEN;
-#endif
     unsigned i;
     char *result = NULL;
 
     T((T_CALLED("tgetstr(%s,%p)"), id, area));
-    if (cur_term != 0) {
-       TERMTYPE *tp = &(cur_term->type);
+    if (HasTInfoTerminal(SP_PARM)) {
+       TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
        for_each_string(i, tp) {
            const char *capname = ExtStrname(tp, i, strcodes);
            if (!strncmp(id, capname, 2)) {
@@ -288,6 +319,14 @@ tgetstr(NCURSES_CONST char *id, char **area)
     returnPtr(result);
 }
 
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(char *)
+tgetstr(NCURSES_CONST char *id, char **area)
+{
+    return NCURSES_SP_NAME(tgetstr) (CURRENT_SCREEN, id, area);
+}
+#endif
+
 #if NO_LEAKS
 NCURSES_EXPORT(void)
 _nc_tgetent_leaks(void)