1 /****************************************************************************
2 * Copyright 2018-2021,2022 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.203 2022/07/27 08:26:39 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_CFMAKERAW
71 #define HAVE_CFMAKERAW 0
78 #ifndef HAVE_COLOR_CONTENT
79 #define HAVE_COLOR_CONTENT 0
83 #define HAVE_COPYWIN 0
86 #ifndef HAVE_COLOR_SET
87 #define HAVE_COLOR_SET 0
90 #ifndef HAVE_BSD_STRING_H
91 #define HAVE_BSD_STRING_H 0
94 #ifndef HAVE_CURSES_VERSION
95 #define HAVE_CURSES_VERSION 0
102 #ifndef HAVE_DELSCREEN
103 #define HAVE_DELSCREEN 0
107 #define HAVE_DUPWIN 0
111 #define HAVE_FILTER 0
115 #define HAVE_FORM_H 0
119 #define HAVE_GETBEGX 0
123 #define HAVE_GETCURX 0
127 #define HAVE_GETMAXX 0
130 #ifndef HAVE_GETTIMEOFDAY
131 #define HAVE_GETTIMEOFDAY 0
134 #ifndef HAVE_GETOPT_H
135 #define HAVE_GETOPT_H 0
139 #define HAVE_GETPARX 0
143 #define HAVE_GETWIN 0
146 #ifndef HAVE_HALFDELAY
147 #define HAVE_HALFDELAY 0
150 #ifndef HAVE_INIT_EXTENDED_COLOR
151 #define HAVE_INIT_EXTENDED_COLOR 0
155 #define HAVE_LIBFORM 0
159 #define HAVE_LIBMENU 0
162 #ifndef HAVE_LIBPANEL
163 #define HAVE_LIBPANEL 0
166 #ifndef HAVE_LANGINFO_CODESET
167 #define HAVE_LANGINFO_CODESET 0
170 #ifndef HAVE_LOCALE_H
171 #define HAVE_LOCALE_H 0
174 #ifndef HAVE_MATH_FUNCS
175 #define HAVE_MATH_FUNCS 0
179 #define HAVE_MATH_H 0
183 #define HAVE_MENU_H 0
186 #ifndef HAVE_MVDERWIN
187 #define HAVE_MVDERWIN 0
191 #define HAVE_MVVLINE 0
198 #ifndef HAVE_MVWVLINE
199 #define HAVE_MVWVLINE 0
206 #ifndef HAVE_NC_ALLOC_H
207 #define HAVE_NC_ALLOC_H 0
211 #define HAVE_NEWPAD 0
215 #define HAVE_PANEL_H 0
219 #define HAVE_PUTWIN 0
222 #ifndef HAVE_RESET_COLOR_PAIRS
223 #define HAVE_RESET_COLOR_PAIRS 0
226 #ifndef HAVE_RESIZE_TERM
227 #define HAVE_RESIZE_TERM 0
230 #ifndef HAVE_RESTARTTERM
231 #define HAVE_RESTARTTERM 0
234 #ifndef HAVE_RIPOFFLINE
235 #define HAVE_RIPOFFLINE 0
238 #ifndef HAVE_SCR_DUMP
239 #define HAVE_SCR_DUMP 0
242 #ifndef HAVE_SETUPTERM
243 #define HAVE_SETUPTERM 0
246 #ifndef HAVE_SLK_COLOR
247 #define HAVE_SLK_COLOR 0
250 #ifndef HAVE_SLK_INIT
251 #define HAVE_SLK_INIT 0
254 #ifndef HAVE_STDINT_H
255 #define HAVE_STDINT_H 0
258 #ifndef HAVE_STDNORETURN_H
259 #define HAVE_STDNORETURN_H 0
263 #define HAVE_STRSTR 0
266 #ifndef HAVE_SYS_IOCTL_H
267 #define HAVE_SYS_IOCTL_H 0
270 #ifndef HAVE_SYS_SELECT_H
271 #define HAVE_SYS_SELECT_H 0
274 #ifndef HAVE_TERMATTRS
275 #define HAVE_TERMATTRS 0
278 #ifndef HAVE_TERMIOS_H
279 #define HAVE_TERMIOS_H 0
282 #ifndef HAVE_TERMNAME
283 #define HAVE_TERMNAME 0
286 #ifndef HAVE_TERM_ENTRY_H
287 #define HAVE_TERM_ENTRY_H 0
291 #define HAVE_TGETENT 0
294 #ifndef HAVE_TIGETNUM
295 #define HAVE_TIGETNUM 0
298 #ifndef HAVE_TIGETSTR
299 #define HAVE_TIGETSTR 0
302 #ifndef HAVE_TPUTS_SP
303 #define HAVE_TPUTS_SP 0
307 #define HAVE_TSEARCH 0
310 #ifndef HAVE_TYPEAHEAD
311 #define HAVE_TYPEAHEAD 0
315 #define HAVE_WINSSTR 0
318 #ifndef HAVE_UNGET_WCH
319 #define HAVE_UNGET_WCH 0
322 #ifndef HAVE_USE_DEFAULT_COLORS
323 #define HAVE_USE_DEFAULT_COLORS 0
327 #define HAVE_USE_ENV 0
330 #ifndef HAVE_USE_EXTENDED_NAMES
331 #define HAVE_USE_EXTENDED_NAMES 0
334 #ifndef HAVE_USE_SCREEN
335 #define HAVE_USE_SCREEN 0
338 #ifndef HAVE_USE_WINDOW
339 #define HAVE_USE_WINDOW 0
343 #define HAVE_VIDPUTS 0
346 #ifndef HAVE_VID_PUTS
347 #define HAVE_VID_PUTS 0
350 #ifndef HAVE_WINSDELLN
351 #define HAVE_WINSDELLN 0
355 #define HAVE_WRESIZE 0
359 #define HAVE__TRACEF 0
362 #ifndef NCURSES_EXT_FUNCS
363 #define NCURSES_EXT_FUNCS 0
367 #define NEED_PTEM_H 0
371 #define NEED_WCHAR_H 0
379 * Workaround for HPUX
381 #if defined(__hpux) && !defined(NCURSES_VERSION)
382 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
388 #include <sys/types.h>
395 #include <signal.h> /* include before curses.h to work around glibc bug */
399 #ifdef HAVE_LIBUTF8_H
404 #if defined(HAVE_XCURSES)
406 #elif defined(HAVE_NCURSESW_NCURSES_H)
407 #include <ncursesw/curses.h>
408 #elif defined(HAVE_NCURSES_NCURSES_H)
409 #include <ncurses/curses.h>
414 #if HAVE_STDNORETURN_H && !defined(NCURSES_VERSION)
415 #include <stdnoreturn.h>
417 #define GCC_NORETURN _Noreturn
420 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
421 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */
424 #if defined(HAVE_XCURSES) || defined(PDCURSES)
425 /* no other headers */
426 #undef HAVE_SETUPTERM /* nonfunctional */
427 #define HAVE_SETUPTERM 0
428 #undef HAVE_TGETENT /* nonfunctional */
429 #define HAVE_TGETENT 0
430 #undef HAVE_TIGETSTR /* nonfunctional */
431 #define HAVE_TIGETSTR 0
432 #elif defined(HAVE_NCURSESW_TERM_H)
433 #include <ncursesw/term.h>
434 #elif defined(HAVE_NCURSES_TERM_H)
435 #include <ncurses/term.h>
436 #elif defined(HAVE_TERM_H)
441 * Not all curses.h implementations include unctrl.h,
443 #if defined(HAVE_NCURSESW_UNCTRL_H)
444 #include <ncursesw/unctrl.h>
445 #elif defined(HAVE_NCURSES_UNCTRL_H)
446 #include <ncurses/unctrl.h>
447 #elif defined(HAVE_UNCTRL_H)
453 #elif !defined(HAVE_GETOPT_HEADER)
454 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
459 #endif /* HAVE_GETOPT_H */
464 #define setlocale(name,string) /* nothing */
470 #if defined(_MSC_VER)
472 #define popen(s,n) _popen(s,n)
474 #define pclose(s) _pclose(s)
478 #define GCC_NORETURN /* nothing */
480 #ifndef GCC_PRINTFLIKE
481 #define GCC_PRINTFLIKE(a,b) /* nothing */
483 #ifndef GCC_SCANFLIKE
484 #define GCC_SCANFLIKE(a,b) /* nothing */
487 #define GCC_UNUSED /* nothing */
491 #define getnstr(s,n) getstr(s)
494 #if HAVE_INIT_EXTENDED_COLOR
495 #define USE_EXTENDED_COLOR 1
497 #define USE_EXTENDED_COLOR 0
502 #define USE_SOFTKEYS 1
504 #define USE_SOFTKEYS 0
509 #define slk_init() /* nothing */
510 #define slk_restore() /* nothing */
511 #define slk_clear() /* nothing */
514 #ifndef HAVE_CURSES_DATA_TABSIZE
515 #define HAVE_CURSES_DATA_TABSIZE 0
518 #if !NCURSES_EXT_FUNCS
519 #if HAVE_CURSES_DATA_TABSIZE
520 #define set_tabsize(n) TABSIZE = (n)
522 #define set_tabsize(n) /* nothing */
527 #define USE_SP_FUNCS 1
529 #define USE_SP_FUNCS 0
532 #ifndef HAVE_WSYNCDOWN
533 #define wsyncdown(win) /* nothing */
536 #ifndef USE_WIDEC_SUPPORT
537 #if (defined(_XOPEN_SOURCE_EXTENDED) \
538 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
539 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
540 && defined(WACS_ULCORNER)
541 #define USE_WIDEC_SUPPORT 1
543 #define USE_WIDEC_SUPPORT 0
547 #if HAVE_PANEL_H && HAVE_LIBPANEL
548 #define USE_LIBPANEL 1
550 #define USE_LIBPANEL 0
553 #if HAVE_MENU_H && HAVE_LIBMENU
554 #define USE_LIBMENU 1
556 #define USE_LIBMENU 0
559 #if HAVE_FORM_H && HAVE_LIBFORM
560 #define USE_LIBFORM 1
562 #define USE_LIBFORM 0
565 /* workaround, to build against NetBSD's variant of the form library */
566 #ifdef HAVE_NETBSD_FORM_H
567 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos
568 #define form_field_row(field) (field)->form_row
569 #define form_field_col(field) (field)->form_col
570 #else /* e.g., SVr4, ncurses */
571 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
572 #define form_field_row(field) (field)->frow
573 #define form_field_col(field) (field)->fcol
576 /* workaround, to build against NetBSD's variant of the form library */
577 #ifdef HAVE_NETBSD_MENU_H
578 #define menu_itemwidth(menu) (menu)->max_item_width
580 #define menu_itemwidth(menu) (menu)->itemlen
583 #ifndef HAVE_TYPE_ATTR_T
584 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
585 #define attr_t chtype
590 #if !USE_WIDEC_SUPPORT
591 #define NCURSES_CH_T chtype
593 #define NCURSES_CH_T cchar_t
596 #ifndef NCURSES_COLOR_T
597 #define NCURSES_COLOR_T short
600 #ifndef NCURSES_PAIRS_T
601 #define NCURSES_PAIRS_T short
608 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
609 #define CURSES_WACS_SYMBOLS
612 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
613 /* NetBSD 5.1 defines these incorrectly */
647 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
648 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
649 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
650 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
651 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
652 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
653 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
654 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
655 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
656 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
657 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
658 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
659 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
660 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
661 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
662 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
663 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
664 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
665 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
666 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
667 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
668 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
669 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
670 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
671 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
672 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
673 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
674 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
675 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
676 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
677 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
678 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
682 #define WA_NORMAL A_NORMAL
685 #define WA_BOLD A_BOLD
688 #define WA_REVERSE A_REVERSE
691 #define WA_UNDERLINE A_UNDERLINE
694 #define WA_BLINK A_BLINK
706 #define CTRL(x) ((x) & 0x1f)
708 #define QUIT CTRL('Q')
709 #define ESCAPE CTRL('[')
712 #define KEY_MIN 256 /* not defined in Solaris 8 */
715 #define HELP_KEY_1 '?'
716 #define HELP_KEY_2 KEY_F(1)
718 /* from nc_string.h, to make this stand alone */
719 #if HAVE_BSD_STRING_H
720 #include <bsd/string.h>
724 #define NCURSES_VOID /* nothing */
726 #define NCURSES_VOID (void)
730 #define HAVE_STRLCAT 0
734 #define HAVE_STRLCPY 0
737 #ifndef HAVE_SNPRINTF
738 #define HAVE_SNPRINTF 0
742 #define HAVE_STRDUP 0
745 #ifndef USE_STRING_HACKS
746 #define USE_STRING_HACKS 0
750 #define HAVE_STRSTR 0
756 #define NCURSES_CAST(type,value) static_cast<type>(value)
758 #define NCURSES_CAST(type,value) (type)(value)
762 #if USE_STRING_HACKS && HAVE_STRLCAT
763 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
764 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
766 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
767 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
770 #if USE_STRING_HACKS && HAVE_STRLCPY
771 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
772 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
774 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
775 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
778 #if USE_STRING_HACKS && HAVE_SNPRINTF
779 #define _nc_SPRINTF NCURSES_VOID (snprintf)
780 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
782 #define _nc_SPRINTF NCURSES_VOID (sprintf)
783 #define _nc_SLIMIT(n) /* nothing */
787 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
788 * curses did, and some implementations provide them anyway, but undeclared.
790 #ifdef DECL_CURSES_DATA_BOOLNAMES
791 extern char *boolnames[], *boolcodes[], *boolfnames[];
792 extern char *numnames[], *numcodes[], *numfnames[];
793 extern char *strnames[], *strcodes[], *strfnames[];
797 * Again, an SVr4 curses feature latent in the libraries but not in headers.
799 #ifndef DECL_CURSES_DATA_TABSIZE
800 #define DECL_CURSES_DATA_TABSIZE 0
803 #if DECL_CURSES_DATA_TABSIZE
805 #undef HAVE_CURSES_DATA_TABSIZE
806 #define HAVE_CURSES_DATA_TABSIZE 1
809 #ifndef HAVE_CURSES_DATA_TABSIZE
810 #define HAVE_CURSES_DATA_TABSIZE 0
814 * X/Open Curses provides termname(), whose return value is analogous to the
815 * SVr4 curses variable ttytype[].
817 #ifndef HAVE_CURSES_DATA_TTYTYPE
818 #define HAVE_CURSES_DATA_TTYTYPE 0
821 #ifndef DECL_CURSES_DATA_TTYTYPE
822 #define DECL_CURSES_DATA_TTYTYPE 0
825 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
826 #define ttytype termname()
829 #define colored_chtype(ch, attr, pair) \
830 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
833 * Workaround for HPUX
835 #if defined(__hpux) && !defined(NCURSES_VERSION)
836 #define getbegx(w) __getbegx(w)
837 #define getbegy(w) __getbegy(w)
838 #define getcurx(w) __getcurx(w)
839 #define getcury(w) __getcury(w)
840 #define getmaxx(w) __getmaxx(w)
841 #define getmaxy(w) __getmaxy(w)
842 #define getparx(w) __getparx(w)
843 #define getpary(w) __getpary(w)
847 * Workaround in case getcchar() returns a positive value when the source
848 * string produces only a L'\0'.
850 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
851 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
852 wchar_t test_wch[CCHARW_MAX + 2]; \
854 NCURSES_PAIRS_T test_pair; \
856 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
857 && test_wch[0] != L'\0') { \
866 * These usually are implemented as macros, but may be functions.
868 #if !defined(getcurx) && !HAVE_GETCURX
869 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
870 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
873 #if !defined(getbegx) && !HAVE_GETBEGX
874 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
875 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
878 #if !defined(getmaxx) && !HAVE_GETMAXX
879 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
880 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
885 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
886 : (w)->_begx - (w)->_parent->_begx)
888 #if !defined(getparx) && !HAVE_GETPARX
890 #define getparx(win) __m_getparx(win)
891 #define getpary(win) __m_getpary(win)
893 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
894 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
898 #if !defined(mvwvline) && !HAVE_MVWVLINE
899 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
900 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
903 #if !defined(mvvline) && !HAVE_MVVLINE
904 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
905 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
909 * Try to accommodate curses implementations that have no terminfo support.
912 #define TIGETNUM(ti,tc) tigetnum(ti)
914 #define TIGETNUM(ti,tc) tgetnum(tc)
918 #define TIGETSTR(ti,tc) tigetstr(ti)
920 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
924 * So far (2013 - more than ten years), only ncurses implements
925 * use_extended_names().
927 #if defined(NCURSES_XNAMES)
928 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
929 #define NCURSES_XNAMES 1
931 #define NCURSES_XNAMES 0
935 * ncurses restores the cursor in endwin(). Other libraries may not.
937 #ifdef NCURSES_VERSION
938 #define stop_curses() endwin()
940 #define stop_curses() do { endwin(); curs_set(1); } while (0)
943 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
944 * (which is incompatible with legacy usage, doesn't solve any problems).
946 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
947 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
949 #define UChar(c) ((unsigned char)(c))
951 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
953 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
954 #include <nc_alloc.h>
955 #if HAVE_EXIT_TERMINFO && !defined(USE_CURSES) && (defined(USE_TERMINFO) || defined(USE_TINFO))
957 #define ExitProgram(code) exit_terminfo(code)
958 #elif HAVE_EXIT_CURSES
960 #define ExitProgram(code) exit_curses(code)
962 #else /* not ncurses-tree */
963 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
964 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
965 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
969 #define ExitProgram(code) exit(code)
973 #define EXIT_SUCCESS 0
976 #define EXIT_FAILURE 1
980 #if (defined(_WIN32) || defined(_WIN64))
981 #define _NC_WINDOWS 1
984 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
986 #if defined(PDCURSES)
989 # error WINVER must at least be 0x0501
992 # define WINVER 0x0501
995 #include <sys/time.h> /* for struct timeval */
997 #define sleep(n) Sleep((n) * 1000)
1000 #define getlogin() "username"
1002 #elif defined(EXP_WIN32_DRIVER)
1004 #if defined(HAVE_NCURSESW_NCURSES_H)
1005 #include <ncursesw/nc_win32.h>
1006 #elif defined(HAVE_NCURSES_NCURSES_H)
1007 #include <ncurses/nc_win32.h>
1009 #include <nc_win32.h>
1014 #if defined(HAVE_NCURSESW_NCURSES_H)
1015 #include <ncursesw/nc_mingw.h>
1016 #elif defined(HAVE_NCURSES_NCURSES_H)
1017 #include <ncurses/nc_mingw.h>
1019 #include <nc_mingw.h>
1024 /* conflicts in test/firstlast.c */
1031 #if TIME_WITH_SYS_TIME
1032 # include <sys/time.h>
1035 # if HAVE_SYS_TIME_H
1036 # include <sys/time.h>
1046 #ifndef STDOUT_FILENO
1047 #define STDOUT_FILENO 1
1051 extern char *_nc_strstr(const char *, const char *);
1052 #define strstr(a,b) _nc_strstr((a),(b))
1053 #endif /* !HAVE_STRSTR */
1055 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
1056 * curses which doesn't have const parameters declared (so far) in the places
1059 #ifndef NCURSES_CONST
1061 #define NCURSES_CONST const /* close enough */
1063 #define NCURSES_CONST /* nothing */
1067 /* out-of-band values for representing absent capabilities */
1068 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
1069 #define ABSENT_NUMERIC (-1)
1070 #define ABSENT_STRING (char *)0
1072 /* out-of-band values for representing cancels */
1073 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
1074 #define CANCELLED_NUMERIC (-2)
1075 #define CANCELLED_STRING (char *)(-1)
1077 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
1078 #define VALID_NUMERIC(s) ((s) >= 0)
1079 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1081 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1083 #define CATCHALL(handler) do { \
1085 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1086 if (nsig != SIGKILL) \
1087 signal(nsig, handler); \
1090 #ifdef NCURSES_VERSION
1091 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1093 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1096 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1097 #define SetupAlarm(opt) (void)opt
1099 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
1103 * Workaround for clean(er) compile with Solaris's legacy curses.
1104 * The same would be needed for HPUX 10.20
1107 #define TPUTS_ARG int
1110 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1112 #define TPUTS_ARG char
1113 extern char *tgoto(char *, int, int); /* available, but not prototyped */
1117 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1120 #ifndef TPUTS_RETURN
1121 #define TPUTS_RETURN(value) return value
1125 * Workarounds for Solaris's X/Open curses
1127 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1128 #define KEY_MIN __KEY_MIN
1130 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1131 #define KEY_MAX __KEY_MAX
1135 * Workaround to build with Sun's default SVr4 curses.
1137 #ifdef NCURSES_VERSION
1138 #ifndef HAVE_VW_PRINTW
1139 #define HAVE_VW_PRINTW 1
1144 * ncurses provides arrays of capability names; X/Open discarded these SVr4
1145 * features. Some implementations continue to provide them (see the test
1146 * configure script).
1148 #ifdef NCURSES_VERSION
1149 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1150 #define HAVE_CURSES_DATA_BOOLNAMES 1
1155 * ncurses provides a termcap interface; a few packagers replace or displace
1156 * its header file with an incompatible one. The demo_termcap program uses
1157 * the ncurses file, if available.
1159 #ifdef NCURSES_VERSION
1160 #ifndef HAVE_NCURSES_TERMCAP_H
1161 #define HAVE_NCURSES_TERMCAP_H 0
1163 #ifndef HAVE_TERMCAP_H
1164 #define HAVE_TERMCAP_H 0
1169 * ncurses uses const in some places where X/Open does (or did) not allow.
1171 #if defined(NCURSES_CONST)
1172 #define CONST_MENUS NCURSES_CONST
1173 #elif defined(PDCURSES)
1174 #define CONST_MENUS const
1176 #define CONST_MENUS /* nothing */
1179 #if defined(NCURSES_CONST)
1180 #define CONST_FMT NCURSES_CONST
1181 #elif defined(PDCURSES)
1182 #define CONST_FMT const
1184 #define CONST_FMT /* nothing */
1188 * Simplify setting up demo of threading with these macros.
1192 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1193 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1194 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1195 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1197 #define USING_WINDOW(w,func) func(w, NULL)
1198 #define USING_WINDOW1(w,func,safe) func(w)
1199 #define USING_WINDOW2(w,func,data) func(w,data)
1200 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1204 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1205 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1207 #define USING_SCREEN(s,func,data) func(data)
1208 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1211 #if defined(TRACE) && HAVE__TRACEF
1212 #define Trace(p) _tracef p
1214 #define START_TRACE() \
1215 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1216 int t = _nc_getenv_num("NCURSES_TRACE"); \
1218 curses_trace((unsigned) t); \
1220 extern unsigned _nc_tracing;
1221 extern int _nc_getenv_num(const char *);
1224 #define Trace(p) /* nothing */
1226 #define START_TRACE() /* nothing */
1229 #define Trace2(p) /* nothing */
1231 #define AddCh(c) (void) addch((chtype)(c))
1232 #define WAddCh(w,c) (void) waddch((w),(chtype)(c))
1233 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c))
1234 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c))
1235 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s))
1236 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s))
1237 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s))
1238 #define MvPrintw (void) mvprintw
1239 #define MvWPrintw (void) mvwprintw
1240 #define MvHLine (void) mvhline
1241 #define MvWHLine (void) mvwhline
1242 #define MvVLine (void) mvvline
1243 #define MvWVLine (void) mvwvline
1246 * The macro likely uses unsigned values, while X/Open prototype uses int.
1248 #if defined(wattrset) || defined(PDCURSES)
1249 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a))
1251 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a))
1255 * Workaround for defective implementation of gcc attribute warn_unused_result
1257 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1258 #define IGNORE_RC(func) errno = func
1260 #define IGNORE_RC(func) (void) func
1261 #endif /* gcc workarounds */
1263 #define init_mb(state) memset(&state, 0, sizeof(state))
1265 #endif /* __TEST_PRIV_H */