1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey 1996-on *
31 ****************************************************************************/
32 /* $Id: test.priv.h,v 1.95 2010/05/01 19:03:04 tom Exp $ */
35 #define __TEST_PRIV_H 1
37 #include <ncurses_cfg.h>
40 * Fix ifdef's that look for the form/menu/panel libraries, if we are building
41 * with wide-character ncurses.
44 #define HAVE_LIBFORMW 1
45 #define HAVE_LIBFORM 1
49 #define HAVE_LIBMENUW 1
50 #define HAVE_LIBMENU 1
54 #define HAVE_LIBPANELW 1
55 #define HAVE_LIBPANEL 1
59 * Fallback definitions to accommodate broken compilers.
61 #ifndef HAVE_CURSES_VERSION
62 #define HAVE_CURSES_VERSION 0
69 #ifndef HAVE_COLOR_SET
70 #define HAVE_COLOR_SET 0
82 #define HAVE_GETBEGX 0
86 #define HAVE_GETCURX 0
90 #define HAVE_GETMAXX 0
94 #define HAVE_GETOPT_H 0
98 #define HAVE_GETPARX 0
102 #define HAVE_GETWIN 0
106 #define HAVE_LIBFORM 0
110 #define HAVE_LIBMENU 0
113 #ifndef HAVE_LIBPANEL
114 #define HAVE_LIBPANEL 0
117 #ifndef HAVE_LOCALE_H
118 #define HAVE_LOCALE_H 0
122 #define HAVE_MENU_H 0
126 #define HAVE_MVVLINE 0
129 #ifndef HAVE_MVWVLINE
130 #define HAVE_MVWVLINE 0
137 #ifndef HAVE_NC_ALLOC_H
138 #define HAVE_NC_ALLOC_H 0
142 #define HAVE_PANEL_H 0
146 #define HAVE_PUTWIN 0
149 #ifndef HAVE_RESIZE_TERM
150 #define HAVE_RESIZE_TERM 0
153 #ifndef HAVE_RIPOFFLINE
154 #define HAVE_RIPOFFLINE 0
157 #ifndef HAVE_SETUPTERM
158 #define HAVE_SETUPTERM 0
161 #ifndef HAVE_SLK_COLOR
162 #define HAVE_SLK_COLOR 0
165 #ifndef HAVE_SLK_INIT
166 #define HAVE_SLK_INIT 0
169 #ifndef HAVE_TERMATTRS
170 #define HAVE_TERMATTRS 0
173 #ifndef HAVE_TERMNAME
174 #define HAVE_TERMNAME 0
178 #define HAVE_TGETENT 0
181 #ifndef HAVE_TIGETNUM
182 #define HAVE_TIGETNUM 0
185 #ifndef HAVE_TYPEAHEAD
186 #define HAVE_TYPEAHEAD 0
189 #ifndef HAVE_TIGETSTR
190 #define HAVE_TIGETSTR 0
194 #define HAVE_WINSSTR 0
197 #ifndef HAVE_USE_DEFAULT_COLORS
198 #define HAVE_USE_DEFAULT_COLORS 0
202 #define HAVE_WRESIZE 0
205 #ifndef NCURSES_EXT_FUNCS
206 #define NCURSES_EXT_FUNCS 0
210 #define NEED_PTEM_H 0
214 #define NEED_WCHAR_H 0
224 #include <sys/types.h>
231 #include <signal.h> /* include before curses.h to work around glibc bug */
235 #ifdef HAVE_LIBUTF8_H
240 #if defined(HAVE_XCURSES)
242 #elif defined(HAVE_NCURSESW_NCURSES_H)
243 #include <ncursesw/curses.h>
244 #elif defined(HAVE_NCURSES_NCURSES_H)
245 #include <ncurses/curses.h>
250 #if defined(HAVE_XCURSES)
251 /* no other headers */
252 #undef HAVE_SETUPTERM /* nonfunctional */
253 #define HAVE_SETUPTERM 0
254 #undef HAVE_TGETENT /* nonfunctional */
255 #define HAVE_TGETENT 0
256 #undef HAVE_TIGETSTR /* nonfunctional */
257 #define HAVE_TIGETSTR 0
258 #elif defined(HAVE_NCURSESW_TERM_H)
259 #include <ncursesw/term.h>
260 #elif defined(HAVE_NCURSES_TERM_H)
261 #include <ncurses/term.h>
262 #elif defined(HAVE_TERM_H)
267 * Not all curses.h implementations include unctrl.h,
268 * Solaris 10 xpg4 for example.
270 #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
271 #if defined(HAVE_NCURSESW_NCURSES_H)
272 #include <ncursesw/unctrl.h>
273 #elif defined(HAVE_NCURSES_NCURSES_H)
274 #include <ncurses/unctrl.h>
283 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
288 #endif /* HAVE_GETOPT_H */
293 #define setlocale(name,string) /* nothing */
300 #define GCC_NORETURN /* nothing */
302 #ifndef GCC_PRINTFLIKE
303 #define GCC_PRINTFLIKE(a,b) /* nothing */
306 #define GCC_UNUSED /* nothing */
310 #define getnstr(s,n) getstr(s)
315 #define USE_SOFTKEYS 1
317 #define USE_SOFTKEYS 0
321 #ifndef USE_WIDEC_SUPPORT
322 #if (defined(_XOPEN_SOURCE_EXTENDED) || defined(_XPG5)) && defined(WACS_ULCORNER)
323 #define USE_WIDEC_SUPPORT 1
325 #define USE_WIDEC_SUPPORT 0
329 #if HAVE_PANEL_H && HAVE_LIBPANEL
330 #define USE_LIBPANEL 1
332 #define USE_LIBPANEL 0
335 #if HAVE_MENU_H && HAVE_LIBMENU
336 #define USE_LIBMENU 1
338 #define USE_LIBMENU 0
341 #if HAVE_FORM_H && HAVE_LIBFORM
342 #define USE_LIBFORM 1
344 #define USE_LIBFORM 0
347 #ifndef HAVE_TYPE_ATTR_T
348 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
349 #define attr_t chtype
354 #if !USE_WIDEC_SUPPORT
355 #define NCURSES_CH_T chtype
357 #define NCURSES_CH_T cchar_t
360 #ifndef NCURSES_OPAQUE
361 #define NCURSES_OPAQUE 0
369 #define CTRL(x) ((x) & 0x1f)
371 #define QUIT CTRL('Q')
372 #define ESCAPE CTRL('[')
375 #define KEY_MIN 256 /* not defined in Solaris 8 */
378 #ifdef DECL_CURSES_DATA_BOOLNAMES
379 extern char *boolnames[], *boolcodes[], *boolfnames[],
380 *numnames[], *numcodes[], *numfnames[],
381 *strnames[], *strcodes[], *strfnames[];
384 #define colored_chtype(ch, attr, pair) \
385 ((ch) | (attr) | COLOR_PAIR(pair))
388 * Workaround for HPUX
390 #if defined(__hpux) && !defined(NCURSES_VERSION)
391 #define getbegx(w) __getbegx(w)
392 #define getbegy(w) __getbegy(w)
393 #define getcurx(w) __getcurx(w)
394 #define getcury(w) __getcury(w)
395 #define getmaxx(w) __getmaxx(w)
396 #define getmaxy(w) __getmaxy(w)
397 #define getparx(w) __getparx(w)
398 #define getpary(w) __getpary(w)
402 * Workaround in case getcchar() returns a positive value when the source
403 * string produces only a L'\0'.
405 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
406 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
407 wchar_t test_wch[CCHARW_MAX + 2]; \
411 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
412 && test_wch[0] != L'\0') { \
421 * These usually are implemented as macros, but may be functions.
423 #if !defined(getcurx) && !HAVE_GETCURX
424 #define getcurx(win) ((win)?(win)->_curx:ERR)
425 #define getcury(win) ((win)?(win)->_cury:ERR)
428 #if !defined(getbegx) && !HAVE_GETBEGX
429 #define getbegx(win) ((win)?(win)->_begx:ERR)
430 #define getbegy(win) ((win)?(win)->_begy:ERR)
433 #if !defined(getmaxx) && !HAVE_GETMAXX
434 #define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
435 #define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
440 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
441 : (w)->_begx - (w)->_parent->_begx)
443 #if !defined(getparx) && !HAVE_GETPARX
445 #define getparx(win) __m_getparx(win)
446 #define getpary(win) __m_getpary(win)
448 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
449 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
453 #if !defined(mvwvline) && !HAVE_MVWVLINE
454 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
455 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
458 #if !defined(mvvline) && !HAVE_MVVLINE
459 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
460 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
464 * Try to accommodate curses implementations that have no terminfo support.
467 #define TIGETNUM(ti,tc) tigetnum(ti)
469 #define TIGETNUM(ti,tc) tgetnum(tc)
473 #define TIGETSTR(ti,tc) tigetstr(ti)
475 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
478 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
479 * (which is incompatible with legacy usage, doesn't solve any problems).
481 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
482 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
484 #define UChar(c) ((unsigned char)(c))
486 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
488 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
489 #include <nc_alloc.h>
490 #if HAVE_NC_FREEALL && defined(USE_TINFO)
492 #define ExitProgram(code) _nc_free_tinfo(code)
495 #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
496 #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
497 #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
501 #define ExitProgram(code) exit(code)
505 #define EXIT_SUCCESS 0
508 #define EXIT_FAILURE 1
512 #include <nc_mingw.h>
513 /* conflicts in test/firstlast.c */
519 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
520 * curses which doesn't have const parameters declared (so far) in the places
523 #ifndef NCURSES_CONST
524 #define NCURSES_CONST /* nothing */
527 /* out-of-band values for representing absent capabilities */
528 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
529 #define ABSENT_NUMERIC (-1)
530 #define ABSENT_STRING (char *)0
532 /* out-of-band values for representing cancels */
533 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
534 #define CANCELLED_NUMERIC (-2)
535 #define CANCELLED_STRING (char *)(-1)
537 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
538 #define VALID_NUMERIC(s) ((s) >= 0)
539 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
541 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
543 #define CATCHALL(handler) { \
545 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
546 if (nsig != SIGKILL) \
547 signal(nsig, handler); \
551 * Workaround for clean(er) compile with Solaris's legacy curses.
552 * The same would be needed for HPUX 10.20
555 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
556 #define TPUTS_ARG char
557 extern char *tgoto(char *, int, int); /* available, but not prototyped */
559 #define TPUTS_ARG int
564 * Workarounds for Solaris's X/Open curses
566 #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
567 #if !defined(KEY_MIN) && defined(__KEY_MIN)
568 #define KEY_MIN __KEY_MIN
570 #if !defined(KEY_MAX) && defined(__KEY_MIN)
571 #define KEY_MAX __KEY_MAX
576 * Workaround to build with Sun's default SVr4 curses.
578 #ifdef NCURSES_VERSION
579 #ifndef HAVE_VW_PRINTW
580 #define HAVE_VW_PRINTW 1
585 * ncurses provides arrays of capability names; X/Open discarded these SVr4
586 * features. Some implementations continue to provide them (see the test
589 #ifdef NCURSES_VERSION
590 #ifndef HAVE_CURSES_DATA_BOOLNAMES
591 #define HAVE_CURSES_DATA_BOOLNAMES 1
596 * ncurses uses const in some places where X/Open does (or did) not allow.
598 #ifdef NCURSES_VERSION
599 #define CONST_MENUS const
601 #define CONST_MENUS /* nothing */
604 #ifndef HAVE_USE_WINDOW
605 #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
606 #define HAVE_USE_WINDOW 0
608 #define HAVE_USE_WINDOW 1
613 * Simplify setting up demo of threading with these macros.
617 typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
618 typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
622 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
623 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
624 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
626 #define USING_WINDOW(w,func) func(w)
627 #define USING_WINDOW2(w,func,data) func(w,data)
628 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
632 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
633 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
635 #define USING_SCREEN(s,func,data) func(data)
636 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
640 #define Trace(p) _tracef p
643 #define Trace(p) /* nothing */
647 #define MvAddCh (void) mvaddch
648 #define MvWAddCh (void) mvwaddch
649 #define MvAddStr (void) mvaddstr
650 #define MvWAddStr (void) mvwaddstr
651 #define MvWAddChStr (void) mvwaddchstr
652 #define MvPrintw (void) mvprintw
653 #define MvWPrintw (void) mvwprintw
654 #define MvHLine (void) mvhline
655 #define MvWHLine (void) mvwhline
656 #define MvVLine (void) mvvline
657 #define MvWVLine (void) mvwvline
660 * Workaround for defective implementation of gcc attribute warn_unused_result
662 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
663 #define IGNORE_RC(func) errno = func
665 #define IGNORE_RC(func) (void) func
666 #endif /* gcc workarounds */
668 #define init_mb(state) memset(&state, 0, sizeof(state))
670 #endif /* __TEST_PRIV_H */