]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/ncurses.c
ncurses 5.9 - patch 20120721
[ncurses.git] / test / ncurses.c
index ddb732ef42b32fd9b7b83ec24126a26404999f19..f5c78dbe717cdb603dcdf63dfb85ba6ea49f1232 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2011,2012 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -40,7 +40,7 @@ AUTHOR
    Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
            Thomas E. Dickey (beginning revision 1.27 in 1996).
 
    Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
            Thomas E. Dickey (beginning revision 1.27 in 1996).
 
-$Id: ncurses.c,v 1.360 2010/07/24 18:04:58 tom Exp $
+$Id: ncurses.c,v 1.373 2012/07/21 17:40:21 tom Exp $
 
 ***************************************************************************/
 
 
 ***************************************************************************/
 
@@ -106,6 +106,7 @@ extern unsigned _nc_tracing;
 #endif
 #endif /* ACS_S3 */
 
 #endif
 #endif /* ACS_S3 */
 
+#ifndef WACS_S3
 #ifdef CURSES_WACS_ARRAY
 #define WACS_S3         (&(CURSES_WACS_ARRAY['p']))    /* scan line 3 */
 #define WACS_S7         (&(CURSES_WACS_ARRAY['r']))    /* scan line 7 */
 #ifdef CURSES_WACS_ARRAY
 #define WACS_S3         (&(CURSES_WACS_ARRAY['p']))    /* scan line 3 */
 #define WACS_S7         (&(CURSES_WACS_ARRAY['r']))    /* scan line 7 */
@@ -115,6 +116,7 @@ extern unsigned _nc_tracing;
 #define WACS_NEQUAL     (&(CURSES_WACS_ARRAY['|']))    /* not equal */
 #define WACS_STERLING   (&(CURSES_WACS_ARRAY['}']))    /* UK pound sign */
 #endif
 #define WACS_NEQUAL     (&(CURSES_WACS_ARRAY['|']))    /* not equal */
 #define WACS_STERLING   (&(CURSES_WACS_ARRAY['}']))    /* UK pound sign */
 #endif
+#endif
 
 #endif
 
 
 #endif
 
@@ -488,7 +490,7 @@ ShellOut(bool message)
 #ifdef __MINGW32__
     system("cmd.exe");
 #else
 #ifdef __MINGW32__
     system("cmd.exe");
 #else
-    system("sh");
+    IGNORE_RC(system("sh"));
 #endif
     if (message)
        addstr("returned from shellout.\n");
 #endif
     if (message)
        addstr("returned from shellout.\n");
@@ -688,7 +690,7 @@ wgetch_wrap(WINDOW *win, int first_y)
     wclrtoeol(win);
 }
 
     wclrtoeol(win);
 }
 
-#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+#if defined(KEY_RESIZE) && HAVE_WRESIZE
 typedef struct {
     WINDOW *text;
     WINDOW *frame;
 typedef struct {
     WINDOW *text;
     WINDOW *frame;
@@ -725,7 +727,7 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
     winstack[level].frame = box_win;
 }
 
     winstack[level].frame = box_win;
 }
 
