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.199 2022/04/09 21:32:05 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_UNGET_WCH
307 #define HAVE_UNGET_WCH 0
310 #ifndef HAVE_USE_DEFAULT_COLORS
311 #define HAVE_USE_DEFAULT_COLORS 0
315 #define HAVE_USE_ENV 0
318 #ifndef HAVE_USE_EXTENDED_NAMES
319 #define HAVE_USE_EXTENDED_NAMES 0
322 #ifndef HAVE_USE_SCREEN
323 #define HAVE_USE_SCREEN 0
326 #ifndef HAVE_USE_WINDOW
327 #define HAVE_USE_WINDOW 0
331 #define HAVE_VIDPUTS 0
334 #ifndef HAVE_VID_PUTS
335 #define HAVE_VID_PUTS 0
338 #ifndef HAVE_WINSDELLN
339 #define HAVE_WINSDELLN 0
343 #define HAVE_WRESIZE 0
347 #define HAVE__TRACEF 0
350 #ifndef NCURSES_EXT_FUNCS
351 #define NCURSES_EXT_FUNCS 0
355 #define NEED_PTEM_H 0
359 #define NEED_WCHAR_H 0
367 * Workaround for HPUX
369 #if defined(__hpux) && !defined(NCURSES_VERSION)
370 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */
376 #include <sys/types.h>
383 #include <signal.h> /* include before curses.h to work around glibc bug */
387 #ifdef HAVE_LIBUTF8_H
392 #if defined(HAVE_XCURSES)
394 #elif defined(HAVE_NCURSESW_NCURSES_H)
395 #include <ncursesw/curses.h>
396 #elif defined(HAVE_NCURSES_NCURSES_H)
397 #include <ncurses/curses.h>
402 #if HAVE_STDNORETURN_H && !defined(NCURSES_VERSION)
403 #include <stdnoreturn.h>
405 #define GCC_NORETURN _Noreturn
408 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
409 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */
412 #if defined(HAVE_XCURSES) || defined(PDCURSES)
413 /* no other headers */
414 #undef HAVE_SETUPTERM /* nonfunctional */
415 #define HAVE_SETUPTERM 0
416 #undef HAVE_TGETENT /* nonfunctional */
417 #define HAVE_TGETENT 0
418 #undef HAVE_TIGETSTR /* nonfunctional */
419 #define HAVE_TIGETSTR 0
420 #elif defined(HAVE_NCURSESW_TERM_H)
421 #include <ncursesw/term.h>
422 #elif defined(HAVE_NCURSES_TERM_H)
423 #include <ncurses/term.h>
424 #elif defined(HAVE_TERM_H)
429 * Not all curses.h implementations include unctrl.h,
431 #if defined(HAVE_NCURSESW_UNCTRL_H)
432 #include <ncursesw/unctrl.h>
433 #elif defined(HAVE_NCURSES_UNCTRL_H)
434 #include <ncurses/unctrl.h>
435 #elif defined(HAVE_UNCTRL_H)
441 #elif !defined(HAVE_GETOPT_HEADER)
442 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
447 #endif /* HAVE_GETOPT_H */
452 #define setlocale(name,string) /* nothing */
458 #if defined(_MSC_VER)
460 #define popen(s,n) _popen(s,n)
462 #define pclose(s) _pclose(s)
466 #define GCC_NORETURN /* nothing */
468 #ifndef GCC_PRINTFLIKE
469 #define GCC_PRINTFLIKE(a,b) /* nothing */
471 #ifndef GCC_SCANFLIKE
472 #define GCC_SCANFLIKE(a,b) /* nothing */
475 #define GCC_UNUSED /* nothing */
479 #define getnstr(s,n) getstr(s)
482 #if HAVE_INIT_EXTENDED_COLOR
483 #define USE_EXTENDED_COLOR 1
485 #define USE_EXTENDED_COLOR 0
490 #define USE_SOFTKEYS 1
492 #define USE_SOFTKEYS 0
497 #define slk_init() /* nothing */
498 #define slk_restore() /* nothing */
499 #define slk_clear() /* nothing */
502 #ifndef HAVE_CURSES_DATA_TABSIZE
503 #define HAVE_CURSES_DATA_TABSIZE 0
506 #if !NCURSES_EXT_FUNCS
507 #if HAVE_CURSES_DATA_TABSIZE
508 #define set_tabsize(n) TABSIZE = (n)
510 #define set_tabsize(n) /* nothing */
515 #define USE_SP_FUNCS 1
517 #define USE_SP_FUNCS 0
520 #ifndef HAVE_WSYNCDOWN
521 #define wsyncdown(win) /* nothing */
524 #ifndef USE_WIDEC_SUPPORT
525 #if (defined(_XOPEN_SOURCE_EXTENDED) \
526 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
527 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
528 && defined(WACS_ULCORNER)
529 #define USE_WIDEC_SUPPORT 1
531 #define USE_WIDEC_SUPPORT 0
535 #if HAVE_PANEL_H && HAVE_LIBPANEL
536 #define USE_LIBPANEL 1
538 #define USE_LIBPANEL 0
541 #if HAVE_MENU_H && HAVE_LIBMENU
542 #define USE_LIBMENU 1
544 #define USE_LIBMENU 0
547 #if HAVE_FORM_H && HAVE_LIBFORM
548 #define USE_LIBFORM 1
550 #define USE_LIBFORM 0
553 /* workaround, to build against NetBSD's variant of the form library */
554 #ifdef HAVE_NETBSD_FORM_H
555 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos
557 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
560 /* workaround, to build against NetBSD's variant of the form library */
561 #ifdef HAVE_NETBSD_MENU_H
562 #define menu_itemwidth(menu) (menu)->max_item_width
564 #define menu_itemwidth(menu) (menu)->itemlen
567 #ifndef HAVE_TYPE_ATTR_T
568 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
569 #define attr_t chtype
574 #if !USE_WIDEC_SUPPORT
575 #define NCURSES_CH_T chtype
577 #define NCURSES_CH_T cchar_t
580 #ifndef NCURSES_COLOR_T
581 #define NCURSES_COLOR_T short
584 #ifndef NCURSES_PAIRS_T
585 #define NCURSES_PAIRS_T short
592 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
593 #define CURSES_WACS_SYMBOLS
596 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
597 /* NetBSD 5.1 defines these incorrectly */
631 #define WACS_RARROW &(CURSES_WACS_ARRAY['+'])
632 #define WACS_LARROW &(CURSES_WACS_ARRAY[','])
633 #define WACS_UARROW &(CURSES_WACS_ARRAY['-'])
634 #define WACS_DARROW &(CURSES_WACS_ARRAY['.'])
635 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0'])
636 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`'])
637 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a'])
638 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f'])
639 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g'])
640 #define WACS_BOARD &(CURSES_WACS_ARRAY['h'])
641 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i'])
642 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j'])
643 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k'])
644 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l'])
645 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m'])
646 #define WACS_PLUS &(CURSES_WACS_ARRAY['n'])
647 #define WACS_HLINE &(CURSES_WACS_ARRAY['q'])
648 #define WACS_S1 &(CURSES_WACS_ARRAY['o'])
649 #define WACS_S9 &(CURSES_WACS_ARRAY['s'])
650 #define WACS_LTEE &(CURSES_WACS_ARRAY['t'])
651 #define WACS_RTEE &(CURSES_WACS_ARRAY['u'])
652 #define WACS_BTEE &(CURSES_WACS_ARRAY['v'])
653 #define WACS_TTEE &(CURSES_WACS_ARRAY['w'])
654 #define WACS_VLINE &(CURSES_WACS_ARRAY['x'])
655 #define WACS_BULLET &(CURSES_WACS_ARRAY['~'])
656 #define WACS_S3 &(CURSES_WACS_ARRAY['p'])
657 #define WACS_S7 &(CURSES_WACS_ARRAY['r'])
658 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y'])
659 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z'])
660 #define WACS_PI &(CURSES_WACS_ARRAY['{'])
661 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|'])
662 #define WACS_STERLING &(CURSES_WACS_ARRAY['}'])
666 #define WA_NORMAL A_NORMAL
669 #define WA_BOLD A_BOLD
672 #define WA_REVERSE A_REVERSE
675 #define WA_UNDERLINE A_UNDERLINE
678 #define WA_BLINK A_BLINK
690 #define CTRL(x) ((x) & 0x1f)
692 #define QUIT CTRL('Q')
693 #define ESCAPE CTRL('[')
696 #define KEY_MIN 256 /* not defined in Solaris 8 */
699 #define HELP_KEY_1 '?'
700 #define HELP_KEY_2 KEY_F(1)
702 /* from nc_string.h, to make this stand alone */
703 #if HAVE_BSD_STRING_H
704 #include <bsd/string.h>
708 #define NCURSES_VOID /* nothing */
710 #define NCURSES_VOID (void)
714 #define HAVE_STRLCAT 0
718 #define HAVE_STRLCPY 0
721 #ifndef HAVE_SNPRINTF
722 #define HAVE_SNPRINTF 0
725 #ifndef USE_STRING_HACKS
726 #define USE_STRING_HACKS 0
732 #define NCURSES_CAST(type,value) static_cast<type>(value)
734 #define NCURSES_CAST(type,value) (type)(value)
738 #if USE_STRING_HACKS && HAVE_STRLCAT
739 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
740 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
742 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
743 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
746 #if USE_STRING_HACKS && HAVE_STRLCPY
747 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
748 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
750 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
751 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
754 #if USE_STRING_HACKS && HAVE_SNPRINTF
755 #define _nc_SPRINTF NCURSES_VOID (snprintf)
756 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
758 #define _nc_SPRINTF NCURSES_VOID (sprintf)
759 #define _nc_SLIMIT(n) /* nothing */
763 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
764 * curses did, and some implementations provide them anyway, but undeclared.
766 #ifdef DECL_CURSES_DATA_BOOLNAMES
767 extern char *boolnames[], *boolcodes[], *boolfnames[];
768 extern char *numnames[], *numcodes[], *numfnames[];
769 extern char *strnames[], *strcodes[], *strfnames[];
773 * Again, an SVr4 curses feature latent in the libraries but not in headers.
775 #ifndef DECL_CURSES_DATA_TABSIZE
776 #define DECL_CURSES_DATA_TABSIZE 0
779 #if DECL_CURSES_DATA_TABSIZE
781 #undef HAVE_CURSES_DATA_TABSIZE
782 #define HAVE_CURSES_DATA_TABSIZE 1
785 #ifndef HAVE_CURSES_DATA_TABSIZE
786 #define HAVE_CURSES_DATA_TABSIZE 0
790 * X/Open Curses provides termname(), whose return value is analogous to the
791 * SVr4 curses variable ttytype[].
793 #ifndef HAVE_CURSES_DATA_TTYTYPE
794 #define HAVE_CURSES_DATA_TTYTYPE 0
797 #ifndef DECL_CURSES_DATA_TTYTYPE
798 #define DECL_CURSES_DATA_TTYTYPE 0
801 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
802 #define ttytype termname()
805 #define colored_chtype(ch, attr, pair) \
806 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
809 * Workaround for HPUX
811 #if defined(__hpux) && !defined(NCURSES_VERSION)
812 #define getbegx(w) __getbegx(w)
813 #define getbegy(w) __getbegy(w)
814 #define getcurx(w) __getcurx(w)
815 #define getcury(w) __getcury(w)
816 #define getmaxx(w) __getmaxx(w)
817 #define getmaxy(w) __getmaxy(w)
818 #define getparx(w) __getparx(w)
819 #define getpary(w) __getpary(w)
823 * Workaround in case getcchar() returns a positive value when the source
824 * string produces only a L'\0'.
826 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
827 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
828 wchar_t test_wch[CCHARW_MAX + 2]; \
830 NCURSES_PAIRS_T test_pair; \
832 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
833 && test_wch[0] != L'\0') { \
842 * These usually are implemented as macros, but may be functions.
844 #if !defined(getcurx) && !HAVE_GETCURX
845 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
846 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
849 #if !defined(getbegx) && !HAVE_GETBEGX
850 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
851 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
854 #if !defined(getmaxx) && !HAVE_GETMAXX
855 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
856 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
861 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
862 : (w)->_begx - (w)->_parent->_begx)
864 #if !defined(getparx) && !HAVE_GETPARX
866 #define getparx(win) __m_getparx(win)
867 #define getpary(win) __m_getpary(win)
869 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
870 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
874 #if !defined(mvwvline) && !HAVE_MVWVLINE
875 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
876 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
879 #if !defined(mvvline) && !HAVE_MVVLINE
880 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
881 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
885 * Try to accommodate curses implementations that have no terminfo support.
888 #define TIGETNUM(ti,tc) tigetnum(ti)
890 #define TIGETNUM(ti,tc) tgetnum(tc)
894 #define TIGETSTR(ti,tc) tigetstr(ti)
896 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
900 * So far (2013 - more than ten years), only ncurses implements
901 * use_extended_names().
903 #if defined(NCURSES_XNAMES)
904 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
905 #define NCURSES_XNAMES 1
907 #define NCURSES_XNAMES 0
911 * ncurses restores the cursor in endwin(). Other libraries may not.
913 #ifdef NCURSES_VERSION
914 #define stop_curses() endwin()
916 #define stop_curses() do { endwin(); curs_set(1); } while (0)
919 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
920 * (which is incompatible with legacy usage, doesn't solve any problems).
922 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
923 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
925 #define UChar(c) ((unsigned char)(c))
927 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
929 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
930 #include <nc_alloc.h>
931 #if HAVE_EXIT_TERMINFO && (defined(USE_TERMINFO) || defined(USE_TINFO))
933 #define ExitProgram(code) exit_terminfo(code)
934 #elif HAVE_EXIT_CURSES
936 #define ExitProgram(code) exit_curses(code)
938 #else /* not ncurses-tree */
939 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
940 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
941 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
945 #define ExitProgram(code) exit(code)
949 #define EXIT_SUCCESS 0
952 #define EXIT_FAILURE 1
956 #if (defined(_WIN32) || defined(_WIN64))
957 #define _NC_WINDOWS 1
960 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
962 #if defined(PDCURSES)
965 # error WINVER must at least be 0x0501
968 # define WINVER 0x0501
971 #include <sys/time.h> /* for struct timeval */
973 #define sleep(n) Sleep((n) * 1000)
976 #define getlogin() "username"
978 #elif defined(EXP_WIN32_DRIVER)
980 #if defined(HAVE_NCURSESW_NCURSES_H)
981 #include <ncursesw/nc_win32.h>
982 #elif defined(HAVE_NCURSES_NCURSES_H)
983 #include <ncurses/nc_win32.h>
985 #include <nc_win32.h>
990 #if defined(HAVE_NCURSESW_NCURSES_H)
991 #include <ncursesw/nc_mingw.h>
992 #elif defined(HAVE_NCURSES_NCURSES_H)
993 #include <ncurses/nc_mingw.h>
995 #include <nc_mingw.h>
1000 /* conflicts in test/firstlast.c */
1007 #if TIME_WITH_SYS_TIME
1008 # include <sys/time.h>
1011 # if HAVE_SYS_TIME_H
1012 # include <sys/time.h>
1022 #ifndef STDOUT_FILENO
1023 #define STDOUT_FILENO 1
1027 extern char *_nc_strstr(const char *, const char *);
1028 #define strstr(a,b) _nc_strstr((a),(b))
1029 #endif /* !HAVE_STRSTR */
1031 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
1032 * curses which doesn't have const parameters declared (so far) in the places
1035 #ifndef NCURSES_CONST
1037 #define NCURSES_CONST const /* close enough */
1039 #define NCURSES_CONST /* nothing */
1043 /* out-of-band values for representing absent capabilities */
1044 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
1045 #define ABSENT_NUMERIC (-1)
1046 #define ABSENT_STRING (char *)0
1048 /* out-of-band values for representing cancels */
1049 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
1050 #define CANCELLED_NUMERIC (-2)
1051 #define CANCELLED_STRING (char *)(-1)
1053 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
1054 #define VALID_NUMERIC(s) ((s) >= 0)
1055 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1057 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1059 #define CATCHALL(handler) do { \
1061 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1062 if (nsig != SIGKILL) \
1063 signal(nsig, handler); \
1066 #ifdef NCURSES_VERSION
1067 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1069 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1072 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1073 #define SetupAlarm(opt) (void)opt
1075 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
1079 * Workaround for clean(er) compile with Solaris's legacy curses.
1080 * The same would be needed for HPUX 10.20
1083 #define TPUTS_ARG int
1086 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1088 #define TPUTS_ARG char
1089 extern char *tgoto(char *, int, int); /* available, but not prototyped */
1093 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1096 #ifndef TPUTS_RETURN
1097 #define TPUTS_RETURN(value) return value
1101 * Workarounds for Solaris's X/Open curses
1103 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1104 #define KEY_MIN __KEY_MIN
1106 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1107 #define KEY_MAX __KEY_MAX
1111 * Workaround to build with Sun's default SVr4 curses.
1113 #ifdef NCURSES_VERSION
1114 #ifndef HAVE_VW_PRINTW
1115 #define HAVE_VW_PRINTW 1
1120 * ncurses provides arrays of capability names; X/Open discarded these SVr4
1121 * features. Some implementations continue to provide them (see the test
1122 * configure script).
1124 #ifdef NCURSES_VERSION
1125 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1126 #define HAVE_CURSES_DATA_BOOLNAMES 1
1131 * ncurses provides a termcap interface; a few packagers replace or displace
1132 * its header file with an incompatible one. The demo_termcap program uses
1133 * the ncurses file, if available.
1135 #ifdef NCURSES_VERSION
1136 #ifndef HAVE_NCURSES_TERMCAP_H
1137 #define HAVE_NCURSES_TERMCAP_H 0
1139 #ifndef HAVE_TERMCAP_H
1140 #define HAVE_TERMCAP_H 0
1145 * ncurses uses const in some places where X/Open does (or did) not allow.
1147 #if defined(NCURSES_CONST)
1148 #define CONST_MENUS NCURSES_CONST
1149 #elif defined(PDCURSES)
1150 #define CONST_MENUS const
1152 #define CONST_MENUS /* nothing */
1155 #if defined(NCURSES_CONST)
1156 #define CONST_FMT NCURSES_CONST
1157 #elif defined(PDCURSES)
1158 #define CONST_FMT const
1160 #define CONST_FMT /* nothing */
1164 * Simplify setting up demo of threading with these macros.
1168 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1169 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1170 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1171 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1173 #define USING_WINDOW(w,func) func(w, NULL)
1174 #define USING_WINDOW1(w,func,safe) func(w)
1175 #define USING_WINDOW2(w,func,data) func(w,data)
1176 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1180 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1181 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1183 #define USING_SCREEN(s,func,data) func(data)
1184 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1187 #if defined(TRACE) && HAVE__TRACEF
1188 #define Trace(p) _tracef p
1190 #define START_TRACE() \
1191 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1192 int t = _nc_getenv_num("NCURSES_TRACE"); \
1194 curses_trace((unsigned) t); \
1196 extern unsigned _nc_tracing;
1197 extern int _nc_getenv_num(const char *);
1200 #define Trace(p) /* nothing */
1202 #define START_TRACE() /* nothing */
1205 #define Trace2(p) /* nothing */
1207 #define AddCh(c) (void) addch((chtype)(c))
1208 #define WAddCh(w,c) (void) waddch((w),(chtype)(c))
1209 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c))
1210 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c))
1211 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s))
1212 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s))
1213 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s))
1214 #define MvPrintw (void) mvprintw
1215 #define MvWPrintw (void) mvwprintw
1216 #define MvHLine (void) mvhline
1217 #define MvWHLine (void) mvwhline
1218 #define MvVLine (void) mvvline
1219 #define MvWVLine (void) mvwvline
1222 * The macro likely uses unsigned values, while X/Open prototype uses int.
1224 #if defined(wattrset) || defined(PDCURSES)
1225 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a))
1227 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a))
1231 * Workaround for defective implementation of gcc attribute warn_unused_result
1233 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1234 #define IGNORE_RC(func) errno = func
1236 #define IGNORE_RC(func) (void) func
1237 #endif /* gcc workarounds */
1239 #define init_mb(state) memset(&state, 0, sizeof(state))
1241 #endif /* __TEST_PRIV_H */