Mercurial > sdl-ios-xcode
comparison src/main/macosx/SDLMain.m @ 1664:cd3db072ba8a SDL-1.3
more indent cleanup
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 18:16:36 +0000 |
parents | 11775724e3fe |
children |
comparison
equal
deleted
inserted
replaced
1663:11775724e3fe | 1664:cd3db072ba8a |
---|---|
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 #import "SDL.h" |
9 #import "SDLMain.h" | 9 #import "SDLMain.h" |
10 #import <sys/param.h> /* for MAXPATHLEN */ | 10 #import <sys/param.h> /* for MAXPATHLEN */ |
11 #import <unistd.h> | 11 #import <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) - (void) setAppleMenu:(NSMenu | 16 @interface NSApplication(SDL_Missing_Methods) |
17 *) | 17 - (void)setAppleMenu:(NSMenu *)menu; |
18 menu; | 18 @end |
19 @end | 19 |
20 /* Use this flag to determine whether we use SDLMain.nib or not */ | 20 /* Use this flag to determine whether we use SDLMain.nib or not */ |
21 #define SDL_USE_NIB_FILE 0 | 21 #define SDL_USE_NIB_FILE 0 |
22 | |
22 /* Use this flag to determine whether we use CPS (docking) or not */ | 23 /* Use this flag to determine whether we use CPS (docking) or not */ |
23 #define SDL_USE_CPS 1 | 24 #define SDL_USE_CPS 1 |
24 #ifdef SDL_USE_CPS | 25 #ifdef SDL_USE_CPS |
25 /* Portions of CPS.h */ | 26 /* Portions of CPS.h */ |
26 typedef struct CPSProcessSerNum | 27 typedef struct CPSProcessSerNum |
27 { | 28 { |
28 UInt32 | 29 UInt32 lo; |
29 lo; | 30 UInt32 hi; |
30 UInt32 | 31 } CPSProcessSerNum; |
31 hi; | 32 |
32 } CPSProcessSerNum; | 33 extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); |
33 | 34 extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); |
34 extern | 35 extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); |
35 OSErr | |
36 CPSGetCurrentProcess (CPSProcessSerNum * psn); | |
37 extern | |
38 OSErr | |
39 CPSEnableForegroundOperation (CPSProcessSerNum * psn, UInt32 _arg2, | |
40 UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); | |
41 extern | |
42 OSErr | |
43 CPSSetFrontProcess (CPSProcessSerNum * psn); | |
44 | 36 |
45 #endif /* SDL_USE_CPS */ | 37 #endif /* SDL_USE_CPS */ |
46 | 38 |
47 static int | 39 static int gArgc; |
48 gArgc; | 40 static char **gArgv; |
49 static char ** | 41 static BOOL gFinderLaunch; |
50 gArgv; | 42 static BOOL gCalledAppMainline = FALSE; |
51 static | 43 |
52 BOOL | 44 static NSString *getApplicationName(void) |
53 gFinderLaunch; | |
54 static | |
55 BOOL | |
56 gCalledAppMainline = FALSE; | |
57 | |
58 static NSString * | |
59 getApplicationName (void) | |
60 { | 45 { |
61 NSDictionary *dict; | 46 NSDictionary *dict; |
62 NSString *appName = 0; | 47 NSString *appName = 0; |
63 | 48 |
64 /* Determine the application name */ | 49 /* Determine the application name */ |
65 dict = | 50 dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); |
66 (NSDictionary *) CFBundleGetInfoDictionary (CFBundleGetMainBundle ()); | |
67 if (dict) | 51 if (dict) |
68 appName =[dict objectForKey:@"CFBundleName"]; | 52 appName = [dict objectForKey: @"CFBundleName"]; |
69 | 53 |
70 if (![appName length]) | 54 if (![appName length]) |
71 appName =[[NSProcessInfo processInfo] processName]; | 55 appName = [[NSProcessInfo processInfo] processName]; |
72 | 56 |
73 return appName; | 57 return appName; |
74 } | 58 } |
75 | 59 |
76 #if SDL_USE_NIB_FILE | 60 #if SDL_USE_NIB_FILE |
77 /* A helper category for NSString */ | 61 /* A helper category for NSString */ |
78 @interface NSString (ReplaceSubString) - (NSString *) stringByReplacingRange:(NSRange) | 62 @interface NSString (ReplaceSubString) |
79 aRange | 63 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString; |
80 with:(NSString *) | 64 @end |
81 aString; | 65 #endif |
82 @end | 66 |
83 #endif | 67 @interface SDLApplication : NSApplication |
84 @ interface SDLApplication:NSApplication | 68 @end |
85 @ end @ implementation SDLApplication | 69 |
70 @implementation SDLApplication | |
86 /* Invoked from the Quit menu item */ | 71 /* Invoked from the Quit menu item */ |
87 - (void) terminate:(id) sender | 72 - (void)terminate:(id)sender |
88 { | 73 { |
89 /* Post a SDL_QUIT event */ | 74 /* Post a SDL_QUIT event */ |
90 SDL_Event event; | 75 SDL_Event event; |
91 event.type = SDL_QUIT; | 76 event.type = SDL_QUIT; |
92 SDL_PushEvent (&event); | 77 SDL_PushEvent(&event); |
93 } | 78 } |
94 | 79 @end |
95 @end | 80 |
96 /* The main class of the application, the application's delegate */ | 81 /* The main class of the application, the application's delegate */ |
97 @ implementation SDLMain | 82 @implementation SDLMain |
83 | |
98 /* Set the working directory to the .app's parent directory */ | 84 /* Set the working directory to the .app's parent directory */ |
99 - (void) setupWorkingDirectory:(BOOL) shouldChdir { | 85 - (void) setupWorkingDirectory:(BOOL)shouldChdir |
100 if (shouldChdir) { | 86 { |
87 if (shouldChdir) | |
88 { | |
101 char parentdir[MAXPATHLEN]; | 89 char parentdir[MAXPATHLEN]; |
102 CFURLRef url = CFBundleCopyBundleURL (CFBundleGetMainBundle ()); | 90 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); |
103 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent (0, url); | 91 CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); |
104 if (CFURLGetFileSystemRepresentation | 92 if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { |
105 (url2, true, (UInt8 *) parentdir, MAXPATHLEN)) { | 93 assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ |
106 assert (chdir (parentdir) == 0); /* chdir to the binary app's parent */ | 94 } |
107 } | 95 CFRelease(url); |
108 CFRelease (url); | 96 CFRelease(url2); |
109 CFRelease (url2); | 97 } |
110 } | |
111 | 98 |
112 } | 99 } |
113 | 100 |
114 #if SDL_USE_NIB_FILE | 101 #if SDL_USE_NIB_FILE |
115 | 102 |
116 /* Fix menu to contain the real app name instead of "SDL App" */ | 103 /* Fix menu to contain the real app name instead of "SDL App" */ |
117 -(void) fixMenu:(NSMenu *) | 104 - (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName |
118 aMenu | |
119 withAppName:(NSString *) | |
120 appName | |
121 { | 105 { |
122 NSRange aRange; | 106 NSRange aRange; |
123 NSEnumerator *enumerator; | 107 NSEnumerator *enumerator; |
124 NSMenuItem *menuItem; | 108 NSMenuItem *menuItem; |
125 | 109 |
126 aRange =[[aMenu title] rangeOfString:@"SDL App"]; | 110 aRange = [[aMenu title] rangeOfString:@"SDL App"]; |
127 if (aRange.length != 0) | 111 if (aRange.length != 0) |
128 [aMenu setTitle: [[aMenu title] stringByReplacingRange: aRange with:appName]]; | 112 [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]]; |
129 | 113 |
130 enumerator =[[aMenu itemArray] objectEnumerator]; | 114 enumerator = [[aMenu itemArray] objectEnumerator]; |
131 while ((menuItem =[enumerator nextObject])) { | 115 while ((menuItem = [enumerator nextObject])) |
132 aRange =[[menuItem title] rangeOfString:@"SDL App"]; | 116 { |
117 aRange = [[menuItem title] rangeOfString:@"SDL App"]; | |
133 if (aRange.length != 0) | 118 if (aRange.length != 0) |
134 [menuItem setTitle: [[menuItem title] stringByReplacingRange: aRange with:appName]]; | 119 [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]]; |
135 if ([menuItem hasSubmenu]) | 120 if ([menuItem hasSubmenu]) |
136 [self fixMenu: [menuItem submenu] withAppName:appName]; | 121 [self fixMenu:[menuItem submenu] withAppName:appName]; |
137 } | 122 } |
138 [aMenu sizeToFit]; | 123 [ aMenu sizeToFit ]; |
139 } | 124 } |
140 | 125 |
141 #else | 126 #else |
142 | 127 |
143 static void | 128 static void setApplicationMenu(void) |
144 setApplicationMenu (void) | |
145 { | 129 { |
146 /* warning: this code is very odd */ | 130 /* warning: this code is very odd */ |
147 NSMenu *appleMenu; | 131 NSMenu *appleMenu; |
148 NSMenuItem *menuItem; | 132 NSMenuItem *menuItem; |
149 NSString *title; | 133 NSString *title; |
150 NSString *appName; | 134 NSString *appName; |
151 | 135 |
152 appName = getApplicationName (); | 136 appName = getApplicationName(); |
153 appleMenu =[[NSMenu alloc] initWithTitle:@""]; | 137 appleMenu = [[NSMenu alloc] initWithTitle:@""]; |
154 | 138 |
155 /* Add menu items */ | 139 /* Add menu items */ |
156 title =[@"About " stringByAppendingString:appName]; | 140 title = [@"About " stringByAppendingString:appName]; |
157 [appleMenu addItemWithTitle: title action: @selector (orderFrontStandardAboutPanel: )keyEquivalent:@""]; | 141 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; |
158 | 142 |
159 [appleMenu addItem:[NSMenuItem separatorItem]]; | 143 [appleMenu addItem:[NSMenuItem separatorItem]]; |
160 | 144 |
161 title =[@"Hide " stringByAppendingString:appName]; | 145 title = [@"Hide " stringByAppendingString:appName]; |
162 [appleMenu addItemWithTitle: title action: @selector (hide: )keyEquivalent:@"h"]; | 146 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; |
163 | 147 |
164 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle: @"Hide Others" action: @selector (hideOtherApplications: )keyEquivalent:@"h"]; | 148 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; |
165 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | | 149 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; |
166 NSCommandKeyMask)]; | 150 |
167 | 151 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; |
168 [appleMenu addItemWithTitle: @"Show All" action: @selector (unhideAllApplications: )keyEquivalent:@""]; | 152 |
169 | 153 [appleMenu addItem:[NSMenuItem separatorItem]]; |
170 [appleMenu addItem:[NSMenuItem separatorItem]]; | 154 |
171 | 155 title = [@"Quit " stringByAppendingString:appName]; |
172 title =[@"Quit " stringByAppendingString:appName]; | 156 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; |
173 [appleMenu addItemWithTitle: title action: @selector (terminate: )keyEquivalent:@"q"]; | 157 |
174 | 158 |
175 | |
176 /* Put menu into the menubar */ | 159 /* Put menu into the menubar */ |
177 menuItem =[[NSMenuItem alloc] initWithTitle: @"" action: nil keyEquivalent:@""]; | 160 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; |
178 [menuItem setSubmenu:appleMenu]; | 161 [menuItem setSubmenu:appleMenu]; |
179 [[NSApp mainMenu] addItem:menuItem]; | 162 [[NSApp mainMenu] addItem:menuItem]; |
180 | 163 |
181 /* Tell the application object that this is now the application menu */ | 164 /* Tell the application object that this is now the application menu */ |
182 [NSApp setAppleMenu:appleMenu]; | 165 [NSApp setAppleMenu:appleMenu]; |
183 | 166 |
184 /* Finally give up our references to the objects */ | 167 /* Finally give up our references to the objects */ |
185 [appleMenu release]; | 168 [appleMenu release]; |
186 [menuItem release]; | 169 [menuItem release]; |
187 } | 170 } |
188 | 171 |
189 /* Create a window menu */ | 172 /* Create a window menu */ |
190 static void | 173 static void setupWindowMenu(void) |
191 setupWindowMenu (void) | 174 { |
192 { | 175 NSMenu *windowMenu; |
193 NSMenu *windowMenu; | 176 NSMenuItem *windowMenuItem; |
194 NSMenuItem *windowMenuItem; | 177 NSMenuItem *menuItem; |
195 NSMenuItem *menuItem; | 178 |
196 | 179 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; |
197 windowMenu =[[NSMenu alloc] initWithTitle:@"Window"]; | 180 |
198 | |
199 /* "Minimize" item */ | 181 /* "Minimize" item */ |
200 menuItem =[[NSMenuItem alloc] initWithTitle: @"Minimize" action: @selector (performMiniaturize: )keyEquivalent:@"m"]; | 182 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; |
201 [windowMenu addItem:menuItem]; | 183 [windowMenu addItem:menuItem]; |
202 [menuItem release]; | 184 [menuItem release]; |
203 | 185 |
204 /* Put menu into the menubar */ | 186 /* Put menu into the menubar */ |
205 windowMenuItem =[[NSMenuItem alloc] initWithTitle: @"Window" action: nil keyEquivalent:@""]; | 187 windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; |
206 [windowMenuItem setSubmenu:windowMenu]; | 188 [windowMenuItem setSubmenu:windowMenu]; |
207 [[NSApp mainMenu] addItem:windowMenuItem]; | 189 [[NSApp mainMenu] addItem:windowMenuItem]; |
208 | 190 |
209 /* Tell the application object that this is now the window menu */ | 191 /* Tell the application object that this is now the window menu */ |
210 [NSApp setWindowsMenu:windowMenu]; | 192 [NSApp setWindowsMenu:windowMenu]; |
211 | 193 |
212 /* Finally give up our references to the objects */ | 194 /* Finally give up our references to the objects */ |
213 [windowMenu release]; | 195 [windowMenu release]; |
214 [windowMenuItem release]; | 196 [windowMenuItem release]; |
215 } | 197 } |
216 | 198 |
217 /* Replacement for NSApplicationMain */ | 199 /* Replacement for NSApplicationMain */ |
218 static void | 200 static void CustomApplicationMain (int argc, char **argv) |
219 CustomApplicationMain (int argc, char **argv) | 201 { |
220 { | 202 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
221 NSAutoreleasePool *pool =[[NSAutoreleasePool alloc] init]; | 203 SDLMain *sdlMain; |
222 SDLMain *sdlMain; | |
223 | 204 |
224 /* Ensure the application object is initialised */ | 205 /* Ensure the application object is initialised */ |
225 [SDLApplication sharedApplication]; | 206 [SDLApplication sharedApplication]; |
226 | 207 |
227 #ifdef SDL_USE_CPS | 208 #ifdef SDL_USE_CPS |
228 { | 209 { |
229 CPSProcessSerNum PSN; | 210 CPSProcessSerNum PSN; |
230 /* Tell the dock about us */ | 211 /* Tell the dock about us */ |
231 if (!CPSGetCurrentProcess (&PSN)) | 212 if (!CPSGetCurrentProcess(&PSN)) |
232 if (!CPSEnableForegroundOperation | 213 if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103)) |
233 (&PSN, 0x03, 0x3C, 0x2C, 0x1103)) | 214 if (!CPSSetFrontProcess(&PSN)) |
234 if (!CPSSetFrontProcess (&PSN)) | |
235 [SDLApplication sharedApplication]; | 215 [SDLApplication sharedApplication]; |
236 } | 216 } |
237 #endif /* SDL_USE_CPS */ | 217 #endif /* SDL_USE_CPS */ |
238 | 218 |
239 /* Set up the menubar */ | 219 /* Set up the menubar */ |
240 [NSApp setMainMenu:[[NSMenu alloc] init]]; | 220 [NSApp setMainMenu:[[NSMenu alloc] init]]; |
241 setApplicationMenu (); | 221 setApplicationMenu(); |
242 setupWindowMenu (); | 222 setupWindowMenu(); |
243 | 223 |
244 /* Create SDLMain and make it the app delegate */ | 224 /* Create SDLMain and make it the app delegate */ |
245 sdlMain =[[SDLMain alloc] init]; | 225 sdlMain = [[SDLMain alloc] init]; |
246 [NSApp setDelegate:sdlMain]; | 226 [NSApp setDelegate:sdlMain]; |
247 | 227 |
248 /* Start the main event loop */ | 228 /* Start the main event loop */ |
249 [NSApp run]; | 229 [NSApp run]; |
250 | 230 |
251 [sdlMain release]; | 231 [sdlMain release]; |
252 [pool release]; | 232 [pool release]; |
253 } | 233 } |
254 | 234 |
255 #endif | 235 #endif |
268 * | 248 * |
269 * This message may be received multiple times to open several docs on launch. | 249 * This message may be received multiple times to open several docs on launch. |
270 * | 250 * |
271 * This message is ignored once the app's mainline has been called. | 251 * This message is ignored once the app's mainline has been called. |
272 */ | 252 */ |
273 -(BOOL) application:(NSApplication *) | 253 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
274 theApplication openFile:(NSString *) filename | |
275 { | 254 { |
276 const char *temparg; | 255 const char *temparg; |
277 size_t arglen; | 256 size_t arglen; |
278 char *arg; | 257 char *arg; |
279 char **newargv; | 258 char **newargv; |
280 | 259 |
281 if (!gFinderLaunch) /* MacOS is passing command line args. */ | 260 if (!gFinderLaunch) /* MacOS is passing command line args. */ |
282 return FALSE; | 261 return FALSE; |
283 | 262 |
284 if (gCalledAppMainline) /* app has started, ignore this document. */ | 263 if (gCalledAppMainline) /* app has started, ignore this document. */ |
285 return FALSE; | 264 return FALSE; |
286 | 265 |
287 temparg =[filename UTF8String]; | 266 temparg = [filename UTF8String]; |
288 arglen = SDL_strlen (temparg) + 1; | 267 arglen = SDL_strlen(temparg) + 1; |
289 arg = (char *) SDL_malloc (arglen); | 268 arg = (char *) SDL_malloc(arglen); |
290 if (arg == NULL) | 269 if (arg == NULL) |
291 return FALSE; | 270 return FALSE; |
292 | 271 |
293 newargv = (char **) realloc (gArgv, sizeof (char *) * (gArgc + 2)); | 272 newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2)); |
294 if (newargv == NULL) { | 273 if (newargv == NULL) |
295 SDL_free (arg); | 274 { |
275 SDL_free(arg); | |
296 return FALSE; | 276 return FALSE; |
297 } | 277 } |
298 gArgv = newargv; | 278 gArgv = newargv; |
299 | 279 |
300 SDL_strlcpy (arg, temparg, arglen); | 280 SDL_strlcpy(arg, temparg, arglen); |
301 gArgv[gArgc++] = arg; | 281 gArgv[gArgc++] = arg; |
302 gArgv[gArgc] = NULL; | 282 gArgv[gArgc] = NULL; |
303 return TRUE; | 283 return TRUE; |
304 } | 284 } |
305 | 285 |
306 | 286 |
307 /* Called when the internal event loop has just started running */ | 287 /* Called when the internal event loop has just started running */ |
308 -(void) applicationDidFinishLaunching:(NSNotification *) note { | 288 - (void) applicationDidFinishLaunching: (NSNotification *) note |
289 { | |
309 int status; | 290 int status; |
310 | 291 |
311 /* Set the working directory to the .app's parent directory */ | 292 /* Set the working directory to the .app's parent directory */ |
312 [self setupWorkingDirectory:gFinderLaunch]; | 293 [self setupWorkingDirectory:gFinderLaunch]; |
313 | 294 |
314 #if SDL_USE_NIB_FILE | 295 #if SDL_USE_NIB_FILE |
315 /* Set the main menu to contain the real app name instead of "SDL App" */ | 296 /* Set the main menu to contain the real app name instead of "SDL App" */ |
316 [self fixMenu: [NSApp mainMenu] withAppName:getApplicationName ()]; | 297 [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()]; |
317 #endif | 298 #endif |
318 | 299 |
319 /* Hand off to main application code */ | 300 /* Hand off to main application code */ |
320 gCalledAppMainline = TRUE; | 301 gCalledAppMainline = TRUE; |
321 status = SDL_main (gArgc, gArgv); | 302 status = SDL_main (gArgc, gArgv); |
322 | 303 |
323 /* We're done, thank you for playing */ | 304 /* We're done, thank you for playing */ |
324 exit (status); | 305 exit(status); |
325 } | 306 } |
326 | 307 @end |
327 @end @ implementation NSString (ReplaceSubString) - (NSString *) stringByReplacingRange:(NSRange) | 308 |
328 aRange | 309 |
329 with:(NSString *) | 310 @implementation NSString (ReplaceSubString) |
330 aString | 311 |
312 - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString | |
331 { | 313 { |
332 unsigned int bufferSize; | 314 unsigned int bufferSize; |
333 unsigned int selfLen =[self length]; | 315 unsigned int selfLen = [self length]; |
334 unsigned int aStringLen =[aString length]; | 316 unsigned int aStringLen = [aString length]; |
335 unichar *buffer; | 317 unichar *buffer; |
336 NSRange localRange; | 318 NSRange localRange; |
337 NSString *result; | 319 NSString *result; |
338 | 320 |
339 bufferSize = selfLen + aStringLen - aRange.length; | 321 bufferSize = selfLen + aStringLen - aRange.length; |
340 buffer = NSAllocateMemoryPages (bufferSize * sizeof (unichar)); | 322 buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar)); |
341 | 323 |
342 /* Get first part into buffer */ | 324 /* Get first part into buffer */ |
343 localRange.location = 0; | 325 localRange.location = 0; |
344 localRange.length = aRange.location; | 326 localRange.length = aRange.location; |
345 [self getCharacters: buffer range:localRange]; | 327 [self getCharacters:buffer range:localRange]; |
346 | 328 |
347 /* Get middle part into buffer */ | 329 /* Get middle part into buffer */ |
348 localRange.location = 0; | 330 localRange.location = 0; |
349 localRange.length = aStringLen; | 331 localRange.length = aStringLen; |
350 [aString getCharacters: (buffer + aRange.location) range:localRange]; | 332 [aString getCharacters:(buffer+aRange.location) range:localRange]; |
351 | 333 |
352 /* Get last part into buffer */ | 334 /* Get last part into buffer */ |
353 localRange.location = aRange.location + aRange.length; | 335 localRange.location = aRange.location + aRange.length; |
354 localRange.length = selfLen - localRange.location; | 336 localRange.length = selfLen - localRange.location; |
355 [self getCharacters: (buffer + aRange.location + aStringLen) range:localRange]; | 337 [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange]; |
356 | 338 |
357 /* Build output string */ | 339 /* Build output string */ |
358 result =[NSString stringWithCharacters: buffer length:bufferSize]; | 340 result = [NSString stringWithCharacters:buffer length:bufferSize]; |
359 | 341 |
360 NSDeallocateMemoryPages (buffer, bufferSize); | 342 NSDeallocateMemoryPages(buffer, bufferSize); |
361 | 343 |
362 return result; | 344 return result; |
363 } | 345 } |
364 | 346 |
365 @end | 347 @end |
348 | |
349 | |
350 | |
366 #ifdef main | 351 #ifdef main |
367 # undef main | 352 # undef main |
368 #endif | 353 #endif |
354 | |
355 | |
369 /* Main entry point to executable - should *not* be SDL_main! */ | 356 /* Main entry point to executable - should *not* be SDL_main! */ |
370 int | 357 int main (int argc, char **argv) |
371 main (int argc, char **argv) | |
372 { | 358 { |
373 /* Copy the arguments into a global variable */ | 359 /* Copy the arguments into a global variable */ |
374 /* This is passed if we are launched by double-clicking */ | 360 /* This is passed if we are launched by double-clicking */ |
375 if (argc >= 2 && strncmp (argv[1], "-psn", 4) == 0) { | 361 if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { |
376 gArgv = (char **) SDL_malloc (sizeof (char *) * 2); | 362 gArgv = (char **) SDL_malloc(sizeof (char *) * 2); |
377 gArgv[0] = argv[0]; | 363 gArgv[0] = argv[0]; |
378 gArgv[1] = NULL; | 364 gArgv[1] = NULL; |
379 gArgc = 1; | 365 gArgc = 1; |
380 gFinderLaunch = YES; | 366 gFinderLaunch = YES; |
381 } else { | 367 } else { |
382 int i; | 368 int i; |
383 gArgc = argc; | 369 gArgc = argc; |
384 gArgv = (char **) SDL_malloc (sizeof (char *) * (argc + 1)); | 370 gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1)); |
385 for (i = 0; i <= argc; i++) | 371 for (i = 0; i <= argc; i++) |
386 gArgv[i] = argv[i]; | 372 gArgv[i] = argv[i]; |
387 gFinderLaunch = NO; | 373 gFinderLaunch = NO; |
388 } | 374 } |
389 | 375 |
390 #if SDL_USE_NIB_FILE | 376 #if SDL_USE_NIB_FILE |
391 [SDLApplication poseAsClass:[NSApplication class]]; | 377 [SDLApplication poseAsClass:[NSApplication class]]; |
392 NSApplicationMain (argc, argv); | 378 NSApplicationMain (argc, argv); |
393 #else | 379 #else |
394 CustomApplicationMain (argc, argv); | 380 CustomApplicationMain (argc, argv); |
395 #endif | 381 #endif |
396 return 0; | 382 return 0; |
397 } | 383 } |
384 |