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