]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 6.3 - patch 20220514
[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.199 2022/04/09 21:32:05 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 #else
557 #define form_getyx(form, y, x) y = (int)(form)->currow, x = (int)(form)->curcol
558 #endif
559
560 /* workaround, to build against NetBSD's variant of the form library */
561 #ifdef HAVE_NETBSD_MENU_H
562 #define menu_itemwidth(menu) (menu)->max_item_width
563 #else
564 #define menu_itemwidth(menu) (menu)->itemlen
565 #endif
566
567 #ifndef HAVE_TYPE_ATTR_T
568 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
569 #define attr_t chtype
570 #endif
571 #endif
572
573 #undef NCURSES_CH_T
574 #if !USE_WIDEC_SUPPORT
575 #define NCURSES_CH_T chtype
576 #else
577 #define NCURSES_CH_T cchar_t
578 #endif
579
580 #ifndef NCURSES_COLOR_T
581 #define NCURSES_COLOR_T short
582 #endif
583
584 #ifndef NCURSES_PAIRS_T
585 #define NCURSES_PAIRS_T short
586 #endif
587
588 #ifndef CCHARW_MAX
589 #define CCHARW_MAX 5
590 #endif
591
592 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
593 #define CURSES_WACS_SYMBOLS
594 #endif
595
596 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
597 /* NetBSD 5.1 defines these incorrectly */
598 #undef  WACS_RARROW
599 #undef  WACS_LARROW
600 #undef  WACS_UARROW
601 #undef  WACS_DARROW
602 #undef  WACS_BLOCK
603 #undef  WACS_DIAMOND
604 #undef  WACS_CKBOARD
605 #undef  WACS_DEGREE
606 #undef  WACS_PLMINUS
607 #undef  WACS_BOARD
608 #undef  WACS_LANTERN
609 #undef  WACS_LRCORNER
610 #undef  WACS_URCORNER
611 #undef  WACS_ULCORNER
612 #undef  WACS_LLCORNER
613 #undef  WACS_PLUS
614 #undef  WACS_HLINE
615 #undef  WACS_S1
616 #undef  WACS_S9
617 #undef  WACS_LTEE
618 #undef  WACS_RTEE
619 #undef  WACS_BTEE
620 #undef  WACS_TTEE
621 #undef  WACS_VLINE
622 #undef  WACS_BULLET
623 #undef  WACS_S3
624 #undef  WACS_S7
625 #undef  WACS_LEQUAL
626 #undef  WACS_GEQUAL
627 #undef  WACS_PI
628 #undef  WACS_NEQUAL
629 #undef  WACS_STERLING
630
631 #define WACS_RARROW     &(CURSES_WACS_ARRAY['+'])
632 #define WACS_LARROW     &(CURSES_WACS_ARRAY[','])
633 #define WACS_UARROW     &(CURSES_WACS_ARRAY['-'])
634 #define WACS_DARROW     &(CURSES_WACS_ARRAY['.'])
635 #define WACS_BLOCK      &(CURSES_WACS_ARRAY['0'])
636 #define WACS_DIAMOND    &(CURSES_WACS_ARRAY['`'])
637 #define WACS_CKBOARD    &(CURSES_WACS_ARRAY['a'])
638 #define WACS_DEGREE     &(CURSES_WACS_ARRAY['f'])
639 #define WACS_PLMINUS    &(CURSES_WACS_ARRAY['g'])
640 #define WACS_BOARD      &(CURSES_WACS_ARRAY['h'])
641 #define WACS_LANTERN    &(CURSES_WACS_ARRAY['i'])
642 #define WACS_LRCORNER   &(CURSES_WACS_ARRAY['j'])
643 #define WACS_URCORNER   &(CURSES_WACS_ARRAY['k'])
644 #define WACS_ULCORNER   &(CURSES_WACS_ARRAY['l'])
645 #define WACS_LLCORNER   &(CURSES_WACS_ARRAY['m'])
646 #define WACS_PLUS       &(CURSES_WACS_ARRAY['n'])
647 #define WACS_HLINE      &(CURSES_WACS_ARRAY['q'])
648 #define WACS_S1         &(CURSES_WACS_ARRAY['o'])
649 #define WACS_S9         &(CURSES_WACS_ARRAY['s'])
650 #define WACS_LTEE       &(CURSES_WACS_ARRAY['t'])
651 #define WACS_RTEE       &(CURSES_WACS_ARRAY['u'])
652 #define WACS_BTEE       &(CURSES_WACS_ARRAY['v'])
653 #define WACS_TTEE       &(CURSES_WACS_ARRAY['w'])
654 #define WACS_VLINE      &(CURSES_WACS_ARRAY['x'])
655 #define WACS_BULLET     &(CURSES_WACS_ARRAY['~'])
656 #define WACS_S3         &(CURSES_WACS_ARRAY['p'])
657 #define WACS_S7         &(CURSES_WACS_ARRAY['r'])
658 #define WACS_LEQUAL     &(CURSES_WACS_ARRAY['y'])
659 #define WACS_GEQUAL     &(CURSES_WACS_ARRAY['z'])
660 #define WACS_PI         &(CURSES_WACS_ARRAY['{'])
661 #define WACS_NEQUAL     &(CURSES_WACS_ARRAY['|'])
662 #define WACS_STERLING   &(CURSES_WACS_ARRAY['}'])
663 #endif
664
665 #ifndef WA_NORMAL
666 #define WA_NORMAL       A_NORMAL
667 #endif
668 #ifndef WA_BOLD
669 #define WA_BOLD         A_BOLD
670 #endif
671 #ifndef WA_REVERSE
672 #define WA_REVERSE      A_REVERSE
673 #endif
674 #ifndef WA_UNDERLINE
675 #define WA_UNDERLINE    A_UNDERLINE
676 #endif
677 #ifndef WA_BLINK
678 #define WA_BLINK        A_BLINK
679 #endif
680
681 #ifndef OK
682 #define OK (0)
683 #endif
684
685 #ifndef ERR
686 #define ERR (-1)
687 #endif
688
689 #undef CTRL
690 #define CTRL(x) ((x) & 0x1f)
691
692 #define QUIT            CTRL('Q')
693 #define ESCAPE          CTRL('[')
694
695 #ifndef KEY_MIN
696 #define KEY_MIN 256             /* not defined in Solaris 8 */
697 #endif
698
699 #define HELP_KEY_1      '?'
700 #define HELP_KEY_2      KEY_F(1)
701
702 /* from nc_string.h, to make this stand alone */
703 #if HAVE_BSD_STRING_H
704 #include <bsd/string.h>
705 #endif
706
707 #ifdef __cplusplus
708 #define NCURSES_VOID            /* nothing */
709 #else
710 #define NCURSES_VOID (void)
711 #endif
712
713 #ifndef HAVE_STRLCAT
714 #define HAVE_STRLCAT 0
715 #endif
716
717 #ifndef HAVE_STRLCPY
718 #define HAVE_STRLCPY 0
719 #endif
720
721 #ifndef HAVE_SNPRINTF
722 #define HAVE_SNPRINTF 0
723 #endif
724
725 #ifndef USE_STRING_HACKS
726 #define USE_STRING_HACKS 0
727 #endif
728
729 #ifndef NCURSES_CAST
730 #ifdef __cplusplus
731 extern "C" {
732 #define NCURSES_CAST(type,value) static_cast<type>(value)
733 #else
734 #define NCURSES_CAST(type,value) (type)(value)
735 #endif
736 #endif
737
738 #if USE_STRING_HACKS && HAVE_STRLCAT
739 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
740 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
741 #else
742 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strcat((d),(s))
743 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strncat((d),(s),(n))
744 #endif
745
746 #if USE_STRING_HACKS && HAVE_STRLCPY
747 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
748 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
749 #else
750 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strcpy((d),(s))
751 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strncpy((d),(s),(n))
752 #endif
753
754 #if USE_STRING_HACKS && HAVE_SNPRINTF
755 #define _nc_SPRINTF             NCURSES_VOID (snprintf)
756 #define _nc_SLIMIT(n)           NCURSES_CAST(size_t,n),
757 #else
758 #define _nc_SPRINTF             NCURSES_VOID (sprintf)
759 #define _nc_SLIMIT(n)           /* nothing */
760 #endif
761
762 /*
763  * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
764  * curses did, and some implementations provide them anyway, but undeclared.
765  */
766 #ifdef DECL_CURSES_DATA_BOOLNAMES
767 extern char *boolnames[], *boolcodes[], *boolfnames[];
768 extern char *numnames[], *numcodes[], *numfnames[];
769 extern char *strnames[], *strcodes[], *strfnames[];
770 #endif
771
772 /*
773  * Again, an SVr4 curses feature latent in the libraries but not in headers.
774  */
775 #ifndef DECL_CURSES_DATA_TABSIZE
776 #define DECL_CURSES_DATA_TABSIZE 0
777 #endif
778
779 #if DECL_CURSES_DATA_TABSIZE
780 extern int TABSIZE;
781 #undef  HAVE_CURSES_DATA_TABSIZE
782 #define HAVE_CURSES_DATA_TABSIZE 1
783 #endif
784
785 #ifndef HAVE_CURSES_DATA_TABSIZE
786 #define HAVE_CURSES_DATA_TABSIZE 0
787 #endif
788
789 /*
790  * X/Open Curses provides termname(), whose return value is analogous to the
791  * SVr4 curses variable ttytype[].
792  */
793 #ifndef HAVE_CURSES_DATA_TTYTYPE
794 #define HAVE_CURSES_DATA_TTYTYPE 0
795 #endif
796
797 #ifndef DECL_CURSES_DATA_TTYTYPE
798 #define DECL_CURSES_DATA_TTYTYPE 0
799 #endif
800
801 #if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
802 #define ttytype termname()
803 #endif
804
805 #define colored_chtype(ch, attr, pair) \
806         ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
807
808 /*
809  * Workaround for HPUX
810  */
811 #if defined(__hpux) && !defined(NCURSES_VERSION)
812 #define getbegx(w) __getbegx(w)
813 #define getbegy(w) __getbegy(w)
814 #define getcurx(w) __getcurx(w)
815 #define getcury(w) __getcury(w)
816 #define getmaxx(w) __getmaxx(w)
817 #define getmaxy(w) __getmaxy(w)
818 #define getparx(w) __getparx(w)
819 #define getpary(w) __getpary(w)
820 #endif
821
822 /*
823  * Workaround in case getcchar() returns a positive value when the source
824  * string produces only a L'\0'.
825  */
826 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
827         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
828             wchar_t test_wch[CCHARW_MAX + 2]; \
829             attr_t test_attrs; \
830             NCURSES_PAIRS_T test_pair; \
831             \
832             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
833                 && test_wch[0] != L'\0') { \
834                 then_stmt \
835             } else { \
836                 else_stmt \
837             } \
838         } else { \
839             else_stmt \
840         }
841 /*
842  * These usually are implemented as macros, but may be functions.
843  */
844 #if !defined(getcurx) && !HAVE_GETCURX
845 #define getcurx(win)            ((win) ? ((int)(win)->_curx) : ERR)
846 #define getcury(win)            ((win) ? ((int)(win)->_cury) : ERR)
847 #endif
848
849 #if !defined(getbegx) && !HAVE_GETBEGX
850 #define getbegx(win)            ((win) ? ((int)(win)->_begx) : ERR)
851 #define getbegy(win)            ((win) ? ((int)(win)->_begy) : ERR)
852 #endif
853
854 #if !defined(getmaxx) && !HAVE_GETMAXX
855 #define getmaxx(win)            ((win) ? ((int)(win)->_maxx + 1) : ERR)
856 #define getmaxy(win)            ((win) ? ((int)(win)->_maxy + 1) : ERR)
857 #endif
858
859 /*
860  * Solaris 10 xpg4:
861 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
862                                 : (w)->_begx - (w)->_parent->_begx)
863  */
864 #if !defined(getparx) && !HAVE_GETPARX
865 #ifdef __m_getparx
866 #define getparx(win)            __m_getparx(win)
867 #define getpary(win)            __m_getpary(win)
868 #else
869 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
870 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
871 #endif
872 #endif
873
874 #if !defined(mvwvline) && !HAVE_MVWVLINE
875 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
876 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
877 #endif
878
879 #if !defined(mvvline) && !HAVE_MVVLINE
880 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
881 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
882 #endif
883
884 /*
885  * Try to accommodate curses implementations that have no terminfo support.
886  */
887 #if HAVE_TIGETNUM
888 #define TIGETNUM(ti,tc) tigetnum(ti)
889 #else
890 #define TIGETNUM(ti,tc) tgetnum(tc)
891 #endif
892
893 #if HAVE_TIGETSTR
894 #define TIGETSTR(ti,tc) tigetstr(ti)
895 #else
896 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
897 #endif
898
899 /*
900  * So far (2013 - more than ten years), only ncurses implements
901  * use_extended_names().
902  */
903 #if defined(NCURSES_XNAMES)
904 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
905 #define NCURSES_XNAMES 1
906 #else
907 #define NCURSES_XNAMES 0
908 #endif
909
910 /*
911  * ncurses restores the cursor in endwin().  Other libraries may not.
912  */
913 #ifdef NCURSES_VERSION
914 #define stop_curses() endwin()
915 #else
916 #define stop_curses() do { endwin(); curs_set(1); } while (0)
917 #endif
918
919 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
920  * (which is incompatible with legacy usage, doesn't solve any problems).
921  */
922 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
923 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
924
925 #define UChar(c)    ((unsigned char)(c))
926
927 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
928
929 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
930 #include <nc_alloc.h>
931 #if HAVE_EXIT_TERMINFO && (defined(USE_TERMINFO) || defined(USE_TINFO))
932 #undef ExitProgram
933 #define ExitProgram(code) exit_terminfo(code)
934 #elif HAVE_EXIT_CURSES
935 #undef ExitProgram
936 #define ExitProgram(code) exit_curses(code)
937 #endif
938 #else /* not ncurses-tree */
939 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
940 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
941 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
942 #endif
943
944 #ifndef ExitProgram
945 #define ExitProgram(code) exit(code)
946 #endif
947
948 #ifndef EXIT_SUCCESS
949 #define EXIT_SUCCESS 0
950 #endif
951 #ifndef EXIT_FAILURE
952 #define EXIT_FAILURE 1
953 #endif
954
955 #undef _NC_WINDOWS
956 #if (defined(_WIN32) || defined(_WIN64))
957 #define _NC_WINDOWS 1
958 #endif
959
960 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
961
962 #if defined(PDCURSES)
963 #ifdef WINVER
964 #  if WINVER < 0x0501
965 #    error WINVER must at least be 0x0501
966 #  endif
967 #else
968 #  define WINVER 0x0501
969 #endif
970 #include <windows.h>
971 #include <sys/time.h>           /* for struct timeval */
972 #undef sleep
973 #define sleep(n) Sleep((n) * 1000)
974 #define SIGHUP  1
975 #define SIGKILL 9
976 #define getlogin() "username"
977
978 #elif defined(EXP_WIN32_DRIVER)
979
980 #if defined(HAVE_NCURSESW_NCURSES_H)
981 #include <ncursesw/nc_win32.h>
982 #elif defined(HAVE_NCURSES_NCURSES_H)
983 #include <ncurses/nc_win32.h>
984 #else
985 #include <nc_win32.h>
986 #endif
987
988 #else
989
990 #if defined(HAVE_NCURSESW_NCURSES_H)
991 #include <ncursesw/nc_mingw.h>
992 #elif defined(HAVE_NCURSES_NCURSES_H)
993 #include <ncurses/nc_mingw.h>
994 #else
995 #include <nc_mingw.h>
996 #endif
997
998 #endif
999
1000 /* conflicts in test/firstlast.c */
1001 #undef large
1002 #undef small
1003
1004 #endif
1005
1006 #ifdef NEED_TIME_H
1007 #if TIME_WITH_SYS_TIME
1008 # include <sys/time.h>
1009 # include <time.h>
1010 #else
1011 # if HAVE_SYS_TIME_H
1012 #  include <sys/time.h>
1013 # else
1014 #  include <time.h>
1015 # endif
1016 #endif
1017 #endif
1018
1019 /*
1020  * Ultrix 3.1
1021  */
1022 #ifndef STDOUT_FILENO
1023 #define STDOUT_FILENO 1
1024 #endif
1025
1026 #if !HAVE_STRSTR
1027 extern char *_nc_strstr(const char *, const char *);
1028 #define strstr(a,b) _nc_strstr((a),(b))
1029 #endif /* !HAVE_STRSTR */
1030
1031 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
1032  * curses which doesn't have const parameters declared (so far) in the places
1033  * that XSI shows.
1034  */
1035 #ifndef NCURSES_CONST
1036 #ifdef PDCURSES
1037 #define NCURSES_CONST           const   /* close enough */
1038 #else
1039 #define NCURSES_CONST           /* nothing */
1040 #endif
1041 #endif
1042
1043 /* out-of-band values for representing absent capabilities */
1044 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
1045 #define ABSENT_NUMERIC          (-1)
1046 #define ABSENT_STRING           (char *)0
1047
1048 /* out-of-band values for representing cancels */
1049 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
1050 #define CANCELLED_NUMERIC       (-2)
1051 #define CANCELLED_STRING        (char *)(-1)
1052
1053 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)      /* reject "-1" */
1054 #define VALID_NUMERIC(s) ((s) >= 0)
1055 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
1056
1057 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
1058
1059 #define CATCHALL(handler) do { \
1060                 int nsig; \
1061                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
1062                     if (nsig != SIGKILL) \
1063                         signal(nsig, handler); \
1064             } while(0)
1065
1066 #ifdef NCURSES_VERSION
1067 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
1068 #else
1069 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
1070 #endif
1071
1072 #if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
1073 #define SetupAlarm(opt) (void)opt
1074 #else
1075 #define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
1076 #endif
1077
1078 /*
1079  * Workaround for clean(er) compile with Solaris's legacy curses.
1080  * The same would be needed for HPUX 10.20
1081  */
1082 #ifndef TPUTS_ARG
1083 #define TPUTS_ARG int
1084 #endif
1085
1086 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
1087 #undef TPUTS_ARG
1088 #define TPUTS_ARG char
1089 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
1090 #endif
1091
1092 #ifndef TPUTS_PROTO
1093 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
1094 #endif
1095
1096 #ifndef TPUTS_RETURN
1097 #define TPUTS_RETURN(value) return value
1098 #endif
1099
1100 /*
1101  * Workarounds for Solaris's X/Open curses
1102  */
1103 #if !defined(KEY_MIN) && defined(__KEY_MIN)
1104 #define KEY_MIN __KEY_MIN
1105 #endif
1106 #if !defined(KEY_MAX) && defined(__KEY_MIN)
1107 #define KEY_MAX __KEY_MAX
1108 #endif
1109
1110 /*
1111  * Workaround to build with Sun's default SVr4 curses.
1112  */
1113 #ifdef NCURSES_VERSION
1114 #ifndef HAVE_VW_PRINTW
1115 #define HAVE_VW_PRINTW 1
1116 #endif
1117 #endif
1118
1119 /*
1120  * ncurses provides arrays of capability names; X/Open discarded these SVr4
1121  * features.  Some implementations continue to provide them (see the test
1122  * configure script).
1123  */
1124 #ifdef NCURSES_VERSION
1125 #ifndef HAVE_CURSES_DATA_BOOLNAMES
1126 #define HAVE_CURSES_DATA_BOOLNAMES 1
1127 #endif
1128 #endif
1129
1130 /*
1131  * ncurses provides a termcap interface; a few packagers replace or displace
1132  * its header file with an incompatible one.  The demo_termcap program uses
1133  * the ncurses file, if available.
1134  */
1135 #ifdef NCURSES_VERSION
1136 #ifndef HAVE_NCURSES_TERMCAP_H
1137 #define HAVE_NCURSES_TERMCAP_H 0
1138 #endif
1139 #ifndef HAVE_TERMCAP_H
1140 #define HAVE_TERMCAP_H 0
1141 #endif
1142 #endif
1143
1144 /*
1145  * ncurses uses const in some places where X/Open does (or did) not allow.
1146  */
1147 #if defined(NCURSES_CONST)
1148 #define CONST_MENUS NCURSES_CONST
1149 #elif defined(PDCURSES)
1150 #define CONST_MENUS const
1151 #else
1152 #define CONST_MENUS             /* nothing */
1153 #endif
1154
1155 #if defined(NCURSES_CONST)
1156 #define CONST_FMT NCURSES_CONST
1157 #elif defined(PDCURSES)
1158 #define CONST_FMT const
1159 #else
1160 #define CONST_FMT               /* nothing */
1161 #endif
1162
1163 /*
1164  * Simplify setting up demo of threading with these macros.
1165  */
1166
1167 #if HAVE_USE_WINDOW
1168 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
1169 #define USING_WINDOW1(w,func,safe) use_window(w, (NCURSES_WINDOW_CB) safe, NULL)
1170 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
1171 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1172 #else
1173 #define USING_WINDOW(w,func) func(w, NULL)
1174 #define USING_WINDOW1(w,func,safe) func(w)
1175 #define USING_WINDOW2(w,func,data) func(w,data)
1176 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
1177 #endif
1178
1179 #if HAVE_USE_WINDOW
1180 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
1181 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1182 #else
1183 #define USING_SCREEN(s,func,data) func(data)
1184 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
1185 #endif
1186
1187 #if defined(TRACE) && HAVE__TRACEF
1188 #define Trace(p) _tracef p
1189 #define USE_TRACE 1
1190 #define START_TRACE() \
1191         if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1192             int t = _nc_getenv_num("NCURSES_TRACE"); \
1193             if (t >= 0) \
1194                 curses_trace((unsigned) t); \
1195         }
1196 extern unsigned _nc_tracing;
1197 extern int _nc_getenv_num(const char *);
1198 #else
1199 #undef TRACE
1200 #define Trace(p)                /* nothing */
1201 #define USE_TRACE 0
1202 #define START_TRACE()           /* nothing */
1203 #endif
1204
1205 #define Trace2(p)               /* nothing */
1206
1207 #define AddCh(c)                (void) addch((chtype)(c))
1208 #define WAddCh(w,c)             (void) waddch((w),(chtype)(c))
1209 #define MvAddCh(y,x,c)          (void) mvaddch((y),(x),(chtype)(c))
1210 #define MvWAddCh(w,y,x,c)       (void) mvwaddch((w),(y),(x),(chtype)(c))
1211 #define MvAddStr(y,x,s)         (void) mvaddstr((y),(x),(s))
1212 #define MvWAddStr(w,y,x,s)      (void) mvwaddstr((w),(y),(x),(s))
1213 #define MvWAddChStr(w,y,x,s)    (void) mvwaddchstr((w),(y),(x),(s))
1214 #define MvPrintw                (void) mvprintw
1215 #define MvWPrintw               (void) mvwprintw
1216 #define MvHLine                 (void) mvhline
1217 #define MvWHLine                (void) mvwhline
1218 #define MvVLine                 (void) mvvline
1219 #define MvWVLine                (void) mvwvline
1220
1221 /*
1222  * The macro likely uses unsigned values, while X/Open prototype uses int.
1223  */
1224 #if defined(wattrset) || defined(PDCURSES)
1225 #define AttrArg(p,a)    (chtype) ((chtype)(p) | (chtype)(a))
1226 #else
1227 #define AttrArg(p,a)    (int) ((chtype)(p) | (chtype)(a))
1228 #endif
1229
1230 /*
1231  * Workaround for defective implementation of gcc attribute warn_unused_result
1232  */
1233 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1234 #define IGNORE_RC(func) errno = func
1235 #else
1236 #define IGNORE_RC(func) (void) func
1237 #endif /* gcc workarounds */
1238
1239 #define init_mb(state)  memset(&state, 0, sizeof(state))
1240
1241 #endif /* __TEST_PRIV_H */