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