]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 6.0 - patch 20170624
[ncurses.git] / test / test.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2016,2017 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.145 2017/06/24 14:07:38 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 #define HAVE_LIBFORM 1
46 #endif
47
48 #ifdef  HAVE_LIBMENUW
49 #define HAVE_LIBMENUW 1
50 #define HAVE_LIBMENU 1
51 #endif
52
53 #ifdef  HAVE_LIBPANELW
54 #define HAVE_LIBPANELW 1
55 #define HAVE_LIBPANEL 1
56 #endif
57
58 /*
59  * Fallback definitions to accommodate broken compilers.
60  */
61 #ifndef HAVE_ALLOC_PAIR
62 #define HAVE_ALLOC_PAIR 0
63 #endif
64
65 #ifndef HAVE_ASSUME_DEFAULT_COLORS
66 #define HAVE_ASSUME_DEFAULT_COLORS 0
67 #endif
68
69 #ifndef HAVE_BSD_STRING_H
70 #define HAVE_BSD_STRING_H 0
71 #endif
72 #ifndef HAVE_CURSES_VERSION
73 #define HAVE_CURSES_VERSION 0
74 #endif
75
76 #ifndef HAVE_CHGAT
77 #define HAVE_CHGAT 0
78 #endif
79
80 #ifndef HAVE_COLOR_SET
81 #define HAVE_COLOR_SET 0
82 #endif
83
84 #ifndef HAVE_FILTER
85 #define HAVE_FILTER 0
86 #endif
87
88 #ifndef HAVE_FORM_H
89 #define HAVE_FORM_H 0
90 #endif
91
92 #ifndef HAVE_GETBEGX
93 #define HAVE_GETBEGX 0
94 #endif
95
96 #ifndef HAVE_GETCURX
97 #define HAVE_GETCURX 0
98 #endif
99
100 #ifndef HAVE_GETMAXX
101 #define HAVE_GETMAXX 0
102 #endif
103
104 #ifndef HAVE_GETOPT_H
105 #define HAVE_GETOPT_H 0
106 #endif
107
108 #ifndef HAVE_GETPARX
109 #define HAVE_GETPARX 0
110 #endif
111
112 #ifndef HAVE_GETWIN
113 #define HAVE_GETWIN 0
114 #endif
115
116 #ifndef HAVE_INIT_EXTENDED_COLOR
117 #define HAVE_INIT_EXTENDED_COLOR 0
118 #endif
119
120 #ifndef HAVE_LIBFORM
121 #define HAVE_LIBFORM 0
122 #endif
123
124 #ifndef HAVE_LIBMENU
125 #define HAVE_LIBMENU 0
126 #endif
127
128 #ifndef HAVE_LIBPANEL
129 #define HAVE_LIBPANEL 0
130 #endif
131
132 #ifndef HAVE_LANGINFO_CODESET
133 #define HAVE_LANGINFO_CODESET 0
134 #endif
135
136 #ifndef HAVE_LOCALE_H
137 #define HAVE_LOCALE_H 0
138 #endif
139
140 #ifndef HAVE_MATH_H
141 #define HAVE_MATH_H 0
142 #endif
143
144 #ifndef HAVE_MENU_H
145 #define HAVE_MENU_H 0
146 #endif
147
148 #ifndef HAVE_MVVLINE
149 #define HAVE_MVVLINE 0
150 #endif
151
152 #ifndef HAVE_MVWVLINE
153 #define HAVE_MVWVLINE 0
154 #endif
155
156 #ifndef HAVE_NAPMS
157 #define HAVE_NAPMS 1
158 #endif
159
160 #ifndef HAVE_NC_ALLOC_H
161 #define HAVE_NC_ALLOC_H 0
162 #endif
163
164 #ifndef HAVE_PANEL_H
165 #define HAVE_PANEL_H 0
166 #endif
167
168 #ifndef HAVE_PUTWIN
169 #define HAVE_PUTWIN 0
170 #endif
171
172 #ifndef HAVE_RESIZE_TERM
173 #define HAVE_RESIZE_TERM 0
174 #endif
175
176 #ifndef HAVE_RESTARTTERM
177 #define HAVE_RESTARTTERM 0
178 #endif
179
180 #ifndef HAVE_RIPOFFLINE
181 #define HAVE_RIPOFFLINE 0
182 #endif
183
184 #ifndef HAVE_SCR_DUMP
185 #define HAVE_SCR_DUMP 0
186 #endif
187
188 #ifndef HAVE_SETUPTERM
189 #define HAVE_SETUPTERM 0
190 #endif
191
192 #ifndef HAVE_SLK_COLOR
193 #define HAVE_SLK_COLOR 0
194 #endif
195
196 #ifndef HAVE_SLK_INIT
197 #define HAVE_SLK_INIT 0
198 #endif
199
200 #ifndef HAVE_SYS_IOCTL_H
201 #define HAVE_SYS_IOCTL_H 0
202 #endif
203
204 #ifndef HAVE_SYS_SELECT_H
205 #define HAVE_SYS_SELECT_H 0
206 #endif
207
208 #ifndef HAVE_TERMATTRS
209 #define HAVE_TERMATTRS 0
210 #endif
211
212 #ifndef HAVE_TERMIOS_H
213 #define HAVE_TERMIOS_H 0
214 #endif
215
216 #ifndef HAVE_TERMNAME
217 #define HAVE_TERMNAME 0
218 #endif
219
220 #ifndef HAVE_TERM_ENTRY_H
221 #define HAVE_TERM_ENTRY_H 0
222 #endif
223
224 #ifndef HAVE_TGETENT
225 #define HAVE_TGETENT 0
226 #endif
227
228 #ifndef HAVE_TIGETNUM
229 #define HAVE_TIGETNUM 0
230 #endif
231
232 #ifndef HAVE_TIGETSTR
233 #define HAVE_TIGETSTR 0
234 #endif
235
236 #ifndef HAVE_TPUTS_SP
237 #define HAVE_TPUTS_SP 0
238 #endif
239
240 #ifndef HAVE_TYPEAHEAD
241 #define HAVE_TYPEAHEAD 0
242 #endif
243
244 #ifndef HAVE_WINSSTR
245 #define HAVE_WINSSTR 0
246 #endif
247
248 #ifndef HAVE_USE_DEFAULT_COLORS
249 #define HAVE_USE_DEFAULT_COLORS 0
250 #endif
251
252 #ifndef HAVE_USE_ENV
253 #define HAVE_USE_ENV 0
254 #endif
255
256 #ifndef HAVE_USE_EXTENDED_NAMES
257 #define HAVE_USE_EXTENDED_NAMES 0
258 #endif
259
260 #ifndef HAVE_USE_SCREEN
261 #define HAVE_USE_SCREEN 0
262 #endif
263
264 #ifndef HAVE_USE_WINDOW
265 #define HAVE_USE_WINDOW 0
266 #endif
267
268 #ifndef HAVE_VIDPUTS
269 #define HAVE_VIDPUTS 0
270 #endif
271
272 #ifndef HAVE_VID_PUTS
273 #define HAVE_VID_PUTS 0
274 #endif
275
276 #ifndef HAVE_WRESIZE
277 #define HAVE_WRESIZE 0
278 #endif
279
280 #ifndef HAVE__TRACEF
281 #define HAVE__TRACEF 0
282 #endif
283
284 #ifndef NCURSES_EXT_FUNCS
285 #define NCURSES_EXT_FUNCS 0
286 #endif
287
288 #ifndef NEED_PTEM_H
289 #define NEED_PTEM_H 0
290 #endif
291
292 #ifndef NEED_WCHAR_H
293 #define NEED_WCHAR_H 0
294 #endif
295
296 #ifndef NO_LEAKS
297 #define NO_LEAKS 0
298 #endif
299
300 /*
301  * Workaround for HPUX
302  */
303 #if defined(__hpux) && !defined(NCURSES_VERSION)
304 #define _ACS_COMPAT_CODE        /* needed for acs_map vs __acs_map */
305 #endif
306
307 #include <stdlib.h>
308 #include <stdarg.h>
309 #include <string.h>
310 #include <sys/types.h>
311 #include <errno.h>
312
313 #if HAVE_UNISTD_H
314 #include <unistd.h>
315 #endif
316
317 #include <signal.h>             /* include before curses.h to work around glibc bug */
318
319 #if NEED_WCHAR_H
320 #include <wchar.h>
321 #ifdef HAVE_LIBUTF8_H
322 #include <libutf8.h>
323 #endif
324 #endif
325
326 #if defined(HAVE_XCURSES)
327 #include <xcurses.h>
328 #elif defined(HAVE_NCURSESW_NCURSES_H)
329 #include <ncursesw/curses.h>
330 #elif defined(HAVE_NCURSES_NCURSES_H)
331 #include <ncurses/curses.h>
332 #else
333 #include <curses.h>
334 #endif
335
336 #if defined(HAVE_XCURSES) || defined(PDCURSES)
337 /* no other headers */
338 #undef  HAVE_SETUPTERM          /* nonfunctional */
339 #define HAVE_SETUPTERM 0
340 #undef  HAVE_TGETENT            /* nonfunctional */
341 #define HAVE_TGETENT 0
342 #undef  HAVE_TIGETSTR           /* nonfunctional */
343 #define HAVE_TIGETSTR 0
344 #elif defined(HAVE_NCURSESW_TERM_H)
345 #include <ncursesw/term.h>
346 #elif defined(HAVE_NCURSES_TERM_H)
347 #include <ncurses/term.h>
348 #elif defined(HAVE_TERM_H)
349 #include <term.h>
350 #endif
351
352 /*
353  * Not all curses.h implementations include unctrl.h,
354  */
355 #if defined(HAVE_NCURSESW_UNCTRL_H)
356 #include <ncursesw/unctrl.h>
357 #elif defined(HAVE_NCURSES_UNCTRL_H)
358 #include <ncurses/unctrl.h>
359 #elif defined(HAVE_UNCTRL_H)
360 #include <unctrl.h>
361 #endif
362
363 #if HAVE_GETOPT_H
364 #include <getopt.h>
365 #elif !defined(HAVE_GETOPT_HEADER)
366 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
367  * doesn't hurt.
368  */
369 extern char *optarg;
370 extern int optind;
371 #endif /* HAVE_GETOPT_H */
372
373 #if HAVE_LOCALE_H
374 #include <locale.h>
375 #else
376 #define setlocale(name,string)  /* nothing */
377 #endif
378
379 #include <assert.h>
380 #include <ctype.h>
381
382 #ifndef GCC_NORETURN
383 #define GCC_NORETURN            /* nothing */
384 #endif
385 #ifndef GCC_PRINTFLIKE
386 #define GCC_PRINTFLIKE(a,b)     /* nothing */
387 #endif
388 #ifndef GCC_UNUSED
389 #define GCC_UNUSED              /* nothing */
390 #endif
391
392 #ifndef HAVE_GETNSTR
393 #define getnstr(s,n) getstr(s)
394 #endif
395
396 #ifndef USE_SOFTKEYS
397 #if HAVE_SLK_INIT
398 #define USE_SOFTKEYS 1
399 #else
400 #define USE_SOFTKEYS 0
401 #endif
402 #endif
403
404 #if !USE_SOFTKEYS
405 #define slk_init()              /* nothing */
406 #define slk_restore()           /* nothing */
407 #define slk_clear()             /* nothing */
408 #endif
409
410 #ifndef HAVE_WSYNCDOWN
411 #define wsyncdown(win)          /* nothing */
412 #endif
413
414 #ifndef USE_WIDEC_SUPPORT
415 #if (defined(_XOPEN_SOURCE_EXTENDED) \
416   || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
417   || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
418   && defined(WACS_ULCORNER)
419 #define USE_WIDEC_SUPPORT 1
420 #else
421 #define USE_WIDEC_SUPPORT 0
422 #endif
423 #endif
424
425 #if HAVE_PANEL_H && HAVE_LIBPANEL
426 #define USE_LIBPANEL 1
427 #else
428 #define USE_LIBPANEL 0
429 #endif
430
431 #if HAVE_MENU_H && HAVE_LIBMENU
432 #define USE_LIBMENU 1
433 #else
434 #define USE_LIBMENU 0
435 #endif
436
437 #if HAVE_FORM_H && HAVE_LIBFORM
438 #define USE_LIBFORM 1
439 #else
440 #define USE_LIBFORM 0
441 #endif
442
443 /* workaround, to build against NetBSD's variant of the form library */
444 #ifdef HAVE_NETBSD_FORM_H
445 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
446 #else
447 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
448 #endif
449
450 /* workaround, to build against NetBSD's variant of the form library */
451 #ifdef HAVE_NETBSD_MENU_H
452 #define menu_itemwidth(menu) (menu)->max_item_width
453 #else
454 #define menu_itemwidth(menu) (menu)->itemlen
455 #endif
456
457 #ifndef HAVE_TYPE_ATTR_T
458 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
459 #define attr_t chtype
460 #endif
461 #endif
462
463 #undef NCURSES_CH_T
464 #if !USE_WIDEC_SUPPORT
465 #define NCURSES_CH_T chtype
466 #else
467 #define NCURSES_CH_T cchar_t
468 #endif
469
470 #ifndef NCURSES_COLOR_T
471 #define NCURSES_COLOR_T short
472 #endif
473
474 #ifndef NCURSES_PAIRS_T
475 #define NCURSES_PAIRS_T short
476 #endif
477
478 #ifndef CCHARW_MAX
479 #define CCHARW_MAX 5
480 #endif
481
482 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
483 #define CURSES_WACS_SYMBOLS
484 #endif
485
486 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
487 /* NetBSD 5.1 defines these incorrectly */
488 #undef  WACS_RARROW
489 #undef  WACS_LARROW
490 #undef  WACS_UARROW
491 #undef  WACS_DARROW
492 #undef  WACS_BLOCK
493 #undef  WACS_DIAMOND
494 #undef  WACS_CKBOARD
495 #undef  WACS_DEGREE
496 #undef  WACS_PLMINUS
497 #undef  WACS_BOARD
498 #undef  WACS_LANTERN
499 #undef  WACS_LRCORNER
500 #undef  WACS_URCORNER
501 #undef  WACS_ULCORNER
502 #undef  WACS_LLCORNER
503 #undef  WACS_PLUS
504 #undef  WACS_HLINE
505 #undef  WACS_S1
506 #undef  WACS_S9
507 #undef  WACS_LTEE
508 #undef  WACS_RTEE
509 #undef  WACS_BTEE
510 #undef  WACS_TTEE
511 #undef  WACS_VLINE
512 #undef  WACS_BULLET
513 #undef  WACS_S3
514 #undef  WACS_S7
515 #undef  WACS_LEQUAL
516 #undef  WACS_GEQUAL
517 #undef  WACS_PI
518 #undef  WACS_NEQUAL
519 #undef  WACS_STERLING
520
521 #define WACS_RARROW     &(CURSES_WACS_ARRAY['+'])
522 #define WACS_LARROW     &(CURSES_WACS_ARRAY[','])
523 #define WACS_UARROW     &(CURSES_WACS_ARRAY['-'])
524 #define WACS_DARROW     &(CURSES_WACS_ARRAY['.'])
525 #define WACS_BLOCK      &(CURSES_WACS_ARRAY['0'])
526 #define WACS_DIAMOND    &(CURSES_WACS_ARRAY['`'])
527 #define WACS_CKBOARD    &(CURSES_WACS_ARRAY['a'])
528 #define WACS_DEGREE     &(CURSES_WACS_ARRAY['f'])
529 #define WACS_PLMINUS    &(CURSES_WACS_ARRAY['g'])
530 #define WACS_BOARD      &(CURSES_WACS_ARRAY['h'])
531 #define WACS_LANTERN    &(CURSES_WACS_ARRAY['i'])
532 #define WACS_LRCORNER   &(CURSES_WACS_ARRAY['j'])
533 #define WACS_URCORNER   &(CURSES_WACS_ARRAY['k'])
534 #define WACS_ULCORNER   &(CURSES_WACS_ARRAY['l'])
535 #define WACS_LLCORNER   &(CURSES_WACS_ARRAY['m'])
536 #define WACS_PLUS       &(CURSES_WACS_ARRAY['n'])
537 #define WACS_HLINE      &(CURSES_WACS_ARRAY['q'])
538 #define WACS_S1         &(CURSES_WACS_ARRAY['o'])
539 #define WACS_S9         &(CURSES_WACS_ARRAY['s'])
540 #define WACS_LTEE       &(CURSES_WACS_ARRAY['t'])
541 #define WACS_RTEE       &(CURSES_WACS_ARRAY['u'])
542 #define WACS_BTEE       &(CURSES_WACS_ARRAY['v'])
543 #define WACS_TTEE       &(CURSES_WACS_ARRAY['w'])
544 #define WACS_VLINE      &(CURSES_WACS_ARRAY['x'])
545 #define WACS_BULLET     &(CURSES_WACS_ARRAY['~'])
546 #define WACS_S3         &(CURSES_WACS_ARRAY['p'])
547 #define WACS_S7         &(CURSES_WACS_ARRAY['r'])
548 #define WACS_LEQUAL     &(CURSES_WACS_ARRAY['y'])
549 #define WACS_GEQUAL     &(CURSES_WACS_ARRAY['z'])
550 #define WACS_PI         &(CURSES_WACS_ARRAY['{'])
551 #define WACS_NEQUAL     &(CURSES_WACS_ARRAY['|'])
552 #define WACS_STERLING   &(CURSES_WACS_ARRAY['}'])
553 #endif
554
555 #undef CTRL
556 #define CTRL(x) ((x) & 0x1f)
557
558 #define QUIT            CTRL('Q')
559 #define ESCAPE          CTRL('[')
560
561 #ifndef KEY_MIN
562 #define KEY_MIN 256             /* not defined in Solaris 8 */
563 #endif
564
565 #define HELP_KEY_1      '?'
566 #define HELP_KEY_2      KEY_F(1)
567
568 /* from nc_string.h, to make this stand alone */
569 #if HAVE_BSD_STRING_H
570 #include <bsd/string.h>
571 #endif
572
573 #ifdef __cplusplus
574 #define NCURSES_VOID            /* nothing */
575 #else
576 #define NCURSES_VOID (void)
577 #endif
578
579 #ifndef HAVE_STRLCAT
580 #define HAVE_STRLCAT 0
581 #endif
582
583 #ifndef HAVE_STRLCPY
584 #define HAVE_STRLCPY 0
585 #endif
586
587 #ifndef HAVE_SNPRINTF
588 #define HAVE_SNPRINTF 0
589 #endif
590
591 #ifndef USE_STRING_HACKS
592 #define USE_STRING_HACKS 0
593 #endif
594
595 #if USE_STRING_HACKS && HAVE_STRLCAT
596 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
597 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
598 #else
599 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strcat((d),(s))
600 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strncat((d),(s),(n))
601 #endif
602
603 #if USE_STRING_HACKS && HAVE_STRLCPY
604 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
605 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
606 #else
607 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strcpy((d),(s))
608 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strncpy((d),(s),(n))
609 #endif
610
611 #if USE_STRING_HACKS && HAVE_SNPRINTF
612 #define _nc_SPRINTF             NCURSES_VOID snprintf
613 #define _nc_SLIMIT(n)           NCURSES_CAST(size_t,n),
614 #else
615 #define _nc_SPRINTF             NCURSES_VOID sprintf
616 #define _nc_SLIMIT(n)           /* nothing */
617 #endif
618
619 #ifdef DECL_CURSES_DATA_BOOLNAMES
620 extern char *boolnames[], *boolcodes[], *boolfnames[];
621 extern char *numnames[], *numcodes[], *numfnames[];
622 extern char *strnames[], *strcodes[], *strfnames[];
623 #endif
624
625 #ifdef DECL_CURSES_DATA_TTYTYPE
626 #define ttytype termname()
627 #endif
628
629 #define colored_chtype(ch, attr, pair) \
630         ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
631
632 /*
633  * Workaround for HPUX
634  */
635 #if defined(__hpux) && !defined(NCURSES_VERSION)
636 #define getbegx(w) __getbegx(w)
637 #define getbegy(w) __getbegy(w)
638 #define getcurx(w) __getcurx(w)
639 #define getcury(w) __getcury(w)
640 #define getmaxx(w) __getmaxx(w)
641 #define getmaxy(w) __getmaxy(w)
642 #define getparx(w) __getparx(w)
643 #define getpary(w) __getpary(w)
644 #endif
645
646 /*
647  * Workaround in case getcchar() returns a positive value when the source
648  * string produces only a L'\0'.
649  */
650 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
651         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
652             wchar_t test_wch[CCHARW_MAX + 2]; \
653             attr_t test_attrs; \
654             NCURSES_PAIRS_T test_pair; \
655             \
656             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
657                 && test_wch[0] != L'\0') { \
658                 then_stmt \
659             } else { \
660                 else_stmt \
661             } \
662         } else { \
663             else_stmt \
664         }
665 /*
666  * These usually are implemented as macros, but may be functions.
667  */
668 #if !defined(getcurx) && !HAVE_GETCURX
669 #define getcurx(win)            ((win)?(win)->_curx:ERR)
670 #define getcury(win)            ((win)?(win)->_cury:ERR)
671 #endif
672
673 #if !defined(getbegx) && !HAVE_GETBEGX
674 #define getbegx(win)            ((win)?(win)->_begx:ERR)
675 #define getbegy(win)            ((win)?(win)->_begy:ERR)
676 #endif
677
678 #if !defined(getmaxx) && !HAVE_GETMAXX
679 #define getmaxx(win)            ((win)?((win)->_maxx + 1):ERR)
680 #define getmaxy(win)            ((win)?((win)->_maxy + 1):ERR)
681 #endif
682
683 /*
684  * Solaris 10 xpg4:
685 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
686                                 : (w)->_begx - (w)->_parent->_begx)
687  */
688 #if !defined(getparx) && !HAVE_GETPARX
689 #ifdef __m_getparx
690 #define getparx(win)            __m_getparx(win)
691 #define getpary(win)            __m_getpary(win)
692 #else
693 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
694 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
695 #endif
696 #endif
697
698 #if !defined(mvwvline) && !HAVE_MVWVLINE
699 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
700 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
701 #endif
702
703 #if !defined(mvvline) && !HAVE_MVVLINE
704 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
705 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
706 #endif
707
708 /*
709  * Try to accommodate curses implementations that have no terminfo support.
710  */
711 #if HAVE_TIGETNUM
712 #define TIGETNUM(ti,tc) tigetnum(ti)
713 #else
714 #define TIGETNUM(ti,tc) tgetnum(tc)
715 #endif
716
717 #if HAVE_TIGETSTR
718 #define TIGETSTR(ti,tc) tigetstr(ti)
719 #else
720 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
721 #endif
722
723 /*
724  * So far (2013 - more than ten years), only ncurses implements
725  * use_extended_names().
726  */
727 #if defined(NCURSES_XNAMES)
728 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
729 #define NCURSES_XNAMES 1
730 #else
731 #define NCURSES_XNAMES 0
732 #endif
733
734 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
735  * (which is incompatible with legacy usage, doesn't solve any problems).
736  */
737 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
738 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
739
740 #define UChar(c)    ((unsigned char)(c))
741
742 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
743
744 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
745 #include <nc_alloc.h>
746 #if HAVE_NC_FREEALL && defined(USE_TINFO)
747 #undef ExitProgram
748 #define ExitProgram(code) _nc_free_tinfo(code)
749 #endif
750 #else
751 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
752 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
753 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
754 #endif
755
756 #ifndef ExitProgram
757 #define ExitProgram(code) exit(code)
758 #endif
759
760 #ifndef EXIT_SUCCESS
761 #define EXIT_SUCCESS 0
762 #endif
763 #ifndef EXIT_FAILURE
764 #define EXIT_FAILURE 1
765 #endif
766
767 #if defined(__MINGW32__) || defined(USE_WIN32CON_DRIVER)
768
769 #if defined(PDCURSES)
770 #ifdef WINVER
771 #  if WINVER < 0x0501
772 #    error WINVER must at least be 0x0501
773 #  endif
774 #else
775 #  define WINVER 0x0501
776 #endif
777 #include <windows.h>
778 #include <sys/time.h>           /* for struct timeval */
779 #undef sleep
780 #define sleep(n) Sleep((n) * 1000)
781 #define SIGHUP  1
782 #define SIGKILL 9
783 #define getlogin() "username"
784
785 #elif defined(HAVE_NCURSESW_NCURSES_H)
786 #include <ncursesw/nc_mingw.h>
787 #elif defined(HAVE_NCURSES_NCURSES_H)
788 #include <ncurses/nc_mingw.h>
789 #else
790 #include <nc_mingw.h>
791 #endif
792
793 /* conflicts in test/firstlast.c */
794 #undef large
795 #undef small
796
797 #endif
798
799 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
800  * curses which doesn't have const parameters declared (so far) in the places
801  * that XSI shows.
802  */
803 #ifndef NCURSES_CONST
804 #define NCURSES_CONST           /* nothing */
805 #endif
806
807 /* out-of-band values for representing absent capabilities */
808 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
809 #define ABSENT_NUMERIC          (-1)
810 #define ABSENT_STRING           (char *)0
811
812 /* out-of-band values for representing cancels */
813 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
814 #define CANCELLED_NUMERIC       (-2)
815 #define CANCELLED_STRING        (char *)(-1)
816
817 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)      /* reject "-1" */
818 #define VALID_NUMERIC(s) ((s) >= 0)
819 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
820
821 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
822
823 #define CATCHALL(handler) { \
824                 int nsig; \
825                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
826                     if (nsig != SIGKILL) \
827                         signal(nsig, handler); \
828             }
829
830 /*
831  * Workaround for clean(er) compile with Solaris's legacy curses.
832  * The same would be needed for HPUX 10.20
833  */
834 #ifndef TPUTS_ARG
835 #define TPUTS_ARG int
836 #endif
837
838 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
839 #undef TPUTS_ARG
840 #define TPUTS_ARG char
841 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
842 #endif
843
844 #ifndef TPUTS_PROTO
845 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
846 #endif
847
848 #ifndef TPUTS_RETURN
849 #define TPUTS_RETURN(value) return value
850 #endif
851
852 /*
853  * Workarounds for Solaris's X/Open curses
854  */
855 #if !defined(KEY_MIN) && defined(__KEY_MIN)
856 #define KEY_MIN __KEY_MIN
857 #endif
858 #if !defined(KEY_MAX) && defined(__KEY_MIN)
859 #define KEY_MAX __KEY_MAX
860 #endif
861
862 /*
863  * Workaround to build with Sun's default SVr4 curses.
864  */
865 #ifdef NCURSES_VERSION
866 #ifndef HAVE_VW_PRINTW
867 #define HAVE_VW_PRINTW 1
868 #endif
869 #endif
870
871 /*
872  * ncurses provides arrays of capability names; X/Open discarded these SVr4
873  * features.  Some implementations continue to provide them (see the test
874  * configure script).
875  */
876 #ifdef NCURSES_VERSION
877 #ifndef HAVE_CURSES_DATA_BOOLNAMES
878 #define HAVE_CURSES_DATA_BOOLNAMES 1
879 #endif
880 #endif
881
882 /*
883  * ncurses uses const in some places where X/Open does (or did) not allow.
884  */
885 #ifdef NCURSES_VERSION
886 #define CONST_MENUS const
887 #else
888 #define CONST_MENUS             /* nothing */
889 #endif
890
891 /*
892  * Simplify setting up demo of threading with these macros.
893  */
894
895 #if HAVE_USE_WINDOW
896 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
897 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
898 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
899 #else
900 #define USING_WINDOW(w,func) func(w)
901 #define USING_WINDOW2(w,func,data) func(w,data)
902 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
903 #endif
904
905 #if HAVE_USE_WINDOW
906 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
907 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
908 #else
909 #define USING_SCREEN(s,func,data) func(data)
910 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
911 #endif
912
913 #if defined(TRACE) && HAVE__TRACEF
914 #define Trace(p) _tracef p
915 #define USE_TRACE 1
916 #define START_TRACE() \
917         if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
918             int t = _nc_getenv_num("NCURSES_TRACE"); \
919             if (t >= 0) \
920                 trace((unsigned) t); \
921         }
922 extern unsigned _nc_tracing;
923 extern int _nc_getenv_num(const char *);
924 #else
925 #undef TRACE
926 #define Trace(p)                /* nothing */
927 #define USE_TRACE 0
928 #define START_TRACE()           /* nothing */
929 #endif
930
931 #define Trace2(p)               /* nothing */
932
933 #define AddCh(c)                (void) addch((chtype)(c))
934 #define WAddCh(w,c)             (void) waddch((w),(chtype)(c))
935 #define MvAddCh(y,x,c)          (void) mvaddch((y),(x),(chtype)(c))
936 #define MvWAddCh(w,y,x,c)       (void) mvwaddch((w),(y),(x),(chtype)(c))
937 #define MvAddStr(y,x,s)         (void) mvaddstr((y),(x),(s))
938 #define MvWAddStr(w,y,x,s)      (void) mvwaddstr((w),(y),(x),(s))
939 #define MvWAddChStr(w,y,x,s)    (void) mvwaddchstr((w),(y),(x),(s))
940 #define MvPrintw                (void) mvprintw
941 #define MvWPrintw               (void) mvwprintw
942 #define MvHLine                 (void) mvhline
943 #define MvWHLine                (void) mvwhline
944 #define MvVLine                 (void) mvvline
945 #define MvWVLine                (void) mvwvline
946
947 /*
948  * The macro likely uses unsigned values, while X/Open prototype uses int.
949  */
950 #if defined(wattrset) || defined(PDCURSES)
951 #define AttrArg(p,a)    (attr_t) ((attr_t)(p) | (attr_t)(a))
952 #else
953 #define AttrArg(p,a)    (int) ((attr_t)(p) | (attr_t)(a))
954 #endif
955
956 /*
957  * Workaround for defective implementation of gcc attribute warn_unused_result
958  */
959 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
960 #define IGNORE_RC(func) errno = func
961 #else
962 #define IGNORE_RC(func) (void) func
963 #endif /* gcc workarounds */
964
965 #define init_mb(state)  memset(&state, 0, sizeof(state))
966
967 #endif /* __TEST_PRIV_H */