1 /****************************************************************************
2 * Copyright 2021,2022 Thomas E. Dickey *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: combine.c,v 1.19 2022/05/21 23:19:31 tom Exp $
32 #include <test.priv.h>
37 #include <dump_window.h>
38 #include <popup_msg.h>
48 } while (!iswprint((wint_t) value));
57 } while (!iswprint((wint_t) value));
62 do_row(int row, int base_ch, int over_ch)
66 bool reverse = (r_opt && !(row % 2));
69 printw("[U+%04X]", over_ch);
74 attr_t attr = reverse ? A_REVERSE : A_NORMAL;
78 source[0] = (wchar_t) base_ch;
79 setcchar(&target, source, attr, 0, NULL);
82 source[0] = (wchar_t) over_ch;
83 setcchar(&target, source, attr, 0, NULL);
88 data[0] = (wchar_t) base_ch;
89 data[1] = (wchar_t) over_ch;
92 attr_on(A_REVERSE, NULL);
95 attr_off(A_REVERSE, NULL);
97 col = getcurx(stdscr);
98 base_ch = next_char(base_ch);
99 done = (col + 1 >= COLS);
103 #define LAST_OVER 0x6f
108 if (++value > LAST_OVER)
122 do_all(int left_at, int over_it)
126 for (row = 0; row < LINES; ++row) {
127 do_row(row, left_at, 0x300 + over_it);
128 over_it = next_over(over_it);
133 show_help(WINDOW *current)
138 CONST_FMT char * msg;
140 { HELP_KEY_1, "Show this screen" },
141 { CTRL('L'), "Repaint screen" },
142 { '$', "Scroll to end of combining-character range" },
143 { '+', "Scroll to next combining-character in range" },
144 { KEY_DOWN, "(same as \"+\")" },
145 { '-', "Scroll to previous combining-character in range" },
146 { KEY_UP, "(same as \"-\")" },
147 { '0', "Scroll to beginning of combining-character range" },
148 { 'c', "Toggle command-line option \"-c\"" },
149 { 'd', "Dump screen using scr_dump unless \"-l\" option used" },
150 { 'h', "Scroll test-data left one column" },
151 { 'j', "Scroll test-data down one row" },
152 { 'k', "Scroll test-data up one row" },
153 { 'l', "Scroll test-data right one column" },
155 { ESCAPE, "(same as \"q\")" },
156 { QUIT, "(same as \"q\")" },
157 { 'r', "Toggle command-line option \"-r\"" },
161 char **msgs = typeCalloc(char *, SIZEOF(help) + 3);
165 msgs[d++] = strdup("Test diacritic combining-characters range "
167 msgs[d++] = strdup("");
168 for (s = 0; s < SIZEOF(help); ++s) {
169 char *name = strdup(keyname(help[s].key));
170 size_t need = (11 + strlen(name) + strlen(help[s].msg));
171 msgs[d] = typeMalloc(char, need);
172 _nc_SPRINTF(msgs[d], _nc_SLIMIT(need) "%-10s%s", name, help[s].msg);
176 popup_msg2(current, msgs);
177 for (s = 0; msgs[s] != 0; ++s) {
186 static const char *msg[] =
188 "Usage: combine [options]",
190 "Demonstrate combining-characters.",
193 " -c use cchar_t data rather than wchar_t string",
194 " -l FILE log window-dumps to this file",
195 " -r draw even-numbered rows in reverse-video",
198 for (n = 0; n < SIZEOF(msg); ++n) {
199 fprintf(stderr, "%s\n", msg[n]);
201 ExitProgram(EXIT_FAILURE);
205 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
211 bool log_option = FALSE;
212 const char *dump_log = "combine.log";
214 while ((n = getopt(argc, argv, "cl:r")) != -1) {
221 if (!open_dump(optarg))
233 setlocale(LC_ALL, "");
237 keypad(stdscr, TRUE);
240 do_all(left_at, over_it);
263 left_at = prev_char(left_at);
266 left_at = next_char(left_at);
285 over_it = prev_over(over_it);
290 over_it = next_over(over_it);
297 ExitProgram(EXIT_SUCCESS);
303 printf("This program requires wide-curses functions\n");
304 ExitProgram(EXIT_FAILURE);