etip.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright 2018-2021,2022 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.50 2022/08/20 20:50:00 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_OVERRIDE
  62. #define CPP_HAS_OVERRIDE 0
  63. #endif
  64. #ifndef CPP_HAS_PARAM_INIT
  65. #define CPP_HAS_PARAM_INIT 0
  66. #endif
  67. #ifndef CPP_HAS_STATIC_CAST
  68. #define CPP_HAS_STATIC_CAST 1
  69. #endif
  70. #ifndef IOSTREAM_NAMESPACE
  71. #define IOSTREAM_NAMESPACE 1
  72. #endif
  73. #ifdef __GNUG__
  74. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  75. # if HAVE_TYPEINFO
  76. # include <typeinfo>
  77. # endif
  78. # endif
  79. #endif
  80. #if defined(__GNUG__)
  81. # if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
  82. # if ETIP_NEEDS_MATH_H
  83. # if ETIP_NEEDS_MATH_EXCEPTION
  84. # undef exception
  85. # define exception math_exception
  86. # endif
  87. # include <math.h>
  88. # endif
  89. # undef exception
  90. # define exception builtin_exception
  91. # if HAVE_GPP_BUILTIN_H
  92. # include <gpp/builtin.h>
  93. # elif HAVE_GXX_BUILTIN_H
  94. # include <g++/builtin.h>
  95. # else
  96. # include <builtin.h>
  97. # endif
  98. # undef exception
  99. # endif
  100. #elif defined (__SUNPRO_CC)
  101. # include <generic.h>
  102. #endif
  103. #include <ncursesw/curses.h>
  104. extern "C" {
  105. #if HAVE_VALUES_H
  106. # include <values.h>
  107. #endif
  108. #include <assert.h>
  109. #include <ncursesw/eti.h>
  110. #include <errno.h>
  111. }
  112. // Language features
  113. #if CPP_HAS_OVERRIDE
  114. #define NCURSES_OVERRIDE override
  115. #else
  116. #define NCURSES_OVERRIDE /*nothing*/
  117. #endif
  118. #if CPP_HAS_PARAM_INIT
  119. #define NCURSES_PARAM_INIT(value) = value
  120. #else
  121. #define NCURSES_PARAM_INIT(value) /*nothing*/
  122. #endif
  123. #if CPP_HAS_STATIC_CAST
  124. #define STATIC_CAST(s) static_cast<s>
  125. #else
  126. #define STATIC_CAST(s) (s)
  127. #endif
  128. #ifndef NCURSES_CXX_IMPEXP
  129. #define NCURSES_CXX_IMPEXP /* nothing */
  130. #endif
  131. // Forward Declarations
  132. class NCURSES_CXX_IMPEXP NCursesPanel;
  133. class NCURSES_CXX_IMPEXP NCursesMenu;
  134. class NCURSES_CXX_IMPEXP NCursesForm;
  135. class NCURSES_CXX_IMPEXP NCursesException
  136. {
  137. public:
  138. const char *message;
  139. int errorno;
  140. NCursesException (const char* msg, int err)
  141. : message(msg), errorno (err)
  142. {};
  143. explicit NCursesException (const char* msg)
  144. : message(msg), errorno (E_SYSTEM_ERROR)
  145. {};
  146. NCursesException& operator=(const NCursesException& rhs)
  147. {
  148. message = rhs.message;
  149. errorno = rhs.errorno;
  150. return *this;
  151. }
  152. NCursesException(const NCursesException& rhs)
  153. : message(rhs.message), errorno(rhs.errorno)
  154. {
  155. }
  156. virtual const char *classname() const {
  157. return "NCursesWindow";
  158. }
  159. virtual ~NCursesException()
  160. {
  161. }
  162. };
  163. class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
  164. {
  165. public:
  166. const NCursesPanel* p;
  167. NCursesPanelException (const char *msg, int err) :
  168. NCursesException (msg, err),
  169. p (0)
  170. {};
  171. NCursesPanelException (const NCursesPanel* panel,
  172. const char *msg,
  173. int err) :
  174. NCursesException (msg, err),
  175. p (panel)
  176. {};
  177. explicit NCursesPanelException (int err) :
  178. NCursesException ("panel library error", err),
  179. p (0)
  180. {};
  181. NCursesPanelException (const NCursesPanel* panel,
  182. int err) :
  183. NCursesException ("panel library error", err),
  184. p (panel)
  185. {};
  186. NCursesPanelException& operator=(const NCursesPanelException& rhs)
  187. {
  188. if (this != &rhs) {
  189. NCursesException::operator=(rhs);
  190. p = rhs.p;
  191. }
  192. return *this;
  193. }
  194. NCursesPanelException(const NCursesPanelException& rhs)
  195. : NCursesException(rhs), p(rhs.p)
  196. {
  197. }
  198. virtual const char *classname() const NCURSES_OVERRIDE {
  199. return "NCursesPanel";
  200. }
  201. virtual ~NCursesPanelException()
  202. {
  203. }
  204. };
  205. class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
  206. {
  207. public:
  208. const NCursesMenu* m;
  209. NCursesMenuException (const char *msg, int err) :
  210. NCursesException (msg, err),
  211. m (0)
  212. {};
  213. NCursesMenuException (const NCursesMenu* menu,
  214. const char *msg,
  215. int err) :
  216. NCursesException (msg, err),
  217. m (menu)
  218. {};
  219. explicit NCursesMenuException (int err) :
  220. NCursesException ("menu library error", err),
  221. m (0)
  222. {};
  223. NCursesMenuException (const NCursesMenu* menu,
  224. int err) :
  225. NCursesException ("menu library error", err),
  226. m (menu)
  227. {};
  228. NCursesMenuException& operator=(const NCursesMenuException& rhs)
  229. {
  230. if (this != &rhs) {
  231. NCursesException::operator=(rhs);
  232. m = rhs.m;
  233. }
  234. return *this;
  235. }
  236. NCursesMenuException(const NCursesMenuException& rhs)
  237. : NCursesException(rhs), m(rhs.m)
  238. {
  239. }
  240. virtual const char *classname() const NCURSES_OVERRIDE {
  241. return "NCursesMenu";
  242. }
  243. virtual ~NCursesMenuException()
  244. {
  245. }
  246. };
  247. class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
  248. {
  249. public:
  250. const NCursesForm* f;
  251. NCursesFormException (const char *msg, int err) :
  252. NCursesException (msg, err),
  253. f (0)
  254. {};
  255. NCursesFormException (const NCursesForm* form,
  256. const char *msg,
  257. int err) :
  258. NCursesException (msg, err),
  259. f (form)
  260. {};
  261. explicit NCursesFormException (int err) :
  262. NCursesException ("form library error", err),
  263. f (0)
  264. {};
  265. NCursesFormException (const NCursesForm* form,
  266. int err) :
  267. NCursesException ("form library error", err),
  268. f (form)
  269. {};
  270. NCursesFormException& operator=(const NCursesFormException& rhs)
  271. {
  272. if (this != &rhs) {
  273. NCursesException::operator=(rhs);
  274. f = rhs.f;
  275. }
  276. return *this;
  277. }
  278. NCursesFormException(const NCursesFormException& rhs)
  279. : NCursesException(rhs), f(rhs.f)
  280. {
  281. }
  282. virtual const char *classname() const NCURSES_OVERRIDE {
  283. return "NCursesForm";
  284. }
  285. virtual ~NCursesFormException()
  286. {
  287. }
  288. };
  289. #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
  290. # if HAVE_IOSTREAM
  291. # include <iostream>
  292. # if IOSTREAM_NAMESPACE
  293. using std::cerr;
  294. using std::endl;
  295. # endif
  296. # else
  297. # include <iostream.h>
  298. # endif
  299. #endif
  300. inline void THROW(const NCursesException *e) {
  301. #if defined(__GNUG__) && defined(__EXCEPTIONS)
  302. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  303. (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
  304. # elif (__GNUG__ >= 7)
  305. // g++ 7.0 warns about deprecation, but lacks the predefined symbols
  306. ::endwin();
  307. std::cerr << "Found a problem - goodbye" << std::endl;
  308. exit(EXIT_FAILURE);
  309. # else
  310. # define CPP_HAS_TRY_CATCH 1
  311. # endif
  312. #elif defined(__SUNPRO_CC)
  313. # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
  314. genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
  315. # else
  316. # define CPP_HAS_TRY_CATCH 1
  317. # endif
  318. #else
  319. if (e)
  320. cerr << e->message << endl;
  321. exit(0);
  322. #endif
  323. #ifndef CPP_HAS_TRY_CATCH
  324. #define CPP_HAS_TRY_CATCH 0
  325. #define NCURSES_CPP_TRY /* nothing */
  326. #define NCURSES_CPP_CATCH(e) if (false)
  327. #define THROWS(s) /* nothing */
  328. #define THROW2(s,t) /* nothing */
  329. #elif CPP_HAS_TRY_CATCH
  330. throw *e;
  331. #define NCURSES_CPP_TRY try
  332. #define NCURSES_CPP_CATCH(e) catch(e)
  333. #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
  334. // C++17 deprecates the usage of throw().
  335. #define THROWS(s) /* nothing */
  336. #define THROW2(s,t) /* nothing */
  337. #else
  338. #define THROWS(s) throw(s)
  339. #define THROW2(s,t) throw(s,t)
  340. #endif
  341. #endif
  342. }
  343. #endif /* NCURSES_ETIP_H_incl */