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