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