1 /****************************************************************************
2 * Copyright (c) 2007-2012,2017 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: inchs.c,v 1.13 2017/04/15 18:52:10 tom Exp $
31 * Author: Thomas E Dickey
35 chtype winch(WINDOW *win);
36 chtype mvinch(int y, int x);
37 chtype mvwinch(WINDOW *win, int y, int x);
38 int inchstr(chtype *chstr);
39 int inchnstr(chtype *chstr, int n);
40 int winchstr(WINDOW *win, chtype *chstr);
41 int winchnstr(WINDOW *win, chtype *chstr, int n);
42 int mvinchstr(int y, int x, chtype *chstr);
43 int mvinchnstr(int y, int x, chtype *chstr, int n);
44 int mvwinchstr(WINDOW *win, int y, int x, chtype *chstr);
45 int mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n);
48 #include <test.priv.h>
49 #include <popup_msg.h>
61 ExitProgram(EXIT_FAILURE);
67 return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
71 test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
73 static const char *help[] =
75 "Test input from screen using inch(), etc., in a moveable viewport.",
79 " h,j,k,l (and arrow-keys) - move viewport",
80 " w - recur to new window",
87 int txt_x = 0, txt_y = 0;
90 chtype text[MAX_COLS];
92 if (argv[level] == 0) {
98 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
100 wnoutrefresh(txtbox);
102 txtwin = derwin(txtbox,
112 failed("cannot create txtwin");
114 keypad(txtwin, TRUE); /* enable keyboard mapping */
115 (void) cbreak(); /* take input chars one at a time, no wait for \n */
116 (void) noecho(); /* don't echo input */
120 wmove(txtwin, txt_y, txt_x);
122 if ((fp = fopen(argv[level], "r")) != 0) {
123 while ((j = fgetc(fp)) != EOF) {
124 if (waddch(txtwin, UChar(j)) != OK) {
130 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
133 while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
137 if (txt_y < getmaxy(txtwin) - 1)
158 if (txt_x < getmaxx(txtwin) - 1)
164 test_inchs(level + 1, argv, chrwin, strwin);
167 wnoutrefresh(txtbox);
170 wnoutrefresh(txtwin);
174 popup_msg(txtwin, help);
181 MvWPrintw(chrwin, 0, 0, "char:");
184 if (txtwin != stdscr) {
185 wmove(txtwin, txt_y, txt_x);
187 if ((ch = (int) winch(txtwin)) != ERR) {
188 if (waddch(chrwin, (chtype) ch) != ERR) {
189 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
190 if ((ch = (int) mvwinch(txtwin, txt_y, j)) != ERR) {
191 if (waddch(chrwin, (chtype) ch) == ERR) {
203 if ((ch = (int) inch()) != ERR) {
204 if (waddch(chrwin, (chtype) ch) != ERR) {
205 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
206 if ((ch = (int) mvinch(txt_y, j)) != ERR) {
207 if (waddch(chrwin, (chtype) ch) == ERR) {
217 wnoutrefresh(chrwin);
219 MvWPrintw(strwin, 0, 0, "text:");
222 limit = getmaxx(strwin) - 5;
224 if (txtwin != stdscr) {
225 wmove(txtwin, txt_y, txt_x);
226 if (winchstr(txtwin, text) != ERR) {
227 MvWAddChStr(strwin, 0, 5, text);
230 wmove(txtwin, txt_y, txt_x);
231 if (winchnstr(txtwin, text, limit) != ERR) {
232 MvWAddChStr(strwin, 1, 5, text);
235 if (mvwinchstr(txtwin, txt_y, txt_x, text) != ERR) {
236 MvWAddChStr(strwin, 2, 5, text);
239 if (mvwinchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
240 MvWAddChStr(strwin, 3, 5, text);
244 if (inchstr(text) != ERR) {
245 MvWAddChStr(strwin, 0, 5, text);
249 if (inchnstr(text, limit) != ERR) {
250 MvWAddChStr(strwin, 1, 5, text);
253 if (mvinchstr(txt_y, txt_x, text) != ERR) {
254 MvWAddChStr(strwin, 2, 5, text);
257 if (mvinchnstr(txt_y, txt_x, text, limit) != ERR) {
258 MvWAddChStr(strwin, 3, 5, text);
262 wnoutrefresh(strwin);
272 main(int argc, char *argv[])
278 setlocale(LC_ALL, "");
281 fprintf(stderr, "usage: %s file\n", argv[0]);
287 chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
289 wnoutrefresh(chrbox);
291 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
292 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
294 test_inchs(1, argv, chrwin, strwin);
297 ExitProgram(EXIT_SUCCESS);