@@ -27,6 +27,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2727
2828#include <stdlib.h>
2929
30+ #ifdef WITHOUT_FRAMEWORKS
3031#include <Types.h>
3132#include <Files.h>
3233#include <Events.h>
@@ -40,6 +41,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4041#include <Menus.h>
4142#include <Dialogs.h>
4243#include <Windows.h>
44+ #else
45+ #include <Carbon/Carbon.h>
46+ #endif /* WITHOUT_FRAMEWORKS */
4347
4448#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
4549typedef long refcontype ;
@@ -54,7 +58,6 @@ static int arg_count;
5458static char * arg_vector [256 ];
5559FSSpec PyMac_ApplicationFSSpec ;
5660char PyMac_ApplicationPath [256 ];
57- static int applocation_inited ;
5861
5962/* Duplicate a string to the heap. We also export this since it isn't standard
6063** and others use it
@@ -70,14 +73,33 @@ strdup(const char *src)
7073}
7174#endif
7275
76+ #if TARGET_API_MAC_OSX
77+ OSErr
78+ PyMac_GetFullPath (FSSpec * fss , char * path )
79+ {
80+ FSRef fsr ;
81+ OSErr err ;
82+
83+ * path = '\0' ;
84+ err = FSpMakeFSRef (fss , & fsr );
85+ if ( err ) return err ;
86+ err = (OSErr )FSRefMakePath (& fsr , path , 1024 );
87+ if ( err ) return err ;
88+ return 0 ;
89+ }
90+ #endif /* TARGET_API_MAC_OSX */
91+
92+
93+ #if !TARGET_API_MAC_OSX
7394/* Initialize FSSpec and full name of current application */
7495
7596OSErr
76- PyMac_init_process_location ()
97+ PyMac_init_process_location (void )
7798{
7899 ProcessSerialNumber currentPSN ;
79100 ProcessInfoRec info ;
80101 OSErr err ;
102+ static int applocation_inited ;
81103
82104 if ( applocation_inited ) return 0 ;
83105 currentPSN .highLongOfPSN = 0 ;
@@ -92,6 +114,7 @@ PyMac_init_process_location()
92114 applocation_inited = 1 ;
93115 return 0 ;
94116}
117+ #endif /* !TARGET_API_MAC_OSX */
95118
96119/* Check that there aren't any args remaining in the event */
97120
@@ -147,15 +170,15 @@ handle_open_doc(const AppleEvent *theAppleEvent, AppleEvent *reply, refcontype r
147170 DescType rttype ;
148171 long i , ndocs , size ;
149172 FSSpec fss ;
150- char path [256 ];
173+ char path [1024 ];
151174
152175 got_one = 1 ;
153- if (err = AEGetParamDesc (theAppleEvent ,
154- keyDirectObject , typeAEList , & doclist ))
176+ if (( err = AEGetParamDesc (theAppleEvent ,
177+ keyDirectObject , typeAEList , & doclist )))
155178 return err ;
156- if (err = get_missing_params (theAppleEvent ))
179+ if (( err = get_missing_params (theAppleEvent ) ))
157180 return err ;
158- if (err = AECountItems (& doclist , & ndocs ))
181+ if (( err = AECountItems (& doclist , & ndocs ) ))
159182 return err ;
160183 for (i = 1 ; i <= ndocs ; i ++ ) {
161184 err = AEGetNthPtr (& doclist , i , typeFSS ,
@@ -174,7 +197,7 @@ AEEventHandlerUPP open_app_upp;
174197AEEventHandlerUPP not_upp ;
175198
176199static void
177- set_ae_handlers ()
200+ set_ae_handlers (void )
178201{
179202 open_doc_upp = NewAEEventHandlerUPP (& handle_open_doc );
180203 open_app_upp = NewAEEventHandlerUPP (& handle_open_app );
@@ -193,7 +216,7 @@ set_ae_handlers()
193216/* Uninstall standard core event handlers */
194217
195218static void
196- reset_ae_handlers ()
219+ reset_ae_handlers (void )
197220{
198221 AERemoveEventHandler (kCoreEventClass , kAEOpenApplication ,
199222 open_app_upp , false);
@@ -208,7 +231,7 @@ reset_ae_handlers()
208231/* Wait for events until a core event has been handled */
209232
210233static void
211- event_loop ()
234+ event_loop (void )
212235{
213236 EventRecord event ;
214237 int n ;
@@ -229,14 +252,16 @@ event_loop()
229252/* Get the argv vector, return argc */
230253
231254int
232- PyMac_GetArgv (pargv , noevents )
233- char * * * pargv ;
234- int noevents ;
255+ PyMac_GetArgv (char * * * pargv , int noevents )
235256{
236-
237257 arg_count = 0 ;
258+ #if TARGET_API_MAC_OSX
259+ /* In an OSX bundle argv[0] is okay */
260+ arg_count ++ ;
261+ #else
238262 (void )PyMac_init_process_location ();
239263 arg_vector [arg_count ++ ] = strdup (PyMac_ApplicationPath );
264+ #endif /* TARGET_API_MAC_OSX */
240265
241266 if ( !noevents ) {
242267 set_ae_handlers ();
0 commit comments