X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fncurses.c;h=ef6e1e481373155fb1647ab01d1175cb5fadece2;hp=5764dd75c2451d15da18f53507d7077e393995f8;hb=690589d8f19e38925db061296d4f704e4a965bb2;hpb=603f0cb25b7acc8f04f4b18d2a2fe6f90039829a diff --git a/test/ncurses.c b/test/ncurses.c index 5764dd75..ef6e1e48 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.438 2016/06/11 21:05:48 tom Exp $ +$Id: ncurses.c,v 1.453 2017/06/24 20:49:44 tom Exp $ ***************************************************************************/ @@ -77,7 +77,6 @@ $Id: ncurses.c,v 1.438 2016/06/11 21:05:48 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) @@ -165,6 +164,7 @@ typedef struct { static RGB_DATA *all_colors; static void main_menu(bool); +static void failed(const char *s) GCC_NORETURN; static void failed(const char *s) @@ -515,10 +515,15 @@ mouse_decode(MEVENT const *ep) { static char buf[80 + (5 * 10) + (32 * 15)]; - (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {", - ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate); + (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) + "id %2d at (%2d, %2d, %d) state %4lx = {", + ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate); -#define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");} +#define SHOW(m, s) \ + if ((ep->bstate & m)==m) { \ + _nc_STRCAT(buf, s, sizeof(buf)); \ + _nc_STRCAT(buf, ", ", sizeof(buf)); \ + } SHOW(BUTTON1_RELEASED, "release-1"); SHOW(BUTTON1_PRESSED, "press-1"); @@ -574,7 +579,7 @@ mouse_decode(MEVENT const *ep) if (buf[strlen(buf) - 1] == ' ') buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf, "}"); + _nc_STRCAT(buf, "}", sizeof(buf)); return (buf); } @@ -1306,7 +1311,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"); } @@ -1569,7 +1574,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); @@ -1919,7 +1924,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); @@ -2089,14 +2094,17 @@ show_color_name(int y, int x, int color, bool wide) int width = 8; if (wide) { - sprintf(temp, "%02d", color); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "%02d", color); width = 4; } else if (color >= 8) { - sprintf(temp, "[%02d]", color); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "[%02d]", color); } else if (color < 0) { - strcpy(temp, "default"); + _nc_STRCPY(temp, "default", sizeof(temp)); } else { - sprintf(temp, "%.*s", 16, the_color_names[color]); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "%.*s", 16, the_color_names[color]); } printw("%-*.*s", width, width, temp); } @@ -2283,7 +2291,8 @@ color_test(void) attron(A_REVERSE); if (opt_nums) { - sprintf(numbered, "{%02X}", (int) i); + _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1)) + "{%02X}", (int) i); hello = numbered; } printw("%-*.*s", width, width, hello); @@ -2377,7 +2386,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); @@ -2507,7 +2516,9 @@ wide_color_test(void) attr_on(A_REVERSE, NULL); if (opt_nums) { - sprintf(numbered, "{%02X}", i); + _nc_SPRINTF(numbered, + _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t)) + "{%02X}", i); if (opt_xchr) { make_fullwidth_text(buffer, numbered); } else { @@ -2611,7 +2622,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); @@ -2692,7 +2703,8 @@ init_all_colors(bool xterm_colors, char *palette_file) int n; int got; char result[BUFSIZ]; - int check_n, check_r, check_g, check_b; + int check_n; + unsigned check_r, check_g, check_b; raw(); noecho(); @@ -2791,7 +2803,7 @@ color_edit(void) && (i < max_colors); i++) { char numeric[80]; - sprintf(numeric, "[%d]", i); + _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i); MvPrintw(2 + i - top_color, 0, "%c %-8s:", (i == current ? '>' : ' '), (i < (int) SIZEOF(the_color_names) @@ -2915,7 +2927,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(""); @@ -3159,7 +3171,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': @@ -3187,9 +3199,9 @@ slk_test(void) case '7': case '8': MvAddStr(SLK_WORK, 0, "Please enter the label value: "); - strcpy(buf, ""); + _nc_STRCPY(buf, "", sizeof(buf)); if ((s = slk_label(c - '0')) != 0) { - strncpy(buf, s, (size_t) 8); + _nc_STRNCPY(buf, s, (size_t) 8); } wGetstring(stdscr, buf, 8); slk_set((c - '0'), buf, fmt); @@ -3279,7 +3291,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': @@ -3411,7 +3423,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)); } } @@ -3445,7 +3457,7 @@ show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_ 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); + _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code); MvPrintw(row, col, "%*s: ", COLS / 4, tmp); do { @@ -3455,7 +3467,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); @@ -3500,7 +3512,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); @@ -3549,7 +3561,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; } @@ -3783,7 +3795,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)); } @@ -3814,7 +3826,8 @@ show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIR int count = repeat; int y, x; - sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code); + _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) + "%3ld (0x%lx)", (long) code, (long) code); MvPrintw(row, col, "%*s: ", COLS / 4, tmp); memset(&codes, 0, sizeof(codes)); @@ -3829,7 +3842,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)); } @@ -3970,7 +3983,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)); @@ -4031,7 +4044,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)); @@ -4097,7 +4110,8 @@ show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIR MvPrintw(row, col, "%*s : ", COLS / 4, name); (void) attr_set(attr, pair, 0); - addstr(strncpy(temp, code, 20)); + _nc_STRNCPY(temp, code, 20); + addstr(temp); (void) attr_set(A_NORMAL, 0, 0); return n + 1; } @@ -4435,16 +4449,19 @@ newwin_legend(FRAME * curp) for (n = 0; n < SIZEOF(legend); n++) { switch (legend[n].code) { default: - strcpy(buf, legend[n].msg); + _nc_STRCPY(buf, legend[n].msg, sizeof(buf)); break; case 1: - sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no"); + _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) + legend[n].msg, do_keypad ? "yes" : "no"); break; case 2: - sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no"); + _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) + legend[n].msg, do_scroll ? "yes" : "no"); break; case 3: - sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : ""); + _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) + legend[n].msg, do_keypad ? "/ESC" : ""); break; } x = getcurx(stdscr); @@ -4533,8 +4550,8 @@ selectcell(int uli, int ulj, int lri, int lrj) break; } } - /* FALLTHRU */ #endif + /* FALLTHRU */ default: res.y = uli + i; res.x = ulj + j; @@ -4635,7 +4652,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; @@ -4972,7 +4989,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); @@ -5004,7 +5021,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); @@ -5041,7 +5058,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); @@ -5064,7 +5081,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'; @@ -5354,8 +5371,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); @@ -5938,29 +5955,31 @@ static char * tracetrace(unsigned tlevel) { static char *buf; + static size_t need = 12; int n; if (buf == 0) { - size_t need = 12; 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); + _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel); if (tlevel == 0) { - sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name); + _nc_STRCAT(buf, t_tbl[0].name, need); + _nc_STRCAT(buf, ", ", need); } else { for (n = 1; t_tbl[n].name != 0; n++) if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) { - strcat(buf, t_tbl[n].name); - strcat(buf, ", "); + _nc_STRCAT(buf, t_tbl[n].name, need); + _nc_STRCAT(buf, ", ", need); } } if (buf[strlen(buf) - 2] == ',') buf[strlen(buf) - 2] = '\0'; - return (strcat(buf, "}")); + _nc_STRCAT(buf, "}", need); + return buf; } /* fake a dynamically reconfigurable menu using the 0th entry to deselect @@ -6108,7 +6127,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; @@ -6126,7 +6145,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); @@ -6139,7 +6158,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; @@ -6152,7 +6171,7 @@ edit_secure(FIELD * me, int c) size_t len; if (temp != 0) { - strncpy(temp, source ? source : "", have + 1); + _nc_STRNCPY(temp, source ? source : "", have + 1); len = (size_t) (char *) field_userptr(me); if (c <= KEY_MAX) { if (isgraph(c) && (len + 1) < sizeof(temp)) { @@ -6205,7 +6224,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 { @@ -6312,7 +6331,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) @@ -6612,7 +6631,8 @@ overlap_help(int state, int flavors[OVERLAP_FLAVORS]) switch (row) { case 0: flavors[row] = 0; - sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "refresh %s, then %s, then doupdate.", ths, tht); break; case 1: if (use_colors) { @@ -6621,7 +6641,8 @@ overlap_help(int state, int flavors[OVERLAP_FLAVORS]) flavors[row] %= 2; } overlap_test_1_attr(stdscr, flavors[row], col); - sprintf(msg, "fill window %s with letter %s.", ths, ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "fill window %s with letter %s.", ths, ths); break; case 2: if (use_colors) { @@ -6631,37 +6652,46 @@ overlap_help(int state, int flavors[OVERLAP_FLAVORS]) } switch (flavors[row]) { case 0: - sprintf(msg, "cross pattern in window %s.", ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "cross pattern in window %s.", ths); break; case 1: - sprintf(msg, "draw box in window %s.", ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "draw box in window %s.", ths); break; case 2: - sprintf(msg, "set background of window %s.", ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "set background of window %s.", ths); break; case 3: - sprintf(msg, "reset background of window %s.", ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "reset background of window %s.", ths); break; } break; case 3: flavors[row] = 0; - sprintf(msg, "clear window %s.", ths); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "clear window %s.", ths); break; case 4: flavors[row] %= 4; switch (flavors[row]) { case 0: - sprintf(msg, "overwrite %s onto %s.", ths, tht); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "overwrite %s onto %s.", ths, tht); break; case 1: - sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "copywin(FALSE) %s onto %s.", ths, tht); break; case 2: - sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "copywin(TRUE) %s onto %s.", ths, tht); break; case 3: - sprintf(msg, "overlay %s onto %s.", ths, tht); + _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg)) + "overlay %s onto %s.", ths, tht); break; } break; @@ -6819,7 +6849,7 @@ overlap_test(void) state = overlap_help(state, flavor); break; - case '?': + case HELP_KEY_1: state = overlap_help(state, flavor); break; @@ -6835,6 +6865,88 @@ overlap_test(void) endwin(); } +static void +show_setting_name(const char *name) +{ + printw("%-25s ", name); +} + +static void +show_string_setting(const char *name, const char *value) +{ + show_setting_name(name); + if (value) { + printw("\"%s\"", value); + } else { + attron(A_REVERSE); + addstr(""); + attroff(A_REVERSE); + } + AddCh('\n'); +} + +static void +show_number_setting(const char *name, int value) +{ + show_setting_name(name); + if (value >= 0) { + printw("%d", value); + } else { + attron(A_REVERSE); + printw("%d", value); + attroff(A_REVERSE); + } + AddCh('\n'); +} + +static void +show_boolean_setting(const char *name, int value) +{ + show_setting_name(name); + if (value >= 0) { + printw("%s", value ? "TRUE" : "FALSE"); + } else { + attron(A_REVERSE); + printw("%d", value); + attroff(A_REVERSE); + } + AddCh('\n'); +} + +static void +show_settings(void) +{ +#if USE_WIDEC_SUPPORT + wchar_t ch; +#endif + + move(0, 0); + show_string_setting("termname", termname()); + show_string_setting("longname", longname()); + show_number_setting("baudrate", baudrate()); + if (erasechar() > 0) { + show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar())); + show_string_setting("keyname(erasechar)", keyname(erasechar())); + } + if (killchar() > 0) { + show_string_setting("unctrl(killchar)", unctrl((chtype) killchar())); + show_string_setting("keyname(killchar)", keyname(killchar())); + } +#if USE_WIDEC_SUPPORT + if (erasewchar(&ch) == OK) { + show_string_setting("key_name(erasewchar)", key_name(ch)); + } + if (killwchar(&ch) == OK) { + show_string_setting("key_name(killwchar)", key_name(ch)); + } +#endif + show_boolean_setting("has_ic", has_ic()); + show_boolean_setting("has_il", has_il()); + Pause(); + erase(); + endwin(); +} + /**************************************************************************** * * Main sequence @@ -6967,6 +7079,10 @@ do_single_test(const char c) break; #endif + case 'v': + show_settings(); + break; + case '?': break; @@ -7114,6 +7230,7 @@ main_menu(bool top) #if USE_LIBMENU && defined(TRACE) (void) puts("t = set trace level"); #endif + (void) puts("v = show terminal name and settings"); (void) puts("? = repeat this command summary"); (void) fputs("> ", stdout);