-#if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
+#if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
 static void
 slk_repaint(void)
 {
 static void
 slk_repaint(void)
 {
@@ -739,6 +741,7 @@ slk_repaint(void)
 #define slk_repaint()          /* nothing */
 #endif
 
 #define slk_repaint()          /* nothing */
 #endif
 
+#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
 /*
  * For wgetch_test(), we create pairs of windows - one for a box, one for text.
  * Resize both and paint the box in the parent.
 /*
  * For wgetch_test(), we create pairs of windows - one for a box, one for text.
  * Resize both and paint the box in the parent.
@@ -774,11 +777,21 @@ resize_boxes(unsigned level, WINDOW *win)
     }
     doupdate();
 }
     }
     doupdate();
 }
+#endif /* resize_boxes */
 #else
 #define forget_boxes()         /* nothing */
 #define remember_boxes(level,text,frame)       /* nothing */
 #endif
 
 #else
 #define forget_boxes()         /* nothing */
 #define remember_boxes(level,text,frame)       /* nothing */
 #endif
 
+/*
+ * Return-code is OK/ERR or a keyname.
+ */
+static const char *
+ok_keyname(int code)
+{
+    return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
+}
+
 static void
 wgetch_test(unsigned level, WINDOW *win, int delay)
 {
 static void
 wgetch_test(unsigned level, WINDOW *win, int delay)
 {
@@ -820,9 +833,11 @@ wgetch_test(unsigned level, WINDOW *win, int delay)
        } else if (c == 'g') {
            waddstr(win, "getstr test: ");
            echo();
        } else if (c == 'g') {
            waddstr(win, "getstr test: ");
            echo();
-           wgetnstr(win, buf, sizeof(buf) - 1);
+           c = wgetnstr(win, buf, sizeof(buf) - 1);
            noecho();
            noecho();
-           wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
+           wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
+                   (int) strlen(buf), buf,
+                   ok_keyname(c));
            wclrtoeol(win);
            wgetch_wrap(win, first_y);
        } else if (c == 'k') {
            wclrtoeol(win);
            wgetch_wrap(win, first_y);
        } else if (c == 'k') {
@@ -1390,7 +1405,7 @@ show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
        if (!(termattrs() & test)) {
            printw(" (N/A)");
        } else {
        if (!(termattrs() & test)) {
            printw(" (N/A)");
        } else {
-           if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
+           if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
                static const chtype table[] =
                {
                    A_STANDOUT,
                static const chtype table[] =
                {
                    A_STANDOUT,
@@ -1534,7 +1549,7 @@ attr_test(void)
                if (init_pair(pair, fg, bg) == ERR) {
                    beep();
                } else {
                if (init_pair(pair, fg, bg) == ERR) {
                    beep();
                } else {
-                   normal |= COLOR_PAIR(pair);
+                   normal |= (chtype) COLOR_PAIR(pair);
                }
            }
            if (tx >= 0) {
                }
            }
            if (tx >= 0) {
@@ -1542,7 +1557,7 @@ attr_test(void)
                if (init_pair(pair, tx, bg) == ERR) {
                    beep();
                } else {
                if (init_pair(pair, tx, bg) == ERR) {
                    beep();
                } else {
-                   extras |= COLOR_PAIR(pair);
+                   extras |= (chtype) COLOR_PAIR(pair);
                }
            }
        }
                }
            }
        }
@@ -1671,8 +1686,8 @@ wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const cha
            add_wch(&ch);
        }
     } else {
            add_wch(&ch);
        }
     } else {
-       attr_t old_attr;
-       short old_pair;
+       attr_t old_attr = 0;
+       short old_pair = 0;
 
        (void) attr_get(&old_attr, &old_pair, 0);
        (void) attr_set(attr, pair, 0);
 
        (void) attr_get(&old_attr, &old_pair, 0);
        (void) attr_set(attr, pair, 0);
@@ -1827,9 +1842,9 @@ wide_attr_test(void)
 
        for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
            row = wide_show_attr(row, n, j == k,
 
        for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
            row = wide_show_attr(row, n, j == k,
-                                ac |
-                                attrs_to_test[j].attr |
-                                attrs_to_test[k].attr,
+                                ((attr_t) ac |
+                                 attrs_to_test[j].attr |
+                                 attrs_to_test[k].attr),
                                 extras,
                                 attrs_to_test[j].name);
        }
                                 extras,
                                 attrs_to_test[j].name);
        }
@@ -2415,7 +2430,7 @@ color_edit(void)
                     (i == current ? '>' : ' '),
                     (i < (int) SIZEOF(the_color_names)
                      ? the_color_names[i] : numeric));
                     (i == current ? '>' : ' '),
                     (i < (int) SIZEOF(the_color_names)
                      ? the_color_names[i] : numeric));
-           (void) attrset(COLOR_PAIR(i));
+           (void) attrset((attr_t) COLOR_PAIR(i));
            addstr("        ");
            (void) attrset(A_NORMAL);
 
            addstr("        ");
            (void) attrset(A_NORMAL);
 
@@ -2577,52 +2592,6 @@ color_edit(void)
     endwin();
 }
 
     endwin();
 }
 
