1/**************************************************************************** 2 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * 3 * * 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: * 11 * * 12 * The above copyright notice and this permission notice shall be included * 13 * in all copies or substantial portions of the Software. * 14 * * 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. * 22 * * 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 * 26 * authorization. * 27 ****************************************************************************/ 28 29/**************************************************************************** 30 * Author: Thomas E. Dickey 1996-on * 31 ****************************************************************************/ 32/* $Id: test.priv.h,v 1.79 2008/10/04 21:53:41 tom Exp $ */ 33 34#ifndef __TEST_PRIV_H 35#define __TEST_PRIV_H 1 36 37#include <ncurses_cfg.h> 38 39/* 40 * Fix ifdef's that look for the form/menu/panel libraries, if we are building 41 * with wide-character ncurses. 42 */ 43#ifdef HAVE_LIBFORMW 44#define HAVE_LIBFORMW 1 45#endif 46 47#ifdef HAVE_LIBMENUW 48#define HAVE_LIBMENUW 1 49#endif 50 51#ifdef HAVE_LIBPANELW 52#define HAVE_LIBPANELW 1 53#endif 54 55/* 56 * Fallback definitions to accommodate broken compilers. 57 */ 58#ifndef HAVE_CURSES_VERSION 59#define HAVE_CURSES_VERSION 0 60#endif 61 62#ifndef HAVE_CHGAT 63#define HAVE_CHGAT 0 64#endif 65 66#ifndef HAVE_COLOR_SET 67#define HAVE_COLOR_SET 0 68#endif 69 70#ifndef HAVE_FILTER 71#define HAVE_FILTER 0 72#endif 73 74#ifndef HAVE_FORM_H 75#define HAVE_FORM_H 0 76#endif 77 78#ifndef HAVE_GETBEGX 79#define HAVE_GETBEGX 0 80#endif 81 82#ifndef HAVE_GETCURX 83#define HAVE_GETCURX 0 84#endif 85 86#ifndef HAVE_GETMAXX 87#define HAVE_GETMAXX 0 88#endif 89 90#ifndef HAVE_GETOPT_H 91#define HAVE_GETOPT_H 0 92#endif 93 94#ifndef HAVE_GETPARX 95#define HAVE_GETPARX 0 96#endif 97 98#ifndef HAVE_GETWIN 99#define HAVE_GETWIN 0 100#endif 101 102#ifndef HAVE_LIBFORM 103#define HAVE_LIBFORM 0 104#endif 105 106#ifndef HAVE_LIBMENU 107#define HAVE_LIBMENU 0 108#endif 109 110#ifndef HAVE_LIBPANEL 111#define HAVE_LIBPANEL 0 112#endif 113 114#ifndef HAVE_LOCALE_H 115#define HAVE_LOCALE_H 0 116#endif 117 118#ifndef HAVE_MENU_H 119#define HAVE_MENU_H 0 120#endif 121 122#ifndef HAVE_MVVLINE 123#define HAVE_MVVLINE 0 124#endif 125 126#ifndef HAVE_MVWVLINE 127#define HAVE_MVWVLINE 0 128#endif 129 130#ifndef HAVE_NAPMS 131#define HAVE_NAPMS 1 132#endif 133 134#ifndef HAVE_NC_ALLOC_H 135#define HAVE_NC_ALLOC_H 0 136#endif 137 138#ifndef HAVE_PANEL_H 139#define HAVE_PANEL_H 0 140#endif 141 142#ifndef HAVE_PUTWIN 143#define HAVE_PUTWIN 0 144#endif 145 146#ifndef HAVE_RESIZE_TERM 147#define HAVE_RESIZE_TERM 0 148#endif 149 150#ifndef HAVE_RIPOFFLINE 151#define HAVE_RIPOFFLINE 0 152#endif 153 154#ifndef HAVE_SETUPTERM 155#define HAVE_SETUPTERM 0 156#endif 157 158#ifndef HAVE_SLK_COLOR 159#define HAVE_SLK_COLOR 0 160#endif 161 162#ifndef HAVE_SLK_INIT 163#define HAVE_SLK_INIT 0 164#endif 165 166#ifndef HAVE_TERMATTRS 167#define HAVE_TERMATTRS 0 168#endif 169 170#ifndef HAVE_TERMNAME 171#define HAVE_TERMNAME 0 172#endif 173 174#ifndef HAVE_TGETENT 175#define HAVE_TGETENT 0 176#endif 177 178#ifndef HAVE_TIGETNUM 179#define HAVE_TIGETNUM 0 180#endif 181 182#ifndef HAVE_TYPEAHEAD 183#define HAVE_TYPEAHEAD 0 184#endif 185 186#ifndef HAVE_TIGETSTR 187#define HAVE_TIGETSTR 0 188#endif 189 190#ifndef HAVE_WINSSTR 191#define HAVE_WINSSTR 0 192#endif 193 194#ifndef HAVE_USE_DEFAULT_COLORS 195#define HAVE_USE_DEFAULT_COLORS 0 196#endif 197 198#ifndef HAVE_WRESIZE 199#define HAVE_WRESIZE 0 200#endif 201 202#ifndef NCURSES_EXT_FUNCS 203#define NCURSES_EXT_FUNCS 0 204#endif 205 206#ifndef NEED_PTEM_H 207#define NEED_PTEM_H 0 208#endif 209 210#ifndef NO_LEAKS 211#define NO_LEAKS 0 212#endif 213 214#include <stdlib.h> 215#include <string.h> 216#include <sys/types.h> 217 218#if HAVE_UNISTD_H 219#include <unistd.h> 220#endif 221 222#include <signal.h> /* include before curses.h to work around glibc bug */ 223 224#if defined(HAVE_XCURSES) 225#include <xcurses.h> 226#elif defined(HAVE_NCURSESW_NCURSES_H) 227#include <ncursesw/curses.h> 228#elif defined(HAVE_NCURSES_NCURSES_H) 229#include <ncurses/curses.h> 230#else 231#include <curses.h> 232#endif 233 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) 247#include <term.h> 248#endif 249 250/* 251 * Not all curses.h implementations include unctrl.h, 252 * Solaris 10 xpg4 for example. 253 */ 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> 259#else 260#include <unctrl.h> 261#endif 262#endif 263 264#if HAVE_GETOPT_H 265#include <getopt.h> 266#else 267/* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables 268 * doesn't hurt. 269 */ 270extern char *optarg; 271extern int optind; 272#endif /* HAVE_GETOPT_H */ 273 274#if HAVE_LOCALE_H 275#include <locale.h> 276#else 277#define setlocale(name,string) /* nothing */ 278#endif 279 280#include <assert.h> 281#include <ctype.h> 282 283#ifndef GCC_NORETURN 284#define GCC_NORETURN /* nothing */ 285#endif 286#ifndef GCC_PRINTFLIKE 287#define GCC_PRINTFLIKE(a,b) /* nothing */ 288#endif 289#ifndef GCC_UNUSED 290#define GCC_UNUSED /* nothing */ 291#endif 292 293#ifndef HAVE_GETNSTR 294#define getnstr(s,n) getstr(s) 295#endif 296 297#ifndef USE_SOFTKEYS 298#if HAVE_SLK_INIT 299#define USE_SOFTKEYS 1 300#else 301#define USE_SOFTKEYS 0 302#endif 303#endif 304 305#ifndef USE_WIDEC_SUPPORT 306#if defined(_XOPEN_SOURCE_EXTENDED) && defined(WACS_ULCORNER) 307#define USE_WIDEC_SUPPORT 1 308#else 309#define USE_WIDEC_SUPPORT 0 310#endif 311#endif 312 313#if HAVE_PANEL_H && HAVE_LIBPANEL 314#define USE_LIBPANEL 1 315#else 316#define USE_LIBPANEL 0 317#endif 318 319#if HAVE_MENU_H && HAVE_LIBMENU 320#define USE_LIBMENU 1 321#else 322#define USE_LIBMENU 0 323#endif 324 325#if HAVE_FORM_H && HAVE_LIBFORM 326#define USE_LIBFORM 1 327#else 328#define USE_LIBFORM 0 329#endif 330 331#ifndef HAVE_TYPE_ATTR_T 332#if !USE_WIDEC_SUPPORT && !defined(attr_t) 333#define attr_t chtype 334#endif 335#endif 336 337#undef NCURSES_CH_T 338#if !USE_WIDEC_SUPPORT 339#define NCURSES_CH_T chtype 340#else 341#define NCURSES_CH_T cchar_t 342#endif 343 344#ifndef NCURSES_OPAQUE 345#define NCURSES_OPAQUE 0 346#endif 347 348#ifndef CCHARW_MAX 349#define CCHARW_MAX 5 350#endif 351 352#undef CTRL 353#define CTRL(x) ((x) & 0x1f) 354 355#define QUIT CTRL('Q') 356#define ESCAPE CTRL('[') 357 358#ifndef KEY_MIN 359#define KEY_MIN 256 /* not defined in Solaris 8 */ 360#endif 361 362/* 363 * Workaround for HPUX 364 */ 365#if defined(__hpux) && !defined(NCURSES_VERSION) 366#define getbegx(w) __getbegx(w) 367#define getbegy(w) __getbegy(w) 368#define getcurx(w) __getcurx(w) 369#define getcury(w) __getcury(w) 370#define getmaxx(w) __getmaxx(w) 371#define getmaxy(w) __getmaxy(w) 372#define getparx(w) __getparx(w) 373#define getpary(w) __getpary(w) 374#endif 375 376/* 377 * These usually are implemented as macros, but may be functions. 378 */ 379#if !defined(getcurx) && !HAVE_GETCURX 380#define getcurx(win) ((win)?(win)->_curx:ERR) 381#define getcury(win) ((win)?(win)->_cury:ERR) 382#endif 383 384#if !defined(getbegx) && !HAVE_GETBEGX 385#define getbegx(win) ((win)?(win)->_begx:ERR) 386#define getbegy(win) ((win)?(win)->_begy:ERR) 387#endif 388 389#if !defined(getmaxx) && !HAVE_GETMAXX 390#define getmaxx(win) ((win)?((win)->_maxx + 1):ERR) 391#define getmaxy(win) ((win)?((win)->_maxy + 1):ERR) 392#endif 393 394/* 395 * Solaris 10 xpg4: 396#define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \ 397 : (w)->_begx - (w)->_parent->_begx) 398 */ 399#if !defined(getparx) && !HAVE_GETPARX 400#ifdef __m_getparx 401#define getparx(win) __m_getparx(win) 402#define getpary(win) __m_getpary(win) 403#else 404#define getparx(win) ((win)?((win)->_parx + 1):ERR) 405#define getpary(win) ((win)?((win)->_pary + 1):ERR) 406#endif 407#endif 408 409#if !defined(mvwvline) && !HAVE_MVWVLINE 410#define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n)) 411#define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n)) 412#endif 413 414#if !defined(mvvline) && !HAVE_MVVLINE 415#define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n)) 416#define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n)) 417#endif 418 419/* 420 * Try to accommodate curses implementations that have no terminfo support. 421 */ 422#if HAVE_TIGETNUM 423#define TIGETNUM(ti,tc) tigetnum(ti) 424#else 425#define TIGETNUM(ti,tc) tgetnum(tc) 426#endif 427 428#if HAVE_TIGETSTR 429#define TIGETSTR(ti,tc) tigetstr(ti) 430#else 431#define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer) 432#endif 433 434/* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list 435 * (which is incompatible with legacy usage, doesn't solve any problems). 436 */ 437#define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0) 438#define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0) 439 440#define UChar(c) ((unsigned char)(c)) 441 442#define SIZEOF(table) (sizeof(table)/sizeof(table[0])) 443 444#if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H 445#include <nc_alloc.h> 446#if HAVE_NC_FREEALL && defined(USE_TINFO) 447#undef ExitProgram 448#define ExitProgram(code) _nc_free_tinfo(code) 449#endif 450#else 451#define typeMalloc(type,n) (type *) malloc((n) * sizeof(type)) 452#define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type)) 453#define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type)) 454#endif 455 456#ifndef ExitProgram 457#define ExitProgram(code) exit(code) 458#endif 459 460#ifndef EXIT_SUCCESS 461#define EXIT_SUCCESS 0 462#endif 463#ifndef EXIT_FAILURE 464#define EXIT_FAILURE 1 465#endif 466 467/* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4 468 * curses which doesn't have const parameters declared (so far) in the places 469 * that XSI shows. 470 */ 471#ifndef NCURSES_CONST 472#define NCURSES_CONST /* nothing */ 473#endif 474 475/* out-of-band values for representing absent capabilities */ 476#define ABSENT_BOOLEAN ((signed char)-1) /* 255 */ 477#define ABSENT_NUMERIC (-1) 478#define ABSENT_STRING (char *)0 479 480/* out-of-band values for representing cancels */ 481#define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */ 482#define CANCELLED_NUMERIC (-2) 483#define CANCELLED_STRING (char *)(-1) 484 485#define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */ 486#define VALID_NUMERIC(s) ((s) >= 0) 487#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING) 488 489#define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~" 490 491#define CATCHALL(handler) { \ 492 int nsig; \ 493 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \ 494 if (nsig != SIGKILL) \ 495 signal(nsig, handler); \ 496 } 497 498/* 499 * Workaround for clean(er) compile with Solaris's legacy curses. 500 * The same would be needed for HPUX 10.20 501 */ 502#ifndef TPUTS_ARG 503#if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH) 504#define TPUTS_ARG char 505extern char *tgoto(char *, int, int); /* available, but not prototyped */ 506#else 507#define TPUTS_ARG int 508#endif 509#endif 510 511/* 512 * Workarounds for Solaris's X/Open curses 513 */ 514#if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH) 515#if !defined(KEY_MIN) && defined(__KEY_MIN) 516#define KEY_MIN __KEY_MIN 517#endif 518#if !defined(KEY_MAX) && defined(__KEY_MIN) 519#define KEY_MAX __KEY_MAX 520#endif 521#endif 522 523/* 524 * ncurses uses const in some places where X/Open does (or did) not allow. 525 */ 526#ifdef NCURSES_VERSION 527#define CONST_MENUS const 528#else 529#define CONST_MENUS /* nothing */ 530#endif 531 532#ifndef HAVE_USE_WINDOW 533#if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS 534#define HAVE_USE_WINDOW 0 535#else 536#define HAVE_USE_WINDOW 1 537#endif 538#endif 539 540/* 541 * Simplify setting up demo of threading with these macros. 542 */ 543 544#if !HAVE_USE_WINDOW 545typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *); 546typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *); 547#endif 548 549#if HAVE_USE_WINDOW 550#define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w) 551#define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data) 552#define WANT_USE_WINDOW() extern void _nc_want_use_window(void) 553#else 554#define USING_WINDOW(w,func) func(w) 555#define USING_WINDOW2(w,func,data) func(w,data) 556#define WANT_USE_WINDOW() extern void _nc_want_use_window(void) 557#endif 558 559#if HAVE_USE_WINDOW 560#define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data) 561#define WANT_USE_SCREEN() extern void _nc_want_use_screen(void) 562#else 563#define USING_SCREEN(s,func,data) func(s,data) 564#define WANT_USE_SCREEN() extern void _nc_want_use_screen(void) 565#endif 566 567#ifdef TRACE 568#define Trace(p) _tracef p 569#define USE_TRACE 1 570#else 571#define Trace(p) /* nothing */ 572#define USE_TRACE 0 573#endif 574 575#define init_mb(state) memset(&state, 0, sizeof(state)) 576 577#endif /* __TEST_PRIV_H */ 578