Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 1 | /* |
Jack Jansen | 5bd85d9 | 1996-08-23 15:45:26 +0000 | [diff] [blame] | 2 | ** 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 Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 15 | #include <Quickdraw.h> |
| 16 | #include <SegLoad.h> |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 17 | #include <FragLoad.h> |
| 18 | #include <Files.h> |
| 19 | #include <Resources.h> |
| 20 | |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 21 | |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 22 | /* |
| 23 | ** Variables passed from shared lib initialization to PyMac_AddLibResources. |
| 24 | */ |
| 25 | static int library_fss_valid; |
| 26 | static FSSpec library_fss; |
| 27 | |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 28 | /* |
| 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 Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 32 | OSErr pascal |
Jack Jansen | 5bd85d9 | 1996-08-23 15:45:26 +0000 | [diff] [blame] | 33 | __initialize_with_resources(InitBlockPtr data) |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 34 | { |
Jack Jansen | 9ff06ce | 1996-08-19 11:17:33 +0000 | [diff] [blame] | 35 | /* Call the MW runtime's initialization routine */ |
Jack Jansen | 5bd85d9 | 1996-08-23 15:45:26 +0000 | [diff] [blame] | 36 | /* #ifdef __CFM68K__ */ |
| 37 | #if 1 |
Jack Jansen | 9ff06ce | 1996-08-19 11:17:33 +0000 | [diff] [blame] | 38 | __initialize(); |
Jack Jansen | a06f13d | 1996-08-19 15:10:50 +0000 | [diff] [blame] | 39 | #else |
| 40 | __sinit(); |
| 41 | #endif |
Jack Jansen | 8ab1148 | 1996-02-29 16:10:32 +0000 | [diff] [blame] | 42 | |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 43 | if ( data == nil ) return noErr; |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 44 | 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 | */ |
| 59 | void |
| 60 | PyMac_AddLibResources() |
| 61 | { |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 62 | if ( !library_fss_valid ) |
| 63 | return; |
Jack Jansen | 83f4540 | 1995-10-09 23:25:32 +0000 | [diff] [blame] | 64 | (void)FSpOpenResFile(&library_fss, fsRdPerm); |
Jack Jansen | 2e4679d | 1995-02-13 11:39:17 +0000 | [diff] [blame] | 65 | } |
Guido van Rossum | 7c496ec | 1995-02-20 23:44:43 +0000 | [diff] [blame] | 66 | |