1 /****************************************************************************
2 * Copyright 2018-2022,2023 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.210 2023/02/25 21:26:04 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_CLOCK_GETTIME
79 #define HAVE_CLOCK_GETTIME 0
82 #ifndef HAVE_COLOR_CONTENT
83 #define HAVE_COLOR_CONTENT 0
87 #define HAVE_COPYWIN 0
90 #ifndef HAVE_COLOR_SET
91 #define HAVE_COLOR_SET 0
94 #ifndef HAVE_BSD_STRING_H
95 #define HAVE_BSD_STRING_H 0
98 #ifndef HAVE_CURSES_VERSION
99 #define HAVE_CURSES_VERSION 0
103 #define HAVE_CURSCR 0
106 #ifndef HAVE_DELSCREEN
107 #define HAVE_DELSCREEN 0
111 #define HAVE_DUPWIN 0
115 #define HAVE_FILTER 0
119 #define HAVE_FORM_H 0
123 #define HAVE_GETBEGX 0
127 #define HAVE_GETCURX 0
131 #define HAVE_GETMAXX 0
134 #ifndef HAVE_GETTIMEOFDAY
135 #define HAVE_GETTIMEOFDAY 0
138 #ifndef HAVE_GETOPT_H
139 #define HAVE_GETOPT_H 0
143 #define HAVE_GETPARX 0
147 #define HAVE_GETWIN 0
150 #ifndef HAVE_HALFDELAY
151 #define HAVE_HALFDELAY 0
154 #ifndef HAVE_INIT_EXTENDED_COLOR
155 #define HAVE_INIT_EXTENDED_COLOR 0
159 #define HAVE_LIBFORM 0
163 #define HAVE_LIBMENU 0
166 #ifndef HAVE_LIBPANEL
167 #define HAVE_LIBPANEL 0
170 #ifndef HAVE_LANGINFO_CODESET
171 #define HAVE_LANGINFO_CODESET 0
174 #ifndef HAVE_LOCALE_H
175 #define HAVE_LOCALE_H 0
178 #ifndef HAVE_MATH_FUNCS
179 #define HAVE_MATH_FUNCS 0
183 #define HAVE_MATH_H 0
187 #define HAVE_MENU_H 0
190 #ifndef HAVE_MVDERWIN
191 #define HAVE_MVDERWIN 0
195 #define HAVE_MVVLINE 0
202 #ifndef HAVE_MVWVLINE
203 #define HAVE_MVWVLINE 0
210 #ifndef HAVE_NC_ALLOC_H
211 #define HAVE_NC_ALLOC_H 0
215 #define HAVE_NEWPAD 0
219 #define HAVE_PANEL_H 0
223 #define HAVE_PUTWIN 0
226 #ifndef HAVE_RESET_COLOR_PAIRS
227 #define HAVE_RESET_COLOR_PAIRS 0
230 #ifndef HAVE_RESIZE_TERM
231 #define HAVE_RESIZE_TERM 0
234 #ifndef HAVE_RESTARTTERM
235 #define HAVE_RESTARTTERM 0
238 #ifndef HAVE_RIPOFFLINE
239 #define HAVE_RIPOFFLINE 0
242 #ifndef HAVE_SCR_DUMP
243 #define HAVE_SCR_DUMP 0
246 #ifndef HAVE_SETUPTERM
247 #define HAVE_SETUPTERM 0
250 #ifndef HAVE_SLK_COLOR
251 #define HAVE_SLK_COLOR 0
254 #ifndef HAVE_SLK_INIT
255 #define HAVE_SLK_INIT 0
258 #ifndef HAVE_STDINT_H
259 #define HAVE_STDINT_H 0
262 #ifndef HAVE_STDNORETURN_H
263 #define HAVE_STDNORETURN_H 0
267 #define HAVE_STRSTR 0
270 #ifndef HAVE_SYS_IOCTL_H
271 #define HAVE_SYS_IOCTL_H 0
274 #ifndef HAVE_SYS_SELECT_H
275 #define HAVE_SYS_SELECT_H 0
278 #ifndef HAVE_TERMATTRS
279 #define HAVE_TERMATTRS 0
282 #ifndef HAVE_TERMIOS_H
283 #define HAVE_TERMIOS_H 0
286 #ifndef HAVE_TERMNAME
287 #define HAVE_TERMNAME 0
290 #ifndef HAVE_TERM_ENTRY_H
291 #define HAVE_TERM_ENTRY_H 0
295 #define HAVE_TGETENT 0
298 #ifndef HAVE_TIGETNUM
299 #define HAVE_TIGETNUM 0
302 #ifndef HAVE_TIGETSTR
303 #define HAVE_TIGETSTR 0
306 #ifndef HAVE_TPUTS_SP
307 #define HAVE_TPUTS_SP 0
311 #define HAVE_TSEARCH 0
314 #ifndef HAVE_TYPEAHEAD
315 #define HAVE_TYPEAHEAD 0
319 #define HAVE_WINSSTR 0
322 #ifndef HAVE_UNGET_WCH
323 #define HAVE_UNGET_WCH 0
326 #ifndef HAVE_USE_DEFAULT_COLORS
327 #define HAVE_USE_DEFAULT_COLORS 0
331 #define HAVE_USE_ENV 0
334 #ifndef HAVE_USE_EXTENDED_NAMES
335 #define HAVE_USE_EXTENDED_NAMES 0
338 #ifndef HAVE_USE_SCREEN
339 #define HAVE_USE_SCREEN 0
342 #ifndef HAVE_USE_WINDOW
343 #define HAVE_USE_WINDOW 0
347 #define HAVE_VIDPUTS 0
350 #ifndef HAVE_VID_PUTS
351 #define HAVE_VID_PUTS 0
354 #ifndef HAVE_WINSDELLN
355 #define HAVE_WINSDELLN 0
359 #define HAVE_WRESIZE 0
363 #define HAVE__TRACEF 0
366 #ifndef NCURSES_EXT_FUNCS
367 #define NCURSES_EXT_FUNCS 0
371 #define NEED_PTEM_H 0
375 #define NEED_WCHAR_H 0
383 * Workaround for HPUX
385 #if defined(__hpux) && !defined(NCURSES_VERSION)
386 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
392 #include <sys/types.h>
399 #include <signal.h> /* include before curses.h to work around glibc bug */
403 #ifdef HAVE_LIBUTF8_H
408 #if defined(HAVE_XCURSES)
410 #elif defined(HAVE_NCURSESW_NCURSES_H)
411 #include <ncursesw/curses.h>
412 #elif defined(HAVE_NCURSES_NCURSES_H)
413 #include <ncurses/curses.h>
418 #if HAVE_STDNORETURN_H && !defined(NCURSES_VERSION)
419 #include <stdnoreturn.h>
421 #define GCC_NORETURN _Noreturn
424 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
425 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */
428 #if defined(HAVE_XCURSES) || defined(PDCURSES)
429 /* no other headers */
430 #undef HAVE_SETUPTERM /* nonfunctional */
431 #define HAVE_SETUPTERM 0
432 #undef HAVE_TGETENT /* nonfunctional */
433 #define HAVE_TGETENT 0
434 #undef HAVE_TIGETSTR /* nonfunctional */
435 #define HAVE_TIGETSTR 0
436 #elif defined(HAVE_NCURSESW_TERM_H)
437 #include <ncursesw/term.h>
438 #elif defined(HAVE_NCURSES_TERM_H)
439 #include <ncurses/term.h>
440 #elif defined(HAVE_TERM_H)
445 * Not all curses.h implementations include unctrl.h,
447 #if defined(HAVE_NCURSESW_UNCTRL_H)
448 #include <ncursesw/unctrl.h>
449 #elif defined(HAVE_NCURSES_UNCTRL_H)
450 #include <ncurses/unctrl.h>
451 #elif defined(HAVE_UNCTRL_H)
457 #elif !defined(HAVE_GETOPT_HEADER)
458 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
463 #endif /* HAVE_GETOPT_H */
468 #define setlocale(name,string) /* nothing */
474 #if defined(_MSC_VER)
476 #define popen(s,n) _popen(s,n)
478 #define pclose(s) _pclose(s)
482 #define GCC_NORETURN /* nothing */
484 #ifndef GCC_PRINTFLIKE
485 #define GCC_PRINTFLIKE(a,b) /* nothing */
487 #ifndef GCC_SCANFLIKE
488 #define GCC_SCANFLIKE(a,b) /* nothing */
491 #define GCC_UNUSED /* nothing */
495 #define getnstr(s,n) getstr(s)
498 #if HAVE_INIT_EXTENDED_COLOR
499 #define USE_EXTENDED_COLOR 1
501 #define USE_EXTENDED_COLOR 0
506 #define USE_SOFTKEYS 1
508 #define USE_SOFTKEYS 0
513 #define slk_init() /* nothing */
514 #define slk_restore() /* nothing */
515 #define slk_clear() /* nothing */
518 #ifndef HAVE_CURSES_DATA_TABSIZE
519 #define HAVE_CURSES_DATA_TABSIZE 0
522 #if !NCURSES_EXT_FUNCS
523 #if HAVE_CURSES_DATA_TABSIZE
524 #define set_tabsize(n) TABSIZE = (n)
526 #define set_tabsize(n) /* nothing */
531 #define USE_SP_FUNCS 1
533 #define USE_SP_FUNCS 0
536 #ifndef HAVE_WSYNCDOWN
537 #define wsyncdown(win) /* nothing */
540 #ifndef USE_WIDEC_SUPPORT
541 #if (defined(_XOPEN_SOURCE_EXTENDED) \
542 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
543 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
544 && defined(WACS_ULCORNER)
545 #define USE_WIDEC_SUPPORT 1
547 #define USE_WIDEC_SUPPORT 0
551 #if HAVE_PANEL_H && HAVE_LIBPANEL
552 #define USE_LIBPANEL 1
554 #define USE_LIBPANEL 0
557 #if HAVE_MENU_H && HAVE_LIBMENU
558 #define USE_LIBMENU 1
560 #define USE_LIBMENU 0
563 #if HAVE_FORM_H && HAVE_LIBFORM
564 #define USE_LIBFORM 1
566 #define USE_LIBFORM 0
569 /* workaround, to build against NetBSD's variant of the form library */
570 #ifdef HAVE_NETBSD_FORM_H
571 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos
572 #define form_field_row(field) (field)->form_row
573 #define form_field_col(field) (field)->form_col
574 #else /* e.g., SVr4, ncurses */
575 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
576 #define form_field_row(field) (field)->frow
577 #define form_field_col(field) (field)->fcol
580 /* workaround, to build against NetBSD's variant of the form library */
581 #ifdef HAVE_NETBSD_MENU_H
582 #define menu_itemwidth(menu) (menu)->max_item_width
584 #define menu_itemwidth(menu) (menu)->itemlen
587 #ifndef HAVE_TYPE_ATTR_T
588 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
589 #define attr_t chtype
594 #if !USE_WIDEC_SUPPORT
595 #define NCURSES_CH_T chtype
597 #define NCURSES_CH_T cchar_t
600 #ifndef NCURSES_COLOR_T
601 #define NCURSES_COLOR_T short
604 #ifndef NCURSES_PAIRS_T
605 #define NCURSES_PAIRS_T short
612 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
613 #define CURSES_WACS_SYMBOLS
616 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
617 /* NetBSD 5.1 defines these incorrectly */
651 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
652 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
653 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
654 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
655 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
656 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
657 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
658 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
659 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
660 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
661 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
662 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
663 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
664 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
665 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
666 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
667 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
668 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
669 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
670 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
671 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
672 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
673 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
674 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
675 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
676 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
677 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
678 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
679 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
680 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
681 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
682 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
686 #define WA_NORMAL A_NORMAL
689 #define WA_BOLD A_BOLD
692 #define WA_REVERSE A_REVERSE
695 #define WA_UNDERLINE A_UNDERLINE
698 #define WA_BLINK A_BLINK
710 #define CTRL(x) ((x) & 0x1f)
712 #define QUIT CTRL('Q')
713 #define ESCAPE CTRL('[')
716 #define KEY_MIN 256 /* not defined in Solaris 8 */
719 #define HELP_KEY_1 '?'
720 #define HELP_KEY_2 KEY_F(1)
722 /* our "standard" options for getopt, needed for help2man */
723 #define OPTS_USAGE 'h'
724 #define OPTS_VERSION 'V'
725 #define OPTS_COMMON "hV"
726 #define USAGE_COMMON \
728 ," -h show this message"\
729 ," -V show version of curses"
731 #if HAVE_CURSES_VERSION
732 #define format_version(buffer) strcpy(buffer, curses_version())
733 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
734 #define format_version(buffer) sprintf(buffer, "ncurses %d.%d.%d", \
735 NCURSES_VERSION_MAJOR, \
736 NCURSES_VERSION_MINOR, \
737 NCURSES_VERSION_PATCH)
739 #define format_version(buffer) strcpy(buffer, "ncurses-examples")
742 #define VERSION_COMMON() \
743 static char *version_common(char **argv) { \
744 char *base = argv[0]; \
745 char *leaf = strrchr(base, '/'); \
746 char *result = malloc(strlen(base) + 80); \
747 if (result == NULL) { \
748 static char unknown[] = "?"; \
751 if (leaf++ == NULL) leaf = base; \
752 sprintf(result, "%.20s: ", leaf); \
753 format_version(result + strlen(result)); \
757 static void show_version(char **argv) { \
758 char *value = version_common(argv); \
759 if (value != NULL) { \
765 /* from nc_string.h, to make this stand alone */
766 #if HAVE_BSD_STRING_H
767 #include <bsd/string.h>
771 #define NCURSES_VOID /* nothing */
773 #define NCURSES_VOID (void)
777 #define HAVE_STRLCAT 0
781 #define HAVE_STRLCPY 0
784 #ifndef HAVE_SNPRINTF
785 #define HAVE_SNPRINTF 0
789 #define HAVE_STRDUP 0
792 #ifndef USE_STRING_HACKS
793 #define USE_STRING_HACKS 0
797 #define HAVE_STRSTR 0
803 #define NCURSES_CAST(type,value) static_cast<type>(value)
805 #define NCURSES_CAST(type,value) (type)(value)
809 #if USE_STRING_HACKS && HAVE_STRLCAT
810 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
811 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
813 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
814 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
817 #if USE_STRING_HACKS && HAVE_STRLCPY
818 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
819 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
821 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
822 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
825 #if USE_STRING_HACKS && HAVE_SNPRINTF
826 #define _nc_SPRINTF NCURSES_VOID (snprintf)
827 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
829 #define _nc_SPRINTF NCURSES_VOID (sprintf)
830 #define _nc_SLIMIT(n) /* nothing */
834 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
835 * curses did, and some implementations provide them anyway, but undeclared.
837 #ifdef DECL_CURSES_DATA_BOOLNAMES
838 extern char *boolnames[], *boolcodes[], *boolfnames[];
839 extern char *numnames[], *numcodes[], *numfnames[];
840 extern char *strnames[], *strcodes[], *strfnames[];
844 * Again, an SVr4 curses feature latent in the libraries but not in headers.
846 #ifndef DECL_CURSES_DATA_TABSIZE
847 #define DECL_CURSES_DATA_TABSIZE 0
850 #if DECL_CURSES_DATA_TABSIZE
852 #undef HAVE_CURSES_DATA_TABSIZE
853 #define HAVE_CURSES_DATA_TABSIZE 1
856 #ifndef HAVE_CURSES_DATA_TABSIZE
857 #define HAVE_CURSES_DATA_TABSIZE 0
861 * X/Open Curses provides termname(), whose return value is analogous to the
862 * SVr4 curses variable ttytype[].
864 #ifndef HAVE_CURSES_DATA_TTYTYPE
865 #define HAVE_CURSES_DATA_TTYTYPE 0
868 #ifndef DECL_CURSES_DATA_TTYTYPE
869 #define DECL_CURSES_DATA_TTYTYPE 0
872 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
873 #define ttytype termname()
876 #define colored_chtype(ch, attr, pair) \
877 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
880 * Workaround for HPUX
882 #if defined(__hpux) && !defined(NCURSES_VERSION)
883 #define getbegx(w) __getbegx(w)
884 #define getbegy(w) __getbegy(w)
885 #define getcurx(w) __getcurx(w)
886 #define getcury(w) __getcury(w)
887 #define getmaxx(w) __getmaxx(w)
888 #define getmaxy(w) __getmaxy(w)
889 #define getparx(w) __getparx(w)
890 #define getpary(w) __getpary(w)
894 * Workaround in case getcchar() returns a positive value when the source
895 * string produces only a L'\0'.
897 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
898 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
899 wchar_t test_wch[CCHARW_MAX + 2]; \
901 NCURSES_PAIRS_T test_pair; \
903 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
904 && test_wch[0] != L'\0') { \
913 * These usually are implemented as macros, but may be functions.
915 #if !defined(getcurx) && !HAVE_GETCURX
916 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
917 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
920 #if !defined(getbegx) && !HAVE_GETBEGX
921 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
922 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
925 #if !defined(getmaxx) && !HAVE_GETMAXX
926 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
927 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
932 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
933 : (w)->_begx - (w)->_parent->_begx)
935 #if !defined(getparx) && !HAVE_GETPARX
937 #define getparx(win) __m_getparx(win)
938 #define getpary(win) __m_getpary(win)
940 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
941 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
945 #if !defined(mvwvline) && !HAVE_MVWVLINE
946 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
947 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
950 #if !defined(mvvline) && !HAVE_MVVLINE
951 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
952 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
956 * Try to accommodate curses implementations that have no terminfo support.
959 #define TIGETNUM(ti,tc) tigetnum(ti)
961 #define TIGETNUM(ti,tc) tgetnum(tc)
965 #define TIGETSTR(ti,tc) tigetstr(ti)
967 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
971 * So far (2013 - more than ten years), only ncurses implements
972 * use_extended_names().
974 #if defined(NCURSES_XNAMES)
975 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
976 #define NCURSES_XNAMES 1
978 #define NCURSES_XNAMES 0
982 * ncurses restores the cursor in endwin(). Other libraries may not.
984 #ifdef NCURSES_VERSION
985 #define stop_curses() endwin()
987 #define stop_curses() do { endwin(); curs_set(1); } while (0)
990 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
991 * (which is incompatible with legacy usage, doesn't solve any problems).
993 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
994 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
996 #define UChar(c) ((unsigned char)(c))
998 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
1000 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
1001 #include <nc_alloc.h>
1002 #if HAVE_EXIT_TERMINFO && !defined(USE_CURSES) && (defined(USE_TERMINFO) || defined(USE_TINFO))
1004 #define ExitProgram(code) exit_terminfo(code)
1005 #elif HAVE_EXIT_CURSES
1007 #define ExitProgram(code) exit_curses(code)
1009 #else /* not ncurses-tree */
1010 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
1011 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
1012 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
1016 #define ExitProgram(code) exit(code)
1019 #ifndef EXIT_SUCCESS
1020 #define EXIT_SUCCESS 0
1022 #ifndef EXIT_FAILURE
1023 #define EXIT_FAILURE 1
1027 #if (defined(_WIN32) || defined(_WIN64))
1028 #define _NC_WINDOWS 1
1031 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1033 #if defined(PDCURSES)
1035 # if WINVER < 0x0501
1036 # error WINVER must at least be 0x0501
1039 # define WINVER 0x0501
1041 #include <windows.h>
1042 #include <sys/time.h> /* for struct timeval */
1044 #define sleep(n) Sleep((n) * 1000)
1047 #define getlogin() "username"
1049 #elif defined(EXP_WIN32_DRIVER)
1051 #if defined(HAVE_NCURSESW_NCURSES_H)
1052 #include <ncursesw/nc_win32.h>
1053 #elif defined(HAVE_NCURSES_NCURSES_H)
1054 #include <ncurses/nc_win32.h>
1056 #include <nc_win32.h>
1061 #if defined(HAVE_NCURSESW_NCURSES_H)
1062 #include <ncursesw/nc_mingw.h>
1063 #elif defined(HAVE_NCURSES_NCURSES_H)
1064 #include <ncurses/nc_mingw.h>
1066 #include <nc_mingw.h>
1071 /* conflicts in test/firstlast.c */
1078 #if TIME_WITH_SYS_TIME
1079 # include <sys/time.h>
1082 # if HAVE_SYS_TIME_H
1083 # include <sys/time.h>
1090 #if HAVE_CLOCK_GETTIME
1091 # define GetClockTime(t) clock_gettime(CLOCK_REALTIME, t)
1092 # define TimeType struct timespec
1093 # define TimeScale 1000000000L /* 1e9 */
1094 # define ElapsedSeconds(b,e) \
1095 (double) (((e)->tv_sec - (b)->tv_sec) \
1096 + ((e)->tv_nsec - (b)->tv_nsec) / TimeScale)
1097 #elif HAVE_GETTIMEOFDAY
1098 # define GetClockTime(t) gettimeofday(t, 0)
1099 # define TimeType struct timeval
1100 # define TimeScale 1000000L /* 1e6 */
1101 # define ElapsedSeconds(b,e) \
1102 (double) (((e)->tv_sec - (b)->tv_sec) \
1103 + ((e)->tv_usec - (b)->tv_usec) / TimeScale)
1105 # define TimeType time_t
1106 # define GetClockTime(t) time((time_t*)0)
1107 # define ElapsedSeconds(b,e) (double)((e) - (b))
1113 #ifndef STDOUT_FILENO
1114 #define STDOUT_FILENO 1
1118 extern char *_nc_strstr(const char *, const char *);
1119 #define strstr(a,b) _nc_strstr((a),(b))
1120 #endif /* !HAVE_STRSTR */
1122 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
1123 * curses which doesn't have const parameters declared (so far) in the places
1126 #ifndef NCURSES_CONST
1128 #define NCURSES_CONST const /* close enough */
1130 #define NCURSES_CONST /* nothing */
1134 /* out-of-band values for representing absent capabilities */
1135 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
1136 #define ABSENT_NUMERIC (-1)
1137 #define ABSENT_STRING (char *)0
1139 /* out-of-band values for representing cancels */
1140 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
1141 #define CANCELLED_NUMERIC (-2)
1142 #define CANCELLED_STRING (char *)(-1)
1144 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
1145 #define VALID_NUMERIC(s) ((s) >= 0)
1146 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1148 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1150 #define CATCHALL(handler) do { \
1152 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1153 if (nsig != SIGKILL) \
1154 signal(nsig, handler); \
1157 #ifdef NCURSES_VERSION
1158 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1160 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1163 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1164 #define SetupAlarm(opt) (void)opt
1166 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
1170 * Workaround for clean(er) compile with Solaris's legacy curses.
1171 * The same would be needed for HPUX 10.20
1174 #define TPUTS_ARG int
1177 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1179 #define TPUTS_ARG char
1180 extern char *tgoto(char *, int, int); /* available, but not prototyped */
1184 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1187 #ifndef TPUTS_RETURN
1188 #define TPUTS_RETURN(value) return value
1192 * Workarounds for Solaris's X/Open curses
1194 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1195 #define KEY_MIN __KEY_MIN
1197 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1198 #define KEY_MAX __KEY_MAX
1202 * Workaround to build with Sun's default SVr4 curses.
1204 #ifdef NCURSES_VERSION
1205 #ifndef HAVE_VW_PRINTW
1206 #define HAVE_VW_PRINTW 1
1211 * ncurses provides arrays of capability names; X/Open discarded these SVr4
1212 * features. Some implementations continue to provide them (see the test
1213 * configure script).
1215 #ifdef NCURSES_VERSION
1216 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1217 #define HAVE_CURSES_DATA_BOOLNAMES 1
1222 * ncurses provides a termcap interface; a few packagers replace or displace
1223 * its header file with an incompatible one. The demo_termcap program uses
1224 * the ncurses file, if available.
1226 #ifdef NCURSES_VERSION
1227 #ifndef HAVE_NCURSES_TERMCAP_H
1228 #define HAVE_NCURSES_TERMCAP_H 0
1230 #ifndef HAVE_TERMCAP_H
1231 #define HAVE_TERMCAP_H 0
1236 * ncurses uses const in some places where X/Open does (or did) not allow.
1238 #if defined(NCURSES_CONST)
1239 #define CONST_MENUS NCURSES_CONST
1240 #elif defined(PDCURSES)
1241 #define CONST_MENUS const
1243 #define CONST_MENUS /* nothing */
1246 #if defined(NCURSES_CONST)
1247 #define CONST_FMT NCURSES_CONST
1248 #elif defined(PDCURSES)
1249 #define CONST_FMT const
1251 #define CONST_FMT /* nothing */
1255 * Simplify setting up demo of threading with these macros.
1259 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1260 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1261 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1262 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1264 #define USING_WINDOW(w,func) func(w, NULL)
1265 #define USING_WINDOW1(w,func,safe) func(w)
1266 #define USING_WINDOW2(w,func,data) func(w,data)
1267 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1271 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1272 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1274 #define USING_SCREEN(s,func,data) func(data)
1275 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1278 #if defined(TRACE) && HAVE__TRACEF && HAVE_CURSES_TRACE
1279 #define Trace(p) _tracef p
1281 #define START_TRACE() \
1282 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1283 int t = _nc_getenv_num("NCURSES_TRACE"); \
1285 curses_trace((unsigned) t); \
1287 extern unsigned _nc_tracing;
1288 extern int _nc_getenv_num(const char *);
1291 #define Trace(p) /* nothing */
1293 #define START_TRACE() /* nothing */
1296 #define Trace2(p) /* nothing */
1298 #define AddCh(c) (void) addch((chtype)(c))
1299 #define WAddCh(w,c) (void) waddch((w),(chtype)(c))
1300 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c))
1301 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c))
1302 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s))
1303 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s))
1304 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s))
1305 #define MvPrintw (void) mvprintw
1306 #define MvWPrintw (void) mvwprintw
1307 #define MvHLine (void) mvhline
1308 #define MvWHLine (void) mvwhline
1309 #define MvVLine (void) mvvline
1310 #define MvWVLine (void) mvwvline
1313 * The macro likely uses unsigned values, while X/Open prototype uses int.
1315 #if defined(wattrset) || defined(PDCURSES)
1316 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a))
1318 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a))
1322 * Workaround for defective implementation of gcc attribute warn_unused_result
1324 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1325 #define IGNORE_RC(func) errno = func
1327 #define IGNORE_RC(func) (void) func
1328 #endif /* gcc workarounds */
1330 #define init_mb(state) memset(&state, 0, sizeof(state))
1332 #endif /* __TEST_PRIV_H */