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