]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_menus.c
ncurses 6.2 - patch 20200627
[ncurses.git] / test / demo_menus.c
index 00fe5b4321c39bc7466bd4a5ea22b74cf0f7b9fc..02f7ca3312fffb7ec5bebb46a20a0b2b9caa8110 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2005-2015,2016 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 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.62 2016/09/10 23:30:33 tom Exp $
+ * $Id: demo_menus.c,v 1.71 2020/02/02 23:34:34 tom Exp $
  *
  * Demonstrate a variety of functions from the menu library.
  * Thomas Dickey - 2005/4/9
@@ -75,11 +76,8 @@ top_row                              -
 #ifdef NCURSES_VERSION
 #ifdef TRACE
 static unsigned save_trace = TRACE_ORDINARY | TRACE_CALLS;
-extern unsigned _nc_tracing;
 static MENU *mpTrace;
 #endif
-#else
-#undef TRACE
 #endif
 
 typedef enum {
@@ -113,6 +111,8 @@ static WINDOW *status;
 static bool loaded_file = FALSE;
 
 static char empty[1];
+
+#ifdef TRACE
 static void failed(const char *s) GCC_NORETURN;
 
 static void
@@ -122,6 +122,7 @@ failed(const char *s)
     endwin();
     ExitProgram(EXIT_FAILURE);
 }
+#endif
 
 /* Common function to allow ^T to toggle trace-mode in the middle of a test
  * so that trace-files can be made smaller.
@@ -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"));
     }
@@ -195,9 +196,9 @@ menu_offset(MenuNo number)
     int result = 0;
 
     if (okMenuNo(number)) {
-       int spc_desc, spc_rows, spc_cols;
-
+       int spc_rows;
 #ifdef NCURSES_VERSION
+       int spc_desc, spc_cols;
        menu_spacing(mpBanner, &spc_desc, &spc_rows, &spc_cols);
 #else
        spc_rows = 0;
@@ -309,12 +310,11 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number)
 static void
 menu_destroy(MENU * m)
 {
-    int count;
-
     Trace(("menu_destroy %p", (void *) m));
     if (m != 0) {
        ITEM **items = menu_items(m);
        const char *blob = 0;
+       int count;
 
        count = item_count(m);
        Trace(("menu_destroy %p count %d", (void *) m, count));
@@ -429,7 +429,6 @@ build_select_menu(MenuNo number, char *filename)
            && (sb.st_mode & S_IFMT) == S_IFREG
            && sb.st_size != 0) {
            size_t size = (size_t) sb.st_size;
-           unsigned j, k;
            char *blob = typeMalloc(char, size + 1);
            MENU_DATA *list = typeCalloc(MENU_DATA, size + 1);
 
@@ -442,6 +441,7 @@ build_select_menu(MenuNo number, char *filename)
                if (fp != 0) {
                    if (fread(blob, sizeof(char), size, fp) == size) {
                        bool mark = TRUE;
+                       unsigned j, k;
                        for (j = k = 0; j < size; ++j) {
                            if (mark) {
                                list[k++].name = blob + j;
@@ -587,13 +587,14 @@ static bool
 update_trace_menu(MENU * m)
 {
     ITEM **items;
-    ITEM *i, **p;
+    ITEM *i;
     bool changed = FALSE;
 
     items = menu_items(m);
     i = current_item(m);
     if (i == items[0]) {
        if (item_value(i)) {
+           ITEM **p;
            for (p = items + 1; *p != 0; p++)
                if (item_value(*p)) {
                    set_item_value(*p, FALSE);
@@ -609,7 +610,6 @@ perform_trace_menu(int cmd)
 /* interactively set the trace level */
 {
     ITEM **ip;
-    unsigned newtrace;
     int result;
 
     for (ip = menu_items(mpTrace); *ip; ip++) {
@@ -625,14 +625,14 @@ perform_trace_menu(int cmd)
 
     if (result == E_OK) {
        if (update_trace_menu(mpTrace) || cmd == REQ_TOGGLE_ITEM) {
-           newtrace = 0;
+           unsigned newtrace = 0;
            for (ip = menu_items(mpTrace); *ip; ip++) {
                if (item_value(*ip)) {
                    MENU_DATA *td = (MENU_DATA *) item_userptr(*ip);
                    newtrace |= td->mask;
                }
            }
-           trace(newtrace);
+           curses_trace(newtrace);
            Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
 
            MvWPrintw(status, 1, 0,
@@ -767,7 +767,7 @@ move_menus(MENU * current, int by_y, int by_x)
     }
 }
 
-#ifdef KEY_RESIZE
+#if defined(KEY_RESIZE) && NCURSES_EXT_FUNCS
 static void
 resize_menu(MENU ** menu)
 {
@@ -795,7 +795,7 @@ resize_menus(MENU * current)
     resize_menu(&mpTrace);
 #endif
 }
-#endif
+#endif /* defined(KEY_RESIZE) && NCURSES_EXT_FUNCS */
 
 static void
 show_status(int ch, MENU * menu)
@@ -849,7 +849,7 @@ perform_menus(void)
        case KEY_SRIGHT:
            move_menus(last_menu, 0, 1);
            continue;
-#ifdef KEY_RESIZE
+#if defined(KEY_RESIZE) && NCURSES_EXT_FUNCS
        case KEY_RESIZE:
            resize_menus(last_menu);
            continue;
@@ -1017,7 +1017,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: