mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Got rid of nfullpath in favor of PyMac_GetFullPath (which was pretty
much identical anyway). Initialize PyMac_ApplicationPath and PyMac_ApplicationFSSpec to point to the current application.
This commit is contained in:
		
							parent
							
								
									8096daad4f
								
							
						
					
					
						commit
						26ee1260a2
					
				
					 2 changed files with 31 additions and 36 deletions
				
			
		|  | @ -46,6 +46,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||
| #include <Dialogs.h> | #include <Dialogs.h> | ||||||
| #include <Windows.h> | #include <Windows.h> | ||||||
| 
 | 
 | ||||||
|  | #include "Python.h" | ||||||
|  | #include "macglue.h" | ||||||
|  | 
 | ||||||
| #ifdef GENERATINGCFM	/* Defined to 0 or 1 in Universal headers */ | #ifdef GENERATINGCFM	/* Defined to 0 or 1 in Universal headers */ | ||||||
| #define HAVE_UNIVERSAL_HEADERS | #define HAVE_UNIVERSAL_HEADERS | ||||||
| #endif | #endif | ||||||
|  | @ -61,6 +64,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||||
| 
 | 
 | ||||||
| static int arg_count; | static int arg_count; | ||||||
| static char *arg_vector[256]; | static char *arg_vector[256]; | ||||||
|  | FSSpec PyMac_ApplicationFSSpec; | ||||||
|  | char PyMac_ApplicationPath[256]; | ||||||
|  | static int applocation_inited; | ||||||
| 
 | 
 | ||||||
| /* Duplicate a string to the heap. We also export this since it isn't standard
 | /* Duplicate a string to the heap. We also export this since it isn't standard
 | ||||||
| ** and others use it | ** and others use it | ||||||
|  | @ -75,20 +81,27 @@ strdup(char *src) | ||||||
| 	return dst; | 	return dst; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Return FSSpec of current application */ | /* Initialize FSSpec and full name of current application */ | ||||||
| 
 | 
 | ||||||
