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