blob: 9a7cc5e34c1bf4ee34425a2e1beb351ff3a9a406 [file] [log] [blame]
Jack Jansen42218ce1997-01-31 16:15:11 +00001/***********************************************************
2Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3The 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 or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
Jack Jansen2e4679d1995-02-13 11:39:17 +000032/*
Jack Jansen5bd85d91996-08-23 15:45:26 +000033** Shared library initialization code.
34**
35** This code calls the MetroWerks shared-library initialization code
36** and performs one extra step: it remembers the FSSpec of the file
37** we are loaded from, so we can later call PyMac_AddLibResources to
38** add the file to our resource file chain.
39**
40** This file is needed for PythonCore and for any dynamically loaded
41** module that has interesting resources in its .slb file.
42** Use by replacing __initialize in the "CFM preferences" init field
43** by __initialize_with_resources.
Jack Jansen2e4679d1995-02-13 11:39:17 +000044*/
45
Jack Jansen2e4679d1995-02-13 11:39:17 +000046#include <Quickdraw.h>
47#include <SegLoad.h>
Jack Jansen2e4679d1995-02-13 11:39:17 +000048#include <FragLoad.h>
49#include <Files.h>
50#include <Resources.h>
51
Jack Jansen2e4679d1995-02-13 11:39:17 +000052
Guido van Rossum7c496ec1995-02-20 23:44:43 +000053/*
54** Variables passed from shared lib initialization to PyMac_AddLibResources.
55*/
56static int library_fss_valid;
57static FSSpec library_fss;
58
Jack Jansen2e4679d1995-02-13 11:39:17 +000059/*
60** Routine called upon fragment load. We attempt to save the FSSpec from which we're
61** loaded. We always return noErr (we just continue without the resources).
62*/
Guido van Rossum7c496ec1995-02-20 23:44:43 +000063OSErr pascal
Jack Jansen5bd85d91996-08-23 15:45:26 +000064__initialize_with_resources(InitBlockPtr data)
Jack Jansen2e4679d1995-02-13 11:39:17 +000065{
Jack Jansen9ff06ce1996-08-19 11:17:33 +000066 /* Call the MW runtime's initialization routine */
Jack Jansen5bd85d91996-08-23 15:45:26 +000067/* #ifdef __CFM68K__ */
68#if 1
Jack Jansen9ff06ce1996-08-19 11:17:33 +000069 __initialize();
Jack Jansena06f13d1996-08-19 15:10:50 +000070#else
71 __sinit();
72#endif
Jack Jansen8ab11481996-02-29 16:10:32 +000073
Guido van Rossum7c496ec1995-02-20 23:44:43 +000074 if ( data == nil ) return noErr;
Jack Jansen2e4679d1995-02-13 11:39:17 +000075 if ( data->fragLocator.where == kOnDiskFlat ) {
76 library_fss = *data->fragLocator.u.onDisk.fileSpec;
77 library_fss_valid = 1;
78 } else if ( data->fragLocator.where == kOnDiskSegmented ) {
79 library_fss = *data->fragLocator.u.inSegs.fileSpec;
80 library_fss_valid = 1;
81 }
82 return noErr;
83}
84
85/*
86** Insert the library resources into the search path. Put them after
87** the resources from the application (which we assume is the current
88** resource file). Again, we ignore errors.
89*/
90void
91PyMac_AddLibResources()
92{
Jack Jansen2e4679d1995-02-13 11:39:17 +000093 if ( !library_fss_valid )
94 return;
Jack Jansen83f45401995-10-09 23:25:32 +000095 (void)FSpOpenResFile(&library_fss, fsRdPerm);
Jack Jansen2e4679d1995-02-13 11:39:17 +000096}
Guido van Rossum7c496ec1995-02-20 23:44:43 +000097