Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages   Examples  

sys-defines.h

00001 #include "config.h"             /* built by autoconf */
00002 
00003 #ifdef HAVE_LIBPLOTTER
00004 
00005 /**********************************************************************/
00006 /* SUPPORT ANCIENT C/C++ COMPILERS.                                   */
00007 /**********************************************************************/
00008 
00009 #ifdef HAVE_VOID                /* defined in config.h  */
00010 #define voidptr_t void *
00011 #else
00012 #define NO_VOID_SUPPORT
00013 #define voidptr_t char *
00014 #define void int
00015 #endif /* not HAVE_VOID */
00016 
00017 #ifdef const                    /* may be defined to empty in config.h */
00018 #define NO_CONST_SUPPORT
00019 #endif
00020 
00021 /* ____P() is a macro used in our source code to wrap function prototypes,
00022    so that compilers that don't understand ANSI C prototypes still work,
00023    and ANSI C compilers can issue warnings about type mismatches. */
00024 #ifdef ____P
00025 #undef ____P
00026 #endif
00027 #ifdef _HAVE_PROTOS
00028 #undef _HAVE_PROTOS
00029 #endif
00030 #if defined (__STDC__) || defined (_AIX) \
00031         || (defined (__mips) && defined (_SYSTYPE_SVR4)) \
00032         || defined(WIN32) || defined(__cplusplus)
00033 #ifdef _SUPPRESS_PROTOS
00034 #define ____P(protos) ()
00035 #else  /* not _SUPPRESS_PROTOS */
00036 #define ____P(protos) protos
00037 #define _HAVE_PROTOS 1
00038 #endif /* not _SUPPRESS_PROTOS */
00039 #else
00040 #define ____P(protos) ()
00041 #endif
00042 
00043 /**********************************************************************/
00044 /* SUPPORT C++.                                                       */
00045 /**********************************************************************/
00046 
00047 /* Support declarations of C linkage in C++, for functions not declared in
00048    C headers the way they should be. */
00049 #ifdef __cplusplus
00050 # define __C_LINKAGE "C"
00051 #else
00052 # define __C_LINKAGE            /* empty */
00053 #endif
00054 
00055 /* config.h, built by `configure', includes a definition of RETSIGTYPE, the
00056    return value for signal().  But `configure' may get it wrong in C++. */
00057 #ifdef __cplusplus
00058 #ifdef RETSIGTYPE
00059 #undef RETSIGTYPE
00060 #endif
00061 #define RETSIGTYPE void
00062 #endif
00063 
00064 /**********************************************************************/
00065 /* Include all the C headers we'll need.  Because many platforms lack one
00066    or more standard headers or function declarations, there are numerous
00067    tests and substitutions here. */
00068 /**********************************************************************/
00069 
00070 /**********************************************************************/
00071 /* If compiling libplot/libplotter, add support for multithreading,
00072    provided that libc includes pthread functions and pthread.h is present.
00073    (This comes first, because defining _REENTRANT may alter system header
00074    files.) */
00075 /**********************************************************************/
00076 
00077 #ifdef LIBPLOT
00078 #ifdef PTHREAD_SUPPORT
00079 #ifdef HAVE_PTHREAD_H
00080 #define _REENTRANT
00081 #include <pthread.h>
00082 #endif
00083 #endif
00084 #endif
00085 
00086 /**********************************************************************/
00087 /* INCLUDE stdio.h, ctype.h, errno.h.  (SUBSTITUTE AS NECESSARY.)     */
00088 /**********************************************************************/
00089 
00090 #include <stdio.h>
00091 #include <ctype.h>              /* why is this needed? */
00092 
00093 #include <errno.h>
00094 #ifndef HAVE_STRERROR
00095 extern __C_LINKAGE char *strerror ____P((int errnum));
00096 #endif
00097 
00098 /***************************************************************************/
00099 /* INCLUDE math.h, float.h, limits.h.  (SUBSTITUTE AS NECESSARY.)          */
00100 /***************************************************************************/
00101 
00102 #ifdef __DJGPP__
00103 /* for DJGPP math.h, must specify that -lm will be used; 
00104    thanks mdruiter@cs.vu.nl */
00105 #define _USE_LIBM_MATH_H
00106 #endif
00107 
00108 /* Include math.h, and whichever other math-related header files we have */
00109 
00110 #include <math.h> 
00111 
00112 #ifdef HAVE_FLOAT_H
00113 #include <float.h>              /* for DBL_MAX, FLT_MAX */
00114 #endif
00115 #ifdef HAVE_LIMITS_H
00116 #include <limits.h>             /* for INT_MAX */
00117 #endif
00118 #ifdef HAVE_VALUES_H
00119 #include <values.h>             /* for MAXDOUBLE, MAXFLOAT, MAXINT (backups) */
00120 #endif
00121 
00122 /* Bounds on integer datatypes (should be in limits.h, but may not be). */
00123 
00124 #ifndef UINT_MAX
00125 #ifdef  __STDC__
00126 #define UINT_MAX ((unsigned int)(~(0U)))
00127 #else
00128 #define UINT_MAX ((unsigned int)(~((unsigned int)0)))
00129 #endif
00130 #endif /* not UINT_MAX */
00131 
00132 #ifndef INT_MAX
00133 #ifdef MAXINT
00134 #define INT_MAX MAXINT
00135 #else
00136 #define INT_MAX ((int)(~(1U << (8 * (int)sizeof(int) - 1))))
00137 #endif
00138 #endif /* not INT_MAX */
00139 
00140 /* IBM's definition of INT_MAX is bizarre, in AIX 4.1 at least, and using
00141    IROUND() below will yield a warning message unless we repair it */
00142 #ifdef _AIX
00143 #ifdef __GNUC__
00144 #undef INT_MAX
00145 #define INT_MAX ((int)(~(1U << (8 * (int)sizeof(int) - 1))))
00146 #endif
00147 #endif
00148 
00149 /* Bounds on floating point datatypes (should be in float.h, but may not be).*/
00150 
00151 #ifndef DBL_MAX
00152 #ifdef MAXDOUBLE
00153 #define DBL_MAX MAXDOUBLE
00154 #else
00155 /* make a very conservative (Vax-like) assumption */
00156 #define DBL_MAX (1.701411834604692293e+38) 
00157 #endif
00158 #endif /* not DBL_MAX */
00159 
00160 #ifndef FLT_MAX
00161 #ifdef MAXFLOAT
00162 #define FLT_MAX MAXFLOAT
00163 #else
00164 /* make a very conservative (Vax-like) assumption */
00165 #define FLT_MAX (1.7014117331926443e+38)
00166 #endif
00167 #endif /* not FLT_MAX */
00168 
00169 /**********************************************************************/
00170 /* INCLUDE stdlib.h, string.h.  (SUBSTITUTE AS NECESSARY; if STDC_HEADERS
00171    is defined then they're both present, and stdarg.h and float.h too.) */
00172 /**********************************************************************/
00173 
00174 #ifdef STDC_HEADERS
00175 #include <stdlib.h>             /* for getenv, atoi, atof, etc. */
00176 #include <string.h>             /* for memcpy, memmove, strchr, malloc, etc. */
00177 
00178 #else  /* not STDC_HEADERS, must do a LOT of declarations by hand */
00179 
00180 #ifdef HAVE_SYS_STDTYPES_H
00181 #include <sys/stdtypes.h>       /* SunOS needs this for size_t */
00182 #endif
00183 
00184 /* supply declarations for functions declared in stdlib.h */
00185 extern __C_LINKAGE char *getenv ____P((const char *name));
00186 extern __C_LINKAGE int atoi ____P((const char *nptr));
00187 extern __C_LINKAGE double atof ____P((const char *nptr));
00188 
00189 /* supply definitions in stdlib.h */
00190 #define EXIT_FAILURE    1       /* Failing exit status.  */
00191 #define EXIT_SUCCESS    0       /* Successful exit status.  */
00192 
00193 /* determine how to declare (or define) functions declared in string.h */
00194 #ifdef HAVE_STRCHR
00195 #ifdef HAVE_STRING_H
00196 #include <string.h>
00197 #else
00198 #ifdef HAVE_STRINGS_H
00199 #include <strings.h>
00200 #endif
00201 #endif
00202 #else  /* don't have strchr, prefer strings.h */
00203 #ifdef HAVE_STRINGS_H
00204 #include <strings.h>
00205 #else
00206 #ifdef HAVE_STRING_H
00207 #include <string.h>
00208 #endif
00209 #endif
00210 #define strchr index
00211 #define strrchr rindex
00212 #endif /* not HAVE_STRCHR */
00213 
00214 #ifndef HAVE_MEMCPY
00215 #define memcpy(d, s, n) bcopy ((s), (d), (n))
00216 #endif /* not HAVE_MEMCPY */
00217 #ifndef HAVE_MEMMOVE
00218 #define memmove(d, s, n) bcopy ((s), (d), (n))
00219 #endif /* not HAVE_MEMMOVE */
00220 
00221 #ifndef HAVE_STRCASECMP         /* will use local version */
00222 extern __C_LINKAGE int strcasecmp ____P((const char *s1, const char *s2));
00223 #endif /* not HAVE_STRCASECMP */
00224 
00225 /* supply declarations for more functions declared in stdlib.h */
00226 #ifdef HAVE_MALLOC_H
00227 #include <malloc.h>
00228 #else
00229 extern __C_LINKAGE voidptr_t malloc ____P((size_t size));
00230 extern __C_LINKAGE voidptr_t realloc ____P((voidptr_t ptr, size_t size));
00231 extern __C_LINKAGE voidptr_t calloc ____P((size_t nmemb, size_t size));
00232 extern __C_LINKAGE void free ____P((voidptr_t ptr));
00233 #endif /* not HAVE_MALLOC_H */
00234 
00235 #endif /* not STDC_HEADERS */
00236 
00237 /**************************************************************************/
00238 /* Define NULL (necessary on some noncompliant or very old platforms?)    */
00239 /**************************************************************************/
00240 
00241 #ifndef NULL
00242 #define NULL 0
00243 #endif
00244 
00245 /**************************************************************************/
00246 /* In both C and C++, support the `bool' datatype.                        */
00247 /**************************************************************************/
00248 
00249 /* we are logical */
00250 #ifdef __cplusplus
00251 #ifndef HAVE_BOOL       /* old C++ compiler, must declare bool */
00252 typedef enum { false = 0, true = 1 } bool;
00253 #endif
00254 #else  /* not __cplusplus */
00255 #ifdef __STDC__
00256 typedef enum { false = 0, true = 1 } bool;
00257 #else  /* not __STDC__, do things the old-fashioned way */
00258 typedef int bool;
00259 #define false 0
00260 #define true 1
00261 #endif
00262 #endif /* not __cplusplus */
00263 
00264 /**************************************************************************/
00265 /* Define numerical constants (unofficial, so may not be in math.h).      */
00266 /**************************************************************************/
00267 
00268 #ifndef M_PI
00269 #define M_PI        3.14159265358979323846264
00270 #endif
00271 #ifndef M_PI_2
00272 #define M_PI_2      1.57079632679489661923
00273 #endif
00274 #ifndef M_SQRT2
00275 #define M_SQRT2     1.41421356237309504880
00276 #endif
00277 #ifndef M_SQRT3
00278 #define M_SQRT3     1.73205080756887719
00279 #endif
00280 
00281 /**************************************************************************/
00282 /* Work around a longstanding botch (the gamma function supplied in some  */
00283 /* versions of the math library).                                         */
00284 /**************************************************************************/
00285 
00286 /* gamma() and lgamma() both compute the log of the gamma function.  There
00287    are some ancient systems out there which do not have lgamma (the name
00288    was introduced after BSD 4.2), but which do have gamma.  Also, systems
00289    that are merely very old (e.g. Apollos), and some modern systems, have
00290    lgamma but not gamma.  Some systems, old and new (e.g. cygwin32) have
00291    neither.  Also at least one vendor's gamma()/lgamma() is buggy, so we
00292    allow the installer to do -DNO_SYSTEM_GAMMA to prevent the use of vendor
00293    code.  What a mess! */
00294 #ifdef _AIX
00295 #define NO_SYSTEM_GAMMA         /* AIX gamma support in libm.a is buggy */
00296 #endif
00297 #ifdef NO_SYSTEM_GAMMA
00298 #define F_LGAMMA f_lgamma       /* our own version, see ode/specfun.c */
00299 #else  /* not NO_SYSTEM_GAMMA */
00300 #ifdef HAVE_LGAMMA
00301 #define F_LGAMMA lgamma
00302 #else
00303 #ifdef HAVE_GAMMA
00304 #define F_LGAMMA gamma
00305 #else
00306 #define F_LGAMMA f_lgamma
00307 #define NO_SYSTEM_GAMMA
00308 #endif
00309 #endif
00310 #endif /* not NO_SYSTEM_GAMMA */
00311 
00312 /**************************************************************************/
00313 /* Define misc. math macros (in GCC, can be evaluated more rapidly).      */
00314 /**************************************************************************/
00315 
00316 #ifdef __GNUC__
00317 #define DMAX(a,b) ({double _a = (a), _b = (b); _a > _b ? _a : _b; })
00318 #define DMIN(a,b) ({double _a = (a), _b = (b); _a < _b ? _a : _b; })
00319 #define IMAX(a,b) ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
00320 #define IMIN(a,b) ({int _a = (a), _b = (b); _a < _b ? _a : _b; })
00321 #define UMAX(a,b) ({unsigned int _a = (a), _b = (b); _a > _b ? _a : _b; })
00322 #define UMIN(a,b) ({unsigned int _a = (a), _b = (b); _a < _b ? _a : _b; })
00323 #define IROUND(x) ({double _x = (x); int _i; \
00324                     if (_x >= INT_MAX) _i = INT_MAX; \
00325                     else if (_x <= -(INT_MAX)) _i = -(INT_MAX); \
00326                     else _i = (_x > 0.0 ? (int)(_x + 0.5) : (int)(_x - 0.5)); \
00327                     _i;})
00328 #define FROUND(x) ({double _x = (x); float _f; \
00329                     if (_x >= FLT_MAX) _f = FLT_MAX; \
00330                     else if (_x <= -(FLT_MAX)) _f = -(FLT_MAX); \
00331                     else _f = _x; \
00332                     _f;})
00333 #define FABS(x) ((x) >= 0.0 ? (x) : -(x))
00334 #define ICEIL(x) ({double _x = (x); int _i = (int)_x; \
00335                    ((_x == _i) || (_x < 0.0)) ? _i : _i + 1;})
00336 #define IFLOOR(x) ({double _x = (x); int _i = (int)_x; \
00337                    ((_x == _i) || (_x > 0.0)) ? _i : _i - 1;})
00338 #else
00339 #define DMAX(a,b) ((a) > (b) ? (a) : (b))
00340 #define DMIN(a,b) ((a) < (b) ? (a) : (b))
00341 #define IMAX(a,b) ((a) > (b) ? (a) : (b))
00342 #define IMIN(a,b) ((a) < (b) ? (a) : (b))
00343 #define UMAX(a,b) ((a) > (b) ? (a) : (b))
00344 #define UMIN(a,b) ((a) < (b) ? (a) : (b))
00345 #define IROUND(x) ((int) ((x) > 0 ? (x) + 0.5 : (x) - 0.5))
00346 #define FROUND(x) ((float)(x))
00347 #define FABS(x) ((x) >= 0.0 ? (x) : -(x))
00348 #define ICEIL(x) ((int)ceil(x))
00349 #define IFLOOR(x) ((int)floor(x))
00350 #endif
00351 
00352 #endif