etip.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright 2018,2020 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.43 2020/02/02 23:34:34 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 <curses.h>
  101. extern "C" {
  102. #if HAVE_VALUES_H
  103. # include <values.h>
  104. #endif
  105. #include <assert.h>
  106. #include <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. // Forward Declarations
  121. class NCURSES_IMPEXP NCursesPanel;
  122. class NCURSES_IMPEXP NCursesMenu;
  123. class NCURSES_IMPEXP NCursesForm;
  124. class NCURSES_IMPEXP NCursesException
  125. {
  126. public:
  127. const char *message;
  128. int errorno;
  129. NCursesException (const char* msg, int err)
  130. : message(msg), errorno (err)
  131. {};
  132. NCursesException (const char* msg)
  133. : message(msg), errorno (E_SYSTEM_ERROR)
  134. {};
  135. NCursesException& operator=(const NCursesException& rhs)
  136. {
  137. errorno = rhs.errorno;
  138. return *this;
  139. }
  140. NCursesException(const NCursesException& rhs)
  141. : message(rhs.message), errorno(rhs.errorno)
  142. {
  143. }
  144. virtual const char *classname() const {
  145. return "NCursesWindow";
  146. }
  147. virtual ~NCursesException()
  148. {
  149. }
  150. };
  151. class NCURSES_IMPEXP NCursesPanelException : public NCursesException
  152. {
  153. public:
  154. const NCursesPanel* p;
  155. NCursesPanelException (const char *msg, int err) :
  156. NCursesException (msg, err),
  157. p (0)
  158. {};
  159. NCursesPanelException (const NCursesPanel* panel,
  160. const char *msg,
  161. int err) :
  162. NCursesException (msg, err),
  163. p (panel)
  164. {};
  165. NCursesPanelException (int err) :
  166. NCursesException ("panel library error", err),
  167. p (0)
  168. {};
  169. NCursesPanelException (const NCursesPanel* panel,
  170. int err) :
  171. NCursesException ("panel library error", err),
  172. p (panel)
  173. {};
  174. NCursesPanelException& operator=(const NCursesPanelException& rhs)
  175. {
  176. if (this != &rhs) {
  177. NCursesException::operator=(rhs);
  178. p = rhs.p;
  179. }
  180. return *this;
  181. }
  182. NCursesPanelException(const NCursesPanelException& rhs)
  183. : NCursesException(rhs), p(rhs.p)
  184. {
  185. }
  186. virtual const char *classname() const {
  187. return "NCursesPanel";
  188. }
  189. virtual ~NCursesPanelException()
  190. {
  191. }
  192. };
  193. class NCURSES_IMPEXP NCursesMenuException : public NCursesException
  194. {
  195. public:
  196. const NCursesMenu* m;
  197. NCursesMenuException (const char *msg, int err) :
  198. NCursesException (msg, err),
  199. m (0)
  200. {};
  201. NCursesMenuException (const NCursesMenu* menu,
  202. const char *msg,
  203. int err) :
  204. NCursesException (msg, err),
  205. m (menu)
  206. {};
  207. NCursesMenuException (int err) :
  208. NCursesException ("menu library error", err),
  209. m (0)
  210. {};
  211. NCursesMenuException (const NCursesMenu* menu,
  212. int err) :
  213. NCursesException ("menu library error", err),
  214. m (menu)
  215. {};
  216. NCursesMenuException& operator=(const NCursesMenuException& rhs)
  217. {
  218. if (this != &rhs) {
  219. NCursesException::operator=(rhs);
  220. m = rhs.m;
  221. }
  222. return *this;
  223. }
  224. NCursesMenuException(const NCursesMenuException& rhs)
  225. : NCursesException(rhs), m(rhs.m)
  226. {
  227. }
  228. virtual const char *classname() const {
  229. return "NCursesMenu";
  230. }
  231. virtual ~NCursesMenuException()
  232. {
  233. }
  234. };
  235. class NCURSES_IMPEXP NCursesFormException : public NCursesException
  236. {
  237. public:
  238. const NCursesForm* f;
  239. NCursesFormException (const char *msg, int err) :
  240. NCursesException (msg, err),
  241. f (0)
  242. {};
  243. NCursesFormException (const NCursesForm* form,
  244. const char *msg,
  245. int err) :
  246. NCursesException (msg, err),
  247. f (form)
  248. {};
  249. NCursesFormException (int err) :
  250. NCursesException ("form library error", err),
  251. f (0)
  252. {};
  253. NCursesFormException (const NCursesForm* form,
  254. int err) :
  255. NCursesException ("form library error", err),
  256. f (form)
  257. {};
  258. NCursesFormException& operator=(const NCursesFormException& rhs)
  259. {
  260. if (this != &rhs) {
  261. NCursesException::operator=(rhs);
  262. f = rhs.f;
  263. }
  264. return *this;
  265. }
  266. NCursesFormException(const NCursesFormException& rhs)
  267. : NCursesException(rhs), f(rhs.f)
  268. {
  269. }
  270. virtual const char *classname() const {
  271. return "NCursesForm";
  272. }
  273. virtual ~NCursesFormException()
  274. {
  275. }
  276. };
  277. #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
  278. # if HAVE_IOSTREAM
  279. # include <iostream>
  280. # if IOSTREAM_NAMESPACE
  281. using std::cerr;
  282. using std::endl;
  283. # endif
  284. # else
  285. # include <iostream.h>
  286. # endif
  287. extern "C" void exit(int);
  288. #endif
  289. inline void THROW(const NCursesException *e) {
  290. #if defined(__GNUG__) && defined(__EXCEPTIONS)
  291. # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
  292. (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
  293. # elif (__GNUG__ >= 7)
  294. // g++ 7.0 warns about deprecation, but lacks the predefined symbols
  295. ::endwin();
  296. std::cerr << "Found a problem - goodbye" << std::endl;
  297. exit(EXIT_FAILURE);
  298. # else
  299. # define CPP_HAS_TRY_CATCH 1
  300. # endif
  301. #elif defined(__SUNPRO_CC)
  302. # if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
  303. genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
  304. # else
  305. # define CPP_HAS_TRY_CATCH 1
  306. # endif
  307. #else
  308. if (e)
  309. cerr << e->message << endl;
  310. exit(0);
  311. #endif
  312. #ifndef CPP_HAS_TRY_CATCH
  313. #define CPP_HAS_TRY_CATCH 0
  314. #define NCURSES_CPP_TRY /* nothing */
  315. #define NCURSES_CPP_CATCH(e) if (false)
  316. #define THROWS(s) /* nothing */
  317. #define THROW2(s,t) /* nothing */
  318. #elif CPP_HAS_TRY_CATCH
  319. throw *e;
  320. #define NCURSES_CPP_TRY try
  321. #define NCURSES_CPP_CATCH(e) catch(e)
  322. #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
  323. // C++17 deprecates the usage of throw().
  324. #define THROWS(s) /* nothing */
  325. #define THROW2(s,t) /* nothing */
  326. #else
  327. #define THROWS(s) throw(s)
  328. #define THROW2(s,t) throw(s,t)
  329. #endif
  330. #endif
  331. }
  332. #endif /* NCURSES_ETIP_H_incl */