]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_menus.c
ncurses 6.3 - patch 20220521
[ncurses.git] / test / demo_menus.c
index 857dfd626f365afe01d13c276194a90c3bce3246..e0e4852ec92f5a25d7eebc4cf295cb2c666ef62a 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2005-2017,2019 Free Software Foundation, Inc.              *
+ * Copyright 2019-2021,2022 Thomas E. Dickey                                *
+ * Copyright 2003-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            *
@@ -26,7 +27,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_menus.c,v 1.69 2019/08/24 21:41:50 tom Exp $
+ * $Id: demo_menus.c,v 1.76 2022/05/15 13:54:48 tom Exp $
  *
  * Demonstrate a variety of functions from the menu library.
  * Thomas Dickey - 2005/4/9
@@ -112,7 +113,7 @@ static bool loaded_file = FALSE;
 static char empty[1];
 
 #ifdef TRACE
-static void failed(const char *s) GCC_NORETURN;
+static GCC_NORETURN void failed(const char *s);
 
 static void
 failed(const char *s)
@@ -139,7 +140,7 @@ wGetchar(WINDOW *win)
        } else {
            _nc_tracing = save_trace;
        }
-       trace(_nc_tracing);
+       curses_trace(_nc_tracing);
        if (_nc_tracing)
            Trace(("TOGGLE-TRACING ON"));
     }
@@ -307,7 +308,7 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number)
 }
 
 static void
-menu_destroy(MENU * m)
+menu_destroy(MENU * m, int itemsToo)
 {
     Trace(("menu_destroy %p", (void *) m));
     if (m != 0) {
@@ -330,18 +331,18 @@ menu_destroy(MENU * m)
                Trace(("freeing blob %p", blob));
                free((void *) blob);
            }
-           free(items);
-           items = 0;
        }
-#ifdef TRACE
-       if ((count > 0) && (m == mpTrace)) {
-           ITEM **ip = items;
-           if (ip != 0) {
-               while (*ip)
-                   free(*ip++);
+       if (count > 0 && itemsToo) {
+           if (itemsToo & 1) {
+               ITEM **ip = items;
+               if (ip != 0) {
+                   while (*ip)
+                       free_item(*ip++);
+               }
            }
+           if (itemsToo & 2)
+               free(items);
        }
-#endif
     }
 }
 
@@ -564,7 +565,7 @@ tracetrace(unsigned tlevel)
     }
     _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
     if (tlevel == 0) {
-       _nc_STRCAT(buf, t_tbl[0].name, need);
+       _nc_STRCAT(buf, t_tbl[0].name ? t_tbl[0].name : "", need);
        _nc_STRCAT(buf, ", ", need);
     } else {
        for (n = 1; t_tbl[n].name != 0; n++)
@@ -631,7 +632,7 @@ perform_trace_menu(int cmd)
                    newtrace |= td->mask;
                }
            }
-           trace(newtrace);
+           curses_trace(newtrace);
            Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
 
            MvWPrintw(status, 1, 0,
@@ -931,12 +932,12 @@ perform_menus(void)
 static void
 destroy_menus(void)
 {
-    menu_destroy(mpFile);
-    menu_destroy(mpSelect);
+    menu_destroy(mpFile, 1);
+    menu_destroy(mpSelect, 3);
 #ifdef TRACE
-    menu_destroy(mpTrace);
+    menu_destroy(mpTrace, 1);
 #endif
-    menu_destroy(mpBanner);
+    menu_destroy(mpBanner, 1);
 }
 
 #if HAVE_RIPOFFLINE
@@ -1003,6 +1004,7 @@ main(int argc, char *argv[])
     int c;
 
     setlocale(LC_ALL, "");
+    START_TRACE();
 
     while ((c = getopt(argc, argv, "fht:")) != -1) {
        switch (c) {
@@ -1016,7 +1018,7 @@ main(int argc, char *argv[])
 #endif /* HAVE_RIPOFFLINE */
 #ifdef TRACE
        case 't':
-           trace((unsigned) strtoul(optarg, 0, 0));
+           curses_trace((unsigned) strtoul(optarg, 0, 0));
            break;
 #endif
        default: