[Python-checkins] CVS: python/dist/src/Mac/Python macmain.c,1.70,1.71

Jack Jansen jackjansen@users.sourceforge.net
Tue, 30 Oct 2001 14:48:39 -0800


Update of /cvsroot/python/python/dist/src/Mac/Python
In directory usw-pr-cvs1:/tmp/cvs-serv31168/Python/Mac/Python

Modified Files:
	macmain.c 
Log Message:
Mod by Donovan Preston to allow MacPython to live in a Python.app bundle and understand the __main__.py convention used there for applets. This gives us applets that work on both OS9 and OSX! (Although "applet" may not be the correct word for something that is going to be multimegabyte:-).

But: the code is currently disabled, as it requires CodeWarrior 7 and I'm still using 6.

Index: macmain.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Python/macmain.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** macmain.c	2001/09/11 13:08:10	1.70
--- macmain.c	2001/10/30 22:48:36	1.71
***************
*** 39,42 ****
--- 39,49 ----
  #include <Fonts.h>
  #include <Balloons.h>
+ #if TARGET_API_MAC_CARBON
+ #include <CFBundle.h>
+ #include <CFURL.h>
+ #include <CFString.h>
+ #include <CFBase.h>
+ #include <CFArray.h>
+ #endif /* TARGET_API_MAC_CARBON */
  #ifdef USE_APPEARANCE
  #include <Gestalt.h>
***************
*** 488,492 ****
  #endif /* USE_MAC_APPLET_SUPPORT */
  
! #if TARGET_API_MAC_OSX
  
  static int
--- 495,499 ----
  #endif /* USE_MAC_APPLET_SUPPORT */
  
! #if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
  
  static int
***************
*** 496,538 ****
      CFStringRef filenameString, filepathString, rsrcString;
      CFIndex size, i;
!     CFArrayRef arrayRef;
!     Boolean success = 0;
! 
!     /* Create a CFString with the resource name in it */
!     rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
  
      /* Get a reference to our main bundle */
      mainBundle = CFBundleGetMainBundle();
  
!     /* Look for py files in the main bundle by type */
!     arrayRef = CFBundleCopyResourceURLsOfType( mainBundle, 
!             CFSTR("py"), 
!            NULL );
  
!     /* See if there are any filename matches */
!     size = CFArrayGetCount(arrayRef);
!     for (i = 0; i < size; i++) {
!         URL = CFArrayGetValueAtIndex(arrayRef, i);
!         filenameString = CFURLCopyLastPathComponent(URL);
!         if (CFStringCompare(filenameString, rsrcString, 0) == kCFCompareEqualTo) {
!             /* We found a match, get the file's full path */
!             absoluteURL = CFURLCopyAbsoluteURL(URL);
!             filepathString = CFURLCopyFileSystemPath(absoluteURL, kCFURLPOSIXPathStyle);
!             CFRelease(absoluteURL);
  
!             /* Copy the full path into the caller's character buffer */
!             success = CFStringGetCString(filepathString, resourceURLCStr, length,
!                                         kCFStringEncodingMacRoman);
  
!             CFRelease(filepathString);
!         }
!         CFRelease(filenameString);
!     }
!     CFRelease(rsrcString);
!     CFRelease(arrayRef);
  
      return success;
  }
  
  int
  main(int argc, char **argv)
--- 503,557 ----
      CFStringRef filenameString, filepathString, rsrcString;
      CFIndex size, i;
!     CFArrayRef arrayRef = NULL;
!     int success = 0;
!     
! #if TARGET_API_MAC_OSX
! 	CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
! #else
! 	CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
! #endif
  
      /* Get a reference to our main bundle */
      mainBundle = CFBundleGetMainBundle();
  
! 	/* If we are running inside a bundle, look through it. Otherwise, do nothing. */
! 	if (mainBundle) {
! 	    /* Create a CFString with the resource name in it */
! 	    rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
  
! 	    /* Look for py files in the main bundle by type */
! 	    arrayRef = CFBundleCopyResourceURLsOfType( mainBundle, 
! 	            CFSTR("py"), 
! 	           NULL );
  
! 	    /* See if there are any filename matches */
! 	    size = CFArrayGetCount(arrayRef);
! 	    for (i = 0; i < size; i++) {
! 	        URL = CFArrayGetValueAtIndex(arrayRef, i);
! 	        filenameString = CFURLCopyLastPathComponent(URL);
! 	        if (CFStringCompare(filenameString, rsrcString, 0) == kCFCompareEqualTo) {
! 	            /* We found a match, get the file's full path */
! 	            absoluteURL = CFURLCopyAbsoluteURL(URL);
! 	            filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle);
! 	            CFRelease(absoluteURL);
  
! 	            /* Copy the full path into the caller's character buffer */
! 	            success = CFStringGetCString(filepathString, resourceURLCStr, length,
! 	                                        kCFStringEncodingMacRoman);
  
+ 	            CFRelease(filepathString);
+ 	        }
+ 	        CFRelease(filenameString);
+ 	    }
+ 		CFRelease(arrayRef);
+ 	    CFRelease(rsrcString);
+ 	}
      return success;
  }
  
+ #endif /* TARGET_API_MAC_CARBON */
+ 
+ #if TARGET_API_MAC_OSX
+ 
  int
  main(int argc, char **argv)
***************
*** 581,585 ****
--- 600,613 ----
  	char **argv;
  	
+ 	static char scriptpath[1024];
+ 	char *script = NULL;
+ 
  	init_common(&argc, &argv, 0);
+ 
+ #if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
+ 	/* If we are running inside of a bundle, and a __main__.py is available, use it */
+ 	if (locateResourcePy("__main__.py", scriptpath, 1024))
+ 		script = scriptpath;
+ #endif
  	
  	if ( argc > 1 ) {
***************
*** 604,608 ****
  		}
  	}
! 	Py_Main(argc, argv, NULL);
  }
  #endif /* TARGET_API_MAC_OSX */
--- 632,636 ----
  		}
  	}
! 	Py_Main(argc, argv, script);
  }
  #endif /* TARGET_API_MAC_OSX */