comparison src/main/macosx/SDLMain.m @ 4145:f00b6b19d57e SDL-1.2

Date: Sat, 5 Apr 2008 19:54:28 -0700 From: "Chris Peterson" To: sdl@lists.libsdl.org Subject: [SDL] [PATCH] SDLMain.m: fix a bug and some warnings for Mac OS X Here are some small fixes for the src/main/macosx/SDLMain.m source file used by Mac OS X apps: 1. setupWorkingDirectory() called chdir() within an assert(), which gets compiled out in non-debug builds. 2. When some of gcc's optional warnings are enabled, it complains about some implicit casts and the use of #import in SDLMain.m.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 13 Apr 2008 04:50:17 +0000
parents 41ab83bec62f
children 1496aa09e41e
comparison
equal deleted inserted replaced
4144:904defc0792e 4145:f00b6b19d57e
3 Non-NIB-Code & other changes: Max Horn <max@quendi.de> 3 Non-NIB-Code & other changes: Max Horn <max@quendi.de>
4 4
5 Feel free to customize this file to suit your needs 5 Feel free to customize this file to suit your needs
6 */ 6 */
7 7
8 #import "SDL.h" 8 #include "SDL.h"
9 #import "SDLMain.h" 9 #include "SDLMain.h"
10 #import <sys/param.h> /* for MAXPATHLEN */ 10 #include <sys/param.h> /* for MAXPATHLEN */
11 #import <unistd.h> 11 #include <unistd.h>
12 12
13 /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, 13 /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
14 but the method still is there and works. To avoid warnings, we declare 14 but the method still is there and works. To avoid warnings, we declare
15 it ourselves here. */ 15 it ourselves here. */
16 @interface NSApplication(SDL_Missing_Methods) 16 @interface NSApplication(SDL_Missing_Methods)
41 static BOOL gFinderLaunch; 41 static BOOL gFinderLaunch;
42 static BOOL gCalledAppMainline = FALSE; 42 static BOOL gCalledAppMainline = FALSE;
43 43
44 static NSString *getApplicationName(void) 44 static NSString *getApplicationName(void)
45 { 45 {
46 NSDictionary *dict; 46 const NSDictionary *dict;
47 NSString *appName = 0; 47 NSString *appName = 0;
48 48
49 /* Determine the application name */ 49 /* Determine the application name */
50 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); 50 dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
51 if (dict) 51 if (dict)
52 appName = [dict objectForKey: @"CFBundleName"]; 52 appName = [dict objectForKey: @"CFBundleName"];
53 53
54 if (![appName length]) 54 if (![appName length])
55 appName = [[NSProcessInfo processInfo] processName]; 55 appName = [[NSProcessInfo processInfo] processName];
85 - (void) setupWorkingDirectory:(BOOL)shouldChdir 85 - (void) setupWorkingDirectory:(BOOL)shouldChdir
86 { 86 {
87 if (shouldChdir) 87 if (shouldChdir)
88 { 88 {
89 char parentdir[MAXPATHLEN]; 89 char parentdir[MAXPATHLEN];
90 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); 90 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
91 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); 91 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
92 if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { 92 if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
93 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ 93 chdir(parentdir); /* chdir to the binary app's parent */
94 } 94 }
95 CFRelease(url); 95 CFRelease(url);
96 CFRelease(url2); 96 CFRelease(url2);
97 } 97 }
98
99 } 98 }
100 99
101 #if SDL_USE_NIB_FILE 100 #if SDL_USE_NIB_FILE
102 101
103 /* Fix menu to contain the real app name instead of "SDL App" */ 102 /* Fix menu to contain the real app name instead of "SDL App" */
317 unichar *buffer; 316 unichar *buffer;
318 NSRange localRange; 317 NSRange localRange;
319 NSString *result; 318 NSString *result;
320 319
321 bufferSize = selfLen + aStringLen - aRange.length; 320 bufferSize = selfLen + aStringLen - aRange.length;
322 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); 321 buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
323 322
324 /* Get first part into buffer */ 323 /* Get first part into buffer */
325 localRange.location = 0; 324 localRange.location = 0;
326 localRange.length = aRange.location; 325 localRange.length = aRange.location;
327 [self getCharacters:buffer range:localRange]; 326 [self getCharacters:buffer range:localRange];