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: inch_wide.c,v 1.3 2007/02/11 00:32:58 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>
55 return (ch == ERR || ch == QUIT || ch == ESCAPE);
59 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
68 int txt_x = 0, txt_y = 0;
71 cchar_t text[MAX_COLS];
73 setlocale(LC_ALL, "");
76 fprintf(stderr, "usage: %s file\n", argv[0]);
82 chrbox = newwin(7, COLS, 0, 0);
86 chrwin = derwin(chrbox, 1, COLS - 2, 1, 1);
87 strwin = derwin(chrbox, 4, COLS - 2, 2, 1);
89 txtbox = newwin(LINES - 7, COLS, 7, 0);
93 txtwin = derwin(txtbox,
98 keypad(txtwin, TRUE); /* enable keyboard mapping */
99 (void) cbreak(); /* take input chars one at a time, no wait for \n */
100 (void) noecho(); /* don't echo input */
102 if ((fp = fopen(argv[1], "r")) != 0) {
103 while ((j = fgetc(fp)) != EOF) {
104 if (waddch(txtwin, j) != OK) {
109 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
112 while (!Quit(j = mvwgetch(txtwin, txt_y, txt_x))) {
116 if (txt_y < getmaxy(txtwin) - 1)
137 if (txt_x < getmaxx(txtwin) - 1)
144 wmove(txtwin, txt_y, txt_x);
146 mvwprintw(chrwin, 0, 0, "char:");
148 if (win_wch(txtwin, &ch) != ERR) {
149 if (wadd_wch(chrwin, &ch) != ERR) {
150 for (j = txt_x + 1; j < getmaxx(txtwin); ++j) {
151 if (mvwin_wch(txtwin, txt_y, j, &ch) != ERR) {
152 if (wadd_wch(chrwin, &ch) == ERR) {
161 wnoutrefresh(chrwin);
163 mvwprintw(strwin, 0, 0, "text:");
166 limit = getmaxx(strwin) - 5;
168 wmove(txtwin, txt_y, txt_x);
169 if (win_wchstr(txtwin, text) != ERR) {
170 mvwadd_wchstr(strwin, 0, 5, text);
173 wmove(txtwin, txt_y, txt_x);
174 if (win_wchnstr(txtwin, text, limit) != ERR) {
175 mvwadd_wchstr(strwin, 1, 5, text);
178 if (mvwin_wchstr(txtwin, txt_y, txt_x, text) != ERR) {
179 mvwadd_wchstr(strwin, 2, 5, text);
182 if (mvwin_wchnstr(txtwin, txt_y, txt_x, text, limit) != ERR) {
183 mvwadd_wchstr(strwin, 3, 5, text);
186 wnoutrefresh(strwin);
188 /* FIXME: want stdscr tests also, but must be separate program */
197 printf("This program requires the wide-ncurses library\n");
198 ExitProgram(EXIT_FAILURE);