test.priv.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /****************************************************************************
  2. * Copyright (c) 1998-2007,2008 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. * Author: Thomas E. Dickey 1996-on *
  30. ****************************************************************************/
  31. /* $Id: test.priv.h,v 1.79 2008/10/04 21:53:41 tom Exp $ */
  32. #ifndef __TEST_PRIV_H
  33. #define __TEST_PRIV_H 1
  34. #include <ncurses_cfg.h>
  35. /*
  36. * Fix ifdef's that look for the form/menu/panel libraries, if we are building
  37. * with wide-character ncurses.
  38. */
  39. #ifdef HAVE_LIBFORMW
  40. #define HAVE_LIBFORMW 1
  41. #endif
  42. #ifdef HAVE_LIBMENUW
  43. #define HAVE_LIBMENUW 1
  44. #endif
  45. #ifdef HAVE_LIBPANELW
  46. #define HAVE_LIBPANELW 1
  47. #endif
  48. /*
  49. * Fallback definitions to accommodate broken compilers.
  50. */
  51. #ifndef HAVE_CURSES_VERSION
  52. #define HAVE_CURSES_VERSION 0
  53. #endif
  54. #ifndef HAVE_CHGAT
  55. #define HAVE_CHGAT 0
  56. #endif
  57. #ifndef HAVE_COLOR_SET
  58. #define HAVE_COLOR_SET 0
  59. #endif
  60. #ifndef HAVE_FILTER
  61. #define HAVE_FILTER 0
  62. #endif
  63. #ifndef HAVE_FORM_H
  64. #define HAVE_FORM_H 0
  65. #endif
  66. #ifndef HAVE_GETBEGX
  67. #define HAVE_GETBEGX 0
  68. #endif
  69. #ifndef HAVE_GETCURX
  70. #define HAVE_GETCURX 0
  71. #endif
  72. #ifndef HAVE_GETMAXX
  73. #define HAVE_GETMAXX 0
  74. #endif
  75. #ifndef HAVE_GETOPT_H
  76. #define HAVE_GETOPT_H 0
  77. #endif
  78. #ifndef HAVE_GETPARX
  79. #define HAVE_GETPARX 0
  80. #endif
  81. #ifndef HAVE_GETWIN
  82. #define HAVE_GETWIN 0
  83. #endif
  84. #ifndef HAVE_LIBFORM
  85. #define HAVE_LIBFORM 0
  86. #endif
  87. #ifndef HAVE_LIBMENU
  88. #define HAVE_LIBMENU 0
  89. #endif
  90. #ifndef HAVE_LIBPANEL
  91. #define HAVE_LIBPANEL 0
  92. #endif
  93. #ifndef HAVE_LOCALE_H
  94. #define HAVE_LOCALE_H 0
  95. #endif
  96. #ifndef HAVE_MENU_H
  97. #define HAVE_MENU_H 0
  98. #endif
  99. #ifndef HAVE_MVVLINE
  100. #define HAVE_MVVLINE 0
  101. #endif
  102. #ifndef HAVE_MVWVLINE
  103. #define HAVE_MVWVLINE 0
  104. #endif
  105. #ifndef HAVE_NAPMS
  106. #define HAVE_NAPMS 1
  107. #endif
  108. #ifndef HAVE_NC_ALLOC_H
  109. #define HAVE_NC_ALLOC_H 0
  110. #endif
  111. #ifndef HAVE_PANEL_H
  112. #define HAVE_PANEL_H 0
  113. #endif
  114. #ifndef HAVE_PUTWIN
  115. #define HAVE_PUTWIN 0
  116. #endif
  117. #ifndef HAVE_RESIZE_TERM
  118. #define HAVE_RESIZE_TERM 0
  119. #endif
  120. #ifndef HAVE_RIPOFFLINE
  121. #define HAVE_RIPOFFLINE 0
  122. #endif
  123. #ifndef HAVE_SETUPTERM
  124. #define HAVE_SETUPTERM 0
  125. #endif
  126. #ifndef HAVE_SLK_COLOR
  127. #define HAVE_SLK_COLOR 0
  128. #endif
  129. #ifndef HAVE_SLK_INIT
  130. #define HAVE_SLK_INIT 0
  131. #endif
  132. #ifndef HAVE_TERMATTRS
  133. #define HAVE_TERMATTRS 0
  134. #endif
  135. #ifndef HAVE_TERMNAME
  136. #define HAVE_TERMNAME 0
  137. #endif
  138. #ifndef HAVE_TGETENT
  139. #define HAVE_TGETENT 0
  140. #endif
  141. #ifndef HAVE_TIGETNUM
  142. #define HAVE_TIGETNUM 0
  143. #endif
  144. #ifndef HAVE_TYPEAHEAD
  145. #define HAVE_TYPEAHEAD 0
  146. #endif
  147. #ifndef HAVE_TIGETSTR
  148. #define HAVE_TIGETSTR 0
  149. #endif
  150. #ifndef HAVE_WINSSTR
  151. #define HAVE_WINSSTR 0
  152. #endif
  153. #ifndef HAVE_USE_DEFAULT_COLORS
  154. #define HAVE_USE_DEFAULT_COLORS 0
  155. #endif
  156. #ifndef HAVE_WRESIZE
  157. #define HAVE_WRESIZE 0
  158. #endif
  159. #ifndef NCURSES_EXT_FUNCS
  160. #define NCURSES_EXT_FUNCS 0
  161. #endif
  162. #ifndef NEED_PTEM_H
  163. #define NEED_PTEM_H 0
  164. #endif
  165. #ifndef NO_LEAKS
  166. #define NO_LEAKS 0
  167. #endif
  168. #include <stdlib.h>
  169. #include <string.h>
  170. #include <sys/types.h>
  171. #if HAVE_UNISTD_H
  172. #include <unistd.h>
  173. #endif
  174. #include <signal.h> /* include before curses.h to work around glibc bug */
  175. #if defined(HAVE_XCURSES)
  176. #include <xcurses.h>
  177. #elif defined(HAVE_NCURSESW_NCURSES_H)
  178. #include <ncursesw/curses.h>
  179. #elif defined(HAVE_NCURSES_NCURSES_H)
  180. #include <ncurses/curses.h>
  181. #else
  182. #include <curses.h>
  183. #endif
  184. #if defined(HAVE_XCURSES)
  185. /* no other headers */
  186. #undef HAVE_SETUPTERM /* nonfunctional */
  187. #define HAVE_SETUPTERM 0
  188. #undef HAVE_TGETENT /* nonfunctional */
  189. #define HAVE_TGETENT 0
  190. #undef HAVE_TIGETSTR /* nonfunctional */
  191. #define HAVE_TIGETSTR 0
  192. #elif defined(HAVE_NCURSESW_TERM_H)
  193. #include <ncursesw/term.h>
  194. #elif defined(HAVE_NCURSES_TERM_H)
  195. #include <ncurses/term.h>
  196. #elif defined(HAVE_TERM_H)
  197. #include <term.h>
  198. #endif
  199. /*
  200. * Not all curses.h implementations include unctrl.h,
  201. * Solaris 10 xpg4 for example.
  202. */
  203. #if defined(NCURSES_VERSION) || defined(_XOPEN_CURSES)
  204. #if defined(HAVE_NCURSESW_NCURSES_H)
  205. #include <ncursesw/unctrl.h>
  206. #elif defined(HAVE_NCURSES_NCURSES_H)
  207. #include <ncurses/unctrl.h>
  208. #else
  209. #include <unctrl.h>
  210. #endif
  211. #endif
  212. #if HAVE_GETOPT_H
  213. #include <getopt.h>
  214. #else
  215. /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its variables
  216. * doesn't hurt.
  217. */
  218. extern char *optarg;
  219. extern int optind;
  220. #endif /* HAVE_GETOPT_H */
  221. #if HAVE_LOCALE_H
  222. #include <locale.h>
  223. #else
  224. #define setlocale(name,string) /* nothing */
  225. #endif
  226. #include <assert.h>
  227. #include <ctype.h>
  228. #ifndef GCC_NORETURN
  229. #define GCC_NORETURN /* nothing */
  230. #endif
  231. #ifndef GCC_PRINTFLIKE
  232. #define GCC_PRINTFLIKE(a,b) /* nothing */
  233. #endif
  234. #ifndef GCC_UNUSED
  235. #define GCC_UNUSED /* nothing */
  236. #endif
  237. #ifndef HAVE_GETNSTR
  238. #define getnstr(s,n) getstr(s)
  239. #endif
  240. #ifndef USE_SOFTKEYS
  241. #if HAVE_SLK_INIT
  242. #define USE_SOFTKEYS 1
  243. #else
  244. #define USE_SOFTKEYS 0
  245. #endif
  246. #endif
  247. #ifndef USE_WIDEC_SUPPORT
  248. #if defined(_XOPEN_SOURCE_EXTENDED) && defined(WACS_ULCORNER)
  249. #define USE_WIDEC_SUPPORT 1
  250. #else
  251. #define USE_WIDEC_SUPPORT 0
  252. #endif
  253. #endif
  254. #if HAVE_PANEL_H && HAVE_LIBPANEL
  255. #define USE_LIBPANEL 1
  256. #else
  257. #define USE_LIBPANEL 0
  258. #endif
  259. #if HAVE_MENU_H && HAVE_LIBMENU
  260. #define USE_LIBMENU 1
  261. #else
  262. #define USE_LIBMENU 0
  263. #endif
  264. #if HAVE_FORM_H && HAVE_LIBFORM
  265. #define USE_LIBFORM 1
  266. #else
  267. #define USE_LIBFORM 0
  268. #endif
  269. #ifndef HAVE_TYPE_ATTR_T
  270. #if !USE_WIDEC_SUPPORT && !defined(attr_t)
  271. #define attr_t chtype
  272. #endif
  273. #endif
  274. #undef NCURSES_CH_T
  275. #if !USE_WIDEC_SUPPORT
  276. #define NCURSES_CH_T chtype
  277. #else
  278. #define NCURSES_CH_T cchar_t
  279. #endif
  280. #ifndef NCURSES_OPAQUE
  281. #define NCURSES_OPAQUE 0
  282. #endif
  283. #ifndef CCHARW_MAX
  284. #define CCHARW_MAX 5
  285. #endif
  286. #undef CTRL
  287. #define CTRL(x) ((x) & 0x1f)
  288. #define QUIT CTRL('Q')
  289. #define ESCAPE CTRL('[')
  290. #ifndef KEY_MIN
  291. #define KEY_MIN 256 /* not defined in Solaris 8 */
  292. #endif
  293. /*
  294. * Workaround for HPUX
  295. */
  296. #if defined(__hpux) && !defined(NCURSES_VERSION)
  297. #define getbegx(w) __getbegx(w)
  298. #define getbegy(w) __getbegy(w)
  299. #define getcurx(w) __getcurx(w)
  300. #define getcury(w) __getcury(w)
  301. #define getmaxx(w) __getmaxx(w)
  302. #define getmaxy(w) __getmaxy(w)
  303. #define getparx(w) __getparx(w)
  304. #define getpary(w) __getpary(w)
  305. #endif
  306. /*
  307. * These usually are implemented as macros, but may be functions.
  308. */
  309. #if !defined(getcurx) && !HAVE_GETCURX
  310. #define getcurx(win) ((win)?(win)->_curx:ERR)
  311. #define getcury(win) ((win)?(win)->_cury:ERR)
  312. #endif
  313. #if !defined(getbegx) && !HAVE_GETBEGX
  314. #define getbegx(win) ((win)?(win)->_begx:ERR)
  315. #define getbegy(win) ((win)?(win)->_begy:ERR)
  316. #endif
  317. #if !defined(getmaxx) && !HAVE_GETMAXX
  318. #define getmaxx(win) ((win)?((win)->_maxx + 1):ERR)
  319. #define getmaxy(win) ((win)?((win)->_maxy + 1):ERR)
  320. #endif
  321. /*
  322. * Solaris 10 xpg4:
  323. #define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
  324. : (w)->_begx - (w)->_parent->_begx)
  325. */
  326. #if !defined(getparx) && !HAVE_GETPARX
  327. #ifdef __m_getparx
  328. #define getparx(win) __m_getparx(win)
  329. #define getpary(win) __m_getpary(win)
  330. #else
  331. #define getparx(win) ((win)?((win)->_parx + 1):ERR)
  332. #define getpary(win) ((win)?((win)->_pary + 1):ERR)
  333. #endif
  334. #endif
  335. #if !defined(mvwvline) && !HAVE_MVWVLINE
  336. #define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
  337. #define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
  338. #endif
  339. #if !defined(mvvline) && !HAVE_MVVLINE
  340. #define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
  341. #define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
  342. #endif
  343. /*
  344. * Try to accommodate curses implementations that have no terminfo support.
  345. */
  346. #if HAVE_TIGETNUM
  347. #define TIGETNUM(ti,tc) tigetnum(ti)
  348. #else
  349. #define TIGETNUM(ti,tc) tgetnum(tc)
  350. #endif
  351. #if HAVE_TIGETSTR
  352. #define TIGETSTR(ti,tc) tigetstr(ti)
  353. #else
  354. #define TIGETSTR(ti,tc) tgetstr(tc,&area_pointer)
  355. #endif
  356. /* ncurses implements tparm() with varargs, X/Open with a fixed-parameter list
  357. * (which is incompatible with legacy usage, doesn't solve any problems).
  358. */
  359. #define tparm3(a,b,c) tparm(a,b,c,0,0,0,0,0,0,0)
  360. #define tparm2(a,b) tparm(a,b,0,0,0,0,0,0,0,0)
  361. #define UChar(c) ((unsigned char)(c))
  362. #define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
  363. #if defined(NCURSES_VERSION) && HAVE_NC_ALLOC_H
  364. #include <nc_alloc.h>
  365. #if HAVE_NC_FREEALL && defined(USE_TINFO)
  366. #undef ExitProgram
  367. #define ExitProgram(code) _nc_free_tinfo(code)
  368. #endif
  369. #else
  370. #define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
  371. #define typeCalloc(type,elts) (type *) calloc((elts), sizeof(type))
  372. #define typeRealloc(type,n,p) (type *) realloc(p, (n) * sizeof(type))
  373. #endif
  374. #ifndef ExitProgram
  375. #define ExitProgram(code) exit(code)
  376. #endif
  377. #ifndef EXIT_SUCCESS
  378. #define EXIT_SUCCESS 0
  379. #endif
  380. #ifndef EXIT_FAILURE
  381. #define EXIT_FAILURE 1
  382. #endif
  383. /* Use this to quiet gcc's -Wwrite-strings warnings, but accommodate SVr4
  384. * curses which doesn't have const parameters declared (so far) in the places
  385. * that XSI shows.
  386. */
  387. #ifndef NCURSES_CONST
  388. #define NCURSES_CONST /* nothing */
  389. #endif
  390. /* out-of-band values for representing absent capabilities */
  391. #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
  392. #define ABSENT_NUMERIC (-1)
  393. #define ABSENT_STRING (char *)0
  394. /* out-of-band values for representing cancels */
  395. #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
  396. #define CANCELLED_NUMERIC (-2)
  397. #define CANCELLED_STRING (char *)(-1)
  398. #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
  399. #define VALID_NUMERIC(s) ((s) >= 0)
  400. #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
  401. #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
  402. #define CATCHALL(handler) { \
  403. int nsig; \
  404. for (nsig = SIGHUP; nsig < SIGTERM; ++nsig) \
  405. if (nsig != SIGKILL) \
  406. signal(nsig, handler); \
  407. }
  408. /*
  409. * Workaround for clean(er) compile with Solaris's legacy curses.
  410. * The same would be needed for HPUX 10.20
  411. */
  412. #ifndef TPUTS_ARG
  413. #if defined(sun) && !defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
  414. #define TPUTS_ARG char
  415. extern char *tgoto(char *, int, int); /* available, but not prototyped */
  416. #else
  417. #define TPUTS_ARG int
  418. #endif
  419. #endif
  420. /*
  421. * Workarounds for Solaris's X/Open curses
  422. */
  423. #if defined(sun) && defined(_XOPEN_CURSES) && !defined(NCURSES_VERSION_PATCH)
  424. #if !defined(KEY_MIN) && defined(__KEY_MIN)
  425. #define KEY_MIN __KEY_MIN
  426. #endif
  427. #if !defined(KEY_MAX) && defined(__KEY_MIN)
  428. #define KEY_MAX __KEY_MAX
  429. #endif
  430. #endif
  431. /*
  432. * ncurses uses const in some places where X/Open does (or did) not allow.
  433. */
  434. #ifdef NCURSES_VERSION
  435. #define CONST_MENUS const
  436. #else
  437. #define CONST_MENUS /* nothing */
  438. #endif
  439. #ifndef HAVE_USE_WINDOW
  440. #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) || !NCURSES_EXT_FUNCS
  441. #define HAVE_USE_WINDOW 0
  442. #else
  443. #define HAVE_USE_WINDOW 1
  444. #endif
  445. #endif
  446. /*
  447. * Simplify setting up demo of threading with these macros.
  448. */
  449. #if !HAVE_USE_WINDOW
  450. typedef int (*NCURSES_WINDOW_CB)(WINDOW *, void *);
  451. typedef int (*NCURSES_SCREEN_CB)(SCREEN *, void *);
  452. #endif
  453. #if HAVE_USE_WINDOW
  454. #define USING_WINDOW(w,func) use_window(w, (NCURSES_WINDOW_CB) func, w)
  455. #define USING_WINDOW2(w,func,data) use_window(w, (NCURSES_WINDOW_CB) func, data)
  456. #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
  457. #else
  458. #define USING_WINDOW(w,func) func(w)
  459. #define USING_WINDOW2(w,func,data) func(w,data)
  460. #define WANT_USE_WINDOW() extern void _nc_want_use_window(void)
  461. #endif
  462. #if HAVE_USE_WINDOW
  463. #define USING_SCREEN(s,func,data) use_screen(s, (NCURSES_SCREEN_CB) func, data)
  464. #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
  465. #else
  466. #define USING_SCREEN(s,func,data) func(s,data)
  467. #define WANT_USE_SCREEN() extern void _nc_want_use_screen(void)
  468. #endif
  469. #ifdef TRACE
  470. #define Trace(p) _tracef p
  471. #define USE_TRACE 1
  472. #else
  473. #define Trace(p) /* nothing */
  474. #define USE_TRACE 0
  475. #endif
  476. #define init_mb(state) memset(&state, 0, sizeof(state))
  477. #endif /* __TEST_PRIV_H */