1 /****************************************************************************
2 * Copyright (c) 1998-2010,2011 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 /****************************************************************************
30 * Author: Thomas E. Dickey 1996-on *
31 ****************************************************************************/
32 /* $Id: test.priv.h,v 1.103 2011/03/22 09:15:45 tom Exp $ */
35 #define __TEST_PRIV_H 1
37 #include <ncurses_cfg.h>
40 * Fix ifdef's that look for the form/menu/panel libraries, if we are building
41 * with wide-character ncurses.
44 #define HAVE_LIBFORMW 1
45 #define HAVE_LIBFORM 1
49 #define HAVE_LIBMENUW 1
50 #define HAVE_LIBMENU 1
54 #define HAVE_LIBPANELW 1
55 #define HAVE_LIBPANEL 1
59 * Fallback definitions to accommodate broken compilers.
61 #ifndef HAVE_CURSES_VERSION
62 #define HAVE_CURSES_VERSION 0
69 #ifndef HAVE_COLOR_SET
70 #define HAVE_COLOR_SET 0
82 #define HAVE_GETBEGX 0
86 #define HAVE_GETCURX 0
90 #define HAVE_GETMAXX 0
94 #define HAVE_GETOPT_H 0
98 #define HAVE_GETPARX 0
102 #define HAVE_GETWIN 0
106 #define HAVE_LIBFORM 0
110 #define HAVE_LIBMENU 0
113 #ifndef HAVE_LIBPANEL
114 #define HAVE_LIBPANEL 0
117 #ifndef HAVE_LOCALE_H
118 #define HAVE_LOCALE_H 0
122 #define HAVE_MATH_H 0
126 #define HAVE_MENU_H 0
130 #define HAVE_MVVLINE 0
133 #ifndef HAVE_MVWVLINE
134 #define HAVE_MVWVLINE 0
141 #ifndef HAVE_NC_ALLOC_H
142 #define HAVE_NC_ALLOC_H 0
146 #define HAVE_PANEL_H 0
150 #define HAVE_PUTWIN 0
153 #ifndef HAVE_RESIZE_TERM
154 #define HAVE_RESIZE_TERM 0
157 #ifndef HAVE_RIPOFFLINE
158 #define HAVE_RIPOFFLINE 0
161 #ifndef HAVE_SETUPTERM
162 #define HAVE_SETUPTERM 0
165 #ifndef HAVE_SLK_COLOR
166 #define HAVE_SLK_COLOR 0
169 #ifndef HAVE_SLK_INIT
170 #define HAVE_SLK_INIT 0
173 #ifndef HAVE_TERMATTRS
174 #define HAVE_TERMATTRS 0
177 #ifndef HAVE_TERMNAME
178 #define HAVE_TERMNAME 0
182 #define HAVE_TGETENT 0
185 #ifndef HAVE_TIGETNUM
186 #define HAVE_TIGETNUM 0
189 #ifndef HAVE_TIGETSTR
190 #define HAVE_TIGETSTR 0
193 #ifndef HAVE_TYPEAHEAD
194 #define HAVE_TYPEAHEAD 0
198 #define HAVE_WINSSTR 0
201 #ifndef HAVE_USE_DEFAULT_COLORS
202 #define HAVE_USE_DEFAULT_COLORS 0
206 #define HAVE_WRESIZE 0
209 #ifndef NCURSES_EXT_FUNCS
210 #define NCURSES_EXT_FUNCS 0
214 #define NEED_PTEM_H 0
218 #define NEED_WCHAR_H 0
228 #include <sys/types.h>
235 #include <signal.h> /* include before curses.h to work around glibc bug */
239 #ifdef HAVE_LIBUTF8_H
244 #if defined(HAVE_XCURSES)
246 #elif defined(HAVE_NCURSESW_NCURSES_H)
247 #include <ncursesw/curses.h>
248 #elif defined(HAVE_NCURSES_NCURSES_H)
249 #include <ncurses/curses.h>
254 #if defined(HAVE_XCURSES) || defined(PDCURSES)
255 /* no other headers */
256 #undef HAVE_SETUPTERM /* nonfunctional */
257 #define HAVE_SETUPTERM 0
258 #undef HAVE_TGETENT /* nonfunctional */
259 #define HAVE_TGETENT 0
260 #undef HAVE_TIGETSTR /* nonfunctional */
261 #define HAVE_TIGETSTR 0
262 #elif defined(HAVE_NCURSESW_TERM_H)
263 #include <ncursesw/term.h>
264 #elif defined(HAVE_NCURSES_TERM_H)
265 #include <ncurses/term.h>
266 #elif defined(HAVE_TERM_H)
271 * Not all curses.h implementations include unctrl.h,
272 * Solaris 10 xpg4 for example.
274 #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
275 #if defined(HAVE_NCURSESW_NCURSES_H)
276 #include <ncursesw/unctrl.h>
277 #elif defined(HAVE_NCURSES_NCURSES_H)
278 #include <ncurses/unctrl.h>
287 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
292 #endif /* HAVE_GETOPT_H */
297 #define setlocale(name,string) /* nothing */
304 #define GCC_NORETURN /* nothing */
306 #ifndef GCC_PRINTFLIKE
307 #define GCC_PRINTFLIKE(a,b) /* nothing */
310 #define GCC_UNUSED /* nothing */
314 #define getnstr(s,n) getstr(s)
319 #define USE_SOFTKEYS 1
321 #define USE_SOFTKEYS 0
326 #define slk_init() /* nothing */
327 #define slk_restore() /* nothing */
328 #define slk_clear() /* nothing */
331 #ifndef HAVE_WSYNCDOWN
332 #define wsyncdown(win) /* nothing */
335 #ifndef USE_WIDEC_SUPPORT
336 #if (defined(_XOPEN_SOURCE_EXTENDED) || defined(_XPG5)) && defined(WACS_ULCORNER)
337 #define USE_WIDEC_SUPPORT 1
339 #define USE_WIDEC_SUPPORT 0
343 #if HAVE_PANEL_H && HAVE_LIBPANEL
344 #define USE_LIBPANEL 1
346 #define USE_LIBPANEL 0
349 #if HAVE_MENU_H && HAVE_LIBMENU
350 #define USE_LIBMENU 1
352 #define USE_LIBMENU 0
355 #if HAVE_FORM_H && HAVE_LIBFORM
356 #define USE_LIBFORM 1
358 #define USE_LIBFORM 0
361 /* workaround, to build against NetBSD's variant of the form library */
362 #ifdef HAVE_NETBSD_FORM_H
363 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
365 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
368 /* workaround, to build against NetBSD's variant of the form library */
369 #ifdef HAVE_NETBSD_MENU_H
370 #define menu_itemwidth(menu) (menu)->max_item_width
372 #define menu_itemwidth(menu) (menu)->itemlen
375 #ifndef HAVE_TYPE_ATTR_T
376 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
377 #define attr_t chtype
382 #if !USE_WIDEC_SUPPORT
383 #define NCURSES_CH_T chtype
385 #define NCURSES_CH_T cchar_t
388 #ifndef NCURSES_OPAQUE
389 #define NCURSES_OPAQUE 0
396 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
397 #define CURSES_WACS_SYMBOLS
400 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
401 /* NetBSD 5.1 defines these incorrectly */
435 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
436 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
437 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
438 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
439 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
440 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
441 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
442 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
443 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
444 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
445 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
446 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
447 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
448 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
449 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
450 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
451 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
452 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
453 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
454 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
455 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
456 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
457 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
458 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
459 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
460 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
461 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
462 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
463 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
464 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
465 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
466 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
470 #define CTRL(x) ((x) & 0x1f)
472 #define QUIT CTRL('Q')
473 #define ESCAPE CTRL('[')
476 #define KEY_MIN 256 /* not defined in Solaris 8 */
479 #ifdef DECL_CURSES_DATA_BOOLNAMES
480 extern char *boolnames[], *boolcodes[], *boolfnames[];
481 extern char *numnames[], *numcodes[], *numfnames[];
482 extern char *strnames[], *strcodes[], *strfnames[];
485 #define colored_chtype(ch, attr, pair) \
486 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
489 * Workaround for HPUX
491 #if defined(__hpux) && !defined(NCURSES_VERSION)
492 #define getbegx(w) __getbegx(w)
493 #define getbegy(w) __getbegy(w)
494 #define getcurx(w) __getcurx(w)
495 #define getcury(w) __getcury(w)
496 #define getmaxx(w) __getmaxx(w)
497 #define getmaxy(w) __getmaxy(w)
498 #define getparx(w) __getparx(w)
499 #define getpary(w) __getpary(w)
503 * Workaround in case getcchar() returns a positive value when the source
504 * string produces only a L'\0'.
506 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
507 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
508 wchar_t test_wch[CCHARW_MAX + 2]; \
512 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
513 && test_wch[0] != L'\0') { \
522 * These usually are implemented as macros, but may be functions.
524 #if !defined(getcurx) && !HAVE_GETCURX
525 #define getcurx(win) ((win)?(win)->_curx:ERR)
526 #define getcury(win) ((win)?(win)->_cury:ERR)
529 #if !defined(getbegx) && !HAVE_GETBEGX
530 #define getbegx(win) ((win)?(win)->_begx:ERR)
531 #define getbegy(win) ((win)?(win)->_begy:ERR)
534 #if !defined(getmaxx) && !HAVE_GETMAXX
535 #define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
536 #define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
541 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
542 : (w)->_begx - (w)->_parent->_begx)
544 #if !defined(getparx) && !HAVE_GETPARX
546 #define getparx(win) __m_getparx(win)
547 #define getpary(win) __m_getpary(win)
549 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
550 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
554 #if !defined(mvwvline) && !HAVE_MVWVLINE
555 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
556 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
559 #if !defined(mvvline) && !HAVE_MVVLINE
560 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
561 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
565 * Try to accommodate curses implementations that have no terminfo support.
568 #define TIGETNUM(ti,tc) tigetnum(ti)
570 #define TIGETNUM(ti,tc) tgetnum(tc)
574 #define TIGETSTR(ti,tc) tigetstr(ti)
576 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
579 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
580 * (which is incompatible with legacy usage, doesn't solve any problems).
582 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
583 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
585 #define UChar(c) ((unsigned char)(c))
587 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
589 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
590 #include <nc_alloc.h>
591 #if HAVE_NC_FREEALL && defined(USE_TINFO)
593 #define ExitProgram(code) _nc_free_tinfo(code)
596 #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
597 #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
598 #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
602 #define ExitProgram(code) exit(code)
606 #define EXIT_SUCCESS 0
609 #define EXIT_FAILURE 1
613 #include <nc_mingw.h>
614 /* conflicts in test/firstlast.c */
620 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
621 * curses which doesn't have const parameters declared (so far) in the places
624 #ifndef NCURSES_CONST
625 #define NCURSES_CONST /* nothing */
628 /* out-of-band values for representing absent capabilities */
629 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
630 #define ABSENT_NUMERIC (-1)
631 #define ABSENT_STRING (char *)0
633 /* out-of-band values for representing cancels */
634 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
635 #define CANCELLED_NUMERIC (-2)
636 #define CANCELLED_STRING (char *)(-1)
638 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
639 #define VALID_NUMERIC(s) ((s) >= 0)
640 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
642 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
644 #define CATCHALL(handler) { \
646 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
647 if (nsig != SIGKILL) \
648 signal(nsig, handler); \
652 * Workaround for clean(er) compile with Solaris's legacy curses.
653 * The same would be needed for HPUX 10.20
656 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
657 #define TPUTS_ARG char
658 extern char *tgoto(char *, int, int); /* available, but not prototyped */
660 #define TPUTS_ARG int
665 * Workarounds for Solaris's X/Open curses
667 #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
668 #if !defined(KEY_MIN) && defined(__KEY_MIN)
669 #define KEY_MIN __KEY_MIN
671 #if !defined(KEY_MAX) && defined(__KEY_MIN)
672 #define KEY_MAX __KEY_MAX
677 * Workaround to build with Sun's default SVr4 curses.
679 #ifdef NCURSES_VERSION
680 #ifndef HAVE_VW_PRINTW
681 #define HAVE_VW_PRINTW 1
686 * ncurses provides arrays of capability names; X/Open discarded these SVr4
687 * features. Some implementations continue to provide them (see the test
690 #ifdef NCURSES_VERSION
691 #ifndef HAVE_CURSES_DATA_BOOLNAMES
692 #define HAVE_CURSES_DATA_BOOLNAMES 1
697 * ncurses uses const in some places where X/Open does (or did) not allow.
699 #ifdef NCURSES_VERSION
700 #define CONST_MENUS const
702 #define CONST_MENUS /* nothing */
705 #ifndef HAVE_USE_WINDOW
706 #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
707 #define HAVE_USE_WINDOW 0
709 #define HAVE_USE_WINDOW 1
714 * Simplify setting up demo of threading with these macros.
718 typedef int (*NCURSES_WINDOW_CB) (WINDOW *, void *);
719 typedef int (*NCURSES_SCREEN_CB) (SCREEN *, void *);
723 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
724 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
725 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
727 #define USING_WINDOW(w,func) func(w)
728 #define USING_WINDOW2(w,func,data) func(w,data)
729 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
733 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
734 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
736 #define USING_SCREEN(s,func,data) func(data)
737 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
741 #define Trace(p) _tracef p
744 #define Trace(p) /* nothing */
748 #define MvAddCh (void) mvaddch
749 #define MvWAddCh (void) mvwaddch
750 #define MvAddStr (void) mvaddstr
751 #define MvWAddStr (void) mvwaddstr
752 #define MvWAddChStr (void) mvwaddchstr
753 #define MvPrintw (void) mvprintw
754 #define MvWPrintw (void) mvwprintw
755 #define MvHLine (void) mvhline
756 #define MvWHLine (void) mvwhline
757 #define MvVLine (void) mvvline
758 #define MvWVLine (void) mvwvline
761 * Workaround for defective implementation of gcc attribute warn_unused_result
763 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
764 #define IGNORE_RC(func) errno = func
766 #define IGNORE_RC(func) (void) func
767 #endif /* gcc workarounds */
769 #define init_mb(state) memset(&state, 0, sizeof(state))
771 #endif /* __TEST_PRIV_H */