]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/test_add_wchstr.c
ncurses 6.0 - patch 20170603
[ncurses.git] / test / test_add_wchstr.c
index 78c8f37141a22e7328d16f843b1d17a07880b362..3e7f1bafcd80ab1b5a56db5a278b7811c778be78 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2009,2010 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2009-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            *
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: test_add_wchstr.c,v 1.13 2010/12/25 22:49:28 tom Exp $
+ * $Id: test_add_wchstr.c,v 1.26 2017/04/15 15:15:25 tom Exp $
  *
  * Demonstrate the waddwchstr() and wadd_wch functions.
  * Thomas Dickey - 2009/9/12
 #define WIDE_LINEDATA
 #include <linedata.h>
 
+#undef AddCh
 #undef MvAddCh
 #undef MvAddStr
 #undef MvWAddCh
+#undef MvWAddChStr
 #undef MvWAddStr
+#undef WAddCh
 
-/* definitions to make it simpler to compare with test_addstr.c */
+/*
+ * redefinitions to simplify comparison between test_*str programs
+ */
 #define AddNStr    add_wchnstr
 #define AddStr     add_wchstr
 #define MvAddNStr  (void) mvadd_wchnstr
 #define MvAddStr   (void) mvadd_wchstr
 #define MvWAddNStr (void) mvwadd_wchnstr
 #define MvWAddStr  (void) mvwadd_wchstr
+#define MvWAddChStr(w,y,x,s)   (void) mvwadd_wchstr((w),(y),(x),(s))
 #define WAddNStr   wadd_wchnstr
 #define WAddStr    wadd_wchstr
 
@@ -90,6 +96,8 @@ static size_t temp_length;
        if (need > temp_length) { \
            temp_length = need * 2; \
            temp_buffer = typeRealloc(cchar_t, temp_length, temp_buffer); \
+           if (!temp_buffer) \
+               failed("TempBuffer"); \
        } \
        have[0] = 0; \
        have[1] = 0; \
@@ -101,7 +109,7 @@ static size_t temp_length;
             && (temp = unctrl((chtype) have[0])) != 0 \
             && strlen(temp) > 1) { \
                while (*temp != '\0') { \
-                   have[0] = *temp++; \
+                   have[0] = (wchar_t) *temp++; \
                    setcchar(&temp_buffer[n++], have, A_NORMAL, 0, NULL); \
                } \
            } else { \
@@ -123,7 +131,7 @@ ChWLen(const wchar_t *source)
     if (!pass_ctls) {
        size_t adjust = 0;
        size_t n;
-       NCURSES_CONST char *s;
+       const char *s;
 
        for (n = 0; n < result; ++n) {
            if (source[n] < 256 && (s = unctrl((chtype) source[n])) != 0) {
@@ -208,7 +216,7 @@ ColOf(wchar_t *buffer, int length, int margin)
            result += 2;
            break;
        default:
-           result += wcwidth(ch);
+           result += wcwidth((wchar_t) ch);
            if (ch < 32)
                ++result;
            break;
@@ -289,7 +297,7 @@ AddCh(chtype ch)
 
 #define LEN(n) ((length - (n) > n_opt) ? n_opt : (length - (n)))
 static void
-test_add_wchstr(int level)
+recursive_test(int level)
 {
     static bool first = TRUE;
 
@@ -304,19 +312,33 @@ test_add_wchstr(int level)
     WINDOW *work = 0;
     WINDOW *show = 0;
     int margin = (2 * MY_TABSIZE) - 1;
-    Options option = ((m_opt ? oMove : oDefault)
-                     | ((w_opt || (level > 0)) ? oWindow : oDefault));
+    Options option = (Options) ((unsigned) (m_opt
+                                           ? oMove
+                                           : oDefault)
+                               | (unsigned) ((w_opt || (level > 0))
+                                             ? oWindow
+                                             : oDefault));
 
     if (first) {
        static char cmd[80];
        setlocale(LC_ALL, "");
 
-       putenv(strcpy(cmd, "TABSIZE=8"));
+       _nc_STRCPY(cmd, "TABSIZE=8", sizeof(cmd));
+       putenv(cmd);
 
        initscr();
        (void) cbreak();        /* take input chars one at a time, no wait for \n */
        (void) noecho();        /* don't echo input */
        keypad(stdscr, TRUE);
+
+       /*
+        * Show the characters added in color, to distinguish from those that
+        * are shifted.
+        */
+       if (has_colors()) {
+           start_color();
+           init_pair(1, COLOR_WHITE, COLOR_BLUE);
+       }
     }
 
     limit = LINES - 5;
@@ -340,8 +362,8 @@ test_add_wchstr(int level)
     MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2);
     limit /= 2;
 
-    (void) mvwadd_wchstr(work, 1, 2, ChStr("String"));
-    (void) mvwadd_wchstr(work, limit + 1, 2, ChStr("Chars"));
+    MvWAddChStr(work, 1, 2, ChStr("String"));
+    MvWAddChStr(work, limit + 1, 2, ChStr("Chars"));
     wnoutrefresh(work);
 
     buffer[length = 0] = '\0';
@@ -350,27 +372,23 @@ test_add_wchstr(int level)
 
     doupdate();
 
-    /*
-     * Show the characters added in color, to distinguish from those that
-     * are shifted.
-     */
     if (has_colors()) {
-       start_color();
-       init_pair(1, COLOR_WHITE, COLOR_BLUE);
-       wbkgdset(work, COLOR_PAIR(1) | ' ');
+       wbkgdset(work, (chtype) (COLOR_PAIR(1) | ' '));
     }
 
     while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) {
        wmove(work, row, margin + 1);
        switch (ch) {
        case key_RECUR:
-           test_add_wchstr(level + 1);
+           recursive_test(level + 1);
 
-           touchwin(look);
+           if (look)
+               touchwin(look);
            touchwin(work);
            touchwin(show);
 
-           wnoutrefresh(look);
+           if (look)
+               wnoutrefresh(look);
            wnoutrefresh(work);
            wnoutrefresh(show);
 
@@ -461,7 +479,7 @@ test_add_wchstr(int level)
            }
            break;
        default:
-           buffer[length++] = ch;
+           buffer[length++] = (wchar_t) ch;
            buffer[length] = '\0';
 
            /* put the string in, one character at a time */
@@ -514,8 +532,8 @@ test_add_wchstr(int level)
            break;
        }
     }
+    delwin(show);
     if (level > 0) {
-       delwin(show);
        delwin(work);
        delwin(look);
     }
@@ -575,8 +593,11 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
     if (optind < argc)
        usage();
 
-    test_add_wchstr(0);
+    recursive_test(0);
     endwin();
+#if NO_LEAKS
+    free(temp_buffer);
+#endif
     ExitProgram(EXIT_SUCCESS);
 }
 #else