-/****************************************************************************
- *
- * Soft-key label test
- *
- ****************************************************************************/
-
-#if USE_SOFTKEYS
-
-#define SLK_HELP 17
-#define SLK_WORK (SLK_HELP + 3)
-
-static void
-slk_help(void)
-{
-    static const char *table[] =
-    {
-       "Available commands are:"
-       ,""
-       ,"^L         -- repaint this message and activate soft keys"
-       ,"a/d        -- activate/disable soft keys"
-       ,"c          -- set centered format for labels"
-       ,"l          -- set left-justified format for labels"
-       ,"r          -- set right-justified format for labels"
-       ,"[12345678] -- set label; labels are numbered 1 through 8"
-       ,"e          -- erase stdscr (should not erase labels)"
-       ,"s          -- test scrolling of shortened screen"
-       ,"v/V        -- cycle through video attributes"
-#if HAVE_SLK_COLOR
-       ,"F/f/B/b    -- cycle through foreground/background colors"
-#endif
-       ,"ESC        -- return to main menu"
-       ,""
-       ,"Note: if activating the soft keys causes your terminal to scroll up"
-       ,"one line, your terminal auto-scrolls when anything is written to the"
-       ,"last screen position.  The ncurses code does not yet handle this"
-       ,"gracefully."
-    };
-    unsigned j;
-
-    move(2, 0);
-    for (j = 0; j < SIZEOF(table); ++j) {
-       P(table[j]);
-    }
-    refresh();
-}
-
 /****************************************************************************
  *
  * Alternate character-set stuff
 /****************************************************************************
  *
  * Alternate character-set stuff
@@ -2707,11 +2676,57 @@ cycle_colors(int ch, int *fg, int *bg, short *pair)
     return result;
 }
 
     return result;
 }
 
+/****************************************************************************
+ *
+ * Soft-key label test
+ *
+ ****************************************************************************/
+
+#if USE_SOFTKEYS
+
+#define SLK_HELP 17
+#define SLK_WORK (SLK_HELP + 3)
+
+static void
+slk_help(void)
+{
+    static const char *table[] =
+    {
+       "Available commands are:"
+       ,""
+       ,"^L         -- repaint this message and activate soft keys"
+       ,"a/d        -- activate/disable soft keys"
+       ,"c          -- set centered format for labels"
+       ,"l          -- set left-justified format for labels"
+       ,"r          -- set right-justified format for labels"
+       ,"[12345678] -- set label; labels are numbered 1 through 8"
+       ,"e          -- erase stdscr (should not erase labels)"
+       ,"s          -- test scrolling of shortened screen"
+       ,"v/V        -- cycle through video attributes"
+#if HAVE_SLK_COLOR
+       ,"F/f/B/b    -- cycle through foreground/background colors"
+#endif
+       ,"ESC        -- return to main menu"
+       ,""
+       ,"Note: if activating the soft keys causes your terminal to scroll up"
+       ,"one line, your terminal auto-scrolls when anything is written to the"
+       ,"last screen position.  The ncurses code does not yet handle this"
+       ,"gracefully."
+    };
+    unsigned j;
+
+    move(2, 0);
+    for (j = 0; j < SIZEOF(table); ++j) {
+       P(table[j]);
+    }
+    refresh();
+}
+
 #if HAVE_SLK_COLOR
 static void
 #if HAVE_SLK_COLOR
 static void
