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