Headers and library sources from all versions of Lightspeed C and THINK C

Import Symantec THINK C 3.02

+400 -231
+73 -84
#include files/math.h
··· 7 7 *****************************************************************************/ 8 8 9 9 #ifndef _math_ 10 + #define _math_ 10 11 11 - #define _math_ /* show symbols defined */ 12 - #define PI (3.14159265358979323846) 13 - #define PI2 (1.57079632679489661923) 14 - #define PI4 (0.78539816339744830966) 12 + #undef _MC68881_ 13 + #if sizeof(double) == 12 14 + #define _MC68881_ 15 + #endif 15 16 16 - #define E (2.71828182845904523536) 17 + #undef _ERRORCHECK_ 18 + #ifndef _NOERRORCHECK_ 19 + #define _ERRORCHECK_ 20 + #endif 17 21 18 - typedef enum{ 19 - EDOM=33, 20 - ERANGE=34 21 - }; 22 + #define PI (3.14159265358979323846) 23 + #define PI2 (1.57079632679489661923) 24 + #define PI4 (0.78539816339744830966) 25 + #define E (2.71828182845904523536) 22 26 23 - int abs(int i); 24 - long labs(long l); 27 + typedef enum { EDOM=33, ERANGE=34 }; 25 28 26 - #ifdef _MC68881_ 27 29 #ifdef _ERRORCHECK_ 28 - double acos(double x); 29 - double asin(double x); 30 - double atan(double x); 31 - double atan2(double y, double x); 32 - double ceil(double x); 33 - double cos(double x); 34 - double cosh(double x); 35 - double exp(double x); 36 - double fabs(double x); 37 - double floor(double x); 38 - double fmod(double x, double y); 39 - double frexp(double x, int *i); 40 - double ldexp(double x, int n); 41 - double log(double x); 42 - double log10(double x); 43 - double modf(double x, int *i); 44 - double pow(double x, double y); 45 - double sin(double x); 46 - double sinh(double x); 47 - double sqrt(double x); 48 - double tan(double x); 49 - double tanh(double x); 30 + extern int errno; /* defined in stdio */ 31 + #endif 32 + 33 + #ifdef _MC68881_ 34 + 35 + #ifdef _ERRORCHECK_ 50 36 51 - #else 52 - 37 + /* non-error-checking versions */ 38 + 53 39 double _acos(double x); 54 40 double _asin(double x); 55 41 double _atan(double x); ··· 65 51 double _ldexp(double x, int n); 66 52 double _log(double x); 67 53 double _log10(double x); 68 - double _modf(double x, int *ip); 54 + double _modf(double x, double *ip); 69 55 double _pow(double x, double y); 70 56 double _sin(double x); 71 57 double _sinh(double x); ··· 73 59 double _tan(double x); 74 60 double _tanh(double x); 75 61 62 + #else 63 + 76 64 #define acos(x) _acos(x) 77 65 #define asin(x) _asin(x) 78 66 #define atan(x) _atan(x) ··· 98 86 99 87 #endif /* _ERRORCHECK_ */ 100 88 101 - typedef struct { 102 - long long1; 103 - long long2; 104 - } TwoLongs; /* the mantissa of a double, be it 80 or 96 bits */ 105 - 106 - /* 80-bit extended */ 107 - typedef struct { 108 - int exponent; /* word also contains sign bit */ 109 - TwoLongs mantissa; 110 - } Extended80; 111 - 112 - /* 96-bit extended */ 113 - typedef struct { 114 - int exponent; /* word also contains sign bit */ 115 - int reserved; /* extra 16 bits of zero reserved for 68881 */ 116 - TwoLongs mantissa; 117 - } Extended96; 118 - #endif 89 + typedef struct { 90 + long long1; 91 + long long2; 92 + } TwoLongs; /* the mantissa of a double, be it 80 or 96 bits */ 93 + 94 + /* 80-bit extended */ 95 + typedef struct { 96 + int exponent; /* word also contains sign bit */ 97 + TwoLongs mantissa; 98 + } Extended80; 99 + 100 + /* 96-bit extended */ 101 + typedef struct { 102 + int exponent; /* word also contains sign bit */ 103 + int reserved; /* extra 16 bits of zero reserved for 68881 */ 104 + TwoLongs mantissa; 105 + } Extended96; 119 106 120 - #ifdef _ERRORCHECK_ 121 - extern int errno; /* actually defined in stdio */ 122 - #endif /* _ERRORCHECK */ 123 - 124 - #ifndef _MC68881_ 125 - double acos(double x); 126 - double asin(double x); 127 - double atan(double x); 128 - double atan2(double y, double x); 129 - double ceil(double x); 130 - double cos(double x); 131 - double cosh(double x); 132 - double exp(double x); 133 - double fabs(double x); 134 - double floor(double x); 135 - double fmod(double x, double y); 136 - double frexp(double x, int *i); 137 - double ldexp(double x, int n); 138 - double log(double x); 139 - double log10(double x); 140 - double modf(double x, int *i); 141 - double pow(double x, double y); 142 - double sin(double x); 143 - double sinh(double x); 144 - double sqrt(double x); 145 - double tan(double x); 146 - double tanh(double x); 147 - #endif 107 + #endif /* _MC68881_ */ 108 + 109 + 110 + /* functions */ 111 + 112 + int abs(int i); 113 + long labs(long l); 114 + 115 + double acos(double x); 116 + double asin(double x); 117 + double atan(double x); 118 + double atan2(double y, double x); 119 + double ceil(double x); 120 + double cos(double x); 121 + double cosh(double x); 122 + double exp(double x); 123 + double fabs(double x); 124 + double floor(double x); 125 + double fmod(double x, double y); 126 + double frexp(double x, int *i); 127 + double ldexp(double x, int n); 128 + double log(double x); 129 + double log10(double x); 130 + double modf(double x, double *i); 131 + double pow(double x, double y); 132 + double sin(double x); 133 + double sinh(double x); 134 + double sqrt(double x); 135 + double tan(double x); 136 + double tanh(double x); 148 137 149 - #endif /* _math_ */ 138 + #endif /* _math_ */
+1 -1
#include files/proto.h
··· 46 46 double ldexp(double x, int n); 47 47 double log(double x); 48 48 double log10(double x); 49 - double modf(double x,int *nptr); 49 + double modf(double x, double *nptr); 50 50 double pow(double x, double y); 51 51 int rand(void); 52 52 double sin(double x);
+13 -12
Library Sources/Math.c
··· 8 8 For details, refer to Harbison & Steele's "C: A Reference Manual", 9 9 Chapter 11. 10 10 11 + Only one version of each function is defined by this library. 12 + Whether error checking is done is determined by how this file 13 + is compiled. Error checking is ENABLED when the following 14 + #define is COMMENTED OUT. 15 + 11 16 */ 12 17 13 - #include "config.h" 18 + /*#define _NOERRORCHECK_*/ 14 19 #include "math.h" 15 20 #include "sane.h" 16 21 ··· 455 460 456 461 double modf(x, nptr) 457 462 double x; 458 - register int *nptr; 463 + register double *nptr; 459 464 { 460 - if (abs(*nptr = x) > fabs(x)) { 461 - if (*nptr > 0) 462 - --*nptr; 463 - else 464 - ++*nptr; 465 - } 465 + *nptr = x; 466 + fp68k(nptr, FOTTI); 466 467 return(x - *nptr); 467 468 } 468 469 ··· 475 476 double pow(x, y) 476 477 double x, y; 477 478 { 478 - int exactint = 0; 479 + int odd = 0; 479 480 double z; 480 481 481 482 ClearExceptions(); ··· 491 492 if (y == 0) 492 493 return(One); 493 494 if (x < 0) { 494 - modf(y, &exactint); 495 - if (exactint != y) { 495 + if (modf(y, &y)) { 496 496 #ifdef _ERRORCHECK_ 497 497 errno = EDOM; 498 498 #endif 499 499 return (MinusMax); 500 500 } 501 501 x = -x; 502 + odd = fmod(y, Two); 502 503 } 503 504 elems68k(&y, &x, FOPWRY); 504 505 505 506 RangeCheck(x); 506 - return((exactint & 1) ? -x : x); 507 + return(odd ? -x : x); 507 508 } 508 509 509 510 /*
-1
Library Sources/Math881.a
··· 1 - MACHINE MC68020 MC68881 BLANKS ON CASE ON STRING ASIS ; Assembly source for the Math881 math library. ; Version 3.0 ; by Rich Siegel (with assistance from Steve Stein) ; �1988 Symantec Corp. ; ; LightspeedC pushes the parameters in reverse order; also, the first parameter ; pushed is a hidden argument that contains the address of the function ; result. ; ; Floating-point arguments are pushed by value. ; ; ; The one-argument transcendentals follow a common template: simply ; evaluate what's on the stack with FP0 as the destination, load the ; function result address into A0, and then do a FMOVE.X FP0, (A0) ; to store the function result. ; ; Since none of the floating-point registers are scratch, these ; routines preserve the registers that they use. ; ; in Math881.a the function names begin with the underscore character; ; this is useful when the _ERRORCHECK_ symbol is defined in <Math881.h>. ; the user can call an underscore directly, or he can call the function ; as it's defined in Math881.c, and get the full benefit of the standard ; C error checking. For example, using tan() or _tan(). ; ; When _ERRORCHECK_ is not defined, the library calls are simply macros ; to call the underscore functions. ; ; int abs(int i); ; ; stack: ; 4 byte return address ; i is at 4(a7) abs proc export move.w 4(a7), d0 bge.s @1 neg.w d0 @1 rts ; ; double acos(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _acos proc export fmovem fp0, -(a7) ; preserve registers facos.x 20(a7), fp0 ; arccos movea.l 16(a7), a0 ; load address of result fmove.x fp0, (a0) ; load result fmovem (a7)+, fp0 ; restore registers rts ; ; double asin(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _asin proc export fmovem fp0, -(a7) fasin.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double atan(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _atan proc export fmovem fp0, -(a7) fatan.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double atan2(double y, double x); ; _atan2 proc export fmovem fp0/fp1, -(a7) ; preserve fp0 and fp1 movea.l 28(a7), a0 ; load address of result fmove.x 32(a7), fp0 ; load y fmove.x 44(a7), fp1 ; load x (we'll use it later) fdiv.x fp1, fp0 ; divide by x fatan.x fp0 ; arctan fcmp.w #0, fp1 ; is x < zero? fbge @1 fmove.x 32(a7), fp1 ; put a fresh copy of y into fp1 fcmp.w #0, fp1 ; is y < zero? fbge @2 fmovecr #0, fp1 ; if it is, subtract pi from result. fsub.x fp1, fp0 bra.s @1 ; ...and go home. @2 fmovecr #0, fp1 ; otherwise, add pi to result. fadd.x fp1, fp0 @1 fmove.x fp0, (a0) ; store result fmovem (a7)+, fp0/fp1 ; restore registers rts ; ; double ceil(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _ceil proc export fmovem fp0, -(a7) ; preserve fp0 fmove.l fpcr, d0 ; fetch the 68881 control register move.l d0, d1 ; save a copy in D1 ori.l #$0030, d0 ; OR in the rounding control fmove.l d0, fpcr ; set up the FPCR fint.x 20(a7), fp0 ; calculate nearest integer of arg fmove.l d1, fpcr ; restore the fpcr from the copy movea.l 16(a7), a0 ; load addr of result, and... fmove.x fp0, (a0) ; ...load the result fmovem (a7)+, fp0 ; restore registers rts ; ; double cos(double x); /* same schema as acos, asin, atan */ ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _cos proc export fmovem fp0, -(a7) fcos.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double cosh(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _cosh proc export fmovem fp0, -(a7) fcosh.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double exp(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _exp proc export fmovem fp0, -(a7) fetox.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double fabs(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _fabs proc export fmovem fp0, -(a7) FABS.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double floor(double x); ; ; this function works the same as ceil(), except that the value to OR in ; is $20 instead of $30. ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _floor proc export fmovem fp0, -(a7) fmove.l fpcr, d0 move.l d0, d1 ori.l #$0020, d0 fmove.l d0, fpcr fint.x 20(a7), fp0 fmove.l d1, fpcr movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double fmod(double x, double y); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 32 ; y equ 20 ; result equ 16 _fmod proc export fmovem fp0, -(a7) ; save the registers fmove.x 20(a7), fp0 ; load Y fmod.x 32(a7), fp0 ; call the '881's FMOD movea.l 16(a7), a0 ; load address of result fmove.x fp0, (a0) ; load result fmovem (a7)+, fp0 ; restore registers rts ; ; double frexp(double x, int *nptr); ; ; This function is machine-dependent, and relies on the internal representation ; of the double floating-point data type. ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 24 ; nptr equ 20 ; result equ 16 _frexp proc export fmovem fp0, -(a7) movea.l 16(a7), a0 ; load result address movea.l 20(a7), a1 ; load nptr fmove.x 24(a7), fp0 ; fetch X fcmp.w #0, fp0 ; if X is zero, then fbne @2 move.w #0, (a1) ; both parts of result are zero fmove.x fp0, (a0) ; return x (since it is also zero) bra.s @3 ; goodbye... @2 move.w 24(a7), d0 ; get the exponent of X move.w d0, d1 ; keep a copy bge.s @1 andi.w #$7FFF, d0 ; mask off the mantissa sign bit @1 subi.w #$3FFE, d0 ; subtract the exponent bias (less one) andi.w #$8000, d1 ; preserve mantissa's sign bit ori.w #$3FFE, d1 ; put in an exponent of (-1) move.w d1, 24(a7) ; and smash that over X's old exponent fmove.x 24(a7), fp0 ; fetch X (again) fmove.x fp0, (a0) ; store it in result move.w d0, (a1) ; and store *nptr @3 fmovem (a7)+, fp0 rts ; ; long labs(long l); ; ; stack: ; 4 byte return address ; l is at 4(a7) labs proc export move.l 4(a7), d0 bge.s @1 neg.l d0 @1 rts ; ; double ldexp(double x, int n); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 22 ; n equ 20 ; result equ 16 _ldexp proc export fmovem fp0, -(a7) movea.l 16(a7), a0 ; load result address fmove.w 20(a7), fp0 ; load N into a float register ftwotox fp0 ; raise two to that power. fmul.x 22(a7), fp0 ; multiply by X fmove.x fp0, (a0) ; load result fmovem (a7)+, fp0 rts ; ; double log(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _log proc export fmovem fp0, -(a7) flogn.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double log10(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _log10 proc export fmovem fp0, -(a7) flog10.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double modf(double x, int *ip); ; ; stack frame: ; 24 bytes of saved registers ; 4 bytes return addr ; result equ 28 ; x equ 32 ; ip equ 36 _modf proc export fmovem fp0/fp1, -(a7) movea.l 28(a7), a0 ; address of result movea.l 36(a7), a1 ; address of int part fmove.x 32(a7), fp0 ; argument fintrz.x fp0, fp1 ; leaves integer part in fp1 fmove.w fp1, (a1) ; store integer part fsub.x fp1, fp0 fmove.x fp0, (a0) ; store function result fmovem (a7)+, fp0/fp1 rts ; ; double pow(double x, double y); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; y equ 32 ; x equ 20 ; result equ 16 _pow proc export link a6, #0 fmovem fp0/fp1, -(a7) fmove.x 12(a6), fp0 ; load x fmove.x 24(a6), fp1 ; load y fcmp.w #0, fp1 ; if y is zero then fbne @6 fcmp.w #0, fp0 fbeq @error ; zero to the zeroth power is bad. fmove.w #1, fp0 bra @store ; store one as the result. @6 fcmp.w #0, fp0 ; is x greater than zero? fbgt @1 fbne @2 ; if x is zero, then fcmp.w #0, fp1 fble @error ; if y is greater than zero, fmove.w #0, fp0 ; then return zero. bra.s @store @2 fint.x fp1 ; round y. fcmp.x 24(a6), fp1 ; is y integral? if not, fbne @error ; return some error fmove.x fp1, fp0 ; save a copy of y fdiv.w #2, fp1 ; test if y is odd fdiv.w #2, fp0 fint.x fp1 fcmp.x fp0, fp1 ; if round(fp1) <> fp0 ; before we branch on this test, ; do the operations that both ; conditions require. ; (in fact, the only thing different ; is that the result gets negated ; if y is odd. fmove.l fpsr, d0 ; save the FPSR so we can branch on it later. fmove.x 12(a6), fp0 ; re-fetch the arguments fmove.x 24(a6), fp1 fneg.x fp0 flogn.x fp0 fmul.x fp1, fp0 fetox.x fp0 fmove.l d0, fpsr ; restore the FPSR fbne @5 ; and branch on it. bra.s @store ; since y is even, do nothing else @5 fneg.x fp0 ; since y is odd, negate the result. bra.s @store @1 flogn.x fp0 ; x > 0, therefore fmul.x fp1, fp0 fetox.x fp0 ; pow(x, y) = exp(y * ln(x)) bra.s @store @error fmove.x #"NAN", fp0 @store movea.l 8(a6), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0/fp1 unlk a6 rts ; double sin(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _sin proc export fmovem fp0, -(a7) fsin.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double sinh(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _sinh proc export fmovem fp0, -(a7) fsinh.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double sqrt(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _sqrt proc export fmovem fp0, -(a7) fsqrt.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double tan(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _tan proc export fmovem fp0, -(a7) ftan.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; double tanh(double x); ; ; stack frame: ; 12 bytes saved registers ; 4 byte return address ; x equ 20 ; result equ 16 _tanh proc export fmovem fp0, -(a7) ftanh.x 20(a7), fp0 movea.l 16(a7), a0 fmove.x fp0, (a0) fmovem (a7)+, fp0 rts ; ; long GetState() ; ; GetState() simply returns the contents of the 68881's status register. ; GetState proc export fmove.l fpsr, d0 rts ; ; void ClearExceptions() ; ; ClearExceptions() clears the exception byte of the 68881 status ; register. ; ClearExceptions proc export fmove.l fpsr, d0 andi.l #$FFFF00FF, d0 fmove.l d0, fpsr rts end
+22 -1
Library Sources/Math881.c
··· 7 7 8 8 For details, refer to Harbison & Steele's "C: A Reference Manual", 9 9 Chapter 11. 10 + 11 + Two versions of each function are defined by this library: an 12 + error-checking version (e.g. "sin") and a non-error-checking 13 + version (e.g. "_sin"). 14 + 15 + The non-underscore names can be made to refer to the non-error- 16 + checking functions by #defining _NOERRORCHECK_ before #including 17 + "math.h". Doing so in THIS file suppresses the definitions of 18 + the error-checking versions of the functions altogether. 10 19 11 20 */ 12 21 13 - #include "config.h" 22 + /*#define _NOERRORCHECK_*/ 14 23 #include "Math.h" 15 24 16 25 /* useful constants */ ··· 300 309 { 301 310 DomainCheck(x <= 0, MinusMax); 302 311 return(_log10(x)); 312 + } 313 + 314 + 315 + /* 316 + * modf - split a floating number into fraction/integer 317 + * 318 + */ 319 + 320 + double modf(x, nptr) 321 + double x, *nptr; 322 + { 323 + return(_modf(x, nptr)); 303 324 } 304 325 305 326
+22 -16
Library Sources/MathHybrid.c
··· 7 7 8 8 For details, refer to Harbison & Steele's "C: A Reference Manual", 9 9 Chapter 11. 10 + 11 + Two versions of each function are defined by this library: an 12 + error-checking version (e.g. "sin") and a non-error-checking 13 + version (e.g. "_sin"). 14 + 15 + The non-underscore names can be made to refer to the non-error- 16 + checking functions by #defining _NOERRORCHECK_ before #including 17 + "math.h". Doing so in THIS file suppresses the definitions of 18 + the error-checking versions of the functions altogether. 10 19 11 20 */ 12 21 13 - #include "config.h" 22 + /*#define _NOERRORCHECK_*/ 14 23 #include "math.h" 15 24 #include "sane.h" 16 25 ··· 322 331 _to80(y); 323 332 fp68k(&_x80, FOABS); 324 333 fp68k(&_x80, &tz, FOREM); 334 + _to96(y); 325 335 _x80tox96(tz, z); 326 336 327 337 if (x > 0 && z < 0) ··· 397 407 398 408 double _modf(x, nptr) 399 409 double x; 400 - register int *nptr; 410 + register double *nptr; 401 411 { 402 - if (abs(*nptr = x) > _fabs(x)) { 403 - if (*nptr > 0) 404 - --*nptr; 405 - else 406 - ++*nptr; 407 - } 412 + _to80(x); 413 + fp68k(&_x80, FOTTI); 414 + x80tox96(&_x80, nptr); 408 415 return(x - *nptr); 409 416 } 410 417 ··· 415 422 _x96tox80(y, ty); 416 423 _x96tox80(x, tx); 417 424 elems68k(&ty, &tx, FOPWRY); 418 - _x80tox96(ty, y); 425 + /* _x80tox96(ty, y); */ 419 426 _x80tox96(tx, x); 427 + return(x); 420 428 } 421 429 422 430 double _sin(x) ··· 607 615 608 616 609 617 double modf(x, nptr) 610 - double x; 611 - register int *nptr; 618 + double x, *nptr; 612 619 { 613 620 return(_modf(x, nptr)); 614 621 } ··· 616 623 double pow(x, y) 617 624 double x, y; 618 625 { 619 - int exactint = 0; 626 + int odd = 0; 620 627 Extended80 tx, ty; 621 628 622 629 ClearExceptions(); ··· 633 640 if (y == 0) 634 641 return(One); 635 642 if (x < 0) { 636 - _modf(y, &exactint); 637 - if (exactint != y) { 643 + if (_modf(y, &y)) { 638 644 #ifdef _ERRORCHECK_ 639 645 errno = EDOM; 640 646 #endif 641 647 return (MinusMax); 642 648 } 643 649 x = -x; 650 + odd = _fmod(y, Two); 644 651 } 645 652 646 653 x = _pow(x, y); 647 654 RangeCheck(x); 648 - return((exactint & 1) ? -x : x); 655 + return(odd ? -x : x); 649 656 } 650 657 651 658 double sin(x) ··· 663 670 ClearExceptions(); 664 671 y = _sinh(x); 665 672 RangeCheck(y); 666 - xfersign(x, &y); 667 673 return(y); 668 674 } 669 675
+1 -1
Library Sources/profiler/profile.c
··· 134 134 saveEnable = VIAEnable; 135 135 VIAEnable |= 0x40; 136 136 137 - onexit( Remove_Rollover ); 137 + _onexit( Remove_Rollover ); 138 138 timer = 1; 139 139 } 140 140
+243 -27
Library Sources/stdio .c files/onexit.c
··· 1 - /* 2 - Routines for LightspeedC 3 1 4 - (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved. 5 - 6 - */ 7 2 /* 8 - * onexit 3 + * onexit.c - Copyright (C) 1989 by Symantec Corp. All rights reserved. 9 4 * 10 - * By calling "onexit", the programmer can arrange for up to NPROCS 11 - * routines to be called just before program exit. The routines are 12 - * called with no arguments and in the reverse order in which they 13 - * were supplied to "onexit". 5 + * Shutdown routines installed with "onexit" are called only on NORMAL 6 + * termination, i.e. calling "exit" or returning from "main". 14 7 * 15 - * "Onexit" returns its argument, the address of the routine to be 16 - * called, or zero if it has already been called NPROCS times. 8 + * Shutdown routines installed with "_onexit" are called on "ExitToShell" 9 + * as well as on normal termination. 17 10 * 18 - * "Onexit" is built on a lower-level mechanism, "_onexit", which 19 - * provides for a single routine to be called at termination. 11 + * When initiating any other form of termination (e.g. "Launch"), the 12 + * user can call "_exiting" to force shutdown routines to be called. 20 13 * 21 14 */ 22 15 16 + #ifndef _MacTypes_ 17 + #include <MacHeaders> 18 + #endif 23 19 24 - typedef void (*Proc)(); /* address of a proc */ 20 + extern long ATrapHandler : 0x28; 25 21 26 - #define NPROCS 32 /* max # of procs in list */ 27 - static int nprocs = 0; /* actual # of procs in list */ 28 - static Proc proctable[NPROCS]; /* list of procs */ 22 + typedef void (*Proc)(); 29 23 30 - static long _onexit = 0x4EED006A; /* "jmp $6A(a5)" */ 24 + Proc onexit(Proc); 25 + Proc _onexit(Proc); 26 + void _exiting(int); 27 + void exit(int); 28 + void nop(void); 29 + void abort(void); 31 30 32 - onexit_handler() 31 + #define NPROCS 32 32 + 33 + static struct proc { Proc proc; int always; } procs[NPROCS]; 34 + static int next = 0; 35 + static Proc oldexit, oldES; 36 + static char *ptrES; 37 + 38 + static void normal_exit(void), newES(void); 39 + 40 + 41 + /* 42 + * exit - normal program termination 43 + * 44 + * The exit status is ignored. 45 + * 46 + */ 47 + 48 + void 49 + exit(i) 33 50 { 34 - while (nprocs>0) 35 - if (proctable[--nprocs]) 36 - (*proctable[nprocs])(); 51 + asm { 52 + movea.l 0x6C(a5),a0 53 + jsr (a0) ; call onexit vector 54 + _ExitToShell 55 + } 37 56 } 38 57 39 - #line 0 onexit() 58 + 59 + /* 60 + * onexit - install user shutdown routine 61 + * 62 + */ 63 + 40 64 Proc 41 65 onexit(proc) 42 66 Proc proc; 43 67 { 44 - if (nprocs == 0) 45 - (* ((Proc) &_onexit))(onexit_handler); 68 + register struct proc *p; 46 69 47 - return(nprocs < NPROCS ? proctable[nprocs++] = proc : 0); 70 + if (next == NPROCS) 71 + return(0); 72 + 73 + /* install proc in table */ 74 + 75 + p = &procs[next++]; 76 + p->proc = proc; 77 + /* p->always = 0; */ 78 + if (!oldexit) { 79 + proc = normal_exit; 80 + 81 + /* install onexit vector */ 82 + 83 + asm { 84 + move.l 0x6C(a5),oldexit 85 + move.l proc,0x6C(a5) 86 + } 87 + } 88 + return(p->proc); 89 + } 90 + 91 + 92 + /* 93 + * normal_exit - onexit vector 94 + * 95 + */ 96 + 97 + static void 98 + normal_exit() 99 + { 100 + _exiting(1); 48 101 } 49 102 50 103 104 + /* 105 + * _onexit - install a critical shutdown routine 106 + * 107 + * Routines installed with "_onexit" are called even if the program does 108 + * not terminate normally, provided only that "ExitToShell" is called. 109 + * 110 + */ 111 + 112 + Proc 113 + _onexit(proc) 114 + Proc proc; 115 + { 116 + register struct proc *p; 117 + 118 + if (next == NPROCS) 119 + return(0); 120 + 121 + /* install proc in table */ 122 + 123 + p = &procs[next++]; 124 + p->proc = proc; 125 + p->always = 1; 126 + if (!oldES) { 127 + proc = newES; 128 + 129 + /* save original ExitToShell */ 130 + 131 + asm { 132 + move.w #0xA9F4,d0 ; _ExitToShell 133 + _GetTrapAddress 134 + move.l a0,oldES 135 + } 136 + 137 + /* (64K ROM only) allocate intercept in sysheap */ 138 + 139 + asm { 140 + movea.l proc,a0 141 + tst.w ROM85 142 + bpl.s @1 143 + moveq #6,d0 144 + _NewPtr SYS 145 + move.l a0,ptrES 146 + move.w #0x4EF9,(a0) ; JMP abs.L 147 + move.l proc,2(a0) 148 + @1 } 149 + 150 + /* install ExitToShell intercept */ 151 + 152 + asm { 153 + move.w #0xA9F4,d0 ; _ExitToShell 154 + _SetTrapAddress 155 + } 156 + } 157 + return(p->proc); 158 + } 159 + 160 + 161 + /* 162 + * newES - ExitToShell intercept 163 + * 164 + */ 165 + 166 + static void 167 + newES() 168 + { 169 + _exiting(0); 170 + ExitToShell(); 171 + } 172 + 173 + 174 + /* 175 + * _exiting - perform shutdown activity 176 + * 177 + * The argument controls which shutdown routines should be called: 178 + * 179 + * _exiting(1) call all installed shutdown routines 180 + * _exiting(0) call only routines installed with "_onexit" 181 + * 182 + */ 183 + 184 + void 185 + _exiting(normally) 186 + { 187 + register struct proc *p; 188 + Proc proc; 189 + int i; 190 + 191 + SetUpA5(); 192 + p = &procs[NPROCS]; 193 + for (i = NPROCS; i--; ) { 194 + if (proc = (--p)->proc) { 195 + p->proc = 0; 196 + if (normally || p->always) 197 + (*proc)(); 198 + } 199 + } 200 + 201 + /* deallocate ExitToShell intercept */ 202 + 203 + asm { 204 + move.l ptrES,d0 205 + beq.s @1 206 + movea.l d0,a0 207 + _DisposPtr 208 + clr.l ptrES 209 + @1 } 210 + 211 + /* remove ExitToShell intercept */ 212 + 213 + asm { 214 + move.l oldES,d0 215 + beq.s @2 216 + movea.l d0,a0 217 + move.w #0xA9F4,d0 218 + _SetTrapAddress 219 + clr.l oldES 220 + @2 } 221 + 222 + /* call original exit proc */ 223 + 224 + asm { 225 + movea.l 0x6C(a5),a0 226 + move.l oldexit,d0 227 + beq.s @3 228 + movea.l d0,a0 229 + @3 jsr (a0) 230 + } 231 + oldexit = nop; 232 + RestoreA5(); 233 + } 234 + 235 + 236 + /* 237 + * nop - do nothing 238 + * 239 + */ 240 + 241 + static void 242 + nop() 243 + { 244 + } 245 + 246 + 247 + /* 248 + * abort - abort execution 249 + * 250 + * A debugger trap is issued if it looks like a debugger is installed. 251 + * 252 + */ 253 + 254 + void 255 + abort() 256 + { 257 + if (GetTrapAddress(0xA055) == GetTrapAddress(0xA89F)) { 258 + if ((ATrapHandler & Lo3Bytes) < ((long) ROMBase & Lo3Bytes)) 259 + Debugger(); 260 + } 261 + else { 262 + if (StripAddress(ATrapHandler) < StripAddress(ROMBase)) 263 + Debugger(); 264 + } 265 + ExitToShell(); 266 + }
+5 -6
Library Sources/stdio .c files/printf-2-w.c
··· 17 17 18 18 /* #define _NonMacScreen_ */ 19 19 20 - #include "config.h" 20 + #define _HALFWINDOW_ 21 21 22 22 #ifndef _stdioh_ 23 23 #include "stdio.h" ··· 152 152 watch = **GetCursor(watchCursor); 153 153 SetCursor(&watch); 154 154 _click_on = false; 155 - onexit_handler(); /* make sure other onexit routines get called */ 156 - ExitToShell(); 155 + exit(0); 157 156 } 158 157 159 158 static ··· 684 683 685 684 /* RMS 4/20/88 */ 686 685 /* procedure to determine if MultiFinder is running by checking for the 687 - existence of the WaitNextEvent() trap */ 686 + existence of the _OSDispatch trap */ 688 687 689 688 static int MFIsRunning() 690 - { /* $8F is for _MFDispatch, $9F is the unimplemented trap */ 689 + { /* $8F is for _OSDispatch, $9F is the unimplemented trap */ 691 690 return (GetTrapAddress(0x8FL) != GetTrapAddress(0x9FL)); 692 691 } 693 692 ··· 966 965 /* make sure all exit routines have been called before we 967 966 do anything */ 968 967 969 - onexit_handler(); 968 + _exiting(1); 970 969 971 970 /* if (emptyrgn) DisposeRgn(emptyrgn); - need not bother since the 972 971 entire application heap should be vaporized shortly */
-2
Library Sources/stdio .c files/printf-3.c
··· 9 9 /* comment this out if you don't need floating point numeric support */ 10 10 #define _FORMAT_FP_ 11 11 12 - #include "config.h" 13 - 14 12 #ifndef _stdioh_ 15 13 #include "stdio.h" 16 14 #endif
-2
Library Sources/stdio .c files/scanf2.c
··· 4 4 (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. 5 5 */ 6 6 7 - #include "config.h" 8 - 9 7 #ifndef _stdioh_ 10 8 #include "stdio.h" 11 9 #endif
+1 -13
Library Sources/stdio .c files/stdget_console.c
··· 31 31 32 32 int (*_key_int_sig_func_)() = 0; 33 33 34 - extern long ATrapHandler : 0x28; 35 - 36 - #define DebuggerIn() (((long)ATrapHandler & Lo3Bytes) < (long)((long)ROMBase & Lo3Bytes)) 37 - 38 34 /* pdg - 6/18/86 - completely revised command character handling of the 39 35 following function to allow control characters to be 40 36 easily generated from the keyboard */ ··· 163 159 case 'C': 164 160 case '.': 165 161 if ((long)_key_int_sig_func_ == SIG_DFL) 166 - { 167 - /* call debugger if loaded, then 168 - (or otherwise) depart */ 169 - 170 - if (DebuggerIn()) 171 - Debugger(); 172 - 173 - ExitToShell(); 174 - } 162 + abort(); 175 163 176 164 _key_int_sig_func_ = (void*) SIG_DFL; 177 165 (*_temp_key_int_sig_func_)(SIGINT);
+2 -2
Library Sources/stdio .c files/stdver.c
··· 15 15 #line 0 std_ver() 16 16 char *std_ver() 17 17 { 18 - static char STDIO_VERSION[] = "THINK C Libraries 3.01"; 19 - static char copyright[] = "� 1988 Symantec Corp. All rights reserved."; 18 + static char STDIO_VERSION[] = "THINK C Libraries 3.02"; 19 + static char copyright[] = "� 1989 Symantec Corp. All rights reserved."; 20 20 21 21 return (STDIO_VERSION); 22 22 }
-1
Library Sources/unix .c files/unixatof.c
··· 1 1 /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 2 3 - #include "config.h" 4 3 #include "unix.h" 5 4 #include "sane.h" 6 5 #include "MacTypes.h"
+13 -4
Library Sources/unix .c files/unixexec.c
··· 9 9 char *CtoPstr(); 10 10 11 11 12 + static void 13 + _exec(path) 14 + char *path; 15 + { 16 + _exiting(1); 17 + Launch(0, CtoPstr(path)); 18 + } 19 + 20 + 12 21 #line 0 execl 13 22 14 23 execl(path, arg) 15 24 char *path, *arg; 16 25 { /* designed for launching application with arg0, arg1, ..., argn */ 17 26 18 - Launch(0, CtoPstr(path)); 27 + _exec(path); 19 28 } 20 29 21 30 #line 0 execv ··· 23 32 execv(path, argv) 24 33 char *path, *argv[]; 25 34 { 26 - Launch(0, CtoPstr(path)); 35 + _exec(path); 27 36 } 28 37 29 38 #line 0 execle ··· 33 42 { 34 43 /* launch application with arg0, arg1, ..., argn, 0, env */ 35 44 36 - Launch(0, CtoPstr(path)); 45 + _exec(path); 37 46 } 38 47 39 48 #line 0 execve ··· 41 50 execve(path, argv, envp) 42 51 char *path, *argv[], *envp[]; 43 52 { 44 - Launch(0, CtoPstr(path)); 53 + _exec(path); 45 54 } 46 55
-37
Library Sources/unix .c files/unixexit.c
··· 1 1 /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 2 3 - #ifndef _stdioh_ 4 - #include "stdio.h" 5 - #endif 6 - 7 - #ifndef _ctypeh_ 8 - #include "ctype.h" 9 - #endif 10 - 11 - #ifndef _unixh_ 12 - #include "unix.h" 13 - #endif 14 - 15 - #line 0 exit 16 - 17 - void exit() 18 - { 19 - ExitToShell(); 20 - } 21 - 22 - #line 0 _exit 23 3 24 4 void _exit() 25 5 { 26 6 ExitToShell(); 27 7 } 28 - 29 - extern long ATrapHandler : 0x28; 30 - extern long ROMBase : 0x2AE; 31 - extern long Lo3Bytes : 0x31A; 32 - 33 - #define DebuggerIn() ((ATrapHandler & Lo3Bytes) < (ROMBase & Lo3Bytes)) 34 - 35 - #line 0 abort 36 - 37 - void abort() 38 - { 39 - 40 - if (DebuggerIn()) 41 - Debugger(); 42 - 43 - ExitToShell(); 44 - }
+4 -21
Library Sources/unix .c files/unixsignal.c
··· 9 9 10 10 extern int errno; 11 11 extern int (*_key_int_sig_func_)(); 12 + extern void abort(); 12 13 13 14 static void *sigptr[_SIGMAX+1]; /* array of signal pointers, initially 0 */ 14 15 static char _initsigterm = 0; /* flag for special SIGTERM set up */ 15 16 16 - extern long ATrapHandler : 0x28; 17 - extern long ROMBase : 0x2AE; 18 - extern long Lo3Bytes : 0x31A; 19 - 20 - #define DebuggerIn() ((ATrapHandler & Lo3Bytes) < (ROMBase & Lo3Bytes)) 21 - 22 - #line 0 bugout 23 - 24 - static void bugout() 25 - { 26 - /* call debugger if loaded, then (or otherwise) depart */ 27 - 28 - if (DebuggerIn()) 29 - Debugger(); 30 - 31 - ExitToShell(); 32 - } 33 - 34 17 #line 0 dosigterm 35 18 36 19 static void dosigterm() ··· 66 49 /* see if user wants to cause an exit on SIGINT */ 67 50 68 51 if ((long)func == SIG_DFL) 69 - _key_int_sig_func_ = (void*) bugout; 52 + _key_int_sig_func_ = (void*) abort; 70 53 else 71 54 if ((long)func == SIG_IGN) 72 55 _key_int_sig_func_ = 0; /* eliminate any set function */ ··· 82 65 if (!_initsigterm) 83 66 { 84 67 _initsigterm = 1; 85 - onexit(dosigterm); 68 + _onexit(dosigterm); 86 69 } 87 70 default: 88 71 if ((sig > 0) && (sig <= _SIGMAX)) ··· 92 75 /* see if user wants to cause an exit on signal */ 93 76 94 77 if ((long)func == SIG_DFL) 95 - sigptr[sig] = (void*) bugout; 78 + sigptr[sig] = (void*) abort; 96 79 else 97 80 if ((long)func == SIG_IGN) 98 81 sigptr[sig] = 0; /* eliminate any set function */