X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=24a2f8779330c06b13c775ad233376b3c4d796ae;hp=ddd054e4d208615903cba4d28144b1b7de52d846;hb=5d8dbcdd9423bf9821db414fd9ec792ccf1f1027;hpb=89175dffb0245ffaa1ffec80373cb9990f8dc7fe diff --git a/test/ncurses.c b/test/ncurses.c index ddd054e4..24a2f877 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * + * Copyright (c) 1998-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 * @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.446 2016/09/17 21:12:04 tom Exp $ +$Id: ncurses.c,v 1.460 2017/09/09 22:52:38 tom Exp $ ***************************************************************************/ @@ -77,7 +77,6 @@ $Id: ncurses.c,v 1.446 2016/09/17 21:12:04 tom Exp $ #ifdef TRACE static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS; -extern unsigned _nc_tracing; #endif #else @@ -142,7 +141,7 @@ extern unsigned _nc_tracing; #define state_unused #endif -#define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real) +#define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real) #define P(string) printw("%s\n", string) @@ -156,6 +155,7 @@ static bool use_colors; /* true if we use colors */ #undef max_pairs static int max_pairs; /* ...and the number of color pairs */ +#if HAVE_COLOR_CONTENT typedef struct { NCURSES_COLOR_T red; NCURSES_COLOR_T green; @@ -163,6 +163,7 @@ typedef struct { } RGB_DATA; static RGB_DATA *all_colors; +#endif static void main_menu(bool); static void failed(const char *s) GCC_NORETURN; @@ -175,29 +176,16 @@ failed(const char *s) 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. - */ -static void -do_h_line(int y, int x, chtype c, int to) -{ - if ((to) > (x)) - MvHLine(y, x, c, (to) - (x)); -} - -static void -do_v_line(int y, int x, chtype c, int to) -{ - if ((to) > (y)) - MvVLine(y, x, c, (to) - (y)); -} - static void Repaint(void) { touchwin(stdscr); +#if HAVE_CURSCR touchwin(curscr); wrefresh(curscr); +#else + wrefresh(stdscr); +#endif } static bool @@ -1312,7 +1300,7 @@ attr_legend(WINDOW *helpwin) "Toggles:"); if (use_colors) { MvWPrintw(helpwin, row++, col, - " f/F/b/F toggle foreground/background background color"); + " f/F/b/B toggle foreground/background background color"); MvWPrintw(helpwin, row++, col, " t/T toggle text/background color attribute"); } @@ -1575,7 +1563,7 @@ attr_getc(int *skip, case CTRL('L'): Repaint(); break; - case '?': + case HELP_KEY_1: if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) { box(helpwin, 0, 0); attr_legend(helpwin); @@ -1925,7 +1913,7 @@ wide_attr_getc(int *skip, case CTRL('L'): Repaint(); break; - case '?': + case HELP_KEY_1: if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) { box_set(helpwin, 0, 0); attr_legend(helpwin); @@ -2387,7 +2375,7 @@ color_test(void) } } break; - case '?': + case HELP_KEY_1: if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) { box(helpwin, 0, 0); color_legend(helpwin, FALSE); @@ -2623,7 +2611,7 @@ wide_color_test(void) } } break; - case '?': + case HELP_KEY_1: if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) { box(helpwin, 0, 0); color_legend(helpwin, TRUE); @@ -2645,6 +2633,7 @@ wide_color_test(void) } #endif /* USE_WIDEC_SUPPORT */ +#if HAVE_COLOR_CONTENT static void change_color(NCURSES_PAIRS_T current, int field, int value, int usebase) { @@ -2928,7 +2917,7 @@ color_edit(void) change_color((NCURSES_PAIRS_T) current, field, value, 0); break; - case '?': + case HELP_KEY_1: erase(); P(" RGB Value Editing Help"); P(""); @@ -2991,6 +2980,7 @@ color_edit(void) endwin(); } +#endif /* HAVE_COLOR_CONTENT */ /**************************************************************************** * @@ -3172,7 +3162,7 @@ slk_test(void) case 's': MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: "); while ((c = Getchar()) != 'Q' && (c != ERR)) - addch((chtype) c); + AddCh(c); break; case 'd': @@ -3292,7 +3282,7 @@ wide_slk_test(void) case 's': MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: "); while ((c = Getchar()) != 'Q' && (c != ERR)) - addch((chtype) c); + AddCh(c); break; case 'd': @@ -3424,7 +3414,7 @@ show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair) int col = (int) (5 * (code % 16)); IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair))); for (count = 1; count < repeat; ++count) { - addch(colored_chtype(code, attr, pair)); + AddCh(colored_chtype(code, attr, pair)); } } @@ -3468,7 +3458,7 @@ show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_ if (C1) { /* (yes, this _is_ crude) */ while ((reply = Getchar()) != ERR) { - addch(UChar(reply)); + AddCh(UChar(reply)); napms(10); } nodelay(stdscr, FALSE); @@ -3513,7 +3503,7 @@ show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair) */ break; default: - addch(colored_chtype(code, A_ALTCHARSET | attr, pair)); + AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair)); break; } } while (--count > 0); @@ -3562,7 +3552,7 @@ show_1_acs(int n, int repeat, const char *name, chtype code) MvPrintw(row, col, "%*s : ", COLS / 4, name); do { - addch(code); + AddCh(code); } while (--repeat > 0); return n + 1; } @@ -3796,7 +3786,7 @@ show_paged_widechars(int base, setcchar(&temp, codes, attr, pair, 0); move(row, col); if (wcwidth(code) == 0 && code != 0) { - addch((chtype) space | + AddCh((chtype) space | (A_REVERSE ^ attr) | (attr_t) COLOR_PAIR(pair)); } @@ -3843,7 +3833,7 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIR * the display. */ if (wcwidth(code) == 0) { - addch((chtype) space | + AddCh((chtype) space | (A_REVERSE ^ attr) | (attr_t) COLOR_PAIR(pair)); } @@ -3984,7 +3974,7 @@ show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair) n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE)); n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND)); n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS)); - n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS)); + n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS)); #ifdef CURSES_WACS_ARRAY n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL)); @@ -4045,7 +4035,7 @@ show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair) n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE)); n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND)); n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS)); - n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS)); + n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS)); #ifdef CURSES_WACS_ARRAY n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL)); @@ -4551,8 +4541,8 @@ selectcell(int uli, int ulj, int lri, int lrj) break; } } - /* FALLTHRU */ #endif + /* FALLTHRU */ default: res.y = uli + i; res.x = ulj + j; @@ -4653,7 +4643,7 @@ delete_framed(FRAME * fp, bool showit) } delwin(fp->wind); - np = (fp == fp->next) ? 0 : fp->next; + np = (fp == fp->next) ? NULL : fp->next; free(fp); } return np; @@ -4990,7 +4980,7 @@ mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx) rmpanel(pan) --------------------------------------------------------------------------*/ static void -rmpanel(PANEL * pan) +rmpanel(PANEL *pan) { WINDOW *win = panel_window(pan); del_panel(pan); @@ -5022,7 +5012,7 @@ init_panel(WINDOW *win) } static void -fill_panel(PANEL * pan) +fill_panel(PANEL *pan) { WINDOW *win = panel_window(pan); const char *userptr = (const char *) panel_userptr(pan); @@ -5059,7 +5049,7 @@ init_wide_panel(WINDOW *win) } static void -fill_wide_panel(PANEL * pan) +fill_wide_panel(PANEL *pan) { WINDOW *win = panel_window(pan); const char *userptr = (const char *) panel_userptr(pan); @@ -5082,7 +5072,7 @@ fill_wide_panel(PANEL * pan) #define MAX_PANELS 5 static void -canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd) +canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd) { int which = cmd[1] - '0'; @@ -5256,6 +5246,25 @@ demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *)) * ****************************************************************************/ +#if HAVE_NEWPAD + +/* The behavior of mvhline, mvvline for negative/zero length is unspecified, + * though we can rely on negative x/y values to stop the macro. + */ +static void +do_h_line(int y, int x, chtype c, int to) +{ + if ((to) > (x)) + MvHLine(y, x, c, (to) - (x)); +} + +static void +do_v_line(int y, int x, chtype c, int to) +{ + if ((to) > (y)) + MvVLine(y, x, c, (to) - (y)); +} + #define GRIDSIZE 3 static bool pending_pan = FALSE; @@ -5372,8 +5381,8 @@ panner(WINDOW *pad, erase(); /* FALLTHRU */ - case '?': - if (c == '?') + case HELP_KEY_1: + if (c == HELP_KEY_1) show_panner_legend = !show_panner_legend; panner_legend(LINES - 4); panner_legend(LINES - 3); @@ -5704,6 +5713,7 @@ demo_pad(bool colored) endwin(); erase(); } +#endif /* HAVE_NEWPAD */ /**************************************************************************** * @@ -6128,7 +6138,7 @@ make_field(int frow, int fcol, int rows, int cols, bool secure) } static void -display_form(FORM * f) +display_form(FORM *f) { WINDOW *w; int rows, cols; @@ -6146,7 +6156,7 @@ display_form(FORM * f) } static void -erase_form(FORM * f) +erase_form(FORM *f) { WINDOW *w = form_win(f); WINDOW *s = form_sub(f); @@ -6159,7 +6169,7 @@ erase_form(FORM * f) } static int -edit_secure(FIELD * me, int c) +edit_secure(FIELD *me, int c) { int rows, cols, frow, fcol, nrow, nbuf; @@ -6225,7 +6235,7 @@ edit_secure(FIELD * me, int c) } static int -form_virtualize(FORM * f, WINDOW *w) +form_virtualize(FORM *f, WINDOW *w) { /* *INDENT-OFF* */ static const struct { @@ -6332,7 +6342,7 @@ form_virtualize(FORM * f, WINDOW *w) } static int -my_form_driver(FORM * form, int c) +my_form_driver(FORM *form, int c) { if (c == (MAX_FORM_COMMAND + 1) && form_driver(form, REQ_VALIDATION) == E_OK) @@ -6520,6 +6530,7 @@ demo_forms(void) * ****************************************************************************/ +#if HAVE_COPYWIN /* ...and overlay, overwrite */ static void fillwin(WINDOW *win, char ch) { @@ -6850,7 +6861,7 @@ overlap_test(void) state = overlap_help(state, flavor); break; - case '?': + case HELP_KEY_1: state = overlap_help(state, flavor); break; @@ -6862,10 +6873,11 @@ overlap_test(void) delwin(win2); delwin(win1); erase(); - curs_set(1); - endwin(); + exit_curses(); } +#endif /* HAVE_COPYWIN */ + static void show_setting_name(const char *name) { @@ -6883,7 +6895,7 @@ show_string_setting(const char *name, const char *value) addstr(""); attroff(A_REVERSE); } - addch('\n'); + AddCh('\n'); } static void @@ -6897,7 +6909,7 @@ show_number_setting(const char *name, int value) printw("%d", value); attroff(A_REVERSE); } - addch('\n'); + AddCh('\n'); } static void @@ -6911,7 +6923,7 @@ show_boolean_setting(const char *name, int value) printw("%d", value); attroff(A_REVERSE); } - addch('\n'); + AddCh('\n'); } static void @@ -6945,7 +6957,7 @@ show_settings(void) show_boolean_setting("has_il", has_il()); Pause(); erase(); - endwin(); + exit_curses(); } /**************************************************************************** @@ -6995,6 +7007,7 @@ do_single_test(const char c) break; #endif +#if HAVE_COLOR_CONTENT case 'd': if (!use_colors) Cannot("does not support color."); @@ -7003,6 +7016,7 @@ do_single_test(const char c) else color_edit(); break; +#endif #if USE_SOFTKEYS case 'e': @@ -7056,6 +7070,7 @@ do_single_test(const char c) break; #endif +#if HAVE_NEWPAD case 'p': demo_pad(FALSE); break; @@ -7063,6 +7078,7 @@ do_single_test(const char c) case 'P': demo_pad(TRUE); break; +#endif #if USE_LIBFORM case 'r': @@ -7070,9 +7086,11 @@ do_single_test(const char c) break; #endif +#if HAVE_COPYWIN case 's': overlap_test(); break; +#endif #if USE_LIBMENU && defined(TRACE) case 't': @@ -7117,7 +7135,9 @@ usage(void) ," -h rip-off header line (can repeat)" #endif ," -m do not use colors" +#if HAVE_COLOR_CONTENT ," -p file rgb values to use in 'd' rather than ncurses's builtin" +#endif #if USE_LIBPANEL ," -s msec specify nominal time for panel-demo (default: 1, to hold)" #endif @@ -7127,7 +7147,9 @@ usage(void) #ifdef TRACE ," -t mask specify default trace-level (may toggle with ^T)" #endif +#if HAVE_COLOR_CONTENT ," -x use xterm-compatible control for reading color palette" +#endif }; size_t n; for (n = 0; n < SIZEOF(tbl); n++) @@ -7197,8 +7219,10 @@ main_menu(bool top) #if USE_WIDEC_SUPPORT (void) puts("C = color test pattern using wide-character calls"); #endif +#if HAVE_COLOR_CONTENT if (top) (void) puts("d = edit RGB color values"); +#endif #if USE_SOFTKEYS (void) puts("e = exercise soft keys"); #if USE_WIDEC_SUPPORT @@ -7221,13 +7245,17 @@ main_menu(bool top) (void) puts("O = exercise panels with wide-characters"); #endif #endif +#if HAVE_NEWPAD (void) puts("p = exercise pad features"); (void) puts("P = exercise pad features, using color"); +#endif (void) puts("q = quit"); #if USE_LIBFORM (void) puts("r = exercise forms code"); #endif +#if HAVE_COPYWIN (void) puts("s = overlapping-refresh test"); +#endif #if USE_LIBMENU && defined(TRACE) (void) puts("t = set trace level"); #endif @@ -7305,9 +7333,11 @@ main(int argc, char *argv[]) bool assumed_colors = FALSE; bool default_colors = FALSE; #endif - char *palette_file = 0; bool monochrome = FALSE; +#if HAVE_COLOR_CONTENT bool xterm_colors = FALSE; + char *palette_file = 0; +#endif setlocale(LC_ALL, ""); @@ -7355,9 +7385,11 @@ main(int argc, char *argv[]) case 'm': monochrome = TRUE; break; +#if HAVE_COLOR_CONTENT case 'p': palette_file = optarg; break; +#endif #if USE_LIBPANEL case 's': nap_msec = (int) atol(optarg); @@ -7373,9 +7405,11 @@ main(int argc, char *argv[]) save_trace = (unsigned) strtol(optarg, 0, 0); break; #endif +#if HAVE_COLOR_CONTENT case 'x': xterm_colors = TRUE; break; +#endif default: usage(); } @@ -7435,9 +7469,11 @@ main(int argc, char *argv[]) #endif max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */ +#if HAVE_COLOR_CONTENT if (can_change_color()) { init_all_colors(xterm_colors, palette_file); } +#endif } /*