]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/newdemo.c
ncurses 6.1 - patch 20191102
[ncurses.git] / test / newdemo.c
index a15e16966f5e96a21d1373e1d534aaac1587518d..04c52751c570814d90b4f96e635e66022c9e971c 100644 (file)
@@ -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.33 2010/05/01 19:07:34 tom Exp $
+ * $Id: newdemo.c,v 1.46 2019/08/24 23:02:49 tom Exp $
  */
 
 #include <test.priv.h>
@@ -33,7 +33,7 @@ static CONST_MENUS char *AusMap[16] =
  */
 #define NMESSAGES   6
 
-static NCURSES_CONST char *messages[] =
+static const char *messages[] =
 {
     "Hello from the Land Down Under",
     "The Land of crocs. and a big Red Rock",
@@ -47,10 +47,10 @@ static NCURSES_CONST char *messages[] =
 /*
  *  Trap interrupt
  */
-static RETSIGTYPE
+static void
 trap(int sig GCC_UNUSED)
 {
-    endwin();
+    exit_curses();
     ExitProgram(EXIT_FAILURE);
 }
 
@@ -61,12 +61,13 @@ static int
 WaitForUser(WINDOW *win)
 {
     time_t t;
-    chtype key;
 
     nodelay(win, TRUE);
     t = time((time_t *) 0);
+
     while (1) {
-       if ((int) (key = wgetch(win)) != ERR) {
+       chtype key;
+       if ((int) (key = (chtype) wgetch(win)) != ERR) {
            if (key == 'q' || key == 'Q')
                return 1;
            else
@@ -83,8 +84,8 @@ set_colors(WINDOW *win, int pair, int foreground, int background)
     if (has_colors()) {
        if (pair > COLOR_PAIRS)
            pair = COLOR_PAIRS;
-       init_pair(pair, foreground, background);
-       (void) wattrset(win, COLOR_PAIR(pair));
+       init_pair((short) pair, (short) foreground, (short) background);
+       (void) wattrset(win, AttrArg(COLOR_PAIR(pair), 0));
     }
 }
 
@@ -94,9 +95,9 @@ use_colors(WINDOW *win, int pair, chtype attrs)
     if (has_colors()) {
        if (pair > COLOR_PAIRS)
            pair = COLOR_PAIRS;
-       attrs |= COLOR_PAIR(pair);
+       attrs |= (chtype) COLOR_PAIR(pair);
     }
-    (void) wattrset(win, attrs);
+    (void) wattrset(win, AttrArg(attrs, 0));
     return attrs;
 }
 
@@ -113,12 +114,19 @@ SubWinTest(WINDOW *win)
     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);
@@ -214,18 +222,14 @@ int
 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();
@@ -234,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();
+       exit_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);
 
@@ -292,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)
@@ -321,10 +330,10 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
        set_colors(win, 7, COLOR_RED, COLOR_GREEN);
        memset(save, ' ', sizeof(save));
        for (i = 2; i < width - 4; ++i) {
-           k = mvwinch(win, 4, i);
+           k = (int) mvwinch(win, 4, i);
            if (k == ERR)
                break;
-           save[j++] = c = k;
+           save[j++] = c = (chtype) k;
            c &= A_CHARTEXT;
            MvWAddCh(win, 4, i, c);
        }
@@ -353,6 +362,6 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
        if (WaitForUser(win) == 1)
            break;
     }
-    endwin();
+    exit_curses();
     ExitProgram(EXIT_SUCCESS);
 }