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