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