Max 5 API Reference
00001 /* 00002 jit.cpost.c 00003 00004 Copyright 2003 - Cycling '74 00005 Jeremy Bernstein jeremy@bootsquad.com 00006 00007 */ 00008 00009 #include "jit.common.h" 00010 #include "ext_strings.h" 00011 #include "jit.cpost.h" 00012 #include "MoreSetup.h" 00013 00014 #if TARGET_API_MAC_CARBON 00015 void jit_cpost_console_init(void); 00016 00017 #if TARGET_RT_MAC_MACHO 00018 00019 #define cpost printf 00020 00021 #else 00022 00023 static CFBundleRef SystemBundle; 00024 typedef void (*printfPtr)(const char *, ...); 00025 printfPtr cpost; 00026 OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr); 00027 00028 #endif 00029 00030 void jit_cpost_console_init(void) 00031 { 00032 #if !TARGET_RT_MAC_MACHO 00033 OSStatus err; 00034 00035 err = LoadFrameworkBundle(CFSTR("System.framework"), &SystemBundle); 00036 if (err == noErr) { 00037 cpost = (printfPtr)CFBundleGetFunctionPointerForName(SystemBundle, CFSTR("printf")); 00038 } 00039 #endif 00040 } 00041 #endif 00042 00043 void jit_cpost(const char *format, ...) 00044 { 00045 #if TARGET_API_MAC_CARBON 00046 char msg[1024]; 00047 00048 strcpy(msg, format); 00049 strcat(msg, "\n"); 00050 cpost(msg, *((t_stack_splat *)(((char *)(&format))+4))); 00051 #endif 00052 } 00053 00054 #if TARGET_API_MAC_CARBON 00055 OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr) 00056 // This routine finds a the named framework and creates a CFBundle 00057 // object for it. It looks for the framework in the frameworks folder, 00058 // as defined by the Folder Manager. Currently this is 00059 // "/System/Library/Frameworks", but we recommend that you avoid hard coded 00060 // paths to ensure future compatibility. 00061 // 00062 // You might think that you could use CFBundleGetBundleWithIdentifier but 00063 // that only finds bundles that are already loaded into your context. 00064 // That would work in the case of the System framework but it wouldn't 00065 // work if you're using some other, less-obvious, framework. 00066 { 00067 OSStatus err; 00068 FSRef frameworksFolderRef; 00069 CFURLRef baseURL; 00070 CFURLRef bundleURL; 00071 00072 MoreAssertQ(bundlePtr != nil); 00073 00074 *bundlePtr = nil; 00075 00076 baseURL = nil; 00077 bundleURL = nil; 00078 00079 // Find the frameworks folder and create a URL for it. 00080 00081 err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef); 00082 if (err == noErr) { 00083 baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef); 00084 if (baseURL == nil) { 00085 err = coreFoundationUnknownErr; 00086 } 00087 } 00088 00089 // Append the name of the framework to the URL. 00090 00091 if (err == noErr) { 00092 bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false); 00093 if (bundleURL == nil) { 00094 err = coreFoundationUnknownErr; 00095 } 00096 } 00097 00098 // Create a bundle based on that URL and load the bundle into memory. 00099 // We never unload the bundle, which is reasonable in this case because 00100 // the sample assumes that you'll be calling functions from this 00101 // framework throughout the life of your application. 00102 00103 if (err == noErr) { 00104 *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL); 00105 if (*bundlePtr == nil) { 00106 err = coreFoundationUnknownErr; 00107 } 00108 } 00109 if (err == noErr) { 00110 if ( ! CFBundleLoadExecutable( *bundlePtr ) ) { 00111 err = coreFoundationUnknownErr; 00112 } 00113 } 00114 00115 // Clean up. 00116 00117 if (err != noErr && *bundlePtr != nil) { 00118 CFRelease(*bundlePtr); 00119 *bundlePtr = nil; 00120 } 00121 if (bundleURL != nil) { 00122 CFRelease(bundleURL); 00123 } 00124 if (baseURL != nil) { 00125 CFRelease(baseURL); 00126 } 00127 00128 return err; 00129 } 00130 #endif
Copyright © 2008, Cycling '74