Improved some error messages for command line processing.
[python/dscho.git] / Mac / Python / macshlglue.c
blob4b5107067029717259a4032650b6b9a77449ece1
1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
15 permission.
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 ** Shared library initialization code.
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.
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.
46 #include <Types.h>
47 #include <Quickdraw.h>
48 #include <SegLoad.h>
49 #include <CodeFragments.h>
50 #include <Files.h>
51 #include <Resources.h>
54 ** Variables passed from shared lib initialization to PyMac_AddLibResources.
56 static int library_fss_valid;
57 static FSSpec library_fss;
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).
63 OSErr pascal
64 __initialize_with_resources(CFragInitBlockPtr data)
66 /* Call the MW runtime's initialization routine */
67 /* #ifdef __CFM68K__ */
68 #if 1
69 __initialize();
70 #else
71 __sinit();
72 #endif
74 if ( data == nil ) return noErr;
75 if ( data->fragLocator.where == kDataForkCFragLocator ) {
76 library_fss = *data->fragLocator.u.onDisk.fileSpec;
77 library_fss_valid = 1;
78 } else if ( data->fragLocator.where == kResourceCFragLocator ) {
79 library_fss = *data->fragLocator.u.inSegs.fileSpec;
80 library_fss_valid = 1;
82 return noErr;
86 ** compare two FSSpecs, return true if equal, false if different
87 ** XXX where could this function live? (jvr)
90 static int
91 FSpCompare(FSSpec *fss1, FSSpec *fss2) {
92 if (fss1->vRefNum != fss2->vRefNum)
93 return 0;
94 if (fss1->parID != fss2->parID)
95 return 0;
96 return !PLstrcmp(fss1->name, fss2->name);
99 /* XXX can't include "macglue.h" somehow (jvr) */
100 extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */
103 ** Insert the library resources into the search path. Put them after
104 ** the resources from the application (which we assume is the current
105 ** resource file). Again, we ignore errors.
107 void
108 PyMac_AddLibResources()
110 if ( !library_fss_valid || FSpCompare(&library_fss, &PyMac_ApplicationFSSpec))
111 return;
112 (void)FSpOpenResFile(&library_fss, fsRdPerm);
116 ** Dummy main() program to keep linker happy: we want to
117 ** use the MW AppRuntime in our shared library (better than building
118 ** custom runtime libraries as we did before) but AppRuntime
119 ** expects a main program. Note that it
122 #pragma export off
124 main(int argc, char **argv) {
125 DebugStr("\pCannot happen: PythonCore dummy main called!");
127 #pragma export reset