1 /****************************************************************************
2 * Copyright 2019-2020,2022 Thomas E. Dickey *
3 * Copyright 2008-2014,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: insdelln.c,v 1.15 2022/12/10 23:31:31 tom Exp $
32 * test-driver for deleteln, wdeleteln, insdelln, winsdelln, insertln, winsertln
35 #include <test.priv.h>
39 #include <popup_msg.h>
41 #define SHOW(n) ((n) == ERR ? "ERR" : "OK")
42 #define COLOR_DEFAULT (-1)
60 color_params(unsigned state, int *pair)
68 { 0, COLOR_DEFAULT, COLOR_DEFAULT, "default" },
69 { 1, COLOR_RED, COLOR_BLACK, "red/black" },
70 { 2, COLOR_WHITE, COLOR_BLUE, "white/blue" },
74 const char *result = 0;
77 static bool first = TRUE;
82 for (n = 0; n < SIZEOF(table); ++n) {
83 init_pair(table[n].pair, table[n].fg, table[n].bg);
86 if (state < SIZEOF(table)) {
87 *pair = table[state].pair;
88 result = table[state].msg;
95 video_params(unsigned state, unsigned *attr)
102 { A_NORMAL, "normal" },
104 { A_REVERSE, "reverse" },
105 { A_UNDERLINE, "underline" },
106 { A_BLINK, "blink" },
110 const char *result = 0;
112 if (state < SIZEOF(table)) {
113 *attr = table[state].attr;
114 result = table[state].msg;
119 /* fill the window with a test-pattern */
121 fill_window(WINDOW *win)
124 int y0 = -1, x0 = -1;
128 while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
131 if (y1 == y0 && x1 == x0)
140 show_status(WINDOW *win, STATUS * sp)
146 wprintw(win, "Count %d", sp->count);
148 wprintw(win, " Video %s", sp->v_msg);
150 wprintw(win, " Color %s", sp->c_msg);
156 reshow_status(WINDOW *win, STATUS * sp)
159 show_status(win, sp);
163 do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
165 WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
166 sp->y_beg + 1, sp->x_beg + 1);
168 if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
169 WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
190 init_status(WINDOW *win, STATUS * sp)
192 memset(sp, 0, sizeof(*sp));
200 getbegyx(win, sp->y_beg, sp->x_beg);
201 getmaxyx(win, sp->y_max, sp->x_max);
205 show_help(WINDOW *win)
207 static const char *table[] =
210 ,"Use h/j/k/l or arrow keys to move the cursor."
211 ,"Set the count parameter for insert/delete by entering digits 0-9."
214 ,"space toggles through the set of video attributes and colors."
215 ,"t touches (forces repaint) of the current line."
216 ,"i calls insertln at the current position with the given count."
217 ,"d calls deleteln at the window beginning with the given count."
218 ,"I calls insdelln at the window beginning with the given count."
219 ,"D calls insdelln at the window beginning with the given -count."
220 ,"f refills the window with test-pattern using current attributes."
221 ,"w recur to test windows other than stdscr"
223 ,"= resets count to zero."
224 ,"? shows this help-window"
228 popup_msg(win, table);
232 update_status(WINDOW *win, STATUS * sp)
235 case ' ': /* next test-iteration */
237 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
238 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
239 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
240 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
244 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
245 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
249 show_status(win, sp);
254 wmove(win, sp->y_val, --(sp->x_val));
258 if (sp->y_val < sp->y_max)
259 wmove(win, ++(sp->y_val), sp->x_val);
264 wmove(win, --(sp->y_val), sp->x_val);
268 if (sp->x_val < sp->x_max)
269 wmove(win, sp->y_val, ++(sp->x_val));
272 touchline(win, sp->y_val, 1);
276 show_status(win, sp);
282 if (isdigit(sp->ch)) {
283 sp->count = (sp->count * 10) + (sp->ch - '0');
284 show_status(win, sp);
293 test_winsdelln(WINDOW *win)
298 init_status(win, &st);
301 (void) wattrset(win, AttrArg(COLOR_PAIR(st.pair), st.attr));
304 for (n = 0; n < st.count; ++n)
308 for (n = 0; n < st.count; ++n)
312 winsdelln(win, st.count);
315 winsdelln(win, -st.count);
319 reshow_status(win, &st);
322 do_subwindow(win, &st, test_winsdelln);
327 update_status(win, &st);
330 } while ((st.ch = wgetch(win)) != ERR);
339 init_status(stdscr, &st);
342 (void) attrset(AttrArg(COLOR_PAIR(st.pair), st.attr));
345 for (n = 0; n < st.count; ++n)
349 for (n = 0; n < st.count; ++n)
360 reshow_status(stdscr, &st);
363 do_subwindow(stdscr, &st, test_winsdelln);
368 update_status(stdscr, &st);
371 } while ((st.ch = getch()) != ERR);
377 static const char *msg[] =
379 "Usage: insdelln [options]"
385 for (n = 0; n < SIZEOF(msg); n++)
386 fprintf(stderr, "%s\n", msg[n]);
388 ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
395 main(int argc, char *argv[])
399 while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
403 ExitProgram(EXIT_SUCCESS);
405 usage(ch == OPTS_USAGE);
419 ExitProgram(EXIT_SUCCESS);
426 printf("This program requires the curses winsdelln function\n");
427 ExitProgram(EXIT_FAILURE);