]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_tparm.c
ncurses 6.2 - patch 20210213
[ncurses.git] / ncurses / tinfo / lib_tparm.c
index 00380151f835e1b129c06c08e7aa2e986d4e7246..b8104eabcd5e57cdf28d930ccbf6947ed6909085 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey                                *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
  * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
@@ -53,7 +53,7 @@
 #include <ctype.h>
 #include <tic.h>
 
-MODULE_ID("$Id: lib_tparm.c,v 1.126 2020/05/31 00:02:03 tom Exp $")
+MODULE_ID("$Id: lib_tparm.c,v 1.129 2021/02/14 00:09:49 tom Exp $")
 
 /*
  *     char *
@@ -135,8 +135,8 @@ typedef struct {
 } TPARM_DATA;
 
 #if HAVE_TSEARCH
-static void *cached_tparm;
-static int count_tparm;
+#define MyCache _nc_globals.cached_tparm
+#define MyCount _nc_globals.count_tparm
 #if NO_LEAKS
 static int which_tparm;
 static TPARM_DATA **delete_tparm;
@@ -172,20 +172,20 @@ NCURSES_EXPORT(void)
 _nc_free_tparm(void)
 {
 #if HAVE_TSEARCH
-    if (count_tparm != 0) {
-       delete_tparm = typeMalloc(TPARM_DATA *, count_tparm);
+    if (MyCount != 0) {
+       delete_tparm = typeMalloc(TPARM_DATA *, MyCount);
        which_tparm = 0;
-       twalk(cached_tparm, visit_nodes);
-       for (which_tparm = 0; which_tparm < count_tparm; ++which_tparm) {
+       twalk(MyCache, visit_nodes);
+       for (which_tparm = 0; which_tparm < MyCount; ++which_tparm) {
            TPARM_DATA *ptr = delete_tparm[which_tparm];
-           tdelete(ptr, &cached_tparm, cmp_format);
+           tdelete(ptr, &MyCache, cmp_format);
            free((char *) ptr->format);
            free(ptr);
        }
        which_tparm = 0;
-       twalk(cached_tparm, visit_nodes);
+       twalk(MyCache, visit_nodes);
        FreeAndNull(delete_tparm);
-       count_tparm = 0;
+       MyCount = 0;
        which_tparm = 0;
     }
 #endif
@@ -405,7 +405,7 @@ parse_format(const char *s, char *format, int *len)
  * may be cases that we cannot see the explicit parameter numbers.
  */
 NCURSES_EXPORT(int)
-_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount)
+_nc_tparm_analyze(const char *string, char **p_is_s, int *popcount)
 {
     size_t len2;
     int i;
@@ -555,7 +555,7 @@ tparm_setup(const char *string, TPARM_DATA * result)
        void *ft;
 
        result->format = string;
-       if ((ft = tfind(result, &cached_tparm, cmp_format)) != 0) {
+       if ((ft = tfind(result, &MyCache, cmp_format)) != 0) {
            fs = *(TPARM_DATA **) ft;
            *result = *fs;
        } else
@@ -589,8 +589,8 @@ tparm_setup(const char *string, TPARM_DATA * result)
                if ((fs = typeCalloc(TPARM_DATA, 1)) != 0) {
                    *fs = *result;
                    if ((fs->format = strdup(string)) != 0) {
-                       if ((ft = tsearch(fs, &cached_tparm, cmp_format)) != 0) {
-                           ++count_tparm;
+                       if (tsearch(fs, &MyCache, cmp_format) != 0) {
+                           ++MyCount;
                        } else {
                            rc = ERR;
                        }
@@ -966,6 +966,13 @@ tparam_internal(const char *string, TPARM_DATA * data)
     get_space((size_t) 1);
     TPS(out_buff)[TPS(out_used)] = '\0';
 
+    if (TPS(stack_ptr) && !_nc_tparm_err) {
+       DEBUG(2, ("tparm: stack has %d item%s on return",
+                 TPS(stack_ptr),
+                 TPS(stack_ptr) == 1 ? "" : "s"));
+       _nc_tparm_err++;
+    }
+
     T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff))));
     return (TPS(out_buff));
 }