mirror of
https://github.com/python/cpython.git
synced 2025-11-17 17:46:45 +00:00
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.
This commit is contained in:
parent
e4df3fd90d
commit
5ded1bf5c7
1 changed files with 58 additions and 30 deletions
|
|
@ -38,6 +38,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Fonts.h>
|
#include <Fonts.h>
|
||||||
#include <Balloons.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
|
#ifdef USE_APPEARANCE
|
||||||
#include <Gestalt.h>
|
#include <Gestalt.h>
|
||||||
#include <Appearance.h>
|
#include <Appearance.h>
|
||||||
|
|
@ -487,7 +494,7 @@ PyMac_Initialize(void)
|
||||||
|
|
||||||
#endif /* USE_MAC_APPLET_SUPPORT */
|
#endif /* USE_MAC_APPLET_SUPPORT */
|
||||||
|
|
||||||
#if TARGET_API_MAC_OSX
|
#if TARGET_API_MAC_OSX /* Really: TARGET_API_MAC_CARBON */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
|
locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
|
||||||
|
|
@ -495,45 +502,57 @@ locateResourcePy(char * resourceName, char * resourceURLCStr, int length) {
|
||||||
CFURLRef URL, absoluteURL;
|
CFURLRef URL, absoluteURL;
|
||||||
CFStringRef filenameString, filepathString, rsrcString;
|
CFStringRef filenameString, filepathString, rsrcString;
|
||||||
CFIndex size, i;
|
CFIndex size, i;
|
||||||
CFArrayRef arrayRef;
|
CFArrayRef arrayRef = NULL;
|
||||||
Boolean success = 0;
|
int success = 0;
|
||||||
|
|
||||||
/* Create a CFString with the resource name in it */
|
#if TARGET_API_MAC_OSX
|
||||||
rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
|
CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle;
|
||||||
|
#else
|
||||||
|
CFURLPathStyle thePathStyle = kCFURLHFSPathStyle;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Get a reference to our main bundle */
|
/* Get a reference to our main bundle */
|
||||||
mainBundle = CFBundleGetMainBundle();
|
mainBundle = CFBundleGetMainBundle();
|
||||||
|
|
||||||
/* Look for py files in the main bundle by type */
|
/* If we are running inside a bundle, look through it. Otherwise, do nothing. */
|
||||||
arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
|
if (mainBundle) {
|
||||||
CFSTR("py"),
|
/* Create a CFString with the resource name in it */
|
||||||
NULL );
|
rsrcString = CFStringCreateWithCString(0, resourceName, kCFStringEncodingMacRoman);
|
||||||
|
|
||||||
/* See if there are any filename matches */
|
/* Look for py files in the main bundle by type */
|
||||||
size = CFArrayGetCount(arrayRef);
|
arrayRef = CFBundleCopyResourceURLsOfType( mainBundle,
|
||||||
for (i = 0; i < size; i++) {
|
CFSTR("py"),
|
||||||
URL = CFArrayGetValueAtIndex(arrayRef, i);
|
NULL );
|
||||||
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 */
|
/* See if there are any filename matches */
|
||||||
success = CFStringGetCString(filepathString, resourceURLCStr, length,
|
size = CFArrayGetCount(arrayRef);
|
||||||
kCFStringEncodingMacRoman);
|
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);
|
||||||
|
|
||||||
CFRelease(filepathString);
|
/* Copy the full path into the caller's character buffer */
|
||||||
}
|
success = CFStringGetCString(filepathString, resourceURLCStr, length,
|
||||||
CFRelease(filenameString);
|
kCFStringEncodingMacRoman);
|
||||||
}
|
|
||||||
CFRelease(rsrcString);
|
|
||||||
CFRelease(arrayRef);
|
|
||||||
|
|
||||||
|
CFRelease(filepathString);
|
||||||
|
}
|
||||||
|
CFRelease(filenameString);
|
||||||
|
}
|
||||||
|
CFRelease(arrayRef);
|
||||||
|
CFRelease(rsrcString);
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* TARGET_API_MAC_CARBON */
|
||||||
|
|
||||||
|
#if TARGET_API_MAC_OSX
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -580,8 +599,17 @@ PyMac_InitApplication(void)
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
|
||||||
|
static char scriptpath[1024];
|
||||||
|
char *script = NULL;
|
||||||
|
|
||||||
init_common(&argc, &argv, 0);
|
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 ) {
|
if ( argc > 1 ) {
|
||||||
/* We're running a script. Attempt to change current directory */
|
/* We're running a script. Attempt to change current directory */
|
||||||
char curwd[256], *endp;
|
char curwd[256], *endp;
|
||||||
|
|
@ -603,7 +631,7 @@ PyMac_InitApplication(void)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Py_Main(argc, argv, NULL);
|
Py_Main(argc, argv, script);
|
||||||
}
|
}
|
||||||
#endif /* TARGET_API_MAC_OSX */
|
#endif /* TARGET_API_MAC_OSX */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue