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