* newdemo.c - A demo program using PDCurses. The program illustrate
* the use of colours for text output.
*
- * $Id: newdemo.c,v 1.36 2012/06/09 19:17:29 tom Exp $
+ * $Id: newdemo.c,v 1.47 2019/12/14 23:25:29 tom Exp $
*/
#include <test.priv.h>
/*
* Trap interrupt
*/
-static RETSIGTYPE
+static void
trap(int sig GCC_UNUSED)
{
- endwin();
+ stop_curses();
ExitProgram(EXIT_FAILURE);
}
WaitForUser(WINDOW *win)
{
time_t t;
- chtype key;
nodelay(win, TRUE);
t = time((time_t *) 0);
+
while (1) {
+ chtype key;
if ((int) (key = (chtype) wgetch(win)) != ERR) {
if (key == 'q' || key == 'Q')
return 1;
if (pair > COLOR_PAIRS)
pair = COLOR_PAIRS;
init_pair((short) pair, (short) foreground, (short) background);
- (void) wattrset(win, (int) COLOR_PAIR(pair));
+ (void) wattrset(win, AttrArg(COLOR_PAIR(pair), 0));
}
}
pair = COLOR_PAIRS;
attrs |= (chtype) COLOR_PAIR(pair);
}
- (void) wattrset(win, (int) attrs);
+ (void) wattrset(win, AttrArg(attrs, 0));
return attrs;
}
getbegyx(win, by, bx);
sw = w / 3;
sh = h / 3;
- if ((swin1 = subwin(win, sh, sw, by + 3, bx + 5)) == NULL)
+
+ if ((swin1 = subwin(win, sh, sw, by + 3, bx + 5)) == NULL) {
return 1;
- if ((swin2 = subwin(win, sh, sw, by + 4, bx + 8)) == NULL)
+ }
+ if ((swin2 = subwin(win, sh, sw, by + 4, bx + 8)) == NULL) {
+ delwin(swin1);
return 1;
- if ((swin3 = subwin(win, sh, sw, by + 5, bx + 11)) == NULL)
+ }
+ if ((swin3 = subwin(win, sh, sw, by + 5, bx + 11)) == NULL) {
+ delwin(swin1);
+ delwin(swin2);
return 1;
+ }
set_colors(swin1, 8, COLOR_RED, COLOR_BLUE);
werase(swin1);
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
WINDOW *win;
- int w, x, y, i, j, k;
- char buffer[200];
- const char *message;
+ int x, y, i, k;
+ char buffer[SIZEOF(messages) * 80];
int width, height;
chtype save[80];
- chtype c;
setlocale(LC_ALL, "");
- CATCHALL(trap);
-
- initscr();
+ InitAndCatch(initscr(), trap);
if (has_colors())
start_color();
cbreak();
height = 14; /* Create a drawing window */
win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
if (win == NULL) {
- endwin();
+ stop_curses();
ExitProgram(EXIT_FAILURE);
}
while (1) {
+ int w;
+ int j;
+ chtype c;
+ const char *message;
+
set_colors(win, 1, COLOR_WHITE, COLOR_BLUE);
werase(win);
message = messages[j = 0];
i = 1;
w = width - 2;
- strcpy(buffer, message);
+ _nc_STRCPY(buffer, message, sizeof(buffer));
while (j < NMESSAGES) {
while ((int) strlen(buffer) < w) {
- strcat(buffer, " ... ");
- strcat(buffer, messages[++j % NMESSAGES]);
+ _nc_STRCAT(buffer, " ... ", sizeof(buffer));
+ _nc_STRCAT(buffer, messages[++j % NMESSAGES], sizeof(buffer));
}
if (i < w)
if (WaitForUser(win) == 1)
break;
}
- endwin();
+ stop_curses();
ExitProgram(EXIT_SUCCESS);
}