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