···88 For details, refer to Harbison & Steele's "C: A Reference Manual",
99 Chapter 11.
10101111+ Only one version of each function is defined by this library.
1212+ Whether error checking is done is determined by how this file
1313+ is compiled. Error checking is ENABLED when the following
1414+ #define is COMMENTED OUT.
1515+1116*/
12171313-#include "config.h"
1818+/*#define _NOERRORCHECK_*/
1419#include "math.h"
1520#include "sane.h"
1621···455460456461double modf(x, nptr)
457462double x;
458458-register int *nptr;
463463+register double *nptr;
459464{
460460- if (abs(*nptr = x) > fabs(x)) {
461461- if (*nptr > 0)
462462- --*nptr;
463463- else
464464- ++*nptr;
465465- }
465465+ *nptr = x;
466466+ fp68k(nptr, FOTTI);
466467 return(x - *nptr);
467468}
468469···475476double pow(x, y)
476477double x, y;
477478{
478478- int exactint = 0;
479479+ int odd = 0;
479480 double z;
480481481482 ClearExceptions();
···491492 if (y == 0)
492493 return(One);
493494 if (x < 0) {
494494- modf(y, &exactint);
495495- if (exactint != y) {
495495+ if (modf(y, &y)) {
496496#ifdef _ERRORCHECK_
497497 errno = EDOM;
498498#endif
499499 return (MinusMax);
500500 }
501501 x = -x;
502502+ odd = fmod(y, Two);
502503 }
503504 elems68k(&y, &x, FOPWRY);
504505505506 RangeCheck(x);
506506- return((exactint & 1) ? -x : x);
507507+ return(odd ? -x : x);
507508}
508509509510/*
-1
Library Sources/Math881.a
···11- MACHINE MC68020
MC68881
BLANKS ON
CASE ON
STRING ASIS
; Assembly source for the Math881 math library.
; Version 3.0
; by Rich Siegel (with assistance from Steve Stein)
; �1988 Symantec Corp.
;
; LightspeedC pushes the parameters in reverse order; also, the first parameter
; pushed is a hidden argument that contains the address of the function
; result.
;
; Floating-point arguments are pushed by value.
;
;
; The one-argument transcendentals follow a common template: simply
; evaluate what's on the stack with FP0 as the destination, load the
; function result address into A0, and then do a FMOVE.X FP0, (A0)
; to store the function result.
;
; Since none of the floating-point registers are scratch, these
; routines preserve the registers that they use.
;
; in Math881.a the function names begin with the underscore character;
; this is useful when the _ERRORCHECK_ symbol is defined in <Math881.h>.
; the user can call an underscore directly, or he can call the function
; as it's defined in Math881.c, and get the full benefit of the standard
; C error checking. For example, using tan() or _tan().
;
; When _ERRORCHECK_ is not defined, the library calls are simply macros
; to call the underscore functions.
;
; int abs(int i);
;
; stack:
; 4 byte return address
; i is at 4(a7)
abs proc export
move.w 4(a7), d0
bge.s @1
neg.w d0
@1 rts
;
; double acos(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_acos proc export
fmovem fp0, -(a7) ; preserve registers
facos.x 20(a7), fp0 ; arccos
movea.l 16(a7), a0 ; load address of result
fmove.x fp0, (a0) ; load result
fmovem (a7)+, fp0 ; restore registers
rts
;
; double asin(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_asin proc export
fmovem fp0, -(a7)
fasin.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double atan(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_atan proc export
fmovem fp0, -(a7)
fatan.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double atan2(double y, double x);
;
_atan2 proc export
fmovem fp0/fp1, -(a7) ; preserve fp0 and fp1
movea.l 28(a7), a0 ; load address of result
fmove.x 32(a7), fp0 ; load y
fmove.x 44(a7), fp1 ; load x (we'll use it later)
fdiv.x fp1, fp0 ; divide by x
fatan.x fp0 ; arctan
fcmp.w #0, fp1 ; is x < zero?
fbge @1
fmove.x 32(a7), fp1 ; put a fresh copy of y into fp1
fcmp.w #0, fp1 ; is y < zero?
fbge @2
fmovecr #0, fp1 ; if it is, subtract pi from result.
fsub.x fp1, fp0
bra.s @1 ; ...and go home.
@2 fmovecr #0, fp1 ; otherwise, add pi to result.
fadd.x fp1, fp0
@1 fmove.x fp0, (a0) ; store result
fmovem (a7)+, fp0/fp1 ; restore registers
rts
;
; double ceil(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_ceil proc export
fmovem fp0, -(a7) ; preserve fp0
fmove.l fpcr, d0 ; fetch the 68881 control register
move.l d0, d1 ; save a copy in D1
ori.l #$0030, d0 ; OR in the rounding control
fmove.l d0, fpcr ; set up the FPCR
fint.x 20(a7), fp0 ; calculate nearest integer of arg
fmove.l d1, fpcr ; restore the fpcr from the copy
movea.l 16(a7), a0 ; load addr of result, and...
fmove.x fp0, (a0) ; ...load the result
fmovem (a7)+, fp0 ; restore registers
rts
;
; double cos(double x); /* same schema as acos, asin, atan */
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_cos proc export
fmovem fp0, -(a7)
fcos.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double cosh(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_cosh proc export
fmovem fp0, -(a7)
fcosh.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double exp(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_exp proc export
fmovem fp0, -(a7)
fetox.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double fabs(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_fabs proc export
fmovem fp0, -(a7)
FABS.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double floor(double x);
;
; this function works the same as ceil(), except that the value to OR in
; is $20 instead of $30.
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_floor proc export
fmovem fp0, -(a7)
fmove.l fpcr, d0
move.l d0, d1
ori.l #$0020, d0
fmove.l d0, fpcr
fint.x 20(a7), fp0
fmove.l d1, fpcr
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double fmod(double x, double y);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 32
; y equ 20
; result equ 16
_fmod proc export
fmovem fp0, -(a7) ; save the registers
fmove.x 20(a7), fp0 ; load Y
fmod.x 32(a7), fp0 ; call the '881's FMOD
movea.l 16(a7), a0 ; load address of result
fmove.x fp0, (a0) ; load result
fmovem (a7)+, fp0 ; restore registers
rts
;
; double frexp(double x, int *nptr);
;
; This function is machine-dependent, and relies on the internal representation
; of the double floating-point data type.
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 24
; nptr equ 20
; result equ 16
_frexp proc export
fmovem fp0, -(a7)
movea.l 16(a7), a0 ; load result address
movea.l 20(a7), a1 ; load nptr
fmove.x 24(a7), fp0 ; fetch X
fcmp.w #0, fp0 ; if X is zero, then
fbne @2
move.w #0, (a1) ; both parts of result are zero
fmove.x fp0, (a0) ; return x (since it is also zero)
bra.s @3 ; goodbye...
@2 move.w 24(a7), d0 ; get the exponent of X
move.w d0, d1 ; keep a copy
bge.s @1
andi.w #$7FFF, d0 ; mask off the mantissa sign bit
@1 subi.w #$3FFE, d0 ; subtract the exponent bias (less one)
andi.w #$8000, d1 ; preserve mantissa's sign bit
ori.w #$3FFE, d1 ; put in an exponent of (-1)
move.w d1, 24(a7) ; and smash that over X's old exponent
fmove.x 24(a7), fp0 ; fetch X (again)
fmove.x fp0, (a0) ; store it in result
move.w d0, (a1) ; and store *nptr
@3 fmovem (a7)+, fp0
rts
;
; long labs(long l);
;
; stack:
; 4 byte return address
; l is at 4(a7)
labs proc export
move.l 4(a7), d0
bge.s @1
neg.l d0
@1 rts
;
; double ldexp(double x, int n);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 22
; n equ 20
; result equ 16
_ldexp proc export
fmovem fp0, -(a7)
movea.l 16(a7), a0 ; load result address
fmove.w 20(a7), fp0 ; load N into a float register
ftwotox fp0 ; raise two to that power.
fmul.x 22(a7), fp0 ; multiply by X
fmove.x fp0, (a0) ; load result
fmovem (a7)+, fp0
rts
;
; double log(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_log proc export
fmovem fp0, -(a7)
flogn.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double log10(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_log10 proc export
fmovem fp0, -(a7)
flog10.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double modf(double x, int *ip);
;
; stack frame:
; 24 bytes of saved registers
; 4 bytes return addr
; result equ 28
; x equ 32
; ip equ 36
_modf proc export
fmovem fp0/fp1, -(a7)
movea.l 28(a7), a0 ; address of result
movea.l 36(a7), a1 ; address of int part
fmove.x 32(a7), fp0 ; argument
fintrz.x fp0, fp1 ; leaves integer part in fp1
fmove.w fp1, (a1) ; store integer part
fsub.x fp1, fp0
fmove.x fp0, (a0) ; store function result
fmovem (a7)+, fp0/fp1
rts
;
; double pow(double x, double y);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; y equ 32
; x equ 20
; result equ 16
_pow proc export
link a6, #0
fmovem fp0/fp1, -(a7)
fmove.x 12(a6), fp0 ; load x
fmove.x 24(a6), fp1 ; load y
fcmp.w #0, fp1 ; if y is zero then
fbne @6
fcmp.w #0, fp0
fbeq @error ; zero to the zeroth power is bad.
fmove.w #1, fp0
bra @store ; store one as the result.
@6 fcmp.w #0, fp0 ; is x greater than zero?
fbgt @1
fbne @2 ; if x is zero, then
fcmp.w #0, fp1
fble @error ; if y is greater than zero,
fmove.w #0, fp0 ; then return zero.
bra.s @store
@2 fint.x fp1 ; round y.
fcmp.x 24(a6), fp1 ; is y integral? if not,
fbne @error ; return some error
fmove.x fp1, fp0 ; save a copy of y
fdiv.w #2, fp1 ; test if y is odd
fdiv.w #2, fp0
fint.x fp1
fcmp.x fp0, fp1 ; if round(fp1) <> fp0
; before we branch on this test,
; do the operations that both
; conditions require.
; (in fact, the only thing different
; is that the result gets negated
; if y is odd.
fmove.l fpsr, d0 ; save the FPSR so we can branch on it later.
fmove.x 12(a6), fp0 ; re-fetch the arguments
fmove.x 24(a6), fp1
fneg.x fp0
flogn.x fp0
fmul.x fp1, fp0
fetox.x fp0
fmove.l d0, fpsr ; restore the FPSR
fbne @5 ; and branch on it.
bra.s @store ; since y is even, do nothing else
@5 fneg.x fp0 ; since y is odd, negate the result.
bra.s @store
@1 flogn.x fp0 ; x > 0, therefore
fmul.x fp1, fp0
fetox.x fp0 ; pow(x, y) = exp(y * ln(x))
bra.s @store
@error fmove.x #"NAN", fp0
@store movea.l 8(a6), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0/fp1
unlk a6
rts
; double sin(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_sin proc export
fmovem fp0, -(a7)
fsin.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double sinh(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_sinh proc export
fmovem fp0, -(a7)
fsinh.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double sqrt(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_sqrt proc export
fmovem fp0, -(a7)
fsqrt.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double tan(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_tan proc export
fmovem fp0, -(a7)
ftan.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; double tanh(double x);
;
; stack frame:
; 12 bytes saved registers
; 4 byte return address
; x equ 20
; result equ 16
_tanh proc export
fmovem fp0, -(a7)
ftanh.x 20(a7), fp0
movea.l 16(a7), a0
fmove.x fp0, (a0)
fmovem (a7)+, fp0
rts
;
; long GetState()
;
; GetState() simply returns the contents of the 68881's status register.
;
GetState proc export
fmove.l fpsr, d0
rts
;
; void ClearExceptions()
;
; ClearExceptions() clears the exception byte of the 68881 status
; register.
;
ClearExceptions proc export
fmove.l fpsr, d0
andi.l #$FFFF00FF, d0
fmove.l d0, fpsr
rts
end
+22-1
Library Sources/Math881.c
···7788 For details, refer to Harbison & Steele's "C: A Reference Manual",
99 Chapter 11.
1010+1111+ Two versions of each function are defined by this library: an
1212+ error-checking version (e.g. "sin") and a non-error-checking
1313+ version (e.g. "_sin").
1414+1515+ The non-underscore names can be made to refer to the non-error-
1616+ checking functions by #defining _NOERRORCHECK_ before #including
1717+ "math.h". Doing so in THIS file suppresses the definitions of
1818+ the error-checking versions of the functions altogether.
10191120*/
12211313-#include "config.h"
2222+/*#define _NOERRORCHECK_*/
1423#include "Math.h"
15241625/* useful constants */
···300309{
301310 DomainCheck(x <= 0, MinusMax);
302311 return(_log10(x));
312312+}
313313+314314+315315+/*
316316+ * modf - split a floating number into fraction/integer
317317+ *
318318+ */
319319+320320+double modf(x, nptr)
321321+double x, *nptr;
322322+{
323323+ return(_modf(x, nptr));
303324}
304325305326
+22-16
Library Sources/MathHybrid.c
···7788 For details, refer to Harbison & Steele's "C: A Reference Manual",
99 Chapter 11.
1010+1111+ Two versions of each function are defined by this library: an
1212+ error-checking version (e.g. "sin") and a non-error-checking
1313+ version (e.g. "_sin").
1414+1515+ The non-underscore names can be made to refer to the non-error-
1616+ checking functions by #defining _NOERRORCHECK_ before #including
1717+ "math.h". Doing so in THIS file suppresses the definitions of
1818+ the error-checking versions of the functions altogether.
10191120*/
12211313-#include "config.h"
2222+/*#define _NOERRORCHECK_*/
1423#include "math.h"
1524#include "sane.h"
1625···322331 _to80(y);
323332 fp68k(&_x80, FOABS);
324333 fp68k(&_x80, &tz, FOREM);
334334+ _to96(y);
325335 _x80tox96(tz, z);
326336327337 if (x > 0 && z < 0)
···397407398408double _modf(x, nptr)
399409double x;
400400-register int *nptr;
410410+register double *nptr;
401411{
402402- if (abs(*nptr = x) > _fabs(x)) {
403403- if (*nptr > 0)
404404- --*nptr;
405405- else
406406- ++*nptr;
407407- }
412412+ _to80(x);
413413+ fp68k(&_x80, FOTTI);
414414+ x80tox96(&_x80, nptr);
408415 return(x - *nptr);
409416}
410417···415422 _x96tox80(y, ty);
416423 _x96tox80(x, tx);
417424 elems68k(&ty, &tx, FOPWRY);
418418- _x80tox96(ty, y);
425425+/* _x80tox96(ty, y); */
419426 _x80tox96(tx, x);
427427+ return(x);
420428}
421429422430double _sin(x)
···607615608616609617double modf(x, nptr)
610610-double x;
611611-register int *nptr;
618618+double x, *nptr;
612619{
613620 return(_modf(x, nptr));
614621}
···616623double pow(x, y)
617624double x, y;
618625{
619619- int exactint = 0;
626626+ int odd = 0;
620627 Extended80 tx, ty;
621628622629 ClearExceptions();
···633640 if (y == 0)
634641 return(One);
635642 if (x < 0) {
636636- _modf(y, &exactint);
637637- if (exactint != y) {
643643+ if (_modf(y, &y)) {
638644#ifdef _ERRORCHECK_
639645 errno = EDOM;
640646#endif
641647 return (MinusMax);
642648 }
643649 x = -x;
650650+ odd = _fmod(y, Two);
644651 }
645652646653 x = _pow(x, y);
647654 RangeCheck(x);
648648- return((exactint & 1) ? -x : x);
655655+ return(odd ? -x : x);
649656}
650657651658double sin(x)
···663670 ClearExceptions();
664671 y = _sinh(x);
665672 RangeCheck(y);
666666- xfersign(x, &y);
667673 return(y);
668674}
669675
···11-/*
22- Routines for LightspeedC
3144- (C) Copyright 1985, 1986. THINK Technologies, Inc. All rights reserved.
55-66-*/
72/*
88- * onexit
33+ * onexit.c - Copyright (C) 1989 by Symantec Corp. All rights reserved.
94 *
1010- * By calling "onexit", the programmer can arrange for up to NPROCS
1111- * routines to be called just before program exit. The routines are
1212- * called with no arguments and in the reverse order in which they
1313- * were supplied to "onexit".
55+ * Shutdown routines installed with "onexit" are called only on NORMAL
66+ * termination, i.e. calling "exit" or returning from "main".
147 *
1515- * "Onexit" returns its argument, the address of the routine to be
1616- * called, or zero if it has already been called NPROCS times.
88+ * Shutdown routines installed with "_onexit" are called on "ExitToShell"
99+ * as well as on normal termination.
1710 *
1818- * "Onexit" is built on a lower-level mechanism, "_onexit", which
1919- * provides for a single routine to be called at termination.
1111+ * When initiating any other form of termination (e.g. "Launch"), the
1212+ * user can call "_exiting" to force shutdown routines to be called.
2013 *
2114 */
22151616+#ifndef _MacTypes_
1717+#include <MacHeaders>
1818+#endif
23192424-typedef void (*Proc)(); /* address of a proc */
2020+extern long ATrapHandler : 0x28;
25212626-#define NPROCS 32 /* max # of procs in list */
2727-static int nprocs = 0; /* actual # of procs in list */
2828-static Proc proctable[NPROCS]; /* list of procs */
2222+typedef void (*Proc)();
29233030-static long _onexit = 0x4EED006A; /* "jmp $6A(a5)" */
2424+Proc onexit(Proc);
2525+Proc _onexit(Proc);
2626+void _exiting(int);
2727+void exit(int);
2828+void nop(void);
2929+void abort(void);
31303232-onexit_handler()
3131+#define NPROCS 32
3232+3333+static struct proc { Proc proc; int always; } procs[NPROCS];
3434+static int next = 0;
3535+static Proc oldexit, oldES;
3636+static char *ptrES;
3737+3838+static void normal_exit(void), newES(void);
3939+4040+4141+/*
4242+ * exit - normal program termination
4343+ *
4444+ * The exit status is ignored.
4545+ *
4646+ */
4747+4848+void
4949+exit(i)
3350{
3434- while (nprocs>0)
3535- if (proctable[--nprocs])
3636- (*proctable[nprocs])();
5151+ asm {
5252+ movea.l 0x6C(a5),a0
5353+ jsr (a0) ; call onexit vector
5454+ _ExitToShell
5555+ }
3756}
38573939-#line 0 onexit()
5858+5959+/*
6060+ * onexit - install user shutdown routine
6161+ *
6262+ */
6363+4064Proc
4165onexit(proc)
4266Proc proc;
4367{
4444- if (nprocs == 0)
4545- (* ((Proc) &_onexit))(onexit_handler);
6868+ register struct proc *p;
46694747- return(nprocs < NPROCS ? proctable[nprocs++] = proc : 0);
7070+ if (next == NPROCS)
7171+ return(0);
7272+7373+ /* install proc in table */
7474+7575+ p = &procs[next++];
7676+ p->proc = proc;
7777+/* p->always = 0; */
7878+ if (!oldexit) {
7979+ proc = normal_exit;
8080+8181+ /* install onexit vector */
8282+8383+ asm {
8484+ move.l 0x6C(a5),oldexit
8585+ move.l proc,0x6C(a5)
8686+ }
8787+ }
8888+ return(p->proc);
8989+}
9090+9191+9292+/*
9393+ * normal_exit - onexit vector
9494+ *
9595+ */
9696+9797+static void
9898+normal_exit()
9999+{
100100+ _exiting(1);
48101}
4910250103104104+/*
105105+ * _onexit - install a critical shutdown routine
106106+ *
107107+ * Routines installed with "_onexit" are called even if the program does
108108+ * not terminate normally, provided only that "ExitToShell" is called.
109109+ *
110110+ */
111111+112112+Proc
113113+_onexit(proc)
114114+Proc proc;
115115+{
116116+ register struct proc *p;
117117+118118+ if (next == NPROCS)
119119+ return(0);
120120+121121+ /* install proc in table */
122122+123123+ p = &procs[next++];
124124+ p->proc = proc;
125125+ p->always = 1;
126126+ if (!oldES) {
127127+ proc = newES;
128128+129129+ /* save original ExitToShell */
130130+131131+ asm {
132132+ move.w #0xA9F4,d0 ; _ExitToShell
133133+ _GetTrapAddress
134134+ move.l a0,oldES
135135+ }
136136+137137+ /* (64K ROM only) allocate intercept in sysheap */
138138+139139+ asm {
140140+ movea.l proc,a0
141141+ tst.w ROM85
142142+ bpl.s @1
143143+ moveq #6,d0
144144+ _NewPtr SYS
145145+ move.l a0,ptrES
146146+ move.w #0x4EF9,(a0) ; JMP abs.L
147147+ move.l proc,2(a0)
148148+@1 }
149149+150150+ /* install ExitToShell intercept */
151151+152152+ asm {
153153+ move.w #0xA9F4,d0 ; _ExitToShell
154154+ _SetTrapAddress
155155+ }
156156+ }
157157+ return(p->proc);
158158+}
159159+160160+161161+/*
162162+ * newES - ExitToShell intercept
163163+ *
164164+ */
165165+166166+static void
167167+newES()
168168+{
169169+ _exiting(0);
170170+ ExitToShell();
171171+}
172172+173173+174174+/*
175175+ * _exiting - perform shutdown activity
176176+ *
177177+ * The argument controls which shutdown routines should be called:
178178+ *
179179+ * _exiting(1) call all installed shutdown routines
180180+ * _exiting(0) call only routines installed with "_onexit"
181181+ *
182182+ */
183183+184184+void
185185+_exiting(normally)
186186+{
187187+ register struct proc *p;
188188+ Proc proc;
189189+ int i;
190190+191191+ SetUpA5();
192192+ p = &procs[NPROCS];
193193+ for (i = NPROCS; i--; ) {
194194+ if (proc = (--p)->proc) {
195195+ p->proc = 0;
196196+ if (normally || p->always)
197197+ (*proc)();
198198+ }
199199+ }
200200+201201+ /* deallocate ExitToShell intercept */
202202+203203+ asm {
204204+ move.l ptrES,d0
205205+ beq.s @1
206206+ movea.l d0,a0
207207+ _DisposPtr
208208+ clr.l ptrES
209209+@1 }
210210+211211+ /* remove ExitToShell intercept */
212212+213213+ asm {
214214+ move.l oldES,d0
215215+ beq.s @2
216216+ movea.l d0,a0
217217+ move.w #0xA9F4,d0
218218+ _SetTrapAddress
219219+ clr.l oldES
220220+@2 }
221221+222222+ /* call original exit proc */
223223+224224+ asm {
225225+ movea.l 0x6C(a5),a0
226226+ move.l oldexit,d0
227227+ beq.s @3
228228+ movea.l d0,a0
229229+@3 jsr (a0)
230230+ }
231231+ oldexit = nop;
232232+ RestoreA5();
233233+}
234234+235235+236236+/*
237237+ * nop - do nothing
238238+ *
239239+ */
240240+241241+static void
242242+nop()
243243+{
244244+}
245245+246246+247247+/*
248248+ * abort - abort execution
249249+ *
250250+ * A debugger trap is issued if it looks like a debugger is installed.
251251+ *
252252+ */
253253+254254+void
255255+abort()
256256+{
257257+ if (GetTrapAddress(0xA055) == GetTrapAddress(0xA89F)) {
258258+ if ((ATrapHandler & Lo3Bytes) < ((long) ROMBase & Lo3Bytes))
259259+ Debugger();
260260+ }
261261+ else {
262262+ if (StripAddress(ATrapHandler) < StripAddress(ROMBase))
263263+ Debugger();
264264+ }
265265+ ExitToShell();
266266+}
+5-6
Library Sources/stdio .c files/printf-2-w.c
···17171818/* #define _NonMacScreen_ */
19192020-#include "config.h"
2020+#define _HALFWINDOW_
21212222#ifndef _stdioh_
2323#include "stdio.h"
···152152 watch = **GetCursor(watchCursor);
153153 SetCursor(&watch);
154154 _click_on = false;
155155- onexit_handler(); /* make sure other onexit routines get called */
156156- ExitToShell();
155155+ exit(0);
157156}
158157159158static
···684683685684/* RMS 4/20/88 */
686685/* procedure to determine if MultiFinder is running by checking for the
687687-existence of the WaitNextEvent() trap */
686686+existence of the _OSDispatch trap */
688687689688static int MFIsRunning()
690690-{ /* $8F is for _MFDispatch, $9F is the unimplemented trap */
689689+{ /* $8F is for _OSDispatch, $9F is the unimplemented trap */
691690 return (GetTrapAddress(0x8FL) != GetTrapAddress(0x9FL));
692691}
693692···966965 /* make sure all exit routines have been called before we
967966 do anything */
968967969969- onexit_handler();
968968+ _exiting(1);
970969971970 /* if (emptyrgn) DisposeRgn(emptyrgn); - need not bother since the
972971 entire application heap should be vaporized shortly */
-2
Library Sources/stdio .c files/printf-3.c
···99/* comment this out if you don't need floating point numeric support */
1010#define _FORMAT_FP_
11111212-#include "config.h"
1313-1412#ifndef _stdioh_
1513#include "stdio.h"
1614#endif
-2
Library Sources/stdio .c files/scanf2.c
···44 (C) Copyright 1986. THINK Technologies, Inc. All rights reserved.
55*/
6677-#include "config.h"
88-97#ifndef _stdioh_
108#include "stdio.h"
119#endif
+1-13
Library Sources/stdio .c files/stdget_console.c
···31313232int (*_key_int_sig_func_)() = 0;
33333434-extern long ATrapHandler : 0x28;
3535-3636-#define DebuggerIn() (((long)ATrapHandler & Lo3Bytes) < (long)((long)ROMBase & Lo3Bytes))
3737-3834/* pdg - 6/18/86 - completely revised command character handling of the
3935 following function to allow control characters to be
4036 easily generated from the keyboard */
···163159 case 'C':
164160 case '.':
165161 if ((long)_key_int_sig_func_ == SIG_DFL)
166166- {
167167- /* call debugger if loaded, then
168168- (or otherwise) depart */
169169-170170- if (DebuggerIn())
171171- Debugger();
172172-173173- ExitToShell();
174174- }
162162+ abort();
175163176164 _key_int_sig_func_ = (void*) SIG_DFL;
177165 (*_temp_key_int_sig_func_)(SIGINT);
+2-2
Library Sources/stdio .c files/stdver.c
···1515#line 0 std_ver()
1616char *std_ver()
1717{
1818-static char STDIO_VERSION[] = "THINK C Libraries 3.01";
1919-static char copyright[] = "� 1988 Symantec Corp. All rights reserved.";
1818+static char STDIO_VERSION[] = "THINK C Libraries 3.02";
1919+static char copyright[] = "� 1989 Symantec Corp. All rights reserved.";
20202121 return (STDIO_VERSION);
2222}
-1
Library Sources/unix .c files/unixatof.c
···11/* (C) Copyright 1986. THINK Technologies, Inc. All rights reserved. */
2233-#include "config.h"
43#include "unix.h"
54#include "sane.h"
65#include "MacTypes.h"
···991010extern int errno;
1111extern int (*_key_int_sig_func_)();
1212+extern void abort();
12131314static void *sigptr[_SIGMAX+1]; /* array of signal pointers, initially 0 */
1415static char _initsigterm = 0; /* flag for special SIGTERM set up */
15161616-extern long ATrapHandler : 0x28;
1717-extern long ROMBase : 0x2AE;
1818-extern long Lo3Bytes : 0x31A;
1919-2020-#define DebuggerIn() ((ATrapHandler & Lo3Bytes) < (ROMBase & Lo3Bytes))
2121-2222-#line 0 bugout
2323-2424-static void bugout()
2525-{
2626- /* call debugger if loaded, then (or otherwise) depart */
2727-2828- if (DebuggerIn())
2929- Debugger();
3030-3131- ExitToShell();
3232-}
3333-3417#line 0 dosigterm
35183619static void dosigterm()
···6649 /* see if user wants to cause an exit on SIGINT */
67506851 if ((long)func == SIG_DFL)
6969- _key_int_sig_func_ = (void*) bugout;
5252+ _key_int_sig_func_ = (void*) abort;
7053 else
7154 if ((long)func == SIG_IGN)
7255 _key_int_sig_func_ = 0; /* eliminate any set function */
···8265 if (!_initsigterm)
8366 {
8467 _initsigterm = 1;
8585- onexit(dosigterm);
6868+ _onexit(dosigterm);
8669 }
8770 default:
8871 if ((sig > 0) && (sig <= _SIGMAX))
···9275 /* see if user wants to cause an exit on signal */
93769477 if ((long)func == SIG_DFL)
9595- sigptr[sig] = (void*) bugout;
7878+ sigptr[sig] = (void*) abort;
9679 else
9780 if ((long)func == SIG_IGN)
9881 sigptr[sig] = 0; /* eliminate any set function */