Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-04 08:43:55

0001 // * This makes emacs happy -*-Mode: C++;-*-
0002 /****************************************************************************
0003  * Copyright 2018-2024,2025 Thomas E. Dickey                                *
0004  * Copyright 1998-2012,2017 Free Software Foundation, Inc.                  *
0005  *                                                                          *
0006  * Permission is hereby granted, free of charge, to any person obtaining a  *
0007  * copy of this software and associated documentation files (the            *
0008  * "Software"), to deal in the Software without restriction, including      *
0009  * without limitation the rights to use, copy, modify, merge, publish,      *
0010  * distribute, distribute with modifications, sublicense, and/or sell       *
0011  * copies of the Software, and to permit persons to whom the Software is    *
0012  * furnished to do so, subject to the following conditions:                 *
0013  *                                                                          *
0014  * The above copyright notice and this permission notice shall be included  *
0015  * in all copies or substantial portions of the Software.                   *
0016  *                                                                          *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
0018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
0019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
0020  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
0021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
0022  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
0023  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
0024  *                                                                          *
0025  * Except as contained in this notice, the name(s) of the above copyright   *
0026  * holders shall not be used in advertising or otherwise to promote the     *
0027  * sale, use or other dealings in this Software without prior written       *
0028  * authorization.                                                           *
0029  ****************************************************************************/
0030 
0031 /****************************************************************************
0032  *   Author: Juergen Pfeifer, 1997                                          *
0033  ****************************************************************************/
0034 
0035 // $Id: etip.h.in,v 1.55 2025/02/08 23:39:52 tom Exp $
0036 
0037 #ifndef NCURSES_ETIP_H_incl
0038 #define NCURSES_ETIP_H_incl 1
0039 
0040 // These are substituted at configure/build time
0041 #ifndef HAVE_BUILTIN_H
0042 #define HAVE_BUILTIN_H 0
0043 #endif
0044 
0045 #ifndef HAVE_EXCEPTION
0046 #define HAVE_EXCEPTION 1
0047 #endif
0048 
0049 #ifndef HAVE_GXX_BUILTIN_H
0050 #define HAVE_GXX_BUILTIN_H 0
0051 #endif
0052 
0053 #ifndef HAVE_GPP_BUILTIN_H
0054 #define HAVE_GPP_BUILTIN_H 0
0055 #endif
0056 
0057 #ifndef HAVE_IOSTREAM
0058 #define HAVE_IOSTREAM 1
0059 #endif
0060 
0061 #ifndef HAVE_NEW
0062 #define HAVE_NEW 1
0063 #endif
0064 
0065 #ifndef HAVE_TYPEINFO
0066 #define HAVE_TYPEINFO 1
0067 #endif
0068 
0069 #ifndef HAVE_VALUES_H
0070 #define HAVE_VALUES_H 0
0071 #endif
0072 
0073 #ifndef ETIP_NEEDS_MATH_H
0074 #define ETIP_NEEDS_MATH_H 0
0075 #endif
0076 
0077 #ifndef ETIP_NEEDS_MATH_EXCEPTION
0078 #define ETIP_NEEDS_MATH_EXCEPTION 0
0079 #endif
0080 
0081 #ifndef CPP_HAS_OVERRIDE
0082 #define CPP_HAS_OVERRIDE 0
0083 #endif
0084 
0085 #ifndef CPP_HAS_PARAM_INIT
0086 #define CPP_HAS_PARAM_INIT 0
0087 #endif
0088 
0089 #ifndef CPP_HAS_STATIC_CAST
0090 #define CPP_HAS_STATIC_CAST 1
0091 #endif
0092 
0093 #ifndef IOSTREAM_NAMESPACE
0094 #define IOSTREAM_NAMESPACE 1
0095 #endif
0096 
0097 #ifdef __GNUG__
0098 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
0099 #    if HAVE_TYPEINFO
0100 #      include <typeinfo>
0101 #    endif
0102 #  endif
0103 #endif
0104 
0105 #include <exception>
0106 
0107 #if defined(__GNUG__)
0108 #  if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
0109 #    if ETIP_NEEDS_MATH_H
0110 #      if ETIP_NEEDS_MATH_EXCEPTION
0111 #        undef exception
0112 #        define exception math_exception
0113 #      endif
0114 #      include <math.h>
0115 #    endif
0116 #    undef exception
0117 #    define exception builtin_exception
0118 #    if HAVE_GPP_BUILTIN_H
0119 #     include <gpp/builtin.h>
0120 #    elif HAVE_GXX_BUILTIN_H
0121 #     include <g++/builtin.h>
0122 #    else
0123 #     include <builtin.h>
0124 #    endif
0125 #    undef exception
0126 #  endif
0127 #elif defined (__SUNPRO_CC)
0128 #  include <generic.h>
0129 #endif
0130 
0131 #if HAVE_EXCEPTION
0132 # include <exception>
0133 #endif
0134 #if HAVE_NEW
0135 # include <new>
0136 #endif
0137 
0138 // This used to include <ncurses/curses.h>, but Apple's configuration as of 2024
0139 // provides only a broken version of ncurses's header, which interferes
0140 // with the configure script.
0141 
0142 extern "C" {
0143 #if HAVE_VALUES_H
0144 #  include <values.h>
0145 #endif
0146 
0147 #include <assert.h>
0148 #include <ncurses/eti.h>
0149 #include <errno.h>
0150 
0151 #ifndef HAVE_CONFIG_H
0152 int endwin(void);   // needed for the configure check
0153 #endif
0154 }
0155 
0156 // Language features
0157 #if CPP_HAS_OVERRIDE
0158 #define NCURSES_OVERRIDE override
0159 #else
0160 #define NCURSES_OVERRIDE /*nothing*/
0161 #endif
0162 
0163 #if CPP_HAS_PARAM_INIT
0164 #define NCURSES_PARAM_INIT(value) = value
0165 #else
0166 #define NCURSES_PARAM_INIT(value) /*nothing*/
0167 #endif
0168 
0169 #if CPP_HAS_STATIC_CAST
0170 #define STATIC_CAST(s) static_cast<s>
0171 #else
0172 #define STATIC_CAST(s) (s)
0173 #endif
0174 
0175 #ifndef NCURSES_CXX_IMPEXP
0176 #define NCURSES_CXX_IMPEXP  /* nothing */
0177 #endif
0178 
0179 // Forward Declarations
0180 class NCURSES_CXX_IMPEXP NCursesPanel;
0181 class NCURSES_CXX_IMPEXP NCursesMenu;
0182 class NCURSES_CXX_IMPEXP NCursesForm;
0183 
0184 class NCURSES_CXX_IMPEXP NCursesException
0185 {
0186 public:
0187   const char *message;
0188   int errorno;
0189 
0190   NCursesException (const char* msg, int err)
0191     : message(msg), errorno (err)
0192     {};
0193 
0194   explicit NCursesException (const char* msg)
0195     : message(msg), errorno (E_SYSTEM_ERROR)
0196     {};
0197 
0198   NCursesException& operator=(const NCursesException& rhs)
0199   {
0200     message = rhs.message;
0201     errorno = rhs.errorno;
0202     return *this;
0203   }
0204 
0205   NCursesException(const NCursesException& rhs)
0206     : message(rhs.message), errorno(rhs.errorno)
0207   {
0208   }
0209 
0210   virtual const char *classname() const {
0211     return "NCursesWindow";
0212   }
0213 
0214   virtual ~NCursesException()
0215   {
0216   }
0217 };
0218 
0219 class NCURSES_CXX_IMPEXP NCursesPanelException : public NCursesException
0220 {
0221 public:
0222   const NCursesPanel* p;
0223 
0224   NCursesPanelException (const char *msg, int err) :
0225     NCursesException (msg, err),
0226     p (NULL)
0227     {};
0228 
0229   NCursesPanelException (const NCursesPanel* panel,
0230              const char *msg,
0231              int err) :
0232     NCursesException (msg, err),
0233     p (panel)
0234     {};
0235 
0236   explicit NCursesPanelException (int err) :
0237     NCursesException ("panel library error", err),
0238     p (NULL)
0239     {};
0240 
0241   NCursesPanelException (const NCursesPanel* panel,
0242              int err) :
0243     NCursesException ("panel library error", err),
0244     p (panel)
0245     {};
0246 
0247   NCursesPanelException& operator=(const NCursesPanelException& rhs)
0248   {
0249     if (this != &rhs) {
0250       NCursesException::operator=(rhs);
0251       p = rhs.p;
0252     }
0253     return *this;
0254   }
0255 
0256   NCursesPanelException(const NCursesPanelException& rhs)
0257     : NCursesException(rhs), p(rhs.p)
0258   {
0259   }
0260 
0261   virtual const char *classname() const NCURSES_OVERRIDE {
0262     return "NCursesPanel";
0263   }
0264 
0265   virtual ~NCursesPanelException()
0266   {
0267   }
0268 };
0269 
0270 class NCURSES_CXX_IMPEXP NCursesMenuException : public NCursesException
0271 {
0272 public:
0273   const NCursesMenu* m;
0274 
0275   NCursesMenuException (const char *msg, int err) :
0276     NCursesException (msg, err),
0277     m (NULL)
0278     {};
0279 
0280   NCursesMenuException (const NCursesMenu* menu,
0281             const char *msg,
0282             int err) :
0283     NCursesException (msg, err),
0284     m (menu)
0285     {};
0286 
0287   explicit NCursesMenuException (int err) :
0288     NCursesException ("menu library error", err),
0289     m (NULL)
0290     {};
0291 
0292   NCursesMenuException (const NCursesMenu* menu,
0293             int err) :
0294     NCursesException ("menu library error", err),
0295     m (menu)
0296     {};
0297 
0298   NCursesMenuException& operator=(const NCursesMenuException& rhs)
0299   {
0300     if (this != &rhs) {
0301       NCursesException::operator=(rhs);
0302       m = rhs.m;
0303     }
0304     return *this;
0305   }
0306 
0307   NCursesMenuException(const NCursesMenuException& rhs)
0308     : NCursesException(rhs), m(rhs.m)
0309   {
0310   }
0311 
0312   virtual const char *classname() const NCURSES_OVERRIDE {
0313     return "NCursesMenu";
0314   }
0315 
0316   virtual ~NCursesMenuException()
0317   {
0318   }
0319 };
0320 
0321 class NCURSES_CXX_IMPEXP NCursesFormException : public NCursesException
0322 {
0323 public:
0324   const NCursesForm* f;
0325 
0326   NCursesFormException (const char *msg, int err) :
0327     NCursesException (msg, err),
0328     f (NULL)
0329     {};
0330 
0331   NCursesFormException (const NCursesForm* form,
0332             const char *msg,
0333             int err) :
0334     NCursesException (msg, err),
0335     f (form)
0336     {};
0337 
0338   explicit NCursesFormException (int err) :
0339     NCursesException ("form library error", err),
0340     f (NULL)
0341     {};
0342 
0343   NCursesFormException (const NCursesForm* form,
0344             int err) :
0345     NCursesException ("form library error", err),
0346     f (form)
0347     {};
0348 
0349   NCursesFormException& operator=(const NCursesFormException& rhs)
0350   {
0351     if (this != &rhs) {
0352       NCursesException::operator=(rhs);
0353       f = rhs.f;
0354     }
0355     return *this;
0356   }
0357 
0358   NCursesFormException(const NCursesFormException& rhs)
0359     : NCursesException(rhs), f(rhs.f)
0360   {
0361   }
0362 
0363   virtual const char *classname() const NCURSES_OVERRIDE {
0364     return "NCursesForm";
0365   }
0366 
0367   virtual ~NCursesFormException()
0368   {
0369   }
0370 };
0371 
0372 #if !((defined(__GNUG__) && defined(__EXCEPTIONS) && (__GNUG__ < 7)) || defined(__SUNPRO_CC))
0373 #  if HAVE_IOSTREAM
0374 #     include <iostream>
0375 #     if IOSTREAM_NAMESPACE
0376 using std::cerr;
0377 using std::endl;
0378 #     endif
0379 #  else
0380 #     include <iostream.h>
0381 #  endif
0382 #endif
0383 
0384 inline void THROW(const NCursesException *e) {
0385 #if defined(__GNUG__) && defined(__EXCEPTIONS)
0386 #  if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
0387       (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
0388 #  elif (__GNUG__ >= 7)
0389      // g++ 7.0 warns about deprecation, but lacks the predefined symbols
0390       ::endwin();
0391       std::cerr << "Found a problem - goodbye" << std::endl;
0392       exit(EXIT_FAILURE);
0393 #  else
0394 #    define CPP_HAS_TRY_CATCH 1
0395 #  endif
0396 #elif defined(__SUNPRO_CC)
0397 #  if !defined(__SUNPRO_CC_COMPAT) || (__SUNPRO_CC_COMPAT < 5)
0398   genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
0399 #  else
0400 #    define CPP_HAS_TRY_CATCH 1
0401 #  endif
0402 #else
0403   if (e)
0404     cerr << e->message << endl;
0405   exit(0);
0406 #endif
0407 
0408 #ifndef CPP_HAS_TRY_CATCH
0409 #define CPP_HAS_TRY_CATCH 0
0410 #define NCURSES_CPP_TRY     /* nothing */
0411 #define NCURSES_CPP_CATCH(e)    if (false)
0412 #define THROWS(s)       /* nothing */
0413 #define THROW2(s,t)     /* nothing */
0414 #elif CPP_HAS_TRY_CATCH
0415   throw *e;
0416 #define NCURSES_CPP_TRY     try
0417 #define NCURSES_CPP_CATCH(e)    catch(e)
0418 #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
0419 // C++17 deprecates the usage of throw().
0420 #define THROWS(s)       /* nothing */
0421 #define THROW2(s,t)     /* nothing */
0422 #else
0423 #define THROWS(s)       throw(s)
0424 #define THROW2(s,t)     throw(s,t)
0425 #endif
0426 #endif
0427 }
0428 
0429 #endif /* NCURSES_ETIP_H_incl */