1 /****************************************************************************
2 * Copyright 2018-2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2017,2018 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 /****************************************************************************
31 * Author: Thomas E. Dickey 1996-on *
32 ****************************************************************************/
33 /* $Id: test.priv.h,v 1.197 2021/04/25 00:00:24 tom Exp $ */
36 #define __TEST_PRIV_H 1
38 #include <ncurses_cfg.h>
41 * Fix ifdef's that look for the form/menu/panel libraries, if we are building
42 * with wide-character ncurses.
45 #define HAVE_LIBFORMW 1
46 #define HAVE_LIBFORM 1
50 #define HAVE_LIBMENUW 1
51 #define HAVE_LIBMENU 1
55 #define HAVE_LIBPANELW 1
56 #define HAVE_LIBPANEL 1
60 * Fallback definitions to accommodate broken compilers.
62 #ifndef HAVE_ALLOC_PAIR
63 #define HAVE_ALLOC_PAIR 0
66 #ifndef HAVE_ASSUME_DEFAULT_COLORS
67 #define HAVE_ASSUME_DEFAULT_COLORS 0
70 #ifndef HAVE_BSD_STRING_H
71 #define HAVE_BSD_STRING_H 0
74 #ifndef HAVE_CURSES_VERSION
75 #define HAVE_CURSES_VERSION 0
86 #ifndef HAVE_COLOR_CONTENT
87 #define HAVE_COLOR_CONTENT 0
91 #define HAVE_COPYWIN 0
94 #ifndef HAVE_COLOR_SET
95 #define HAVE_COLOR_SET 0
98 #ifndef HAVE_DELSCREEN
99 #define HAVE_DELSCREEN 0
103 #define HAVE_DUPWIN 0
107 #define HAVE_FILTER 0
111 #define HAVE_FORM_H 0
115 #define HAVE_GETBEGX 0
119 #define HAVE_GETCURX 0
123 #define HAVE_GETMAXX 0
126 #ifndef HAVE_GETOPT_H
127 #define HAVE_GETOPT_H 0
131 #define HAVE_GETPARX 0
135 #define HAVE_GETWIN 0
138 #ifndef HAVE_HALFDELAY
139 #define HAVE_HALFDELAY 0
142 #ifndef HAVE_INIT_EXTENDED_COLOR
143 #define HAVE_INIT_EXTENDED_COLOR 0
147 #define HAVE_LIBFORM 0
151 #define HAVE_LIBMENU 0
154 #ifndef HAVE_LIBPANEL
155 #define HAVE_LIBPANEL 0
158 #ifndef HAVE_LANGINFO_CODESET
159 #define HAVE_LANGINFO_CODESET 0
162 #ifndef HAVE_LOCALE_H
163 #define HAVE_LOCALE_H 0
167 #define HAVE_MATH_H 0
171 #define HAVE_MENU_H 0
174 #ifndef HAVE_MVDERWIN
175 #define HAVE_MVDERWIN 0
179 #define HAVE_MVVLINE 0
186 #ifndef HAVE_MVWVLINE
187 #define HAVE_MVWVLINE 0
194 #ifndef HAVE_NC_ALLOC_H
195 #define HAVE_NC_ALLOC_H 0
199 #define HAVE_NEWPAD 0
203 #define HAVE_PANEL_H 0
207 #define HAVE_PUTWIN 0
210 #ifndef HAVE_RESET_COLOR_PAIRS
211 #define HAVE_RESET_COLOR_PAIRS 0
214 #ifndef HAVE_RESIZE_TERM
215 #define HAVE_RESIZE_TERM 0
218 #ifndef HAVE_RESTARTTERM
219 #define HAVE_RESTARTTERM 0
222 #ifndef HAVE_RIPOFFLINE
223 #define HAVE_RIPOFFLINE 0
226 #ifndef HAVE_SCR_DUMP
227 #define HAVE_SCR_DUMP 0
230 #ifndef HAVE_SETUPTERM
231 #define HAVE_SETUPTERM 0
234 #ifndef HAVE_SLK_COLOR
235 #define HAVE_SLK_COLOR 0
238 #ifndef HAVE_SLK_INIT
239 #define HAVE_SLK_INIT 0
242 #ifndef HAVE_STDINT_H
243 #define HAVE_STDINT_H 0
246 #ifndef HAVE_STDNORETURN_H
247 #define HAVE_STDNORETURN_H 0
251 #define HAVE_STRSTR 0
254 #ifndef HAVE_SYS_IOCTL_H
255 #define HAVE_SYS_IOCTL_H 0
258 #ifndef HAVE_SYS_SELECT_H
259 #define HAVE_SYS_SELECT_H 0
262 #ifndef HAVE_TERMATTRS
263 #define HAVE_TERMATTRS 0
266 #ifndef HAVE_TERMIOS_H
267 #define HAVE_TERMIOS_H 0
270 #ifndef HAVE_TERMNAME
271 #define HAVE_TERMNAME 0
274 #ifndef HAVE_TERM_ENTRY_H
275 #define HAVE_TERM_ENTRY_H 0
279 #define HAVE_TGETENT 0
282 #ifndef HAVE_TIGETNUM
283 #define HAVE_TIGETNUM 0
286 #ifndef HAVE_TIGETSTR
287 #define HAVE_TIGETSTR 0
290 #ifndef HAVE_TPUTS_SP
291 #define HAVE_TPUTS_SP 0
295 #define HAVE_TSEARCH 0
298 #ifndef HAVE_TYPEAHEAD
299 #define HAVE_TYPEAHEAD 0
303 #define HAVE_WINSSTR 0
306 #ifndef HAVE_USE_DEFAULT_COLORS
307 #define HAVE_USE_DEFAULT_COLORS 0
311 #define HAVE_USE_ENV 0
314 #ifndef HAVE_USE_EXTENDED_NAMES
315 #define HAVE_USE_EXTENDED_NAMES 0
318 #ifndef HAVE_USE_SCREEN
319 #define HAVE_USE_SCREEN 0
322 #ifndef HAVE_USE_WINDOW
323 #define HAVE_USE_WINDOW 0
327 #define HAVE_VIDPUTS 0
330 #ifndef HAVE_VID_PUTS
331 #define HAVE_VID_PUTS 0
334 #ifndef HAVE_WINSDELLN
335 #define HAVE_WINSDELLN 0
339 #define HAVE_WRESIZE 0
343 #define HAVE__TRACEF 0
346 #ifndef NCURSES_EXT_FUNCS
347 #define NCURSES_EXT_FUNCS 0
351 #define NEED_PTEM_H 0
355 #define NEED_WCHAR_H 0
363 * Workaround for HPUX
365 #if defined(__hpux) && !defined(NCURSES_VERSION)
366 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
372 #include <sys/types.h>
379 #include <signal.h> /* include before curses.h to work around glibc bug */
383 #ifdef HAVE_LIBUTF8_H
388 #if defined(HAVE_XCURSES)
390 #elif defined(HAVE_NCURSESW_NCURSES_H)
391 #include <ncursesw/curses.h>
392 #elif defined(HAVE_NCURSES_NCURSES_H)
393 #include <ncurses/curses.h>
398 #if HAVE_STDNORETURN_H && !defined(NCURSES_VERSION)
399 #include <stdnoreturn.h>
401 #define GCC_NORETURN _Noreturn
404 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
405 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */
408 #if defined(HAVE_XCURSES) || defined(PDCURSES)
409 /* no other headers */
410 #undef HAVE_SETUPTERM /* nonfunctional */
411 #define HAVE_SETUPTERM 0
412 #undef HAVE_TGETENT /* nonfunctional */
413 #define HAVE_TGETENT 0
414 #undef HAVE_TIGETSTR /* nonfunctional */
415 #define HAVE_TIGETSTR 0
416 #elif defined(HAVE_NCURSESW_TERM_H)
417 #include <ncursesw/term.h>
418 #elif defined(HAVE_NCURSES_TERM_H)
419 #include <ncurses/term.h>
420 #elif defined(HAVE_TERM_H)
425 * Not all curses.h implementations include unctrl.h,
427 #if defined(HAVE_NCURSESW_UNCTRL_H)
428 #include <ncursesw/unctrl.h>
429 #elif defined(HAVE_NCURSES_UNCTRL_H)
430 #include <ncurses/unctrl.h>
431 #elif defined(HAVE_UNCTRL_H)
437 #elif !defined(HAVE_GETOPT_HEADER)
438 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
443 #endif /* HAVE_GETOPT_H */
448 #define setlocale(name,string) /* nothing */
454 #if defined(_MSC_VER)
456 #define popen(s,n) _popen(s,n)
458 #define pclose(s) _pclose(s)
462 #define GCC_NORETURN /* nothing */
464 #ifndef GCC_PRINTFLIKE
465 #define GCC_PRINTFLIKE(a,b) /* nothing */
467 #ifndef GCC_SCANFLIKE
468 #define GCC_SCANFLIKE(a,b) /* nothing */
471 #define GCC_UNUSED /* nothing */
475 #define getnstr(s,n) getstr(s)
478 #if HAVE_INIT_EXTENDED_COLOR
479 #define USE_EXTENDED_COLOR 1
481 #define USE_EXTENDED_COLOR 0
486 #define USE_SOFTKEYS 1
488 #define USE_SOFTKEYS 0
493 #define slk_init() /* nothing */
494 #define slk_restore() /* nothing */
495 #define slk_clear() /* nothing */
498 #ifndef HAVE_CURSES_DATA_TABSIZE
499 #define HAVE_CURSES_DATA_TABSIZE 0
502 #if !NCURSES_EXT_FUNCS
503 #if HAVE_CURSES_DATA_TABSIZE
504 #define set_tabsize(n) TABSIZE = (n)
506 #define set_tabsize(n) /* nothing */
511 #define USE_SP_FUNCS 1
513 #define USE_SP_FUNCS 0
516 #ifndef HAVE_WSYNCDOWN
517 #define wsyncdown(win) /* nothing */
520 #ifndef USE_WIDEC_SUPPORT
521 #if (defined(_XOPEN_SOURCE_EXTENDED) \
522 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
523 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
524 && defined(WACS_ULCORNER)
525 #define USE_WIDEC_SUPPORT 1
527 #define USE_WIDEC_SUPPORT 0
531 #if HAVE_PANEL_H && HAVE_LIBPANEL
532 #define USE_LIBPANEL 1
534 #define USE_LIBPANEL 0
537 #if HAVE_MENU_H && HAVE_LIBMENU
538 #define USE_LIBMENU 1
540 #define USE_LIBMENU 0
543 #if HAVE_FORM_H && HAVE_LIBFORM
544 #define USE_LIBFORM 1
546 #define USE_LIBFORM 0
549 /* workaround, to build against NetBSD's variant of the form library */
550 #ifdef HAVE_NETBSD_FORM_H
551 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos
553 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
556 /* workaround, to build against NetBSD's variant of the form library */
557 #ifdef HAVE_NETBSD_MENU_H
558 #define menu_itemwidth(menu) (menu)->max_item_width
560 #define menu_itemwidth(menu) (menu)->itemlen
563 #ifndef HAVE_TYPE_ATTR_T
564 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
565 #define attr_t chtype
570 #if !USE_WIDEC_SUPPORT
571 #define NCURSES_CH_T chtype
573 #define NCURSES_CH_T cchar_t
576 #ifndef NCURSES_COLOR_T
577 #define NCURSES_COLOR_T short
580 #ifndef NCURSES_PAIRS_T
581 #define NCURSES_PAIRS_T short
588 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
589 #define CURSES_WACS_SYMBOLS
592 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
593 /* NetBSD 5.1 defines these incorrectly */
627 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
628 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
629 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
630 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
631 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
632 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
633 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
634 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
635 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
636 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
637 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
638 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
639 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
640 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
641 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
642 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
643 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
644 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
645 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
646 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
647 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
648 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
649 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
650 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
651 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
652 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
653 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
654 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
655 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
656 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
657 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
658 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
662 #define WA_NORMAL A_NORMAL
665 #define WA_BOLD A_BOLD
668 #define WA_REVERSE A_REVERSE
671 #define WA_UNDERLINE A_UNDERLINE
674 #define WA_BLINK A_BLINK
686 #define CTRL(x) ((x) & 0x1f)
688 #define QUIT CTRL('Q')
689 #define ESCAPE CTRL('[')
692 #define KEY_MIN 256 /* not defined in Solaris 8 */
695 #define HELP_KEY_1 '?'
696 #define HELP_KEY_2 KEY_F(1)
698 /* from nc_string.h, to make this stand alone */
699 #if HAVE_BSD_STRING_H
700 #include <bsd/string.h>
704 #define NCURSES_VOID /* nothing */
706 #define NCURSES_VOID (void)
710 #define HAVE_STRLCAT 0
714 #define HAVE_STRLCPY 0
717 #ifndef HAVE_SNPRINTF
718 #define HAVE_SNPRINTF 0
721 #ifndef USE_STRING_HACKS
722 #define USE_STRING_HACKS 0
728 #define NCURSES_CAST(type,value) static_cast<type>(value)
730 #define NCURSES_CAST(type,value) (type)(value)
734 #if USE_STRING_HACKS && HAVE_STRLCAT
735 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
736 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
738 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
739 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
742 #if USE_STRING_HACKS && HAVE_STRLCPY
743 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
744 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
746 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
747 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
750 #if USE_STRING_HACKS && HAVE_SNPRINTF
751 #define _nc_SPRINTF NCURSES_VOID (snprintf)
752 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
754 #define _nc_SPRINTF NCURSES_VOID (sprintf)
755 #define _nc_SLIMIT(n) /* nothing */
759 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
760 * curses did, and some implementations provide them anyway, but undeclared.
762 #ifdef DECL_CURSES_DATA_BOOLNAMES
763 extern char *boolnames[], *boolcodes[], *boolfnames[];
764 extern char *numnames[], *numcodes[], *numfnames[];
765 extern char *strnames[], *strcodes[], *strfnames[];
769 * Again, an SVr4 curses feature latent in the libraries but not in headers.
771 #ifndef DECL_CURSES_DATA_TABSIZE
772 #define DECL_CURSES_DATA_TABSIZE 0
775 #if DECL_CURSES_DATA_TABSIZE
777 #undef HAVE_CURSES_DATA_TABSIZE
778 #define HAVE_CURSES_DATA_TABSIZE 1
781 #ifndef HAVE_CURSES_DATA_TABSIZE
782 #define HAVE_CURSES_DATA_TABSIZE 0
786 * X/Open Curses provides termname(), whose return value is analogous to the
787 * SVr4 curses variable ttytype[].
789 #ifndef HAVE_CURSES_DATA_TTYTYPE
790 #define HAVE_CURSES_DATA_TTYTYPE 0
793 #ifndef DECL_CURSES_DATA_TTYTYPE
794 #define DECL_CURSES_DATA_TTYTYPE 0
797 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
798 #define ttytype termname()
801 #define colored_chtype(ch, attr, pair) \
802 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
805 * Workaround for HPUX
807 #if defined(__hpux) && !defined(NCURSES_VERSION)
808 #define getbegx(w) __getbegx(w)
809 #define getbegy(w) __getbegy(w)
810 #define getcurx(w) __getcurx(w)
811 #define getcury(w) __getcury(w)
812 #define getmaxx(w) __getmaxx(w)
813 #define getmaxy(w) __getmaxy(w)
814 #define getparx(w) __getparx(w)
815 #define getpary(w) __getpary(w)
819 * Workaround in case getcchar() returns a positive value when the source
820 * string produces only a L'\0'.
822 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
823 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
824 wchar_t test_wch[CCHARW_MAX + 2]; \
826 NCURSES_PAIRS_T test_pair; \
828 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
829 && test_wch[0] != L'\0') { \
838 * These usually are implemented as macros, but may be functions.
840 #if !defined(getcurx) && !HAVE_GETCURX
841 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
842 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
845 #if !defined(getbegx) && !HAVE_GETBEGX
846 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
847 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
850 #if !defined(getmaxx) && !HAVE_GETMAXX
851 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
852 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
857 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
858 : (w)->_begx - (w)->_parent->_begx)
860 #if !defined(getparx) && !HAVE_GETPARX
862 #define getparx(win) __m_getparx(win)
863 #define getpary(win) __m_getpary(win)
865 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
866 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
870 #if !defined(mvwvline) && !HAVE_MVWVLINE
871 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
872 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
875 #if !defined(mvvline) && !HAVE_MVVLINE
876 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
877 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
881 * Try to accommodate curses implementations that have no terminfo support.
884 #define TIGETNUM(ti,tc) tigetnum(ti)
886 #define TIGETNUM(ti,tc) tgetnum(tc)
890 #define TIGETSTR(ti,tc) tigetstr(ti)
892 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
896 * So far (2013 - more than ten years), only ncurses implements
897 * use_extended_names().
899 #if defined(NCURSES_XNAMES)
900 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
901 #define NCURSES_XNAMES 1
903 #define NCURSES_XNAMES 0
907 * ncurses restores the cursor in endwin(). Other libraries may not.
909 #ifdef NCURSES_VERSION
910 #define stop_curses() endwin()
912 #define stop_curses() do { endwin(); curs_set(1); } while (0)
915 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
916 * (which is incompatible with legacy usage, doesn't solve any problems).
918 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
919 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
921 #define UChar(c) ((unsigned char)(c))
923 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
925 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
926 #include <nc_alloc.h>
927 #if HAVE_EXIT_TERMINFO && (defined(USE_TERMINFO) || defined(USE_TINFO))
929 #define ExitProgram(code) exit_terminfo(code)
930 #elif HAVE_EXIT_CURSES
932 #define ExitProgram(code) exit_curses(code)
934 #else /* not ncurses-tree */
935 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
936 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
937 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
941 #define ExitProgram(code) exit(code)
945 #define EXIT_SUCCESS 0
948 #define EXIT_FAILURE 1
952 #if (defined(_WIN32) || defined(_WIN64))
953 #define _NC_WINDOWS 1
956 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
958 #if defined(PDCURSES)
961 # error WINVER must at least be 0x0501
964 # define WINVER 0x0501
967 #include <sys/time.h> /* for struct timeval */
969 #define sleep(n) Sleep((n) * 1000)
972 #define getlogin() "username"
974 #elif defined(EXP_WIN32_DRIVER)
976 #if defined(HAVE_NCURSESW_NCURSES_H)
977 #include <ncursesw/nc_win32.h>
978 #elif defined(HAVE_NCURSES_NCURSES_H)
979 #include <ncurses/nc_win32.h>
981 #include <nc_win32.h>
986 #if defined(HAVE_NCURSESW_NCURSES_H)
987 #include <ncursesw/nc_mingw.h>
988 #elif defined(HAVE_NCURSES_NCURSES_H)
989 #include <ncurses/nc_mingw.h>
991 #include <nc_mingw.h>
996 /* conflicts in test/firstlast.c */
1003 #if TIME_WITH_SYS_TIME
1004 # include <sys/time.h>
1007 # if HAVE_SYS_TIME_H
1008 # include <sys/time.h>
1018 #ifndef STDOUT_FILENO
1019 #define STDOUT_FILENO 1
1023 extern char *_nc_strstr(const char *, const char *);
1024 #define strstr(a,b) _nc_strstr((a),(b))
1025 #endif /* !HAVE_STRSTR */
1027 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
1028 * curses which doesn't have const parameters declared (so far) in the places
1031 #ifndef NCURSES_CONST
1033 #define NCURSES_CONST const /* close enough */
1035 #define NCURSES_CONST /* nothing */
1039 /* out-of-band values for representing absent capabilities */
1040 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
1041 #define ABSENT_NUMERIC (-1)
1042 #define ABSENT_STRING (char *)0
1044 /* out-of-band values for representing cancels */
1045 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
1046 #define CANCELLED_NUMERIC (-2)
1047 #define CANCELLED_STRING (char *)(-1)
1049 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
1050 #define VALID_NUMERIC(s) ((s) >= 0)
1051 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1053 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1055 #define CATCHALL(handler) do { \
1057 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1058 if (nsig != SIGKILL) \
1059 signal(nsig, handler); \
1062 #ifdef NCURSES_VERSION
1063 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1065 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1068 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1069 #define SetupAlarm(opt) (void)opt
1071 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
1075 * Workaround for clean(er) compile with Solaris's legacy curses.
1076 * The same would be needed for HPUX 10.20
1079 #define TPUTS_ARG int
1082 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1084 #define TPUTS_ARG char
1085 extern char *tgoto(char *, int, int); /* available, but not prototyped */
1089 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1092 #ifndef TPUTS_RETURN
1093 #define TPUTS_RETURN(value) return value
1097 * Workarounds for Solaris's X/Open curses
1099 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1100 #define KEY_MIN __KEY_MIN
1102 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1103 #define KEY_MAX __KEY_MAX
1107 * Workaround to build with Sun's default SVr4 curses.
1109 #ifdef NCURSES_VERSION
1110 #ifndef HAVE_VW_PRINTW
1111 #define HAVE_VW_PRINTW 1
1116 * ncurses provides arrays of capability names; X/Open discarded these SVr4
1117 * features. Some implementations continue to provide them (see the test
1118 * configure script).
1120 #ifdef NCURSES_VERSION
1121 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1122 #define HAVE_CURSES_DATA_BOOLNAMES 1
1127 * ncurses provides a termcap interface; a few packagers replace or displace
1128 * its header file with an incompatible one. The demo_termcap program uses
1129 * the ncurses file, if available.
1131 #ifdef NCURSES_VERSION
1132 #ifndef HAVE_NCURSES_TERMCAP_H
1133 #define HAVE_NCURSES_TERMCAP_H 0
1135 #ifndef HAVE_TERMCAP_H
1136 #define HAVE_TERMCAP_H 0
1141 * ncurses uses const in some places where X/Open does (or did) not allow.
1143 #if defined(NCURSES_CONST)
1144 #define CONST_MENUS NCURSES_CONST
1145 #elif defined(PDCURSES)
1146 #define CONST_MENUS const
1148 #define CONST_MENUS /* nothing */
1152 * Simplify setting up demo of threading with these macros.
1156 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1157 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1158 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1159 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1161 #define USING_WINDOW(w,func) func(w, NULL)
1162 #define USING_WINDOW1(w,func,safe) func(w)
1163 #define USING_WINDOW2(w,func,data) func(w,data)
1164 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1168 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1169 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1171 #define USING_SCREEN(s,func,data) func(data)
1172 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1175 #if defined(TRACE) && HAVE__TRACEF
1176 #define Trace(p) _tracef p
1178 #define START_TRACE() \
1179 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1180 int t = _nc_getenv_num("NCURSES_TRACE"); \
1182 curses_trace((unsigned) t); \
1184 extern unsigned _nc_tracing;
1185 extern int _nc_getenv_num(const char *);
1188 #define Trace(p) /* nothing */
1190 #define START_TRACE() /* nothing */
1193 #define Trace2(p) /* nothing */
1195 #define AddCh(c) (void) addch((chtype)(c))
1196 #define WAddCh(w,c) (void) waddch((w),(chtype)(c))
1197 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c))
1198 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c))
1199 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s))
1200 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s))
1201 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s))
1202 #define MvPrintw (void) mvprintw
1203 #define MvWPrintw (void) mvwprintw
1204 #define MvHLine (void) mvhline
1205 #define MvWHLine (void) mvwhline
1206 #define MvVLine (void) mvvline
1207 #define MvWVLine (void) mvwvline
1210 * The macro likely uses unsigned values, while X/Open prototype uses int.
1212 #if defined(wattrset) || defined(PDCURSES)
1213 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a))
1215 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a))
1219 * Workaround for defective implementation of gcc attribute warn_unused_result
1221 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1222 #define IGNORE_RC(func) errno = func
1224 #define IGNORE_RC(func) (void) func
1225 #endif /* gcc workarounds */
1227 #define init_mb(state) memset(&state, 0, sizeof(state))
1229 #endif /* __TEST_PRIV_H */