]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/ncurses.c
ncurses 5.9 - patch 20130608
[ncurses.git] / test / ncurses.c
index ddb732ef42b32fd9b7b83ec24126a26404999f19..4722e3f871fd38de89486c0497d4dd6ed2beb5a8 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 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            *
@@ -40,7 +40,7 @@ AUTHOR
    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.389 2013/04/27 19:46:53 tom Exp $
 
 ***************************************************************************/
 
@@ -106,6 +106,7 @@ extern unsigned _nc_tracing;
 #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 */
@@ -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
+#endif
 
 #endif
 
@@ -164,6 +166,14 @@ static RGB_DATA *all_colors;
 
 static void main_menu(bool);
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    endwin();
+    ExitProgram(EXIT_FAILURE);
+}
+
 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
  * though we can rely on negative x/y values to stop the macro.
  */
@@ -488,7 +498,7 @@ ShellOut(bool message)
 #ifdef __MINGW32__
     system("cmd.exe");
 #else
-    system("sh");
+    IGNORE_RC(system("sh"));
 #endif
     if (message)
        addstr("returned from shellout.\n");
@@ -688,7 +698,7 @@ wgetch_wrap(WINDOW *win, int first_y)
     wclrtoeol(win);
 }
 
-#if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
+#if defined(KEY_RESIZE) && HAVE_WRESIZE
 typedef struct {
     WINDOW *text;
     WINDOW *frame;
@@ -721,11 +731,13 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
        len_winstack = need;
        winstack = typeRealloc(WINSTACK, len_winstack, winstack);
     }
+    if (!winstack)
+       failed("remember_boxes");
     winstack[level].text = txt_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)
 {
@@ -739,6 +751,7 @@ slk_repaint(void)
 #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.
@@ -774,11 +787,21 @@ resize_boxes(unsigned level, WINDOW *win)
     }
     doupdate();
 }
+#endif /* resize_boxes */
 #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)
 {
@@ -820,9 +843,11 @@ wgetch_test(unsigned level, WINDOW *win, int delay)
        } else if (c == 'g') {
            waddstr(win, "getstr test: ");
            echo();
-           wgetnstr(win, buf, sizeof(buf) - 1);
+           c = wgetnstr(win, buf, sizeof(buf) - 1);
            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') {
@@ -1019,6 +1044,8 @@ wcstos(const wchar_t *src)
                free(result);
                result = 0;
            }
+       } else {
+           failed("wcstos");
        }
     }
     return result;
@@ -1068,7 +1095,7 @@ wget_wch_test(unsigned level, WINDOW *win, int delay)
        } else if (c == 'g') {
            waddstr(win, "getstr test: ");
            echo();
-           code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
+           code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
            noecho();
            if (code == ERR) {
                wprintw(win, "wgetn_wstr returns an error.");
@@ -1390,7 +1417,7 @@ show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
        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,
@@ -1534,7 +1561,7 @@ attr_test(void)
                if (init_pair(pair, fg, bg) == ERR) {
                    beep();
                } else {
-                   normal |= COLOR_PAIR(pair);
+                   normal |= (chtype) COLOR_PAIR(pair);
                }
            }
            if (tx >= 0) {
@@ -1542,7 +1569,7 @@ attr_test(void)
                if (init_pair(pair, tx, bg) == ERR) {
                    beep();
                } else {
-                   extras |= COLOR_PAIR(pair);
+                   extras |= (chtype) COLOR_PAIR(pair);
                }
            }
        }
@@ -1633,6 +1660,7 @@ get_wide_background(void)
     short pair;
     wchar_t wch[10];
 
+    memset(&ch, 0, sizeof(ch));
     if (getbkgrnd(&ch) != ERR) {
        if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
            result = attr;
@@ -1671,8 +1699,8 @@ wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const cha
            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);
@@ -1827,9 +1855,9 @@ wide_attr_test(void)
 
        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);
        }
@@ -1891,7 +1919,7 @@ show_color_name(int y, int x, int color, bool wide)
        } else if (color < 0) {
            strcpy(temp, "default");
        } else {
-           strcpy(temp, the_color_names[color]);
+           sprintf(temp, "%.*s", 16, the_color_names[color]);
        }
        printw("%-*.*s", width, width, temp);
     }
@@ -2155,7 +2183,7 @@ wide_color_test(void)
     bool opt_wide = FALSE;
     bool opt_nums = FALSE;
     bool opt_xchr = FALSE;
-    wchar_t buffer[10];
+    wchar_t buffer[80];
     WINDOW *helpwin;
 
     if (COLORS * COLORS == COLOR_PAIRS) {
@@ -2216,7 +2244,7 @@ wide_color_test(void)
 
            if (row >= 0 && move(row, col) != ERR) {
                init_pair(pair, InxToFG(i), InxToBG(i));
-               color_set(pair, NULL);
+               (void) color_set(pair, NULL);
                if (opt_acsc)
                    attr_on((attr_t) A_ALTCHARSET, NULL);
                if (opt_bold)
@@ -2415,7 +2443,7 @@ color_edit(void)
                     (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);
 
@@ -2577,52 +2605,6 @@ color_edit(void)
     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
@@ -2707,11 +2689,57 @@ cycle_colors(int ch, int *fg, int *bg, short *pair)
     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
-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();
@@ -2968,7 +2996,7 @@ wide_slk_test(void)
 #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;
@@ -2996,15 +3024,46 @@ wide_slk_test(void)
 #endif
 #endif /* SLK_INIT */
 
-/* ISO 6429:  codes 0x80 to 0x9f may be control characters that cause the
+static void
+show_256_chars(int repeat, attr_t attr, short pair)
+{
+    unsigned first = 0;
+    unsigned last = 255;
+    unsigned code;
+    int count;
+
+    erase();
+    attron(A_BOLD);
+    MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
+            first, last);
+    attroff(A_BOLD);
+    refresh();
+
+    for (code = first; code <= last; ++code) {
+       int row = (int) (2 + (code / 16));
+       int col = (int) (5 * (code % 16));
+       mvaddch(row, col, colored_chtype(code, attr, pair));
+       for (count = 1; count < repeat; ++count) {
+           addch(colored_chtype(code, attr, pair));
+       }
+    }
+
+}
+
+/*
+ * Show a slice of 32 characters, allowing those to be repeated up to the
+ * screen's width.
+ *
+ * ISO 6429:  codes 0x80 to 0x9f may be control characters that cause the
  * terminal to perform functions.  The remaining codes can be graphic.
  */
 static void
-show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
+show_upper_chars(int base, int pagesize, int repeat, attr_t attr, short pair)
 {
-    bool C1 = (first == 128);
     unsigned code;
-    unsigned last = first + 31;
+    unsigned first = (unsigned) base;
+    unsigned last = first + (unsigned) pagesize - 2;
+    bool C1 = (first == 128);
     int reply;
 
     erase();
@@ -3016,8 +3075,8 @@ show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
 
     for (code = first; code <= last; code++) {
        int count = repeat;
-       int row = 2 + ((int) (code - first) % 16);
-       int col = ((int) (code - first) / 16) * COLS / 2;
+       int row = 2 + ((int) (code - first) % (pagesize / 2));
+       int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
        char tmp[80];
        sprintf(tmp, "%3u (0x%x)", code, code);
        MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
@@ -3085,7 +3144,8 @@ static void
 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);
@@ -3133,7 +3193,7 @@ show_acs_chars(int repeat, attr_t attr, short pair)
 {
     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);
@@ -3190,6 +3250,7 @@ static void
 acs_display(void)
 {
     int c = 'a';
+    int pagesize = 32;
     char *term = getenv("TERM");
     const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
                              ? "p=PC, "
@@ -3217,6 +3278,13 @@ acs_display(void)
            else
                beep();
            break;
+       case 'w':
+           if (pagesize == 32) {
+               pagesize = 256;
+           } else {
+               pagesize = 32;
+           }
+           break;
        case 'x':
            ToggleAcs(last_show_acs, show_box_chars);
            break;
@@ -3260,15 +3328,18 @@ acs_display(void)
            }
            break;
        }
-       if (last_show_acs != 0)
+       if (pagesize != 32) {
+           show_256_chars(repeat, attr, pair);
+       } else if (last_show_acs != 0) {
            last_show_acs(repeat, attr, pair);
-       else
-           show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
+       } else {
+           show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
+       }
 
        MvPrintw(LINES - 3, 0,
                 "Note: ANSI terminals may not display C1 characters.");
        MvPrintw(LINES - 2, 0,
-                "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
+                "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
                 pch_kludge);
        if (use_colors) {
            MvPrintw(LINES - 1, 0,
@@ -3307,6 +3378,53 @@ merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
     return dst;
 }
 
+/*
+ * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
+ * display.  If there are no repeats, we could normally display 16 lines of 64
+ * characters (1024 total).  However, taking repeats and double-width cells
+ * into account, use 256 characters for the page.
+ */
+static void
+show_paged_widechars(int base,
+                    int pagesize,
+                    int repeat,
+                    int space,
+                    attr_t attr,
+                    short pair)
+{
+    int first = base * pagesize;
+    int last = first + pagesize - 1;
+    int per_line = 16;
+    cchar_t temp;
+    wchar_t code;
+    wchar_t codes[10];
+
+    erase();
+    attron(A_BOLD);
+    MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
+    attroff(A_BOLD);
+
+    for (code = first; (int) code <= last; code++) {
+       int row = (2 + ((int) code - first) / per_line);
+       int col = 5 * ((int) code % per_line);
+       int count;
+
+       memset(&codes, 0, sizeof(codes));
+       codes[0] = code;
+       setcchar(&temp, codes, attr, pair, 0);
+       move(row, col);
+       if (wcwidth(code) == 0 && code != 0) {
+           addch((chtype) space |
+                 (A_REVERSE ^ attr) |
+                 (attr_t) COLOR_PAIR(pair));
+       }
+       add_wch(&temp);
+       for (count = 1; count < repeat; ++count) {
+           add_wch(&temp);
+       }
+    }
+}
+
 static void
 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
 {
@@ -3327,11 +3445,13 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
        int count = repeat;
        int y, x;
 
-       memset(&codes, 0, sizeof(codes));
-       codes[0] = code;
        sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
        MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
+
+       memset(&codes, 0, sizeof(codes));
+       codes[0] = code;
        setcchar(&temp, codes, attr, pair, 0);
+
        do {
            /*
             * Give non-spacing characters something to combine with.  If we
@@ -3339,19 +3459,23 @@ 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.
             */
-           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()).
-            * The screen will flicker because the erase() at the top of the
-            * function is met by the builtin refresh() in echo_wchar().
+            * This uses echo_wchar(), for comparison with the normal 'f'
+            * test (and to make a test-case for echo_wchar()).  The screen
+            * may flicker because the erase() at the top of the function
+            * is met by the builtin refresh() in echo_wchar().
             */
            echo_wchar(&temp);
            /*
             * 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);
@@ -3604,7 +3728,7 @@ show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
 
     MvPrintw(row, col, "%*s : ", COLS / 4, name);
     (void) attr_set(attr, pair, 0);
-    addstr(strcpy(temp, code));
+    addstr(strncpy(temp, code, 20));
     (void) attr_set(A_NORMAL, 0, 0);
     return n + 1;
 }
@@ -3672,6 +3796,7 @@ wide_acs_display(void)
     int digit = 0;
     int repeat = 1;
     int space = ' ';
+    int pagesize = 32;
     chtype attr = A_NORMAL;
     int fg = COLOR_BLACK;
     int bg = COLOR_BLACK;
@@ -3697,6 +3822,13 @@ wide_acs_display(void)
            ToggleAcs(last_show_wacs, show_wacs_chars_thick);
            break;
 #endif
+       case 'w':
+           if (pagesize == 32) {
+               pagesize = 256;
+           } else {
+               pagesize = 32;
+           }
+           break;
        case 'x':
            ToggleAcs(last_show_wacs, show_wbox_chars);
            break;
@@ -3730,20 +3862,25 @@ wide_acs_display(void)
            }
            break;
        }
-       if (last_show_wacs != 0)
+       if (pagesize != 32) {
+           show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
+       } else if (last_show_wacs != 0) {
            last_show_wacs(repeat, attr, pair);
-       else
+       } else {
            show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
+       }
 
-       MvPrintw(LINES - 3, 0,
-                "Select: a/d/t WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
+       MvPrintw(LINES - 4, 0,
+                "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
+       MvPrintw(LINES - 3, 2,
+                "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
        if (use_colors) {
-           MvPrintw(LINES - 2, 0,
+           MvPrintw(LINES - 2, 2,
                     "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
                     attrs_to_cycle[at_code].name,
                     fg, bg);
        } else {
-           MvPrintw(LINES - 2, 0,
+           MvPrintw(LINES - 2, 2,
                     "v/V cycles through video attributes (%s).",
                     attrs_to_cycle[at_code].name);
        }
@@ -3771,7 +3908,7 @@ test_sgr_attributes(void)
        /* Use non-default colors if possible to exercise bce a little */
        if (use_colors) {
            init_pair(1, COLOR_WHITE, COLOR_BLUE);
-           normal |= COLOR_PAIR(1);
+           normal |= (chtype) COLOR_PAIR(1);
        }
        bkgdset(normal);
        erase();
@@ -4107,7 +4244,8 @@ getwindow(void)
     outerbox(ul, lr, TRUE);
     refresh();
 
-    wrefresh(rwindow);
+    if (rwindow != 0)
+       wrefresh(rwindow);
 
     move(0, 0);
     clrtoeol();
@@ -4178,9 +4316,11 @@ acs_and_scroll(void)
        switch (c) {
        case CTRL('C'):
            if ((neww = typeCalloc(FRAME, 1)) == 0) {
+               failed("acs_and_scroll");
                goto breakout;
            }
            if ((neww->wind = getwindow()) == (WINDOW *) 0) {
+               failed("acs_and_scroll");
                free(neww);
                goto breakout;
            }
@@ -4261,12 +4401,16 @@ acs_and_scroll(void)
 
                    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);
 
                    wrefresh(neww->wind);
+               } else {
+                   failed("acs_and_scroll");
                }
                (void) fclose(fp);
            }
@@ -4468,7 +4612,7 @@ mkpanel(short color, int rows, int cols, int tly, int tlx)
            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 | ' ');
        }
@@ -5062,11 +5206,11 @@ panner(WINDOW *pad,
 
            doupdate();
 #if HAVE_GETTIMEOFDAY
+#define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
            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();
@@ -5218,7 +5362,7 @@ flushinp_test(WINDOW *win)
 #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);
@@ -5441,6 +5585,8 @@ tracetrace(unsigned tlevel)
        for (n = 0; t_tbl[n].name != 0; n++)
            need += strlen(t_tbl[n].name) + 2;
        buf = typeMalloc(char, need);
+       if (!buf)
+           failed("tracetrace");
     }
     sprintf(buf, "0x%02x = {", tlevel);
     if (tlevel == 0) {
@@ -5584,7 +5730,7 @@ make_label(int frow, int fcol, NCURSES_CONST char *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);
 }
@@ -5614,10 +5760,9 @@ display_form(FORM * f)
        set_form_sub(f, derwin(w, rows, cols, 1, 2));
        box(w, 0, 0);
        keypad(w, TRUE);
+       if (post_form(f) != E_OK)
+           wrefresh(w);
     }
-
-    if (post_form(f) != E_OK)
-       wrefresh(w);
 }
 
 static void
@@ -5641,55 +5786,60 @@ edit_secure(FIELD * me, int c)
     if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
        && nbuf > 0) {
        char *source = field_buffer(me, 1);
-       char temp[80];
+       size_t have = (source ? strlen(source) : 0) + 1;
+       size_t need = 80 + have;
+       char *temp = malloc(need);
        long len;
 
-       strcpy(temp, source ? source : "");
-       len = (long) (char *) field_userptr(me);
-       if (c <= KEY_MAX) {
-           if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
-               temp[len++] = (char) c;
-               temp[len] = 0;
-               set_field_buffer(me, 1, temp);
-               c = '*';
-           } else {
-               c = 0;
-           }
-       } else {
-           switch (c) {
-           case REQ_BEG_FIELD:
-           case REQ_CLR_EOF:
-           case REQ_CLR_EOL:
-           case REQ_DEL_LINE:
-           case REQ_DEL_WORD:
-           case REQ_DOWN_CHAR:
-           case REQ_END_FIELD:
-           case REQ_INS_CHAR:
-           case REQ_INS_LINE:
-           case REQ_LEFT_CHAR:
-           case REQ_NEW_LINE:
-           case REQ_NEXT_WORD:
-           case REQ_PREV_WORD:
-           case REQ_RIGHT_CHAR:
-           case REQ_UP_CHAR:
-               c = 0;          /* we don't want to do inline editing */
-               break;
-           case REQ_CLR_FIELD:
-               if (len) {
-                   temp[0] = 0;
+       if (temp != 0) {
+           strncpy(temp, source ? source : "", have + 1);
+           len = (long) (char *) field_userptr(me);
+           if (c <= KEY_MAX) {
+               if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
+                   temp[len++] = (char) c;
+                   temp[len] = 0;
                    set_field_buffer(me, 1, temp);
+                   c = '*';
+               } else {
+                   c = 0;
                }
-               break;
-           case REQ_DEL_CHAR:
-           case REQ_DEL_PREV:
-               if (len) {
-                   temp[--len] = 0;
-                   set_field_buffer(me, 1, temp);
+           } else {
+               switch (c) {
+               case REQ_BEG_FIELD:
+               case REQ_CLR_EOF:
+               case REQ_CLR_EOL:
+               case REQ_DEL_LINE:
+               case REQ_DEL_WORD:
+               case REQ_DOWN_CHAR:
+               case REQ_END_FIELD:
+               case REQ_INS_CHAR:
+               case REQ_INS_LINE:
+               case REQ_LEFT_CHAR:
+               case REQ_NEW_LINE:
+               case REQ_NEXT_WORD:
+               case REQ_PREV_WORD:
+               case REQ_RIGHT_CHAR:
+               case REQ_UP_CHAR:
+                   c = 0;      /* we don't want to do inline editing */
+                   break;
+               case REQ_CLR_FIELD:
+                   if (len) {
+                       temp[0] = 0;
+                       set_field_buffer(me, 1, temp);
+                   }
+                   break;
+               case REQ_DEL_CHAR:
+               case REQ_DEL_PREV:
+                   if (len) {
+                       temp[--len] = 0;
+                       set_field_buffer(me, 1, temp);
+                   }
+                   break;
                }
-               break;
            }
+           set_field_userptr(me, (void *) len);
+           free(temp);
        }
-       set_field_userptr(me, (void *) len);
     }
     return c;
 }
@@ -6048,11 +6198,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col)
        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);
-       (void) wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
+       (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD));
        break;
     }
 }
@@ -6385,13 +6535,14 @@ do_single_test(const char c)
     case 'e':
        slk_test();
        break;
-#endif
 
 #if USE_WIDEC_SUPPORT
     case 'E':
        wide_slk_test();
        break;
 #endif
+#endif
+
     case 'f':
        acs_display();
        break;
@@ -6474,6 +6625,7 @@ usage(void)
        ,"  -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
@@ -6486,6 +6638,9 @@ usage(void)
 #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
@@ -6508,7 +6663,7 @@ set_terminal_modes(void)
 }
 
 #ifdef SIGUSR1
-static RETSIGTYPE
+static void
 announce_sig(int sig)
 {
     (void) fprintf(stderr, "Handled signal %d\r\n", sig);
@@ -6672,17 +6827,27 @@ main(int argc, char *argv[])
 
     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':
            assumed_colors = TRUE;
-           sscanf(optarg, "%d,%d", &default_fg, &default_bg);
+           switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
+           case 0:
+               default_fg = COLOR_WHITE;
+               /* FALLTHRU */
+           case 1:
+               default_bg = COLOR_BLACK;
+               break;
+           }
            break;
        case 'd':
            default_colors = TRUE;
            break;
 #endif
+       case 'E':
+           use_env(FALSE);
+           break;
        case 'e':
            my_e_param = atoi(optarg);
 #ifdef NCURSES_VERSION
@@ -6709,7 +6874,12 @@ main(int argc, char *argv[])
            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
@@ -6752,7 +6922,7 @@ main(int argc, char *argv[])
     bkgdset(BLANK);
 
     /* tests, in general, will want these modes */
-    use_colors = monochrome ? FALSE : has_colors();
+    use_colors = (bool) (monochrome ? FALSE : has_colors());
 
     if (use_colors) {
        start_color();
@@ -6763,7 +6933,7 @@ main(int argc, char *argv[])
            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
@@ -6776,6 +6946,8 @@ main(int argc, char *argv[])
        if (can_change_color()) {
            short cp;
            all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
+           if (!all_colors)
+               failed("all_colors");
            for (cp = 0; cp < max_colors; ++cp) {
                color_content(cp,
                              &all_colors[cp].red,