comparison src/main/macosx/SDLMain.m @ 168:e92aa316c517

Added Max's patches for building MacOS X apps on command line
author Sam Lantinga <slouken@libsdl.org>
date Tue, 04 Sep 2001 23:18:45 +0000
parents 4382c38dfbee
children
comparison
equal deleted inserted replaced
167:cb384ef627f6 168:e92aa316c517
10 #import <unistd.h> 10 #import <unistd.h>
11 11
12 static int gArgc; 12 static int gArgc;
13 static char **gArgv; 13 static char **gArgv;
14 static NSString *gAppName = 0; 14 static NSString *gAppName = 0;
15 static BOOL gFinderLaunch;
15 16
16 @interface NSString (ReplaceSubString) 17 @interface NSString (ReplaceSubString)
17 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; 18 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
18 @end 19 @end
19 20
27 SDL_Event event; 28 SDL_Event event;
28 event.type = SDL_QUIT; 29 event.type = SDL_QUIT;
29 SDL_PushEvent(&event); 30 SDL_PushEvent(&event);
30 } 31 }
31 32
33 /* Invoked from the Make Full-Screen menu item */
34 - (void) makeFullscreen:(id)sender
35 {
36 /* TODO */
37 }
38
32 /* Set the working directory to the .app's parent directory */ 39 /* Set the working directory to the .app's parent directory */
33 - (void) setupWorkingDirectory 40 - (void) setupWorkingDirectory:(BOOL)shouldChdir
34 { 41 {
35 char parentdir[MAXPATHLEN]; 42 char parentdir[MAXPATHLEN];
36 char *c; 43 char *c;
37 44
38 strncpy ( parentdir, gArgv[0], sizeof(parentdir) ); 45 strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
39 c = (char*) parentdir; 46 c = (char*) parentdir;
40 47
41 while (*c != '\0') /* go to end */ 48 while (*c != '\0') /* go to end */
42 c++; 49 c++;
43 50
44 while (*c != '/') /* back up to parent */ 51 while (*c != '/') /* back up to parent */
45 c--; 52 c--;
46 53
47 *c++ = '\0'; /* cut off last part (binary name) */ 54 *c++ = '\0'; /* cut off last part (binary name) */
48 55
49 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ 56 if (shouldChdir)
50 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */ 57 {
51 58 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
52 gAppName = [ NSString stringWithCString: c ]; 59 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
60 }
61 /* gAppName = [ NSString stringWithCString: c ]; */
53 } 62 }
54 63
55 /* Fix menu to contain the real app name instead of "SDL App" */ 64 /* Fix menu to contain the real app name instead of "SDL App" */
56 - (void) fixMenu:(NSMenu *)aMenu 65 - (void) fixMenu:(NSMenu *)aMenu
57 { 66 {
79 - (void) applicationDidFinishLaunching: (NSNotification *) note 88 - (void) applicationDidFinishLaunching: (NSNotification *) note
80 { 89 {
81 int status; 90 int status;
82 91
83 /* Set the working directory to the .app's parent directory */ 92 /* Set the working directory to the .app's parent directory */
84 [ self setupWorkingDirectory ]; 93 [ self setupWorkingDirectory: gFinderLaunch ];
85 94
86 /* Set the main menu to contain the real app name instead of "SDL App" */ 95 /* Set the main menu to contain the real app name instead of "SDL App" */
96 gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
87 [ self fixMenu: [ NSApp mainMenu ] ]; 97 [ self fixMenu: [ NSApp mainMenu ] ];
88 98
89 /* Hand off to main application code */ 99 /* Hand off to main application code */
90 status = SDL_main (gArgc, gArgv); 100 status = SDL_main (gArgc, gArgv);
91 101
146 int i; 156 int i;
147 157
148 /* This is passed if we are launched by double-clicking */ 158 /* This is passed if we are launched by double-clicking */
149 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { 159 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
150 gArgc = 1; 160 gArgc = 1;
161 gFinderLaunch = YES;
151 } else { 162 } else {
152 gArgc = argc; 163 gArgc = argc;
164 gFinderLaunch = NO;
153 } 165 }
154 gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1)); 166 gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
155 assert (gArgv != NULL); 167 assert (gArgv != NULL);
156 for (i = 0; i < gArgc; i++) { 168 for (i = 0; i < gArgc; i++) {
157 gArgv[i] = argv[i]; 169 gArgv[i] = argv[i];