1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.80 2008/12/20 16:37:20 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
48 #define HAVE_LIBMENUW 1
52 #define HAVE_LIBPANELW 1
56 * Fallback definitions to accommodate broken compilers.
58 #ifndef HAVE_CURSES_VERSION
59 #define HAVE_CURSES_VERSION 0
66 #ifndef HAVE_COLOR_SET
67 #define HAVE_COLOR_SET 0
79 #define HAVE_GETBEGX 0
83 #define HAVE_GETCURX 0
87 #define HAVE_GETMAXX 0
91 #define HAVE_GETOPT_H 0
95 #define HAVE_GETPARX 0
103 #define HAVE_LIBFORM 0
107 #define HAVE_LIBMENU 0
110 #ifndef HAVE_LIBPANEL
111 #define HAVE_LIBPANEL 0
114 #ifndef HAVE_LOCALE_H
115 #define HAVE_LOCALE_H 0
119 #define HAVE_MENU_H 0
123 #define HAVE_MVVLINE 0
126 #ifndef HAVE_MVWVLINE
127 #define HAVE_MVWVLINE 0
134 #ifndef HAVE_NC_ALLOC_H
135 #define HAVE_NC_ALLOC_H 0
139 #define HAVE_PANEL_H 0
143 #define HAVE_PUTWIN 0
146 #ifndef HAVE_RESIZE_TERM
147 #define HAVE_RESIZE_TERM 0
150 #ifndef HAVE_RIPOFFLINE
151 #define HAVE_RIPOFFLINE 0
154 #ifndef HAVE_SETUPTERM
155 #define HAVE_SETUPTERM 0
158 #ifndef HAVE_SLK_COLOR
159 #define HAVE_SLK_COLOR 0
162 #ifndef HAVE_SLK_INIT
163 #define HAVE_SLK_INIT 0
166 #ifndef HAVE_TERMATTRS
167 #define HAVE_TERMATTRS 0
170 #ifndef HAVE_TERMNAME
171 #define HAVE_TERMNAME 0
175 #define HAVE_TGETENT 0
178 #ifndef HAVE_TIGETNUM
179 #define HAVE_TIGETNUM 0
182 #ifndef HAVE_TYPEAHEAD
183 #define HAVE_TYPEAHEAD 0
186 #ifndef HAVE_TIGETSTR
187 #define HAVE_TIGETSTR 0
191 #define HAVE_WINSSTR 0
194 #ifndef HAVE_USE_DEFAULT_COLORS
195 #define HAVE_USE_DEFAULT_COLORS 0
199 #define HAVE_WRESIZE 0
202 #ifndef NCURSES_EXT_FUNCS
203 #define NCURSES_EXT_FUNCS 0
207 #define NEED_PTEM_H 0
216 #include <sys/types.h>
222 #include <signal.h> /* include before curses.h to work around glibc bug */
224 #if defined(HAVE_XCURSES)
226 #elif defined(HAVE_NCURSESW_NCURSES_H)
227 #include <ncursesw/curses.h>
228 #elif defined(HAVE_NCURSES_NCURSES_H)
229 #include <ncurses/curses.h>
234 #if defined(HAVE_XCURSES)
235 /* no other headers */
236 #undef HAVE_SETUPTERM /* nonfunctional */
237 #define HAVE_SETUPTERM 0
238 #undef HAVE_TGETENT /* nonfunctional */
239 #define HAVE_TGETENT 0
240 #undef HAVE_TIGETSTR /* nonfunctional */
241 #define HAVE_TIGETSTR 0
242 #elif defined(HAVE_NCURSESW_TERM_H)
243 #include <ncursesw/term.h>
244 #elif defined(HAVE_NCURSES_TERM_H)
245 #include <ncurses/term.h>
246 #elif defined(HAVE_TERM_H)
251 * Not all curses.h implementations include unctrl.h,
252 * Solaris 10 xpg4 for example.
254 #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
255 #if defined(HAVE_NCURSESW_NCURSES_H)
256 #include <ncursesw/unctrl.h>
257 #elif defined(HAVE_NCURSES_NCURSES_H)
258 #include <ncurses/unctrl.h>
267 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
272 #endif /* HAVE_GETOPT_H */
277 #define setlocale(name,string) /* nothing */
284 #define GCC_NORETURN /* nothing */
286 #ifndef GCC_PRINTFLIKE
287 #define GCC_PRINTFLIKE(a,b) /* nothing */
290 #define GCC_UNUSED /* nothing */
294 #define getnstr(s,n) getstr(s)
299 #define USE_SOFTKEYS 1
301 #define USE_SOFTKEYS 0
305 #ifndef USE_WIDEC_SUPPORT
306 #if defined(_XOPEN_SOURCE_EXTENDED) && defined(WACS_ULCORNER)
307 #define USE_WIDEC_SUPPORT 1
309 #define USE_WIDEC_SUPPORT 0
313 #if HAVE_PANEL_H && HAVE_LIBPANEL
314 #define USE_LIBPANEL 1
316 #define USE_LIBPANEL 0
319 #if HAVE_MENU_H && HAVE_LIBMENU
320 #define USE_LIBMENU 1
322 #define USE_LIBMENU 0
325 #if HAVE_FORM_H && HAVE_LIBFORM
326 #define USE_LIBFORM 1
328 #define USE_LIBFORM 0
331 #ifndef HAVE_TYPE_ATTR_T
332 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
333 #define attr_t chtype
338 #if !USE_WIDEC_SUPPORT
339 #define NCURSES_CH_T chtype
341 #define NCURSES_CH_T cchar_t
344 #ifndef NCURSES_OPAQUE
345 #define NCURSES_OPAQUE 0
353 #define CTRL(x) ((x) & 0x1f)
355 #define QUIT CTRL('Q')
356 #define ESCAPE CTRL('[')
359 #define KEY_MIN 256 /* not defined in Solaris 8 */
362 #define colored_chtype(ch, attr, pair) \
363 ((ch) | (attr) | COLOR_PAIR(pair))
366 * Workaround for HPUX
368 #if defined(__hpux) && !defined(NCURSES_VERSION)
369 #define getbegx(w) __getbegx(w)
370 #define getbegy(w) __getbegy(w)
371 #define getcurx(w) __getcurx(w)
372 #define getcury(w) __getcury(w)
373 #define getmaxx(w) __getmaxx(w)
374 #define getmaxy(w) __getmaxy(w)
375 #define getparx(w) __getparx(w)
376 #define getpary(w) __getpary(w)
380 * These usually are implemented as macros, but may be functions.
382 #if !defined(getcurx) && !HAVE_GETCURX
383 #define getcurx(win) ((win)?(win)->_curx:ERR)
384 #define getcury(win) ((win)?(win)->_cury:ERR)
387 #if !defined(getbegx) && !HAVE_GETBEGX
388 #define getbegx(win) ((win)?(win)->_begx:ERR)
389 #define getbegy(win) ((win)?(win)->_begy:ERR)
392 #if !defined(getmaxx) && !HAVE_GETMAXX
393 #define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
394 #define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
399 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
400 : (w)->_begx - (w)->_parent->_begx)
402 #if !defined(getparx) && !HAVE_GETPARX
404 #define getparx(win) __m_getparx(win)
405 #define getpary(win) __m_getpary(win)
407 #define getparx(win) ((win)?((win)->_parx + 1):ERR)
408 #define getpary(win) ((win)?((win)->_pary + 1):ERR)
412 #if !defined(mvwvline) && !HAVE_MVWVLINE
413 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
414 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
417 #if !defined(mvvline) && !HAVE_MVVLINE
418 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
419 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
423 * Try to accommodate curses implementations that have no terminfo support.
426 #define TIGETNUM(ti,tc) tigetnum(ti)
428 #define TIGETNUM(ti,tc) tgetnum(tc)
432 #define TIGETSTR(ti,tc) tigetstr(ti)
434 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
437 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
438 * (which is incompatible with legacy usage, doesn't solve any problems).
440 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
441 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
443 #define UChar(c) ((unsigned char)(c))
445 #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
447 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
448 #include <nc_alloc.h>
449 #if HAVE_NC_FREEALL && defined(USE_TINFO)
451 #define ExitProgram(code) _nc_free_tinfo(code)
454 #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
455 #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
456 #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
460 #define ExitProgram(code) exit(code)
464 #define EXIT_SUCCESS 0
467 #define EXIT_FAILURE 1
470 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
471 * curses which doesn't have const parameters declared (so far) in the places
474 #ifndef NCURSES_CONST
475 #define NCURSES_CONST /* nothing */
478 /* out-of-band values for representing absent capabilities */
479 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
480 #define ABSENT_NUMERIC (-1)
481 #define ABSENT_STRING (char *)0
483 /* out-of-band values for representing cancels */
484 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
485 #define CANCELLED_NUMERIC (-2)
486 #define CANCELLED_STRING (char *)(-1)
488 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
489 #define VALID_NUMERIC(s) ((s) >= 0)
490 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
492 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
494 #define CATCHALL(handler) { \
496 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
497 if (nsig != SIGKILL) \
498 signal(nsig, handler); \
502 * Workaround for clean(er) compile with Solaris's legacy curses.
503 * The same would be needed for HPUX 10.20
506 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
507 #define TPUTS_ARG char
508 extern char *tgoto(char *, int, int); /* available, but not prototyped */
510 #define TPUTS_ARG int
515 * Workarounds for Solaris's X/Open curses
517 #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
518 #if !defined(KEY_MIN) && defined(__KEY_MIN)
519 #define KEY_MIN __KEY_MIN
521 #if !defined(KEY_MAX) && defined(__KEY_MIN)
522 #define KEY_MAX __KEY_MAX
527 * ncurses uses const in some places where X/Open does (or did) not allow.
529 #ifdef NCURSES_VERSION
530 #define CONST_MENUS const
532 #define CONST_MENUS /* nothing */
535 #ifndef HAVE_USE_WINDOW
536 #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
537 #define HAVE_USE_WINDOW 0
539 #define HAVE_USE_WINDOW 1
544 * Simplify setting up demo of threading with these macros.
548 typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
549 typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
553 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
554 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
555 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
557 #define USING_WINDOW(w,func) func(w)
558 #define USING_WINDOW2(w,func,data) func(w,data)
559 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
563 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
564 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
566 #define USING_SCREEN(s,func,data) func(s,data)
567 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
571 #define Trace(p) _tracef p
574 #define Trace(p) /* nothing */
578 #define init_mb(state) memset(&state, 0, sizeof(state))
580 #endif /* __TEST_PRIV_H */