etip.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright 2018-2020,2021 Thomas E. Dickey *
  4. * Copyright 1998-2012,2017 Free Software Foundation, Inc. *
  5. * *
  6. * Permission is hereby granted, free of charge, to any person obtaining a *
  7. * copy of this software and associated documentation files (the *
  8. * "Software"), to deal in the Software without restriction, including *
  9. * without limitation the rights to use, copy, modify, merge, publish, *
  10. * distribute, distribute with modifications, sublicense, and/or sell *
  11. * copies of the Software, and to permit persons to whom the Software is *
  12. * furnished to do so, subject to the following conditions: *
  13. * *
  14. * The above copyright notice and this permission notice shall be included *
  15. * in all copies or substantial portions of the Software. *
  16. * *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  20. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  21. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  23. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  24. * *
  25. * Except as contained in this notice, the name(s) of the above copyright *
  26. * holders shall not be used in advertising or otherwise to promote the *
  27. * sale, use or other dealings in this Software without prior written *
  28. * authorization. *
  29. ****************************************************************************/
  30. /****************************************************************************
  31. * Author: Juergen Pfeifer, 1997 *
  32. ****************************************************************************/
  33. // $Id: etip.h.in,v 1.48 2021/06/17 21:11:08 tom Exp $
  34. #ifndef NCURSES_ETIP_H_incl
  35. #define NCURSES_ETIP_H_incl 1
  36. // These are substituted at configure/build time
  37. #ifndef HAVE_BUILTIN_H
  38. #define HAVE_BUILTIN_H 0
  39. #endif
  40. #ifndef HAVE_GXX_BUILTIN_H
  41. #define HAVE_GXX_BUILTIN_H 0
  42. #endif
  43. #ifndef HAVE_GPP_BUILTIN_H
  44. #define HAVE_GPP_BUILTIN_H 0
  45. #endif
  46. #ifndef HAVE_IOSTREAM
  47. #define HAVE_IOSTREAM 1
  48. #endif
  49. #ifndef HAVE_TYPEINFO
  50. #define HAVE_TYPEINFO 1
  51. #endif
  52. #ifndef HAVE_VALUES_H
  53. #define HAVE_VALUES_H 0
  54. #endif
  55. #ifndef ETIP_NEEDS_MATH_H
  56. #define ETIP_NEEDS_MATH_H 0
  57. #endif
  58. #ifndef ETIP_NEEDS_MATH_EXCEPTION
  59. #define ETIP_NEEDS_MATH_EXCEPTION 0
  60. #endif
  61. #ifndef CPP_HAS_PARAM_INIT
  62. #define CPP_HAS_PARAM_INIT 0
  63. #endif
  64. #ifndef CPP_HAS_STATIC_CAST
  65. #define CPP_HAS_STATIC_CAST 1
  66. #endif
  67. #ifndef IOSTREAM_NAMESPACE
  68. #define IOSTREAM_NAMESPACE 1
  69. #endif
  70. #ifdef __GNUG__
  71. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  72. # if HAVE_TYPEINFO
  73. # include <typeinfo>
  74. # endif
  75. # endif
  76. #endif
  77. #if defined(__GNUG__)
  78. # if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
  79. # if ETIP_NEEDS_MATH_H
  80. # if ETIP_NEEDS_MATH_EXCEPTION
  81. # undef exception
  82. # define exception math_exception
  83. # endif
  84. # include <math.h>
  85. # endif
  86. # undef exception
  87. # define exception builtin_exception
  88. # if HAVE_GPP_BUILTIN_H
  89. # include <gpp/builtin.h>
  90. # elif HAVE_GXX_BUILTIN_H
  91. # include <g++/builtin.h>
  92. # else
  93. # include <builtin.h>
  94. # endif
  95. # undef exception
  96. # endif
  97. #elif defined (__SUNPRO_CC)
  98. # include <generic.h>
  99. #endif
  100. #include <ncursesw/curses.h>
  101. extern "C" {
  102. #if HAVE_VALUES_H
  103. # include <values.h>
  104. #endif
  105. #include <assert.h>
  106. #include <ncursesw/eti.h>
  107. #include <errno.h>
  108. }
  109. // Language features
  110. #if CPP_HAS_PARAM_INIT
  111. #define NCURSES_PARAM_INIT(value) = value
  112. #else
  113. #define NCURSES_PARAM_INIT(value) /*nothing*/
  114. #endif
  115. #if CPP_HAS_STATIC_CAST
  116. #define STATIC_CAST(s) static_cast<s>
  117. #else
  118. #define STATIC_CAST(s) (s)
  119. #endif
  120. #ifndef NCURSES_CXX_IMPEXP
  121. #define NCURSES_CXX_IMPEXP /* nothing */
  122. #endif
  123. // Forward Declarations
  124. class NCURSES_CXX_IMPEXP NCursesPanel;
  125. class NCURSES_CXX_IMPEXP NCursesMenu;
  126. class NCURSES_CXX_IMPEXP NCursesForm;
  127. class NCURSES_CXX_IMPEXP NCursesException
  128. {
  129. public:
  130. const char *message;
  131. int errorno;
  132. NCursesException (const char* msg, int err)
  133. : message(msg), errorno (err)
  134. {};
  135. explicit NCursesException (const char* msg)
  136. : message(msg), errorno (E_SYSTEM_ERROR)
  137. {};
  138. NCursesException& operator=(const NCursesException& rhs)
  139. {
  140. message = rhs.message;
  141. errorno = rhs.errorno;
  142. return *this;
  143. }
  144. NCursesException(const NCursesException& rhs)
  145. : message(rhs.message), errorno(rhs.errorno)
  146. {
  147. }
  148. virtual const char *classname() const {
  149. return "NCursesWindow";
  150. }
  151. virtual ~NCursesException()
  152. {
  153. }
  154. };
  155. class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
  156. {
  157. public:
  158. const NCursesPanel* p;
  159. NCursesPanelException (const char *msg, int err) :
  160. NCursesException (msg, err),
  161. p (0)
  162. {};
  163. NCursesPanelException (const NCursesPanel* panel,
  164. const char *msg,
  165. int err) :
  166. NCursesException (msg, err),
  167. p (panel)
  168. {};
  169. explicit NCursesPanelException (int err) :
  170. NCursesException ("panel library error", err),
  171. p (0)
  172. {};
  173. NCursesPanelException (const NCursesPanel* panel,
  174. int err) :
  175. NCursesException ("panel library error", err),
  176. p (panel)
  177. {};
  178. NCursesPanelException& operator=(const NCursesPanelException& rhs)
  179. {
  180. if (this != &rhs) {
  181. NCursesException::operator=(rhs);
  182. p = rhs.p;
  183. }
  184. return *this;
  185. }
  186. NCursesPanelException(const NCursesPanelException& rhs)
  187. : NCursesException(rhs), p(rhs.p)
  188. {
  189. }
  190. virtual const char *classname() const {
  191. return "NCursesPanel";
  192. }
  193. virtual ~NCursesPanelException()
  194. {
  195. }
  196. };
  197. class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
  198. {
  199. public:
  200. const NCursesMenu* m;
  201. NCursesMenuException (const char *msg, int err) :
  202. NCursesException (msg, err),
  203. m (0)
  204. {};
  205. NCursesMenuException (const NCursesMenu* menu,
  206. const char *msg,
  207. int err) :
  208. NCursesException (msg, err),
  209. m (menu)
  210. {};
  211. explicit NCursesMenuException (int err) :
  212. NCursesException ("menu library error", err),
  213. m (0)
  214. {};
  215. NCursesMenuException (const NCursesMenu* menu,
  216. int err) :
  217. NCursesException ("menu library error", err),
  218. m (menu)
  219. {};
  220. NCursesMenuException& operator=(const NCursesMenuException& rhs)
  221. {
  222. if (this != &rhs) {
  223. NCursesException::operator=(rhs);
  224. m = rhs.m;
  225. }
  226. return *this;
  227. }
  228. NCursesMenuException(const NCursesMenuException& rhs)
  229. : NCursesException(rhs), m(rhs.m)
  230. {
  231. }
  232. virtual const char *classname() const {
  233. return "NCursesMenu";
  234. }
  235. virtual ~NCursesMenuException()
  236. {
  237. }
  238. };
  239. class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
  240. {
  241. public:
  242. const NCursesForm* f;
  243. NCursesFormException (const char *msg, int err) :
  244. NCursesException (msg, err),
  245. f (0)
  246. {};
  247. NCursesFormException (const NCursesForm* form,
  248. const char *msg,
  249. int err) :
  250. NCursesException (msg, err),
  251. f (form)
  252. {};
  253. explicit NCursesFormException (int err) :
  254. NCursesException ("form library error", err),
  255. f (0)
  256. {};
  257. NCursesFormException (const NCursesForm* form,
  258. int err) :
  259. NCursesException ("form library error", err),
  260. f (form)
  261. {};
  262. NCursesFormException& operator=(const NCursesFormException& rhs)
  263. {
  264. if (this != &rhs) {
  265. NCursesException::operator=(rhs);
  266. f = rhs.f;
  267. }
  268. return *this;
  269. }
  270. NCursesFormException(const NCursesFormException& rhs)
  271. : NCursesException(rhs), f(rhs.f)
  272. {
  273. }
  274. virtual const char *classname() const {
  275. return "NCursesForm";
  276. }
  277. virtual ~NCursesFormException()
  278. {
  279. }
  280. };
  281. #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
  282. # if HAVE_IOSTREAM
  283. # include <iostream>
  284. # if IOSTREAM_NAMESPACE
  285. using std::cerr;
  286. using std::endl;
  287. # endif
  288. # else
  289. # include <iostream.h>
  290. # endif
  291. #endif
  292. inline void THROW(const NCursesException *e) {
  293. #if defined(__GNUG__) && defined(__EXCEPTIONS)
  294. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  295. (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
  296. # elif (__GNUG__ >= 7)
  297. // g++ 7.0 warns about deprecation, but lacks the predefined symbols
  298. ::endwin();
  299. std::cerr << "Found a problem - goodbye" << std::endl;
  300. exit(EXIT_FAILURE);
  301. # else
  302. # define CPP_HAS_TRY_CATCH 1
  303. # endif
  304. #elif defined(__SUNPRO_CC)
  305. # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
  306. genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
  307. # else
  308. # define CPP_HAS_TRY_CATCH 1
  309. # endif
  310. #else
  311. if (e)
  312. cerr << e->message << endl;
  313. exit(0);
  314. #endif
  315. #ifndef CPP_HAS_TRY_CATCH
  316. #define CPP_HAS_TRY_CATCH 0
  317. #define NCURSES_CPP_TRY /* nothing */
  318. #define NCURSES_CPP_CATCH(e) if (false)
  319. #define THROWS(s) /* nothing */
  320. #define THROW2(s,t) /* nothing */
  321. #elif CPP_HAS_TRY_CATCH
  322. throw *e;
  323. #define NCURSES_CPP_TRY try
  324. #define NCURSES_CPP_CATCH(e) catch(e)
  325. #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
  326. // C++17 deprecates the usage of throw().
  327. #define THROWS(s) /* nothing */
  328. #define THROW2(s,t) /* nothing */
  329. #else
  330. #define THROWS(s) throw(s)
  331. #define THROW2(s,t) throw(s,t)
  332. #endif
  333. #endif
  334. }
  335. #endif /* NCURSES_ETIP_H_incl */