diff --git a/Mac/Python/macmain.c b/Mac/Python/macmain.c index a14e3a893b8..0498be4e6d7 100644 --- a/Mac/Python/macmain.c +++ b/Mac/Python/macmain.c @@ -81,7 +81,7 @@ int console_output_state = STATE_UNKNOWN; PyMac_PrefRecord PyMac_options; -static void Py_Main(int, char **); /* Forward */ +static void Py_Main(int, char **, char *); /* Forward */ void PyMac_Exit(int); /* Forward */ static void init_appearance(void) @@ -488,17 +488,87 @@ PyMac_Initialize(void) #endif /* USE_MAC_APPLET_SUPPORT */ #if TARGET_API_MAC_OSX + +static int +locateResourcePy(char * resourceName, char * resourceURLCStr, int length) { + CFBundleRef mainBundle = NULL; + CFURLRef URL, absoluteURL; + 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) { - int i; - printf("first argc=%d\n", argc); - for(i=0; i