1 /**************************************************************************** 2 * Copyright 2018-2020,2021 Thomas E. Dickey * 3 * Copyright 1998-2017,2018 Free Software Foundation, Inc. * 4 * * 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: * 12 * * 13 * The above copyright notice and this permission notice shall be included * 14 * in all copies or substantial portions of the Software. * 15 * * 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. * 23 * * 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 * 27 * authorization. * 28 ****************************************************************************/ 29 30 /**************************************************************************** 31 * Author: Thomas E. Dickey 1996-on * 32 ****************************************************************************/ 33 /* $Id: test.priv.h,v 1.197 2021/04/25 00:00:24 tom Exp $ */ 34 35 #ifndef __TEST_PRIV_H 36 #define __TEST_PRIV_H 1 37 38 #include <ncurses_cfg.h> 39 40 /* 41 * Fix ifdef's that look for the form/menu/panel libraries, if we are building 42 * with wide-character ncurses. 43 */ 44 #ifdef HAVE_LIBFORMW 45 #define HAVE_LIBFORMW 1 46 #define HAVE_LIBFORM 1 47 #endif 48 49 #ifdef HAVE_LIBMENUW 50 #define HAVE_LIBMENUW 1 51 #define HAVE_LIBMENU 1 52 #endif 53 54 #ifdef HAVE_LIBPANELW 55 #define HAVE_LIBPANELW 1 56 #define HAVE_LIBPANEL 1 57 #endif 58 59 /* 60 * Fallback definitions to accommodate broken compilers. 61 */ 62 #ifndef HAVE_ALLOC_PAIR 63 #define HAVE_ALLOC_PAIR 0 64 #endif 65 66 #ifndef HAVE_ASSUME_DEFAULT_COLORS 67 #define HAVE_ASSUME_DEFAULT_COLORS 0 68 #endif 69 70 #ifndef HAVE_BSD_STRING_H 71 #define HAVE_BSD_STRING_H 0 72 #endif 73 74 #ifndef HAVE_CURSES_VERSION 75 #define HAVE_CURSES_VERSION 0 76 #endif 77 78 #ifndef HAVE_CURSCR 79 #define HAVE_CURSCR 0 80 #endif 81 82 #ifndef HAVE_CHGAT 83 #define HAVE_CHGAT 0 84 #endif 85 86 #ifndef HAVE_COLOR_CONTENT 87 #define HAVE_COLOR_CONTENT 0 88 #endif 89 90 #ifndef HAVE_COPYWIN 91 #define HAVE_COPYWIN 0 92 #endif 93 94 #ifndef HAVE_COLOR_SET 95 #define HAVE_COLOR_SET 0 96 #endif 97 98 #ifndef HAVE_DELSCREEN 99 #define HAVE_DELSCREEN 0 100 #endif 101 102 #ifndef HAVE_DUPWIN 103 #define HAVE_DUPWIN 0 104 #endif 105 106 #ifndef HAVE_FILTER 107 #define HAVE_FILTER 0 108 #endif 109 110 #ifndef HAVE_FORM_H 111 #define HAVE_FORM_H 0 112 #endif 113 114 #ifndef HAVE_GETBEGX 115 #define HAVE_GETBEGX 0 116 #endif 117 118 #ifndef HAVE_GETCURX 119 #define HAVE_GETCURX 0 120 #endif 121 122 #ifndef HAVE_GETMAXX 123 #define HAVE_GETMAXX 0 124 #endif 125 126 #ifndef HAVE_GETOPT_H 127 #define HAVE_GETOPT_H 0 128 #endif 129 130 #ifndef HAVE_GETPARX 131 #define HAVE_GETPARX 0 132 #endif 133 134 #ifndef HAVE_GETWIN 135 #define HAVE_GETWIN 0 136 #endif 137 138 #ifndef HAVE_HALFDELAY 139 #define HAVE_HALFDELAY 0 140 #endif 141 142 #ifndef HAVE_INIT_EXTENDED_COLOR 143 #define HAVE_INIT_EXTENDED_COLOR 0 144 #endif 145 146 #ifndef HAVE_LIBFORM 147 #define HAVE_LIBFORM 0 148 #endif 149 150 #ifndef HAVE_LIBMENU 151 #define HAVE_LIBMENU 0 152 #endif 153 154 #ifndef HAVE_LIBPANEL 155 #define HAVE_LIBPANEL 0 156 #endif 157 158 #ifndef HAVE_LANGINFO_CODESET 159 #define HAVE_LANGINFO_CODESET 0 160 #endif 161 162 #ifndef HAVE_LOCALE_H 163 #define HAVE_LOCALE_H 0 164 #endif 165 166 #ifndef HAVE_MATH_H 167 #define HAVE_MATH_H 0 168 #endif 169 170 #ifndef HAVE_MENU_H 171 #define HAVE_MENU_H 0 172 #endif 173 174 #ifndef HAVE_MVDERWIN 175 #define HAVE_MVDERWIN 0 176 #endif 177 178 #ifndef HAVE_MVVLINE 179 #define HAVE_MVVLINE 0 180 #endif 181 182 #ifndef HAVE_MVWIN 183 #define HAVE_MVWIN 0 184 #endif 185 186 #ifndef HAVE_MVWVLINE 187 #define HAVE_MVWVLINE 0 188 #endif 189 190 #ifndef HAVE_NAPMS 191 #define HAVE_NAPMS 1 192 #endif 193 194 #ifndef HAVE_NC_ALLOC_H 195 #define HAVE_NC_ALLOC_H 0 196 #endif 197 198 #ifndef HAVE_NEWPAD 199 #define HAVE_NEWPAD 0 200 #endif 201 202 #ifndef HAVE_PANEL_H 203 #define HAVE_PANEL_H 0 204 #endif 205 206 #ifndef HAVE_PUTWIN 207 #define HAVE_PUTWIN 0 208 #endif 209 210 #ifndef HAVE_RESET_COLOR_PAIRS 211 #define HAVE_RESET_COLOR_PAIRS 0 212 #endif 213 214 #ifndef HAVE_RESIZE_TERM 215 #define HAVE_RESIZE_TERM 0 216 #endif 217 218 #ifndef HAVE_RESTARTTERM 219 #define HAVE_RESTARTTERM 0 220 #endif 221 222 #ifndef HAVE_RIPOFFLINE 223 #define HAVE_RIPOFFLINE 0 224 #endif 225 226 #ifndef HAVE_SCR_DUMP 227 #define HAVE_SCR_DUMP 0 228 #endif 229 230 #ifndef HAVE_SETUPTERM 231 #define HAVE_SETUPTERM 0 232 #endif 233 234 #ifndef HAVE_SLK_COLOR 235 #define HAVE_SLK_COLOR 0 236 #endif 237 238 #ifndef HAVE_SLK_INIT 239 #define HAVE_SLK_INIT 0 240 #endif 241 242 #ifndef HAVE_STDINT_H 243 #define HAVE_STDINT_H 0 244 #endif 245 246 #ifndef HAVE_STDNORETURN_H 247 #define HAVE_STDNORETURN_H 0 248 #endif 249 250 #ifndef HAVE_STRSTR 251 #define HAVE_STRSTR 0 252 #endif 253 254 #ifndef HAVE_SYS_IOCTL_H 255 #define HAVE_SYS_IOCTL_H 0 256 #endif 257 258 #ifndef HAVE_SYS_SELECT_H 259 #define HAVE_SYS_SELECT_H 0 260 #endif 261 262 #ifndef HAVE_TERMATTRS 263 #define HAVE_TERMATTRS 0 264 #endif 265 266 #ifndef HAVE_TERMIOS_H 267 #define HAVE_TERMIOS_H 0 268 #endif 269 270 #ifndef HAVE_TERMNAME 271 #define HAVE_TERMNAME 0 272 #endif 273 274 #ifndef HAVE_TERM_ENTRY_H 275 #define HAVE_TERM_ENTRY_H 0 276 #endif 277 278 #ifndef HAVE_TGETENT 279 #define HAVE_TGETENT 0 280 #endif 281 282 #ifndef HAVE_TIGETNUM 283 #define HAVE_TIGETNUM 0 284 #endif 285 286 #ifndef HAVE_TIGETSTR 287 #define HAVE_TIGETSTR 0 288 #endif 289 290 #ifndef HAVE_TPUTS_SP 291 #define HAVE_TPUTS_SP 0 292 #endif 293 294 #ifndef HAVE_TSEARCH 295 #define HAVE_TSEARCH 0 296 #endif 297 298 #ifndef HAVE_TYPEAHEAD 299 #define HAVE_TYPEAHEAD 0 300 #endif 301 302 #ifndef HAVE_WINSSTR 303 #define HAVE_WINSSTR 0 304 #endif 305 306 #ifndef HAVE_USE_DEFAULT_COLORS 307 #define HAVE_USE_DEFAULT_COLORS 0 308 #endif 309 310 #ifndef HAVE_USE_ENV 311 #define HAVE_USE_ENV 0 312 #endif 313 314 #ifndef HAVE_USE_EXTENDED_NAMES 315 #define HAVE_USE_EXTENDED_NAMES 0 316 #endif 317 318 #ifndef HAVE_USE_SCREEN 319 #define HAVE_USE_SCREEN 0 320 #endif 321 322 #ifndef HAVE_USE_WINDOW 323 #define HAVE_USE_WINDOW 0 324 #endif 325 326 #ifndef HAVE_VIDPUTS 327 #define HAVE_VIDPUTS 0 328 #endif 329 330 #ifndef HAVE_VID_PUTS 331 #define HAVE_VID_PUTS 0 332 #endif 333 334 #ifndef HAVE_WINSDELLN 335 #define HAVE_WINSDELLN 0 336 #endif 337 338 #ifndef HAVE_WRESIZE 339 #define HAVE_WRESIZE 0 340 #endif 341 342 #ifndef HAVE__TRACEF 343 #define HAVE__TRACEF 0 344 #endif 345 346 #ifndef NCURSES_EXT_FUNCS 347 #define NCURSES_EXT_FUNCS 0 348 #endif 349 350 #ifndef NEED_PTEM_H 351 #define NEED_PTEM_H 0 352 #endif 353 354 #ifndef NEED_WCHAR_H 355 #define NEED_WCHAR_H 0 356 #endif 357 358 #ifndef NO_LEAKS 359 #define NO_LEAKS 0 360 #endif 361 362 /* 363 * Workaround for HPUX 364 */ 365 #if defined(__hpux) && !defined(NCURSES_VERSION) 366 #define _ACS_COMPAT_CODE /* needed for acs_map vs __acs_map */ 367 #endif 368 369 #include <stdlib.h> 370 #include <stdarg.h> 371 #include <string.h> 372 #include <sys/types.h> 373 #include <errno.h> 374 375 #if HAVE_UNISTD_H 376 #include <unistd.h> 377 #endif 378 379 #include <signal.h> /* include before curses.h to work around glibc bug */ 380 381 #if NEED_WCHAR_H 382 #include <wchar.h> 383 #ifdef HAVE_LIBUTF8_H 384 #include <libutf8.h> 385 #endif 386 #endif 387 388 #if defined(HAVE_XCURSES) 389 #include <xcurses.h> 390 #elif defined(HAVE_NCURSESW_NCURSES_H) 391 #include <ncursesw/curses.h> 392 #elif defined(HAVE_NCURSES_NCURSES_H) 393 #include <ncurses/curses.h> 394 #else 395 #include <curses.h> 396 #endif 397 398 #if HAVE_STDNORETURN_H && !defined(NCURSES_VERSION) 399 #include <stdnoreturn.h> 400 #undef GCC_NORETURN 401 #define GCC_NORETURN _Noreturn 402 #endif 403 404 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT)) 405 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */ 406 #endif 407 408 #if defined(HAVE_XCURSES) || defined(PDCURSES) 409 /* no other headers */ 410 #undef HAVE_SETUPTERM /* nonfunctional */ 411 #define HAVE_SETUPTERM 0 412 #undef HAVE_TGETENT /* nonfunctional */ 413 #define HAVE_TGETENT 0 414 #undef HAVE_TIGETSTR /* nonfunctional */ 415 #define HAVE_TIGETSTR 0 416 #elif defined(HAVE_NCURSESW_TERM_H) 417 #include <ncursesw/term.h> 418 #elif defined(HAVE_NCURSES_TERM_H) 419 #include <ncurses/term.h> 420 #elif defined(HAVE_TERM_H) 421 #include <term.h> 422 #endif 423 424 /* 425 * Not all curses.h implementations include unctrl.h, 426 */ 427 #if defined(HAVE_NCURSESW_UNCTRL_H) 428 #include <ncursesw/unctrl.h> 429 #elif defined(HAVE_NCURSES_UNCTRL_H) 430 #include <ncurses/unctrl.h> 431 #elif defined(HAVE_UNCTRL_H) 432 #include <unctrl.h> 433 #endif 434 435 #if HAVE_GETOPT_H 436 #include <getopt.h> 437 #elif !defined(HAVE_GETOPT_HEADER) 438 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables 439 * doesn't hurt. 440 */ 441 extern char *optarg; 442 extern int optind; 443 #endif /* HAVE_GETOPT_H */ 444 445 #if HAVE_LOCALE_H 446 #include <locale.h> 447 #else 448 #define setlocale(name,string) /* nothing */ 449 #endif 450 451 #include <assert.h> 452 #include <ctype.h> 453 454 #if defined(_MSC_VER) 455 #undef popen 456 #define popen(s,n) _popen(s,n) 457 #undef pclose 458 #define pclose(s) _pclose(s) 459 #endif 460 461 #ifndef GCC_NORETURN 462 #define GCC_NORETURN /* nothing */ 463 #endif 464 #ifndef GCC_PRINTFLIKE 465 #define GCC_PRINTFLIKE(a,b) /* nothing */ 466 #endif 467 #ifndef GCC_SCANFLIKE 468 #define GCC_SCANFLIKE(a,b) /* nothing */ 469 #endif 470 #ifndef GCC_UNUSED 471 #define GCC_UNUSED /* nothing */ 472 #endif 473 474 #ifndef HAVE_GETNSTR 475 #define getnstr(s,n) getstr(s) 476 #endif 477 478 #if HAVE_INIT_EXTENDED_COLOR 479 #define USE_EXTENDED_COLOR 1 480 #else 481 #define USE_EXTENDED_COLOR 0 482 #endif 483 484 #ifndef USE_SOFTKEYS 485 #if HAVE_SLK_INIT 486 #define USE_SOFTKEYS 1 487 #else 488 #define USE_SOFTKEYS 0 489 #endif 490 #endif 491 492 #if !USE_SOFTKEYS 493 #define slk_init() /* nothing */ 494 #define slk_restore() /* nothing */ 495 #define slk_clear() /* nothing */ 496 #endif 497 498 #ifndef HAVE_CURSES_DATA_TABSIZE 499 #define HAVE_CURSES_DATA_TABSIZE 0 500 #endif 501 502 #if !NCURSES_EXT_FUNCS 503 #if HAVE_CURSES_DATA_TABSIZE 504 #define set_tabsize(n) TABSIZE = (n) 505 #else 506 #define set_tabsize(n) /* nothing */ 507 #endif 508 #endif 509 510 #if HAVE_TPUTS_SP 511 #define USE_SP_FUNCS 1 512 #else 513 #define USE_SP_FUNCS 0 514 #endif 515 516 #ifndef HAVE_WSYNCDOWN 517 #define wsyncdown(win) /* nothing */ 518 #endif 519 520 #ifndef USE_WIDEC_SUPPORT 521 #if (defined(_XOPEN_SOURCE_EXTENDED) \ 522 || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \ 523 || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \ 524 && defined(WACS_ULCORNER) 525 #define USE_WIDEC_SUPPORT 1 526 #else 527 #define USE_WIDEC_SUPPORT 0 528 #endif 529 #endif 530 531 #if HAVE_PANEL_H && HAVE_LIBPANEL 532 #define USE_LIBPANEL 1 533 #else 534 #define USE_LIBPANEL 0 535 #endif 536 537 #if HAVE_MENU_H && HAVE_LIBMENU 538 #define USE_LIBMENU 1 539 #else 540 #define USE_LIBMENU 0 541 #endif 542 543 #if HAVE_FORM_H && HAVE_LIBFORM 544 #define USE_LIBFORM 1 545 #else 546 #define USE_LIBFORM 0 547 #endif 548 549 /* workaround, to build against NetBSD's variant of the form library */ 550 #ifdef HAVE_NETBSD_FORM_H 551 #define form_getyx(form, y, x) y = (int)current_field(form)->cursor_ypos, x = (int)current_field(form)->cursor_xpos 552 #else 553 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol 554 #endif 555 556 /* workaround, to build against NetBSD's variant of the form library */ 557 #ifdef HAVE_NETBSD_MENU_H 558 #define menu_itemwidth(menu) (menu)->max_item_width 559 #else 560 #define menu_itemwidth(menu) (menu)->itemlen 561 #endif 562 563 #ifndef HAVE_TYPE_ATTR_T 564 #if !USE_WIDEC_SUPPORT && !defined(attr_t) 565 #define attr_t chtype 566 #endif 567 #endif 568 569 #undef NCURSES_CH_T 570 #if !USE_WIDEC_SUPPORT 571 #define NCURSES_CH_T chtype 572 #else 573 #define NCURSES_CH_T cchar_t 574 #endif 575 576 #ifndef NCURSES_COLOR_T 577 #define NCURSES_COLOR_T short 578 #endif 579 580 #ifndef NCURSES_PAIRS_T 581 #define NCURSES_PAIRS_T short 582 #endif 583 584 #ifndef CCHARW_MAX 585 #define CCHARW_MAX 5 586 #endif 587 588 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS) 589 #define CURSES_WACS_SYMBOLS 590 #endif 591 592 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS) 593 /* NetBSD 5.1 defines these incorrectly */ 594 #undef WACS_RARROW 595 #undef WACS_LARROW 596 #undef WACS_UARROW 597 #undef WACS_DARROW 598 #undef WACS_BLOCK 599 #undef WACS_DIAMOND 600 #undef WACS_CKBOARD 601 #undef WACS_DEGREE 602 #undef WACS_PLMINUS 603 #undef WACS_BOARD 604 #undef WACS_LANTERN 605 #undef WACS_LRCORNER 606 #undef WACS_URCORNER 607 #undef WACS_ULCORNER 608 #undef WACS_LLCORNER 609 #undef WACS_PLUS 610 #undef WACS_HLINE 611 #undef WACS_S1 612 #undef WACS_S9 613 #undef WACS_LTEE 614 #undef WACS_RTEE 615 #undef WACS_BTEE 616 #undef WACS_TTEE 617 #undef WACS_VLINE 618 #undef WACS_BULLET 619 #undef WACS_S3 620 #undef WACS_S7 621 #undef WACS_LEQUAL 622 #undef WACS_GEQUAL 623 #undef WACS_PI 624 #undef WACS_NEQUAL 625 #undef WACS_STERLING 626 627 #define WACS_RARROW &(CURSES_WACS_ARRAY['+']) 628 #define WACS_LARROW &(CURSES_WACS_ARRAY[',']) 629 #define WACS_UARROW &(CURSES_WACS_ARRAY['-']) 630 #define WACS_DARROW &(CURSES_WACS_ARRAY['.']) 631 #define WACS_BLOCK &(CURSES_WACS_ARRAY['0']) 632 #define WACS_DIAMOND &(CURSES_WACS_ARRAY['`']) 633 #define WACS_CKBOARD &(CURSES_WACS_ARRAY['a']) 634 #define WACS_DEGREE &(CURSES_WACS_ARRAY['f']) 635 #define WACS_PLMINUS &(CURSES_WACS_ARRAY['g']) 636 #define WACS_BOARD &(CURSES_WACS_ARRAY['h']) 637 #define WACS_LANTERN &(CURSES_WACS_ARRAY['i']) 638 #define WACS_LRCORNER &(CURSES_WACS_ARRAY['j']) 639 #define WACS_URCORNER &(CURSES_WACS_ARRAY['k']) 640 #define WACS_ULCORNER &(CURSES_WACS_ARRAY['l']) 641 #define WACS_LLCORNER &(CURSES_WACS_ARRAY['m']) 642 #define WACS_PLUS &(CURSES_WACS_ARRAY['n']) 643 #define WACS_HLINE &(CURSES_WACS_ARRAY['q']) 644 #define WACS_S1 &(CURSES_WACS_ARRAY['o']) 645 #define WACS_S9 &(CURSES_WACS_ARRAY['s']) 646 #define WACS_LTEE &(CURSES_WACS_ARRAY['t']) 647 #define WACS_RTEE &(CURSES_WACS_ARRAY['u']) 648 #define WACS_BTEE &(CURSES_WACS_ARRAY['v']) 649 #define WACS_TTEE &(CURSES_WACS_ARRAY['w']) 650 #define WACS_VLINE &(CURSES_WACS_ARRAY['x']) 651 #define WACS_BULLET &(CURSES_WACS_ARRAY['~']) 652 #define WACS_S3 &(CURSES_WACS_ARRAY['p']) 653 #define WACS_S7 &(CURSES_WACS_ARRAY['r']) 654 #define WACS_LEQUAL &(CURSES_WACS_ARRAY['y']) 655 #define WACS_GEQUAL &(CURSES_WACS_ARRAY['z']) 656 #define WACS_PI &(CURSES_WACS_ARRAY['{']) 657 #define WACS_NEQUAL &(CURSES_WACS_ARRAY['|']) 658 #define WACS_STERLING &(CURSES_WACS_ARRAY['}']) 659 #endif 660 661 #ifndef WA_NORMAL 662 #define WA_NORMAL A_NORMAL 663 #endif 664 #ifndef WA_BOLD 665 #define WA_BOLD A_BOLD 666 #endif 667 #ifndef WA_REVERSE 668 #define WA_REVERSE A_REVERSE 669 #endif 670 #ifndef WA_UNDERLINE 671 #define WA_UNDERLINE A_UNDERLINE 672 #endif 673 #ifndef WA_BLINK 674 #define WA_BLINK A_BLINK 675 #endif 676 677 #ifndef OK 678 #define OK (0) 679 #endif 680 681 #ifndef ERR 682 #define ERR (-1) 683 #endif 684 685 #undef CTRL 686 #define CTRL(x) ((x) & 0x1f) 687 688 #define QUIT CTRL('Q') 689 #define ESCAPE CTRL('[') 690 691 #ifndef KEY_MIN 692 #define KEY_MIN 256 /* not defined in Solaris 8 */ 693 #endif 694 695 #define HELP_KEY_1 '?' 696 #define HELP_KEY_2 KEY_F(1) 697 698 /* from nc_string.h, to make this stand alone */ 699 #if HAVE_BSD_STRING_H 700 #include <bsd/string.h> 701 #endif 702 703 #ifdef __cplusplus 704 #define NCURSES_VOID /* nothing */ 705 #else 706 #define NCURSES_VOID (void) 707 #endif 708 709 #ifndef HAVE_STRLCAT 710 #define HAVE_STRLCAT 0 711 #endif 712 713 #ifndef HAVE_STRLCPY 714 #define HAVE_STRLCPY 0 715 #endif 716 717 #ifndef HAVE_SNPRINTF 718 #define HAVE_SNPRINTF 0 719 #endif 720 721 #ifndef USE_STRING_HACKS 722 #define USE_STRING_HACKS 0 723 #endif 724 725 #ifndef NCURSES_CAST 726 #ifdef __cplusplus 727 extern "C" { 728 #define NCURSES_CAST(type,value) static_cast<type>(value) 729 #else 730 #define NCURSES_CAST(type,value) (type)(value) 731 #endif 732 #endif 733 734 #if USE_STRING_HACKS && HAVE_STRLCAT 735 #define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n)) 736 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m)) 737 #else 738 #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s)) 739 #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n)) 740 #endif 741 742 #if USE_STRING_HACKS && HAVE_STRLCPY 743 #define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n)) 744 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n)) 745 #else 746 #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s)) 747 #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n)) 748 #endif 749 750 #if USE_STRING_HACKS && HAVE_SNPRINTF 751 #define _nc_SPRINTF NCURSES_VOID (snprintf) 752 #define _nc_SLIMIT(n) NCURSES_CAST(size_t,n), 753 #else 754 #define _nc_SPRINTF NCURSES_VOID (sprintf) 755 #define _nc_SLIMIT(n) /* nothing */ 756 #endif 757 758 /* 759 * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4 760 * curses did, and some implementations provide them anyway, but undeclared. 761 */ 762 #ifdef DECL_CURSES_DATA_BOOLNAMES 763 extern char *boolnames[], *boolcodes[], *boolfnames[]; 764 extern char *numnames[], *numcodes[], *numfnames[]; 765 extern char *strnames[], *strcodes[], *strfnames[]; 766 #endif 767 768 /* 769 * Again, an SVr4 curses feature latent in the libraries but not in headers. 770 */ 771 #ifndef DECL_CURSES_DATA_TABSIZE 772 #define DECL_CURSES_DATA_TABSIZE 0 773 #endif 774 775 #if DECL_CURSES_DATA_TABSIZE 776 extern int TABSIZE; 777 #undef HAVE_CURSES_DATA_TABSIZE 778 #define HAVE_CURSES_DATA_TABSIZE 1 779 #endif 780 781 #ifndef HAVE_CURSES_DATA_TABSIZE 782 #define HAVE_CURSES_DATA_TABSIZE 0 783 #endif 784 785 /* 786 * X/Open Curses provides termname(), whose return value is analogous to the 787 * SVr4 curses variable ttytype[]. 788 */ 789 #ifndef HAVE_CURSES_DATA_TTYTYPE 790 #define HAVE_CURSES_DATA_TTYTYPE 0 791 #endif 792 793 #ifndef DECL_CURSES_DATA_TTYTYPE 794 #define DECL_CURSES_DATA_TTYTYPE 0 795 #endif 796 797 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE) 798 #define ttytype termname() 799 #endif 800 801 #define colored_chtype(ch, attr, pair) \ 802 ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair)) 803 804 /* 805 * Workaround for HPUX 806 */ 807 #if defined(__hpux) && !defined(NCURSES_VERSION) 808 #define getbegx(w) __getbegx(w) 809 #define getbegy(w) __getbegy(w) 810 #define getcurx(w) __getcurx(w) 811 #define getcury(w) __getcury(w) 812 #define getmaxx(w) __getmaxx(w) 813 #define getmaxy(w) __getmaxy(w) 814 #define getparx(w) __getparx(w) 815 #define getpary(w) __getpary(w) 816 #endif 817 818 /* 819 * Workaround in case getcchar() returns a positive value when the source 820 * string produces only a L'\0'. 821 */ 822 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \ 823 if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \ 824 wchar_t test_wch[CCHARW_MAX + 2]; \ 825 attr_t test_attrs; \ 826 NCURSES_PAIRS_T test_pair; \ 827 \ 828 if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \ 829 && test_wch[0] != L'\0') { \ 830 then_stmt \ 831 } else { \ 832 else_stmt \ 833 } \ 834 } else { \ 835 else_stmt \ 836 } 837 /* 838 * These usually are implemented as macros, but may be functions. 839 */ 840 #if !defined(getcurx) && !HAVE_GETCURX 841 #define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR) 842 #define getcury(win) ((win) ? ((int)(win)->_cury) : ERR) 843 #endif 844 845 #if !defined(getbegx) && !HAVE_GETBEGX 846 #define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR) 847 #define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR) 848 #endif 849 850 #if !defined(getmaxx) && !HAVE_GETMAXX 851 #define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR) 852 #define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR) 853 #endif 854 855 /* 856 * Solaris 10 xpg4: 857 #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \ 858 : (w)->_begx - (w)->_parent->_begx) 859 */ 860 #if !defined(getparx) && !HAVE_GETPARX 861 #ifdef __m_getparx 862 #define getparx(win) __m_getparx(win) 863 #define getpary(win) __m_getpary(win) 864 #else 865 #define getparx(win) ((win)?((win)->_parx + 1):ERR) 866 #define getpary(win) ((win)?((win)->_pary + 1):ERR) 867 #endif 868 #endif 869 870 #if !defined(mvwvline) && !HAVE_MVWVLINE 871 #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n)) 872 #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n)) 873 #endif 874 875 #if !defined(mvvline) && !HAVE_MVVLINE 876 #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n)) 877 #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n)) 878 #endif 879 880 /* 881 * Try to accommodate curses implementations that have no terminfo support. 882 */ 883 #if HAVE_TIGETNUM 884 #define TIGETNUM(ti,tc) tigetnum(ti) 885 #else 886 #define TIGETNUM(ti,tc) tgetnum(tc) 887 #endif 888 889 #if HAVE_TIGETSTR 890 #define TIGETSTR(ti,tc) tigetstr(ti) 891 #else 892 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer) 893 #endif 894 895 /* 896 * So far (2013 - more than ten years), only ncurses implements 897 * use_extended_names(). 898 */ 899 #if defined(NCURSES_XNAMES) 900 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H 901 #define NCURSES_XNAMES 1 902 #else 903 #define NCURSES_XNAMES 0 904 #endif 905 906 /* 907 * ncurses restores the cursor in endwin(). Other libraries may not. 908 */ 909 #ifdef NCURSES_VERSION 910 #define stop_curses() endwin() 911 #else 912 #define stop_curses() do { endwin(); curs_set(1); } while (0) 913 #endif 914 915 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list 916 * (which is incompatible with legacy usage, doesn't solve any problems). 917 */ 918 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0) 919 #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0) 920 921 #define UChar(c) ((unsigned char)(c)) 922 923 #define SIZEOF(table) (sizeof(table)/sizeof(table[0])) 924 925 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H 926 #include <nc_alloc.h> 927 #if HAVE_EXIT_TERMINFO && (defined(USE_TERMINFO) || defined(USE_TINFO)) 928 #undef ExitProgram 929 #define ExitProgram(code) exit_terminfo(code) 930 #elif HAVE_EXIT_CURSES 931 #undef ExitProgram 932 #define ExitProgram(code) exit_curses(code) 933 #endif 934 #else /* not ncurses-tree */ 935 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type)) 936 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type)) 937 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type)) 938 #endif 939 940 #ifndef ExitProgram 941 #define ExitProgram(code) exit(code) 942 #endif 943 944 #ifndef EXIT_SUCCESS 945 #define EXIT_SUCCESS 0 946 #endif 947 #ifndef EXIT_FAILURE 948 #define EXIT_FAILURE 1 949 #endif 950 951 #undef _NC_WINDOWS 952 #if (defined(_WIN32) || defined(_WIN64)) 953 #define _NC_WINDOWS 1 954 #endif 955 956 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER) 957 958 #if defined(PDCURSES) 959 #ifdef WINVER 960 # if WINVER < 0x0501 961 # error WINVER must at least be 0x0501 962 # endif 963 #else 964 # define WINVER 0x0501 965 #endif 966 #include <windows.h> 967 #include <sys/time.h> /* for struct timeval */ 968 #undef sleep 969 #define sleep(n) Sleep((n) * 1000) 970 #define SIGHUP 1 971 #define SIGKILL 9 972 #define getlogin() "username" 973 974 #elif defined(EXP_WIN32_DRIVER) 975 976 #if defined(HAVE_NCURSESW_NCURSES_H) 977 #include <ncursesw/nc_win32.h> 978 #elif defined(HAVE_NCURSES_NCURSES_H) 979 #include <ncurses/nc_win32.h> 980 #else 981 #include <nc_win32.h> 982 #endif 983 984 #else 985 986 #if defined(HAVE_NCURSESW_NCURSES_H) 987 #include <ncursesw/nc_mingw.h> 988 #elif defined(HAVE_NCURSES_NCURSES_H) 989 #include <ncurses/nc_mingw.h> 990 #else 991 #include <nc_mingw.h> 992 #endif 993 994 #endif 995 996 /* conflicts in test/firstlast.c */ 997 #undef large 998 #undef small 999 1000 #endif 1001 1002 #ifdef NEED_TIME_H 1003 #if TIME_WITH_SYS_TIME 1004 # include <sys/time.h> 1005 # include <time.h> 1006 #else 1007 # if HAVE_SYS_TIME_H 1008 # include <sys/time.h> 1009 # else 1010 # include <time.h> 1011 # endif 1012 #endif 1013 #endif 1014 1015 /* 1016 * Ultrix 3.1 1017 */ 1018 #ifndef STDOUT_FILENO 1019 #define STDOUT_FILENO 1 1020 #endif 1021 1022 #if !HAVE_STRSTR 1023 extern char *_nc_strstr(const char *, const char *); 1024 #define strstr(a,b) _nc_strstr((a),(b)) 1025 #endif /* !HAVE_STRSTR */ 1026 1027 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4 1028 * curses which doesn't have const parameters declared (so far) in the places 1029 * that XSI shows. 1030 */ 1031 #ifndef NCURSES_CONST 1032 #ifdef PDCURSES 1033 #define NCURSES_CONST const /* close enough */ 1034 #else 1035 #define NCURSES_CONST /* nothing */ 1036 #endif 1037 #endif 1038 1039 /* out-of-band values for representing absent capabilities */ 1040 #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */ 1041 #define ABSENT_NUMERIC (-1) 1042 #define ABSENT_STRING (char *)0 1043 1044 /* out-of-band values for representing cancels */ 1045 #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */ 1046 #define CANCELLED_NUMERIC (-2) 1047 #define CANCELLED_STRING (char *)(-1) 1048 1049 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */ 1050 #define VALID_NUMERIC(s) ((s) >= 0) 1051 #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING) 1052 1053 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~" 1054 1055 #define CATCHALL(handler) do { \ 1056 int nsig; \ 1057 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \ 1058 if (nsig != SIGKILL) \ 1059 signal(nsig, handler); \ 1060 } while(0) 1061 1062 #ifdef NCURSES_VERSION 1063 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0) 1064 #else 1065 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0) 1066 #endif 1067 1068 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER) 1069 #define SetupAlarm(opt) (void)opt 1070 #else 1071 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt) 1072 #endif 1073 1074 /* 1075 * Workaround for clean(er) compile with Solaris's legacy curses. 1076 * The same would be needed for HPUX 10.20 1077 */ 1078 #ifndef TPUTS_ARG 1079 #define TPUTS_ARG int 1080 #endif 1081 1082 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH) 1083 #undef TPUTS_ARG 1084 #define TPUTS_ARG char 1085 extern char *tgoto(char *, int, int); /* available, but not prototyped */ 1086 #endif 1087 1088 #ifndef TPUTS_PROTO 1089 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value) 1090 #endif 1091 1092 #ifndef TPUTS_RETURN 1093 #define TPUTS_RETURN(value) return value 1094 #endif 1095 1096 /* 1097 * Workarounds for Solaris's X/Open curses 1098 */ 1099 #if !defined(KEY_MIN) && defined(__KEY_MIN) 1100 #define KEY_MIN __KEY_MIN 1101 #endif 1102 #if !defined(KEY_MAX) && defined(__KEY_MIN) 1103 #define KEY_MAX __KEY_MAX 1104 #endif 1105 1106 /* 1107 * Workaround to build with Sun's default SVr4 curses. 1108 */ 1109 #ifdef NCURSES_VERSION 1110 #ifndef HAVE_VW_PRINTW 1111 #define HAVE_VW_PRINTW 1 1112 #endif 1113 #endif 1114 1115 /* 1116 * ncurses provides arrays of capability names; X/Open discarded these SVr4 1117 * features. Some implementations continue to provide them (see the test 1118 * configure script). 1119 */ 1120 #ifdef NCURSES_VERSION 1121 #ifndef HAVE_CURSES_DATA_BOOLNAMES 1122 #define HAVE_CURSES_DATA_BOOLNAMES 1 1123 #endif 1124 #endif 1125 1126 /* 1127 * ncurses provides a termcap interface; a few packagers replace or displace 1128 * its header file with an incompatible one. The demo_termcap program uses 1129 * the ncurses file, if available. 1130 */ 1131 #ifdef NCURSES_VERSION 1132 #ifndef HAVE_NCURSES_TERMCAP_H 1133 #define HAVE_NCURSES_TERMCAP_H 0 1134 #endif 1135 #ifndef HAVE_TERMCAP_H 1136 #define HAVE_TERMCAP_H 0 1137 #endif 1138 #endif 1139 1140 /* 1141 * ncurses uses const in some places where X/Open does (or did) not allow. 1142 */ 1143 #if defined(NCURSES_CONST) 1144 #define CONST_MENUS NCURSES_CONST 1145 #elif defined(PDCURSES) 1146 #define CONST_MENUS const 1147 #else 1148 #define CONST_MENUS /* nothing */ 1149 #endif 1150 1151 /* 1152 * Simplify setting up demo of threading with these macros. 1153 */ 1154 1155 #if HAVE_USE_WINDOW 1156 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w) 1157 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL) 1158 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data) 1159 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void) 1160 #else 1161 #define USING_WINDOW(w,func) func(w, NULL) 1162 #define USING_WINDOW1(w,func,safe) func(w) 1163 #define USING_WINDOW2(w,func,data) func(w,data) 1164 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void) 1165 #endif 1166 1167 #if HAVE_USE_WINDOW 1168 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data) 1169 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void) 1170 #else 1171 #define USING_SCREEN(s,func,data) func(data) 1172 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void) 1173 #endif 1174 1175 #if defined(TRACE) && HAVE__TRACEF 1176 #define Trace(p) _tracef p 1177 #define USE_TRACE 1 1178 #define START_TRACE() \ 1179 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \ 1180 int t = _nc_getenv_num("NCURSES_TRACE"); \ 1181 if (t >= 0) \ 1182 curses_trace((unsigned) t); \ 1183 } 1184 extern unsigned _nc_tracing; 1185 extern int _nc_getenv_num(const char *); 1186 #else 1187 #undef TRACE 1188 #define Trace(p) /* nothing */ 1189 #define USE_TRACE 0 1190 #define START_TRACE() /* nothing */ 1191 #endif 1192 1193 #define Trace2(p) /* nothing */ 1194 1195 #define AddCh(c) (void) addch((chtype)(c)) 1196 #define WAddCh(w,c) (void) waddch((w),(chtype)(c)) 1197 #define MvAddCh(y,x,c) (void) mvaddch((y),(x),(chtype)(c)) 1198 #define MvWAddCh(w,y,x,c) (void) mvwaddch((w),(y),(x),(chtype)(c)) 1199 #define MvAddStr(y,x,s) (void) mvaddstr((y),(x),(s)) 1200 #define MvWAddStr(w,y,x,s) (void) mvwaddstr((w),(y),(x),(s)) 1201 #define MvWAddChStr(w,y,x,s) (void) mvwaddchstr((w),(y),(x),(s)) 1202 #define MvPrintw (void) mvprintw 1203 #define MvWPrintw (void) mvwprintw 1204 #define MvHLine (void) mvhline 1205 #define MvWHLine (void) mvwhline 1206 #define MvVLine (void) mvvline 1207 #define MvWVLine (void) mvwvline 1208 1209 /* 1210 * The macro likely uses unsigned values, while X/Open prototype uses int. 1211 */ 1212 #if defined(wattrset) || defined(PDCURSES) 1213 #define AttrArg(p,a) (chtype) ((chtype)(p) | (chtype)(a)) 1214 #else 1215 #define AttrArg(p,a) (int) ((chtype)(p) | (chtype)(a)) 1216 #endif 1217 1218 /* 1219 * Workaround for defective implementation of gcc attribute warn_unused_result 1220 */ 1221 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE) 1222 #define IGNORE_RC(func) errno = func 1223 #else 1224 #define IGNORE_RC(func) (void) func 1225 #endif /* gcc workarounds */ 1226 1227 #define init_mb(state) memset(&state, 0, sizeof(state)) 1228 1229 #endif /* __TEST_PRIV_H */ 1230