X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=f5c78dbe717cdb603dcdf63dfb85ba6ea49f1232;hp=2fd9b7b6e80557aa043aeec13a92d6b6e3aeaea2;hb=173dd870810c8b85baa31f9a272d15f96a8f9ff4;hpb=52aa842907b31bb56fb5133da3f023b45bd4355f;ds=sidebyside diff --git a/test/ncurses.c b/test/ncurses.c index 2fd9b7b6..f5c78dbe 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -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 * @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.362 2010/11/14 01:04:13 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 */ +#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,11 +777,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 +833,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') { @@ -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 (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) { + if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) { static const chtype table[] = { A_STANDOUT, @@ -1671,8 +1686,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); @@ -2577,52 +2592,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,6 +2676,52 @@ 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(int fg, int bg) @@ -2968,7 +2983,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; @@ -3356,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); + (void) y; if (x >= col + (COLS / 2) - 2) break; } while (--count > 0); @@ -4265,8 +4281,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); @@ -5222,7 +5240,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); @@ -6052,11 +6070,11 @@ overlap_test_1_attr(WINDOW *win, int flavor, int col) break; case 2: init_pair(cpair, COLOR_BLUE, COLOR_WHITE); - (void) wattrset(win, (attr_t) 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, (attr_t) COLOR_PAIR(cpair) | A_BOLD); + (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD)); break; } } @@ -6389,13 +6407,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; @@ -6478,6 +6497,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 @@ -6490,6 +6510,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 @@ -6676,7 +6699,7 @@ 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': @@ -6687,6 +6710,9 @@ main(int argc, char *argv[]) default_colors = TRUE; break; #endif + case 'E': + use_env(FALSE); + break; case 'e': my_e_param = atoi(optarg); #ifdef NCURSES_VERSION @@ -6716,6 +6742,11 @@ main(int argc, char *argv[]) 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 case 't': save_trace = (unsigned) strtol(optarg, 0, 0); @@ -6767,7 +6798,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