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