-call_slk_color(short fg, short bg)
+call_slk_color(int fg, int bg)
 {
 {
-    init_pair(1, bg, fg);
+    init_pair(1, (short) bg, (short) fg);
     slk_color(1);
     MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
     clrtoeol();
     slk_color(1);
     MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
     clrtoeol();
@@ -2968,7 +2983,7 @@ wide_slk_test(void)
 #endif
        default:
            if (cycle_attr(c, &at_code, &attr)) {
 #endif
        default:
            if (cycle_attr(c, &at_code, &attr)) {
-               slk_attr_set(attr, (fg || bg), NULL);
+               slk_attr_set(attr, (short) (fg || bg), NULL);
                slk_touch();
                slk_noutrefresh();
                break;
                slk_touch();
                slk_noutrefresh();
                break;
@@ -3085,7 +3100,8 @@ static void
 show_box_chars(int repeat, attr_t attr, short pair)
 {
     (void) repeat;
 show_box_chars(int repeat, attr_t attr, short pair)
 {
     (void) repeat;
-    attr |= COLOR_PAIR(pair);
+
+    attr |= (attr_t) COLOR_PAIR(pair);
 
     erase();
     attron(A_BOLD);
 
     erase();
     attron(A_BOLD);
@@ -3133,7 +3149,7 @@ show_acs_chars(int repeat, attr_t attr, short pair)
 {
     int n;
 
 {
     int n;
 
-#define BOTH(name) #name, colored_chtype(name, attr, pair)
+#define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
 
     erase();
     attron(A_BOLD);
 
     erase();
     attron(A_BOLD);
@@ -3339,8 +3355,11 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
             * Mark them with reverse-video to make them simpler to find on
             * the display.
             */
             * Mark them with reverse-video to make them simpler to find on
             * the display.
             */
-           if (wcwidth(code) == 0)
-               addch(space | (A_REVERSE ^ attr) | COLOR_PAIR(pair));
+           if (wcwidth(code) == 0) {
+               addch((chtype) space |
+                     (A_REVERSE ^ attr) |
+                     (attr_t) COLOR_PAIR(pair));
+           }
            /*
             * This could use add_wch(), but is done for comparison with the
             * normal 'f' test (and to make a test-case for echo_wchar()).
            /*
             * This could use add_wch(), but is done for comparison with the
             * normal 'f' test (and to make a test-case for echo_wchar()).
@@ -3352,6 +3371,7 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
             * The repeat-count may make text wrap - avoid that.
             */
            getyx(stdscr, y, x);
             * The repeat-count may make text wrap - avoid that.
             */
            getyx(stdscr, y, x);
+           (void) y;
            if (x >= col + (COLS / 2) - 2)
                break;
        } while (--count > 0);
            if (x >= col + (COLS / 2) - 2)
                break;
        } while (--count > 0);
@@ -4261,8 +4281,10 @@ acs_and_scroll(void)
 
                    neww->next = current ? current->next : 0;
                    neww->last = current;
 
                    neww->next = current ? current->next : 0;
                    neww->last = current;
-                   neww->last->next = neww;
-                   neww->next->last = neww;
+                   if (neww->last != 0)
+                       neww->last->next = neww;
+                   if (neww->next != 0)
+                       neww->next->last = neww;
 
                    neww->wind = getwin(fp);
 
 
                    neww->wind = getwin(fp);
 
@@ -4468,7 +4490,7 @@ mkpanel(short color, int rows, int cols, int tly, int tlx)
            short bg = color;
 
            init_pair(color, fg, bg);
            short bg = color;
 
            init_pair(color, fg, bg);
-           wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
+           wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
        } else {
            wbkgdset(win, A_BOLD | ' ');
        }
        } else {
            wbkgdset(win, A_BOLD | ' ');
        }
@@ -5062,11 +5084,11 @@ panner(WINDOW *pad,
 
            doupdate();
 #if HAVE_GETTIMEOFDAY
 
            doupdate();
 #if HAVE_GETTIMEOFDAY
+#define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
            if (timing) {
                double elapsed;
                gettimeofday(&after, 0);
            if (timing) {
                double elapsed;
                gettimeofday(&after, 0);
-               elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
-                   - (before.tv_sec + before.tv_usec / 1.0e6);
+               elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
                move(LINES - 1, COLS - 12);
                printw("Secs: %2.03f", elapsed);
                refresh();
                move(LINES - 1, COLS - 12);
                printw("Secs: %2.03f", elapsed);
                refresh();
@@ -5218,7 +5240,7 @@ flushinp_test(WINDOW *win)
 #ifdef A_COLOR
     if (use_colors) {
        init_pair(2, COLOR_CYAN, COLOR_BLUE);
 #ifdef A_COLOR
     if (use_colors) {
        init_pair(2, COLOR_CYAN, COLOR_BLUE);
-       wbkgd(subWin, COLOR_PAIR(2) | ' ');
+       wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
     }
 #endif
     (void) wattrset(subWin, A_BOLD);
     }
 #endif
     (void) wattrset(subWin, A_BOLD);
@@ -5584,7 +5606,7 @@ make_label(int frow, int fcol, NCURSES_CONST char *label)
 
     if (f) {
        set_field_buffer(f, 0, label);
 
     if (f) {
        set_field_buffer(f, 0, label);
-       set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
+       set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
     }
     return (f);
 }
     }
     return (f);
 }
@@ -6048,11 +6070,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col)
        break;
     case 2:
        init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
        break;
     case 2:
        init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
-       (void) wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
+       (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL));
        break;
     case 3:
        init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
        break;
     case 3:
        init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
-       (void) wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
+       (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD));
        break;
     }
 }
        break;
     }
 }
