1 /****************************************************************************
2 * Copyright (c) 2007 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.4 2007/02/11 00:27:12 tom Exp $
33 chtype winch(WINDOW *win);
34 chtype mvinch(int y, int x);
35 chtype mvwinch(WINDOW *win, int y, int x);
36 int inchstr(chtype *chstr);
37 int inchnstr(chtype *chstr, int n);
38 int winchstr(WINDOW *win, chtype *chstr);
39 int winchnstr(WINDOW *win, chtype *chstr, int n);
40 int mvinchstr(int y, int x, chtype *chstr);
41 int mvinchnstr(int y, int x, chtype *chstr, int n);
42 int mvwinchstr(WINDOW *win, int y, int x, chtype *chstr);
43 int mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n);
46 #include <test.priv.h>
53 return (ch == ERR || ch == QUIT || ch == ESCAPE);
57 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
66 int txt_x = 0, txt_y = 0;
68 chtype text[MAX_COLS];
70 setlocale(LC_ALL, "");
73 fprintf(stderr, "usage: %s file\n", argv[0]);
79 chrbox = newwin(7, COLS, 0, 0);
83 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
84 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
86 txtbox = newwin(LINES - 7, COLS, 7, 0);
90 txtwin = derwin(txtbox,
95 keypad(txtwin, TRUE); /* enable keyboard mapping */
96 (void) cbreak(); /* take input chars one at a time, no wait for \n */
97 (void) noecho(); /* don't echo input */
99 if ((fp = fopen(argv[1], "r")) != 0) {
100 while ((ch = fgetc(fp)) != EOF) {
101 if (waddch(txtwin, ch) != OK) {
106 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
109 while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
113 if (txt_y < getmaxy(txtwin) - 1)
134 if (txt_x < getmaxx(txtwin) - 1)
141 wmove(txtwin, txt_y, txt_x);
143 mvwprintw(chrwin, 0, 0, "char:");
145 if ((ch = winch(txtwin)) != ERR) {
146 if (waddch(chrwin, (chtype) ch) != ERR) {
147 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
148 if ((ch = mvwinch(txtwin, txt_y, j)) != ERR) {
149 if (waddch(chrwin, (chtype) ch) == ERR) {
158 wnoutrefresh(chrwin);
160 mvwprintw(strwin, 0, 0, "text:");
163 limit = getmaxx(strwin) - 5;
165 wmove(txtwin, txt_y, txt_x);
166 if (winchstr(txtwin, text) != ERR) {
167 mvwaddchstr(strwin, 0, 5, text);
170 wmove(txtwin, txt_y, txt_x);
171 if (winchnstr(txtwin, text, limit) != ERR) {
172 mvwaddchstr(strwin, 1, 5, text);
175 if (mvwinchstr(txtwin, txt_y, txt_x, text) != ERR) {
176 mvwaddchstr(strwin, 2, 5, text);
179 if (mvwinchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
180 mvwaddchstr(strwin, 3, 5, text);
183 wnoutrefresh(strwin);
185 /* FIXME: want stdscr tests also, but must be separate program */