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