1 /****************************************************************************
2 * Copyright (c) 2007,2010 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.7 2010/05/01 19:13:46 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>
56 return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
60 test_inchs(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
66 int txt_x = 0, txt_y = 0;
70 cchar_t text[MAX_COLS];
72 if (argv[level] == 0) {
78 txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
82 txtwin = derwin(txtbox,
92 keypad(txtwin, TRUE); /* enable keyboard mapping */
93 (void) cbreak(); /* take input chars one at a time, no wait for \n */
94 (void) noecho(); /* don't echo input */
98 wmove(txtwin, txt_y, txt_x);
100 if ((fp = fopen(argv[level], "r")) != 0) {
101 while ((j = fgetc(fp)) != EOF) {
102 if (waddch(txtwin, UChar(j)) != OK) {
108 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
111 while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
115 if (txt_y < getmaxy(txtwin) - 1)
136 if (txt_x < getmaxx(txtwin) - 1)
142 test_inchs(level + 1, argv, chrwin, strwin);
145 wnoutrefresh(txtbox);
148 wnoutrefresh(txtwin);
156 MvWPrintw(chrwin, 0, 0, "char:");
159 if (txtwin != stdscr) {
160 wmove(txtwin, txt_y, txt_x);
161 if (win_wch(txtwin, &ch) != ERR) {
162 if (wadd_wch(chrwin, &ch) != ERR) {
163 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
164 if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
165 if (wadd_wch(chrwin, &ch) == ERR) {
176 if (in_wch(&ch) != ERR) {
177 if (wadd_wch(chrwin, &ch) != ERR) {
178 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
179 if (mvin_wch(txt_y, j, &ch) != ERR) {
180 if (wadd_wch(chrwin, &ch) == ERR) {
190 wnoutrefresh(chrwin);
192 MvWPrintw(strwin, 0, 0, "text:");
195 limit = getmaxx(strwin) - 5;
197 if (txtwin != stdscr) {
198 wmove(txtwin, txt_y, txt_x);
199 if (win_wchstr(txtwin, text) != ERR) {
200 (void) mvwadd_wchstr(strwin, 0, 5, text);
203 wmove(txtwin, txt_y, txt_x);
204 if (win_wchnstr(txtwin, text, limit) != ERR) {
205 (void) mvwadd_wchstr(strwin, 1, 5, text);
208 if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
209 (void) mvwadd_wchstr(strwin, 2, 5, text);
212 if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
213 (void) mvwadd_wchstr(strwin, 3, 5, text);
217 if (in_wchstr(text) != ERR) {
218 (void) mvwadd_wchstr(strwin, 0, 5, text);
222 if (in_wchnstr(text, limit) != ERR) {
223 (void) mvwadd_wchstr(strwin, 1, 5, text);
226 if (mvin_wchstr(txt_y, txt_x, text) != ERR) {
227 (void) mvwadd_wchstr(strwin, 2, 5, text);
230 if (mvin_wchnstr(txt_y, txt_x, text, limit) != ERR) {
231 (void) mvwadd_wchstr(strwin, 3, 5, text);
235 wnoutrefresh(strwin);
245 main(int argc, char *argv[])
251 setlocale(LC_ALL, "");
254 fprintf(stderr, "usage: %s file\n", argv[0]);
260 chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
262 wnoutrefresh(chrbox);
264 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
265 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
267 test_inchs(1, argv, chrwin, strwin);
270 ExitProgram(EXIT_SUCCESS);
276 printf("This program requires the wide-ncurses library\n");
277 ExitProgram(EXIT_FAILURE);