annotate src/main/macosx/SDLMain.m @ 211:0cc95f442f3a

If we're looking at the /dev/input event devices, and we found at least one, then we don't want to look at the input joystick devices, since they're built on top of devices that we've already seen, so we're done.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 22 Oct 2001 21:34:50 +0000
parents ba9e0fcc2ae2
children 50620ec9c86a
rev   line source
194
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* SDLMain.m - main entry point for our Cocoa-ized SDL app
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 Darrell Walisser - dwaliss1@purdue.edu
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 Feel free to customize this file to suit your needs
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 #import "SDL.h"
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 #import "SDLMain.h"
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 #import <sys/param.h> /* for MAXPATHLEN */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #import <unistd.h>
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 static int gArgc;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 static char **gArgv;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 static NSString *gAppName = 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 static BOOL gFinderLaunch;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 @interface NSString (ReplaceSubString)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 @end
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 /* The main class of the application, the application's delegate */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 @implementation SDLMain
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 /* Invoked from the Quit menu item */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 - (void) quit:(id)sender
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 SDL_Event event;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 event.type = SDL_QUIT;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 SDL_PushEvent(&event);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 /* Invoked from the Make Full-Screen menu item */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 - (void) makeFullscreen:(id)sender
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 /* TODO */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 /* Set the working directory to the .app's parent directory */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 - (void) setupWorkingDirectory:(BOOL)shouldChdir
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 char parentdir[MAXPATHLEN];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 char *c;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 c = (char*) parentdir;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 while (*c != '\0') /* go to end */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 c++;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 while (*c != '/') /* back up to parent */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 c--;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 *c++ = '\0'; /* cut off last part (binary name) */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 if (shouldChdir)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 /* gAppName = [ NSString stringWithCString: c ]; */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 /* Fix menu to contain the real app name instead of "SDL App" */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 - (void) fixMenu:(NSMenu *)aMenu
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 NSRange aRange;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 NSEnumerator *enumerator;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 NSMenuItem *menuItem;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 aRange = [[aMenu title] rangeOfString:@"SDL App"];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 if (aRange.length != 0)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:gAppName]];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 enumerator = [[aMenu itemArray] objectEnumerator];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 while ((menuItem = [enumerator nextObject]))
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 aRange = [[menuItem title] rangeOfString:@"SDL App"];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 if (aRange.length != 0)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:gAppName]];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 if ([menuItem hasSubmenu])
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 [self fixMenu: [menuItem submenu]];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 [ aMenu sizeToFit ];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 /* Called when the internal event loop has just started running */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 - (void) applicationDidFinishLaunching: (NSNotification *) note
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 int status;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 /* Set the working directory to the .app's parent directory */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 [ self setupWorkingDirectory: gFinderLaunch ];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 /* Set the main menu to contain the real app name instead of "SDL App" */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 [ self fixMenu: [ NSApp mainMenu ] ];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 /* Hand off to main application code */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 status = SDL_main (gArgc, gArgv);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 /* We're done, thank you for playing */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 exit(status);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 @end
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 @implementation NSString (ReplaceSubString)
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 unsigned int bufferSize;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 unsigned int selfLen = [self length];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 unsigned int aStringLen = [aString length];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 unichar *buffer;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 NSRange localRange;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 NSString *result;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 bufferSize = selfLen + aStringLen - aRange.length;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 // Get first part into buffer
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 localRange.location = 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 localRange.length = aRange.location;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 [self getCharacters:buffer range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 // Get middle part into buffer
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 localRange.location = 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 localRange.length = aStringLen;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 [aString getCharacters:(buffer+aRange.location) range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 // Get last part into buffer
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 localRange.location = aRange.location + aRange.length;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 localRange.length = selfLen - localRange.location;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 // Build output string
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 result = [NSString stringWithCharacters:buffer length:bufferSize];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 NSDeallocateMemoryPages(buffer, bufferSize);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 return result;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 @end
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 #ifdef main
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 # undef main
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 #endif
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 /* Main entry point to executible - should *not* be SDL_main! */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 int main (int argc, char **argv) {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 /* Copy the arguments into a global variable */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 int i;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 /* This is passed if we are launched by double-clicking */
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 gArgc = 1;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 gFinderLaunch = YES;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 } else {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 gArgc = argc;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 gFinderLaunch = NO;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 assert (gArgv != NULL);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 for (i = 0; i < gArgc; i++) {
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 gArgv[i] = argv[i];
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 }
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 gArgv[i] = NULL;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 NSApplicationMain (argc, argv);
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 return 0;
ba9e0fcc2ae2 Oops, back out that SDL_main -> SDLMain conversion
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }