]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/ncurses.c
ncurses 5.9 - patch 20110820
[ncurses.git] / test / ncurses.c
index 3289ada6f3842b128eb9364dd38d3f955980b403..ea5f5f867dc4079ca421e154f989f1fa42f1f570 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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.359 2010/05/01 22:39:06 tom Exp $
+$Id: ncurses.c,v 1.369 2011/08/20 15:49:08 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
 
@@ -488,7 +490,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 +690,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;
@@ -725,7 +727,7 @@ remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *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)
 {
@@ -739,6 +741,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,6 +777,7 @@ resize_boxes(unsigned level, WINDOW *win)
     }
     doupdate();
 }
+#endif /* resize_boxes */
 #else
 #define forget_boxes()         /* nothing */
 #define remember_boxes(level,text,frame)       /* nothing */
@@ -1390,7 +1394,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 +1538,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 +1546,7 @@ attr_test(void)
                if (init_pair(pair, tx, bg) == ERR) {
                    beep();
                } else {
-                   extras |= COLOR_PAIR(pair);
+                   extras |= (chtype) COLOR_PAIR(pair);
                }
            }
        }
@@ -1671,8 +1675,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 +1831,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);
        }
@@ -2415,7 +2419,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);
 
@@ -2540,6 +2544,8 @@ color_edit(void)
        case 'm':
            endwin();
            main_menu(FALSE);
+           for (i = 0; i < max_colors; i++)
+               init_pair((short) i, (short) COLOR_WHITE, (short) i);
            refresh();
            break;
 
@@ -2575,52 +2581,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
@@ -2705,11 +2665,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();
@@ -3083,7 +3089,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);
@@ -3131,7 +3138,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);
@@ -3337,8 +3344,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.
             */
-           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()).
@@ -4259,8 +4269,10 @@ 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);
 
@@ -4466,7 +4478,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 | ' ');
        }
@@ -5060,11 +5072,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();
@@ -5582,7 +5594,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);
 }
@@ -6046,11 +6058,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, (attr_t) 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, (attr_t) COLOR_PAIR(cpair) | A_BOLD);
        break;
     }
 }
@@ -6383,13 +6395,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;
@@ -6707,7 +6720,7 @@ main(int argc, char *argv[])
            break;
 #if USE_LIBPANEL
        case 's':
-           nap_msec = atol(optarg);
+           nap_msec = (int) atol(optarg);
            break;
 #endif
 #ifdef TRACE
@@ -6761,7 +6774,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