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) || defined(__DragonFly__) 48 #include <sys/endian.h> 49 #elif defined(__APPLE__) 50 #include <machine/endian.h> 51 #else 52 #include <endian.h> 53 #endif 54 #endif 55 #ifndef BIG_ENDIAN 56 #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ 57 #endif 58 #ifndef LITTLE_ENDIAN 59 #define LITTLE_ENDIAN 1234 60 #endif 61 62 #define MSDOS 1 63 64 #define overwrite fract_overwrite /* avoid name conflict with curses */ 65 66 #ifdef XFRACT /* XFRACT forces unix configuration! --CWM-- */ 67 68 #ifdef BIG_ANSI_C /* remove far's */ 69 #ifdef far 70 #undef far 71 #endif 72 #define far 73 #ifdef _far 74 #undef _far 75 #endif 76 #define _far 77 #ifdef __far 78 #undef __far 79 #endif 80 #define __far 81 #define _fmemcpy memcpy 82 #define _fmemset memset 83 #define _fmemmove memmove 84 #ifndef USE_BIGNUM_C_CODE 85 #define USE_BIGNUM_C_CODE 86 #endif 87 #endif 88 /* CAE added ltoa, overwrite fix for HP-UX v9 26Jan95 */ 89 #ifdef _HPUX_SOURCE 90 #define ltoa fr_ltoa 91 #endif 92 93 #ifdef MSDOS 94 #undef MSDOS 95 #endif 96 97 #ifdef __MSDOS__ 98 #undef __MSDOS__ 99 #endif 100 101 #ifndef unix 102 #define unix 103 #endif 104 105 #endif /* XFRACT */ 106 107 #ifdef __TURBOC__ 108 #define __cdecl cdecl 109 #endif 110 111 #ifdef MSDOS /* Microsoft C 5.1 for OS/2 and MSDOS */ 112 /* NOTE: this is always true on DOS! */ 113 /* (MSDOS is defined above) */ 114 #define timebx timeb 115 116 #ifndef BYTE_ORDER 117 #define BYTE_ORDER LITTLE_ENDIAN 118 #endif 119 120 #ifdef _MSC_VER /* MSC assert does nothing under MSDOS */ 121 #ifdef assert 122 #undef assert 123 #define assert(X) 124 #endif 125 #endif 126 127 typedef unsigned char U8; 128 typedef signed char S8; 129 typedef unsigned short U16; 130 typedef signed short S16; 131 typedef unsigned long U32; 132 typedef signed long S32; 133 typedef unsigned char BYTE; 134 typedef unsigned char CHAR; 135 typedef void *VOIDPTR; 136 typedef void far *VOIDFARPTR; 137 typedef const void *VOIDCONSTPTR; 138 139 #define CONST const 140 #define PRINTER "/dev/prn" 141 #define LOBYTEFIRST 1 142 #define SLASHC '\\' 143 #define SLASH "\\" 144 #define SLASHSLASH "\\\\" 145 #define SLASHDOT "\\." 146 #define DOTSLASH ".\\" 147 #define DOTDOTSLASH "..\\" 148 #define READMODE "rb" /* Correct DOS text-mode */ 149 #define WRITEMODE "wb" /* file open "feature". */ 150 151 #define write1(ptr,len,n,stream) fwrite(ptr,len,n,stream) 152 #define write2(ptr,len,n,stream) fwrite(ptr,len,n,stream) 153 #define rand15() rand() 154 155 #else /* Have to nest because #elif is not portable */ 156 #ifdef AMIGA /* Lattice C 3.02 for Amiga */ 157 typedef UBYTE U8; 158 typedef BYTE S8; 159 typedef UWORD U16; 160 typedef WORD S16; 161 typedef unsigned int U32; 162 typedef int S32; 163 typedef UBYTE BYTE; 164 typedef UBYTE CHAR; 165 166 typedef void *VOIDPTR; 167 typedef void *VOIDFARPTR; 168 typedef const void *VOIDCONSTPTR; 169 170 #define PRINTER "PRT:" 171 #define LOBYTEFIRST 0 172 #define SLASHC '/' 173 #define SLASH "/" 174 #define SLASHSLASH "//" 175 #define SLASHDOT "/." 176 #define DOTSLASH "./" 177 #define DOTDOTSLASH "../" 178 #define READMODE "rb" 179 #define WRITEMODE "wb" 180 181 #define write1(ptr,len,n,stream) (fputc(*(ptr),stream),1) 182 #define write2(ptr,len,n,stream) (fputc((*(ptr))&255,stream),fputc((*(ptr))>>8,stream),1) 183 #define rand15() (rand()&0x7FFF) 184 185 #define BYTE_ORDER BIG_ENDIAN 186 #define USE_BIGNUM_C_CODE 187 #define BIG_ANSI_C 188 189 #else 190 #ifdef unix /* Unix machine */ 191 typedef unsigned char U8; 192 typedef signed char S8; 193 typedef unsigned short U16; 194 typedef short S16; 195 typedef unsigned long U32; 196 typedef long S32; 197 typedef unsigned char BYTE; 198 typedef char CHAR; 199 200 #ifndef __cdecl 201 #define __cdecl 202 #endif 203 204 #ifdef __SVR4 205 typedef void *VOIDPTR; 206 typedef void *VOIDFARPTR; 207 typedef const void *VOIDCONSTPTR; 208 #else 209 # ifdef BADVOID 210 typedef char *VOIDPTR; 211 typedef char *VOIDFARPTR; 212 typedef char *VOIDCONSTPTR; 213 # else 214 typedef void *VOIDPTR; 215 typedef void *VOIDFARPTR; 216 typedef const void *VOIDCONSTPTR; 217 # endif 218 #endif 219 220 #ifdef __SVR4 221 # include <fcntl.h> 222 typedef void sigfunc(int); 223 #else 224 typedef int sigfunc(int); 225 #endif 226 227 #ifndef BYTE_ORDER 228 /* change for little endians that don't have this defined elsewhere (endian.h) */ 229 #ifdef LINUX 230 #define BYTE_ORDER LITTLE_ENDIAN 231 #else 232 #define BYTE_ORDER BIG_ENDIAN /* the usual case */ 233 #endif 234 #endif 235 236 #ifndef USE_BIGNUM_C_CODE 237 #define USE_BIGNUM_C_CODE 238 #endif 239 #ifndef BIG_ANSI_C 240 #define BIG_ANSI_C 241 #endif 242 243 # define CONST const 244 # define PRINTER "/dev/lp" 245 # define SLASHC '/' 246 # define SLASH "/" 247 # define SLASHSLASH "//" 248 # define SLASHDOT "/." 249 # define DOTSLASH "./" 250 # define DOTDOTSLASH "../" 251 # define READMODE "r" 252 # define WRITEMODE "w" 253 254 # define write1(ptr,len,n,stream) (fputc(*(ptr),stream),1) 255 # define write2(ptr,len,n,stream) (fputc((*(ptr))&255,stream),fputc((*(ptr))>>8,stream),1) 256 # define rand15() (rand()&0x7FFF) 257 258 # include "unix.h" 259 260 261 #endif 262 #endif 263 #endif 264 265 266 /* The following FILE_* #defines were moved here from fractint.h to 267 * avoid inconsistent declarations in dos_help/hc.c and unix/unix.c. */ 268 269 /* these are used to declare arrays for file names */ 270 #ifdef XFRACT 271 #define FILE_MAX_PATH 256 /* max length of path+filename */ 272 #define FILE_MAX_DIR 256 /* max length of directory name */ 273 #else 274 #define FILE_MAX_PATH 80 /* max length of path+filename */ 275 #define FILE_MAX_DIR 80 /* max length of directory name */ 276 #endif 277 #define FILE_MAX_DRIVE 3 /* max length of drive letter */ 278 279 #if 1 280 #define FILE_MAX_FNAME 9 /* max length of filename */ 281 #define FILE_MAX_EXT 5 /* max length of extension */ 282 #else 283 /* 284 The filename limits were increased in Xfract 3.02. But alas, 285 in this poor program that was originally developed on the 286 nearly-brain-dead DOS operating system, quite a few things 287 in the UI would break if file names were bigger than DOS 8-3 288 names. So for now humor us and let's keep the names short. 289 */ 290 #define FILE_MAX_FNAME 64 /* max length of filename */ 291 #define FILE_MAX_EXT 64 /* max length of extension */ 292 #endif 293 294 #define MAX_NAME FILE_MAX_FNAME+FILE_MAX_EXT-1 295 296 struct DIR_SEARCH /* Allocate DTA and define structure */ 297 { 298 char path[21]; /* DOS path and filespec */ 299 char attribute; /* File attributes wanted */ 300 int ftime; /* File creation time */ 301 int fdate; /* File creation date */ 302 long size; /* File size in bytes */ 303 char filename[MAX_NAME+1]; /* Filename and extension */ 304 }; 305 extern struct DIR_SEARCH DTA; /* Disk Transfer Area */ 306 307 /* Uses big_access32(), big_set32(),... functions instead of macros. */ 308 /* Some little endian machines may require this as well. */ 309 #if BYTE_ORDER == BIG_ENDIAN 310 #define ACCESS_BY_BYTE 311 #endif 312 313 314 #ifdef LOBYTEFIRST 315 #define GET16(c,i) (i) = *((U16*)(&(c))) 316 #else 317 #define GET16(c,i) (i) = (*(unsigned char *)&(c))+\ 318 ((*((unsigned char*)&(c)+1))<<8) 319 #endif 320 321 322 323 324 /* Some compiler libraries don't correctly handle long double.*/ 325 /* If you want to force the use of doubles, or */ 326 /* if the compiler supports long doubles, but does not allow */ 327 /* scanf("%Lf", &longdoublevar); */ 328 /* to read in a long double, then uncomment this next line */ 329 /* #define DO_NOT_USE_LONG_DOUBLE */ 330 /* #define USE_BIGNUM_C_CODE */ /* ASM code requires using long double */ 331 332 333 /* HP-UX support long doubles and allows them to be read in with */ 334 /* scanf(), but does not support the functions sinl, cosl, fabsl, etc. */ 335 /* CAE added this 26Jan95 so it would compile (altered by Wes to new macro) */ 336 #if defined _HPUX_SOURCE || defined (__DragonFly__) 337 #define DO_NOT_USE_LONG_DOUBLE 338 #endif 339 340 /* Solaris itself does not provide long double arithmetics like sinl. 341 * However, the "sunmath" library that comes bundled with Sun C does 342 * provide them. */ 343 #ifdef sun 344 #ifdef USE_SUNMATH 345 #include <sunmath.h> 346 #else 347 #define DO_NOT_USE_LONG_DOUBLE 348 #endif 349 #endif 350 351 /* This should not be neccessary, but below appears to not work */ 352 #ifdef CYGWIN 353 #define DO_NOT_USE_LONG_DOUBLE 354 #endif 355 356 #ifndef DO_NOT_USE_LONG_DOUBLE 357 #ifdef LDBL_DIG 358 /* this is what we're hoping for */ 359 #define USE_LONG_DOUBLE 360 typedef long double LDBL; 361 #else 362 #define DO_NOT_USE_LONG_DOUBLE 363 #endif /* #ifdef LDBL_DIG */ 364 #endif /* #ifndef DO_NOT_USE_LONG_DOUBLE */ 365 366 367 #ifdef DO_NOT_USE_LONG_DOUBLE 368 369 #ifdef USE_LONG_DOUBLE 370 #undef USE_LONG_DOUBLE 371 #endif 372 373 /* long double isn't supported */ 374 /* impliment LDBL as double */ 375 typedef double LDBL; 376 377 #if !defined(LDBL_DIG) 378 #define LDBL_DIG DBL_DIG /* # of decimal digits of precision */ 379 #endif 380 #if !defined(LDBL_EPSILON) 381 #define LDBL_EPSILON DBL_EPSILON /* smallest such that 1.0+LDBL_EPSILON != 1.0 */ 382 #endif 383 #if !defined(LDBL_MANT_DIG) 384 #define LDBL_MANT_DIG DBL_MANT_DIG /* # of bits in mantissa */ 385 #endif 386 #if !defined(LDBL_MAX) 387 #define LDBL_MAX DBL_MAX /* max value */ 388 #endif 389 #if !defined(LDBL_MAX_10_EXP) 390 #define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* max decimal exponent */ 391 #endif 392 #if !defined(LDBL_MAX_EXP) 393 #define LDBL_MAX_EXP DBL_MAX_EXP /* max binary exponent */ 394 #endif 395 #if !defined(LDBL_MIN) 396 #define LDBL_MIN DBL_MIN /* min positive value */ 397 #endif 398 #if !defined(LDBL_MIN_10_EXP) 399 #define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* min decimal exponent */ 400 #endif 401 #if !defined(LDBL_MIN_EXP) 402 #define LDBL_MIN_EXP DBL_MIN_EXP /* min binary exponent */ 403 #endif 404 #if !defined(LDBL_RADIX) 405 #define LDBL_RADIX DBL_RADIX /* exponent radix */ 406 #endif 407 #if !defined(LDBL_ROUNDS) 408 #define LDBL_ROUNDS DBL_ROUNDS /* addition rounding: near */ 409 #endif 410 411 #define asinl asin 412 #define atanl atan 413 #define atan2l atan2 414 #define ceill ceil 415 #define cosl cos 416 #define expl exp 417 #define fabsl fabs 418 #define floorl floor 419 #define logl log 420 #define log10l log10 421 #define sinl sin 422 #define sqrtl sqrt 423 #endif /* #ifdef DO_NOT_USE_LONG_DOUBLE */ 424 425 #endif /* PORT_H */ 426