1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2013,2014 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 /*
30  * This is an example written by Alexander V. Lukyanov <lav@yars.free.net>,
31  * to demonstrate an inconsistency between ncurses and SVr4 curses.
32  *
33  * $Id: testaddch.c,v 1.13 2020/02/02 23:34:34 tom Exp $
34  */
35 #include <test.priv.h>
36 
37 static void
attr_addstr(const char * s,chtype a)38 attr_addstr(const char *s, chtype a)
39 {
40     while (*s)
41 	addch(((unsigned char) (*s++)) | a);
42 }
43 
44 int
main(int argc GCC_UNUSED,char * argv[]GCC_UNUSED)45 main(
46 	int argc GCC_UNUSED,
47 	char *argv[]GCC_UNUSED)
48 {
49     unsigned i;
50     chtype back, set, attr;
51 
52     setlocale(LC_ALL, "");
53 
54     initscr();
55     start_color();
56     init_pair(1, COLOR_WHITE, COLOR_BLUE);
57     init_pair(2, COLOR_WHITE, COLOR_RED);
58     init_pair(3, COLOR_BLACK, COLOR_MAGENTA);
59     init_pair(4, COLOR_BLACK, COLOR_GREEN);
60     init_pair(5, COLOR_BLACK, COLOR_CYAN);
61     init_pair(6, COLOR_BLACK, COLOR_YELLOW);
62     init_pair(7, COLOR_BLACK, COLOR_WHITE);
63 
64     for (i = 0; i < 8; i++) {
65 	back = (i & 1) ? A_BOLD | 'B' : ' ';
66 	set = (i & 2) ? A_REVERSE : 0;
67 	attr = (chtype) ((i & 4) ? COLOR_PAIR(4) : 0);
68 
69 	bkgdset(back);
70 	(void) attrset(AttrArg(set, 0));
71 
72 	attr_addstr("Test string with spaces ->   <-\n", attr);
73     }
74     addch('\n');
75     for (i = 0; i < 8; i++) {
76 	back = (i & 1) ? (A_BOLD | 'B' | (chtype) COLOR_PAIR(1)) : ' ';
77 	set = (i & 2) ? (A_REVERSE | (chtype) COLOR_PAIR(2)) : 0;
78 	attr = (chtype) ((i & 4) ? (chtype) COLOR_PAIR(4) : 0);
79 
80 	bkgdset(back);
81 	(void) attrset(AttrArg(set, 0));
82 
83 	attr_addstr("Test string with spaces ->   <-\n", attr);
84     }
85 
86     getch();
87     endwin();
88     ExitProgram(EXIT_SUCCESS);
89 }
90