• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Copyright 2020,2022 Thomas E. Dickey                                     *
3  * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
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:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
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.                               *
23  *                                                                          *
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       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 /*
30  * This test was written by Alexander V. Lukyanov to demonstrate difference
31  * between ncurses 4.1 and SVR4 curses
32  *
33  * $Id: firstlast.c,v 1.10 2022/12/10 23:31:31 tom Exp $
34  */
35 
36 #include <test.priv.h>
37 
38 static void
fill(WINDOW * w,const char * str)39 fill(WINDOW *w, const char *str)
40 {
41     const char *s;
42     int x0 = -1, y0 = -1;
43     int x1, y1;
44     int maxx, maxy, limit;
45 
46     getmaxyx(w, maxy, maxx);
47     wmove(w, 0, 0);
48     limit = maxy * maxx;
49 
50     for (;;) {
51 	for (s = str; *s; s++) {
52 	    getyx(w, y1, x1);
53 	    if (waddch(w, UChar(*s)) == ERR
54 		|| (x1 == x0 && y1 == y0)) {
55 		wmove(w, 0, 0);
56 		return;
57 	    }
58 	    /* waddch() should return ERR at the lower-right corner */
59 	    if (--limit < 0) {
60 		beep();
61 		if (*str == '?')
62 		    return;
63 		napms(500);
64 		wmove(w, maxy - 1, 0);
65 		str = "?";
66 		limit = maxx + 1;
67 	    }
68 	    x0 = x1;
69 	    y0 = y1;
70 	}
71     }
72 }
73 
74 static void
usage(int ok)75 usage(int ok)
76 {
77     static const char *msg[] =
78     {
79 	"Usage: firstlast [options]"
80 	,""
81 	,USAGE_COMMON
82     };
83     size_t n;
84 
85     for (n = 0; n < SIZEOF(msg); n++)
86 	fprintf(stderr, "%s\n", msg[n]);
87 
88     ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
89 }
90 /* *INDENT-OFF* */
VERSION_COMMON()91 VERSION_COMMON()
92 /* *INDENT-ON* */
93 
94 int
95 main(int argc, char *argv[])
96 {
97     WINDOW *large, *small;
98     int ch;
99 
100     while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) {
101 	switch (ch) {
102 	case OPTS_VERSION:
103 	    show_version(argv);
104 	    ExitProgram(EXIT_SUCCESS);
105 	default:
106 	    usage(ch == OPTS_USAGE);
107 	    /* NOTREACHED */
108 	}
109     }
110     if (optind < argc)
111 	usage(FALSE);
112 
113     initscr();
114     noecho();
115 
116     large = newwin(20, 60, 2, 10);
117     small = newwin(10, 30, 7, 25);
118 
119     /* test 1 - addch */
120     fill(large, "LargeWindow");
121 
122     refresh();
123     wrefresh(large);
124     wrefresh(small);
125 
126     MvWAddStr(small, 5, 5, "   Test <place to change> String   ");
127     wrefresh(small);
128     getch();
129 
130     touchwin(large);
131     wrefresh(large);
132 
133     MvWAddStr(small, 5, 5, "   Test <***************> String   ");
134     wrefresh(small);
135 
136     /* DIFFERENCE! */
137     getch();
138 
139     /* test 2: erase */
140     erase();
141     refresh();
142     getch();
143 
144     /* test 3: clrtoeol */
145     werase(small);
146     wrefresh(small);
147     touchwin(large);
148     wrefresh(large);
149     wmove(small, 5, 0);
150     waddstr(small, " clrtoeol>");
151     wclrtoeol(small);
152     wrefresh(small);
153 
154     /* DIFFERENCE! */ ;
155     getch();
156 
157     /* test 4: clrtobot */
158     werase(small);
159     wrefresh(small);
160     touchwin(large);
161     wrefresh(large);
162     wmove(small, 5, 3);
163     waddstr(small, " clrtobot>");
164     wclrtobot(small);
165     wrefresh(small);
166 
167     /* DIFFERENCE! */
168     getch();
169 
170     endwin();
171 
172     ExitProgram(EXIT_SUCCESS);
173 }
174