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

Import Symantec Lightspeed C 3.01

+2383 -287
+149
#include files/math.h
··· 1 + /**************************************************************************** 2 + 3 + Standard math library header for LightspeedC. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + *****************************************************************************/ 8 + 9 + #ifndef _math_ 10 + 11 + #define _math_ /* show symbols defined */ 12 + #define PI (3.14159265358979323846) 13 + #define PI2 (1.57079632679489661923) 14 + #define PI4 (0.78539816339744830966) 15 + 16 + #define E (2.71828182845904523536) 17 + 18 + typedef enum{ 19 + EDOM=33, 20 + ERANGE=34 21 + }; 22 + 23 + int abs(int i); 24 + long labs(long l); 25 + 26 + #ifdef _MC68881_ 27 + #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); 50 + 51 + #else 52 + 53 + double _acos(double x); 54 + double _asin(double x); 55 + double _atan(double x); 56 + double _atan2(double y, double x); 57 + double _ceil(double x); 58 + double _cos(double x); 59 + double _cosh(double x); 60 + double _exp(double x); 61 + double _fabs(double x); 62 + double _floor(double x); 63 + double _fmod(double x, double y); 64 + double _frexp(double x, int *i); 65 + double _ldexp(double x, int n); 66 + double _log(double x); 67 + double _log10(double x); 68 + double _modf(double x, int *ip); 69 + double _pow(double x, double y); 70 + double _sin(double x); 71 + double _sinh(double x); 72 + double _sqrt(double x); 73 + double _tan(double x); 74 + double _tanh(double x); 75 + 76 + #define acos(x) _acos(x) 77 + #define asin(x) _asin(x) 78 + #define atan(x) _atan(x) 79 + #define atan2(y, x) _atan2(y, x) 80 + #define ceil(x) _ceil(x) 81 + #define cos(x) _cos(x) 82 + #define cosh(x) _cosh(x) 83 + #define exp(x) _exp(x) 84 + #define fabs(x) _fabs(x) 85 + #define floor(x) _floor(x) 86 + #define fmod(x, y) _fmod(x, y) 87 + #define frexp(x, i) _frexp(x, i) 88 + #define ldexp(x, n) _ldexp(x, n) 89 + #define log(x) _log(x) 90 + #define log10(x) _log10(x) 91 + #define modf(x, ip) _modf(x, ip) 92 + #define pow(x, y) _pow(x, y) 93 + #define sin(x) _sin(x) 94 + #define sinh(x) _sinh(x) 95 + #define sqrt(x) _sqrt(x) 96 + #define tan(x) _tan(x) 97 + #define tanh(x) _tanh(x) 98 + 99 + #endif /* _ERRORCHECK_ */ 100 + 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 119 + 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 148 + 149 + #endif /* _math_ */
C Libraries/headers/ctype.h #include files/ctype.h
C Libraries/headers/errno.h #include files/errno.h
+3 -2
C Libraries/headers/fopenw.h #include files/fopenw.h
··· 24 24 #include "EventMgr.h" 25 25 #endif 26 26 27 - extern GrafPtr WMgrPort:0x9DE; 27 + #ifndef _MenuMgr_ 28 + #include "MenuMgr.h" 29 + #endif 28 30 29 31 /* This is the Standard Window Options structure (passed in to fopenw) */ 30 32 ··· 111 113 #define _LEFTEDGE 4 /* margins */ 112 114 #define _TOPEDGE 4 113 115 114 - extern int MBarHeight:0xBAA; 115 116 #define _MBARHEIGHT (ROM85==-1?20:MBarHeight) 116 117 117 118 #define _TITLEBARHEIGHT 20
C Libraries/headers/io.h #include files/io.h
-49
C Libraries/headers/math.h
··· 1 - /**************************************************************************** 2 - 3 - Standard math library header for LightspeedC. 4 - 5 - (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 - 7 - *****************************************************************************/ 8 - 9 - #ifndef _math_ 10 - 11 - #define _math_ /* show symbols defined */ 12 - double acos(double x); 13 - double asin(double x); 14 - double atan(double x); 15 - double atan2(double y, double x); 16 - double ceil(double x); 17 - double cos(double x); 18 - double cosh(double x); 19 - double exp(double x); 20 - double fabs(double x); 21 - double floor(double x); 22 - double fmod(double x, double y); 23 - double frexp(double x, int *i); 24 - long labs(long l); 25 - double ldexp(double x, int n); 26 - double log(double x); 27 - double log10(double x); 28 - double modf(double x, int *i); 29 - double pow(double x, double y); 30 - double sin(double x); 31 - double sinh(double x); 32 - double sqrt(double x); 33 - double tan(double x); 34 - double tanh(double x); 35 - 36 - #define PI (3.14159265358979323846) 37 - #define PI2 (1.57079632679489661923) 38 - #define PI4 (0.78539816339744830966) 39 - 40 - #define E (2.71828182845904523536) 41 - 42 - typedef enum{ 43 - EDOM=33, 44 - ERANGE=34 45 - }; 46 - 47 - extern int errno; /* actually defined in stdio */ 48 - 49 - #endif
+12 -8
C Libraries/headers/proto.h #include files/proto.h
··· 93 93 94 94 /* storage.h */ 95 95 96 - char *clalloc(unsigned long count,unsigned long size); 97 - char *calloc(unsigned int count, unsigned int size); 98 - int free(char *ptr); 99 - int cfree(char *ptr); 100 - char *mlalloc(unsigned long size); 101 - char *malloc(unsigned int size); 102 - char *relalloc(char *ptr,unsigned long newsize); 103 - char *realloc(char *ptr,unsigned newsize); 96 + void *clalloc(unsigned long count,unsigned long size); 97 + void *calloc(unsigned int count, unsigned int size); 98 + int free(void *ptr); 99 + int cfree(void *ptr); 100 + void *mlalloc(unsigned long size); 101 + void *malloc(unsigned int size); 102 + void *relalloc(void *ptr,unsigned long newsize); 103 + void *realloc(void *ptr,unsigned newsize); 104 104 105 105 /* storageu.h */ 106 106 ··· 218 218 int getche(void); 219 219 char *cgets(char *s); 220 220 221 + /* For 3.0, these are macros. 221 222 int min(int v1, int v2); 222 223 int max(int v1, int v2); 224 + */ 223 225 224 226 int fclose(FILE *who); 225 227 FILE *fopen(char *nameptr, char *type); ··· 273 275 int getxpos(void); 274 276 int getypos(void); 275 277 void putch(char c); 278 + 279 + void SetFPU(int IsUsingFPU); 276 280 277 281 #ifndef _setjmph_ 278 282 #include "setjmp.h"
+1 -1
C Libraries/headers/sane.h #include files/sane.h
··· 28 28 typedef struct 29 29 { 30 30 short sgn; /* char */ 31 - short exp; 31 + short exponent; 32 32 struct 33 33 { 34 34 unsigned char length; /* was char sig[22] */
C Libraries/headers/setjmp.h #include files/setjmp.h
C Libraries/headers/signal.h #include files/signal.h
+7 -3
C Libraries/headers/stdio.h #include files/stdio.h
··· 29 29 #define stderr (&_file[STDERRNO]) 30 30 #define _console (&_console_) 31 31 32 + #define MAX(a, b) (a > b ? a : b) 33 + #define MIN(a, b) (a < b ? a : b) 34 + 32 35 typedef struct { 33 36 int refnum; /* OS Reference number */ 34 37 int last_error; /* holds last error on file */ ··· 77 80 78 81 int _closeall(); /* close all open files */ 79 82 extern int errno; 80 - 83 + 81 84 /* Default for these functions are int so they don't need to be declared 82 85 Boolean StdEvent(); -- this is fine since Booleans become ints 83 86 cprintf(); ··· 101 104 isupper(); 102 105 islower(); 103 106 kbhit(); 104 - max(); 105 - min(); 107 + 108 + - max() and min() are now defined as macros in <stdio.h> 109 + 106 110 puts(); 107 111 printf(); 108 112 sprintf();
+6 -6
C Libraries/headers/storage.h #include files/Storage.h
··· 11 11 #ifndef _storagech_ 12 12 #define _storagech_ 13 13 14 - char *calloc(); 15 - char *clalloc(); 14 + void *calloc(); 15 + void *clalloc(); 16 16 /* int cfree(); Default for these functions are int so they don't need to be declared*/ 17 17 /* int free(); */ 18 - char *malloc(); 19 - char *mlalloc(); 20 - char *realloc(); 21 - char *relalloc(); 18 + void *malloc(); 19 + void *mlalloc(); 20 + void *realloc(); 21 + void *relalloc(); 22 22 23 23 #endif
C Libraries/headers/storageu.h #include files/storageu.h
C Libraries/headers/strings.h #include files/strings.h
C Libraries/headers/time.h #include files/time.h
C Libraries/headers/types.h #include files/types.h
+12
C Libraries/headers/unix.h #include files/unix.h
··· 19 19 #include "signal.h" 20 20 #endif _signalh_ 21 21 22 + /* _UnixFPU_ is used to tell stdio whether to work with 80-bit (SANE) doubles 23 + or with 96-bit (68881) doubles. By default, it's undefined; if you 24 + are using 68881 code generation and wish to use stdio, uncomment the 25 + declaration and rebuild stdio and sprintf (there are only two files 26 + to recompile. 27 + 28 + <stdio.h> has a similar #define in it, called _FPU_, and it will have 29 + to be changed under the same conditions. 30 + */ 31 + 32 + #define _UnixFPU_ 33 + 22 34 double atof(); 23 35 long atol(); 24 36 long lseek();
+32 -32
C Libraries/sources/math.c Library Sources/Math.c
··· 10 10 11 11 */ 12 12 13 - 13 + #include "config.h" 14 14 #include "math.h" 15 15 #include "sane.h" 16 16 ··· 26 26 static double Pi2 = PI2; 27 27 static double Log2Ten = 3.321928094887362348; 28 28 29 + static short _Max[] = { 0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 30 + static short _MinusMax[] = { 0xFFFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 31 + #define Max (* (double *) _Max) 32 + #define MinusMax (* (double *) _MinusMax) 29 33 30 34 /* seed for pseudo-random number generator */ 31 35 static unsigned long seed = 1; ··· 40 44 41 45 /* ---------- error checking ---------- */ 42 46 43 - 44 - #define ERRORCHECK 45 - 46 - /* 47 - Error checking will be suppressed if ERRORCHECK is not #defined. 48 - 49 - To conform to standard C, error checking must be enabled. If 50 - the "stdio" library is not included in the project, the integer 51 - variable "errno" must be defined somewhere else. 52 - 53 - Without error checking, the math functions will execute somewhat 54 - faster, and no references to "errno" will result. 55 - */ 56 - 57 - #ifdef ERRORCHECK 47 + #ifdef _ERRORCHECK_ 58 48 59 49 #define DomainCheck(test, result) if (test) { \ 60 50 errno = EDOM; \ ··· 64 54 errno = ERANGE; \ 65 55 target = Max; \ 66 56 } 67 - static short _Max[] = { 0x7FFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 68 - static short _MinusMax[] = { 0xFFFE, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 69 - #define Max (* (double *) _Max) 70 - #define MinusMax (* (double *) _MinusMax) 71 57 72 - #else ERRORCHECK 58 + #else _ERRORCHECK_ 73 59 74 60 #define ClearExceptions() 75 61 #define DomainCheck(test, result) 76 62 #define RangeCheck(target) 77 63 78 - #endif ERRORCHECK 79 - 64 + #endif _ERRORCHECK_ 80 65 81 66 /* ---------- environment ---------- */ 82 67 ··· 115 100 * 116 101 */ 117 102 118 - #ifdef ERRORCHECK 103 + #ifdef _ERRORCHECK_ 119 104 static 120 105 ClearExceptions() 121 106 { ··· 125 110 state &= ~ERROR; 126 111 SetEnvironment(&state); 127 112 } 128 - #endif ERRORCHECK 113 + #endif _ERRORCHECK_ 129 114 130 115 131 116 /* ··· 268 253 double x; 269 254 { 270 255 int state = SetRound(ROUND_UP); 271 - 272 256 fp68k(&x, FORTI); 273 257 SetState(state); 274 258 return(x); ··· 282 266 283 267 double cos(x) 284 268 double x; 285 - { 269 + { 286 270 elems68k(&x, FOCOSX); 287 271 return(x); 288 272 } ··· 363 347 364 348 fp68k(&y, FOABS); 365 349 fp68k(&y, &z, FOREM); 350 + 366 351 if (x > 0 && z < 0) 367 352 z += y; 368 353 else if (x < 0 && z > 0) ··· 389 374 *nptr = 0; 390 375 return(Zero); 391 376 } 377 + 392 378 elems68k(&y, FOLOG2X); 379 + 393 380 y -= *nptr = y; 381 + 394 382 elems68k(&y, &z, FOPWRY); 383 + 395 384 if (z >= One) { 396 385 z *= PointFive; 397 386 ++*nptr; ··· 487 476 double x, y; 488 477 { 489 478 int exactint = 0; 490 - 479 + double z; 480 + 491 481 ClearExceptions(); 492 482 if (x == 0) { 493 - DomainCheck(y <= 0, MinusMax); 483 + if (y <= 0) { 484 + #ifdef _ERRORCHECK_ 485 + errno = EDOM; 486 + #endif 487 + return (MinusMax); 488 + } 494 489 return(Zero); 495 490 } 496 491 if (y == 0) 497 492 return(One); 498 493 if (x < 0) { 499 - DomainCheck(modf(y, &exactint), MinusMax); 494 + modf(y, &exactint); 495 + if (exactint != y) { 496 + #ifdef _ERRORCHECK_ 497 + errno = EDOM; 498 + #endif 499 + return (MinusMax); 500 + } 500 501 x = -x; 501 502 } 502 503 elems68k(&y, &x, FOPWRY); 504 + 503 505 RangeCheck(x); 504 506 return((exactint & 1) ? -x : x); 505 507 } 506 - 507 508 508 509 /* 509 510 * rand - pseudo-random number generator (ANSI C standard) ··· 603 604 double x; 604 605 { 605 606 double y = MinusTwo * fabs(x); 606 - 607 607 elems68k(&y, FOEXP1X); 608 608 y = -y / (y + Two); 609 609 xfersign(x, &y);
C Libraries/sources/stdio .c files/Dec2Str.Lib

This is a binary file and will not be displayed.

C Libraries/sources/stdio .c files/Str2Dec.Lib

This is a binary file and will not be displayed.

C Libraries/sources/stdio .c files/onexit.c Library Sources/stdio .c files/onexit.c
C Libraries/sources/stdio .c files/printf-1.c Library Sources/stdio .c files/printf-1.c
C Libraries/sources/stdio .c files/printf-1a.c Library Sources/stdio .c files/printf-1a.c
+25
C Libraries/sources/stdio .c files/printf-2-w.c Library Sources/stdio .c files/printf-2-w.c
··· 17 17 18 18 /* #define _NonMacScreen_ */ 19 19 20 + #include "config.h" 21 + 20 22 #ifndef _stdioh_ 21 23 #include "stdio.h" 22 24 #endif ··· 680 682 while (--p >= begp) *p = sp; 681 683 } 682 684 685 + /* RMS 4/20/88 */ 686 + /* procedure to determine if MultiFinder is running by checking for the 687 + existence of the WaitNextEvent() trap */ 688 + 689 + static int MFIsRunning() 690 + { /* $8F is for _MFDispatch, $9F is the unimplemented trap */ 691 + return (GetTrapAddress(0x8FL) != GetTrapAddress(0x9FL)); 692 + } 683 693 684 694 static 685 695 FILE *fopenwx(titlebar, upper_left, optionsptr, whichfilevar, ourwp) ··· 755 765 maxrow = (screenHeight - upper_left.v - _TOPEDGE - _CONTROLWIDTH - 1 - charheight + 1) / 756 766 charheight; 757 767 768 + /***************** RMS 4/20/88 *************** 769 + * 770 + * 771 + * If MultiFinder is running, we'll make the console window half-height, 772 + * so that we can see the contents while running the debugger. 773 + * 774 + * As soon as a possible, "MFIsRunning()" will be replaced by a 775 + * mechanism to see if the debugger is being used. 776 + * 777 + **********************************************/ 778 + 779 + #ifdef _HALFWINDOW_ 780 + if (MFIsRunning()) maxrow = 11; /* half a standard screen */ 781 + #endif 782 + 758 783 if (!maxcol) 759 784 maxcol = (screenWidth - upper_left.h - _LEFTEDGE - _CONTROLWIDTH - 1 - _sf.widMax + 1) / 760 785 _sf.widMax;
C Libraries/sources/stdio .c files/printf-2.c Library Sources/stdio .c files/printf-2.c
+66 -1
C Libraries/sources/stdio .c files/printf-3.c 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 + 12 14 #ifndef _stdioh_ 13 15 #include "stdio.h" 14 16 #endif ··· 23 25 24 26 #ifndef _setjmph_ 25 27 #include "setjmp.h" 28 + #endif 29 + 30 + #ifndef _math_ 31 + #include "Math.h" 32 + #endif 33 + 34 + #ifdef _MC68881_ 35 + /* conversion from 68881 to SANE extended type */ 36 + static void x96tox80(x96, x80) 37 + register Extended96 *x96; 38 + register Extended80 *x80; 39 + 40 + { 41 + (*x80).exponent = (*x96).exponent; 42 + (*x80).mantissa = (*x96).mantissa; 43 + } 44 + 45 + #define _tox80() x96tox80(doublep, &x80); 46 + #define _ToDecimal() fp68k(&_decform_, &x80, &_decimal_, FFEXT+FOB2D) 47 + 48 + #else 49 + 50 + #define _tox80() 51 + #define _ToDecimal() fp68k(&_decform_, doublep, &_decimal_, FFEXT+FOB2D) 52 + 26 53 #endif 27 54 28 55 /* it turns out that defining min, max, and isdigit as follows works pretty ··· 182 209 DecForm _decform_; /* information record for conversion */ 183 210 Decimal _decimal_; /* intermediate record */ 184 211 212 + #ifdef _MC68881_ 213 + Extended80 x80; 214 + #endif 215 + 216 + /* convert double to Extended80 (as defined in Math881.h) */ 217 + _tox80(); 218 + 185 219 /* convert binary to decimal record */ 186 220 187 221 _decform_.style = style; 188 222 _decform_.digits = digits; 189 223 190 - fp68k(&_decform_, doublep, &_decimal_, FFEXT+FOB2D); 224 + _ToDecimal(); 191 225 192 226 /* decimal record to string */ 193 227 ··· 590 624 } 591 625 argument += sizeof (int); 592 626 break; 627 + 628 + case 'p': 629 + {register char *char_ptr; 630 + 631 + /* get the length of the string */ 632 + char_ptr = *((char **)argument); 633 + length = *char_ptr++; 634 + argument += sizeof(char_ptr); 635 + 636 + /* check for truncation */ 637 + if (do_precision) 638 + if (length > precision) length = precision; 639 + 640 + /* set width to padding width */ 641 + if ((width -= length) < 0) width = 0; 642 + 643 + if (left_justify) 644 + { 645 + while (--length >= 0) 646 + (*outputx)(*char_ptr++); 647 + 648 + padd(BLANKS, width); 649 + } 650 + else 651 + { 652 + padd(zero_fill, width); 653 + while (--length >= 0) 654 + (*outputx)(*char_ptr++); 655 + } 656 + break; 657 + } 593 658 594 659 case 's': 595 660 {register char *char_ptr;
C Libraries/sources/stdio .c files/printf-4.c Library Sources/stdio .c files/printf-4.c
C Libraries/sources/stdio .c files/scanf1.c Library Sources/stdio .c files/scanf1.c
+62 -8
C Libraries/sources/stdio .c files/scanf2.c 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 + 7 9 #ifndef _stdioh_ 8 10 #include "stdio.h" 9 11 #endif ··· 24 26 #include "setjmp.h" 25 27 #endif 26 28 29 + #ifndef _math_ 30 + #include "Math.h" 31 + #endif 32 + 33 + #include "pascal.h" 34 + 35 + #ifdef _MC68881_ 36 + 37 + /* conversion from 68881 to SANE extended type */ 38 + static void x96tox80(x96, x80) 39 + register Extended96 *x96; 40 + register Extended80 *x80; 41 + 42 + { 43 + (*x80).exponent = (*x96).exponent; 44 + (*x80).mantissa = (*x96).mantissa; 45 + } 46 + 47 + static void x80tox96(x80, x96) 48 + register Extended80 *x80; 49 + register Extended96 *x96; 50 + { 51 + (*x96).exponent = (*x80).exponent; 52 + (*x96).reserved = 0; 53 + (*x96).mantissa = (*x80).mantissa; 54 + } 55 + 56 + #define _fromDecimal() fp68k(&_decimal_,&x80,FFEXT|FOD2B) 57 + #define _tox96() x80tox96(&x80, *(double**)argument) 58 + #else 59 + 60 + #define _fromDecimal() fp68k(&_decimal_,*(double**)argument,FFEXT|FOD2B) 61 + #define _tox96() 62 + #endif 63 + 27 64 /*---------------------------------------------------------------------------- 28 65 some global storage to prevent excessive parameter transfer 29 66 ----------------------------------------------------------------------------*/ ··· 39 76 static 40 77 int from_memory() 41 78 { 42 - return(*destination++); /* return next character in memory stream */ 79 + register unsigned char c; 80 + c = *destination; 81 + if (c) { 82 + destination++; 83 + return(c); 84 + } else return(EOF); 43 85 } 44 86 45 87 static ··· 49 91 destination--; 50 92 } 51 93 52 - 53 94 #line 0 sscanf 54 95 int sscanf(dest, fmt) 55 96 unsigned char *dest; /* pointer to buffer space */ ··· 168 209 169 210 return(c); /* returns character after white space */ 170 211 } 171 - 172 - 173 212 int _scanf_scan(fmt) 174 213 char **fmt; /* pointer to pointer to format string */ 175 214 { ··· 189 228 int i; /* counter */ 190 229 register count; /* counter */ 191 230 register int (*_scanf_putbackx)() = _scanf_putback; 231 + 232 + #ifdef _MC68881_ 233 + Extended80 x80; 234 + #endif 192 235 193 236 if (count=setjmp(_scanf_env)) return (count); /* set up error handler */ 194 237 ··· 351 394 } 352 395 353 396 break; 354 - 397 + 398 + case 'p': 355 399 case 's': 400 + { char *strStart; 356 401 /* first char cannot be EOF after skip_white */ 357 402 358 403 (*_scanf_putbackx)(skip_white()); 359 404 360 405 loc = (char **)argument; 406 + strStart = *loc; 361 407 362 408 do 363 409 { 364 410 if ((curr_char = (*_scanf_input)()) == EOF) 365 411 { 366 - if (assign) **(char**) loc = '\0'; 412 + if (assign) { 413 + **(char**) loc = '\0'; 414 + if (c == 'p') CtoPstr(strStart); 415 + } 367 416 return (count); 368 417 } 369 418 ··· 384 433 if (assign) 385 434 **(char **)loc = '\0'; 386 435 436 + 387 437 if (assign) 388 438 { 389 439 argument += sizeof(long); 440 + if (c == 'p') CtoPstr(strStart); 390 441 count++; 391 442 } 392 443 break; 444 + } 393 445 394 446 case '[': neg = false; 395 447 ··· 500 552 501 553 if (assign) 502 554 { 503 - if (its_a_long) 504 - fp68k(&_decimal_,*(double**)argument,FFEXT|FOD2B); 555 + if (its_a_long) { 556 + _fromDecimal(); 557 + _tox96(); 558 + } 505 559 else 506 560 if (its_a_short) 507 561 fp68k(&_decimal_,*(short double**)argument,FFDBL|FOD2B);
C Libraries/sources/stdio .c files/std_decode.c Library Sources/stdio .c files/std_decode.c
C Libraries/sources/stdio .c files/stddata_ctype.c Library Sources/stdio .c files/stddata_ctype.c
C Libraries/sources/stdio .c files/stddata_file.c Library Sources/stdio .c files/stddata_file.c
C Libraries/sources/stdio .c files/stdfile_error.c Library Sources/stdio .c files/stdfile_error.c
C Libraries/sources/stdio .c files/stdfile_pos.c Library Sources/stdio .c files/stdfile_pos.c
C Libraries/sources/stdio .c files/stdfilebuf.c Library Sources/stdio .c files/stdfilebuf.c
C Libraries/sources/stdio .c files/stdfwrite.c Library Sources/stdio .c files/stdfwrite.c
+1 -3
C Libraries/sources/stdio .c files/stdget_console.c Library Sources/stdio .c files/stdget_console.c
··· 32 32 int (*_key_int_sig_func_)() = 0; 33 33 34 34 extern long ATrapHandler : 0x28; 35 - extern long ROMBase : 0x2AE; 36 - extern long Lo3Bytes : 0x31A; 37 35 38 - #define DebuggerIn() ((ATrapHandler & Lo3Bytes) < (ROMBase & Lo3Bytes)) 36 + #define DebuggerIn() (((long)ATrapHandler & Lo3Bytes) < (long)((long)ROMBase & Lo3Bytes)) 39 37 40 38 /* pdg - 6/18/86 - completely revised command character handling of the 41 39 following function to allow control characters to be
C Libraries/sources/stdio .c files/stdgets.c Library Sources/stdio .c files/stdgets.c
C Libraries/sources/stdio .c files/stdmax_min.c Library Sources/stdio .c files/stdmax_min.c
C Libraries/sources/stdio .c files/stdopen.c Library Sources/stdio .c files/stdopen.c
C Libraries/sources/stdio .c files/stdput_console.c Library Sources/stdio .c files/stdput_console.c
+9 -9
C Libraries/sources/stdio .c files/stdputs.c Library Sources/stdio .c files/stdputs.c
··· 48 48 { 49 49 ioParam pb; /* my parameter block for PB's */ 50 50 51 + if (who->StdStream) 52 + { 53 + stdwsave(who, &saverec); 54 + putch(c); /* put char directly to the screen */ 55 + stdwrestore(who, &saverec); 56 + return(c); /* never an error on fputc(stdout). */ 57 + } 58 + 51 59 if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */ 52 60 { 53 61 if (!who->wr) ··· 57 65 return(EOF); 58 66 } 59 67 60 - 61 - if (who->StdStream) 62 - { 63 - stdwsave(who, &saverec); 64 - putch(c); /* put char directly to the screen */ 65 - stdwrestore(who, &saverec); 66 - return(c); /* never an error on fputc(stdout). */ 67 - } 68 68 69 69 if (who->fpos>(BUFSIZ-1)) 70 70 if (write_to_buffer(who)) ··· 83 83 register FILE *who; 84 84 85 85 { 86 - register int c; 86 + register unsigned char c; 87 87 88 88 if ((!who)||(!who->InUse)||(!who->wr)) /* error if file not open */ 89 89 {
C Libraries/sources/stdio .c files/stdto..x.c Library Sources/stdio .c files/stdto..x.c
+2 -2
C Libraries/sources/stdio .c files/stdver.c 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[] = "LightspeedC Libraries 2.15"; 19 - static char copyright[] = "(C) 1986 THINK Technologies, Inc. All rights reserved."; 18 + static char STDIO_VERSION[] = "THINK C Libraries 3.01"; 19 + static char copyright[] = "� 1988 Symantec Corp. All rights reserved."; 20 20 21 21 return (STDIO_VERSION); 22 22 }
+11 -11
C Libraries/sources/storage .c files/storage.c Library Sources/storage .c files/storage.c
··· 34 34 #define CLEAR 1 35 35 36 36 #line 0 clalloc 37 - char *clalloc(count,size) 37 + void *clalloc(count,size) 38 38 unsigned long count; 39 39 unsigned long size; 40 40 { ··· 50 50 } 51 51 52 52 #line 0 calloc 53 - char *calloc(count, size) 53 + void *calloc(count, size) 54 54 unsigned int count; 55 55 unsigned int size; 56 56 { ··· 61 61 62 62 #line 0 free 63 63 int free(ptr) 64 - char *ptr; 64 + void *ptr; 65 65 { 66 66 /* Get the handle back from the pointer */ 67 67 ··· 72 72 73 73 #line 0 cfree 74 74 int cfree(ptr) 75 - char *ptr; 75 + void *ptr; 76 76 { 77 77 free(ptr); 78 78 } 79 79 80 80 #line 0 mlalloc 81 - char *mlalloc(size) 81 + void *mlalloc(size) 82 82 unsigned long size; 83 83 { 84 84 return NewPtr(size); 85 85 } 86 86 87 87 #line 0 malloc 88 - char *malloc(size) 88 + void *malloc(size) 89 89 unsigned int size; 90 90 { 91 91 return NewPtr(size); 92 92 } 93 93 94 94 #line 0 relalloc 95 - char *relalloc(ptr,newsize) 96 - char *ptr; 95 + void *relalloc(ptr,newsize) 96 + void *ptr; 97 97 unsigned long newsize; 98 98 { 99 99 unsigned long oldsize; 100 - char *pnew; 100 + void *pnew; 101 101 102 102 SetPtrSize(ptr, newsize); 103 103 ··· 116 116 117 117 118 118 #line 0 realloc 119 - char *realloc(ptr,newsize) 120 - char *ptr; 119 + void *realloc(ptr,newsize) 120 + void *ptr; 121 121 unsigned newsize; 122 122 { 123 123 return (relalloc(ptr, (long)newsize));
C Libraries/sources/storage .c files/storageu.c Library Sources/storage .c files/storageu.c
C Libraries/sources/strings .c files/strings.c Library Sources/strings .c files/strings.c
C Libraries/sources/strings .c files/stringsasm.c Library Sources/strings .c files/stringsasm.c
C Libraries/sources/strings .c files/unix_strings.c Library Sources/strings .c files/unix_strings.c
C Libraries/sources/unix .c files/qsort.c Library Sources/unix .c files/qsort.c
C Libraries/sources/unix .c files/unix2.c Library Sources/unix .c files/unix2.c
C Libraries/sources/unix .c files/unix3.c Library Sources/unix .c files/unix3.c
-21
C Libraries/sources/unix .c files/unixatof.c
··· 1 - /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 - 3 - #include "unix.h" 4 - #include "sane.h" 5 - #include "MacTypes.h" 6 - 7 - double atof(s) 8 - char *s; 9 - 10 - { 11 - 12 - Decimal _decimal_; 13 - int index=0; 14 - Boolean read_error; 15 - double x; 16 - 17 - 18 - CStr2Dec(s,&index,&_decimal_,&read_error); 19 - fp68k(&_decimal_,&x,FFEXT|FOD2B); 20 - return(x); 21 - }
C Libraries/sources/unix .c files/unixatox.c Library Sources/unix .c files/unixatox.c
C Libraries/sources/unix .c files/unixexec.c Library Sources/unix .c files/unixexec.c
C Libraries/sources/unix .c files/unixexit.c Library Sources/unix .c files/unixexit.c
+1 -1
C Libraries/sources/unix .c files/unixfileio.c Library Sources/unix .c files/unixfileio.c
··· 64 64 return (NULL); 65 65 } 66 66 67 - if ((mode & O_CREAT)||(mode & O_TRUNC)) 67 + if (mode & O_TRUNC) 68 68 { 69 69 stdmode[i++] = 'w'; 70 70 stdmode[i++] = '+';
C Libraries/sources/unix .c files/unixid.c Library Sources/unix .c files/unixid.c
C Libraries/sources/unix .c files/unixmem.c Library Sources/unix .c files/unixmem.c
C Libraries/sources/unix .c files/unixplot.c Library Sources/unix .c files/unixplot.c
C Libraries/sources/unix .c files/unixsetbuf.c Library Sources/unix .c files/unixsetbuf.c
C Libraries/sources/unix .c files/unixsignal.c Library Sources/unix .c files/unixsignal.c
C Libraries/sources/unix .c files/unixst2d.c Library Sources/unix .c files/unixst2d.c
C Libraries/sources/unix .c files/unixst2i.c Library Sources/unix .c files/unixst2i.c
C Libraries/sources/unix .c files/unixtime.c Library Sources/unix .c files/unixtime.c
+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
+384
Library Sources/Math881.c
··· 1 + 2 + /* 3 + 4 + Math library for LightspeedC 5 + 6 + (C) Copyright 1986 THINK Technologies. All rights reserved. 7 + 8 + For details, refer to Harbison & Steele's "C: A Reference Manual", 9 + Chapter 11. 10 + 11 + */ 12 + 13 + #include "config.h" 14 + #include "Math.h" 15 + 16 + /* useful constants */ 17 + static double Zero = 0.0; 18 + static double One = 1.0; 19 + static double MinusOne = -1.0; 20 + static double Pi = PI; 21 + static double Pi2 = PI2; 22 + 23 + 24 + /* seed for pseudo-random number generator */ 25 + static unsigned long seed = 1; 26 + 27 + #ifdef _ERRORCHECK_ 28 + 29 + extern int errno; /* defined in stdio */ 30 + 31 + #define EDOM 33 32 + #define ERANGE 34 33 + 34 + #define ERROR 0x0000FF00 /* 68881 mask to check for exceptions */ 35 + 36 + /* GetState() and ClearExceptions() are in Math881.a */ 37 + /* 38 + GetState returns the entire 68881 Floating-Point Status Register (FPSR); 39 + ClearExceptions ANDs the FPSR with $00FF0000 to clear all but the quotient 40 + byte. 41 + */ 42 + 43 + long GetState(); 44 + void ClearExceptions(); 45 + 46 + #define DomainCheck(test, result) if (test) { \ 47 + errno = EDOM; \ 48 + return(result); \ 49 + } 50 + 51 + #define RangeCheck(target) if (GetState() & ERROR) { \ 52 + errno = ERANGE; \ 53 + target = Max; \ 54 + } 55 + 56 + static short _Max[] = { 0x7FFE, 0x0000, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 57 + static short _MinusMax[] = { 0xFFFE, 0x0000, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 58 + #define Max (* (double *) _Max) 59 + #define MinusMax (* (double *) _MinusMax) 60 + 61 + #else 62 + #define DomainCheck(test, result) 63 + #define RangeCheck(value) 64 + #endif 65 + 66 + /* 67 + the functions rand, srand, and xfersign 68 + get defined regardless of whether there's error checking or not. 69 + */ 70 + 71 + /* rand - pseudo-random number generator (ANSI C standard) */ 72 + 73 + int rand() 74 + { 75 + seed = seed * 1103515245 + 12345; 76 + asm { 77 + move.w seed,d0 ; high word of long 78 + andi.w #0x7FFF,d0 ; remove high bit 79 + } 80 + } 81 + 82 + 83 + /* srand - seed pseudo-random number generator */ 84 + 85 + void srand(n) 86 + unsigned n; 87 + { 88 + seed = n; 89 + } 90 + 91 + /* xfersign - transfer sign from one floating number to another */ 92 + 93 + static 94 + xfersign(x, yp) 95 + double x, *yp; 96 + { 97 + asm { 98 + movea.l yp,a0 99 + bclr #7,(a0) 100 + tst.w x 101 + bpl.s @1 102 + bset #7,(a0) 103 + @1 } 104 + } 105 + 106 + 107 + #ifdef _ERRORCHECK_ 108 + 109 + /* ---------- math functions (alphabetically) ---------- */ 110 + 111 + 112 + /* 113 + * acos - inverse circular cosine 114 + * 115 + */ 116 + 117 + double acos(x) 118 + register double x; 119 + { 120 + DomainCheck(x > One || x < MinusOne, Zero); 121 + if (x == MinusOne) 122 + return(Pi); 123 + return(_acos(x)); 124 + } 125 + 126 + 127 + /* 128 + * asin - inverse circular sine 129 + * 130 + */ 131 + 132 + double asin(x) 133 + register double x; 134 + { 135 + double y = fabs(x); 136 + 137 + DomainCheck(y > One, Zero); 138 + return(_asin(x)); 139 + } 140 + 141 + 142 + /* 143 + * atan - inverse circular tangent - defined as macro in Math881.h 144 + * 145 + */ 146 + double atan(x) 147 + register double x; 148 + { 149 + return(_atan(x)); 150 + } 151 + 152 + double atan2(y, x) 153 + register double y, x; 154 + { 155 + return(_atan2(y, x)); 156 + } 157 + 158 + /* 159 + * ceil - round up to an integer 160 + * 161 + */ 162 + 163 + double ceil(x) 164 + register double x; 165 + { 166 + return(_ceil(x)); 167 + } 168 + 169 + 170 + /* 171 + * cos - circular cosine 172 + * 173 + */ 174 + 175 + double cos(x) 176 + register double x; 177 + { 178 + return(_cos(x)); 179 + } 180 + 181 + 182 + /* 183 + * cosh - hyperbolic cosine 184 + * 185 + */ 186 + 187 + double cosh(x) 188 + register double x; 189 + { 190 + ClearExceptions(); 191 + x = _cosh(x); 192 + RangeCheck(x); 193 + return(x); 194 + } 195 + 196 + 197 + /* 198 + * exp - exponential function 199 + * 200 + */ 201 + 202 + double exp(x) 203 + register double x; 204 + { 205 + ClearExceptions(); 206 + x = _exp(x); 207 + RangeCheck(x); 208 + return(x); 209 + } 210 + 211 + 212 + /* 213 + * fabs - absolute value of a floating number 214 + * 215 + */ 216 + 217 + double fabs(x) 218 + register double x; 219 + { 220 + return(_fabs(x)); 221 + } 222 + 223 + 224 + /* 225 + * floor - round down to an integer 226 + * 227 + */ 228 + 229 + double floor(x) 230 + register double x; 231 + { 232 + return(_floor(x)); 233 + } 234 + 235 + 236 + /* 237 + * fmod - remainder function 238 + * 239 + * This computes a value z, with the same sign as x, such that for some 240 + * integer k, k*y + z == x. 241 + * 242 + */ 243 + 244 + double fmod(x, y) 245 + register double x, y; 246 + { 247 + return(_fmod(x, y)); 248 + } 249 + 250 + 251 + /* 252 + * frexp - split floating number into fraction/exponent 253 + * 254 + * This computes a value z, where 0.5 <= fabs(z) < 1.0, and an integer n such 255 + * that z*(2^n) == x. 256 + * 257 + */ 258 + 259 + double frexp(x, nptr) 260 + register double x; 261 + register int *nptr; 262 + { 263 + return(_frexp(x, nptr)); 264 + } 265 + 266 + 267 + /* 268 + * ldexp - combine fraction/exponent into a floating number 269 + * 270 + */ 271 + 272 + double ldexp(x, n) 273 + register double x; 274 + register int n; 275 + { 276 + return(_ldexp(x, n)); 277 + } 278 + 279 + 280 + /* 281 + * log - natural logarithm 282 + * 283 + */ 284 + 285 + double log(x) 286 + register double x; 287 + { 288 + DomainCheck(x <= 0, MinusMax); 289 + return(_log(x)); 290 + } 291 + 292 + 293 + /* 294 + * log10 - logarithm base 10 295 + * 296 + */ 297 + 298 + double log10(x) 299 + register double x; 300 + { 301 + DomainCheck(x <= 0, MinusMax); 302 + return(_log10(x)); 303 + } 304 + 305 + 306 + /* pow - power function (exponentiation) */ 307 + 308 + double pow(x, y) 309 + register double x, y; 310 + { 311 + return(_pow(x, y)); /* _pow() does the proper error checking. */ 312 + } 313 + 314 + 315 + /* 316 + * sin - circular sine 317 + * 318 + */ 319 + 320 + double sin(x) 321 + register double x; 322 + { 323 + return(_sin(x)); 324 + } 325 + 326 + 327 + /* 328 + * sinh - hyperbolic sine 329 + * 330 + */ 331 + 332 + double sinh(x) 333 + register double x; 334 + { 335 + register double y; 336 + 337 + ClearExceptions(); 338 + y = _sinh(x); 339 + RangeCheck(y); 340 + return(y); 341 + } 342 + 343 + 344 + /* 345 + * sqrt - square root 346 + * 347 + */ 348 + 349 + double sqrt(x) 350 + register double x; 351 + { 352 + DomainCheck(x < 0, Zero); 353 + return(_sqrt(x)); 354 + } 355 + 356 + 357 + /* 358 + * tan - circular tangent 359 + * 360 + */ 361 + 362 + double tan(x) 363 + register double x; 364 + { 365 + ClearExceptions(); 366 + x = _tan(x); 367 + RangeCheck(x); 368 + return(x); 369 + } 370 + 371 + 372 + /* 373 + * tanh - hyperbolic tangent 374 + * 375 + */ 376 + 377 + double tanh(x) 378 + double x; 379 + { 380 + return(_tanh(x)); 381 + } 382 + 383 + #endif _ERRORCHECK_ 384 +
+704
Library Sources/MathHybrid.c
··· 1 + 2 + /* 3 + 4 + Math library for LightspeedC 5 + 6 + (C) Copyright 1986 THINK Technologies. All rights reserved. 7 + 8 + For details, refer to Harbison & Steele's "C: A Reference Manual", 9 + Chapter 11. 10 + 11 + */ 12 + 13 + #include "config.h" 14 + #include "math.h" 15 + #include "sane.h" 16 + 17 + /* useful constants */ 18 + static double Zero = 0.0; 19 + static double One = 1.0; 20 + static double Two = 2.0; 21 + static double MinusOne = -1.0; 22 + static double MinusTwo = -2.0; 23 + static double PointFive = 0.5; 24 + static double PointTwoFive = 0.25; 25 + static double Pi = PI; 26 + static double Pi2 = PI2; 27 + static double Log2Ten = 3.321928094887362348; 28 + 29 + /* the 80-bit extended "_x80" is used as the destination to convert the 30 + arguments to SANE doubles. */ 31 + static Extended80 _x80; 32 + 33 + /* the extra word of zeros is for 68881 compatibility. */ 34 + static short _Max[] = { 0x7FFE, 0x0000, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 35 + static short _MinusMax[] = { 0xFFFE, 0x0000, 0x7FFF, 0xFFFF, 0xFFFF, 0xFFFF }; 36 + #define Max (* (double *) _Max) 37 + #define MinusMax (* (double *) _MinusMax) 38 + 39 + /* routines for conversion between 80- and 96-bit formats */ 40 + 41 + void x80tox96(x80, x96) 42 + register Extended80 *x80; 43 + register Extended96 *x96; 44 + { 45 + (*x96).exponent = (*x80).exponent; 46 + (*x96).reserved = 0; 47 + (*x96).mantissa = (*x80).mantissa; 48 + } 49 + 50 + void x96tox80(x96, x80) 51 + register Extended96 *x96; 52 + register Extended80 *x80; 53 + 54 + { 55 + (*x80).exponent = (*x96).exponent; 56 + (*x80).mantissa = (*x96).mantissa; 57 + } 58 + 59 + #define _x80tox96(x80, x96) x80tox96(&x80, &x96) 60 + #define _x96tox80(x96, x80) x96tox80(&x96, &x80) 61 + 62 + #define _to80(x) _x96tox80(x, _x80); 63 + #define _to96(x) _x80tox96(_x80, x); 64 + 65 + /* seed for pseudo-random number generator */ 66 + static unsigned long seed = 1; 67 + 68 + 69 + /* environment word masks */ 70 + #define ROUND 0x6000 71 + #define ROUND_UP 0x2000 72 + #define ROUND_DOWN 0x4000 73 + #define ERROR 0x0F00 74 + 75 + 76 + /* ---------- error checking ---------- */ 77 + 78 + #ifdef _ERRORCHECK_ 79 + 80 + #define DomainCheck(test, result) if (test) { \ 81 + errno = EDOM; \ 82 + return(result); \ 83 + } 84 + #define RangeCheck(target) if (GetState() & ERROR) { \ 85 + errno = ERANGE; \ 86 + target = Max; \ 87 + } 88 + 89 + #else _ERRORCHECK_ 90 + 91 + #define ClearExceptions() 92 + #define DomainCheck(test, result) 93 + #define RangeCheck(target) 94 + 95 + #endif _ERRORCHECK_ 96 + 97 + /* 98 + * GetState - query environment word 99 + * 100 + */ 101 + 102 + static 103 + GetState() 104 + { 105 + int state; 106 + 107 + GetEnvironment(&state); 108 + return(state); 109 + } 110 + 111 + 112 + /* 113 + * SetState - define environment word 114 + * 115 + */ 116 + 117 + static 118 + SetState(state) 119 + { 120 + SetEnvironment(&state); 121 + } 122 + 123 + 124 + /* 125 + * ClearExceptions - clear error conditions 126 + * 127 + * This must be called if RangeCheck is to be used. 128 + * 129 + */ 130 + 131 + #ifdef _ERRORCHECK_ 132 + static 133 + ClearExceptions() 134 + { 135 + int state; 136 + 137 + GetEnvironment(&state); 138 + state &= ~ERROR; 139 + SetEnvironment(&state); 140 + } 141 + #endif _ERRORCHECK_ 142 + 143 + 144 + /* 145 + * SetRound - define rounding direction 146 + * 147 + * The previous environment word is returned. The rounding direction can 148 + * be restored by passing this value to SetState. 149 + * 150 + */ 151 + 152 + static 153 + SetRound(direction) 154 + { 155 + int state; 156 + 157 + GetEnvironment(&state); 158 + SetState((state & ~ROUND) | direction); 159 + return(state); 160 + } 161 + 162 + 163 + /* 164 + * xfersign - transfer sign from one floating number to another 165 + * 166 + */ 167 + 168 + static 169 + xfersign(x, yp) 170 + double x, *yp; 171 + { 172 + asm { 173 + movea.l yp,a0 174 + bclr #7,(a0) 175 + tst.w x 176 + bpl.s @1 177 + bset #7,(a0) 178 + @1 } 179 + } 180 + 181 + 182 + /* ---------- math functions (alphabetically) ---------- */ 183 + 184 + 185 + /* 186 + * abs - absolute value of an integer 187 + * 188 + */ 189 + 190 + int abs(x) 191 + int x; 192 + { 193 + return(x < 0 ? -x : x); 194 + } 195 + 196 + /* the real functions are here, in fact, when _ERRORCHECK_ is undefined, 197 + they will be called directly.*/ 198 + 199 + /* some pre-declarations..*/ 200 + double _exp(); 201 + double _fabs(); 202 + 203 + double _acos(x) 204 + double x; 205 + { 206 + return(Two * atan(sqrt((One - x) / (One + x)))); 207 + } 208 + 209 + double _asin(x) 210 + double x; 211 + { 212 + double y = _fabs(x); 213 + 214 + DomainCheck(y > One, Zero); 215 + if (y == One) { 216 + y = Pi2; 217 + xfersign(x, &y); 218 + return(y); 219 + } 220 + if (y > PointFive) { 221 + y = One - y; 222 + y = Two * y - y * y; 223 + } 224 + else 225 + y = One - y * y; 226 + return(atan(x / sqrt(y))); 227 + } 228 + 229 + double _atan(x) 230 + double x; 231 + { 232 + _to80(x); 233 + elems68k(&_x80, FOATANX); 234 + _to96(x); 235 + return(x); 236 + } 237 + 238 + double _atan2(y, x) 239 + double y, x; 240 + { 241 + double z; 242 + 243 + if (x == 0) { 244 + DomainCheck(y == 0, Zero); 245 + z = Pi2; 246 + } 247 + else { 248 + z = atan(fabs(y / x)); 249 + if (x < 0) 250 + z = Pi - z; 251 + } 252 + xfersign(y, &z); 253 + return(z); 254 + } 255 + 256 + double _ceil(x) 257 + double x; 258 + { 259 + register int state = SetRound(ROUND_UP); 260 + _to80(x); 261 + fp68k(&_x80, FORTI); 262 + SetState(state); 263 + _to96(x); 264 + return(x); 265 + } 266 + 267 + double _cos(x) 268 + double x; 269 + { 270 + _to80(x) 271 + elems68k(&_x80, FOCOSX); 272 + _to96(x) 273 + return(x); 274 + } 275 + 276 + double _cosh(x) 277 + double x; 278 + { 279 + ClearExceptions(); 280 + x = PointFive * _exp(_fabs(x)); 281 + x += PointTwoFive / x; 282 + RangeCheck(x); 283 + return(x); 284 + } 285 + 286 + double _exp(x) 287 + double x; 288 + { 289 + _to80(x); 290 + elems68k(&_x80, FOEXPX); 291 + _to96(x); 292 + return(x); 293 + } 294 + 295 + double _fabs(x) 296 + double x; 297 + { 298 + _to80(x); 299 + fp68k(&_x80, FOABS); 300 + _to96(x); 301 + return(x); 302 + } 303 + 304 + double _floor(x) 305 + double x; 306 + { 307 + register int state = SetRound(ROUND_DOWN); 308 + 309 + _to80(x); 310 + fp68k(&_x80, FORTI); 311 + _to96(x); 312 + SetState(state); 313 + return(x); 314 + } 315 + 316 + double _fmod(x, y) 317 + double x, y; 318 + { 319 + double z; 320 + Extended80 tz; 321 + _x96tox80(x, tz); 322 + _to80(y); 323 + fp68k(&_x80, FOABS); 324 + fp68k(&_x80, &tz, FOREM); 325 + _x80tox96(tz, z); 326 + 327 + if (x > 0 && z < 0) 328 + z += y; 329 + else if (x < 0 && z > 0) 330 + z -= y; 331 + return(z); 332 + } 333 + 334 + double _frexp(x, nptr) 335 + double x; 336 + register int *nptr; 337 + { 338 + double y = fabs(x), z = Two; 339 + Extended80 ty, tz; 340 + 341 + if (y == 0) { 342 + *nptr = 0; 343 + return(Zero); 344 + } 345 + 346 + _x96tox80(y, ty); 347 + elems68k(&ty, FOLOG2X); 348 + _x80tox96(ty, y); 349 + 350 + y -= *nptr = y; 351 + 352 + _x96tox80(y, ty); 353 + _x96tox80(z, tz); 354 + elems68k(&ty, &tz, FOPWRY); 355 + _x80tox96(ty, y); 356 + _x80tox96(tz, z); 357 + 358 + if (z >= One) { 359 + z *= PointFive; 360 + ++*nptr; 361 + } 362 + else if (z < PointFive) { 363 + z += z; 364 + --*nptr; 365 + } 366 + xfersign(x, &z); 367 + return(z); 368 + } 369 + 370 + double _ldexp(x, n) 371 + double x; 372 + int n; 373 + { 374 + _to80(x); 375 + fp68k(&n, &_x80, FOSCALB); 376 + _to96(x); 377 + return(x); 378 + } 379 + 380 + double _log(x) 381 + double x; 382 + { 383 + _to80(x); 384 + elems68k(&_x80, FOLNX); 385 + _to96(x); 386 + return(x); 387 + } 388 + 389 + double _log10(x) 390 + double x; 391 + { 392 + _to80(x); 393 + elems68k(&_x80, FOLOG2X); /* LOG2 is much faster than LN */ 394 + _to96(x); 395 + return(x/ Log2Ten); 396 + } 397 + 398 + double _modf(x, nptr) 399 + double x; 400 + register int *nptr; 401 + { 402 + if (abs(*nptr = x) > _fabs(x)) { 403 + if (*nptr > 0) 404 + --*nptr; 405 + else 406 + ++*nptr; 407 + } 408 + return(x - *nptr); 409 + } 410 + 411 + double _pow(x, y) 412 + double x, y; 413 + { 414 + double tx, ty; 415 + _x96tox80(y, ty); 416 + _x96tox80(x, tx); 417 + elems68k(&ty, &tx, FOPWRY); 418 + _x80tox96(ty, y); 419 + _x80tox96(tx, x); 420 + } 421 + 422 + double _sin(x) 423 + double x; 424 + { 425 + _to80(x); 426 + elems68k(&_x80, FOSINX); 427 + _to96(x); 428 + return(x); 429 + } 430 + 431 + double _sinh(x) 432 + double x; 433 + { 434 + double y = _fabs(x); 435 + 436 + _to80(y); 437 + elems68k(&_x80, FOEXP1X); 438 + _to96(y); 439 + y += y / (y + One); 440 + y *= PointFive; 441 + 442 + xfersign(x, &y); 443 + return(y); 444 + } 445 + 446 + double _sqrt(x) 447 + double x; 448 + { 449 + _to80(x); 450 + fp68k(&_x80, FOSQRT); 451 + _to96(x); 452 + return(x); 453 + } 454 + 455 + double _tan(x) 456 + double x; 457 + { 458 + _to80(x); 459 + elems68k(&_x80, FOTANX); 460 + _to96(x); 461 + return(x); 462 + } 463 + 464 + double _tanh(x) 465 + double x; 466 + { 467 + double y = MinusTwo * _fabs(x); 468 + _to80(y); 469 + elems68k(&_x80, FOEXP1X); 470 + _to96(y); 471 + y = -y / (y + Two); 472 + xfersign(x, &y); 473 + return(y); 474 + } 475 + 476 + long labs(x) 477 + long x; 478 + { 479 + return(x < 0 ? x: -x); 480 + } 481 + 482 + int rand() 483 + { 484 + seed = seed * 1103515245 + 12345; 485 + asm { 486 + move.w seed,d0 ; high word of long 487 + andi.w #0x7FFF,d0 ; remove high bit 488 + } 489 + } 490 + 491 + void srand(n) 492 + unsigned n; 493 + { 494 + seed = n; 495 + } 496 + 497 + 498 + #ifdef _ERRORCHECK_ 499 + double acos(x) 500 + double x; 501 + { 502 + DomainCheck(x > One || x < MinusOne, Zero); 503 + if (x == MinusOne) 504 + return(Pi); 505 + return(_acos(x)); 506 + } 507 + 508 + double asin(x) 509 + double x; 510 + { 511 + return(_asin(x)); 512 + } 513 + 514 + 515 + double atan(x) 516 + double x; 517 + { 518 + return(_atan(x)); 519 + } 520 + 521 + 522 + double atan2(y, x) 523 + double y, x; 524 + { 525 + return(_atan2(y, x)); 526 + } 527 + 528 + double ceil(x) 529 + double x; 530 + { 531 + return(_ceil(x)); 532 + } 533 + 534 + double cos(x) 535 + double x; 536 + { 537 + return(_cos(x)); 538 + } 539 + 540 + double cosh(x) 541 + double x; 542 + { 543 + return(_cosh(x)); 544 + } 545 + 546 + double exp(x) 547 + double x; 548 + { 549 + ClearExceptions(); 550 + x = _exp(x); 551 + RangeCheck(x); 552 + return(x); 553 + } 554 + 555 + double fabs(x) 556 + double x; 557 + { 558 + return(_fabs(x)); 559 + } 560 + 561 + double floor(x) 562 + double x; 563 + { 564 + return(_floor(x)); 565 + } 566 + 567 + double fmod(x, y) 568 + double x, y; 569 + { 570 + return(_fmod(x, y)); 571 + } 572 + 573 + double frexp(x, nptr) 574 + double x; 575 + register int *nptr; 576 + { 577 + return(_frexp(x, nptr)); 578 + } 579 + 580 + 581 + /* 582 + * ldexp - combine fraction/exponent into a floating number 583 + * 584 + */ 585 + 586 + double ldexp(x, n) 587 + double x; 588 + int n; 589 + { 590 + return(_ldexp(x, n)); 591 + } 592 + 593 + 594 + double log(x) 595 + double x; 596 + { 597 + DomainCheck(x <= 0, MinusMax); 598 + return(_log(x)); 599 + } 600 + 601 + double log10(x) 602 + double x; 603 + { 604 + DomainCheck(x <= 0, MinusMax); 605 + return(_log10(x)); 606 + } 607 + 608 + 609 + double modf(x, nptr) 610 + double x; 611 + register int *nptr; 612 + { 613 + return(_modf(x, nptr)); 614 + } 615 + 616 + double pow(x, y) 617 + double x, y; 618 + { 619 + int exactint = 0; 620 + Extended80 tx, ty; 621 + 622 + ClearExceptions(); 623 + if (x == 0) { 624 + if (y <= 0) { 625 + #ifdef _ERRORCHECK_ 626 + errno = EDOM; 627 + #endif 628 + return (MinusMax); 629 + } 630 + return(Zero); 631 + } 632 + 633 + if (y == 0) 634 + return(One); 635 + if (x < 0) { 636 + _modf(y, &exactint); 637 + if (exactint != y) { 638 + #ifdef _ERRORCHECK_ 639 + errno = EDOM; 640 + #endif 641 + return (MinusMax); 642 + } 643 + x = -x; 644 + } 645 + 646 + x = _pow(x, y); 647 + RangeCheck(x); 648 + return((exactint & 1) ? -x : x); 649 + } 650 + 651 + double sin(x) 652 + double x; 653 + { 654 + return(_sin(x)); 655 + } 656 + 657 + 658 + double sinh(x) 659 + double x; 660 + { 661 + double y; 662 + 663 + ClearExceptions(); 664 + y = _sinh(x); 665 + RangeCheck(y); 666 + xfersign(x, &y); 667 + return(y); 668 + } 669 + 670 + double sqrt(x) 671 + double x; 672 + { 673 + DomainCheck(x < 0, Zero); 674 + return(_sqrt(x)); 675 + } 676 + 677 + 678 + /* 679 + * tan - circular tangent 680 + * 681 + */ 682 + 683 + double tan(x) 684 + double x; 685 + { 686 + ClearExceptions(); 687 + x = _tan(x); 688 + RangeCheck(x); 689 + return(x); 690 + } 691 + 692 + 693 + /* 694 + * tanh - hyperbolic tangent 695 + * 696 + */ 697 + 698 + double tanh(x) 699 + double x; 700 + { 701 + return(_tanh(x)); 702 + } 703 + 704 + #endif
+389
Library Sources/profiler/profile.c
··· 1 + /* 2 + 3 + Profile and tracing package for LightspeedC�. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + */ 8 + 9 + 10 + #include "stdio.h" 11 + #include "DeviceMgr.h" 12 + 13 + 14 + typedef unsigned char Bool; /* for size */ 15 + 16 + typedef void (*address)(); /* address type */ 17 + typedef unsigned char byte; 18 + typedef unsigned long time; 19 + 20 + typedef struct { 21 + char *name; /* function name */ 22 + time average; /* average time */ 23 + time maximum; /* largest time */ 24 + time minimum; /* smallest time */ 25 + time total; /* total time */ 26 + unsigned int entries; /* times entered */ 27 + } PROFILE; 28 + 29 + typedef struct { 30 + address user; /* user return address */ 31 + int function; /* index into profiles */ 32 + time correction; /* nested call time */ 33 + time start; /* entry time */ 34 + } STACK; 35 + 36 + #define LOCAL static /* local to profiler */ 37 + #define MAX_PROFILES 200 /* routines to follow */ 38 + #define MAX_STACK 200 /* max nested calls */ 39 + #define MAX_TIME 500000L /* max time */ 40 + 41 + /* 42 + 43 + Select execution/compilation options. 44 + 45 + SINGLE - each routine contains only its time 46 + TESTING - test profile package without LightspeedC PROFILE option 47 + 48 + */ 49 + 50 + #define SINGLE /* single routine only */ 51 + /* #define TESTING standalone testing */ 52 + 53 + 54 + #ifdef TESTING 55 + #undef LOCAL /* make items visible */ 56 + #define LOCAL 57 + #endif 58 + 59 + 60 + 61 + LOCAL int depth = -1; 62 + LOCAL PROFILE profiles[MAX_PROFILES]; 63 + LOCAL int profile_count = 0; 64 + LOCAL STACK stack[MAX_STACK]; 65 + LOCAL int stack_pointer = -1; 66 + LOCAL time start_time; 67 + 68 + int _profile = 1; 69 + int _trace = 0; 70 + 71 + void DumpProfile(); 72 + extern _profile_exit_(); 73 + extern char *CtoPstr(); 74 + extern char *PtoCstr(); 75 + 76 + #define _VIATIMER_ /* if this symbol is defined, the VIA timer now is used 77 + instead of TickCount -- it provides faster ticks, 78 + however there is a false precision to the numbers 79 + and there is a range of + or - 500 ticks since 80 + the VIAtimer is so fast that interrupts and such 81 + play a more significant time role. 82 + 83 + NOTE THAT THIS PROFILE OPTION CANNOT BE USED WITH 84 + ANY PROGRAM THAT MANIPULATES THE #1 VIA timer */ 85 + 86 + 87 + #ifdef _VIATIMER_ 88 + 89 + /* TickCount() - redefine TickCount trap to be a procedure for determining 90 + the timing according to the VIA timer */ 91 + 92 + #define VIAbase (*((unsigned char**)0x01D4)) 93 + #define VIAt1lo (*(VIAbase+512*4)) 94 + #define VIAt1hi (*(VIAbase+512*5)) 95 + #define VIAEnable (*((unsigned char *) ((long)VIA + 0x1C00))) 96 + #define VIAmaxtime ~0 97 + #define ProcAddr(x) (*(ProcPtr *)&((short *)(x))[1]) 98 + 99 + time timer=0; 100 + ProcPtr savePtr; 101 + unsigned char saveEnable; 102 + 103 + pascal void Rollover() 104 + { 105 + SetUpA5(); 106 + timer += 65536; 107 + VIAt1hi = VIAmaxtime; 108 + VIAt1lo = VIAmaxtime; 109 + RestoreA5(); 110 + } 111 + 112 + void Remove_Rollover() 113 + { 114 + if ((saveEnable&0x40)==0) VIAEnable = 0x40; 115 + Lvl1DT[6] = savePtr; 116 + } 117 + 118 + time TickCount() 119 + { 120 + 121 + if (timer > 0) 122 + { 123 + /* Use VIA timer #1 (sound driver) and to implement a fine 124 + resolution counter */ 125 + 126 + /* Find delta of VIA #1 */ 127 + 128 + timer += VIAmaxtime - (((unsigned short)VIAt1hi<<8)+VIAt1lo); 129 + } 130 + else { 131 + /* initialize profiling interrupt: */ 132 + savePtr = Lvl1DT[6]; 133 + Lvl1DT[6] = ProcAddr(Rollover); 134 + saveEnable = VIAEnable; 135 + VIAEnable |= 0x40; 136 + 137 + onexit( Remove_Rollover ); 138 + timer = 1; 139 + } 140 + 141 + /* Reset VIA counter */ 142 + 143 + VIAt1hi = VIAmaxtime; 144 + VIAt1lo = VIAmaxtime; 145 + 146 + return (timer); 147 + } 148 + 149 + #endif _VIATIMER_ 150 + 151 + 152 + /* 153 + 154 + Compare two Pascal strings for equality. 155 + 156 + */ 157 + 158 + LOCAL Bool pstreq( s1, s2 ) 159 + register unsigned char *s1, *s2; 160 + { 161 + register int n = *s1; 162 + 163 + if ((n = *s1++) != *s2++) 164 + return( false ); 165 + while (n-- > 0) 166 + if (*s1++ != *s2++) 167 + return( false ); 168 + return( true ); 169 + } 170 + 171 + 172 + /* 173 + 174 + Return the time difference caused by the overhead of function entry and 175 + timer call. 176 + 177 + */ 178 + 179 + LOCAL time delta( original ) 180 + time original; 181 + { 182 + /* return( (time) TickCount() - original ); */ 183 + return(0L); 184 + } 185 + 186 + 187 + /* 188 + 189 + Lookup a name in the active profile table. For this system, "names" are 190 + the address of the routine. If the name is found in the table, then the 191 + index to the table entry is returned. If the name is not found and the 192 + insert flag is on, then the item is inserted, and the new table index 193 + is returned (if insert is false, then -1 is returned). If the profile 194 + table is full, then -1 is returned. 195 + 196 + */ 197 + 198 + LOCAL int lookup( name, insert ) 199 + char *name; 200 + Bool insert; 201 + { 202 + register int i; 203 + 204 + insert = _profile; /* only insert if profiling is on */ 205 + 206 + for (i = 0; i < profile_count; i++) 207 + if (pstreq( profiles[i].name, name )) 208 + return( i ); 209 + 210 + if ( insert && (profile_count < MAX_PROFILES)) 211 + { /* place in table - i points to correct entry */ 212 + if (++profile_count == 1) 213 + { /* first time in */ 214 + start_time = (time) TickCount(); 215 + onexit( DumpProfile ); 216 + } 217 + profiles[i].name = name; 218 + profiles[i].minimum = MAX_TIME; 219 + profiles[i].maximum = 220 + profiles[i].total = NULL; 221 + profiles[i].entries = 0; 222 + return( i ); 223 + } 224 + return( -1 ); 225 + } 226 + 227 + 228 + /* 229 + 230 + Skip over to column 32 from position 'n'. 231 + 232 + */ 233 + 234 + LOCAL void Skip( n ) 235 + register int n; 236 + { 237 + for (; n < 32; n++) 238 + putchar( ' ' ); 239 + } 240 + 241 + 242 + /* 243 + 244 + Print the profile table on demand. Output is written to stdout and may 245 + be redirected with the Unix '>' mechanism to a file. The user should 246 + call this routine whenever a report is desired. Each time the routine is 247 + called, the program opens the map file which corresponds to the program 248 + running. The name of the map file is built by appending ".map" to the name 249 + of the running program. If the map file cannot be found then the routine 250 + returns. 251 + 252 + */ 253 + 254 + void DumpProfile() 255 + { 256 + Boolean flag; /* save state of _profile */ 257 + int j, k; /* generic loop variables */ 258 + register int i; /* primary loop variable */ 259 + register time duration = 0L; /* time in test regions */ 260 + 261 + flag = _profile; 262 + 263 + _profile = 0; /* turn off profiling here */ 264 + 265 + for (i = 0; i < profile_count; i++) 266 + duration += profiles[i].total; /* compute total time */ 267 + 268 + printf( "\n\n" ); 269 + printf( "\t\t\t\tRoutine Profiles\n\n" ); 270 + printf( "Routine Address" ); 271 + Skip( 15 ); 272 + printf( " Minimum Maximum Average %% Entries\n" ); 273 + 274 + if (duration <= 0.0) 275 + duration++; 276 + 277 + for (i = 0; i < profile_count; i++) 278 + { /* for all entries in the profile table */ 279 + if (profiles[i].minimum == MAX_TIME) 280 + continue; /* routine entry, no exit */ 281 + printf( "%s", PtoCstr( profiles[i].name ) ); 282 + CtoPstr( profiles[i].name ); 283 + Skip( profiles[i].name[0] ); 284 + printf( "%9lu %9lu %9lu %3.0f %7u\n", 285 + profiles[i].minimum, profiles[i].maximum, 286 + profiles[i].average, 287 + ((float) profiles[i].total * 100.0) / (float) duration + 0.05, 288 + profiles[i].entries ); 289 + } 290 + 291 + _profile = flag; /* restore state of _profile */ 292 + } 293 + 294 + 295 + /* 296 + 297 + Called by assembler exit routine. Compute usage statistics for routine on 298 + top of profiling stack. 299 + 300 + */ 301 + 302 + address __profile_exit() 303 + { 304 + int i; 305 + time exit_time = (time) TickCount(); 306 + 307 + depth--; 308 + /* end timing for a function */ 309 + 310 + /* Debugger(); */ 311 + i = stack[stack_pointer].function; 312 + #ifdef SINGLE 313 + exit_time = exit_time - delta( exit_time ) - 314 + stack[stack_pointer].start - stack[stack_pointer--].correction; 315 + if (exit_time > 0x7FFFFFFF) 316 + exit_time = 0L; /* handle clock rollover */ 317 + profiles[i].total += exit_time; 318 + if (stack_pointer >= 0) 319 + stack[stack_pointer].correction += exit_time + stack[stack_pointer + 1].correction; 320 + #else 321 + exit_time = exit_time - delta( exit_time ) - stack[stack_pointer--].start; 322 + if (exit_time > 0x7FFFFFFF) 323 + exit_time = 0L; /* handle clock rollover */ 324 + profiles[i].total += exit_time; 325 + #endif 326 + if (exit_time > profiles[i].maximum) 327 + profiles[i].maximum = exit_time; 328 + if (exit_time < profiles[i].minimum) 329 + profiles[i].minimum = exit_time; 330 + if (profiles[i].entries) 331 + profiles[i].average = profiles[i].total / profiles[i].entries; 332 + return( stack[stack_pointer + 1].user ); 333 + } 334 + 335 + 336 + /* 337 + 338 + Handle the routine entry profiling. Setup a stack frame and a profile 339 + table entry if needed. 340 + 341 + */ 342 + 343 + void __profile( unused, ret, name ) 344 + unsigned long *ret; 345 + address unused; 346 + char *name; 347 + 348 + { 349 + register int function, /* index of routine */ 350 + i; 351 + register time entry_time = (time) TickCount(); 352 + Boolean flag; /* save state of _profile */ 353 + depth++; 354 + if (_trace) 355 + { 356 + flag = _profile; /* save _profile */ 357 + _profile = 0; 358 + 359 + for (i = 0; i < depth; i++) 360 + putchar( ' ' ); 361 + printf( "%s\n", PtoCstr( name ) ); 362 + CtoPstr( name ); 363 + _profile = flag; 364 + } 365 + if (++stack_pointer < MAX_STACK) 366 + { /* setup for return to PROFILE_EXIT on user exit */ 367 + stack[stack_pointer].user = (address) *ret; 368 + *ret = (unsigned long) _profile_exit_; 369 + stack[stack_pointer].correction = NULL; 370 + } 371 + else 372 + { 373 + depth--; 374 + return; 375 + } 376 + 377 + if (_profile && ((function = lookup( name, true )) >= 0)) 378 + { /* process function entry */ 379 + profiles[function].entries++; 380 + stack[stack_pointer].function = function; 381 + entry_time = TickCount(); 382 + stack[stack_pointer].start = entry_time - delta( entry_time ); 383 + } 384 + else 385 + { /* remove entry from stack */ 386 + *ret = (unsigned long) stack[stack_pointer--].user; 387 + depth--; 388 + } 389 + }
+49
Library Sources/profiler/profilehooks.c
··· 1 + /* 2 + 3 + Profile and tracing package for LightspeedC. 4 + 5 + (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. 6 + 7 + */ 8 + 9 + extern void __profile(); 10 + extern void __profile_exit(); 11 + 12 + /* 13 + ; 14 + ; Entry point for profiler. Add another parameter to the stack which is 15 + ; a pointer to the return address of the caller of this function. 16 + ; 17 + */ 18 + _profile_() 19 + { 20 + 21 + asm 22 + { 23 + move.l (a7)+,d0 ; get current return address 24 + pea 4(a6) ; push pointer to return address 25 + move.l d0,-(a7) ; push back the return address 26 + jsr __profile ; call the C profiler 27 + move.l (a7)+,d0 ; get return address 28 + move.l d0,(a7) ; write on top of stack and return 29 + } 30 + } 31 + 32 + /* 33 + ; 34 + ; Exit point for profiler. This calls the end of function timing routine 35 + ; and returns to the user. 36 + ; 37 + */ 38 + 39 + _profile_exit_() 40 + { 41 + asm 42 + { 43 + move.l d0, -(a7) ; save old function result 44 + jsr __profile_exit ; call end of routine timer 45 + move.l d0, a0 ; save return address in A0 46 + move.l (a7)+, d0 ; retrieve old function result 47 + jmp (a0) ; then return 48 + } 49 + }
+61
Library Sources/unix .c files/unixatof.c
··· 1 + /* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */ 2 + 3 + #include "config.h" 4 + #include "unix.h" 5 + #include "sane.h" 6 + #include "MacTypes.h" 7 + 8 + #ifndef _math_ 9 + #include "Math.h" 10 + #endif 11 + 12 + #ifdef _MC68881_ 13 + 14 + #define _toDecimal() fp68k(&_decimal_,&x80,FFEXT|FOD2B) 15 + #define _tox96() x80tox96(&x80, &x) 16 + 17 + /* conversion from 68881 to SANE extended type */ 18 + static void x96tox80(x96, x80) 19 + register Extended96 *x96; 20 + register Extended80 *x80; 21 + 22 + { 23 + (*x80).exponent = (*x96).exponent; 24 + (*x80).mantissa = (*x96).mantissa; 25 + } 26 + 27 + static void x80tox96(x80, x96) 28 + register Extended80 *x80; 29 + register Extended96 *x96; 30 + { 31 + (*x96).exponent = (*x80).exponent; 32 + (*x96).reserved = 0; 33 + (*x96).mantissa = (*x80).mantissa; 34 + } 35 + 36 + #else 37 + 38 + #define _toDecimal() fp68k(&_decimal_,&x,FFEXT|FOD2B) 39 + #define _tox96() 40 + 41 + #endif 42 + 43 + double atof(s) 44 + char *s; 45 + 46 + { 47 + 48 + Decimal _decimal_; 49 + int index=0; 50 + Boolean read_error; 51 + double x; 52 + 53 + #ifdef _MC68881_ 54 + Extended80 x80; 55 + #endif 56 + 57 + CStr2Dec(s,&index,&_decimal_,&read_error); 58 + _toDecimal(); 59 + _tox96(); 60 + return(x); 61 + }
+52
Mac #includes.c
··· 1 + 2 + /* This is the source for <MacHeaders> */ 3 + 4 + #include "ControlMgr.h" 5 + #include "DeskMgr.h" 6 + #include "DeviceMgr.h" 7 + #include "DialogMgr.h" 8 + #include "EventMgr.h" 9 + #include "FileMgr.h" 10 + #include "FontMgr.h" 11 + #include "HFS.h" 12 + #include "IntlPkg.h" 13 + #include "ListMgr.h" 14 + #include "MacTypes.h" 15 + #include "MemoryMgr.h" 16 + #include "MenuMgr.h" 17 + #include "OSUtil.h" 18 + #include "PackageMgr.h" 19 + #include "Quickdraw.h" 20 + #include "ResourceMgr.h" 21 + #include "ScrapMgr.h" 22 + #include "SegmentLdr.h" 23 + #include "StdFilePkg.h" 24 + #include "TextEdit.h" 25 + #include "ToolboxUtil.h" 26 + #include "WindowMgr.h" 27 + #include "asm.h" 28 + #include "pascal.h" 29 + 30 + /* 31 + * These files are NOT included: 32 + 33 + #include "Appletalk.h" 34 + #include "nAppletalk.h" 35 + #include "Color.h" 36 + #include "ColorToolbox.h" 37 + #include "DeskBus.h" 38 + #include "DiskDvr.h" 39 + #include "PrintMgr.h" 40 + #include "ScriptMgr.h" 41 + #include "SCSIMgr.h" 42 + #include "SerialDvr.h" 43 + #include "SlotMgr.h" 44 + #include "SoundDvr.h" 45 + #include "SoundMgr.h" 46 + #include "StartMgr.h" 47 + #include "TimeMgr.h" 48 + #include "VRetraceMgr.h" 49 + 50 + * 51 + */ 52 +
+3 -3
Mac #includes/Appletalk.h
··· 2 2 /* 3 3 * Appletalk.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/Color.h
··· 2 2 /* 3 3 * Color.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -4
Mac #includes/ColorToolbox.h
··· 2 2 /* 3 3 * ColorToolbox.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 110 110 pascal MCEntryPtr GetMCEntry(); 111 111 pascal WindowPtr NewCWindow(); 112 112 pascal WindowPtr GetNewCWindow(); 113 - pascal RgnHandle GetGrayRgn(); 114 113 115 114 116 115 /* low-memory globals */
+3 -3
Mac #includes/ControlMgr.h
··· 2 2 /* 3 3 * ControlMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/DeskBus.h
··· 2 2 /* 3 3 * DeskBus.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/DeskMgr.h
··· 2 2 /* 3 3 * DeskMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+9 -4
Mac #includes/DeviceMgr.h
··· 2 2 /* 3 3 * DeviceMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 129 129 activDev, 130 130 deactivDev, 131 131 keyEvtDev, 132 - macDev 132 + macDev, 133 + undoDev, 134 + cutDev, 135 + copyDev, 136 + pasteDev, 137 + clearDev 133 138 }; 134 139 135 140 /* cdev error codes */
+3 -3
Mac #includes/DialogMgr.h
··· 2 2 /* 3 3 * DialogMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/DiskDvr.h
··· 2 2 /* 3 3 * DiskDvr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/EventMgr.h
··· 2 2 /* 3 3 * EventMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/FileMgr.h
··· 2 2 /* 3 3 * FileMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+5 -5
Mac #includes/FontMgr.h
··· 2 2 /* 3 3 * FontMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 89 89 int widMax ; 90 90 int kernMax ; 91 91 int nDescent ; 92 - int fRectMax ; 93 - int chHeight ; 92 + int fRectWidth ; 93 + int fRectHeight ; 94 94 int owTLoc ; 95 95 int ascent ; 96 96 int descent ;
+3 -3
Mac #includes/HFS.h
··· 2 2 /* 3 3 * HFS.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/IntlPkg.h
··· 2 2 /* 3 3 * IntlPkg.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/ListMgr.h
··· 2 2 /* 3 3 * ListMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/MacTypes.h
··· 2 2 /* 3 3 * MacTypes.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/MemoryMgr.h
··· 2 2 /* 3 3 * MemoryMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+5 -6
Mac #includes/MenuMgr.h
··· 2 2 /* 3 3 * MenuMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 27 27 }; 28 28 29 29 /* menu defproc messages */ 30 - enum { mDrawMsg, mChooseMsg, mSizeMsg }; 30 + enum { mDrawMsg, mChooseMsg, mSizeMsg, mPopUpMsg }; 31 31 32 32 /* MDEF id */ 33 33 #define textMenuProc 0 34 34 35 - /* hierarchical and pop-up menus */ 35 + /* hierarchical menus */ 36 36 #define hMenuCmd 0x1B 37 37 #define hierMenu -1 38 - #define mPopUpMsg 4 39 38 40 39 41 40 typedef struct
+26 -4
Mac #includes/OSUtil.h
··· 2 2 /* 3 3 * OSUtil.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 17 17 18 18 /* result codes */ 19 19 enum { 20 + nmTypErr = -299, 20 21 prInitErr = -88, 21 22 prWrErr, 22 23 clkWrErr, ··· 34 35 ioQType, 35 36 drvQType, 36 37 evType, 37 - fsQType 38 + fsQType, 39 + siQType, 40 + dtQType, 41 + nmType 38 42 }; 39 43 40 44 /* machine types */ ··· 169 173 #define sdOnUnmount 4 170 174 #define sdOnDrivers 8 171 175 #define sdRestartOrPower (sdOnRestart+sdOnPowerOff) 176 + 177 + 178 + /* ---------- Notification Manager ---------- */ 179 + 180 + 181 + typedef struct NMRec { 182 + QElemPtr qLink; 183 + short qType; 184 + short nmFlags; 185 + long nmPrivate; 186 + short nmReserved; 187 + short nmMark; 188 + Handle nmSIcon; 189 + Handle nmSound; 190 + StringPtr nmStr; 191 + ProcPtr nmResp; 192 + long nmRefCon; 193 + } NMRec; 172 194 173 195 174 196 /* ---------- */
+3 -3
Mac #includes/PackageMgr.h
··· 2 2 /* 3 3 * PackageMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/PrintMgr.h
··· 2 2 /* 3 3 * PrintMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/Quickdraw.h
··· 2 2 /* 3 3 * Quickdraw.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/ResourceMgr.h
··· 2 2 /* 3 3 * ResourceMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/SCSIMgr.h
··· 2 2 /* 3 3 * SCSIMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/ScrapMgr.h
··· 2 2 /* 3 3 * ScrapMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+6 -6
Mac #includes/ScriptMgr.h
··· 2 2 /* 3 3 * ScriptMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 242 242 /* Roman script constants */ 243 243 244 244 #define romanVers 1 245 - #define romanSysFond $3FFF 245 + #define romanSysFond 0x3FFF 246 246 #define romanAppFond 3 247 247 248 248 /* Script Manager font equates. */ 249 249 250 - #define smFondStart $4000 251 - #define smFondEnd $C000 250 + #define smFondStart 0x4000 251 + #define smFondEnd 0xC000 252 252 253 253 254 254
+3 -3
Mac #includes/SegmentLdr.h
··· 2 2 /* 3 3 * SegmentLdr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/SerialDvr.h
··· 2 2 /* 3 3 * SerialDvr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+40
Mac #includes/SetUpA4.h
··· 1 + 2 + /* 3 + * SetUpA4.h 4 + * 5 + * This defines "SetUpA4()" and "RestoreA4()" routines that will work 6 + * in all A4-based projects. 7 + * 8 + * "RememberA4()" or "RememberA0()" must be called in advance to 9 + * store away the value of A4 where it can be found by "SetUpA4()". 10 + * The matching calls to "RememberA4()" (or "RememberA0()") and 11 + * "SetUpA4()" *MUST* occur in the same file. 12 + * 13 + * Note that "RememberA4()", "RememberA0()" "SetUpA4()", and 14 + * "RestoreA4()" are not external. Each file that uses them must 15 + * include its own copy. 16 + * 17 + * If this file is used in the main file of a code resource with 18 + * "Custom Headers", be sure to #include it *AFTER* the custom 19 + * header! Otherwise, the code resource will begin with the code 20 + * for the function "__GetA4()", defined below. 21 + * 22 + */ 23 + 24 + 25 + static 26 + __GetA4() 27 + { 28 + asm { 29 + bsr.s @1 30 + dc.l 0 ; store A4 here 31 + @1 move.l (sp)+,a1 32 + } 33 + } 34 + 35 + 36 + #define RememberA4() __GetA4(); asm { move.l a4,(a1) } 37 + #define RememberA0() __GetA4(); asm { move.l a0,(a1) } 38 + 39 + #define SetUpA4() asm { move.l a4,-(sp) } __GetA4(); asm { move.l (a1),a4 } 40 + #define RestoreA4() asm { move.l (sp)+,a4 }
+3 -3
Mac #includes/SlotMgr.h
··· 2 2 /* 3 3 * SlotMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/SoundDvr.h
··· 2 2 /* 3 3 * SoundDvr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/SoundMgr.h
··· 2 2 /* 3 3 * SoundMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/StartMgr.h
··· 2 2 /* 3 3 * StartMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/StdFilePkg.h
··· 2 2 /* 3 3 * StdFilePkg.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+8 -3
Mac #includes/TextEdit.h
··· 2 2 /* 3 3 * TextEdit.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 65 65 #define doColor 8 66 66 #define doAll 15 67 67 #define addSize 16 68 + #define doToggle 32 69 + 70 + typedef enum { 71 + intEOLHook, intDrawHook, intWidthHook, intHitTestHook 72 + } TEHook; 68 73 69 74 70 75 /* avoid having to bring in all of Color Quickdraw */
+3 -3
Mac #includes/TimeMgr.h
··· 2 2 /* 3 3 * TimeMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/ToolboxUtil.h
··· 2 2 /* 3 3 * ToolboxUtil.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+3 -3
Mac #includes/VRetraceMgr.h
··· 2 2 /* 3 3 * VRetraceMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+4 -3
Mac #includes/WindowMgr.h
··· 2 2 /* 3 3 * WindowMgr.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10 ··· 105 105 pascal WindowPtr GetNewWindow(); 106 106 pascal WindowPtr FrontWindow(); 107 107 pascal PicHandle GetWindowPic(); 108 + pascal RgnHandle GetGrayRgn(); 108 109 109 110 /* low-memory globals */ 110 111 extern WindowPeek WindowList : 0x9D6;
+7
Mac #includes/asm.h
··· 3 3 /* ----- asm.h: definitions useful with inline assembly ----- */ 4 4 5 5 6 + #ifndef __asm__ 7 + #define __asm__ 8 + 9 + 6 10 /* trap modifier flags, e.g. "NewHandle SYS+CLEAR" */ 7 11 8 12 enum { ··· 27 31 /* field offsets, e.g. "move.w d0,OFFSET(Rect,bottom)(a2)" */ 28 32 29 33 #define OFFSET(type, field) ((int) &((type *) 0)->field) 34 + 35 + 36 + #endif __asm__
+3 -3
Mac #includes/nAppletalk.h
··· 2 2 /* 3 3 * nAppletalk.h 4 4 * 5 - * Copyright (c) 1986, 1987 THINK Technologies, Inc. 6 - * These interfaces are based on information copyrighted 7 - * by Apple Computer, Inc., 1985, 1986, 1987. 5 + * Copyright (c) 1988 Symantec Corporation. 6 + * These interfaces are based on material copyrighted 7 + * by Apple Computer, Inc., 1985, 1986, 1987, 1988. 8 8 * 9 9 */ 10 10
+5
Mac #includes/pascal.h
··· 1 + 2 + #ifndef __pascal__ 3 + #define __pascal__ 1 4 2 5 pascal void CallPascal(...); 3 6 pascal char CallPascalB(...); ··· 6 9 7 10 char *CtoPstr(char *); 8 11 char *PtoCstr(char *); 12 + 13 + #endif __pascal__
-1
profiler/profile.c
··· 1 - /* Profile and tracing package for LightspeedC. (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. */ #include "stdio.h" typedef unsigned char Bool; /* for size */ enum{false,true}; typedef void (*address)(); /* address type */ typedef unsigned char byte; typedef unsigned long time; typedef struct { char *name; /* function name */ time average; /* average time */ time maximum; /* largest time */ time minimum; /* smallest time */ time total; /* total time */ unsigned int entries; /* times entered */ } PROFILE; typedef struct { address user; /* user return address */ int function; /* index into profiles */ time correction; /* nested call time */ time start; /* entry time */ } STACK; #define LOCAL static /* local to profiler */ #define MAX_PROFILES 200 /* routines to follow */ #define MAX_STACK 200 /* max nested calls */ #define MAX_TIME 500000L /* max time */ /* Select execution/compilation options. SINGLE - each routine contains only its time TESTING - test profile package without LightspeedC PROFILE option */ #define SINGLE /* single routine only */ /* #define TESTING standalone testing */ #ifdef TESTING #undef LOCAL /* make items visible */ #define LOCAL #endif LOCAL int depth = -1; LOCAL PROFILE profiles[MAX_PROFILES]; LOCAL int profile_count = 0; LOCAL STACK stack[MAX_STACK]; LOCAL int stack_pointer = -1; LOCAL time start_time; int _profile = 1; int _trace = 0; void DumpProfile(); extern _profile_exit_(); extern char *CtoPstr(); extern char *PtoCstr(); #define _VIATIMER_ /* if this symbol is defined, the VIA timer now is used instead of TickCount -- it provides faster ticks, however there is a false precision to the numbers and there is a range of + or - 500 ticks since the VIAtimer is so fast that interrupts and such play a more significant time role. NOTE THAT THIS PROFILE OPTION CANNOT BE USED WITH ANY PROGRAM THAT MANIPULATES THE #1 VIA timer */ #ifdef _VIATIMER_ /* TickCount() - redefine TickCount trap to be a procedure for determining the timing according to the VIA timer */ #define VIAbase (*((unsigned char**)0x01D4)) #define VIAt1lo (*(VIAbase+512*4)) #define VIAt1hi (*(VIAbase+512*5)) #define VIAmaxtime ~0 time TickCount() { static time timer=0; if (timer > 0) { /* Use VIA timer #1 (sound driver) and to implement a fine resolution counter */ /* Find delta of VIA #1 */ timer += VIAmaxtime - (((unsigned short)VIAt1hi<<8)+VIAt1lo); } else timer = 1; /* Reset VIA counter */ VIAt1hi = VIAmaxtime; VIAt1lo = VIAmaxtime; return (timer); } #endif _VIATIMER_ /* Compare two Pascal strings for equality. */ LOCAL Bool pstreq( s1, s2 ) register unsigned char *s1, *s2; { register int n = *s1; if ((n = *s1++) != *s2++) return( false ); while (n-- > 0) if (*s1++ != *s2++) return( false ); return( true ); } /* Return the time difference caused by the overhead of function entry and timer call. */ LOCAL time delta( original ) time original; { return( (time) TickCount() - original ); } /* Lookup a name in the active profile table. For this system, "names" are the address of the routine. If the name is found in the table, then the index to the table entry is returned. If the name is not found and the insert flag is on, then the item is inserted, and the new table index is returned (if insert is false, then -1 is returned). If the profile table is full, then -1 is returned. */ LOCAL int lookup( name, insert ) char *name; Bool insert; { register int i; for (i = 0; i < profile_count; i++) if (pstreq( profiles[i].name, name )) return( i ); if ( insert && profile_count < MAX_PROFILES) { /* place in table - i points to correct entry */ if (++profile_count == 1) { /* first time in */ start_time = (time) TickCount(); onexit( DumpProfile ); } profiles[i].name = name; profiles[i].minimum = MAX_TIME; profiles[i].maximum = profiles[i].total = NULL; profiles[i].entries = 0; return( i ); } return( -1 ); } /* Skip over to column 32 from position 'n'. */ LOCAL void Skip( n ) register int n; { for (; n < 32; n++) putchar( ' ' ); } /* Print the profile table on demand. Output is written to stdout and may be redirected with the Unix '>' mechanism to a file. The user should call this routine whenever a report is desired. Each time the routine is called, the program opens the map file which corresponds to the program running. The name of the map file is built by appending ".map" to the name of the running program. If the map file cannot be found then the routine returns. */ void DumpProfile() { int j, k; /* generic loop variables */ register int i; /* primary loop variable */ register time duration = 0L; /* time in test regions */ _profile = 0; /* turn off profiling here */ for (i = 0; i < profile_count; i++) duration += profiles[i].total; /* compute total time */ printf( "\n\n" ); printf( "\t\t\t\tRoutine Profiles\n\n" ); printf( "Routine Address" ); Skip( 15 ); printf( " Minimum Maximum Average %% Entries\n" ); if (duration <= 0.0) duration++; for (i = 0; i < profile_count; i++) { /* for all entries in the profile table */ if (profiles[i].minimum == MAX_TIME) continue; /* routine entry, no exit */ printf( "%s", PtoCstr( profiles[i].name ) ); CtoPstr( profiles[i].name ); Skip( profiles[i].name[0] ); printf( "%9lu %9lu %9lu %3.0f %7u\n", profiles[i].minimum, profiles[i].maximum, profiles[i].average, ((float) profiles[i].total * 100.0) / (float) duration + 0.05, profiles[i].entries ); } _profile = 1; /* re-enable profiling */ } /* Called by assembler exit routine. Compute usage statistics for routine on top of profiling stack. */ address __profile_exit() { int i; time exit_time = (time) TickCount(); depth--; /* end timing for a function */ i = stack[stack_pointer].function; #ifdef SINGLE exit_time = exit_time - delta( exit_time ) - stack[stack_pointer].start - stack[stack_pointer--].correction; if (exit_time > 0x7FFFFFFF) exit_time = 0L; /* handle clock rollover */ profiles[i].total += exit_time; if (stack_pointer >= 0) stack[stack_pointer].correction += exit_time + stack[stack_pointer + 1].correction; #else exit_time = exit_time - delta( exit_time ) - stack[stack_pointer--].start; if (exit_time > 0x7FFFFFFF) exit_time = 0L; /* handle clock rollover */ profiles[i].total += exit_time; #endif if (exit_time > profiles[i].maximum) profiles[i].maximum = exit_time; if (exit_time < profiles[i].minimum) profiles[i].minimum = exit_time; if (profiles[i].entries) profiles[i].average = profiles[i].total / profiles[i].entries; return( stack[stack_pointer + 1].user ); } /* Handle the routine entry profiling. Setup a stack frame and a profile table entry if needed. */ void __profile( unused, ret, name ) unsigned long *ret; address unused; char *name; { register int function, /* index of routine */ i; register time entry_time = (time) TickCount(); depth++; if (_trace) { _profile = 0; for (i = 0; i < depth; i++) putchar( ' ' ); printf( "%s\n", PtoCstr( name ) ); CtoPstr( name ); _profile = 1; } if (++stack_pointer < MAX_STACK) { /* setup for return to PROFILE_EXIT on user exit */ stack[stack_pointer].user = (address) *ret; *ret = (unsigned long) _profile_exit_; stack[stack_pointer].correction = NULL; } else { depth--; return; } if ((function = lookup( name, true )) >= 0) { /* process function entry */ profiles[function].entries++; stack[stack_pointer].function = function; entry_time = TickCount(); stack[stack_pointer].start = entry_time - delta( entry_time ); } else { /* remove entry from stack */ *ret = (unsigned long) stack[stack_pointer--].user; depth--; } }
-1
profiler/profilehooks.c
··· 1 - /* Profile and tracing package for LightspeedC. (C) Copyright 1986 THINK Technologies, Inc. All rights reserved. */ extern void __profile(); extern void __profile_exit(); /* ; ; Entry point for profiler. Add another parameter to the stack which is ; a pointer to the return address of the caller of this function. ; */ _profile_() { asm { move.l (a7)+,d0 ; get current return address pea 4(a6) ; push pointer to return address move.l d0,-(a7) ; push back the return address jsr __profile ; call the C profiler move.l (a7)+,d0 ; get return address move.l d0,(a7) ; write on top of stack and return } } /* ; ; Exit point for profiler. This calls the end of function timing routine ; and returns to the user. ; */ _profile_exit_() { asm { move.l d0, -(a7) ; save old function result jsr __profile_exit ; call end of routine timer move.l d0, a0 ; save return address in A0 move.l (a7)+, d0 ; retrieve old function result jmp (a0) ; then return } }
+133
unix main.c
··· 1 + /************************************************************************* 2 + * * 3 + * Module: unix main.c * 4 + * Programmer: Steve Adams * 5 + * * 6 + * (C) Copyright 1985, THINK Technologies, Inc. All rights reserved. * 7 + * * 8 + * Alternate main program to handle Unix command lines under Lightspeed * 9 + * C. The user is prompted for the command line on program entry. The * 10 + * line is disected and placed in an "argv" array up to a maximum of * 11 + * MAX_ARGS entries. I/O redirection is also supported, as follows: * 12 + * * 13 + * > redirects stdout to following file name * 14 + * < redirects stdin to following file name * 15 + * >> redirects stderr to following file name * 16 + * * 17 + * File names following a redirection may be immediately after the * 18 + * redirector, or at what appears to be the next argument. If a file * 19 + * open error occurs, then the program calls "SysBeep" and exits to the * 20 + * shell. * 21 + * * 22 + * TO USE: change the "main" function in you application to "_main" and * 23 + * include this file in your project. * 24 + * * 25 + *************************************************************************/ 26 + 27 + 28 + #include <stdio.h> 29 + #include <ctype.h> 30 + 31 + #define MAX_ARGS 50 32 + 33 + #ifndef true 34 + #define true 1 35 + #define false 0 36 + #endif 37 + 38 + static int argc = 1; /* final argument count */ 39 + static char *argv[MAX_ARGS] = { "" }; /* array of pointers */ 40 + static char command[256]; /* input line buffer */ 41 + static int filename = false; /* TRUE iff file name */ 42 + 43 + 44 + /************************************************************************* 45 + * * 46 + * Local routine to make a "beep" and exit to the shell. * 47 + * * 48 + *************************************************************************/ 49 + 50 + static void punt() 51 + { 52 + SysBeep( 5L ); 53 + ExitToShell(); 54 + } 55 + 56 + 57 + /************************************************************************* 58 + * * 59 + * Local routine to open a file in argv[--argc] after closing it's * 60 + * previous existance. * 61 + * * 62 + *************************************************************************/ 63 + 64 + 65 + static void openfile( file, mode ) 66 + char *mode; /* mode for file open */ 67 + FILE *file; /* file pointer to use */ 68 + { 69 + 70 + if ( (file = freopen( argv[--argc], mode, file ) ) <= (FILE *) NULL) 71 + punt(); 72 + filename = false; 73 + } 74 + 75 + 76 + /************************************************************************* 77 + * * 78 + * New main routine. Prompts for command line then calls user's main * 79 + * now called "_main" with the argument list and redirected I/O. * 80 + * * 81 + *************************************************************************/ 82 + 83 + 84 + void main() 85 + { 86 + char c; /* temp for EOLN check */ 87 + register char *cp; /* index in command line */ 88 + char *mode; /* local file mode */ 89 + FILE *file; /* file to change */ 90 + int i; 91 + 92 + printf( "Enter Unix command line:\n" ); 93 + gets( &command ); /* allow user to edit */ 94 + cp = &command[0]; /* start of buffer */ 95 + argv[0] = ""; /* program name is NULL */ 96 + while (argc < MAX_ARGS) 97 + { /* up to MAX_ARGS entries */ 98 + while (isspace( *cp++ )); 99 + if ( !*--cp ) 100 + break; 101 + else if ( *cp == '<' ) 102 + { /* redirect stdin */ 103 + cp++; 104 + file = stdin; 105 + mode = "r"; 106 + filename = true; 107 + } 108 + else if ( *cp == '>' ) 109 + { 110 + mode = "w"; 111 + filename = true; 112 + if (*++cp == '>') 113 + { 114 + file = stderr; 115 + cp++; 116 + } 117 + else 118 + file = stdout; 119 + } 120 + else 121 + { /* either an argument or a filename */ 122 + argv[argc++] = cp; 123 + while ( *++cp && !isspace( *cp ) ); 124 + c = *cp; 125 + *cp++ = '\0'; 126 + if (filename) 127 + openfile( file, mode ); 128 + if (!c) 129 + break; 130 + } 131 + } 132 + _main( argc, argv ); 133 + }