1 /****************************************************************************
2 * Copyright 2019,2020 Thomas E. Dickey *
3 * Copyright 2007-2010,2017 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 * $Id: inch_wide.c,v 1.11 2020/02/02 23:34:34 tom Exp $
33 int in_wch(cchar_t *wcval);
34 int mvin_wch(int y, int x, cchar_t *wcval);
35 int mvwin_wch(WINDOW *win, int y, int x, cchar_t *wcval);
36 int win_wch(WINDOW *win, cchar_t *wcval);
37 int in_wchstr(cchar_t *wchstr);
38 int in_wchnstr(cchar_t *wchstr, int n);
39 int win_wchstr(WINDOW *win, cchar_t *wchstr);
40 int win_wchnstr(WINDOW *win, cchar_t *wchstr, int n);
41 int mvin_wchstr(int y, int x, cchar_t *wchstr);
42 int mvin_wchnstr(int y, int x, cchar_t *wchstr, int n);
43 int mvwin_wchstr(WINDOW *win, int y, int x, cchar_t *wchstr);
44 int mvwin_wchnstr(WINDOW *win, int y, int x, cchar_t *wchstr, int n);
47 #include <test.priv.h>
48 #include <popup_msg.h>
58 return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
62 test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
64 static const char *help[] =
66 "Test input from screen using inch(), etc., in a moveable viewport.",
70 " h,j,k,l (and arrow-keys) - move viewport",
71 " w - recur to new window",
72 " for next input file",
80 int txt_x = 0, txt_y = 0;
83 cchar_t text[MAX_COLS];
85 if (argv[level] == 0) {
91 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
95 txtwin = derwin(txtbox,
105 keypad(txtwin, TRUE); /* enable keyboard mapping */
106 (void) cbreak(); /* take input chars one at a time, no wait for \n */
107 (void) noecho(); /* don't echo input */
111 wmove(txtwin, txt_y, txt_x);
113 if ((fp = fopen(argv[level], "r")) != 0) {
114 while ((j = fgetc(fp)) != EOF) {
115 if (waddch(txtwin, UChar(j)) != OK) {
121 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
124 while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
130 if (txt_y < getmaxy(txtwin) - 1)
151 if (txt_x < getmaxx(txtwin) - 1)
157 test_inchs(level + 1, argv, chrwin, strwin);
160 wnoutrefresh(txtbox);
163 wnoutrefresh(txtwin);
167 popup_msg(txtwin, help);
174 MvWPrintw(chrwin, 0, 0, "char:");
177 if (txtwin != stdscr) {
178 wmove(txtwin, txt_y, txt_x);
179 if (win_wch(txtwin, &ch) != ERR) {
180 if (wadd_wch(chrwin, &ch) != ERR) {
181 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
182 if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
183 if (wadd_wch(chrwin, &ch) == ERR) {
194 if (in_wch(&ch) != ERR) {
195 if (wadd_wch(chrwin, &ch) != ERR) {
196 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
197 if (mvin_wch(txt_y, j, &ch) != ERR) {
198 if (wadd_wch(chrwin, &ch) == ERR) {
208 wnoutrefresh(chrwin);
210 MvWPrintw(strwin, 0, 0, "text:");
213 limit = getmaxx(strwin) - 5;
215 if (txtwin != stdscr) {
216 wmove(txtwin, txt_y, txt_x);
217 if (win_wchstr(txtwin, text) != ERR) {
218 (void) mvwadd_wchstr(strwin, 0, 5, text);
221 wmove(txtwin, txt_y, txt_x);
222 if (win_wchnstr(txtwin, text, limit) != ERR) {
223 (void) mvwadd_wchstr(strwin, 1, 5, text);
226 if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
227 (void) mvwadd_wchstr(strwin, 2, 5, text);
230 if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
231 (void) mvwadd_wchstr(strwin, 3, 5, text);
235 if (in_wchstr(text) != ERR) {
236 (void) mvwadd_wchstr(strwin, 0, 5, text);
240 if (in_wchnstr(text, limit) != ERR) {
241 (void) mvwadd_wchstr(strwin, 1, 5, text);
244 if (mvin_wchstr(txt_y, txt_x, text) != ERR) {
245 (void) mvwadd_wchstr(strwin, 2, 5, text);
248 if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) {
249 (void) mvwadd_wchstr(strwin, 3, 5, text);
253 wnoutrefresh(strwin);
263 main(int argc, char *argv[])
269 setlocale(LC_ALL, "");
272 fprintf(stderr, "usage: %s file1 [file2 [...]]\n", argv[0]);
278 chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
280 wnoutrefresh(chrbox);
282 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
283 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
285 test_inchs(1, argv, chrwin, strwin);
288 ExitProgram(EXIT_SUCCESS);
294 printf("This program requires the wide-ncurses library\n");
295 ExitProgram(EXIT_FAILURE);