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