]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 6.0 - patch 20170930
[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.158 2017/09/30 17:58:37 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_RESIZE_TERM
210 #define HAVE_RESIZE_TERM 0
211 #endif
212
213 #ifndef HAVE_RESTARTTERM
214 #define HAVE_RESTARTTERM 0
215 #endif
216
217 #ifndef HAVE_RIPOFFLINE
218 #define HAVE_RIPOFFLINE 0
219 #endif
220
221 #ifndef HAVE_SCR_DUMP
222 #define HAVE_SCR_DUMP 0
223 #endif
224
225 #ifndef HAVE_SETUPTERM
226 #define HAVE_SETUPTERM 0
227 #endif
228
229 #ifndef HAVE_SLK_COLOR
230 #define HAVE_SLK_COLOR 0
231 #endif
232
233 #ifndef HAVE_SLK_INIT
234 #define HAVE_SLK_INIT 0
235 #endif
236
237 #ifndef HAVE_STDINT_H
238 #define HAVE_STDINT_H 0
239 #endif
240
241 #ifndef HAVE_SYS_IOCTL_H
242 #define HAVE_SYS_IOCTL_H 0
243 #endif
244
245 #ifndef HAVE_SYS_SELECT_H
246 #define HAVE_SYS_SELECT_H 0
247 #endif
248
249 #ifndef HAVE_TDESTROY
250 #define HAVE_TDESTROY 0
251 #endif
252
253 #ifndef HAVE_TERMATTRS
254 #define HAVE_TERMATTRS 0
255 #endif
256
257 #ifndef HAVE_TERMIOS_H
258 #define HAVE_TERMIOS_H 0
259 #endif
260
261 #ifndef HAVE_TERMNAME
262 #define HAVE_TERMNAME 0
263 #endif
264
265 #ifndef HAVE_TERM_ENTRY_H
266 #define HAVE_TERM_ENTRY_H 0
267 #endif
268
269 #ifndef HAVE_TGETENT
270 #define HAVE_TGETENT 0
271 #endif
272
273 #ifndef HAVE_TIGETNUM
274 #define HAVE_TIGETNUM 0
275 #endif
276
277 #ifndef HAVE_TIGETSTR
278 #define HAVE_TIGETSTR 0
279 #endif
280
281 #ifndef HAVE_TPUTS_SP
282 #define HAVE_TPUTS_SP 0
283 #endif
284
285 #ifndef HAVE_TSEARCH
286 #define HAVE_TSEARCH 0
287 #endif
288
289 #ifndef HAVE_TYPEAHEAD
290 #define HAVE_TYPEAHEAD 0
291 #endif
292
293 #ifndef HAVE_WINSSTR
294 #define HAVE_WINSSTR 0
295 #endif
296
297 #ifndef HAVE_USE_DEFAULT_COLORS
298 #define HAVE_USE_DEFAULT_COLORS 0
299 #endif
300
301 #ifndef HAVE_USE_ENV
302 #define HAVE_USE_ENV 0
303 #endif
304
305 #ifndef HAVE_USE_EXTENDED_NAMES
306 #define HAVE_USE_EXTENDED_NAMES 0
307 #endif
308
309 #ifndef HAVE_USE_SCREEN
310 #define HAVE_USE_SCREEN 0
311 #endif
312
313 #ifndef HAVE_USE_WINDOW
314 #define HAVE_USE_WINDOW 0
315 #endif
316
317 #ifndef HAVE_VIDPUTS
318 #define HAVE_VIDPUTS 0
319 #endif
320
321 #ifndef HAVE_VID_PUTS
322 #define HAVE_VID_PUTS 0
323 #endif
324
325 #ifndef HAVE_WINSDELLN
326 #define HAVE_WINSDELLN 0
327 #endif
328
329 #ifndef HAVE_WRESIZE
330 #define HAVE_WRESIZE 0
331 #endif
332
333 #ifndef HAVE__TRACEF
334 #define HAVE__TRACEF 0
335 #endif
336
337 #ifndef NCURSES_EXT_FUNCS
338 #define NCURSES_EXT_FUNCS 0
339 #endif
340
341 #ifndef NEED_PTEM_H
342 #define NEED_PTEM_H 0
343 #endif
344
345 #ifndef NEED_WCHAR_H
346 #define NEED_WCHAR_H 0
347 #endif
348
349 #ifndef NO_LEAKS
350 #define NO_LEAKS 0
351 #endif
352
353 /*
354  * Workaround for HPUX
355  */
356 #if defined(__hpux) && !defined(NCURSES_VERSION)
357 #define _ACS_COMPAT_CODE        /* needed for acs_map vs __acs_map */
358 #endif
359
360 #include <stdlib.h>
361 #include <stdarg.h>
362 #include <string.h>
363 #include <sys/types.h>
364 #include <errno.h>
365
366 #if HAVE_UNISTD_H
367 #include <unistd.h>
368 #endif
369
370 #include <signal.h>             /* include before curses.h to work around glibc bug */
371
372 #if NEED_WCHAR_H
373 #include <wchar.h>
374 #ifdef HAVE_LIBUTF8_H
375 #include <libutf8.h>
376 #endif
377 #endif
378
379 #if defined(HAVE_XCURSES)
380 #include <xcurses.h>
381 #elif defined(HAVE_NCURSESW_NCURSES_H)
382 #include <ncursesw/curses.h>
383 #elif defined(HAVE_NCURSES_NCURSES_H)
384 #include <ncurses/curses.h>
385 #else
386 #include <curses.h>
387 #endif
388
389 #if defined(HAVE_XCURSES) || defined(PDCURSES)
390 /* no other headers */
391 #undef  HAVE_SETUPTERM          /* nonfunctional */
392 #define HAVE_SETUPTERM 0
393 #undef  HAVE_TGETENT            /* nonfunctional */
394 #define HAVE_TGETENT 0
395 #undef  HAVE_TIGETSTR           /* nonfunctional */
396 #define HAVE_TIGETSTR 0
397 #elif defined(HAVE_NCURSESW_TERM_H)
398 #include <ncursesw/term.h>
399 #elif defined(HAVE_NCURSES_TERM_H)
400 #include <ncurses/term.h>
401 #elif defined(HAVE_TERM_H)
402 #include <term.h>
403 #endif
404
405 /*
406  * Not all curses.h implementations include unctrl.h,
407  */
408 #if defined(HAVE_NCURSESW_UNCTRL_H)
409 #include <ncursesw/unctrl.h>
410 #elif defined(HAVE_NCURSES_UNCTRL_H)
411 #include <ncurses/unctrl.h>
412 #elif defined(HAVE_UNCTRL_H)
413 #include <unctrl.h>
414 #endif
415
416 #if HAVE_GETOPT_H
417 #include <getopt.h>
418 #elif !defined(HAVE_GETOPT_HEADER)
419 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
420  * doesn't hurt.
421  */
422 extern char *optarg;
423 extern int optind;
424 #endif /* HAVE_GETOPT_H */
425
426 #if HAVE_LOCALE_H
427 #include <locale.h>
428 #else
429 #define setlocale(name,string)  /* nothing */
430 #endif
431
432 #include <assert.h>
433 #include <ctype.h>
434
435 #ifndef GCC_NORETURN
436 #define GCC_NORETURN            /* nothing */
437 #endif
438 #ifndef GCC_PRINTFLIKE
439 #define GCC_PRINTFLIKE(a,b)     /* nothing */
440 #endif
441 #ifndef GCC_UNUSED
442 #define GCC_UNUSED              /* nothing */
443 #endif
444
445 #ifndef HAVE_GETNSTR
446 #define getnstr(s,n) getstr(s)
447 #endif
448
449 #ifndef USE_SOFTKEYS
450 #if HAVE_SLK_INIT
451 #define USE_SOFTKEYS 1
452 #else
453 #define USE_SOFTKEYS 0
454 #endif
455 #endif
456
457 #if !USE_SOFTKEYS
458 #define slk_init()              /* nothing */
459 #define slk_restore()           /* nothing */
460 #define slk_clear()             /* nothing */
461 #endif
462
463 #ifndef HAVE_WSYNCDOWN
464 #define wsyncdown(win)          /* nothing */
465 #endif
466
467 #ifndef USE_WIDEC_SUPPORT
468 #if (defined(_XOPEN_SOURCE_EXTENDED) \
469   || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
470   || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
471   && defined(WACS_ULCORNER)
472 #define USE_WIDEC_SUPPORT 1
473 #else
474 #define USE_WIDEC_SUPPORT 0
475 #endif
476 #endif
477
478 #if HAVE_PANEL_H && HAVE_LIBPANEL
479 #define USE_LIBPANEL 1
480 #else
481 #define USE_LIBPANEL 0
482 #endif
483
484 #if HAVE_MENU_H && HAVE_LIBMENU
485 #define USE_LIBMENU 1
486 #else
487 #define USE_LIBMENU 0
488 #endif
489
490 #if HAVE_FORM_H && HAVE_LIBFORM
491 #define USE_LIBFORM 1
492 #else
493 #define USE_LIBFORM 0
494 #endif
495
496 /* workaround, to build against NetBSD's variant of the form library */
497 #ifdef HAVE_NETBSD_FORM_H
498 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
499 #else
500 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
501 #endif
502
503 /* workaround, to build against NetBSD's variant of the form library */
504 #ifdef HAVE_NETBSD_MENU_H
505 #define menu_itemwidth(menu) (menu)->max_item_width
506 #else
507 #define menu_itemwidth(menu) (menu)->itemlen
508 #endif
509
510 #ifndef HAVE_TYPE_ATTR_T
511 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
512 #define attr_t chtype
513 #endif
514 #endif
515
516 #undef NCURSES_CH_T
517 #if !USE_WIDEC_SUPPORT
518 #define NCURSES_CH_T chtype
519 #else
520 #define NCURSES_CH_T cchar_t
521 #endif
522
523 #ifndef NCURSES_COLOR_T
524 #define NCURSES_COLOR_T short
525 #endif
526
527 #ifndef NCURSES_PAIRS_T
528 #define NCURSES_PAIRS_T short
529 #endif
530
531 #ifndef CCHARW_MAX
532 #define CCHARW_MAX 5
533 #endif
534
535 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
536 #define CURSES_WACS_SYMBOLS
537 #endif
538
539 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
540 /* NetBSD 5.1 defines these incorrectly */
541 #undef  WACS_RARROW
542 #undef  WACS_LARROW
543 #undef  WACS_UARROW
544 #undef  WACS_DARROW
545 #undef  WACS_BLOCK
546 #undef  WACS_DIAMOND
547 #undef  WACS_CKBOARD
548 #undef  WACS_DEGREE
549 #undef  WACS_PLMINUS
550 #undef  WACS_BOARD
551 #undef  WACS_LANTERN
552 #undef  WACS_LRCORNER
553 #undef  WACS_URCORNER
554 #undef  WACS_ULCORNER
555 #undef  WACS_LLCORNER
556 #undef  WACS_PLUS
557 #undef  WACS_HLINE
558 #undef  WACS_S1
559 #undef  WACS_S9
560 #undef  WACS_LTEE
561 #undef  WACS_RTEE
562 #undef  WACS_BTEE
563 #undef  WACS_TTEE
564 #undef  WACS_VLINE
565 #undef  WACS_BULLET
566 #undef  WACS_S3
567 #undef  WACS_S7
568 #undef  WACS_LEQUAL
569 #undef  WACS_GEQUAL
570 #undef  WACS_PI
571 #undef  WACS_NEQUAL
572 #undef  WACS_STERLING
573
574 #define WACS_RARROW     &(CURSES_WACS_ARRAY['+'])
575 #define WACS_LARROW     &(CURSES_WACS_ARRAY[','])
576 #define WACS_UARROW     &(CURSES_WACS_ARRAY['-'])
577 #define WACS_DARROW     &(CURSES_WACS_ARRAY['.'])
578 #define WACS_BLOCK      &(CURSES_WACS_ARRAY['0'])
579 #define WACS_DIAMOND    &(CURSES_WACS_ARRAY['`'])
580 #define WACS_CKBOARD    &(CURSES_WACS_ARRAY['a'])
581 #define WACS_DEGREE     &(CURSES_WACS_ARRAY['f'])
582 #define WACS_PLMINUS    &(CURSES_WACS_ARRAY['g'])
583 #define WACS_BOARD      &(CURSES_WACS_ARRAY['h'])
584 #define WACS_LANTERN    &(CURSES_WACS_ARRAY['i'])
585 #define WACS_LRCORNER   &(CURSES_WACS_ARRAY['j'])
586 #define WACS_URCORNER   &(CURSES_WACS_ARRAY['k'])
587 #define WACS_ULCORNER   &(CURSES_WACS_ARRAY['l'])
588 #define WACS_LLCORNER   &(CURSES_WACS_ARRAY['m'])
589 #define WACS_PLUS       &(CURSES_WACS_ARRAY['n'])
590 #define WACS_HLINE      &(CURSES_WACS_ARRAY['q'])
591 #define WACS_S1         &(CURSES_WACS_ARRAY['o'])
592 #define WACS_S9         &(CURSES_WACS_ARRAY['s'])
593 #define WACS_LTEE       &(CURSES_WACS_ARRAY['t'])
594 #define WACS_RTEE       &(CURSES_WACS_ARRAY['u'])
595 #define WACS_BTEE       &(CURSES_WACS_ARRAY['v'])
596 #define WACS_TTEE       &(CURSES_WACS_ARRAY['w'])
597 #define WACS_VLINE      &(CURSES_WACS_ARRAY['x'])
598 #define WACS_BULLET     &(CURSES_WACS_ARRAY['~'])
599 #define WACS_S3         &(CURSES_WACS_ARRAY['p'])
600 #define WACS_S7         &(CURSES_WACS_ARRAY['r'])
601 #define WACS_LEQUAL     &(CURSES_WACS_ARRAY['y'])
602 #define WACS_GEQUAL     &(CURSES_WACS_ARRAY['z'])
603 #define WACS_PI         &(CURSES_WACS_ARRAY['{'])
604 #define WACS_NEQUAL     &(CURSES_WACS_ARRAY['|'])
605 #define WACS_STERLING   &(CURSES_WACS_ARRAY['}'])
606 #endif
607
608 #ifndef OK
609 #define OK (0)
610 #endif
611
612 #ifndef ERR
613 #define ERR (-1)
614 #endif
615
616 #undef CTRL
617 #define CTRL(x) ((x) & 0x1f)
618
619 #define QUIT            CTRL('Q')
620 #define ESCAPE          CTRL('[')
621
622 #ifndef KEY_MIN
623 #define KEY_MIN 256             /* not defined in Solaris 8 */
624 #endif
625
626 #define HELP_KEY_1      '?'
627 #define HELP_KEY_2      KEY_F(1)
628
629 /* from nc_string.h, to make this stand alone */
630 #if HAVE_BSD_STRING_H
631 #include <bsd/string.h>
632 #endif
633
634 #ifdef __cplusplus
635 #define NCURSES_VOID            /* nothing */
636 #else
637 #define NCURSES_VOID (void)
638 #endif
639
640 #ifndef HAVE_STRLCAT
641 #define HAVE_STRLCAT 0
642 #endif
643
644 #ifndef HAVE_STRLCPY
645 #define HAVE_STRLCPY 0
646 #endif
647
648 #ifndef HAVE_SNPRINTF
649 #define HAVE_SNPRINTF 0
650 #endif
651
652 #ifndef USE_STRING_HACKS
653 #define USE_STRING_HACKS 0
654 #endif
655
656 #if USE_STRING_HACKS && HAVE_STRLCAT
657 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
658 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
659 #else
660 #define _nc_STRCAT(d,s,n)       NCURSES_VOID strcat((d),(s))
661 #define _nc_STRNCAT(d,s,m,n)    NCURSES_VOID strncat((d),(s),(n))
662 #endif
663
664 #if USE_STRING_HACKS && HAVE_STRLCPY
665 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
666 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
667 #else
668 #define _nc_STRCPY(d,s,n)       NCURSES_VOID strcpy((d),(s))
669 #define _nc_STRNCPY(d,s,n)      NCURSES_VOID strncpy((d),(s),(n))
670 #endif
671
672 #if USE_STRING_HACKS && HAVE_SNPRINTF
673 #define _nc_SPRINTF             NCURSES_VOID snprintf
674 #define _nc_SLIMIT(n)           NCURSES_CAST(size_t,n),
675 #else
676 #define _nc_SPRINTF             NCURSES_VOID sprintf
677 #define _nc_SLIMIT(n)           /* nothing */
678 #endif
679
680 #ifdef DECL_CURSES_DATA_BOOLNAMES
681 extern char *boolnames[], *boolcodes[], *boolfnames[];
682 extern char *numnames[], *numcodes[], *numfnames[];
683 extern char *strnames[], *strcodes[], *strfnames[];
684 #endif
685
686 #ifndef HAVE_CURSES_DATA_TTYTYPE
687 #define HAVE_CURSES_DATA_TTYTYPE 0
688 #endif
689
690 #ifndef DECL_CURSES_DATA_TTYTYPE
691 #define DECL_CURSES_DATA_TTYTYPE 0
692 #endif
693
694 #if !HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE
695 #define ttytype termname()
696 #endif
697
698 #define colored_chtype(ch, attr, pair) \
699         ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
700
701 /*
702  * Workaround for HPUX
703  */
704 #if defined(__hpux) && !defined(NCURSES_VERSION)
705 #define getbegx(w) __getbegx(w)
706 #define getbegy(w) __getbegy(w)
707 #define getcurx(w) __getcurx(w)
708 #define getcury(w) __getcury(w)
709 #define getmaxx(w) __getmaxx(w)
710 #define getmaxy(w) __getmaxy(w)
711 #define getparx(w) __getparx(w)
712 #define getpary(w) __getpary(w)
713 #endif
714
715 /*
716  * Workaround in case getcchar() returns a positive value when the source
717  * string produces only a L'\0'.
718  */
719 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
720         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
721             wchar_t test_wch[CCHARW_MAX + 2]; \
722             attr_t test_attrs; \
723             NCURSES_PAIRS_T test_pair; \
724             \
725             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
726                 && test_wch[0] != L'\0') { \
727                 then_stmt \
728             } else { \
729                 else_stmt \
730             } \
731         } else { \
732             else_stmt \
733         }
734 /*
735  * These usually are implemented as macros, but may be functions.
736  */
737 #if !defined(getcurx) && !HAVE_GETCURX
738 #define getcurx(win)            ((win) ? ((int)(win)->_curx) : ERR)
739 #define getcury(win)            ((win) ? ((int)(win)->_cury) : ERR)
740 #endif
741
742 #if !defined(getbegx) && !HAVE_GETBEGX
743 #define getbegx(win)            ((win) ? ((int)(win)->_begx) : ERR)
744 #define getbegy(win)            ((win) ? ((int)(win)->_begy) : ERR)
745 #endif
746
747 #if !defined(getmaxx) && !HAVE_GETMAXX
748 #define getmaxx(win)            ((win) ? ((int)(win)->_maxx + 1) : ERR)
749 #define getmaxy(win)            ((win) ? ((int)(win)->_maxy + 1) : ERR)
750 #endif
751
752 /*
753  * Solaris 10 xpg4:
754 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
755                                 : (w)->_begx - (w)->_parent->_begx)
756  */
757 #if !defined(getparx) && !HAVE_GETPARX
758 #ifdef __m_getparx
759 #define getparx(win)            __m_getparx(win)
760 #define getpary(win)            __m_getpary(win)
761 #else
762 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
763 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
764 #endif
765 #endif
766
767 #if !defined(mvwvline) && !HAVE_MVWVLINE
768 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
769 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
770 #endif
771
772 #if !defined(mvvline) && !HAVE_MVVLINE
773 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
774 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
775 #endif
776
777 /*
778  * Try to accommodate curses implementations that have no terminfo support.
779  */
780 #if HAVE_TIGETNUM
781 #define TIGETNUM(ti,tc) tigetnum(ti)
782 #else
783 #define TIGETNUM(ti,tc) tgetnum(tc)
784 #endif
785
786 #if HAVE_TIGETSTR
787 #define TIGETSTR(ti,tc) tigetstr(ti)
788 #else
789 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
790 #endif
791
792 /*
793  * So far (2013 - more than ten years), only ncurses implements
794  * use_extended_names().
795  */
796 #if defined(NCURSES_XNAMES)
797 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
798 #define NCURSES_XNAMES 1
799 #else
800 #define NCURSES_XNAMES 0
801 #endif
802
803 /*
804  * ncurses restores the cursor in endwin().  Other libraries may not.
805  */
806 #ifdef NCURSES_VERSION
807 #define exit_curses() endwin()
808 #else
809 #define exit_curses() do { endwin(); curs_set(1); } while (0)
810 #endif
811
812 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
813  * (which is incompatible with legacy usage, doesn't solve any problems).
814  */
815 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
816 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
817
818 #define UChar(c)    ((unsigned char)(c))
819
820 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
821
822 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
823 #include <nc_alloc.h>
824 #if HAVE_NC_FREEALL && defined(USE_TINFO)
825 #undef ExitProgram
826 #define ExitProgram(code) _nc_free_tinfo(code)
827 #endif
828 #else
829 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
830 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
831 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
832 #endif
833
834 #ifndef ExitProgram
835 #define ExitProgram(code) exit(code)
836 #endif
837
838 #ifndef EXIT_SUCCESS
839 #define EXIT_SUCCESS 0
840 #endif
841 #ifndef EXIT_FAILURE
842 #define EXIT_FAILURE 1
843 #endif
844
845 #if defined(__MINGW32__) || defined(USE_WIN32CON_DRIVER)
846
847 #if defined(PDCURSES)
848 #ifdef WINVER
849 #  if WINVER < 0x0501
850 #    error WINVER must at least be 0x0501
851 #  endif
852 #else
853 #  define WINVER 0x0501
854 #endif
855 #include <windows.h>
856 #include <sys/time.h>           /* for struct timeval */
857 #undef sleep
858 #define sleep(n) Sleep((n) * 1000)
859 #define SIGHUP  1
860 #define SIGKILL 9
861 #define getlogin() "username"
862
863 #elif defined(HAVE_NCURSESW_NCURSES_H)
864 #include <ncursesw/nc_mingw.h>
865 #elif defined(HAVE_NCURSES_NCURSES_H)
866 #include <ncurses/nc_mingw.h>
867 #else
868 #include <nc_mingw.h>
869 #endif
870
871 /* conflicts in test/firstlast.c */
872 #undef large
873 #undef small
874
875 #endif
876
877 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
878  * curses which doesn't have const parameters declared (so far) in the places
879  * that XSI shows.
880  */
881 #ifndef NCURSES_CONST
882 #define NCURSES_CONST           /* nothing */
883 #endif
884
885 /* out-of-band values for representing absent capabilities */
886 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
887 #define ABSENT_NUMERIC          (-1)
888 #define ABSENT_STRING           (char *)0
889
890 /* out-of-band values for representing cancels */
891 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
892 #define CANCELLED_NUMERIC       (-2)
893 #define CANCELLED_STRING        (char *)(-1)
894
895 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)      /* reject "-1" */
896 #define VALID_NUMERIC(s) ((s) >= 0)
897 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
898
899 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
900
901 #define CATCHALL(handler) do { \
902                 int nsig; \
903                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
904                     if (nsig != SIGKILL) \
905                         signal(nsig, handler); \
906             } while(0)
907
908 #ifdef NCURSES_VERSION
909 #define InitAndCatch(init,handler) do { CATCHALL(handler); init; } while (0)
910 #else
911 #define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
912 #endif
913
914 /*
915  * Workaround for clean(er) compile with Solaris's legacy curses.
916  * The same would be needed for HPUX 10.20
917  */
918 #ifndef TPUTS_ARG
919 #define TPUTS_ARG int
920 #endif
921
922 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
923 #undef TPUTS_ARG
924 #define TPUTS_ARG char
925 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
926 #endif
927
928 #ifndef TPUTS_PROTO
929 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
930 #endif
931
932 #ifndef TPUTS_RETURN
933 #define TPUTS_RETURN(value) return value
934 #endif
935
936 /*
937  * Workarounds for Solaris's X/Open curses
938  */
939 #if !defined(KEY_MIN) && defined(__KEY_MIN)
940 #define KEY_MIN __KEY_MIN
941 #endif
942 #if !defined(KEY_MAX) && defined(__KEY_MIN)
943 #define KEY_MAX __KEY_MAX
944 #endif
945
946 /*
947  * Workaround to build with Sun's default SVr4 curses.
948  */
949 #ifdef NCURSES_VERSION
950 #ifndef HAVE_VW_PRINTW
951 #define HAVE_VW_PRINTW 1
952 #endif
953 #endif
954
955 /*
956  * ncurses provides arrays of capability names; X/Open discarded these SVr4
957  * features.  Some implementations continue to provide them (see the test
958  * configure script).
959  */
960 #ifdef NCURSES_VERSION
961 #ifndef HAVE_CURSES_DATA_BOOLNAMES
962 #define HAVE_CURSES_DATA_BOOLNAMES 1
963 #endif
964 #endif
965
966 /*
967  * ncurses uses const in some places where X/Open does (or did) not allow.
968  */
969 #ifdef NCURSES_VERSION
970 #define CONST_MENUS const
971 #else
972 #define CONST_MENUS             /* nothing */
973 #endif
974
975 /*
976  * Simplify setting up demo of threading with these macros.
977  */
978
979 #if HAVE_USE_WINDOW
980 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
981 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
982 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
983 #else
984 #define USING_WINDOW(w,func) func(w)
985 #define USING_WINDOW2(w,func,data) func(w,data)
986 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
987 #endif
988
989 #if HAVE_USE_WINDOW
990 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
991 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
992 #else
993 #define USING_SCREEN(s,func,data) func(data)
994 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
995 #endif
996
997 #if defined(TRACE) && HAVE__TRACEF
998 #define Trace(p) _tracef p
999 #define USE_TRACE 1
1000 #define START_TRACE() \
1001         if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1002             int t = _nc_getenv_num("NCURSES_TRACE"); \
1003             if (t >= 0) \
1004                 trace((unsigned) t); \
1005         }
1006 extern unsigned _nc_tracing;
1007 extern int _nc_getenv_num(const char *);
1008 #else
1009 #undef TRACE
1010 #define Trace(p)                /* nothing */
1011 #define USE_TRACE 0
1012 #define START_TRACE()           /* nothing */
1013 #endif
1014
1015 #define Trace2(p)               /* nothing */
1016
1017 #define AddCh(c)                (void) addch((chtype)(c))
1018 #define WAddCh(w,c)             (void) waddch((w),(chtype)(c))
1019 #define MvAddCh(y,x,c)          (void) mvaddch((y),(x),(chtype)(c))
1020 #define MvWAddCh(w,y,x,c)       (void) mvwaddch((w),(y),(x),(chtype)(c))
1021 #define MvAddStr(y,x,s)         (void) mvaddstr((y),(x),(s))
1022 #define MvWAddStr(w,y,x,s)      (void) mvwaddstr((w),(y),(x),(s))
1023 #define MvWAddChStr(w,y,x,s)    (void) mvwaddchstr((w),(y),(x),(s))
1024 #define MvPrintw                (void) mvprintw
1025 #define MvWPrintw               (void) mvwprintw
1026 #define MvHLine                 (void) mvhline
1027 #define MvWHLine                (void) mvwhline
1028 #define MvVLine                 (void) mvvline
1029 #define MvWVLine                (void) mvwvline
1030
1031 /*
1032  * The macro likely uses unsigned values, while X/Open prototype uses int.
1033  */
1034 #if defined(wattrset) || defined(PDCURSES)
1035 #define AttrArg(p,a)    (chtype) ((chtype)(p) | (chtype)(a))
1036 #else
1037 #define AttrArg(p,a)    (int) ((chtype)(p) | (chtype)(a))
1038 #endif
1039
1040 /*
1041  * Workaround for defective implementation of gcc attribute warn_unused_result
1042  */
1043 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1044 #define IGNORE_RC(func) errno = func
1045 #else
1046 #define IGNORE_RC(func) (void) func
1047 #endif /* gcc workarounds */
1048
1049 #define init_mb(state)  memset(&state, 0, sizeof(state))
1050
1051 #endif /* __TEST_PRIV_H */