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