Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 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. |
| 16 | |
| 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. |
| 20 | |
| 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. |
| 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 32 | /* |
Jack Jansen | 5bd85d9 | 1996-08-23 15:45:26 +0000 | [diff] [blame] | 33 | ** 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 Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 44 | */ |
| 45 | |
Jack Jansen | 3089b7e | 1997-05-07 15:48:01 +0000 | [diff] [blame] | 46 | #include <Types.h> |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 47 | #include <Quickdraw.h> |
| 48 | #include <SegLoad.h> |
Jack Jansen | c587301 | 1997-02-24 13:59:38 +0000 | [diff] [blame] | 49 | #include <CodeFragments.h> |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 50 | #include <Files.h> |
| 51 | #include <Resources.h> |
| 52 | |
Jack Jansen | 5bdbabd | 2000-07-24 19:52:52 +0000 | [diff] [blame] | 53 | /* Defined in the MSL runtime: */ |
| 54 | extern void __initialize(void); |
| 55 | |
| 56 | /* Defined either in macglue.c or in a MPW library: */ |
| 57 | extern pascal int PLstrcmp(unsigned char *, unsigned char *); |
| 58 | |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 59 | /* |
| 60 | ** Variables passed from shared lib initialization to PyMac_AddLibResources. |
| 61 | */ |
| 62 | static int library_fss_valid; |
| 63 | static FSSpec library_fss; |
| 64 | |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 65 | /* |
| 66 | ** Routine called upon fragment load. We attempt to save the FSSpec from which we're |
| 67 | ** loaded. We always return noErr (we just continue without the resources). |
| 68 | */ |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 69 | OSErr pascal |
Jack Jansen | 3089b7e | 1997-05-07 15:48:01 +0000 | [diff] [blame] | 70 | __initialize_with_resources(CFragInitBlockPtr data) |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 71 | { |
Jack Jansen | 9ff06ce | 1996-08-19 11:17:33 +0000 | [diff] [blame] | 72 | /* Call the MW runtime's initialization routine */ |
| 73 | __initialize(); |
Jack Jansen | 8ab1148 | 1996-02-29 16:10:32 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 75 | if ( data == nil ) return noErr; |
Jack Jansen | 3089b7e | 1997-05-07 15:48:01 +0000 | [diff] [blame] | 76 | if ( data->fragLocator.where == kDataForkCFragLocator ) { |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 77 | library_fss = *data->fragLocator.u.onDisk.fileSpec; |
| 78 | library_fss_valid = 1; |
Jack Jansen | 3089b7e | 1997-05-07 15:48:01 +0000 | [diff] [blame] | 79 | } else if ( data->fragLocator.where == kResourceCFragLocator ) { |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 80 | library_fss = *data->fragLocator.u.inSegs.fileSpec; |
| 81 | library_fss_valid = 1; |
| 82 | } |
| 83 | return noErr; |
| 84 | } |
| 85 | |
| 86 | /* |
Jack Jansen | 2e6445c | 1998-07-31 09:37:02 +0000 | [diff] [blame] | 87 | ** compare two FSSpecs, return true if equal, false if different |
| 88 | ** XXX where could this function live? (jvr) |
| 89 | */ |
| 90 | |
| 91 | static int |
| 92 | FSpCompare(FSSpec *fss1, FSSpec *fss2) { |
| 93 | if (fss1->vRefNum != fss2->vRefNum) |
| 94 | return 0; |
| 95 | if (fss1->parID != fss2->parID) |
| 96 | return 0; |
| 97 | return !PLstrcmp(fss1->name, fss2->name); |
| 98 | } |
| 99 | |
| 100 | /* XXX can't include "macglue.h" somehow (jvr) */ |
| 101 | extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */ |
| 102 | |
| 103 | /* |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 104 | ** Insert the library resources into the search path. Put them after |
| 105 | ** the resources from the application (which we assume is the current |
| 106 | ** resource file). Again, we ignore errors. |
| 107 | */ |
| 108 | void |
| 109 | PyMac_AddLibResources() |
| 110 | { |
Jack Jansen | 2e6445c | 1998-07-31 09:37:02 +0000 | [diff] [blame] | 111 | if ( !library_fss_valid || FSpCompare(&library_fss, &PyMac_ApplicationFSSpec)) |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 112 | return; |
Jack Jansen | 83f4540 | 1995-10-09 23:25:32 +0000 | [diff] [blame] | 113 | (void)FSpOpenResFile(&library_fss, fsRdPerm); |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 114 | } |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 115 | |
Jack Jansen | 3089b7e | 1997-05-07 15:48:01 +0000 | [diff] [blame] | 116 | /* |
| 117 | ** Dummy main() program to keep linker happy: we want to |
| 118 | ** use the MW AppRuntime in our shared library (better than building |
| 119 | ** custom runtime libraries as we did before) but AppRuntime |
| 120 | ** expects a main program. Note that it |
| 121 | */ |
| 122 | |
| 123 | #pragma export off |
| 124 | int |
| 125 | main(int argc, char **argv) { |
| 126 | DebugStr("\pCannot happen: PythonCore dummy main called!"); |
| 127 | } |
| 128 | #pragma export reset |