1 /****************************************************************************
2 * Copyright 2021 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.17 2021/12/18 21:04:00 tom Exp $
32 #include <test.priv.h>
36 #include <dump_window.h>
37 #include <popup_msg.h>
47 } while (!iswprint((wint_t) value));
56 } while (!iswprint((wint_t) value));
61 do_row(int row, int base_ch, int over_ch)
65 bool reverse = (r_opt && !(row % 2));
68 printw("[U+%04X]", over_ch);
73 attr_t attr = reverse ? A_REVERSE : A_NORMAL;
77 source[0] = (wchar_t) base_ch;
78 setcchar(&target, source, attr, 0, NULL);
81 source[0] = (wchar_t) over_ch;
82 setcchar(&target, source, attr, 0, NULL);
87 data[0] = (wchar_t) base_ch;
88 data[1] = (wchar_t) over_ch;
91 attr_on(A_REVERSE, NULL);
94 attr_off(A_REVERSE, NULL);
96 col = getcurx(stdscr);
97 base_ch = next_char(base_ch);
98 done = (col + 1 >= COLS);
102 #define LAST_OVER 0x6f
107 if (++value > LAST_OVER)
121 do_all(int left_at, int over_it)
125 for (row = 0; row < LINES; ++row) {
126 do_row(row, left_at, 0x300 + over_it);
127 over_it = next_over(over_it);
132 show_help(WINDOW *current)
137 CONST_FMT char * msg;
139 { HELP_KEY_1, "Show this screen" },
140 { CTRL('L'), "Repaint screen" },
141 { '$', "Scroll to end of combining-character range" },
142 { '+', "Scroll to next combining-character in range" },
143 { KEY_DOWN, "(same as \"+\")" },
144 { '-', "Scroll to previous combining-character in range" },
145 { KEY_UP, "(same as \"-\")" },
146 { '0', "Scroll to beginning of combining-character range" },
147 { 'c', "Toggle command-line option \"-c\"" },
148 { 'd', "Dump screen using scr_dump unless \"-l\" option used" },
149 { 'h', "Scroll test-data left one column" },
150 { 'j', "Scroll test-data down one row" },
151 { 'k', "Scroll test-data up one row" },
152 { 'l', "Scroll test-data right one column" },
154 { ESCAPE, "(same as \"q\")" },
155 { QUIT, "(same as \"q\")" },
156 { 'r', "Toggle command-line option \"-r\"" },
160 char **msgs = typeCalloc(char *, SIZEOF(help) + 3);
164 msgs[d++] = strdup("Test diacritic combining-characters range "
166 msgs[d++] = strdup("");
167 for (s = 0; s < SIZEOF(help); ++s) {
168 char *name = strdup(keyname(help[s].key));
169 size_t need = (11 + strlen(name) + strlen(help[s].msg));
170 msgs[d] = typeMalloc(char, need);
171 _nc_SPRINTF(msgs[d], _nc_SLIMIT(need) "%-10s%s", name, help[s].msg);
175 popup_msg2(current, msgs);
176 for (s = 0; msgs[s] != 0; ++s) {
185 static const char *msg[] =
187 "Usage: combine [options]",
189 "Demonstrate combining-characters.",
192 " -c use cchar_t data rather than wchar_t string",
193 " -l FILE log window-dumps to this file",
194 " -r draw even-numbered rows in reverse-video",
197 for (n = 0; n < SIZEOF(msg); ++n) {
198 fprintf(stderr, "%s\n", msg[n]);
200 ExitProgram(EXIT_FAILURE);
204 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
210 bool log_option = FALSE;
211 const char *dump_log = "combine.log";
213 while ((n = getopt(argc, argv, "cl:r")) != -1) {
220 if (!open_dump(optarg))
232 setlocale(LC_ALL, "");
236 keypad(stdscr, TRUE);
239 do_all(left_at, over_it);
260 left_at = prev_char(left_at);
263 left_at = next_char(left_at);
282 over_it = prev_over(over_it);
287 over_it = next_over(over_it);
294 ExitProgram(EXIT_SUCCESS);
300 printf("This program requires wide-curses functions\n");
301 ExitProgram(EXIT_FAILURE);