]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 6.0 - patch 20161008
[ncurses.git] / test / test.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2014,2016 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.138 2016/09/10 23:42:33 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_ASSUME_DEFAULT_COLORS
62 #define HAVE_ASSUME_DEFAULT_COLORS 0
63 #endif
64
65 #ifndef HAVE_BSD_STRING_H
66 #define HAVE_BSD_STRING_H 0
67 #endif
68 #ifndef HAVE_CURSES_VERSION
69 #define HAVE_CURSES_VERSION 0
70 #endif
71
72 #ifndef HAVE_CHGAT
73 #define HAVE_CHGAT 0
74 #endif
75
76 #ifndef HAVE_COLOR_SET
77 #define HAVE_COLOR_SET 0
78 #endif
79
80 #ifndef HAVE_FILTER
81 #define HAVE_FILTER 0
82 #endif
83
84 #ifndef HAVE_FORM_H
85 #define HAVE_FORM_H 0
86 #endif
87
88 #ifndef HAVE_GETBEGX
89 #define HAVE_GETBEGX 0
90 #endif
91
92 #ifndef HAVE_GETCURX
93 #define HAVE_GETCURX 0
94 #endif
95
96 #ifndef HAVE_GETMAXX
97 #define HAVE_GETMAXX 0
98 #endif
99
100 #ifndef HAVE_GETOPT_H
101 #define HAVE_GETOPT_H 0
102 #endif
103
104 #ifndef HAVE_GETPARX
105 #define HAVE_GETPARX 0
106 #endif
107
108 #ifndef HAVE_GETWIN
109 #define HAVE_GETWIN 0
110 #endif
111
112 #ifndef HAVE_LIBFORM
113 #define HAVE_LIBFORM 0
114 #endif
115
116 #ifndef HAVE_LIBMENU
117 #define HAVE_LIBMENU 0
118 #endif
119
120 #ifndef HAVE_LIBPANEL
121 #define HAVE_LIBPANEL 0
122 #endif
123
124 #ifndef HAVE_LANGINFO_CODESET
125 #define HAVE_LANGINFO_CODESET 0
126 #endif
127
128 #ifndef HAVE_LOCALE_H
129 #define HAVE_LOCALE_H 0
130 #endif
131
132 #ifndef HAVE_MATH_H
133 #define HAVE_MATH_H 0
134 #endif
135
136 #ifndef HAVE_MENU_H
137 #define HAVE_MENU_H 0
138 #endif
139
140 #ifndef HAVE_MVVLINE
141 #define HAVE_MVVLINE 0
142 #endif
143
144 #ifndef HAVE_MVWVLINE
145 #define HAVE_MVWVLINE 0
146 #endif
147
148 #ifndef HAVE_NAPMS
149 #define HAVE_NAPMS 1
150 #endif
151
152 #ifndef HAVE_NC_ALLOC_H
153 #define HAVE_NC_ALLOC_H 0
154 #endif
155
156 #ifndef HAVE_PANEL_H
157 #define HAVE_PANEL_H 0
158 #endif
159
160 #ifndef HAVE_PUTWIN
161 #define HAVE_PUTWIN 0
162 #endif
163
164 #ifndef HAVE_RESIZE_TERM
165 #define HAVE_RESIZE_TERM 0
166 #endif
167
168 #ifndef HAVE_RESTARTTERM
169 #define HAVE_RESTARTTERM 0
170 #endif
171
172 #ifndef HAVE_RIPOFFLINE
173 #define HAVE_RIPOFFLINE 0
174 #endif
175
176 #ifndef HAVE_SCR_DUMP
177 #define HAVE_SCR_DUMP 0
178 #endif
179
180 #ifndef HAVE_SETUPTERM
181 #define HAVE_SETUPTERM 0
182 #endif
183
184 #ifndef HAVE_SLK_COLOR
185 #define HAVE_SLK_COLOR 0
186 #endif
187
188 #ifndef HAVE_SLK_INIT
189 #define HAVE_SLK_INIT 0
190 #endif
191
192 #ifndef HAVE_SYS_IOCTL_H
193 #define HAVE_SYS_IOCTL_H 0
194 #endif
195
196 #ifndef HAVE_SYS_SELECT_H
197 #define HAVE_SYS_SELECT_H 0
198 #endif
199
200 #ifndef HAVE_TERMATTRS
201 #define HAVE_TERMATTRS 0
202 #endif
203
204 #ifndef HAVE_TERMIOS_H
205 #define HAVE_TERMIOS_H 0
206 #endif
207
208 #ifndef HAVE_TERMNAME
209 #define HAVE_TERMNAME 0
210 #endif
211
212 #ifndef HAVE_TERM_ENTRY_H
213 #define HAVE_TERM_ENTRY_H 0
214 #endif
215
216 #ifndef HAVE_TGETENT
217 #define HAVE_TGETENT 0
218 #endif
219
220 #ifndef HAVE_TIGETNUM
221 #define HAVE_TIGETNUM 0
222 #endif
223
224 #ifndef HAVE_TIGETSTR
225 #define HAVE_TIGETSTR 0
226 #endif
227
228 #ifndef HAVE_TYPEAHEAD
229 #define HAVE_TYPEAHEAD 0
230 #endif
231
232 #ifndef HAVE_WINSSTR
233 #define HAVE_WINSSTR 0
234 #endif
235
236 #ifndef HAVE_USE_DEFAULT_COLORS
237 #define HAVE_USE_DEFAULT_COLORS 0
238 #endif
239
240 #ifndef HAVE_USE_ENV
241 #define HAVE_USE_ENV 0
242 #endif
243
244 #ifndef HAVE_USE_EXTENDED_NAMES
245 #define HAVE_USE_EXTENDED_NAMES 0
246 #endif
247
248 #ifndef HAVE_USE_SCREEN
249 #define HAVE_USE_SCREEN 0
250 #endif
251
252 #ifndef HAVE_USE_WINDOW
253 #define HAVE_USE_WINDOW 0
254 #endif
255
256 #ifndef HAVE_VIDPUTS
257 #define HAVE_VIDPUTS 0
258 #endif
259
260 #ifndef HAVE_VID_PUTS
261 #define HAVE_VID_PUTS 0
262 #endif
263
264 #ifndef HAVE_WRESIZE
265 #define HAVE_WRESIZE 0
266 #endif
267
268 #ifndef NCURSES_EXT_FUNCS
269 #define NCURSES_EXT_FUNCS 0
270 #endif
271
272 #ifndef NEED_PTEM_H
273 #define NEED_PTEM_H 0
274 #endif
275
276 #ifndef NEED_WCHAR_H
277 #define NEED_WCHAR_H 0
278 #endif
279
280 #ifndef NO_LEAKS
281 #define NO_LEAKS 0
282 #endif
283
284 /*
285  * Workaround for HPUX
286  */
287 #if defined(__hpux) && !defined(NCURSES_VERSION)
288 #define _ACS_COMPAT_CODE        /* needed for acs_map vs __acs_map */
289 #endif
290
291 #include <stdlib.h>
292 #include <stdarg.h>
293 #include <string.h>
294 #include <sys/types.h>
295 #include <errno.h>
296
297 #if HAVE_UNISTD_H
298 #include <unistd.h>
299 #endif
300
301 #include <signal.h>             /* include before curses.h to work around glibc bug */
302
303 #if NEED_WCHAR_H
304 #include <wchar.h>
305 #ifdef HAVE_LIBUTF8_H
306 #include <libutf8.h>
307 #endif
308 #endif
309
310 #if defined(HAVE_XCURSES)
311 #include <xcurses.h>
312 #elif defined(HAVE_NCURSESW_NCURSES_H)
313 #include <ncursesw/curses.h>
314 #elif defined(HAVE_NCURSES_NCURSES_H)
315 #include <ncurses/curses.h>
316 #else
317 #include <curses.h>
318 #endif
319
320 #if defined(HAVE_XCURSES) || defined(PDCURSES)
321 /* no other headers */
322 #undef  HAVE_SETUPTERM          /* nonfunctional */
323 #define HAVE_SETUPTERM 0
324 #undef  HAVE_TGETENT            /* nonfunctional */
325 #define HAVE_TGETENT 0
326 #undef  HAVE_TIGETSTR           /* nonfunctional */
327 #define HAVE_TIGETSTR 0
328 #elif defined(HAVE_NCURSESW_TERM_H)
329 #include <ncursesw/term.h>
330 #elif defined(HAVE_NCURSES_TERM_H)
331 #include <ncurses/term.h>
332 #elif defined(HAVE_TERM_H)
333 #include <term.h>
334 #endif
335
336 /*
337  * Not all curses.h implementations include unctrl.h,
338  */
339 #if defined(HAVE_NCURSESW_UNCTRL_H)
340 #include <ncursesw/unctrl.h>
341 #elif defined(HAVE_NCURSES_UNCTRL_H)
342 #include <ncurses/unctrl.h>
343 #elif defined(HAVE_UNCTRL_H)
344 #include <unctrl.h>
345 #endif
346
347 #if HAVE_GETOPT_H
348 #include <getopt.h>
349 #elif !defined(HAVE_GETOPT_HEADER)
350 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
351  * doesn't hurt.
352  */
353 extern char *optarg;
354 extern int optind;
355 #endif /* HAVE_GETOPT_H */
356
357 #if HAVE_LOCALE_H
358 #include <locale.h>
359 #else
360 #define setlocale(name,string)  /* nothing */
361 #endif
362
363 #include <assert.h>
364 #include <ctype.h>
365
366 #ifndef GCC_NORETURN
367 #define GCC_NORETURN            /* nothing */
368 #endif
369 #ifndef GCC_PRINTFLIKE
370 #define GCC_PRINTFLIKE(a,b)     /* nothing */
371 #endif
372 #ifndef GCC_UNUSED
373 #define GCC_UNUSED              /* nothing */
374 #endif
375
376 #ifndef HAVE_GETNSTR
377 #define getnstr(s,n) getstr(s)
378 #endif
379
380 #ifndef USE_SOFTKEYS
381 #if HAVE_SLK_INIT
382 #define USE_SOFTKEYS 1
383 #else
384 #define USE_SOFTKEYS 0
385 #endif
386 #endif
387
388 #if !USE_SOFTKEYS
389 #define slk_init()              /* nothing */
390 #define slk_restore()           /* nothing */
391 #define slk_clear()             /* nothing */
392 #endif
393
394 #ifndef HAVE_WSYNCDOWN
395 #define wsyncdown(win)          /* nothing */
396 #endif
397
398 #ifndef USE_WIDEC_SUPPORT
399 #if (defined(_XOPEN_SOURCE_EXTENDED) \
400   || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
401   || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
402   && defined(WACS_ULCORNER)
403 #define USE_WIDEC_SUPPORT 1
404 #else
405 #define USE_WIDEC_SUPPORT 0
406 #endif
407 #endif
408
409 #if HAVE_PANEL_H && HAVE_LIBPANEL
410 #define USE_LIBPANEL 1
411 #else
412 #define USE_LIBPANEL 0
413 #endif
414
415 #if HAVE_MENU_H && HAVE_LIBMENU
416 #define USE_LIBMENU 1
417 #else
418 #define USE_LIBMENU 0
419 #endif
420
421 #if HAVE_FORM_H && HAVE_LIBFORM
422 #define USE_LIBFORM 1
423 #else
424 #define USE_LIBFORM 0
425 #endif
426
427 /* workaround, to build against NetBSD's variant of the form library */
428 #ifdef HAVE_NETBSD_FORM_H
429 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
430 #else
431 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
432 #endif
433
434 /* workaround, to build against NetBSD's variant of the form library */
435 #ifdef HAVE_NETBSD_MENU_H
436 #define menu_itemwidth(menu) (menu)->max_item_width
437 #else
438 #define menu_itemwidth(menu) (menu)->itemlen
439 #endif
440
441 #ifndef HAVE_TYPE_ATTR_T
442 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
443 #define attr_t chtype
444 #endif
445 #endif
446
447 #undef NCURSES_CH_T
448 #if !USE_WIDEC_SUPPORT
449 #define NCURSES_CH_T chtype
450 #else
451 #define NCURSES_CH_T cchar_t
452 #endif
453
454 #ifndef NCURSES_COLOR_T
455 #define NCURSES_COLOR_T short
456 #endif
457
458 #ifndef NCURSES_PAIRS_T
459 #define NCURSES_PAIRS_T short
460 #endif
461
462 #ifndef NCURSES_OPAQUE
463 #define NCURSES_OPAQUE 0
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 */