| OSErr | OSErr | ||||||
| PyMac_process_location(FSSpec *applicationSpec) | PyMac_init_process_location() | ||||||
| { | { | ||||||
| 	ProcessSerialNumber currentPSN; | 	ProcessSerialNumber currentPSN; | ||||||
| 	ProcessInfoRec info; | 	ProcessInfoRec info; | ||||||
|  | 	OSErr err; | ||||||
| 	 | 	 | ||||||
|  | 	if ( applocation_inited ) return 0; | ||||||
| 	currentPSN.highLongOfPSN = 0; | 	currentPSN.highLongOfPSN = 0; | ||||||
| 	currentPSN.lowLongOfPSN = kCurrentProcess; | 	currentPSN.lowLongOfPSN = kCurrentProcess; | ||||||
| 	info.processInfoLength = sizeof(ProcessInfoRec); | 	info.processInfoLength = sizeof(ProcessInfoRec); | ||||||
| 	info.processName = NULL; | 	info.processName = NULL; | ||||||
| 	info.processAppSpec = applicationSpec; | 	info.processAppSpec = &PyMac_ApplicationFSSpec; | ||||||
| 	return GetProcessInformation(¤tPSN, &info); | 	if ( err=GetProcessInformation(¤tPSN, &info)) | ||||||
|  | 		return err; | ||||||
|  | 	if ( err=PyMac_GetFullPath(&PyMac_ApplicationFSSpec, PyMac_ApplicationPath) ) | ||||||
|  | 		return err; | ||||||
|  | 	applocation_inited = 1; | ||||||
|  | 	return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Given an FSSpec, return the FSSpec of the parent folder */ | /* Given an FSSpec, return the FSSpec of the parent folder */ | ||||||
|  | @ -114,8 +127,8 @@ get_folder_parent (FSSpec * fss, FSSpec * parent) | ||||||
| 
 | 
 | ||||||
| /* Given an FSSpec return a full, colon-separated pathname */ | /* Given an FSSpec return a full, colon-separated pathname */ | ||||||
| 
 | 
 | ||||||
| static OSErr | OSErr | ||||||
| get_full_path (FSSpec *fss, char *buf) | PyMac_GetFullPath (FSSpec *fss, char *buf) | ||||||
| { | { | ||||||
| 	short err; | 	short err; | ||||||
| 	FSSpec fss_parent, fss_current; | 	FSSpec fss_parent, fss_current; | ||||||
|  | @ -146,21 +159,6 @@ get_full_path (FSSpec *fss, char *buf) | ||||||
|         return 0; |         return 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Return the full program name */ |  | ||||||
| 
 |  | ||||||
| static char * |  | ||||||
| get_application_name() |  | ||||||
| { |  | ||||||
| 	static char appname[256]; |  | ||||||
| 	FSSpec appspec; |  | ||||||
| 	 |  | ||||||
| 	if (PyMac_process_location(&appspec)) |  | ||||||
| 		return NULL; |  | ||||||
| 	if (get_full_path(&appspec, appname)) |  | ||||||
| 		return NULL; |  | ||||||
| 	return appname; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /* Check that there aren't any args remaining in the event */ | /* Check that there aren't any args remaining in the event */ | ||||||
| 
 | 
 | ||||||
| static OSErr  | static OSErr  | ||||||
|  | @ -230,7 +228,7 @@ handle_open_doc(AppleEvent *theAppleEvent, AppleEvent *reply, long refCon) | ||||||
| 				  &keywd, &rttype, &fss, sizeof(fss), &size); | 				  &keywd, &rttype, &fss, sizeof(fss), &size); | ||||||
| 		if (err) | 		if (err) | ||||||
| 			break; | 			break; | ||||||
| 		get_full_path(&fss, path); | 		PyMac_GetFullPath(&fss, path); | ||||||
| 		arg_vector[arg_count++] = strdup(path); | 		arg_vector[arg_count++] = strdup(path); | ||||||
| 	} | 	} | ||||||
| 	return err; | 	return err; | ||||||
|  | @ -301,7 +299,8 @@ PyMac_GetArgv(pargv, noevents) | ||||||
| { | { | ||||||
| 	 | 	 | ||||||
| 	arg_count = 0; | 	arg_count = 0; | ||||||
| 	arg_vector[arg_count++] = strdup(get_application_name()); | 	(void)PyMac_init_process_location(); | ||||||
|  | 	arg_vector[arg_count++] = strdup(PyMac_ApplicationPath); | ||||||
| 	 | 	 | ||||||
| 	if( !noevents ) { | 	if( !noevents ) { | ||||||
| 		set_ae_handlers(); | 		set_ae_handlers(); | ||||||
|  |  | ||||||
|  | @ -147,10 +147,11 @@ PyMac_OpenPrefFile() | ||||||
| 			printf("Cannot create preferences file, error %d\n", ResError()); | 			printf("Cannot create preferences file, error %d\n", ResError()); | ||||||
| 			exit(1); | 			exit(1); | ||||||
| 		} | 		} | ||||||
| 		if ( (err=PyMac_process_location(&dirspec)) != 0 ) { | 		if ( (err=PyMac_init_process_location()) != 0 ) { | ||||||
| 			printf("Cannot get FSSpec for application, error %d\n", err); | 			printf("Cannot get application location, error %d\n", err); | ||||||
| 			exit(1); | 			exit(1); | ||||||
| 		} | 		} | ||||||
|  | 		dirspec = PyMac_ApplicationFSSpec; | ||||||
| 		dirspec.name[0] = 0; | 		dirspec.name[0] = 0; | ||||||
| 		if ((err=NewAlias(NULL, &dirspec, &handle)) != 0 ) { | 		if ((err=NewAlias(NULL, &dirspec, &handle)) != 0 ) { | ||||||
| 			printf("Cannot make alias to application directory, error %d\n", err); | 			printf("Cannot make alias to application directory, error %d\n", err); | ||||||
|  | @ -212,7 +213,7 @@ PyMac_GetPythonDir() | ||||||
|     if ( prefrh != -1 ) CloseResFile(prefrh); |     if ( prefrh != -1 ) CloseResFile(prefrh); | ||||||
|     UseResFile(oldrh); |     UseResFile(oldrh); | ||||||
| 
 | 
 | ||||||
|    	if ( nfullpath(&dirspec, name) == 0 ) { |    	if ( PyMac_GetFullPath(&dirspec, name) == 0 ) { | ||||||
|    		strcat(name, ":"); |    		strcat(name, ":"); | ||||||
|     } else { |     } else { | ||||||
|  		/* If all fails, we return the current directory */ |  		/* If all fails, we return the current directory */ | ||||||
|  | @ -228,7 +229,6 @@ PyMac_GetPythonDir() | ||||||
| static char * | static char * | ||||||
| PyMac_GetPythonPath() | PyMac_GetPythonPath() | ||||||
| { | { | ||||||
|     FSSpec dirspec; |  | ||||||
|     short oldrh, prefrh = -1; |     short oldrh, prefrh = -1; | ||||||
|     char *rv; |     char *rv; | ||||||
|     int i, newlen; |     int i, newlen; | ||||||
|  | @ -289,20 +289,16 @@ PyMac_GetPythonPath() | ||||||
|     		rv[newlen-1] = 0; |     		rv[newlen-1] = 0; | ||||||
|     	} else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) { |     	} else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) { | ||||||
|     		/* This is the application itself */ |     		/* This is the application itself */ | ||||||
| 			char fullname[256]; |  | ||||||
| 			 | 			 | ||||||
|     		if ( (err=PyMac_process_location(&dirspec)) != 0 ) { |     		if ( (err=PyMac_init_process_location()) != 0 ) { | ||||||
| 				printf("Cannot get FSSpec for application, error %d\n", err); | 				printf("Cannot get  application location, error %d\n", err); | ||||||
| 				exit(1); | 				exit(1); | ||||||
| 			} | 			} | ||||||
| 			if ( nfullpath(&dirspec, fullname) != 0 ) { | 
 | ||||||
| 				printf("Cannot convert application fsspec to path\n"); | 			newlen = strlen(rv) + strlen(PyMac_ApplicationPath) + 2; | ||||||
| 				exit(1); |  | ||||||
| 			} |  | ||||||
| 			newlen = strlen(rv) + strlen(fullname) + 2; |  | ||||||
|     		if( (rv=realloc(rv, newlen)) == NULL) |     		if( (rv=realloc(rv, newlen)) == NULL) | ||||||
|     			goto out; |     			goto out; | ||||||
|     		strcpy(rv+strlen(rv), fullname); |     		strcpy(rv+strlen(rv), PyMac_ApplicationPath); | ||||||
|     		rv[newlen-2] = '\n'; |     		rv[newlen-2] = '\n'; | ||||||
|     		rv[newlen-1] = 0; |     		rv[newlen-1] = 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Jansen
						Jack Jansen