X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fnewdemo.c;h=d76523ab6ffda5c7930f8f224fdc21fdbd820d4d;hp=f9b6f82f6038099c042f88b03055bc4e8bb45bdc;hb=9b4c4abadc0a29999c5ddad5aa8d769fee28d687;hpb=73b54c0812e4b8dfddcf87f59c7488bb3c10e10d;ds=inline diff --git a/test/newdemo.c b/test/newdemo.c index f9b6f82f..d76523ab 100644 --- a/test/newdemo.c +++ b/test/newdemo.c @@ -2,7 +2,7 @@ * newdemo.c - A demo program using PDCurses. The program illustrate * the use of colours for text output. * - * $Id: newdemo.c,v 1.41 2014/08/02 23:10:56 tom Exp $ + * $Id: newdemo.c,v 1.47 2019/12/14 23:25:29 tom Exp $ */ #include @@ -50,7 +50,7 @@ static const char *messages[] = static void trap(int sig GCC_UNUSED) { - endwin(); + stop_curses(); ExitProgram(EXIT_FAILURE); } @@ -61,11 +61,12 @@ static int 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; @@ -221,18 +222,14 @@ int main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) { WINDOW *win; - int w, x, y, i, j, k; + int x, y, i, k; char buffer[SIZEOF(messages) * 80]; - const char *message; int width, height; chtype save[80]; - chtype c; setlocale(LC_ALL, ""); - CATCHALL(trap); - - initscr(); + InitAndCatch(initscr(), trap); if (has_colors()) start_color(); cbreak(); @@ -241,11 +238,16 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) 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); @@ -299,11 +301,11 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) 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) @@ -360,6 +362,6 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) if (WaitForUser(win) == 1) break; } - endwin(); + stop_curses(); ExitProgram(EXIT_SUCCESS); }