]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/test.priv.h
ncurses 5.7 - patch 20101113
[ncurses.git] / test / test.priv.h
1 /****************************************************************************
2  * Copyright (c) 1998-2009,2010 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.97 2010/11/13 20:33:36 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_CURSES_VERSION
62 #define HAVE_CURSES_VERSION 0
63 #endif
64
65 #ifndef HAVE_CHGAT
66 #define HAVE_CHGAT 0
67 #endif
68
69 #ifndef HAVE_COLOR_SET
70 #define HAVE_COLOR_SET 0
71 #endif
72
73 #ifndef HAVE_FILTER
74 #define HAVE_FILTER 0
75 #endif
76
77 #ifndef HAVE_FORM_H
78 #define HAVE_FORM_H 0
79 #endif
80
81 #ifndef HAVE_GETBEGX
82 #define HAVE_GETBEGX 0
83 #endif
84
85 #ifndef HAVE_GETCURX
86 #define HAVE_GETCURX 0
87 #endif
88
89 #ifndef HAVE_GETMAXX
90 #define HAVE_GETMAXX 0
91 #endif
92
93 #ifndef HAVE_GETOPT_H
94 #define HAVE_GETOPT_H 0
95 #endif
96
97 #ifndef HAVE_GETPARX
98 #define HAVE_GETPARX 0
99 #endif
100
101 #ifndef HAVE_GETWIN
102 #define HAVE_GETWIN 0
103 #endif
104
105 #ifndef HAVE_LIBFORM
106 #define HAVE_LIBFORM 0
107 #endif
108
109 #ifndef HAVE_LIBMENU
110 #define HAVE_LIBMENU 0
111 #endif
112
113 #ifndef HAVE_LIBPANEL
114 #define HAVE_LIBPANEL 0
115 #endif
116
117 #ifndef HAVE_LOCALE_H
118 #define HAVE_LOCALE_H 0
119 #endif
120
121 #ifndef HAVE_MENU_H
122 #define HAVE_MENU_H 0
123 #endif
124
125 #ifndef HAVE_MVVLINE
126 #define HAVE_MVVLINE 0
127 #endif
128
129 #ifndef HAVE_MVWVLINE
130 #define HAVE_MVWVLINE 0
131 #endif
132
133 #ifndef HAVE_NAPMS
134 #define HAVE_NAPMS 1
135 #endif
136
137 #ifndef HAVE_NC_ALLOC_H
138 #define HAVE_NC_ALLOC_H 0
139 #endif
140
141 #ifndef HAVE_PANEL_H
142 #define HAVE_PANEL_H 0
143 #endif
144
145 #ifndef HAVE_PUTWIN
146 #define HAVE_PUTWIN 0
147 #endif
148
149 #ifndef HAVE_RESIZE_TERM
150 #define HAVE_RESIZE_TERM 0
151 #endif
152
153 #ifndef HAVE_RIPOFFLINE
154 #define HAVE_RIPOFFLINE 0
155 #endif
156
157 #ifndef HAVE_SETUPTERM
158 #define HAVE_SETUPTERM 0
159 #endif
160
161 #ifndef HAVE_SLK_COLOR
162 #define HAVE_SLK_COLOR 0
163 #endif
164
165 #ifndef HAVE_SLK_INIT
166 #define HAVE_SLK_INIT 0
167 #endif
168
169 #ifndef HAVE_TERMATTRS
170 #define HAVE_TERMATTRS 0
171 #endif
172
173 #ifndef HAVE_TERMNAME
174 #define HAVE_TERMNAME 0
175 #endif
176
177 #ifndef HAVE_TGETENT
178 #define HAVE_TGETENT 0
179 #endif
180
181 #ifndef HAVE_TIGETNUM
182 #define HAVE_TIGETNUM 0
183 #endif
184
185 #ifndef HAVE_TYPEAHEAD
186 #define HAVE_TYPEAHEAD 0
187 #endif
188
189 #ifndef HAVE_WINSSTR
190 #define HAVE_WINSSTR 0
191 #endif
192
193 #ifndef HAVE_USE_DEFAULT_COLORS
194 #define HAVE_USE_DEFAULT_COLORS 0
195 #endif
196
197 #ifndef HAVE_WRESIZE
198 #define HAVE_WRESIZE 0
199 #endif
200
201 #ifndef NCURSES_EXT_FUNCS
202 #define NCURSES_EXT_FUNCS 0
203 #endif
204
205 #ifndef NEED_PTEM_H
206 #define NEED_PTEM_H 0
207 #endif
208
209 #ifndef NEED_WCHAR_H
210 #define NEED_WCHAR_H 0
211 #endif
212
213 #ifndef NO_LEAKS
214 #define NO_LEAKS 0
215 #endif
216
217 #include <stdlib.h>
218 #include <stdarg.h>
219 #include <string.h>
220 #include <sys/types.h>
221 #include <errno.h>
222
223 #if HAVE_UNISTD_H
224 #include <unistd.h>
225 #endif
226
227 #include <signal.h>             /* include before curses.h to work around glibc bug */
228
229 #if NEED_WCHAR_H
230 #include <wchar.h>
231 #ifdef HAVE_LIBUTF8_H
232 #include <libutf8.h>
233 #endif
234 #endif
235
236 #if defined(HAVE_XCURSES)
237 #include <xcurses.h>
238 #elif defined(HAVE_NCURSESW_NCURSES_H)
239 #include <ncursesw/curses.h>
240 #elif defined(HAVE_NCURSES_NCURSES_H)
241 #include <ncurses/curses.h>
242 #else
243 #include <curses.h>
244 #endif
245
246 #if defined(HAVE_XCURSES)
247 /* no other headers */
248 #undef  HAVE_SETUPTERM          /* nonfunctional */
249 #define HAVE_SETUPTERM 0
250 #undef  HAVE_TGETENT            /* nonfunctional */
251 #define HAVE_TGETENT 0
252 #undef  HAVE_TIGETSTR           /* nonfunctional */
253 #define HAVE_TIGETSTR 0
254 #elif defined(HAVE_NCURSESW_TERM_H)
255 #include <ncursesw/term.h>
256 #elif defined(HAVE_NCURSES_TERM_H)
257 #include <ncurses/term.h>
258 #elif defined(HAVE_TERM_H)
259 #include <term.h>
260 #endif
261
262 /*
263  * Not all curses.h implementations include unctrl.h,
264  * Solaris 10 xpg4 for example.
265  */
266 #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
267 #if defined(HAVE_NCURSESW_NCURSES_H)
268 #include <ncursesw/unctrl.h>
269 #elif defined(HAVE_NCURSES_NCURSES_H)
270 #include <ncurses/unctrl.h>
271 #else
272 #include <unctrl.h>
273 #endif
274 #endif
275
276 #if HAVE_GETOPT_H
277 #include <getopt.h>
278 #else
279 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
280  * doesn't hurt.
281  */
282 extern char *optarg;
283 extern int optind;
284 #endif /* HAVE_GETOPT_H */
285
286 #if HAVE_LOCALE_H
287 #include <locale.h>
288 #else
289 #define setlocale(name,string)  /* nothing */
290 #endif
291
292 #include <assert.h>
293 #include <ctype.h>
294
295 #ifndef GCC_NORETURN
296 #define GCC_NORETURN            /* nothing */
297 #endif
298 #ifndef GCC_PRINTFLIKE
299 #define GCC_PRINTFLIKE(a,b)     /* nothing */
300 #endif
301 #ifndef GCC_UNUSED
302 #define GCC_UNUSED              /* nothing */
303 #endif
304
305 #ifndef HAVE_GETNSTR
306 #define getnstr(s,n) getstr(s)
307 #endif
308
309 #ifndef USE_SOFTKEYS
310 #if HAVE_SLK_INIT
311 #define USE_SOFTKEYS 1
312 #else
313 #define USE_SOFTKEYS 0
314 #endif
315 #endif
316
317 #ifndef USE_WIDEC_SUPPORT
318 #if (defined(_XOPEN_SOURCE_EXTENDED) || defined(_XPG5)) && defined(WACS_ULCORNER)
319 #define USE_WIDEC_SUPPORT 1
320 #else
321 #define USE_WIDEC_SUPPORT 0
322 #endif
323 #endif
324
325 #if HAVE_PANEL_H && HAVE_LIBPANEL
326 #define USE_LIBPANEL 1
327 #else
328 #define USE_LIBPANEL 0
329 #endif
330
331 #if HAVE_MENU_H && HAVE_LIBMENU
332 #define USE_LIBMENU 1
333 #else
334 #define USE_LIBMENU 0
335 #endif
336
337 #if HAVE_FORM_H && HAVE_LIBFORM
338 #define USE_LIBFORM 1
339 #else
340 #define USE_LIBFORM 0
341 #endif
342
343 #ifndef HAVE_TYPE_ATTR_T
344 #if !USE_WIDEC_SUPPORT && !defined(attr_t)
345 #define attr_t chtype
346 #endif
347 #endif
348
349 #undef NCURSES_CH_T
350 #if !USE_WIDEC_SUPPORT
351 #define NCURSES_CH_T chtype
352 #else
353 #define NCURSES_CH_T cchar_t
354 #endif
355
356 #ifndef NCURSES_OPAQUE
357 #define NCURSES_OPAQUE 0
358 #endif
359
360 #ifndef CCHARW_MAX
361 #define CCHARW_MAX 5
362 #endif
363
364 #undef CTRL
365 #define CTRL(x) ((x) & 0x1f)
366
367 #define QUIT            CTRL('Q')
368 #define ESCAPE          CTRL('[')
369
370 #ifndef KEY_MIN
371 #define KEY_MIN 256             /* not defined in Solaris 8 */
372 #endif
373
374 #ifdef DECL_CURSES_DATA_BOOLNAMES
375 extern char *boolnames[], *boolcodes[], *boolfnames[];
376 extern char *numnames[], *numcodes[], *numfnames[];
377 extern char *strnames[], *strcodes[], *strfnames[];
378 #endif
379
380 #define colored_chtype(ch, attr, pair) \
381         ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
382
383 /*
384  * Workaround for HPUX
385  */
386 #if defined(__hpux) && !defined(NCURSES_VERSION)
387 #define getbegx(w) __getbegx(w)
388 #define getbegy(w) __getbegy(w)
389 #define getcurx(w) __getcurx(w)
390 #define getcury(w) __getcury(w)
391 #define getmaxx(w) __getmaxx(w)
392 #define getmaxy(w) __getmaxy(w)
393 #define getparx(w) __getparx(w)
394 #define getpary(w) __getpary(w)
395 #endif
396
397 /*
398  * Workaround in case getcchar() returns a positive value when the source
399  * string produces only a L'\0'.
400  */
401 #define TEST_CCHAR(s, count, then_stmt, else_stmt) \
402         if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
403             wchar_t test_wch[CCHARW_MAX + 2]; \
404             attr_t test_attrs; \
405             short test_pair; \
406             \
407             if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
408                 && test_wch[0] != L'\0') { \
409                 then_stmt \
410             } else { \
411                 else_stmt \
412             } \
413         } else { \
414             else_stmt \
415         }
416 /*
417  * These usually are implemented as macros, but may be functions.
418  */
419 #if !defined(getcurx) && !HAVE_GETCURX
420 #define getcurx(win)            ((win)?(win)->_curx:ERR)
421 #define getcury(win)            ((win)?(win)->_cury:ERR)
422 #endif
423
424 #if !defined(getbegx) && !HAVE_GETBEGX
425 #define getbegx(win)            ((win)?(win)->_begx:ERR)
426 #define getbegy(win)            ((win)?(win)->_begy:ERR)
427 #endif
428
429 #if !defined(getmaxx) && !HAVE_GETMAXX
430 #define getmaxx(win)            ((win)?((win)->_maxx + 1):ERR)
431 #define getmaxy(win)            ((win)?((win)->_maxy + 1):ERR)
432 #endif
433
434 /*
435  * Solaris 10 xpg4:
436 #define __m_getparx(w)          ((w)->_parent == (WINDOW *) 0 ? -1 \
437                                 : (w)->_begx - (w)->_parent->_begx)
438  */
439 #if !defined(getparx) && !HAVE_GETPARX
440 #ifdef __m_getparx
441 #define getparx(win)            __m_getparx(win)
442 #define getpary(win)            __m_getpary(win)
443 #else
444 #define getparx(win)            ((win)?((win)->_parx + 1):ERR)
445 #define getpary(win)            ((win)?((win)->_pary + 1):ERR)
446 #endif
447 #endif
448
449 #if !defined(mvwvline) && !HAVE_MVWVLINE
450 #define mvwvline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : wvline(w,ch,n))
451 #define mvwhline(w,y,x,ch,n)    (move(y,x) == ERR ? ERR : whline(w,ch,n))
452 #endif
453
454 #if !defined(mvvline) && !HAVE_MVVLINE
455 #define mvvline(y,x,ch,n)       (move(y,x) == ERR ? ERR : vline(ch,n))
456 #define mvhline(y,x,ch,n)       (move(y,x) == ERR ? ERR : hline(ch,n))
457 #endif
458
459 /*
460  * Try to accommodate curses implementations that have no terminfo support.
461  */
462 #if HAVE_TIGETNUM
463 #define TIGETNUM(ti,tc) tigetnum(ti)
464 #else
465 #define TIGETNUM(ti,tc) tgetnum(tc)
466 #endif
467
468 #if HAVE_TIGETSTR
469 #define TIGETSTR(ti,tc) tigetstr(ti)
470 #else
471 #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
472 #endif
473
474 /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
475  * (which is incompatible with legacy usage, doesn't solve any problems).
476  */
477 #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
478 #define tparm2(a,b)   tparm(a,b,0,0,0,0,0,0,0,0)
479
480 #define UChar(c)    ((unsigned char)(c))
481
482 #define SIZEOF(table)   (sizeof(table)/sizeof(table[0]))
483
484 #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
485 #include <nc_alloc.h>
486 #if HAVE_NC_FREEALL && defined(USE_TINFO)
487 #undef ExitProgram
488 #define ExitProgram(code) _nc_free_tinfo(code)
489 #endif
490 #else
491 #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
492 #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
493 #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
494 #endif
495
496 #ifndef ExitProgram
497 #define ExitProgram(code) exit(code)
498 #endif
499
500 #ifndef EXIT_SUCCESS
501 #define EXIT_SUCCESS 0
502 #endif
503 #ifndef EXIT_FAILURE
504 #define EXIT_FAILURE 1
505 #endif
506
507 #ifdef __MINGW32__
508 #include <nc_mingw.h>
509 /* conflicts in test/firstlast.c */
510 #undef large
511 #undef small
512
513 #endif
514
515 /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
516  * curses which doesn't have const parameters declared (so far) in the places
517  * that XSI shows.
518  */
519 #ifndef NCURSES_CONST
520 #define NCURSES_CONST           /* nothing */
521 #endif
522
523 /* out-of-band values for representing absent capabilities */
524 #define ABSENT_BOOLEAN          ((signed char)-1)       /* 255 */
525 #define ABSENT_NUMERIC          (-1)
526 #define ABSENT_STRING           (char *)0
527
528 /* out-of-band values for representing cancels */
529 #define CANCELLED_BOOLEAN       ((signed char)-2)       /* 254 */
530 #define CANCELLED_NUMERIC       (-2)
531 #define CANCELLED_STRING        (char *)(-1)
532
533 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)      /* reject "-1" */
534 #define VALID_NUMERIC(s) ((s) >= 0)
535 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
536
537 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
538
539 #define CATCHALL(handler) { \
540                 int nsig; \
541                 for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
542                     if (nsig != SIGKILL) \
543                         signal(nsig, handler); \
544             }
545
546 /*
547  * Workaround for clean(er) compile with Solaris's legacy curses.
548  * The same would be needed for HPUX 10.20
549  */
550 #ifndef TPUTS_ARG
551 #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
552 #define TPUTS_ARG char
553 extern char *tgoto(char *, int, int);   /* available, but not prototyped */
554 #else
555 #define TPUTS_ARG int
556 #endif
557 #endif
558
559 /*
560  * Workarounds for Solaris's X/Open curses
561  */
562 #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
563 #if !defined(KEY_MIN) && defined(__KEY_MIN)
564 #define KEY_MIN __KEY_MIN
565 #endif
566 #if !defined(KEY_MAX) && defined(__KEY_MIN)
567 #define KEY_MAX __KEY_MAX
568 #endif
569 #endif
570
571 /*
572  * Workaround to build with Sun's default SVr4 curses.
573  */
574 #ifdef NCURSES_VERSION
575 #ifndef HAVE_VW_PRINTW
576 #define HAVE_VW_PRINTW 1
577 #endif
578 #endif
579
580 /*
581  * ncurses provides arrays of capability names; X/Open discarded these SVr4
582  * features.  Some implementations continue to provide them (see the test
583  * configure script).
584  */
585 #ifdef NCURSES_VERSION
586 #ifndef HAVE_CURSES_DATA_BOOLNAMES
587 #define HAVE_CURSES_DATA_BOOLNAMES 1
588 #endif
589 #endif
590
591 /*
592  * ncurses uses const in some places where X/Open does (or did) not allow.
593  */
594 #ifdef NCURSES_VERSION
595 #define CONST_MENUS const
596 #else
597 #define CONST_MENUS             /* nothing */
598 #endif
599
600 #ifndef HAVE_USE_WINDOW
601 #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
602 #define HAVE_USE_WINDOW 0
603 #else
604 #define HAVE_USE_WINDOW 1
605 #endif
606 #endif
607
608 /*
609  * Simplify setting up demo of threading with these macros.
610  */
611
612 #if !HAVE_USE_WINDOW
613 typedef int (*NCURSES_WINDOW_CB) (WINDOW *, void *);
614 typedef int (*NCURSES_SCREEN_CB) (SCREEN *, void *);
615 #endif
616
617 #if HAVE_USE_WINDOW
618 #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
619 #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
620 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
621 #else
622 #define USING_WINDOW(w,func) func(w)
623 #define USING_WINDOW2(w,func,data) func(w,data)
624 #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
625 #endif
626
627 #if HAVE_USE_WINDOW
628 #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
629 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
630 #else
631 #define USING_SCREEN(s,func,data) func(data)
632 #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
633 #endif
634
635 #ifdef TRACE
636 #define Trace(p) _tracef p
637 #define USE_TRACE 1
638 #else
639 #define Trace(p)                /* nothing */
640 #define USE_TRACE 0
641 #endif
642
643 #define MvAddCh         (void) mvaddch
644 #define MvWAddCh        (void) mvwaddch
645 #define MvAddStr        (void) mvaddstr
646 #define MvWAddStr       (void) mvwaddstr
647 #define MvWAddChStr     (void) mvwaddchstr
648 #define MvPrintw        (void) mvprintw
649 #define MvWPrintw       (void) mvwprintw
650 #define MvHLine         (void) mvhline
651 #define MvWHLine        (void) mvwhline
652 #define MvVLine         (void) mvvline
653 #define MvWVLine        (void) mvwvline
654
655 /*
656  * Workaround for defective implementation of gcc attribute warn_unused_result
657  */
658 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
659 #define IGNORE_RC(func) errno = func
660 #else
661 #define IGNORE_RC(func) (void) func
662 #endif /* gcc workarounds */
663
664 #define init_mb(state)  memset(&state, 0, sizeof(state))
665
666 #endif /* __TEST_PRIV_H */