1 /****************************************************************************
2 * Copyright (c) 1998-2013,2014 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.131 2014/10/25 01:20:34 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_ASSUME_DEFAULT_COLORS
62 #define HAVE_ASSUME_DEFAULT_COLORS 0
65 #ifndef HAVE_CURSES_VERSION
66 #define HAVE_CURSES_VERSION 0
73 #ifndef HAVE_COLOR_SET
74 #define HAVE_COLOR_SET 0
86 #define HAVE_GETBEGX 0
90 #define HAVE_GETCURX 0
94 #define HAVE_GETMAXX 0
98 #define HAVE_GETOPT_H 0
102 #define HAVE_GETPARX 0
106 #define HAVE_GETWIN 0
110 #define HAVE_LIBFORM 0
114 #define HAVE_LIBMENU 0
117 #ifndef HAVE_LIBPANEL
118 #define HAVE_LIBPANEL 0
121 #ifndef HAVE_LOCALE_H
122 #define HAVE_LOCALE_H 0
126 #define HAVE_MATH_H 0
130 #define HAVE_MENU_H 0
134 #define HAVE_MVVLINE 0
137 #ifndef HAVE_MVWVLINE
138 #define HAVE_MVWVLINE 0
145 #ifndef HAVE_NC_ALLOC_H
146 #define HAVE_NC_ALLOC_H 0
150 #define HAVE_PANEL_H 0
154 #define HAVE_PUTWIN 0
157 #ifndef HAVE_RESIZE_TERM
158 #define HAVE_RESIZE_TERM 0
161 #ifndef HAVE_RIPOFFLINE
162 #define HAVE_RIPOFFLINE 0
165 #ifndef HAVE_SCR_DUMP
166 #define HAVE_SCR_DUMP 0
169 #ifndef HAVE_SETUPTERM
170 #define HAVE_SETUPTERM 0
173 #ifndef HAVE_SLK_COLOR
174 #define HAVE_SLK_COLOR 0
177 #ifndef HAVE_SLK_INIT
178 #define HAVE_SLK_INIT 0
181 #ifndef HAVE_SYS_IOCTL_H
182 #define HAVE_SYS_IOCTL_H 0
185 #ifndef HAVE_SYS_SELECT_H
186 #define HAVE_SYS_SELECT_H 0
189 #ifndef HAVE_TERMATTRS
190 #define HAVE_TERMATTRS 0
193 #ifndef HAVE_TERMIOS_H
194 #define HAVE_TERMIOS_H 0
197 #ifndef HAVE_TERMNAME
198 #define HAVE_TERMNAME 0
201 #ifndef HAVE_TERM_ENTRY_H
202 #define HAVE_TERM_ENTRY_H 0
206 #define HAVE_TGETENT 0
209 #ifndef HAVE_TIGETNUM
210 #define HAVE_TIGETNUM 0
213 #ifndef HAVE_TIGETSTR
214 #define HAVE_TIGETSTR 0
217 #ifndef HAVE_TYPEAHEAD
218 #define HAVE_TYPEAHEAD 0
222 #define HAVE_WINSSTR 0
225 #ifndef HAVE_USE_DEFAULT_COLORS
226 #define HAVE_USE_DEFAULT_COLORS 0
230 #define HAVE_USE_ENV 0
233 #ifndef HAVE_USE_EXTENDED_NAMES
234 #define HAVE_USE_EXTENDED_NAMES 0
237 #ifndef HAVE_USE_SCREEN
238 #define HAVE_USE_SCREEN 0
241 #ifndef HAVE_USE_WINDOW
242 #define HAVE_USE_WINDOW 0
246 #define HAVE_VIDPUTS 0
249 #ifndef HAVE_VID_PUTS
250 #define HAVE_VID_PUTS 0
254 #define HAVE_WRESIZE 0
257 #ifndef NCURSES_EXT_FUNCS
258 #define NCURSES_EXT_FUNCS 0
262 #define NEED_PTEM_H 0
266 #define NEED_WCHAR_H 0
274 * Workaround for HPUX
276 #if defined(__hpux) && !defined(NCURSES_VERSION)
277 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
283 #include <sys/types.h>
290 #include <signal.h> /* include before curses.h to work around glibc bug */
294 #ifdef HAVE_LIBUTF8_H
299 #if defined(HAVE_XCURSES)
301 #elif defined(HAVE_NCURSESW_NCURSES_H)
302 #include <ncursesw/curses.h>
303 #elif defined(HAVE_NCURSES_NCURSES_H)
304 #include <ncurses/curses.h>
309 #if defined(HAVE_XCURSES) || defined(PDCURSES)
310 /* no other headers */
311 #undef HAVE_SETUPTERM /* nonfunctional */
312 #define HAVE_SETUPTERM 0
313 #undef HAVE_TGETENT /* nonfunctional */
314 #define HAVE_TGETENT 0
315 #undef HAVE_TIGETSTR /* nonfunctional */
316 #define HAVE_TIGETSTR 0
317 #elif defined(HAVE_NCURSESW_TERM_H)
318 #include <ncursesw/term.h>
319 #elif defined(HAVE_NCURSES_TERM_H)
320 #include <ncurses/term.h>
321 #elif defined(HAVE_TERM_H)
326 * Not all curses.h implementations include unctrl.h,
328 #if defined(HAVE_NCURSESW_UNCTRL_H)
329 #include <ncursesw/unctrl.h>
330 #elif defined(HAVE_NCURSES_UNCTRL_H)
331 #include <ncurses/unctrl.h>
332 #elif defined(HAVE_UNCTRL_H)
338 #elif !defined(HAVE_GETOPT_HEADER)
339 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
344 #endif /* HAVE_GETOPT_H */
349 #define setlocale(name,string) /* nothing */
356 #define GCC_NORETURN /* nothing */
358 #ifndef GCC_PRINTFLIKE
359 #define GCC_PRINTFLIKE(a,b) /* nothing */
362 #define GCC_UNUSED /* nothing */
366 #define getnstr(s,n) getstr(s)
371 #define USE_SOFTKEYS 1
373 #define USE_SOFTKEYS 0
378 #define slk_init() /* nothing */
379 #define slk_restore() /* nothing */
380 #define slk_clear() /* nothing */
383 #ifndef HAVE_WSYNCDOWN
384 #define wsyncdown(win) /* nothing */
387 #ifndef USE_WIDEC_SUPPORT
388 #if (defined(_XOPEN_SOURCE_EXTENDED) \
389 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
390 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
391 && defined(WACS_ULCORNER)
392 #define USE_WIDEC_SUPPORT 1
394 #define USE_WIDEC_SUPPORT 0
398 #if HAVE_PANEL_H && HAVE_LIBPANEL
399 #define USE_LIBPANEL 1
401 #define USE_LIBPANEL 0
404 #if HAVE_MENU_H && HAVE_LIBMENU
405 #define USE_LIBMENU 1
407 #define USE_LIBMENU 0
410 #if HAVE_FORM_H && HAVE_LIBFORM
411 #define USE_LIBFORM 1
413 #define USE_LIBFORM 0
416 /* workaround, to build against NetBSD's variant of the form library */
417 #ifdef HAVE_NETBSD_FORM_H
418 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
420 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
423 /* workaround, to build against NetBSD's variant of the form library */
424 #ifdef HAVE_NETBSD_MENU_H
425 #define menu_itemwidth(menu) (menu)->max_item_width
427 #define menu_itemwidth(menu) (menu)->itemlen
430 #ifndef HAVE_TYPE_ATTR_T
431 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
432 #define attr_t chtype
437 #if !USE_WIDEC_SUPPORT
438 #define NCURSES_CH_T chtype
440 #define NCURSES_CH_T cchar_t
443 #ifndef NCURSES_COLOR_T
444 #define NCURSES_COLOR_T short
447 #ifndef NCURSES_PAIRS_T
448 #define NCURSES_PAIRS_T short
451 #ifndef NCURSES_OPAQUE
452 #define NCURSES_OPAQUE 0
459 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
460 #define CURSES_WACS_SYMBOLS
463 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
464 /* NetBSD 5.1 defines these incorrectly */
498 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
499 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
500 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
501 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
502 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
503 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
504 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
505 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
506 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
507 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
508 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
509 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
510 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
511 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
512 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
513 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
514 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
515 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
516 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
517 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
518 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
519 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
520 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
521 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
522 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
523 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
524 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
525 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
526 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
527 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
528 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
529 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
533 #define CTRL(x) ((x) & 0x1f)
535 #define QUIT CTRL('Q')
536 #define ESCAPE CTRL('[')
539 #define KEY_MIN 256 /* not defined in Solaris 8 */
542 #ifdef DECL_CURSES_DATA_BOOLNAMES
543 extern char *boolnames[], *boolcodes[], *boolfnames[];
544 extern char *numnames[], *numcodes[], *numfnames[];
545 extern char *strnames[], *strcodes[], *strfnames[];
548 #define colored_chtype(ch, attr, pair) \
549 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
552 * Workaround for HPUX
554 #if defined(__hpux) && !defined(NCURSES_VERSION)
555 #define getbegx(w) __getbegx(w)
556 #define getbegy(w) __getbegy(w)
557 #define getcurx(w) __getcurx(w)
558 #define getcury(w) __getcury(w)
559 #define getmaxx(w) __getmaxx(w)
560 #define getmaxy(w) __getmaxy(w)
561 #define getparx(w) __getparx(w)
562 #define getpary(w) __getpary(w)
566 * Workaround in case getcchar() returns a positive value when the source
567 * string produces only a L'\0'.
569 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
570 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
571 wchar_t test_wch[CCHARW_MAX + 2]; \
573 NCURSES_PAIRS_T test_pair; \
575 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
576 && test_wch[0] != L'\0') { \
585 * These usually are implemented as macros, but may be functions.
587 #if !defined(getcurx) && !HAVE_GETCURX
588 #define getcurx(win) ((win)?(win)->_curx:ERR)
589 #define getcury(win) ((win)?(win)->_cury:ERR)
592 #if !defined(getbegx) && !HAVE_GETBEGX
593 #define getbegx(win) ((win)?(win)->_begx:ERR)
594 #define getbegy(win) ((win)?(win)->_begy:ERR)
597 #if !defined(getmaxx) && !HAVE_GETMAXX
598 #define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
599 #define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
604 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
605 : (w)->_begx - (w)->_parent->_begx)
607 #if !defined(getparx) && !HAVE_GETPARX
609 #define getparx(win) __m_getparx(win)
610 #define getpary(win) __m_getpary(win)
612 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
613 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
617 #if !defined(mvwvline) && !HAVE_MVWVLINE
618 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
619 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
622 #if !defined(mvvline) && !HAVE_MVVLINE
623 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
624 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
628 * Try to accommodate curses implementations that have no terminfo support.
631 #define TIGETNUM(ti,tc) tigetnum(ti)
633 #define TIGETNUM(ti,tc) tgetnum(tc)
637 #define TIGETSTR(ti,tc) tigetstr(ti)
639 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
643 * So far (2013 - more than ten years), only ncurses implements
644 * use_extended_names().
646 #if defined(NCURSES_XNAMES)
647 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
648 #define NCURSES_XNAMES 1
650 #define NCURSES_XNAMES 0
653 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
654 * (which is incompatible with legacy usage, doesn't solve any problems).
656 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
657 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
659 #define UChar(c) ((unsigned char)(c))
661 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
663 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
664 #include <nc_alloc.h>
665 #if HAVE_NC_FREEALL && defined(USE_TINFO)
667 #define ExitProgram(code) _nc_free_tinfo(code)
670 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
671 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
672 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
676 #define ExitProgram(code) exit(code)
680 #define EXIT_SUCCESS 0
683 #define EXIT_FAILURE 1
686 #if defined(__MINGW32__) || defined(USE_WIN32CON_DRIVER)
688 #if defined(PDCURSES)
691 # error WINVER must at least be 0x0501
694 # define WINVER 0x0501
697 #include <sys/time.h> /* for struct timeval */
699 #define sleep(n) Sleep((n) * 1000)
702 #define getlogin() "username"
704 #elif defined(HAVE_NCURSESW_NCURSES_H)
705 #include <ncursesw/nc_mingw.h>
706 #elif defined(HAVE_NCURSES_NCURSES_H)
707 #include <ncurses/nc_mingw.h>
709 #include <nc_mingw.h>
712 /* conflicts in test/firstlast.c */
718 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
719 * curses which doesn't have const parameters declared (so far) in the places
722 #ifndef NCURSES_CONST
723 #define NCURSES_CONST /* nothing */
726 /* out-of-band values for representing absent capabilities */
727 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
728 #define ABSENT_NUMERIC (-1)
729 #define ABSENT_STRING (char *)0
731 /* out-of-band values for representing cancels */
732 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
733 #define CANCELLED_NUMERIC (-2)
734 #define CANCELLED_STRING (char *)(-1)
736 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
737 #define VALID_NUMERIC(s) ((s) >= 0)
738 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
740 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
742 #define CATCHALL(handler) { \
744 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
745 if (nsig != SIGKILL) \
746 signal(nsig, handler); \
750 * Workaround for clean(er) compile with Solaris's legacy curses.
751 * The same would be needed for HPUX 10.20
754 #define TPUTS_ARG int
757 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
759 #define TPUTS_ARG char
760 extern char *tgoto(char *, int, int); /* available, but not prototyped */
764 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
768 #define TPUTS_RETURN(value) return value
772 * Workarounds for Solaris's X/Open curses
774 #if !defined(KEY_MIN) && defined(__KEY_MIN)
775 #define KEY_MIN __KEY_MIN
777 #if !defined(KEY_MAX) && defined(__KEY_MIN)
778 #define KEY_MAX __KEY_MAX
782 * Workaround to build with Sun's default SVr4 curses.
784 #ifdef NCURSES_VERSION
785 #ifndef HAVE_VW_PRINTW
786 #define HAVE_VW_PRINTW 1
791 * ncurses provides arrays of capability names; X/Open discarded these SVr4
792 * features. Some implementations continue to provide them (see the test
795 #ifdef NCURSES_VERSION
796 #ifndef HAVE_CURSES_DATA_BOOLNAMES
797 #define HAVE_CURSES_DATA_BOOLNAMES 1
802 * ncurses uses const in some places where X/Open does (or did) not allow.
804 #ifdef NCURSES_VERSION
805 #define CONST_MENUS const
807 #define CONST_MENUS /* nothing */
811 * Simplify setting up demo of threading with these macros.
815 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
816 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
817 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
819 #define USING_WINDOW(w,func) func(w)
820 #define USING_WINDOW2(w,func,data) func(w,data)
821 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
825 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
826 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
828 #define USING_SCREEN(s,func,data) func(data)
829 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
833 #define Trace(p) _tracef p
836 #define Trace(p) /* nothing */
840 #define Trace2(p) /* nothing */
842 #define MvAddCh (void) mvaddch
843 #define MvWAddCh (void) mvwaddch
844 #define MvAddStr (void) mvaddstr
845 #define MvWAddStr (void) mvwaddstr
846 #define MvWAddChStr (void) mvwaddchstr
847 #define MvPrintw (void) mvprintw
848 #define MvWPrintw (void) mvwprintw
849 #define MvHLine (void) mvhline
850 #define MvWHLine (void) mvwhline
851 #define MvVLine (void) mvvline
852 #define MvWVLine (void) mvwvline
855 * The macro likely uses unsigned values, while X/Open prototype uses int.
857 #if defined(wattrset) || defined(PDCURSES)
858 #define AttrArg(p,a) (attr_t) ((attr_t)(p) | (attr_t)(a))
860 #define AttrArg(p,a) (int) ((attr_t)(p) | (attr_t)(a))
864 * Workaround for defective implementation of gcc attribute warn_unused_result
866 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
867 #define IGNORE_RC(func) errno = func
869 #define IGNORE_RC(func) (void) func
870 #endif /* gcc workarounds */
872 #define init_mb(state) memset(&state, 0, sizeof(state))
874 #endif /* __TEST_PRIV_H */