@@ -46,6 +46,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4646#include <Dialogs.h>
4747#include <Windows.h>
4848
49+ #include "Python.h"
50+ #include "macglue.h"
51+
4952#ifdef GENERATINGCFM /* Defined to 0 or 1 in Universal headers */
5053#define HAVE_UNIVERSAL_HEADERS
5154#endif
@@ -61,6 +64,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6164
6265static int arg_count ;
6366static char * arg_vector [256 ];
67+ FSSpec PyMac_ApplicationFSSpec ;
68+ char PyMac_ApplicationPath [256 ];
69+ static int applocation_inited ;
6470
6571/* Duplicate a string to the heap. We also export this since it isn't standard
6672** and others use it
@@ -75,20 +81,27 @@ strdup(char *src)
7581 return dst ;
7682}
7783
78- /* Return FSSpec of current application */
84+ /* Initialize FSSpec and full name of current application */
7985
8086OSErr
81- PyMac_process_location ( FSSpec * applicationSpec )
87+ PyMac_init_process_location ( )
8288{
8389 ProcessSerialNumber currentPSN ;
8490 ProcessInfoRec info ;
91+ OSErr err ;
8592
93+ if ( applocation_inited ) return 0 ;
8694 currentPSN .highLongOfPSN = 0 ;
8795 currentPSN .lowLongOfPSN = kCurrentProcess ;
8896 info .processInfoLength = sizeof (ProcessInfoRec );
8997 info .processName = NULL ;
90- info .processAppSpec = applicationSpec ;
91- return GetProcessInformation (& currentPSN , & info );
98+ info .processAppSpec = & PyMac_ApplicationFSSpec ;
99+ if ( err = GetProcessInformation (& currentPSN , & info ))
100+ return err ;
101+ if ( err = PyMac_GetFullPath (& PyMac_ApplicationFSSpec , PyMac_ApplicationPath ) )
102+ return err ;
103+ applocation_inited = 1 ;
104+ return 0 ;
92105}
93106
94107/* Given an FSSpec, return the FSSpec of the parent folder */
@@ -114,8 +127,8 @@ get_folder_parent (FSSpec * fss, FSSpec * parent)
114127
115128/* Given an FSSpec return a full, colon-separated pathname */
116129
117- static OSErr
118- get_full_path (FSSpec * fss , char * buf )
130+ OSErr
131+ PyMac_GetFullPath (FSSpec * fss , char * buf )
119132{
120133 short err ;
121134 FSSpec fss_parent , fss_current ;
@@ -146,21 +159,6 @@ get_full_path (FSSpec *fss, char *buf)
146159 return 0 ;
147160}
148161
149- /* Return the full program name */
150-
151- static char *
152- get_application_name ()
153- {
154- static char appname [256 ];
155- FSSpec appspec ;
156-
157- if (PyMac_process_location (& appspec ))
158- return NULL ;
159- if (get_full_path (& appspec , appname ))
160- return NULL ;
161- return appname ;
162- }
163-
164162/* Check that there aren't any args remaining in the event */
165163
166164static OSErr
@@ -230,7 +228,7 @@ handle_open_doc(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon)
230228 & keywd , & rttype , & fss , sizeof (fss ), & size );
231229 if (err )
232230 break ;
233- get_full_path (& fss , path );
231+ PyMac_GetFullPath (& fss , path );
234232 arg_vector [arg_count ++ ] = strdup (path );
235233 }
236234 return err ;
@@ -301,7 +299,8 @@ PyMac_GetArgv(pargv, noevents)
301299{
302300
303301 arg_count = 0 ;
304- arg_vector [arg_count ++ ] = strdup (get_application_name ());
302+ (void )PyMac_init_process_location ();
303+ arg_vector [arg_count ++ ] = strdup (PyMac_ApplicationPath );
305304
306305 if ( !noevents ) {
307306 set_ae_handlers ();
0 commit comments