/****************************************************************************
- * 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 *
Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
Thomas E. Dickey (beginning revision 1.27 in 1996).
-$Id: ncurses.c,v 1.441 2016/08/27 23:43:06 tom Exp $
+$Id: ncurses.c,v 1.453 2017/06/24 20:49:44 tom Exp $
***************************************************************************/
#ifdef TRACE
static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
-extern unsigned _nc_tracing;
#endif
#else
#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)
static RGB_DATA *all_colors;
static void main_menu(bool);
+static void failed(const char *s) GCC_NORETURN;
static void
failed(const char *s)
{
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");
if (buf[strlen(buf) - 1] == ' ')
buf[strlen(buf) - 2] = '\0';
- (void) strcat(buf, "}");
+ _nc_STRCAT(buf, "}", sizeof(buf));
return (buf);
}
"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");
}
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);
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);
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);
}
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);
}
}
break;
- case '?':
+ case HELP_KEY_1:
if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
box(helpwin, 0, 0);
color_legend(helpwin, FALSE);
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 {
}
}
break;
- case '?':
+ case HELP_KEY_1:
if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
box(helpwin, 0, 0);
color_legend(helpwin, TRUE);
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();
&& (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)
change_color((NCURSES_PAIRS_T) current, field, value, 0);
break;
- case '?':
+ case HELP_KEY_1:
erase();
P(" RGB Value Editing Help");
P("");
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':
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);
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':
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));
}
}
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 {
if (C1) {
/* (yes, this _is_ crude) */
while ((reply = Getchar()) != ERR) {
- addch(UChar(reply));
+ AddCh(UChar(reply));
napms(10);
}
nodelay(stdscr, FALSE);
*/
break;
default:
- addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
+ AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
break;
}
} while (--count > 0);
MvPrintw(row, col, "%*s : ", COLS / 4, name);
do {
- addch(code);
+ AddCh(code);
} while (--repeat > 0);
return n + 1;
}
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));
}
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));
* the display.
*/
if (wcwidth(code) == 0) {
- addch((chtype) space |
+ AddCh((chtype) space |
(A_REVERSE ^ attr) |
(attr_t) COLOR_PAIR(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));
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));
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;
}
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);
break;
}
}
- /* FALLTHRU */
#endif
+ /* FALLTHRU */
default:
res.y = uli + i;
res.x = ulj + j;
}
delwin(fp->wind);
- np = (fp == fp->next) ? 0 : fp->next;
+ np = (fp == fp->next) ? NULL : fp->next;
free(fp);
}
return np;
rmpanel(pan)
--------------------------------------------------------------------------*/
static void
-rmpanel(PANEL * pan)
+rmpanel(PANEL *pan)
{
WINDOW *win = panel_window(pan);
del_panel(pan);
}
static void
-fill_panel(PANEL * pan)
+fill_panel(PANEL *pan)
{
WINDOW *win = panel_window(pan);
const char *userptr = (const char *) panel_userptr(pan);
}
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);
#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';
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);
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
}
static void
-display_form(FORM * f)
+display_form(FORM *f)
{
WINDOW *w;
int rows, cols;
}
static void
-erase_form(FORM * f)
+erase_form(FORM *f)
{
WINDOW *w = form_win(f);
WINDOW *s = form_sub(f);
}
static int
-edit_secure(FIELD * me, int c)
+edit_secure(FIELD *me, int c)
{
int rows, cols, frow, fcol, nrow, nbuf;
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)) {
}
static int
-form_virtualize(FORM * f, WINDOW *w)
+form_virtualize(FORM *f, WINDOW *w)
{
/* *INDENT-OFF* */
static const struct {
}
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)
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) {
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) {
}
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;
state = overlap_help(state, flavor);
break;
- case '?':
+ case HELP_KEY_1:
state = overlap_help(state, flavor);
break;
addstr("<NULL>");
attroff(A_REVERSE);
}
- addch('\n');
+ AddCh('\n');
}
static void
printw("%d", value);
attroff(A_REVERSE);
}
- addch('\n');
+ AddCh('\n');
}
static void
printw("%d", value);
attroff(A_REVERSE);
}
- addch('\n');
+ AddCh('\n');
}
static void
show_string_setting("longname", longname());
show_number_setting("baudrate", baudrate());
if (erasechar() > 0) {
- show_string_setting("unctrl(erasechar)", unctrl(erasechar()));
+ show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
show_string_setting("keyname(erasechar)", keyname(erasechar()));
}
if (killchar() > 0) {
- show_string_setting("unctrl(killchar)", unctrl(killchar()));
+ show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
show_string_setting("keyname(killchar)", keyname(killchar()));
}
#if USE_WIDEC_SUPPORT