blob: 3923af204b288995ea10adb113b261749635355b [file] [log] [blame]
Jack Jansen76efd8e1995-02-24 22:53:16 +00001/***********************************************************
Jack Jansen42218ce1997-01-31 16:15:11 +00002Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Jack Jansen76efd8e1995-02-24 22:53:16 +00003The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Jack Jansen6b6e61d1999-02-15 21:33:34 +000025/* Macintosh Python main program for both applets and interpreter */
Jack Jansen76efd8e1995-02-24 22:53:16 +000026
Jack Jansen6b6e61d1999-02-15 21:33:34 +000027#include <Resources.h>
Jack Jansen205b4352000-01-07 14:53:31 +000028#include <CodeFragments.h>
Jack Jansen6b6e61d1999-02-15 21:33:34 +000029
30#ifdef __CFM68K__
Jack Jansen76efd8e1995-02-24 22:53:16 +000031#pragma lib_export on
32#endif
33
Jack Jansen9ae898b2000-07-11 21:16:03 +000034extern void PyMac_InitApplication(void);
Jack Jansen68ecab41999-02-15 23:34:56 +000035#ifdef USE_MAC_APPLET_SUPPORT
Jack Jansen9ae898b2000-07-11 21:16:03 +000036extern void PyMac_InitApplet(void);
Jack Jansen68ecab41999-02-15 23:34:56 +000037#endif /* USE_MAC_APPLET_SUPPORT */
Jack Jansen76efd8e1995-02-24 22:53:16 +000038
Jack Jansen9ae898b2000-07-11 21:16:03 +000039/* From the MSL runtime: */
40extern void __initialize(void);
Jack Jansen205b4352000-01-07 14:53:31 +000041
42/*
43** Alternative initialization entry point for some very special cases.
44** Use this in stead of __initialize in the PEF settings to remember (and
45** re-open as resource file) the application. This is needed if we link against
46** a dynamic library that, in its own __initialize routine, opens a resource
47** file. This would mess up our finding of override preferences.
48** Only set this entrypoint in your apps if you notice sys.path or some such is
49** messed up.
50*/
51static int application_fss_valid;
52static FSSpec application_fss;
53
54OSErr pascal
55__initialize_remember_app_fsspec(CFragInitBlockPtr data)
56{
57 /* Call the MW runtime's initialization routine */
58 __initialize();
59 if ( data == nil ) return noErr;
60 if ( data->fragLocator.where == kDataForkCFragLocator ) {
61 application_fss = *data->fragLocator.u.onDisk.fileSpec;
62 application_fss_valid = 1;
63 } else if ( data->fragLocator.where == kResourceCFragLocator ) {
64 application_fss = *data->fragLocator.u.inSegs.fileSpec;
65 application_fss_valid = 1;
66 }
67 return noErr;
68}
69
Jack Jansen499a8af1996-08-19 11:38:03 +000070void
Jack Jansen76efd8e1995-02-24 22:53:16 +000071main() {
Jack Jansen205b4352000-01-07 14:53:31 +000072 if ( application_fss_valid )
73 (void)FSpOpenResFile(&application_fss, fsRdPerm);
Jack Jansen68ecab41999-02-15 23:34:56 +000074#ifdef USE_MAC_APPLET_SUPPORT
Jack Jansen205b4352000-01-07 14:53:31 +000075 {
Jack Jansen6b6e61d1999-02-15 21:33:34 +000076 Handle mainpyc;
77
78 mainpyc = Get1NamedResource('PYC ', "\p__main__");
79 if (mainpyc != NULL)
80 PyMac_InitApplet();
81 else
82 PyMac_InitApplication();
Jack Jansen205b4352000-01-07 14:53:31 +000083 }
Jack Jansen68ecab41999-02-15 23:34:56 +000084#else
85 PyMac_InitApplication();
86#endif /* USE_MAC_APPLET_SUPPORT */
Jack Jansen76efd8e1995-02-24 22:53:16 +000087}