blob: 4c71234637f39a6014ec30c82e025faccdb21dee [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
Jack Jansen9ae898b2000-07-11 21:16:03 +000030extern void PyMac_InitApplication(void);
Jack Jansen68ecab41999-02-15 23:34:56 +000031#ifdef USE_MAC_APPLET_SUPPORT
Jack Jansen9ae898b2000-07-11 21:16:03 +000032extern void PyMac_InitApplet(void);
Jack Jansen68ecab41999-02-15 23:34:56 +000033#endif /* USE_MAC_APPLET_SUPPORT */
Jack Jansen76efd8e1995-02-24 22:53:16 +000034
Jack Jansen9ae898b2000-07-11 21:16:03 +000035/* From the MSL runtime: */
36extern void __initialize(void);
Jack Jansen205b4352000-01-07 14:53:31 +000037
38/*
39** Alternative initialization entry point for some very special cases.
40** Use this in stead of __initialize in the PEF settings to remember (and
41** re-open as resource file) the application. This is needed if we link against
42** a dynamic library that, in its own __initialize routine, opens a resource
43** file. This would mess up our finding of override preferences.
44** Only set this entrypoint in your apps if you notice sys.path or some such is
45** messed up.
46*/
47static int application_fss_valid;
48static FSSpec application_fss;
49
50OSErr pascal
51__initialize_remember_app_fsspec(CFragInitBlockPtr data)
52{
53 /* Call the MW runtime's initialization routine */
54 __initialize();
55 if ( data == nil ) return noErr;
56 if ( data->fragLocator.where == kDataForkCFragLocator ) {
57 application_fss = *data->fragLocator.u.onDisk.fileSpec;
58 application_fss_valid = 1;
59 } else if ( data->fragLocator.where == kResourceCFragLocator ) {
60 application_fss = *data->fragLocator.u.inSegs.fileSpec;
61 application_fss_valid = 1;
62 }
63 return noErr;
64}
65
Jack Jansen499a8af1996-08-19 11:38:03 +000066void
Jack Jansen76efd8e1995-02-24 22:53:16 +000067main() {
Jack Jansen205b4352000-01-07 14:53:31 +000068 if ( application_fss_valid )
69 (void)FSpOpenResFile(&application_fss, fsRdPerm);
Jack Jansen68ecab41999-02-15 23:34:56 +000070#ifdef USE_MAC_APPLET_SUPPORT
Jack Jansen205b4352000-01-07 14:53:31 +000071 {
Jack Jansen6b6e61d1999-02-15 21:33:34 +000072 Handle mainpyc;
73
74 mainpyc = Get1NamedResource('PYC ', "\p__main__");
75 if (mainpyc != NULL)
76 PyMac_InitApplet();
77 else
78 PyMac_InitApplication();
Jack Jansen205b4352000-01-07 14:53:31 +000079 }
Jack Jansen68ecab41999-02-15 23:34:56 +000080#else
81 PyMac_InitApplication();
82#endif /* USE_MAC_APPLET_SUPPORT */
Jack Jansen76efd8e1995-02-24 22:53:16 +000083}