Update to ncurses-6.0

Change-Id: I98ab2ea8a5e13cca9f8b7cf6277b9b14a4da4299
diff --git a/ncurses/tinfo/lib_ti.c b/ncurses/tinfo/lib_ti.c
index df460f9..e9ae746 100644
--- a/ncurses/tinfo/lib_ti.c
+++ b/ncurses/tinfo/lib_ti.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2000,2003 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2013 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            *
@@ -29,75 +29,159 @@
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
  ****************************************************************************/
 
 #include <curses.priv.h>
 
-#include <term_entry.h>
 #include <tic.h>
 
-MODULE_ID("$Id: lib_ti.c,v 1.23 2003/05/24 21:10:28 tom Exp $")
+MODULE_ID("$Id: lib_ti.c,v 1.30 2013/06/08 16:55:05 tom Exp $")
 
+#if 0
+static bool
+same_name(const char *a, const char *b)
+{
+    fprintf(stderr, "compare(%s,%s)\n", a, b);
+    return !strcmp(a, b);
+}
+#else
+#define same_name(a,b) !strcmp(a,b)
+#endif
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    int result = ABSENT_BOOLEAN;
+    int j = -1;
+
+    T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, BOOLEAN, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_boolean(i, tp) {
+		const char *capname = ExtBoolname(tp, i, boolnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
+	    }
+	}
+#endif
+	if (j >= 0) {
+	    /* note: setupterm forces invalid booleans to false */
+	    result = tp->Booleans[j];
+	}
+    }
+
+    returnCode(result);
+}
+
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 tigetflag(NCURSES_CONST char *str)
 {
-    unsigned i;
+    return NCURSES_SP_NAME(tigetflag) (CURRENT_SCREEN, str);
+}
+#endif
 
-    T((T_CALLED("tigetflag(%s)"), str));
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    int j = -1;
+    int result = CANCELLED_NUMERIC;	/* Solaris returns a -1 on error */
 
-    if (cur_term != 0) {
-	TERMTYPE *tp = &(cur_term->type);
-	for_each_boolean(i, tp) {
-	    const char *capname = ExtBoolname(tp, i, boolnames);
-	    if (!strcmp(str, capname)) {
-		/* setupterm forces invalid booleans to false */
-		returnCode(tp->Booleans[i]);
+    T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, NUMBER, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_number(i, tp) {
+		const char *capname = ExtNumname(tp, i, numnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    if (VALID_NUMERIC(tp->Numbers[j]))
+		result = tp->Numbers[j];
+	    else
+		result = ABSENT_NUMERIC;
+	}
     }
 
-    returnCode(ABSENT_BOOLEAN);
+    returnCode(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(int)
 tigetnum(NCURSES_CONST char *str)
 {
-    unsigned i;
+    return NCURSES_SP_NAME(tigetnum) (CURRENT_SCREEN, str);
+}
+#endif
 
-    T((T_CALLED("tigetnum(%s)"), str));
+NCURSES_EXPORT(char *)
+NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
+{
+    char *result = CANCELLED_STRING;
+    int j = -1;
 
-    if (cur_term != 0) {
-	TERMTYPE *tp = &(cur_term->type);
-	for_each_number(i, tp) {
-	    const char *capname = ExtNumname(tp, i, numnames);
-	    if (!strcmp(str, capname)) {
-		if (!VALID_NUMERIC(tp->Numbers[i]))
-		    returnCode(ABSENT_NUMERIC);
-		returnCode(tp->Numbers[i]);
+    T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
+
+    if (HasTInfoTerminal(SP_PARM)) {
+	TERMTYPE *tp = &(TerminalOf(SP_PARM)->type);
+	struct name_table_entry const *entry_ptr;
+
+	entry_ptr = _nc_find_type_entry(str, STRING, FALSE);
+	if (entry_ptr != 0) {
+	    j = entry_ptr->nte_index;
+	}
+#if NCURSES_XNAMES
+	else {
+	    int i;
+	    for_each_ext_string(i, tp) {
+		const char *capname = ExtStrname(tp, i, strnames);
+		if (same_name(str, capname)) {
+		    j = i;
+		    break;
+		}
 	    }
 	}
+#endif
+	if (j >= 0) {
+	    /* note: setupterm forces cancelled strings to null */
+	    result = tp->Strings[j];
+	}
     }
 
-    returnCode(CANCELLED_NUMERIC);	/* Solaris returns a -1 instead */
+    returnPtr(result);
 }
 
+#if NCURSES_SP_FUNCS
 NCURSES_EXPORT(char *)
 tigetstr(NCURSES_CONST char *str)
 {
-    unsigned i;
-
-    T((T_CALLED("tigetstr(%s)"), str));
-
-    if (cur_term != 0) {
-	TERMTYPE *tp = &(cur_term->type);
-	for_each_string(i, tp) {
-	    const char *capname = ExtStrname(tp, i, strnames);
-	    if (!strcmp(str, capname)) {
-		/* setupterm forces cancelled strings to null */
-		returnPtr(tp->Strings[i]);
-	    }
-	}
-    }
-
-    returnPtr(CANCELLED_STRING);
+    return NCURSES_SP_NAME(tigetstr) (CURRENT_SCREEN, str);
 }
+#endif