1 /****************************************************************************
2 * Copyright 2020,2022 Thomas E. Dickey *
3 * Copyright 1998-2013,2014 Free Software Foundation, Inc. *
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: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
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. *
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 *
28 ****************************************************************************/
30 * This is an example written by Alexander V. Lukyanov <lav@yars.free.net>,
31 * to demonstrate an inconsistency between ncurses and SVr4 curses.
33 * $Id: testaddch.c,v 1.15 2022/12/10 23:44:18 tom Exp $
35 #include <test.priv.h>
38 attr_addstr(const char *s, chtype a)
41 addch(((unsigned char) (*s++)) | a);
47 static const char *msg[] =
49 "Usage: testaddch [options]"
55 for (n = 0; n < SIZEOF(msg); n++)
56 fprintf(stderr, "%s\n", msg[n]);
58 ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
65 main(int argc, char *argv[])
68 chtype back, set, attr;
71 while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
75 ExitProgram(EXIT_SUCCESS);
77 usage(ch == OPTS_USAGE);
84 setlocale(LC_ALL, "");
88 init_pair(1, COLOR_WHITE, COLOR_BLUE);
89 init_pair(2, COLOR_WHITE, COLOR_RED);
90 init_pair(3, COLOR_BLACK, COLOR_MAGENTA);
91 init_pair(4, COLOR_BLACK, COLOR_GREEN);
92 init_pair(5, COLOR_BLACK, COLOR_CYAN);
93 init_pair(6, COLOR_BLACK, COLOR_YELLOW);
94 init_pair(7, COLOR_BLACK, COLOR_WHITE);
96 for (i = 0; i < 8; i++) {
97 back = (i & 1) ? A_BOLD | 'B' : ' ';
98 set = (i & 2) ? A_REVERSE : 0;
99 attr = (chtype) ((i & 4) ? COLOR_PAIR(4) : 0);
102 (void) attrset(AttrArg(set, 0));
104 attr_addstr("Test string with spaces -> <-\n", attr);
107 for (i = 0; i < 8; i++) {
108 back = (i & 1) ? (A_BOLD | 'B' | (chtype) COLOR_PAIR(1)) : ' ';
109 set = (i & 2) ? (A_REVERSE | (chtype) COLOR_PAIR(2)) : 0;
110 attr = (chtype) ((i & 4) ? (chtype) COLOR_PAIR(4) : 0);
113 (void) attrset(AttrArg(set, 0));
115 attr_addstr("Test string with spaces -> <-\n", attr);
120 ExitProgram(EXIT_SUCCESS);