]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 6.0 - patch 20160604
[ncurses.git] / test / test.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2014,2016 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.132 2016/04/09 23:55:01 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_ASSUME_DEFAULT_COLORS
62 #define HAVE_ASSUME_DEFAULT_COLORS 0
63 #endif
64
65 #ifndef HAVE_CURSES_VERSION
66 #define HAVE_CURSES_VERSION 0
67 #endif
68
69 #ifndef HAVE_CHGAT
70 #define HAVE_CHGAT 0
71 #endif
72
73 #ifndef HAVE_COLOR_SET
74 #define HAVE_COLOR_SET 0
75 #endif
76
77 #ifndef HAVE_FILTER
78 #define HAVE_FILTER 0
79 #endif
80
81 #ifndef HAVE_FORM_H
82 #define HAVE_FORM_H 0
83 #endif
84
85 #ifndef HAVE_GETBEGX
86 #define HAVE_GETBEGX 0
87 #endif
88
89 #ifndef HAVE_GETCURX
90 #define HAVE_GETCURX 0
91 #endif
92
93 #ifndef HAVE_GETMAXX
94 #define HAVE_GETMAXX 0
95 #endif
96
97 #ifndef HAVE_GETOPT_H
98 #define HAVE_GETOPT_H 0
99 #endif
100
101 #ifndef HAVE_GETPARX
102 #define HAVE_GETPARX 0
103 #endif
104
105 #ifndef HAVE_GETWIN
106 #define HAVE_GETWIN 0
107 #endif
108
109 #ifndef HAVE_LIBFORM
110 #define HAVE_LIBFORM 0
111 #endif
112
113 #ifndef HAVE_LIBMENU
114 #define HAVE_LIBMENU 0
115 #endif
116
117 #ifndef HAVE_LIBPANEL
118 #define HAVE_LIBPANEL 0
119 #endif
120
121 #ifndef HAVE_LANGINFO_CODESET
122 #define HAVE_LANGINFO_CODESET 0
123 #endif
124
125 #ifndef HAVE_LOCALE_H
126 #define HAVE_LOCALE_H 0
127 #endif
128
129 #ifndef HAVE_MATH_H
130 #define HAVE_MATH_H 0
131 #endif
132
133 #ifndef HAVE_MENU_H
134 #define HAVE_MENU_H 0
135 #endif
136
137 #ifndef HAVE_MVVLINE
138 #define HAVE_MVVLINE 0
139 #endif
140
141 #ifndef HAVE_MVWVLINE
142 #define HAVE_MVWVLINE 0
143 #endif
144
145 #ifndef HAVE_NAPMS
146 #define HAVE_NAPMS 1
147 #endif
148
149 #ifndef HAVE_NC_ALLOC_H
150 #define HAVE_NC_ALLOC_H 0
151 #endif
152
153 #ifndef HAVE_PANEL_H
154 #define HAVE_PANEL_H 0
155 #endif
156
157 #ifndef HAVE_PUTWIN
158 #define HAVE_PUTWIN 0
159 #endif
160
161 #ifndef HAVE_RESIZE_TERM
162 #define HAVE_RESIZE_TERM 0
163 #endif
164
165 #ifndef HAVE_RIPOFFLINE
166 #define HAVE_RIPOFFLINE 0
167 #endif
168
169 #ifndef HAVE_SCR_DUMP
170 #define HAVE_SCR_DUMP 0
171 #endif
172
173 #ifndef HAVE_SETUPTERM
174 #define HAVE_SETUPTERM 0
175 #endif
176
177 #ifndef HAVE_SLK_COLOR
178 #define HAVE_SLK_COLOR 0
179 #endif
180
181 #ifndef HAVE_SLK_INIT
182 #define HAVE_SLK_INIT 0
183 #endif
184
185 #ifndef HAVE_SYS_IOCTL_H
186 #define HAVE_SYS_IOCTL_H 0
187 #endif
188
189 #ifndef HAVE_SYS_SELECT_H
190 #define HAVE_SYS_SELECT_H 0
191 #endif
192
193 #ifndef HAVE_TERMATTRS
194 #define HAVE_TERMATTRS 0
195 #endif
196
197 #ifndef HAVE_TERMIOS_H
198 #define HAVE_TERMIOS_H 0
199 #endif
200
201 #ifndef HAVE_TERMNAME
202 #define HAVE_TERMNAME 0
203 #endif
204
205 #ifndef HAVE_TERM_ENTRY_H
206 #define HAVE_TERM_ENTRY_H 0
207 #endif
208
209 #ifndef HAVE_TGETENT
210 #define HAVE_TGETENT 0
211 #endif
212
213 #ifndef HAVE_TIGETNUM
214 #define HAVE_TIGETNUM 0
215 #endif
216
217 #ifndef HAVE_TIGETSTR
218 #define HAVE_TIGETSTR 0
219 #endif
220
221 #ifndef HAVE_TYPEAHEAD
222 #define HAVE_TYPEAHEAD 0
223 #endif
224
225 #ifndef HAVE_WINSSTR
226 #define HAVE_WINSSTR 0
227 #endif
228
229 #ifndef HAVE_USE_DEFAULT_COLORS
230 #define HAVE_USE_DEFAULT_COLORS 0
231 #endif
232
233 #ifndef HAVE_USE_ENV
234 #define HAVE_USE_ENV 0
235 #endif
236
237 #ifndef HAVE_USE_EXTENDED_NAMES
238 #define HAVE_USE_EXTENDED_NAMES 0
239 #endif
240
241 #ifndef HAVE_USE_SCREEN
242 #define HAVE_USE_SCREEN 0
243 #endif
244
245 #ifndef HAVE_USE_WINDOW
246 #define HAVE_USE_WINDOW 0
247 #endif
248
249 #ifndef HAVE_VIDPUTS
250 #define HAVE_VIDPUTS 0
251 #endif
252
253 #ifndef HAVE_VID_PUTS
254 #define HAVE_VID_PUTS 0
255 #endif
256
257 #ifndef HAVE_WRESIZE
258 #define HAVE_WRESIZE 0
259 #endif
260
261 #ifndef NCURSES_EXT_FUNCS
262 #define NCURSES_EXT_FUNCS 0
263 #endif
264
265 #ifndef NEED_PTEM_H
266 #define NEED_PTEM_H 0
267 #endif
268
269 #ifndef NEED_WCHAR_H
270 #define NEED_WCHAR_H 0
271 #endif
272
273 #ifndef NO_LEAKS
274 #define NO_LEAKS 0
275 #endif
276
277 /*
278  * Workaround for HPUX
279  */
280 #if defined(__hpux) && !defined(NCURSES_VERSION)
281 #define _ACS_COMPAT_CODE        /* needed for acs_map vs __acs_map */
282 #endif
283
284 #include <stdlib.h>
285 #include <stdarg.h>
286 #include <string.h>
287 #include <sys/types.h>
288 #include <errno.h>
289
290 #if HAVE_UNISTD_H
291 #include <unistd.h>
292 #endif
293
294 #include <signal.h>             /* include before curses.h to work around glibc bug */
295
296 #if NEED_WCHAR_H
297 #include <wchar.h>
298 #ifdef HAVE_LIBUTF8_H
299 #include <libutf8.h>
300 #endif
301 #endif
302
303 #if defined(HAVE_XCURSES)
304 #include <xcurses.h>
305 #elif defined(HAVE_NCURSESW_NCURSES_H)
306 #include <ncursesw/curses.h>
307 #elif defined(HAVE_NCURSES_NCURSES_H)
308 #include <ncurses/curses.h>
309 #else
310 #include <curses.h>
311 #endif
312
313 #if defined(HAVE_XCURSES) || defined(PDCURSES)
314 /* no other headers */
315 #undef  HAVE_SETUPTERM          /* nonfunctional */
316 #define HAVE_SETUPTERM 0
317 #undef  HAVE_TGETENT            /* nonfunctional */
318 #define HAVE_TGETENT 0
319 #undef  HAVE_TIGETSTR           /* nonfunctional */
320 #define HAVE_TIGETSTR 0
321 #elif defined(HAVE_NCURSESW_TERM_H)
322 #include <ncursesw/term.h>
323 #elif defined(HAVE_NCURSES_TERM_H)
324 #include <ncurses/term.h>
325 #elif defined(HAVE_TERM_H)
326 #include <term.h>
327 #endif
328
329 /*
330  * Not all curses.h implementations include unctrl.h,
331  */
332 #if defined(HAVE_NCURSESW_UNCTRL_H)
333 #include <ncursesw/unctrl.h>
334 #elif defined(HAVE_NCURSES_UNCTRL_H)
335 #include <ncurses/unctrl.h>
336 #elif defined(HAVE_UNCTRL_H)
337 #include <unctrl.h>
338 #endif
339
340 #if HAVE_GETOPT_H
341 #include <getopt.h>
342 #elif !defined(HAVE_GETOPT_HEADER)
343 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
344  * doesn't hurt.
345  */
346 extern char *optarg;
347 extern int optind;
348 #endif /* HAVE_GETOPT_H */
349
350 #if HAVE_LOCALE_H
351 #include <locale.h>
352 #else
353 #define setlocale(name,string)  /* nothing */
354 #endif
355
356 #include <assert.h>
357 #include <ctype.h>
358
359 #ifndef GCC_NORETURN
360 #define GCC_NORETURN            /* nothing */
361 #endif
362 #ifndef GCC_PRINTFLIKE
363 #define GCC_PRINTFLIKE(a,b)     /* nothing */
364 #endif
365 #ifndef GCC_UNUSED
366 #define GCC_UNUSED              /* nothing */
367 #endif
368
369 #ifndef HAVE_GETNSTR
370 #define getnstr(s,n) getstr(s)
371 #endif
372
373 #ifndef USE_SOFTKEYS
374 #if HAVE_SLK_INIT
375 #define USE_SOFTKEYS 1
376 #else
377 #define USE_SOFTKEYS 0
378 #endif
379 #endif
380
381 #if !USE_SOFTKEYS
382 #define slk_init()              /* nothing */
383 #define slk_restore()           /* nothing */
384 #define slk_clear()             /* nothing */
385 #endif
386
387 #ifndef HAVE_WSYNCDOWN
388 #define wsyncdown(win)          /* nothing */
389 #endif
390
391 #ifndef USE_WIDEC_SUPPORT
392 #if (defined(_XOPEN_SOURCE_EXTENDED) \
393   || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 >= 500)) \
394   || (defined(NCURSES_WIDECHAR) && (NCURSES_WIDECHAR - 0 < 1))) \
395   && defined(WACS_ULCORNER)
396 #define USE_WIDEC_SUPPORT 1
397 #else
398 #define USE_WIDEC_SUPPORT 0
399 #endif
400 #endif
401
402 #if HAVE_PANEL_H && HAVE_LIBPANEL
403 #define USE_LIBPANEL 1
404 #else
405 #define USE_LIBPANEL 0
406 #endif
407
408 #if HAVE_MENU_H && HAVE_LIBMENU
409 #define USE_LIBMENU 1
410 #else
411 #define USE_LIBMENU 0
412 #endif
413
414 #if HAVE_FORM_H && HAVE_LIBFORM
415 #define USE_LIBFORM 1
416 #else
417 #define USE_LIBFORM 0
418 #endif
419
420 /* workaround, to build against NetBSD's variant of the form library */
421 #ifdef HAVE_NETBSD_FORM_H
422 #define form_getyx(form, y, x) y = current_field(form)->cursor_ypos, x = current_field(form)->cursor_xpos
423 #else
424 #define form_getyx(form, y, x) y = (form)->currow, x = (form)->curcol
425 #endif
426
427 /* workaround, to build against NetBSD's variant of the form library */
428 #ifdef HAVE_NETBSD_MENU_H
429 #define menu_itemwidth(menu) (menu)->max_item_width
430 #else
431 #define menu_itemwidth(menu) (menu)->itemlen
432 #endif
433
434 #ifndef HAVE_TYPE_ATTR_T
435 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
436 #define attr_t chtype
437 #endif
438 #endif
439
440 #undef NCURSES_CH_T
441 #if !USE_WIDEC_SUPPORT
442 #define NCURSES_CH_T chtype
443 #else
444 #define NCURSES_CH_T cchar_t
445 #endif
446
447 #ifndef NCURSES_COLOR_T
448 #define NCURSES_COLOR_T short
449 #endif
450
451 #ifndef NCURSES_PAIRS_T
452 #define NCURSES_PAIRS_T short
453 #endif
454
455 #ifndef NCURSES_OPAQUE
456 #define NCURSES_OPAQUE 0
457 #endif
458
459 #ifndef CCHARW_MAX
460 #define CCHARW_MAX 5
461 #endif
462
463 #if defined(NCURSES_VERSION) && defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
464 #define CURSES_WACS_SYMBOLS
465 #endif
466
467 #if defined(CURSES_WACS_ARRAY) && !defined(CURSES_WACS_SYMBOLS)
468 /* NetBSD 5.1 defines these incorrectly */
469 #undef  WACS_RARROW
470 #undef  WACS_LARROW
471 #undef  WACS_UARROW
472 #undef  WACS_DARROW
473 #undef  WACS_BLOCK
474 #undef  WACS_DIAMOND
475 #undef  WACS_CKBOARD
476 #undef  WACS_DEGREE
477 #undef  WACS_PLMINUS
478 #undef  WACS_BOARD
479 #undef  WACS_LANTERN
480 #undef  WACS_LRCORNER
481 #undef  WACS_URCORNER
482 #undef  WACS_ULCORNER
483 #undef  WACS_LLCORNER
484 #undef  WACS_PLUS
485 #undef  WACS_HLINE
486 #undef  WACS_S1
487 #undef  WACS_S9
488 #undef  WACS_LTEE
489 #undef  WACS_RTEE
490 #undef  WACS_BTEE
491 #undef  WACS_TTEE
492 #undef  WACS_VLINE
493 #undef  WACS_BULLET
494 #undef  WACS_S3
495 #undef  WACS_S7
496 #undef  WACS_LEQUAL
497 #undef  WACS_GEQUAL
498 #undef  WACS_PI
499 #undef  WACS_NEQUAL
500 #undef  WACS_STERLING
501
502 #define WACS_RARROW     &(CURSES_WACS_ARRAY['+'])
503 #define WACS_LARROW     &(CURSES_WACS_ARRAY[','])
504 #define WACS_UARROW     &(CURSES_WACS_ARRAY['-'])
505 #define WACS_DARROW     &(CURSES_WACS_ARRAY['.'])
506 #define WACS_BLOCK      &(CURSES_WACS_ARRAY['0'])
507 #define WACS_DIAMOND    &(CURSES_WACS_ARRAY['`'])
508 #define WACS_CKBOARD    &(CURSES_WACS_ARRAY['a'])
509 #define WACS_DEGREE     &(CURSES_WACS_ARRAY['f'])
510 #define WACS_PLMINUS    &(CURSES_WACS_ARRAY['g'])
511 #define WACS_BOARD      &(CURSES_WACS_ARRAY['h'])
512 #define WACS_LANTERN    &(CURSES_WACS_ARRAY['i'])
513 #define WACS_LRCORNER   &(CURSES_WACS_ARRAY['j'])
514 #define WACS_URCORNER   &(CURSES_WACS_ARRAY['k'])
515 #define WACS_ULCORNER   &(CURSES_WACS_ARRAY['l'])
516 #define WACS_LLCORNER   &(CURSES_WACS_ARRAY['m'])
517 #define WACS_PLUS       &(CURSES_WACS_ARRAY['n'])
518 #define WACS_HLINE      &(CURSES_WACS_ARRAY['q'])
519 #define WACS_S1         &(CURSES_WACS_ARRAY['o'])
520 #define WACS_S9         &(CURSES_WACS_ARRAY['s'])
521 #define WACS_LTEE       &(CURSES_WACS_ARRAY['t'])
522 #define WACS_RTEE       &(CURSES_WACS_ARRAY['u'])
523 #define WACS_BTEE       &(CURSES_WACS_ARRAY['v'])
524 #define WACS_TTEE       &(CURSES_WACS_ARRAY['w'])
525 #define WACS_VLINE      &(CURSES_WACS_ARRAY['x'])
526 #define WACS_BULLET     &(CURSES_WACS_ARRAY['~'])
527 #define WACS_S3         &(CURSES_WACS_ARRAY['p'])
528 #define WACS_S7         &(CURSES_WACS_ARRAY['r'])
529 #define WACS_LEQUAL     &(CURSES_WACS_ARRAY['y'])
530 #define WACS_GEQUAL     &(CURSES_WACS_ARRAY['z'])
531 #define WACS_PI         &(CURSES_WACS_ARRAY['{'])
532 #define WACS_NEQUAL     &(CURSES_WACS_ARRAY['|'])
533 #define WACS_STERLING   &(CURSES_WACS_ARRAY['}'])
534 #endif
535
536 #undef CTRL
537 #define CTRL(x) ((x) & 0x1f)
538
539 #define QUIT            CTRL('Q')
540 #define ESCAPE          CTRL('[')
541
542 #ifndef KEY_MIN
543 #define KEY_MIN 256             /* not defined in Solaris 8 */
544 #endif
545
546 #ifdef DECL_CURSES_DATA_BOOLNAMES
547 extern char *boolnames[], *boolcodes[], *boolfnames[];
548 extern char *numnames[], *numcodes[], *numfnames[];
549 extern char *strnames[], *strcodes[], *strfnames[];
550 #endif
551
552 #define colored_chtype(ch, attr, pair) \
553         ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
554
555 /*
556  * Workaround for HPUX
557  */
558 #if defined(__hpux) && !defined(NCURSES_VERSION)
559 #define getbegx(w) __getbegx(w)
560 #define getbegy(w) __getbegy(w)
561 #define getcurx(w) __getcurx(w)
562 #define getcury(w) __getcury(w)
563 #define getmaxx(w) __getmaxx(w)
564 #define getmaxy(w) __getmaxy(w)
565 #define getparx(w) __getparx(w)
566 #define getpary(w) __getpary(w)
567 #endif
568
569 /*
570  * Workaround in case getcchar() returns a positive value when the source
571  * string produces only a L'\0'.
572  */
573 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
574         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
575             wchar_t test_wch[CCHARW_MAX + 2]; \
576             attr_t test_attrs; \
577             NCURSES_PAIRS_T test_pair; \
578             \
579             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
580                 && test_wch[0] != L'\0') { \
581                 then_stmt \
582             } else { \
583                 else_stmt \
584             } \
585         } else { \
586             else_stmt \
587         }
588 /*
589  * These usually are implemented as macros, but may be functions.
590  */
591 #if !defined(getcurx) && !HAVE_GETCURX
592 #define getcurx(win)            ((win)?(win)->_curx:ERR)
593 #define getcury(win)            ((win)?(win)->_cury:ERR)
594 #endif
595
596 #if !defined(getbegx) && !HAVE_GETBEGX
597 #define getbegx(win)            ((win)?(win)->_begx:ERR)
598 #define getbegy(win)            ((win)?(win)->_begy:ERR)
599 #endif
600
601 #if !defined(getmaxx) && !HAVE_GETMAXX
602 #define getmaxx(win)            ((win)?((win)->_maxx + 1):ERR)
603 #define getmaxy(win)            ((win)?((win)->_maxy + 1):ERR)
604 #endif
605
606 /*
607  * Solaris 10 xpg4:
608 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
609                                 : (w)->_begx - (w)->_parent->_begx)
610  */
611 #if !defined(getparx) && !HAVE_GETPARX
612 #ifdef __m_getparx
613 #define getparx(win)            __m_getparx(win)
614 #define getpary(win)            __m_getpary(win)
615 #else
616 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
617 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
618 #endif
619 #endif
620
621 #if !defined(mvwvline) && !HAVE_MVWVLINE
622 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
623 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
624 #endif
625
626 #if !defined(mvvline) && !HAVE_MVVLINE
627 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
628 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
629 #endif
630
631 /*
632  * Try to accommodate curses implementations that have no terminfo support.
633  */
634 #if HAVE_TIGETNUM
635 #define TIGETNUM(ti,tc) tigetnum(ti)
636 #else
637 #define TIGETNUM(ti,tc) tgetnum(tc)
638 #endif
639
640 #if HAVE_TIGETSTR
641 #define TIGETSTR(ti,tc) tigetstr(ti)
642 #else
643 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
644 #endif
645
646 /*
647  * So far (2013 - more than ten years), only ncurses implements
648  * use_extended_names().
649  */
650 #if defined(NCURSES_XNAMES)
651 #elif defined(NCURSES_VERSION) && defined(HAVE_TERM_ENTRY_H) && HAVE_TERM_ENTRY_H
652 #define NCURSES_XNAMES 1
653 #else
654 #define NCURSES_XNAMES 0
655 #endif
656
657 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
658  * (which is incompatible with legacy usage, doesn't solve any problems).
659  */
660 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
661 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
662
663 #define UChar(c)    ((unsigned char)(c))
664
665 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
666
667 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
668 #include <nc_alloc.h>
669 #if HAVE_NC_FREEALL && defined(USE_TINFO)
670 #undef ExitProgram
671 #define ExitProgram(code) _nc_free_tinfo(code)
672 #endif
673 #else
674 #define typeMalloc(type,n) (type *) malloc((size_t)(n) * sizeof(type))
675 #define typeCalloc(type,elts) (type *) calloc((size_t)(elts), sizeof(type))
676 #define typeRealloc(type,n,p) (type *) realloc(p, (size_t)(n) * sizeof(type))
677 #endif
678
679 #ifndef ExitProgram
680 #define ExitProgram(code) exit(code)
681 #endif
682
683 #ifndef EXIT_SUCCESS
684 #define EXIT_SUCCESS 0
685 #endif
686 #ifndef EXIT_FAILURE
687 #define EXIT_FAILURE 1
688 #endif
689
690 #if defined(__MINGW32__) || defined(USE_WIN32CON_DRIVER)
691
692 #if defined(PDCURSES)
693 #ifdef WINVER
694 #  if WINVER < 0x0501
695 #    error WINVER must at least be 0x0501
696 #  endif
697 #else
698 #  define WINVER 0x0501
699 #endif
700 #include <windows.h>
701 #include <sys/time.h>           /* for struct timeval */
702 #undef sleep
703 #define sleep(n) Sleep((n) * 1000)
704 #define SIGHUP  1
705 #define SIGKILL 9
706 #define getlogin() "username"
707
708 #elif defined(HAVE_NCURSESW_NCURSES_H)
709 #include <ncursesw/nc_mingw.h>
710 #elif defined(HAVE_NCURSES_NCURSES_H)
711 #include <ncurses/nc_mingw.h>
712 #else
713 #include <nc_mingw.h>
714 #endif
715
716 /* conflicts in test/firstlast.c */
717 #undef large
718 #undef small
719
720 #endif
721
722 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
723  * curses which doesn't have const parameters declared (so far) in the places
724  * that XSI shows.
725  */
726 #ifndef NCURSES_CONST
727 #define NCURSES_CONST           /* nothing */
728 #endif
729
730 /* out-of-band values for representing absent capabilities */
731 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
732 #define ABSENT_NUMERIC          (-1)
733 #define ABSENT_STRING           (char *)0
734
735 /* out-of-band values for representing cancels */
736 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
737 #define CANCELLED_NUMERIC       (-2)
738 #define CANCELLED_STRING        (char *)(-1)
739
740 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)      /* reject "-1" */
741 #define VALID_NUMERIC(s) ((s) >= 0)
742 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
743
744 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
745
746 #define CATCHALL(handler) { \
747                 int nsig; \
748                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
749                     if (nsig != SIGKILL) \
750                         signal(nsig, handler); \
751             }
752
753 /*
754  * Workaround for clean(er) compile with Solaris's legacy curses.
755  * The same would be needed for HPUX 10.20
756  */
757 #ifndef TPUTS_ARG
758 #define TPUTS_ARG int
759 #endif
760
761 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
762 #undef TPUTS_ARG
763 #define TPUTS_ARG char
764 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
765 #endif
766
767 #ifndef TPUTS_PROTO
768 #define TPUTS_PROTO(func,value) int func(TPUTS_ARG value)
769 #endif
770
771 #ifndef TPUTS_RETURN
772 #define TPUTS_RETURN(value) return value
773 #endif
774
775 /*
776  * Workarounds for Solaris's X/Open curses
777  */
778 #if !defined(KEY_MIN) && defined(__KEY_MIN)
779 #define KEY_MIN __KEY_MIN
780 #endif
781 #if !defined(KEY_MAX) && defined(__KEY_MIN)
782 #define KEY_MAX __KEY_MAX
783 #endif
784
785 /*
786  * Workaround to build with Sun's default SVr4 curses.
787  */
788 #ifdef NCURSES_VERSION
789 #ifndef HAVE_VW_PRINTW
790 #define HAVE_VW_PRINTW 1
791 #endif
792 #endif
793
794 /*
795  * ncurses provides arrays of capability names; X/Open discarded these SVr4
796  * features.  Some implementations continue to provide them (see the test
797  * configure script).
798  */
799 #ifdef NCURSES_VERSION
800 #ifndef HAVE_CURSES_DATA_BOOLNAMES
801 #define HAVE_CURSES_DATA_BOOLNAMES 1
802 #endif
803 #endif
804
805 /*
806  * ncurses uses const in some places where X/Open does (or did) not allow.
807  */
808 #ifdef NCURSES_VERSION
809 #define CONST_MENUS const
810 #else
811 #define CONST_MENUS             /* nothing */
812 #endif
813
814 /*
815  * Simplify setting up demo of threading with these macros.
816  */
817
818 #if HAVE_USE_WINDOW
819 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
820 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
821 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
822 #else
823 #define USING_WINDOW(w,func) func(w)
824 #define USING_WINDOW2(w,func,data) func(w,data)
825 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
826 #endif
827
828 #if HAVE_USE_WINDOW
829 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
830 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
831 #else
832 #define USING_SCREEN(s,func,data) func(data)
833 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
834 #endif
835
836 #ifdef TRACE
837 #define Trace(p) _tracef p
838 #define USE_TRACE 1
839 #else
840 #define Trace(p)                /* nothing */
841 #define USE_TRACE 0
842 #endif
843
844 #define Trace2(p)               /* nothing */
845
846 #define MvAddCh         (void) mvaddch
847 #define MvWAddCh        (void) mvwaddch
848 #define MvAddStr        (void) mvaddstr
849 #define MvWAddStr       (void) mvwaddstr
850 #define MvWAddChStr     (void) mvwaddchstr
851 #define MvPrintw        (void) mvprintw
852 #define MvWPrintw       (void) mvwprintw
853 #define MvHLine         (void) mvhline
854 #define MvWHLine        (void) mvwhline
855 #define MvVLine         (void) mvvline
856 #define MvWVLine        (void) mvwvline
857
858 /*
859  * The macro likely uses unsigned values, while X/Open prototype uses int.
860  */
861 #if defined(wattrset) || defined(PDCURSES)
862 #define AttrArg(p,a)    (attr_t) ((attr_t)(p) | (attr_t)(a))
863 #else
864 #define AttrArg(p,a)    (int) ((attr_t)(p) | (attr_t)(a))
865 #endif
866
867 /*
868  * Workaround for defective implementation of gcc attribute warn_unused_result
869  */
870 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
871 #define IGNORE_RC(func) errno = func
872 #else
873 #define IGNORE_RC(func) (void) func
874 #endif /* gcc workarounds */
875
876 #define init_mb(state)  memset(&state, 0, sizeof(state))
877
878 #endif /* __TEST_PRIV_H */