File: headers\port.h

    1 /**************************************
    2 **
    3 ** PORT.H : Miscellaneous definitions for portability.  Please add
    4 ** to this file for any new machines/compilers you may have.
    5 **
    6 ** XFRACT file "SHARED.H" merged into PORT.H on 3/14/92 by --CWM--
    7 ** TW also merged in Wes Loewer's BIGPORT.H.
    8 */
    9 
   10 #ifndef PORT_H          /* If this is defined, this file has been       */
   11 #define PORT_H          /* included already in this module.             */
   12 
   13 #ifndef XFRACT
   14 #include        <dos.h>
15 #else 16 #include <unistd.h>
17 #endif 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <math.h> 21 #include <float.h> 22 23 24 #if (defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) || defined(__TURBOC__)) && !defined(STDC) 25 # define STDC 26 #endif 27 28 #if (defined(LINUX)) && !defined(STDC)
29 # define STDC
30 #endif 31 32 #ifndef STDC
33 # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 34 # define const 35 # endif
36 #endif 37 38 #ifdef __TURBOC__
39 #define _matherr matherr 40 #define _stackavail stackavail 41 #define USE_BIGNUM_C_CODE
42 #endif 43 44 /* If endian.h is not present, it can be handled in the code below, */ 45 /* but if you have this file, it can make it more fool proof. */ 46 #if (defined(XFRACT) && !defined(__sun))
47 #if defined(sgi) 48 #include <sys/endian.h> 49 #else 50 #include <endian.h> 51 #endif
52 #endif 53 #ifndef BIG_ENDIAN 54 #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ 55 #endif 56 #ifndef LITTLE_ENDIAN 57 #define LITTLE_ENDIAN 1234 58 #endif 59 60 #define MSDOS 1 61 62 #define overwrite fract_overwrite /* avoid name conflict with curses */ 63 64 #ifdef XFRACT /* XFRACT forces unix configuration! --CWM-- */
65 66 #ifdef BIG_ANSI_C /* remove far's */ 67 #ifdef far 68 #undef far 69 #endif 70 #define far 71 #ifdef _far 72 #undef _far 73 #endif 74 #define _far 75 #ifdef __far 76 #undef __far 77 #endif 78 #define __far 79 #define _fmemcpy memcpy 80 #define _fmemset memset 81 #define _fmemmove memmove 82 #ifndef USE_BIGNUM_C_CODE 83 #define USE_BIGNUM_C_CODE 84 #endif 85 #endif 86 /* CAE added ltoa, overwrite fix for HP-UX v9 26Jan95 */ 87 #ifdef _HPUX_SOURCE 88 #define ltoa fr_ltoa 89 #endif 90 91 #ifdef MSDOS 92 #undef MSDOS 93 #endif 94 95 #ifdef __MSDOS__ 96 #undef __MSDOS__ 97 #endif 98 99 #ifndef unix 100 #define unix 101 #endif 102
103 #endif /* XFRACT */ 104 105 #ifdef __TURBOC__
106 #define __cdecl cdecl
107 #endif 108 109 #ifdef MSDOS /* Microsoft C 5.1 for OS/2 and MSDOS */ 110 /* NOTE: this is always true on DOS! */ 111 /* (MSDOS is defined above) */ 112 #define timebx timeb 113 114 #ifndef BYTE_ORDER 115 #define BYTE_ORDER LITTLE_ENDIAN 116 #endif 117 118 #ifdef _MSC_VER /* MSC assert does nothing under MSDOS */ 119 #ifdef assert
120 #undef assert 121 #define assert(X)
122 #endif 123 #endif 124 125 typedef unsigned char U8; 126 typedef signed char S8; 127 typedef unsigned short U16; 128 typedef signed short S16; 129 typedef unsigned long U32; 130 typedef signed long S32; 131 typedef unsigned char BYTE; 132 typedef unsigned char CHAR; 133 typedef void *VOIDPTR; 134 typedef void far *VOIDFARPTR; 135 typedef const void *VOIDCONSTPTR; 136 137 #define CONST const 138 #define PRINTER "/dev/prn" 139 #define LOBYTEFIRST 1 140 #define SLASHC '\\' 141 #define SLASH "\\" 142 #define SLASHSLASH "\\\\" 143 #define SLASHDOT "\\." 144 #define DOTSLASH ".\\" 145 #define DOTDOTSLASH "..\\" 146 #define READMODE "rb" /* Correct DOS text-mode */ 147 #define WRITEMODE "wb" /* file open "feature". */ 148 149 #define write1(ptr,len,n,stream) fwrite(ptr,len,n,stream) 150 #define write2(ptr,len,n,stream) fwrite(ptr,len,n,stream) 151 #define rand15() rand() 152
153 #else /* Have to nest because #elif is not portable */ 154 #ifdef AMIGA /* Lattice C 3.02 for Amiga */ 155 typedef UBYTE U8; 156 typedef BYTE S8; 157 typedef UWORD U16; 158 typedef WORD S16; 159 typedef unsigned int U32; 160 typedef int S32; 161 typedef UBYTE BYTE; 162 typedef UBYTE CHAR; 163 164 typedef void *VOIDPTR; 165 typedef void *VOIDFARPTR; 166 typedef const void *VOIDCONSTPTR; 167 168 #define PRINTER "PRT:" 169 #define LOBYTEFIRST 0 170 #define SLASHC '/' 171 #define SLASH "/" 172 #define SLASHSLASH "//" 173 #define SLASHDOT "/." 174 #define DOTSLASH "./" 175 #define DOTDOTSLASH "../" 176 #define READMODE "rb" 177 #define WRITEMODE "wb" 178 179 #define write1(ptr,len,n,stream) (fputc(*(ptr),stream),1) 180 #define write2(ptr,len,n,stream) (fputc((*(ptr))&255,stream),fputc((*(ptr))>>8,stream),1) 181 #define rand15() (rand()&0x7FFF) 182 183 #define BYTE_ORDER BIG_ENDIAN 184 #define USE_BIGNUM_C_CODE 185 #define BIG_ANSI_C 186 187 #else 188 #ifdef unix /* Unix machine */ 189 typedef unsigned char U8; 190 typedef signed char S8; 191 typedef unsigned short U16; 192 typedef short S16; 193 typedef unsigned long U32; 194 typedef long S32; 195 typedef unsigned char BYTE; 196 typedef char CHAR; 197 198 #ifndef __cdecl 199 #define __cdecl 200 #endif 201 202 #ifdef __SVR4 203 typedef void *VOIDPTR; 204 typedef void *VOIDFARPTR; 205 typedef const void *VOIDCONSTPTR; 206 #else 207 # ifdef BADVOID 208 typedef char *VOIDPTR; 209 typedef char *VOIDFARPTR; 210 typedef char *VOIDCONSTPTR; 211 # else 212 typedef void *VOIDPTR; 213 typedef void *VOIDFARPTR; 214 typedef const void *VOIDCONSTPTR; 215 # endif 216 #endif 217 218 #ifdef __SVR4 219 # include <fcntl.h> 220 typedef void sigfunc(int); 221 #else 222 typedef int sigfunc(int); 223 #endif 224 225 #ifndef BYTE_ORDER 226 /* change for little endians that don't have this defined elsewhere (endian.h) */ 227 #ifdef LINUX 228 #define BYTE_ORDER LITTLE_ENDIAN 229 #else 230 #define BYTE_ORDER BIG_ENDIAN /* the usual case */ 231 #endif 232 #endif 233 234 #ifndef USE_BIGNUM_C_CODE 235 #define USE_BIGNUM_C_CODE 236 #endif 237 #ifndef BIG_ANSI_C 238 #define BIG_ANSI_C 239 #endif 240 241 # define CONST const 242 # define PRINTER "/dev/lp" 243 # define SLASHC '/' 244 # define SLASH "/" 245 # define SLASHSLASH "//" 246 # define SLASHDOT "/." 247 # define DOTSLASH "./" 248 # define DOTDOTSLASH "../" 249 # define READMODE "r" 250 # define WRITEMODE "w" 251 252 # define write1(ptr,len,n,stream) (fputc(*(ptr),stream),1) 253 # define write2(ptr,len,n,stream) (fputc((*(ptr))&255,stream),fputc((*(ptr))>>8,stream),1) 254 # define rand15() (rand()&0x7FFF) 255 256 # include "unix.h" 257 258 259 #endif 260 #endif
261 #endif 262 263 /* Uses big_access32(), big_set32(),... functions instead of macros. */ 264 /* Some little endian machines may require this as well. */ 265 #if BYTE_ORDER == BIG_ENDIAN
266 #define ACCESS_BY_BYTE
267 #endif 268 269 270 #ifdef LOBYTEFIRST 271 #define GET16(c,i) (i) = *((U16*)(&(c)))
272 #else 273 #define GET16(c,i) (i) = (*(unsigned char *)&(c))+\ 274 ((*((unsigned char*)&(c)+1))<<8)
275 #endif 276 277 278 279 280 /* Some compiler libraries don't correctly handle long double.*/ 281 /* If you want to force the use of doubles, or */ 282 /* if the compiler supports long doubles, but does not allow */ 283 /* scanf("%Lf", &longdoublevar); */ 284 /* to read in a long double, then uncomment this next line */ 285 /* #define DO_NOT_USE_LONG_DOUBLE */ 286 /* #define USE_BIGNUM_C_CODE */ /* ASM code requires using long double */ 287 288 289 /* HP-UX support long doubles and allows them to be read in with */ 290 /* scanf(), but does not support the functions sinl, cosl, fabsl, etc. */ 291 /* CAE added this 26Jan95 so it would compile (altered by Wes to new macro) */ 292 #ifdef _HPUX_SOURCE
293 #define DO_NOT_USE_LONG_DOUBLE
294 #endif 295 296 /* Solaris itself does not provide long double arithmetics like sinl. 297 * However, the "sunmath" library that comes bundled with Sun C does 298 * provide them. */ 299 #ifdef sun
300 #ifdef USE_SUNMATH 301 #include <sunmath.h> 302 #else 303 #define DO_NOT_USE_LONG_DOUBLE 304 #endif
305 #endif 306 307 /* This should not be neccessary, but below appears to not work */ 308 #ifdef CYGWIN
309 #define DO_NOT_USE_LONG_DOUBLE
310 #endif 311 312 #ifndef DO_NOT_USE_LONG_DOUBLE 313 #ifdef LDBL_DIG 314 /* this is what we're hoping for */ 315 #define USE_LONG_DOUBLE 316 typedef long double LDBL;
317 #else 318 #define DO_NOT_USE_LONG_DOUBLE
319 #endif /* #ifdef LDBL_DIG */ 320 #endif /* #ifndef DO_NOT_USE_LONG_DOUBLE */ 321 322 323 #ifdef DO_NOT_USE_LONG_DOUBLE
324 325 #ifdef USE_LONG_DOUBLE 326 #undef USE_LONG_DOUBLE 327 #endif 328 329 /* long double isn't supported */ 330 /* impliment LDBL as double */ 331 typedef double LDBL; 332 333 #if !defined(LDBL_DIG) 334 #define LDBL_DIG DBL_DIG /* # of decimal digits of precision */ 335 #endif 336 #if !defined(LDBL_EPSILON) 337 #define LDBL_EPSILON DBL_EPSILON /* smallest such that 1.0+LDBL_EPSILON != 1.0 */ 338 #endif 339 #if !defined(LDBL_MANT_DIG) 340 #define LDBL_MANT_DIG DBL_MANT_DIG /* # of bits in mantissa */ 341 #endif 342 #if !defined(LDBL_MAX) 343 #define LDBL_MAX DBL_MAX /* max value */ 344 #endif 345 #if !defined(LDBL_MAX_10_EXP) 346 #define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* max decimal exponent */ 347 #endif 348 #if !defined(LDBL_MAX_EXP) 349 #define LDBL_MAX_EXP DBL_MAX_EXP /* max binary exponent */ 350 #endif 351 #if !defined(LDBL_MIN) 352 #define LDBL_MIN DBL_MIN /* min positive value */ 353 #endif 354 #if !defined(LDBL_MIN_10_EXP) 355 #define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* min decimal exponent */ 356 #endif 357 #if !defined(LDBL_MIN_EXP) 358 #define LDBL_MIN_EXP DBL_MIN_EXP /* min binary exponent */ 359 #endif 360 #if !defined(LDBL_RADIX) 361 #define LDBL_RADIX DBL_RADIX /* exponent radix */ 362 #endif 363 #if !defined(LDBL_ROUNDS) 364 #define LDBL_ROUNDS DBL_ROUNDS /* addition rounding: near */ 365 #endif 366 367 #define sqrtl sqrt 368 #define logl log 369 #define log10l log10 370 #define atanl atan 371 #define fabsl fabs 372 #define sinl sin 373 #define cosl cos
374 #endif 375 376 #endif /* PORT_H */ 377