Mercurial > sdl-ios-xcode
comparison src/main/macos/SDL_main.c @ 1424:7a610f25c12f
Updated MacOS Classic MPW build
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 24 Feb 2006 09:57:14 +0000 |
parents | 604d73db6802 |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
comparison
equal
deleted
inserted
replaced
1423:4ed717f9e509 | 1424:7a610f25c12f |
---|---|
22 | 22 |
23 /* This file takes care of command line argument parsing, and stdio redirection | 23 /* This file takes care of command line argument parsing, and stdio redirection |
24 in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) | 24 in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) |
25 */ | 25 */ |
26 | 26 |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <ctype.h> | |
31 #if defined(__APPLE__) && defined(__MACH__) | 27 #if defined(__APPLE__) && defined(__MACH__) |
32 #include <Carbon/Carbon.h> | 28 #include <Carbon/Carbon.h> |
33 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) | 29 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
34 #include <Carbon.h> | 30 #include <Carbon.h> |
35 #else | 31 #else |
87 int argc; | 83 int argc; |
88 | 84 |
89 argc = 0; | 85 argc = 0; |
90 for ( bufp = cmdline; *bufp; ) { | 86 for ( bufp = cmdline; *bufp; ) { |
91 /* Skip leading whitespace */ | 87 /* Skip leading whitespace */ |
92 while ( isspace(*bufp) ) { | 88 while ( SDL_isspace(*bufp) ) { |
93 ++bufp; | 89 ++bufp; |
94 } | 90 } |
95 /* Skip over argument */ | 91 /* Skip over argument */ |
96 if ( *bufp == '"' ) { | 92 if ( *bufp == '"' ) { |
97 ++bufp; | 93 ++bufp; |
111 argv[argc] = bufp; | 107 argv[argc] = bufp; |
112 } | 108 } |
113 ++argc; | 109 ++argc; |
114 } | 110 } |
115 /* Skip over word */ | 111 /* Skip over word */ |
116 while ( *bufp && ! isspace(*bufp) ) { | 112 while ( *bufp && ! SDL_isspace(*bufp) ) { |
117 ++bufp; | 113 ++bufp; |
118 } | 114 } |
119 } | 115 } |
120 if ( *bufp ) { | 116 if ( *bufp ) { |
121 if ( argv ) { | 117 if ( argv ) { |
174 process_info.processAppSpec = &process_fsp; | 170 process_info.processAppSpec = &process_fsp; |
175 | 171 |
176 if ( noErr != GetProcessInformation (&process, &process_info) ) | 172 if ( noErr != GetProcessInformation (&process, &process_info) ) |
177 return 0; | 173 return 0; |
178 | 174 |
179 memcpy (name, process_fsp.name, process_fsp.name[0] + 1); | 175 SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1); |
180 return 1; | 176 return 1; |
181 } | 177 } |
182 | 178 |
183 static int getPrefsFile (FSSpec *prefs_fsp, int create) { | 179 static int getPrefsFile (FSSpec *prefs_fsp, int create) { |
184 | 180 |
203 | 199 |
204 /* Truncate if name is too long */ | 200 /* Truncate if name is too long */ |
205 if (app_name[0] > MAX_NAME ) | 201 if (app_name[0] > MAX_NAME ) |
206 app_name[0] = MAX_NAME; | 202 app_name[0] = MAX_NAME; |
207 | 203 |
208 memcpy (prefs_name + 1, app_name + 1, app_name[0]); | 204 SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]); |
209 memcpy (prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); | 205 SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); |
210 prefs_name[0] = app_name[0] + strlen (SUFFIX); | 206 prefs_name[0] = app_name[0] + strlen (SUFFIX); |
211 | 207 |
212 /* Make the file spec for prefs file */ | 208 /* Make the file spec for prefs file */ |
213 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { | 209 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { |
214 if ( !create ) | 210 if ( !create ) |
215 return 0; | 211 return 0; |
216 else { | 212 else { |
217 /* Create the prefs file */ | 213 /* Create the prefs file */ |
218 memcpy (prefs_fsp->name, prefs_name, prefs_name[0] + 1); | 214 SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1); |
219 prefs_fsp->parID = directory_id; | 215 prefs_fsp->parID = directory_id; |
220 prefs_fsp->vRefNum = volume_ref_number; | 216 prefs_fsp->vRefNum = volume_ref_number; |
221 | 217 |
222 FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph | 218 FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph |
223 | 219 |
239 // int j = 0; | 235 // int j = 0; |
240 | 236 |
241 HLock(prefs_handle); | 237 HLock(prefs_handle); |
242 | 238 |
243 /* Get command line string */ | 239 /* Get command line string */ |
244 memcpy (prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); | 240 SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); |
245 | 241 |
246 /* Get video driver name */ | 242 /* Get video driver name */ |
247 offset += (*prefs_handle)[0] + 1; | 243 offset += (*prefs_handle)[0] + 1; |
248 memcpy (prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); | 244 SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); |
249 | 245 |
250 /* Get save-to-file option (1 or 0) */ | 246 /* Get save-to-file option (1 or 0) */ |
251 offset += (*prefs_handle)[offset] + 1; | 247 offset += (*prefs_handle)[offset] + 1; |
252 prefs->output_to_file = (*prefs_handle)[offset]; | 248 prefs->output_to_file = (*prefs_handle)[offset]; |
253 | 249 |
276 | 272 |
277 HLock (prefs_handle); | 273 HLock (prefs_handle); |
278 | 274 |
279 /* Command line text */ | 275 /* Command line text */ |
280 offset = 0; | 276 offset = 0; |
281 memcpy (*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); | 277 SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); |
282 | 278 |
283 /* Video driver name */ | 279 /* Video driver name */ |
284 offset += prefs->command_line[0] + 1; | 280 offset += prefs->command_line[0] + 1; |
285 memcpy (*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); | 281 SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); |
286 | 282 |
287 /* Output-to-file option */ | 283 /* Output-to-file option */ |
288 offset += prefs->video_driver_name[0] + 1; | 284 offset += prefs->video_driver_name[0] + 1; |
289 *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; | 285 *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; |
290 *( *((char**)prefs_handle) + offset + 1) = 0; | 286 *( *((char**)prefs_handle) + offset + 1) = 0; |
434 SDL_InitQuickDraw(&qd); | 430 SDL_InitQuickDraw(&qd); |
435 #endif | 431 #endif |
436 | 432 |
437 if ( readPreferences (&prefs) ) { | 433 if ( readPreferences (&prefs) ) { |
438 | 434 |
439 if (memcmp (prefs.video_driver_name+1, "DSp", 3) == 0) | 435 if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0) |
440 videodriver = 1; | 436 videodriver = 1; |
441 else if (memcmp (prefs.video_driver_name+1, "toolbox", 7) == 0) | 437 else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0) |
442 videodriver = 2; | 438 videodriver = 2; |
443 } | 439 } |
444 | 440 |
445 if ( CommandKeyIsDown() ) { | 441 if ( CommandKeyIsDown() ) { |
446 | 442 |
538 } | 534 } |
539 | 535 |
540 /* Set pseudo-environment variables for video driver, update prefs */ | 536 /* Set pseudo-environment variables for video driver, update prefs */ |
541 switch ( videodriver ) { | 537 switch ( videodriver ) { |
542 case VIDEO_ID_DRAWSPROCKET: | 538 case VIDEO_ID_DRAWSPROCKET: |
543 putenv ("SDL_VIDEODRIVER=DSp"); | 539 SDL_putenv("SDL_VIDEODRIVER=DSp"); |
544 memcpy (prefs.video_driver_name, "\pDSp", 4); | 540 SDL_memcpy(prefs.video_driver_name, "\pDSp", 4); |
545 break; | 541 break; |
546 case VIDEO_ID_TOOLBOX: | 542 case VIDEO_ID_TOOLBOX: |
547 putenv ("SDL_VIDEODRIVER=toolbox"); | 543 SDL_putenv("SDL_VIDEODRIVER=toolbox"); |
548 memcpy (prefs.video_driver_name, "\ptoolbox", 8); | 544 SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8); |
549 break; | 545 break; |
550 } | 546 } |
551 | 547 |
552 #if !(defined(__APPLE__) && defined(__MACH__)) | 548 #if !(defined(__APPLE__) && defined(__MACH__)) |
553 /* Redirect standard I/O to files */ | 549 /* Redirect standard I/O to files */ |
580 /* so that the app name is only 1 argument */ | 576 /* so that the app name is only 1 argument */ |
581 for (i = 1; i < 1+appNameText[0]; i++) | 577 for (i = 1; i < 1+appNameText[0]; i++) |
582 if ( appNameText[i] == ' ' ) appNameText[i] = '_'; | 578 if ( appNameText[i] == ' ' ) appNameText[i] = '_'; |
583 | 579 |
584 /* Copy app name & full command text to command-line C-string */ | 580 /* Copy app name & full command text to command-line C-string */ |
585 memcpy (commandLine, appNameText + 1, appNameText[0]); | 581 SDL_memcpy(commandLine, appNameText + 1, appNameText[0]); |
586 commandLine[appNameText[0]] = ' '; | 582 commandLine[appNameText[0]] = ' '; |
587 memcpy (commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); | 583 SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); |
588 commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; | 584 commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; |
589 | 585 |
590 /* Parse C-string into argv and argc */ | 586 /* Parse C-string into argv and argc */ |
591 nargs = ParseCommandLine (commandLine, NULL); | 587 nargs = ParseCommandLine (commandLine, NULL); |
592 args = (char **)malloc((nargs+1)*(sizeof *args)); | 588 args = (char **)malloc((nargs+1)*(sizeof *args)); |