home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * Startup.c - Default init/startup/termination routines for Metrowerks C++ (PowerPC)
- *
- * Copyright © 1993 metrowerks inc. All Rights Reserved.
- *
- */
-
- #include <Quickdraw.h>
- #include <SegLoad.h>
- #include <setjmp.h>
- #include <MWException.h>
-
- /* public data */
-
- QDGlobals qd; /* define the Quickdraw globals here! */
- jmp_buf __program_exit; /* exit() does a longjmp() to here */
- void (*__atexit_hook)(void); /* atexit() sets this up if it is ever called */
- void (*___atexit_hook)(void); /* _atexit() sets this up if it is ever called */
- int __aborting; /* abort() sets this and longjmps to __program_exit */
-
-
- /* external references */
-
- extern int main(int argc, char **argv);
-
-
- /* prototypes */
-
- void __sinit(void);
- void __start(void);
-
-
- /*
- * __sinit - stub for static initialization of C++ objects
- *
- * The linker replaces the contents of this module with something of the form:
- *
- * mflr r0
- * stw r0,8(sp)
- * stwu sp,-64(sp)
- * bl __sinit_<file1>
- * bl __sinit_<file2>
- * ...
- * bl __sinit_<fileN>
- * addi sp,sp,64
- * lwz r0,8(sp)
- * mtlr r0
- * blr
- */
-
- void __sinit(void)
- {
- }
-
-
- /*
- * __start - Default startup routine for Metrowerks C++ (PowerPC)
- *
- * This routine should be specified as the PEF main routine in the container
- * for any application. The program startup/termination sequence is:
- *
- * 1. Set up a jmp_buf for exit() to jump to
- * 2. Call all static initializers--these might call exit()
- * 3. Set up default values for 'argc' and 'argv' and call main()
- * 4. Execute any atexit() routines
- * 5. Destroy all static objects
- * 6. Execute any cleanup code, e.g. close open files, console window, etc.
- * 7. Terminate the Macintosh program
- *
- * We postulate that there are 2 kinds of atexit() routines: those which must
- * execute before any objects are destroyed, and those which must execute after.
- * We assume there is a non-standard _atexit() routine which can be used to install
- * the post-destruction exit handlers.
- *
- */
-
- void __start(void)
- {
- char *argv = 0;
-
- if (setjmp(__program_exit) == 0) { // set up jmp_buf for exit()
- __sinit(); // call all static initializers
- main(0, &argv); // call main(argc, argv)
- if (__atexit_hook)
- __atexit_hook(); // call atexit() procs
- }
- if (!__aborting) {
- __destroy_global_chain(); // destroy static objects
- if (___atexit_hook)
- ___atexit_hook(); // call _atexit() procs
- }
- // ExitToShell();
- }
-