@@ -6385,13 +6407,14 @@ do_single_test(const char c)
     case 'e':
        slk_test();
        break;
     case 'e':
        slk_test();
        break;
-#endif
 
 #if USE_WIDEC_SUPPORT
     case 'E':
        wide_slk_test();
        break;
 #endif
 
 #if USE_WIDEC_SUPPORT
     case 'E':
        wide_slk_test();
        break;
 #endif
+#endif
+
     case 'f':
        acs_display();
        break;
     case 'f':
        acs_display();
        break;
@@ -6474,6 +6497,7 @@ usage(void)
        ,"  -a f,b   set default-colors (assumed white-on-black)"
        ,"  -d       use default-colors if terminal supports them"
 #endif
        ,"  -a f,b   set default-colors (assumed white-on-black)"
        ,"  -d       use default-colors if terminal supports them"
 #endif
+       ,"  -E       call use_env(FALSE) to ignore $LINES and $COLUMNS"
 #if USE_SOFTKEYS
        ,"  -e fmt   specify format for soft-keys test (e)"
 #endif
 #if USE_SOFTKEYS
        ,"  -e fmt   specify format for soft-keys test (e)"
 #endif
@@ -6486,6 +6510,9 @@ usage(void)
 #if USE_LIBPANEL
        ,"  -s msec  specify nominal time for panel-demo (default: 1, to hold)"
 #endif
 #if USE_LIBPANEL
        ,"  -s msec  specify nominal time for panel-demo (default: 1, to hold)"
 #endif
+#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
+       ,"  -T       call use_tioctl(TRUE) to allow SIGWINCH to override environment"
+#endif
 #ifdef TRACE
        ,"  -t mask  specify default trace-level (may toggle with ^T)"
 #endif
 #ifdef TRACE
        ,"  -t mask  specify default trace-level (may toggle with ^T)"
 #endif
@@ -6672,7 +6699,7 @@ main(int argc, char *argv[])
 
     setlocale(LC_ALL, "");
 
 
     setlocale(LC_ALL, "");
 
-    while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
+    while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) {
        switch (c) {
 #ifdef NCURSES_VERSION
        case 'a':
        switch (c) {
 #ifdef NCURSES_VERSION
        case 'a':
@@ -6683,6 +6710,9 @@ main(int argc, char *argv[])
            default_colors = TRUE;
            break;
 #endif
            default_colors = TRUE;
            break;
 #endif
+       case 'E':
+           use_env(FALSE);
+           break;
        case 'e':
            my_e_param = atoi(optarg);
 #ifdef NCURSES_VERSION
        case 'e':
            my_e_param = atoi(optarg);
 #ifdef NCURSES_VERSION
@@ -6709,7 +6739,12 @@ main(int argc, char *argv[])
            break;
 #if USE_LIBPANEL
        case 's':
            break;
 #if USE_LIBPANEL
        case 's':
-           nap_msec = atol(optarg);
+           nap_msec = (int) atol(optarg);
+           break;
+#endif
+#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
+       case 'T':
+           use_tioctl(TRUE);
            break;
 #endif
 #ifdef TRACE
            break;
 #endif
 #ifdef TRACE
@@ -6763,7 +6798,7 @@ main(int argc, char *argv[])
            use_default_colors();
            min_colors = -1;
        }
            use_default_colors();
            min_colors = -1;
        }
-#if NCURSES_VERSION_PATCH >= 20000708
+#if HAVE_ASSUME_DEFAULT_COLORS
        if (assumed_colors)
            assume_default_colors(default_fg, default_bg);
 #endif
        if (assumed_colors)
            assume_default_colors(default_fg, default_bg);
 #endif