1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/***********************************************************
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI or Corporation for National Research Initiatives or
CNRI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
While CWI is the initial source for this software, a modified version
is made available by the Corporation for National Research Initiatives
(CNRI) at the Internet address ftp://ftp.python.org.
STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/*
** Shared library initialization code.
**
** This code calls the MetroWerks shared-library initialization code
** and performs one extra step: it remembers the FSSpec of the file
** we are loaded from, so we can later call PyMac_AddLibResources to
** add the file to our resource file chain.
**
** This file is needed for PythonCore and for any dynamically loaded
** module that has interesting resources in its .slb file.
** Use by replacing __initialize in the "CFM preferences" init field
** by __initialize_with_resources.
*/
#include <Types.h>
#include <Quickdraw.h>
#include <SegLoad.h>
#include <CodeFragments.h>
#include <Files.h>
#include <Resources.h>
/* Defined in the MSL runtime: */
extern void __initialize(void);
/* Defined either in macglue.c or in a MPW library: */
extern pascal int PLstrcmp(unsigned char *, unsigned char *);
/*
** Variables passed from shared lib initialization to PyMac_AddLibResources.
*/
static int library_fss_valid;
static FSSpec library_fss;
/*
** Routine called upon fragment load. We attempt to save the FSSpec from which we're
** loaded. We always return noErr (we just continue without the resources).
*/
OSErr pascal
__initialize_with_resources(CFragInitBlockPtr data)
{
/* Call the MW runtime's initialization routine */
__initialize();
if ( data == nil ) return noErr;
if ( data->fragLocator.where == kDataForkCFragLocator ) {
library_fss = *data->fragLocator.u.onDisk.fileSpec;
library_fss_valid = 1;
} else if ( data->fragLocator.where == kResourceCFragLocator ) {
library_fss = *data->fragLocator.u.inSegs.fileSpec;
library_fss_valid = 1;
}
return noErr;
}
/*
** compare two FSSpecs, return true if equal, false if different
** XXX where could this function live? (jvr)
*/
static int
FSpCompare(FSSpec *fss1, FSSpec *fss2) {
if (fss1->vRefNum != fss2->vRefNum)
return 0;
if (fss1->parID != fss2->parID)
return 0;
return !PLstrcmp(fss1->name, fss2->name);
}
/* XXX can't include "macglue.h" somehow (jvr) */
extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */
/*
** Insert the library resources into the search path. Put them after
** the resources from the application (which we assume is the current
** resource file). Again, we ignore errors.
*/
void
PyMac_AddLibResources()
{
if ( !library_fss_valid || FSpCompare(&library_fss, &PyMac_ApplicationFSSpec))
return;
(void)FSpOpenResFile(&library_fss, fsRdPerm);
}
/*
** Dummy main() program to keep linker happy: we want to
** use the MW AppRuntime in our shared library (better than building
** custom runtime libraries as we did before) but AppRuntime
** expects a main program. Note that it
*/
#pragma export off
int
main(int argc, char **argv) {
DebugStr("\pCannot happen: PythonCore dummy main called!");
}
#pragma export reset
|