1 /****************************************************************************
2 * Copyright (c) 2007-2017,2019 Free Software Foundation, Inc. *
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: inch_wide.c,v 1.10 2019/08/24 23:11:01 tom Exp $
32 int in_wch(cchar_t *wcval);
33 int mvin_wch(int y, int x, cchar_t *wcval);
34 int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval);
35 int win_wch(WINDOW *win, cchar_t *wcval);
36 int in_wchstr(cchar_t *wchstr);
37 int in_wchnstr(cchar_t *wchstr, int n);
38 int win_wchstr(WINDOW *win, cchar_t *wchstr);
39 int win_wchnstr(WINDOW *win, cchar_t *wchstr, int n);
40 int mvin_wchstr(int y, int x, cchar_t *wchstr);
41 int mvin_wchnstr(int y, int x, cchar_t *wchstr, int n);
42 int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wchstr);
43 int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wchstr, int n);
46 #include <test.priv.h>
47 #include <popup_msg.h>
57 return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
61 test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
63 static const char *help[] =
65 "Test input from screen using inch(), etc., in a moveable viewport.",
69 " h,j,k,l (and arrow-keys) - move viewport",
70 " w - recur to new window",
71 " for next input file",
79 int txt_x = 0, txt_y = 0;
82 cchar_t text[MAX_COLS];
84 if (argv[level] == 0) {
90 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
94 txtwin = derwin(txtbox,
104 keypad(txtwin, TRUE); /* enable keyboard mapping */
105 (void) cbreak(); /* take input chars one at a time, no wait for \n */
106 (void) noecho(); /* don't echo input */
110 wmove(txtwin, txt_y, txt_x);
112 if ((fp = fopen(argv[level], "r")) != 0) {
113 while ((j = fgetc(fp)) != EOF) {
114 if (waddch(txtwin, UChar(j)) != OK) {
120 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
123 while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
129 if (txt_y < getmaxy(txtwin) - 1)
150 if (txt_x < getmaxx(txtwin) - 1)
156 test_inchs(level + 1, argv, chrwin, strwin);
159 wnoutrefresh(txtbox);
162 wnoutrefresh(txtwin);
166 popup_msg(txtwin, help);
173 MvWPrintw(chrwin, 0, 0, "char:");
176 if (txtwin != stdscr) {
177 wmove(txtwin, txt_y, txt_x);
178 if (win_wch(txtwin, &ch) != ERR) {
179 if (wadd_wch(chrwin, &ch) != ERR) {
180 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
181 if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
182 if (wadd_wch(chrwin, &ch) == ERR) {
193 if (in_wch(&ch) != ERR) {
194 if (wadd_wch(chrwin, &ch) != ERR) {
195 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
196 if (mvin_wch(txt_y, j, &ch) != ERR) {
197 if (wadd_wch(chrwin, &ch) == ERR) {
207 wnoutrefresh(chrwin);
209 MvWPrintw(strwin, 0, 0, "text:");
212 limit = getmaxx(strwin) - 5;
214 if (txtwin != stdscr) {
215 wmove(txtwin, txt_y, txt_x);
216 if (win_wchstr(txtwin, text) != ERR) {
217 (void) mvwadd_wchstr(strwin, 0, 5, text);
220 wmove(txtwin, txt_y, txt_x);
221 if (win_wchnstr(txtwin, text, limit) != ERR) {
222 (void) mvwadd_wchstr(strwin, 1, 5, text);
225 if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
226 (void) mvwadd_wchstr(strwin, 2, 5, text);
229 if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
230 (void) mvwadd_wchstr(strwin, 3, 5, text);
234 if (in_wchstr(text) != ERR) {
235 (void) mvwadd_wchstr(strwin, 0, 5, text);
239 if (in_wchnstr(text, limit) != ERR) {
240 (void) mvwadd_wchstr(strwin, 1, 5, text);
243 if (mvin_wchstr(txt_y, txt_x, text) != ERR) {
244 (void) mvwadd_wchstr(strwin, 2, 5, text);
247 if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) {
248 (void) mvwadd_wchstr(strwin, 3, 5, text);
252 wnoutrefresh(strwin);
262 main(int argc, char *argv[])
268 setlocale(LC_ALL, "");
271 fprintf(stderr, "usage: %s file1 [file2 [...]]\n", argv[0]);
277 chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
279 wnoutrefresh(chrbox);
281 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
282 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
284 test_inchs(1, argv, chrwin, strwin);
287 ExitProgram(EXIT_SUCCESS);
293 printf("This program requires the wide-ncurses library\n");
294 ExitProgram(EXIT_FAILURE);