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