blob: 58fe7fd3a0c9064bcd268fa5442d3a1db9dc7b8d [file] [log] [blame]
Jack Jansen2e4679d1995-02-13 11:39:17 +00001/*
Jack Jansen5bd85d91996-08-23 15:45:26 +00002** Shared library initialization code.
3**
4** This code calls the MetroWerks shared-library initialization code
5** and performs one extra step: it remembers the FSSpec of the file
6** we are loaded from, so we can later call PyMac_AddLibResources to
7** add the file to our resource file chain.
8**
9** This file is needed for PythonCore and for any dynamically loaded
10** module that has interesting resources in its .slb file.
11** Use by replacing __initialize in the "CFM preferences" init field
12** by __initialize_with_resources.
Jack Jansen2e4679d1995-02-13 11:39:17 +000013*/
14
Jack Jansen2e4679d1995-02-13 11:39:17 +000015#include <Quickdraw.h>
16#include <SegLoad.h>
Jack Jansen2e4679d1995-02-13 11:39:17 +000017#include <FragLoad.h>
18#include <Files.h>
19#include <Resources.h>
20
Jack Jansen2e4679d1995-02-13 11:39:17 +000021
Guido van Rossum7c496ec1995-02-20 23:44:43 +000022/*
23** Variables passed from shared lib initialization to PyMac_AddLibResources.
24*/
25static int library_fss_valid;
26static FSSpec library_fss;
27
Jack Jansen2e4679d1995-02-13 11:39:17 +000028/*
29** Routine called upon fragment load. We attempt to save the FSSpec from which we're
30** loaded. We always return noErr (we just continue without the resources).
31*/
Guido van Rossum7c496ec1995-02-20 23:44:43 +000032OSErr pascal
Jack Jansen5bd85d91996-08-23 15:45:26 +000033__initialize_with_resources(InitBlockPtr data)
Jack Jansen2e4679d1995-02-13 11:39:17 +000034{
Jack Jansen9ff06ce1996-08-19 11:17:33 +000035 /* Call the MW runtime's initialization routine */
Jack Jansen5bd85d91996-08-23 15:45:26 +000036/* #ifdef __CFM68K__ */
37#if 1
Jack Jansen9ff06ce1996-08-19 11:17:33 +000038 __initialize();
Jack Jansena06f13d1996-08-19 15:10:50 +000039#else
40 __sinit();
41#endif
Jack Jansen8ab11481996-02-29 16:10:32 +000042
Guido van Rossum7c496ec1995-02-20 23:44:43 +000043 if ( data == nil ) return noErr;
Jack Jansen2e4679d1995-02-13 11:39:17 +000044 if ( data->fragLocator.where == kOnDiskFlat ) {
45 library_fss = *data->fragLocator.u.onDisk.fileSpec;
46 library_fss_valid = 1;
47 } else if ( data->fragLocator.where == kOnDiskSegmented ) {
48 library_fss = *data->fragLocator.u.inSegs.fileSpec;
49 library_fss_valid = 1;
50 }
51 return noErr;
52}
53
54/*
55** Insert the library resources into the search path. Put them after
56** the resources from the application (which we assume is the current
57** resource file). Again, we ignore errors.
58*/
59void
60PyMac_AddLibResources()
61{
Jack Jansen2e4679d1995-02-13 11:39:17 +000062 if ( !library_fss_valid )
63 return;
Jack Jansen83f45401995-10-09 23:25:32 +000064 (void)FSpOpenResFile(&library_fss, fsRdPerm);
Jack Jansen2e4679d1995-02-13 11:39:17 +000065}
Guido van Rossum7c496ec1995-02-20 23:44:43 +000066