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