]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_terminfo.c
ncurses 6.2 - patch 20200509
[ncurses.git] / test / demo_terminfo.c
index c1fffc7048f057277dd0295c8f5fa63dfffc1f8e..61c4076b6254d98e21b61b034345679767457f50 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2009-2015,2016 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 2009-2016,2017 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,7 +30,7 @@
 /*
  * Author: Thomas E. Dickey
  *
- * $Id: demo_terminfo.c,v 1.44 2016/09/10 21:22:49 tom Exp $
+ * $Id: demo_terminfo.c,v 1.51 2020/05/09 13:56:40 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
@@ -69,8 +70,10 @@ static bool f_opt = FALSE;
 static bool n_opt = FALSE;
 static bool q_opt = FALSE;
 static bool s_opt = FALSE;
+#ifdef NCURSES_VERSION
 static bool x_opt = FALSE;
 static bool y_opt = FALSE;
+#endif
 
 static char *d_opt;
 static char *e_opt;
@@ -148,11 +151,12 @@ next_dbitem(void)
            db_item++;
        }
     }
-    printf("** %s\n", result);
+    if (result != 0)
+       printf("** %s\n", result);
     return result;
 }
 
-#ifdef NO_LEAKS
+#if NO_LEAKS
 static void
 free_dblist(void)
 {
@@ -360,10 +364,9 @@ demo_terminfo(char *name)
     }
 #ifdef NCURSES_VERSION
     if (x_opt && (my_blob == 0)) {
-       int mod;
        if (y_opt) {
 #if NCURSES_XNAMES
-           TERMTYPE *term = &(cur_term->type);
+           TERMTYPE *term = (TERMTYPE *) cur_term;
            if (term != 0
                && ((NUM_BOOLEANS(term) != BOOLCOUNT)
                    || (NUM_NUMBERS(term) != NUMCOUNT)
@@ -387,6 +390,7 @@ demo_terminfo(char *name)
                "kLFT", "kNXT", "kPRV", "kRIT", "kUP",
            };
            for (n = 0; n < SIZEOF(xterm_keys); ++n) {
+               int mod;
                for (mod = 0; mod < 8; ++mod) {
                    if (mod == 0) {
                        /* these happen to be standard - avoid duplicates */
@@ -726,7 +730,6 @@ copy_code_list(NCURSES_CONST char *const *list)
     size_t count;
     size_t length = 1;
     char **result = 0;
-    char *blob = 0;
     char *unused = 0;
 
     for (pass = 0; pass < 2; ++pass) {
@@ -741,7 +744,7 @@ copy_code_list(NCURSES_CONST char *const *list)
            }
        }
        if (pass == 0) {
-           blob = malloc(length);
+           char *blob = malloc(length);
            result = typeCalloc(char *, count + 1);
            unused = blob;
            if (blob == 0 || result == 0)
@@ -751,7 +754,18 @@ copy_code_list(NCURSES_CONST char *const *list)
 
     return result;
 }
+
+#if NO_LEAKS
+static void
+free_code_list(char **list)
+{
+    if (list) {
+       free(list[0]);
+       free(list);
+    }
+}
 #endif
+#endif /* USE_CODE_LISTS */
 
 static void
 usage(void)
@@ -828,10 +842,12 @@ main(int argc, char *argv[])
        case 's':
            s_opt = TRUE;
            break;
-#ifdef NCURSES_VERSION
        case 'x':
+#ifdef NCURSES_VERSION
            x_opt = TRUE;
+#endif
            break;
+#ifdef NCURSES_VERSION
        case 'y':
            y_opt = TRUE;
            x_opt = TRUE;
@@ -904,17 +920,26 @@ main(int argc, char *argv[])
           PLURAL(total_n_values),
           PLURAL(total_s_values));
 
-#ifdef NO_LEAKS
+#if NO_LEAKS
     free_dblist();
-    if (my_blob != 0) {
-       free(my_blob);
-       free(my_boolcodes);
-       free(my_numcodes);
-       free(my_numvalues);
-       free(my_strcodes);
-       free(my_strvalues);
+    if (input_name != 0) {
+       if (my_blob != 0) {
+           free(my_blob);
+           free(my_boolcodes);
+           free(my_numcodes);
+           free(my_numvalues);
+           free(my_strcodes);
+           free(my_strvalues);
+       }
+    }
+#if USE_CODE_LISTS
+    else {
+       free_code_list(my_boolcodes);
+       free_code_list(my_numcodes);
+       free_code_list(my_strcodes);
     }
 #endif
+#endif /* NO_LEAKS */
 
     ExitProgram(EXIT_SUCCESS);
 }