]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_termcap.c
ncurses 5.7 - patch 20090523
[ncurses.git] / ncurses / tinfo / lib_termcap.c
index 111fecd0689d0d5e0f168407251413d864a08f16..fbaacb425364d9573d052e4909a1917e51039401 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -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>
 
-MODULE_ID("$Id: lib_termcap.c,v 1.59 2007/01/28 00:33:11 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_termcap.c,v 1.66 2009/05/23 23:47:34 tom Exp $")
 
 NCURSES_EXPORT_VAR(char *) UP = 0;
 NCURSES_EXPORT_VAR(char *) BC = 0;
 
-typedef struct {
-    long sequence;
-    bool last_used;
-    char *fix_sgr0;            /* this holds the filtered sgr0 string */
-    char *last_bufp;           /* help with fix_sgr0 leak */
-    TERMINAL *last_term;
-} CACHE;
+#define MyCache  _nc_globals.tgetent_cache
+#define CacheInx _nc_globals.tgetent_index
+#define CacheSeq _nc_globals.tgetent_sequence
 
-#define MAX_CACHE 4
-static CACHE cache[MAX_CACHE];
-static int in_cache = 0;
-
-#define FIX_SGR0 cache[in_cache].fix_sgr0
-#define LAST_TRM cache[in_cache].last_term
-#define LAST_BUF cache[in_cache].last_bufp
-#define LAST_USE cache[in_cache].last_used
-#define LAST_SEQ cache[in_cache].sequence
+#define FIX_SGR0 MyCache[CacheInx].fix_sgr0
+#define LAST_TRM MyCache[CacheInx].last_term
+#define LAST_BUF MyCache[CacheInx].last_bufp
+#define LAST_USE MyCache[CacheInx].last_used
+#define LAST_SEQ MyCache[CacheInx].sequence
 
 /***************************************************************************
  *
@@ -84,10 +81,8 @@ static int in_cache = 0;
  ***************************************************************************/
 
 NCURSES_EXPORT(int)
-tgetent(char *bufp, const char *name)
+NCURSES_SP_NAME(tgetent) (NCURSES_SP_DCLx char *bufp, const char *name)
 {
-    static long sequence;
-
     int errcode;
     int n;
     bool found_cache = FALSE;
@@ -109,10 +104,10 @@ tgetent(char *bufp, const char *name)
      * caller-supplied buffers, can have multiple terminal descriptions in
      * use at a given time.
      */
-    for (n = 0; n < MAX_CACHE; ++n) {
-       bool same_result = (cache[n].last_used && cache[n].last_bufp == bufp);
+    for (n = 0; n < TGETENT_MAX; ++n) {
+       bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp);
        if (same_result) {
-           in_cache = n;
+           CacheInx = n;
            if (FIX_SGR0 != 0) {
                FreeAndNull(FIX_SGR0);
            }
@@ -121,11 +116,11 @@ tgetent(char *bufp, const char *name)
             */
            if (LAST_TRM != 0 && LAST_TRM != cur_term) {
                TERMINAL *trm = LAST_TRM;
-               del_curterm(LAST_TRM);
-               for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache)
+               NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx LAST_TRM);
+               for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx)
                    if (LAST_TRM == trm)
                        LAST_TRM = 0;
-               in_cache = n;
+               CacheInx = n;
            }
            found_cache = TRUE;
            break;
@@ -134,15 +129,15 @@ tgetent(char *bufp, const char *name)
     if (!found_cache) {
        int best = 0;
 
-       for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) {
-           if (LAST_SEQ < cache[best].sequence) {
-               best = in_cache;
+       for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
+           if (LAST_SEQ < MyCache[best].sequence) {
+               best = CacheInx;
            }
        }
-       in_cache = best;
+       CacheInx = best;
     }
     LAST_TRM = cur_term;
-    LAST_SEQ = ++sequence;
+    LAST_SEQ = ++CacheSeq;
 
     PC = 0;
     UP = 0;
@@ -152,7 +147,7 @@ tgetent(char *bufp, const char *name)
     if (errcode == 1) {
 
        if (cursor_left)
-           if ((backspaces_with_bs = !strcmp(cursor_left, "\b")) == 0)
+           if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0)
                backspace_if_not_bs = cursor_left;
 
        /* we're required to export these */
@@ -174,7 +169,8 @@ tgetent(char *bufp, const char *name)
        LAST_BUF = bufp;
        LAST_USE = TRUE;
 
-       (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*/
@@ -186,6 +182,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)
@@ -196,7 +200,7 @@ 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;
 
@@ -214,6 +218,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)
@@ -224,7 +236,7 @@ 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;
 
@@ -243,6 +255,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)
@@ -253,7 +273,7 @@ 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)
 {
     unsigned i;
     char *result = NULL;
@@ -287,13 +307,22 @@ 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)
 {
-    for (in_cache = 0; in_cache < MAX_CACHE; ++in_cache) {
+    for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) {
        FreeIfNeeded(FIX_SGR0);
-       del_curterm(LAST_TRM);
+       if (LAST_TRM != 0)
+           del_curterm(LAST_TRM);
     }
 }
 #endif