]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
50b6effbb383783f2e9f20c1820b8503ee61b9eb
[ncurses.git] / test / test.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc.              *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Thomas E. Dickey                    1996-on                     *
31  ****************************************************************************/
32 /* $Id: test.priv.h,v 1.91 2009/07/18 12:19:23 tom Exp $ */
33
34 #ifndef __TEST_PRIV_H
35 #define __TEST_PRIV_H 1
36
37 #include <ncurses_cfg.h>
38
39 /*
40  * Fix ifdef's that look for the form/menu/panel libraries, if we are building
41  * with wide-character ncurses.
42  */
43 #ifdef  HAVE_LIBFORMW
44 #define HAVE_LIBFORMW 1
45 #define HAVE_LIBFORM 1
46 #endif
47
48 #ifdef  HAVE_LIBMENUW
49 #define HAVE_LIBMENUW 1
50 #define HAVE_LIBMENU 1
51 #endif
52
53 #ifdef  HAVE_LIBPANELW
54 #define HAVE_LIBPANELW 1
55 #define HAVE_LIBPANEL 1
56 #endif
57
58 /*
59  * Fallback definitions to accommodate broken compilers.
60  */
61 #ifndef HAVE_CURSES_VERSION
62 #define HAVE_CURSES_VERSION 0
63 #endif
64
65 #ifndef HAVE_CHGAT
66 #define HAVE_CHGAT 0
67 #endif
68
69 #ifndef HAVE_COLOR_SET
70 #define HAVE_COLOR_SET 0
71 #endif
72
73 #ifndef HAVE_FILTER
74 #define HAVE_FILTER 0
75 #endif
76
77 #ifndef HAVE_FORM_H
78 #define HAVE_FORM_H 0
79 #endif
80
81 #ifndef HAVE_GETBEGX
82 #define HAVE_GETBEGX 0
83 #endif
84
85 #ifndef HAVE_GETCURX
86 #define HAVE_GETCURX 0
87 #endif
88
89 #ifndef HAVE_GETMAXX
90 #define HAVE_GETMAXX 0
91 #endif
92
93 #ifndef HAVE_GETOPT_H
94 #define HAVE_GETOPT_H 0
95 #endif
96
97 #ifndef HAVE_GETPARX
98 #define HAVE_GETPARX 0
99 #endif
100
101 #ifndef HAVE_GETWIN
102 #define HAVE_GETWIN 0
103 #endif
104
105 #ifndef HAVE_LIBFORM
106 #define HAVE_LIBFORM 0
107 #endif
108
109 #ifndef HAVE_LIBMENU
110 #define HAVE_LIBMENU 0
111 #endif
112
113 #ifndef HAVE_LIBPANEL
114 #define HAVE_LIBPANEL 0
115 #endif
116
117 #ifndef HAVE_LOCALE_H
118 #define HAVE_LOCALE_H 0
119 #endif
120
121 #ifndef HAVE_MENU_H
122 #define HAVE_MENU_H 0
123 #endif
124
125 #ifndef HAVE_MVVLINE
126 #define HAVE_MVVLINE 0
127 #endif
128
129 #ifndef HAVE_MVWVLINE
130 #define HAVE_MVWVLINE 0
131 #endif
132
133 #ifndef HAVE_NAPMS
134 #define HAVE_NAPMS 1
135 #endif
136
137 #ifndef HAVE_NC_ALLOC_H
138 #define HAVE_NC_ALLOC_H 0
139 #endif
140
141 #ifndef HAVE_PANEL_H
142 #define HAVE_PANEL_H 0
143 #endif
144
145 #ifndef HAVE_PUTWIN
146 #define HAVE_PUTWIN 0
147 #endif
148
149 #ifndef HAVE_RESIZE_TERM
150 #define HAVE_RESIZE_TERM 0
151 #endif
152
153 #ifndef HAVE_RIPOFFLINE
154 #define HAVE_RIPOFFLINE 0
155 #endif
156
157 #ifndef HAVE_SETUPTERM
158 #define HAVE_SETUPTERM 0
159 #endif
160
161 #ifndef HAVE_SLK_COLOR
162 #define HAVE_SLK_COLOR 0
163 #endif
164
165 #ifndef HAVE_SLK_INIT
166 #define HAVE_SLK_INIT 0
167 #endif
168
169 #ifndef HAVE_TERMATTRS
170 #define HAVE_TERMATTRS 0
171 #endif
172
173 #ifndef HAVE_TERMNAME
174 #define HAVE_TERMNAME 0
175 #endif
176
177 #ifndef HAVE_TGETENT
178 #define HAVE_TGETENT 0
179 #endif
180
181 #ifndef HAVE_TIGETNUM
182 #define HAVE_TIGETNUM 0
183 #endif
184
185 #ifndef HAVE_TYPEAHEAD
186 #define HAVE_TYPEAHEAD 0
187 #endif
188
189 #ifndef HAVE_TIGETSTR
190 #define HAVE_TIGETSTR 0
191 #endif
192
193 #ifndef HAVE_WINSSTR
194 #define HAVE_WINSSTR 0
195 #endif
196
197 #ifndef HAVE_USE_DEFAULT_COLORS
198 #define HAVE_USE_DEFAULT_COLORS 0
199 #endif
200
201 #ifndef HAVE_WRESIZE
202 #define HAVE_WRESIZE 0
203 #endif
204
205 #ifndef NCURSES_EXT_FUNCS
206 #define NCURSES_EXT_FUNCS 0
207 #endif
208
209 #ifndef NEED_PTEM_H
210 #define NEED_PTEM_H 0
211 #endif
212
213 #ifndef NEED_WCHAR_H
214 #define NEED_WCHAR_H 0
215 #endif
216
217 #ifndef NO_LEAKS
218 #define NO_LEAKS 0
219 #endif
220
221 #include <stdlib.h>
222 #include <stdarg.h>
223 #include <string.h>
224 #include <sys/types.h>
225
226 #if HAVE_UNISTD_H
227 #include <unistd.h>
228 #endif
229
230 #include <signal.h>     /* include before curses.h to work around glibc bug */
231
232 #if NEED_WCHAR_H
233 #include <wchar.h>
234 #ifdef HAVE_LIBUTF8_H
235 #include <libutf8.h>
236 #endif
237 #endif
238
239 #if defined(HAVE_XCURSES)
240 #include <xcurses.h>
241 #elif defined(HAVE_NCURSESW_NCURSES_H)
242 #include <ncursesw/curses.h>
243 #elif defined(HAVE_NCURSES_NCURSES_H)
244 #include <ncurses/curses.h>
245 #else
246 #include <curses.h>
247 #endif
248
249 #if defined(HAVE_XCURSES)
250 /* no other headers */
251 #undef  HAVE_SETUPTERM          /* nonfunctional */
252 #define HAVE_SETUPTERM 0
253 #undef  HAVE_TGETENT            /* nonfunctional */
254 #define HAVE_TGETENT 0
255 #undef  HAVE_TIGETSTR           /* nonfunctional */
256 #define HAVE_TIGETSTR 0
257 #elif defined(HAVE_NCURSESW_TERM_H)
258 #include <ncursesw/term.h>
259 #elif defined(HAVE_NCURSES_TERM_H)
260 #include <ncurses/term.h>
261 #elif defined(HAVE_TERM_H)
262 #include <term.h>
263 #endif
264
265 /*
266  * Not all curses.h implementations include unctrl.h,
267  * Solaris 10 xpg4 for example.
268  */
269 #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
270 #if defined(HAVE_NCURSESW_NCURSES_H)
271 #include <ncursesw/unctrl.h>
272 #elif defined(HAVE_NCURSES_NCURSES_H)
273 #include <ncurses/unctrl.h>
274 #else
275 #include <unctrl.h>
276 #endif
277 #endif
278
279 #if HAVE_GETOPT_H
280 #include <getopt.h>
281 #else
282 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
283  * doesn't hurt.
284  */
285 extern char *optarg;
286 extern int optind;
287 #endif /* HAVE_GETOPT_H */
288
289 #if HAVE_LOCALE_H
290 #include <locale.h>
291 #else
292 #define setlocale(name,string) /* nothing */
293 #endif
294
295 #include <assert.h>
296 #include <ctype.h>
297
298 #ifndef GCC_NORETURN
299 #define GCC_NORETURN /* nothing */
300 #endif
301 #ifndef GCC_PRINTFLIKE
302 #define GCC_PRINTFLIKE(a,b) /* nothing */
303 #endif
304 #ifndef GCC_UNUSED
305 #define GCC_UNUSED /* nothing */
306 #endif
307
308 #ifndef HAVE_GETNSTR
309 #define getnstr(s,n) getstr(s)
310 #endif
311
312 #ifndef USE_SOFTKEYS
313 #if HAVE_SLK_INIT
314 #define USE_SOFTKEYS 1
315 #else
316 #define USE_SOFTKEYS 0
317 #endif
318 #endif
319
320 #ifndef USE_WIDEC_SUPPORT
321 #if defined(_XOPEN_SOURCE_EXTENDED) && defined(WACS_ULCORNER)
322 #define USE_WIDEC_SUPPORT 1
323 #else
324 #define USE_WIDEC_SUPPORT 0
325 #endif
326 #endif
327
328 #if HAVE_PANEL_H && HAVE_LIBPANEL
329 #define USE_LIBPANEL 1
330 #else
331 #define USE_LIBPANEL 0
332 #endif
333
334 #if HAVE_MENU_H && HAVE_LIBMENU
335 #define USE_LIBMENU 1
336 #else
337 #define USE_LIBMENU 0
338 #endif
339
340 #if HAVE_FORM_H && HAVE_LIBFORM
341 #define USE_LIBFORM 1
342 #else
343 #define USE_LIBFORM 0
344 #endif
345
346 #ifndef HAVE_TYPE_ATTR_T
347 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
348 #define attr_t chtype
349 #endif
350 #endif
351
352 #undef NCURSES_CH_T
353 #if !USE_WIDEC_SUPPORT
354 #define NCURSES_CH_T chtype
355 #else
356 #define NCURSES_CH_T cchar_t
357 #endif
358
359 #ifndef NCURSES_OPAQUE
360 #define NCURSES_OPAQUE 0
361 #endif
362
363 #ifndef CCHARW_MAX
364 #define CCHARW_MAX 5
365 #endif
366
367 #undef CTRL
368 #define CTRL(x) ((x) & 0x1f)
369
370 #define QUIT            CTRL('Q')
371 #define ESCAPE          CTRL('[')
372
373 #ifndef KEY_MIN
374 #define KEY_MIN 256     /* not defined in Solaris 8 */
375 #endif
376
377 #ifdef DECL_CURSES_DATA_BOOLNAMES
378 extern char     *boolnames[], *boolcodes[], *boolfnames[],
379                 *numnames[], *numcodes[], *numfnames[],
380                 *strnames[], *strcodes[], *strfnames[];
381 #endif
382
383 #define colored_chtype(ch, attr, pair) \
384         ((ch) | (attr) | COLOR_PAIR(pair))
385
386 /*
387  * Workaround for HPUX
388  */
389 #if defined(__hpux) && !defined(NCURSES_VERSION)
390 #define getbegx(w) __getbegx(w)
391 #define getbegy(w) __getbegy(w)
392 #define getcurx(w) __getcurx(w)
393 #define getcury(w) __getcury(w)
394 #define getmaxx(w) __getmaxx(w)
395 #define getmaxy(w) __getmaxy(w)
396 #define getparx(w) __getparx(w)
397 #define getpary(w) __getpary(w)
398 #endif
399
400 /*
401  * Workaround in case getcchar() returns a positive value when the source
402  * string produces only a L'\0'.
403  */
404 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
405         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
406             wchar_t test_wch[CCHARW_MAX + 2]; \
407             attr_t test_attrs; \
408             short test_pair; \
409             \
410             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
411                 && test_wch[0] != L'\0') { \
412                 then_stmt \
413             } else { \
414                 else_stmt \
415             } \
416         } else { \
417             else_stmt \
418         }
419 /*
420  * These usually are implemented as macros, but may be functions.
421  */
422 #if !defined(getcurx) && !HAVE_GETCURX
423 #define getcurx(win)            ((win)?(win)->_curx:ERR)
424 #define getcury(win)            ((win)?(win)->_cury:ERR)
425 #endif
426
427 #if !defined(getbegx) && !HAVE_GETBEGX
428 #define getbegx(win)            ((win)?(win)->_begx:ERR)
429 #define getbegy(win)            ((win)?(win)->_begy:ERR)
430 #endif
431
432 #if !defined(getmaxx) && !HAVE_GETMAXX
433 #define getmaxx(win)            ((win)?((win)->_maxx + 1):ERR)
434 #define getmaxy(win)            ((win)?((win)->_maxy + 1):ERR)
435 #endif
436
437 /*
438  * Solaris 10 xpg4:
439 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
440                                 : (w)->_begx - (w)->_parent->_begx)
441  */
442 #if !defined(getparx) && !HAVE_GETPARX
443 #ifdef __m_getparx
444 #define getparx(win)            __m_getparx(win)
445 #define getpary(win)            __m_getpary(win)
446 #else
447 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
448 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
449 #endif
450 #endif
451
452 #if !defined(mvwvline) && !HAVE_MVWVLINE
453 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
454 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
455 #endif
456
457 #if !defined(mvvline) && !HAVE_MVVLINE
458 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
459 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
460 #endif
461
462 /*
463  * Try to accommodate curses implementations that have no terminfo support.
464  */
465 #if HAVE_TIGETNUM
466 #define TIGETNUM(ti,tc) tigetnum(ti)
467 #else
468 #define TIGETNUM(ti,tc) tgetnum(tc)
469 #endif
470
471 #if HAVE_TIGETSTR
472 #define TIGETSTR(ti,tc) tigetstr(ti)
473 #else
474 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
475 #endif
476
477 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
478  * (which is incompatible with legacy usage, doesn't solve any problems).
479  */
480 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
481 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
482
483 #define UChar(c)    ((unsigned char)(c))
484
485 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
486
487 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
488 #include <nc_alloc.h>
489 #if HAVE_NC_FREEALL && defined(USE_TINFO)
490 #undef ExitProgram
491 #define ExitProgram(code) _nc_free_tinfo(code)
492 #endif
493 #else
494 #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
495 #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
496 #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
497 #endif
498
499 #ifndef ExitProgram
500 #define ExitProgram(code) exit(code)
501 #endif
502
503 #ifndef EXIT_SUCCESS
504 #define EXIT_SUCCESS 0
505 #endif
506 #ifndef EXIT_FAILURE
507 #define EXIT_FAILURE 1
508 #endif
509
510 #ifdef __MINGW32__
511 #include <nc_mingw.h>
512 /* conflicts in test/firstlast.c */
513 #undef large
514 #undef small
515
516 #endif
517
518 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
519  * curses which doesn't have const parameters declared (so far) in the places
520  * that XSI shows.
521  */
522 #ifndef NCURSES_CONST
523 #define NCURSES_CONST /* nothing */
524 #endif
525
526 /* out-of-band values for representing absent capabilities */
527 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
528 #define ABSENT_NUMERIC          (-1)
529 #define ABSENT_STRING           (char *)0
530
531 /* out-of-band values for representing cancels */
532 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
533 #define CANCELLED_NUMERIC       (-2)
534 #define CANCELLED_STRING        (char *)(-1)
535
536 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
537 #define VALID_NUMERIC(s) ((s) >= 0)
538 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
539
540 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
541
542 #define CATCHALL(handler) { \
543                 int nsig; \
544                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
545                     if (nsig != SIGKILL) \
546                         signal(nsig, handler); \
547             }
548
549 /*
550  * Workaround for clean(er) compile with Solaris's legacy curses.
551  * The same would be needed for HPUX 10.20
552  */
553 #ifndef TPUTS_ARG
554 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
555 #define TPUTS_ARG char
556 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
557 #else
558 #define TPUTS_ARG int
559 #endif
560 #endif
561
562 /*
563  * Workarounds for Solaris's X/Open curses
564  */
565 #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
566 #if !defined(KEY_MIN) && defined(__KEY_MIN)
567 #define KEY_MIN __KEY_MIN
568 #endif
569 #if !defined(KEY_MAX) && defined(__KEY_MIN)
570 #define KEY_MAX __KEY_MAX
571 #endif
572 #endif
573
574 /*
575  * Workaround to build with Sun's default SVr4 curses.
576  */
577 #ifdef NCURSES_VERSION
578 #ifndef HAVE_VW_PRINTW
579 #define HAVE_VW_PRINTW 1
580 #endif
581 #endif
582
583 /*
584  * ncurses provides arrays of capability names; X/Open discarded these SVr4
585  * features.  Some implementations continue to provide them (see the test
586  * configure script).
587  */
588 #ifdef NCURSES_VERSION
589 #ifndef HAVE_CURSES_DATA_BOOLNAMES
590 #define HAVE_CURSES_DATA_BOOLNAMES 1
591 #endif
592 #endif
593
594 /*
595  * ncurses uses const in some places where X/Open does (or did) not allow.
596  */
597 #ifdef NCURSES_VERSION
598 #define CONST_MENUS const
599 #else
600 #define CONST_MENUS /* nothing */
601 #endif
602
603 #ifndef HAVE_USE_WINDOW
604 #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
605 #define HAVE_USE_WINDOW 0
606 #else
607 #define HAVE_USE_WINDOW 1
608 #endif
609 #endif
610
611 /*
612  * Simplify setting up demo of threading with these macros.
613  */
614
615 #if !HAVE_USE_WINDOW
616 typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
617 typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
618 #endif
619
620 #if HAVE_USE_WINDOW
621 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
622 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
623 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
624 #else
625 #define USING_WINDOW(w,func) func(w)
626 #define USING_WINDOW2(w,func,data) func(w,data)
627 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
628 #endif
629
630 #if HAVE_USE_WINDOW
631 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
632 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
633 #else
634 #define USING_SCREEN(s,func,data) func(data)
635 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
636 #endif
637
638 #ifdef TRACE
639 #define Trace(p) _tracef p
640 #define USE_TRACE 1
641 #else
642 #define Trace(p)                /* nothing */
643 #define USE_TRACE 0
644 #endif
645
646 #define init_mb(state)  memset(&state, 0, sizeof(state))
647
648 #endif /* __TEST_PRIV_H */