1 /****************************************************************************
2 * Copyright 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: test_inwstr.c,v 1.6 2020/02/02 23:34:34 tom Exp $
32 * Author: Thomas E Dickey
34 * Demonstrate the inwstr functions from the curses library.
36 int inwstr(wchar_t *str);
37 int innwstr(wchar_t *str, int n);
38 int winwstr(WINDOW *win, wchar_t *str);
39 int winnwstr(WINDOW *win, wchar_t *str, int n);
40 int mvinwstr(int y, int x, wchar_t *str);
41 int mvinnwstr(int y, int x, wchar_t *str, int n);
42 int mvwinwstr(WINDOW *win, int y, int x, wchar_t *str);
43 int mvwinnwstr(WINDOW *win, int y, int x, wchar_t *str, int n);
46 #include <test.priv.h>
56 return (ch == ERR || ch == 'q' || ch == QUIT || ch == ESCAPE);
60 show_1st(WINDOW *win, int line, wchar_t *buffer)
62 (void) mvwaddwstr(win, line, 5, buffer);
66 showmore(WINDOW *win, int line, wchar_t *buffer)
70 show_1st(win, line, buffer);
74 recursive_test(int level, char **argv, WINDOW *chrwin, WINDOW *strwin)
80 int txt_x = 0, txt_y = 0;
82 int limit = getmaxx(strwin) - 5;
83 wchar_t buffer[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 ((ch = fgetc(fp)) != EOF) {
115 if (waddch(txtwin, UChar(ch)) != OK) {
121 wprintw(txtwin, "Cannot open:\n%s", argv[1]);
124 while (!Quit(ch = mvwgetch(txtwin, txt_y, txt_x))) {
128 if (txt_y < getmaxy(txtwin) - 1)
149 if (txt_x < getmaxx(txtwin) - 1)
155 recursive_test(level + 1, argv, chrwin, strwin);
158 wnoutrefresh(txtbox);
161 wnoutrefresh(txtwin);
179 MvWPrintw(chrwin, 0, 0, "line:");
182 if (txtwin != stdscr) {
183 wmove(txtwin, txt_y, txt_x);
185 if (winwstr(txtwin, buffer) != ERR) {
186 show_1st(chrwin, 0, buffer);
188 if (mvwinwstr(txtwin, txt_y, txt_x, buffer) != ERR) {
189 showmore(chrwin, 1, buffer);
194 if (inwstr(buffer) != ERR) {
195 show_1st(chrwin, 0, buffer);
197 if (mvinwstr(txt_y, txt_x, buffer) != ERR) {
198 showmore(chrwin, 1, buffer);
201 wnoutrefresh(chrwin);
203 MvWPrintw(strwin, 0, 0, "%4d:", limit);
206 if (txtwin != stdscr) {
207 wmove(txtwin, txt_y, txt_x);
208 if (winnwstr(txtwin, buffer, limit) != ERR) {
209 show_1st(strwin, 0, buffer);
212 if (mvwinnwstr(txtwin, txt_y, txt_x, buffer, limit) != ERR) {
213 showmore(strwin, 1, buffer);
217 if (innwstr(buffer, limit) != ERR) {
218 show_1st(strwin, 0, buffer);
221 if (mvinnwstr(txt_y, txt_x, buffer, limit) != ERR) {
222 showmore(strwin, 1, buffer);
226 wnoutrefresh(strwin);
236 main(int argc, char *argv[])
242 setlocale(LC_ALL, "");
245 fprintf(stderr, "usage: %s file\n", argv[0]);
251 chrbox = derwin(stdscr, BASE_Y, COLS, 0, 0);
253 wnoutrefresh(chrbox);
255 chrwin = derwin(chrbox, 2, COLS - 2, 1, 1);
256 strwin = derwin(chrbox, 2, COLS - 2, 3, 1);
258 recursive_test(1, argv, chrwin, strwin);
261 ExitProgram(EXIT_SUCCESS);
267 printf("This program requires the wide-ncurses library\n");
268 ExitProgram(EXIT_FAILURE);