1 /****************************************************************************
2 * Copyright 2018-2019,2020 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.185 2020/02/02 23:34:34 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
247 #define HAVE_STRSTR 0
250 #ifndef HAVE_SYS_IOCTL_H
251 #define HAVE_SYS_IOCTL_H 0
254 #ifndef HAVE_SYS_SELECT_H
255 #define HAVE_SYS_SELECT_H 0
258 #ifndef HAVE_TERMATTRS
259 #define HAVE_TERMATTRS 0
262 #ifndef HAVE_TERMIOS_H
263 #define HAVE_TERMIOS_H 0
266 #ifndef HAVE_TERMNAME
267 #define HAVE_TERMNAME 0
270 #ifndef HAVE_TERM_ENTRY_H
271 #define HAVE_TERM_ENTRY_H 0
275 #define HAVE_TGETENT 0
278 #ifndef HAVE_TIGETNUM
279 #define HAVE_TIGETNUM 0
282 #ifndef HAVE_TIGETSTR
283 #define HAVE_TIGETSTR 0
286 #ifndef HAVE_TPUTS_SP
287 #define HAVE_TPUTS_SP 0
291 #define HAVE_TSEARCH 0
294 #ifndef HAVE_TYPEAHEAD
295 #define HAVE_TYPEAHEAD 0
299 #define HAVE_WINSSTR 0
302 #ifndef HAVE_USE_DEFAULT_COLORS
303 #define HAVE_USE_DEFAULT_COLORS 0
307 #define HAVE_USE_ENV 0
310 #ifndef HAVE_USE_EXTENDED_NAMES
311 #define HAVE_USE_EXTENDED_NAMES 0
314 #ifndef HAVE_USE_SCREEN
315 #define HAVE_USE_SCREEN 0
318 #ifndef HAVE_USE_WINDOW
319 #define HAVE_USE_WINDOW 0
323 #define HAVE_VIDPUTS 0
326 #ifndef HAVE_VID_PUTS
327 #define HAVE_VID_PUTS 0
330 #ifndef HAVE_WINSDELLN
331 #define HAVE_WINSDELLN 0
335 #define HAVE_WRESIZE 0
339 #define HAVE__TRACEF 0
342 #ifndef NCURSES_EXT_FUNCS
343 #define NCURSES_EXT_FUNCS 0
347 #define NEED_PTEM_H 0
351 #define NEED_WCHAR_H 0
359 * Workaround for HPUX
361 #if defined(__hpux) && !defined(NCURSES_VERSION)
362 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
368 #include <sys/types.h>
375 #include <signal.h> /* include before curses.h to work around glibc bug */
379 #ifdef HAVE_LIBUTF8_H
384 #if defined(HAVE_XCURSES)
386 #elif defined(HAVE_NCURSESW_NCURSES_H)
387 #include <ncursesw/curses.h>
388 #elif defined(HAVE_NCURSES_NCURSES_H)
389 #include <ncurses/curses.h>
394 #if defined(HAVE_XCURSES) || defined(PDCURSES)
395 /* no other headers */
396 #undef HAVE_SETUPTERM /* nonfunctional */
397 #define HAVE_SETUPTERM 0
398 #undef HAVE_TGETENT /* nonfunctional */
399 #define HAVE_TGETENT 0
400 #undef HAVE_TIGETSTR /* nonfunctional */
401 #define HAVE_TIGETSTR 0
402 #elif defined(HAVE_NCURSESW_TERM_H)
403 #include <ncursesw/term.h>
404 #elif defined(HAVE_NCURSES_TERM_H)
405 #include <ncurses/term.h>
406 #elif defined(HAVE_TERM_H)
411 * Not all curses.h implementations include unctrl.h,
413 #if defined(HAVE_NCURSESW_UNCTRL_H)
414 #include <ncursesw/unctrl.h>
415 #elif defined(HAVE_NCURSES_UNCTRL_H)
416 #include <ncurses/unctrl.h>
417 #elif defined(HAVE_UNCTRL_H)
423 #elif !defined(HAVE_GETOPT_HEADER)
424 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
429 #endif /* HAVE_GETOPT_H */
434 #define setlocale(name,string) /* nothing */
441 #define GCC_NORETURN /* nothing */
443 #ifndef GCC_PRINTFLIKE
444 #define GCC_PRINTFLIKE(a,b) /* nothing */
446 #ifndef GCC_SCANFLIKE
447 #define GCC_SCANFLIKE(a,b) /* nothing */
450 #define GCC_UNUSED /* nothing */
454 #define getnstr(s,n) getstr(s)
457 #if HAVE_INIT_EXTENDED_COLOR
458 #define USE_EXTENDED_COLOR 1
460 #define USE_EXTENDED_COLOR 0
465 #define USE_SOFTKEYS 1
467 #define USE_SOFTKEYS 0
472 #define slk_init() /* nothing */
473 #define slk_restore() /* nothing */
474 #define slk_clear() /* nothing */
477 #ifndef HAVE_CURSES_DATA_TABSIZE
478 #define HAVE_CURSES_DATA_TABSIZE 0
481 #if !NCURSES_EXT_FUNCS
482 #if HAVE_CURSES_DATA_TABSIZE
483 #define set_tabsize(n) TABSIZE = (n)
485 #define set_tabsize(n) /* nothing */
490 #define USE_SP_FUNCS 1
492 #define USE_SP_FUNCS 0
495 #ifndef HAVE_WSYNCDOWN
496 #define wsyncdown(win) /* nothing */
499 #ifndef USE_WIDEC_SUPPORT
500 #if (defined(_XOPEN_SOURCE_EXTENDED) \
501 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
502 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
503 && defined(WACS_ULCORNER)
504 #define USE_WIDEC_SUPPORT 1
506 #define USE_WIDEC_SUPPORT 0
510 #if HAVE_PANEL_H && HAVE_LIBPANEL
511 #define USE_LIBPANEL 1
513 #define USE_LIBPANEL 0
516 #if HAVE_MENU_H && HAVE_LIBMENU
517 #define USE_LIBMENU 1
519 #define USE_LIBMENU 0
522 #if HAVE_FORM_H && HAVE_LIBFORM
523 #define USE_LIBFORM 1
525 #define USE_LIBFORM 0
528 /* workaround, to build against NetBSD's variant of the form library */
529 #ifdef HAVE_NETBSD_FORM_H
530 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos
532 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
535 /* workaround, to build against NetBSD's variant of the form library */
536 #ifdef HAVE_NETBSD_MENU_H
537 #define menu_itemwidth(menu) (menu)->max_item_width
539 #define menu_itemwidth(menu) (menu)->itemlen
542 #ifndef HAVE_TYPE_ATTR_T
543 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
544 #define attr_t chtype
549 #if !USE_WIDEC_SUPPORT
550 #define NCURSES_CH_T chtype
552 #define NCURSES_CH_T cchar_t
555 #ifndef NCURSES_COLOR_T
556 #define NCURSES_COLOR_T short
559 #ifndef NCURSES_PAIRS_T
560 #define NCURSES_PAIRS_T short
567 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
568 #define CURSES_WACS_SYMBOLS
571 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
572 /* NetBSD 5.1 defines these incorrectly */
606 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
607 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
608 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
609 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
610 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
611 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
612 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
613 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
614 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
615 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
616 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
617 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
618 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
619 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
620 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
621 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
622 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
623 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
624 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
625 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
626 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
627 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
628 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
629 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
630 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
631 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
632 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
633 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
634 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
635 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
636 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
637 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
641 #define WA_NORMAL A_NORMAL
644 #define WA_BOLD A_BOLD
647 #define WA_REVERSE A_REVERSE
650 #define WA_UNDERLINE A_UNDERLINE
653 #define WA_BLINK A_BLINK
665 #define CTRL(x) ((x) & 0x1f)
667 #define QUIT CTRL('Q')
668 #define ESCAPE CTRL('[')
671 #define KEY_MIN 256 /* not defined in Solaris 8 */
674 #define HELP_KEY_1 '?'
675 #define HELP_KEY_2 KEY_F(1)
677 /* from nc_string.h, to make this stand alone */
678 #if HAVE_BSD_STRING_H
679 #include <bsd/string.h>
683 #define NCURSES_VOID /* nothing */
685 #define NCURSES_VOID (void)
689 #define HAVE_STRLCAT 0
693 #define HAVE_STRLCPY 0
696 #ifndef HAVE_SNPRINTF
697 #define HAVE_SNPRINTF 0
700 #ifndef USE_STRING_HACKS
701 #define USE_STRING_HACKS 0
707 #define NCURSES_CAST(type,value) static_cast<type>(value)
709 #define NCURSES_CAST(type,value) (type)(value)
713 #if USE_STRING_HACKS && HAVE_STRLCAT
714 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
715 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
717 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
718 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
721 #if USE_STRING_HACKS && HAVE_STRLCPY
722 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
723 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
725 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
726 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
729 #if USE_STRING_HACKS && HAVE_SNPRINTF
730 #define _nc_SPRINTF NCURSES_VOID snprintf
731 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
733 #define _nc_SPRINTF NCURSES_VOID sprintf
734 #define _nc_SLIMIT(n) /* nothing */
738 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
739 * curses did, and some implementations provide them anyway, but undeclared.
741 #ifdef DECL_CURSES_DATA_BOOLNAMES
742 extern char *boolnames[], *boolcodes[], *boolfnames[];
743 extern char *numnames[], *numcodes[], *numfnames[];
744 extern char *strnames[], *strcodes[], *strfnames[];
748 * Again, an SVr4 curses feature latent in the libraries but not in headers.
750 #ifndef DECL_CURSES_DATA_TABSIZE
751 #define DECL_CURSES_DATA_TABSIZE 0
754 #if DECL_CURSES_DATA_TABSIZE
756 #undef HAVE_CURSES_DATA_TABSIZE
757 #define HAVE_CURSES_DATA_TABSIZE 1
760 #ifndef HAVE_CURSES_DATA_TABSIZE
761 #define HAVE_CURSES_DATA_TABSIZE 0
765 * X/Open Curses provides termname(), whose return value is analogous to the
766 * SVr4 curses variable ttytype[].
768 #ifndef HAVE_CURSES_DATA_TTYTYPE
769 #define HAVE_CURSES_DATA_TTYTYPE 0
772 #ifndef DECL_CURSES_DATA_TTYTYPE
773 #define DECL_CURSES_DATA_TTYTYPE 0
776 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
777 #define ttytype termname()
780 #define colored_chtype(ch, attr, pair) \
781 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
784 * Workaround for HPUX
786 #if defined(__hpux) && !defined(NCURSES_VERSION)
787 #define getbegx(w) __getbegx(w)
788 #define getbegy(w) __getbegy(w)
789 #define getcurx(w) __getcurx(w)
790 #define getcury(w) __getcury(w)
791 #define getmaxx(w) __getmaxx(w)
792 #define getmaxy(w) __getmaxy(w)
793 #define getparx(w) __getparx(w)
794 #define getpary(w) __getpary(w)
798 * Workaround in case getcchar() returns a positive value when the source
799 * string produces only a L'\0'.
801 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
802 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
803 wchar_t test_wch[CCHARW_MAX + 2]; \
805 NCURSES_PAIRS_T test_pair; \
807 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
808 && test_wch[0] != L'\0') { \
817 * These usually are implemented as macros, but may be functions.
819 #if !defined(getcurx) && !HAVE_GETCURX
820 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
821 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
824 #if !defined(getbegx) && !HAVE_GETBEGX
825 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
826 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
829 #if !defined(getmaxx) && !HAVE_GETMAXX
830 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
831 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
836 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
837 : (w)->_begx - (w)->_parent->_begx)
839 #if !defined(getparx) && !HAVE_GETPARX
841 #define getparx(win) __m_getparx(win)
842 #define getpary(win) __m_getpary(win)
844 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
845 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
849 #if !defined(mvwvline) && !HAVE_MVWVLINE
850 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
851 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
854 #if !defined(mvvline) && !HAVE_MVVLINE
855 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
856 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
860 * Try to accommodate curses implementations that have no terminfo support.
863 #define TIGETNUM(ti,tc) tigetnum(ti)
865 #define TIGETNUM(ti,tc) tgetnum(tc)
869 #define TIGETSTR(ti,tc) tigetstr(ti)
871 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
875 * So far (2013 - more than ten years), only ncurses implements
876 * use_extended_names().
878 #if defined(NCURSES_XNAMES)
879 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
880 #define NCURSES_XNAMES 1
882 #define NCURSES_XNAMES 0
886 * ncurses restores the cursor in endwin(). Other libraries may not.
888 #ifdef NCURSES_VERSION
889 #define stop_curses() endwin()
891 #define stop_curses() do { endwin(); curs_set(1); } while (0)
894 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
895 * (which is incompatible with legacy usage, doesn't solve any problems).
897 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
898 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
900 #define UChar(c) ((unsigned char)(c))
902 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
904 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
905 #include <nc_alloc.h>
906 #if HAVE_NC_FREEALL && defined(USE_TINFO)
908 #define ExitProgram(code) exit_terminfo(code)
911 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
912 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
913 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
917 #define ExitProgram(code) exit(code)
921 #define EXIT_SUCCESS 0
924 #define EXIT_FAILURE 1
927 #if defined(_WIN32) || defined(USE_WIN32CON_DRIVER)
929 #if defined(PDCURSES)
932 # error WINVER must at least be 0x0501
935 # define WINVER 0x0501
938 #include <sys/time.h> /* for struct timeval */
940 #define sleep(n) Sleep((n) * 1000)
943 #define getlogin() "username"
945 #elif defined(HAVE_NCURSESW_NCURSES_H)
946 #include <ncursesw/nc_mingw.h>
947 #elif defined(HAVE_NCURSES_NCURSES_H)
948 #include <ncurses/nc_mingw.h>
950 #include <nc_mingw.h>
953 /* conflicts in test/firstlast.c */
960 #if TIME_WITH_SYS_TIME
961 # include <sys/time.h>
965 # include <sys/time.h>
975 #ifndef STDOUT_FILENO
976 #define STDOUT_FILENO 1
980 extern char *_nc_strstr(const char *, const char *);
981 #define strstr(a,b) _nc_strstr((a),(b))
982 #endif /* !HAVE_STRSTR */
984 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
985 * curses which doesn't have const parameters declared (so far) in the places
988 #ifndef NCURSES_CONST
990 #define NCURSES_CONST const /* close enough */
992 #define NCURSES_CONST /* nothing */
996 /* out-of-band values for representing absent capabilities */
997 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
998 #define ABSENT_NUMERIC (-1)
999 #define ABSENT_STRING (char *)0
1001 /* out-of-band values for representing cancels */
1002 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
1003 #define CANCELLED_NUMERIC (-2)
1004 #define CANCELLED_STRING (char *)(-1)
1006 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
1007 #define VALID_NUMERIC(s) ((s) >= 0)
1008 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1010 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1012 #define CATCHALL(handler) do { \
1014 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1015 if (nsig != SIGKILL) \
1016 signal(nsig, handler); \
1019 #ifdef NCURSES_VERSION
1020 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1022 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1026 * Workaround for clean(er) compile with Solaris's legacy curses.
1027 * The same would be needed for HPUX 10.20
1030 #define TPUTS_ARG int
1033 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1035 #define TPUTS_ARG char
1036 extern char *tgoto(char *, int, int); /* available, but not prototyped */
1040 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1043 #ifndef TPUTS_RETURN
1044 #define TPUTS_RETURN(value) return value
1048 * Workarounds for Solaris's X/Open curses
1050 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1051 #define KEY_MIN __KEY_MIN
1053 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1054 #define KEY_MAX __KEY_MAX
1058 * Workaround to build with Sun's default SVr4 curses.
1060 #ifdef NCURSES_VERSION
1061 #ifndef HAVE_VW_PRINTW
1062 #define HAVE_VW_PRINTW 1
1067 * ncurses provides arrays of capability names; X/Open discarded these SVr4
1068 * features. Some implementations continue to provide them (see the test
1069 * configure script).
1071 #ifdef NCURSES_VERSION
1072 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1073 #define HAVE_CURSES_DATA_BOOLNAMES 1
1078 * ncurses provides a termcap interface; a few packagers replace or displace
1079 * its header file with an incompatible one. The demo_termcap program uses
1080 * the ncurses file, if available.
1082 #ifdef NCURSES_VERSION
1083 #ifndef HAVE_NCURSES_TERMCAP_H
1084 #define HAVE_NCURSES_TERMCAP_H 0
1086 #ifndef HAVE_TERMCAP_H
1087 #define HAVE_TERMCAP_H 0
1092 * ncurses uses const in some places where X/Open does (or did) not allow.
1094 #if defined(NCURSES_CONST)
1095 #define CONST_MENUS NCURSES_CONST
1096 #elif defined(PDCURSES)
1097 #define CONST_MENUS const
1099 #define CONST_MENUS /* nothing */
1103 * Simplify setting up demo of threading with these macros.
1107 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1108 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1109 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1110 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1112 #define USING_WINDOW(w,func) func(w, NULL)
1113 #define USING_WINDOW1(w,func,safe) func(w)
1114 #define USING_WINDOW2(w,func,data) func(w,data)
1115 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1119 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1120 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1122 #define USING_SCREEN(s,func,data) func(data)
1123 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1126 #if defined(TRACE) && HAVE__TRACEF
1127 #define Trace(p) _tracef p
1129 #define START_TRACE() \
1130 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1131 int t = _nc_getenv_num("NCURSES_TRACE"); \
1133 curses_trace((unsigned) t); \
1135 extern unsigned _nc_tracing;
1136 extern int _nc_getenv_num(const char *);
1139 #define Trace(p) /* nothing */
1141 #define START_TRACE() /* nothing */
1144 #define Trace2(p) /* nothing */
1146 #define AddCh(c) (void) addch((chtype)(c))
1147 #define WAddCh(w,c) (void) waddch((w),(chtype)(c))
1148 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c))
1149 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c))
1150 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s))
1151 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s))
1152 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s))
1153 #define MvPrintw (void) mvprintw
1154 #define MvWPrintw (void) mvwprintw
1155 #define MvHLine (void) mvhline
1156 #define MvWHLine (void) mvwhline
1157 #define MvVLine (void) mvvline
1158 #define MvWVLine (void) mvwvline
1161 * The macro likely uses unsigned values, while X/Open prototype uses int.
1163 #if defined(wattrset) || defined(PDCURSES)
1164 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a))
1166 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a))
1170 * Workaround for defective implementation of gcc attribute warn_unused_result
1172 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1173 #define IGNORE_RC(func) errno = func
1175 #define IGNORE_RC(func) (void) func
1176 #endif /* gcc workarounds */
1178 #define init_mb(state) memset(&state, 0, sizeof(state))
1180 #endif /* __TEST_PRIV_H */