Mercurial > sdl-ios-xcode
annotate src/main/macos/SDL_main.c @ 3961:4b093ecae4a7 SDL-1.2
Don't install the extra SDL config headers or SDL_copying.h
Fixes Bugzilla #361.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 15 Jun 2007 05:41:22 +0000 |
parents | 7a610f25c12f |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* This file takes care of command line argument parsing, and stdio redirection | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
24 in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) |
0 | 25 */ |
26 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
27 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
28 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
29 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 30 #include <Carbon.h> |
31 #else | |
32 #include <Dialogs.h> | |
33 #include <Fonts.h> | |
34 #include <Events.h> | |
35 #include <Resources.h> | |
36 #include <Folders.h> | |
37 #endif | |
38 | |
39 /* Include the SDL main definition header */ | |
40 #include "SDL.h" | |
41 #include "SDL_main.h" | |
42 #ifdef main | |
43 #undef main | |
44 #endif | |
45 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
46 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 47 /* The standard output files */ |
48 #define STDOUT_FILE "stdout.txt" | |
49 #define STDERR_FILE "stderr.txt" | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
50 #endif |
0 | 51 |
52 #if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON | |
53 /* In MPW, the qd global has been removed from the libraries */ | |
54 QDGlobals qd; | |
55 #endif | |
56 | |
57 /* Structure for keeping prefs in 1 variable */ | |
58 typedef struct { | |
59 Str255 command_line; | |
60 Str255 video_driver_name; | |
61 Boolean output_to_file; | |
62 } PrefsRecord; | |
63 | |
64 /* See if the command key is held down at startup */ | |
65 static Boolean CommandKeyIsDown(void) | |
66 { | |
67 KeyMap theKeyMap; | |
68 | |
69 GetKeys(theKeyMap); | |
70 | |
71 if (((unsigned char *) theKeyMap)[6] & 0x80) { | |
72 return(true); | |
73 } | |
74 return(false); | |
75 } | |
76 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
77 #if !(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
78 |
0 | 79 /* Parse a command line buffer into arguments */ |
80 static int ParseCommandLine(char *cmdline, char **argv) | |
81 { | |
82 char *bufp; | |
83 int argc; | |
84 | |
85 argc = 0; | |
86 for ( bufp = cmdline; *bufp; ) { | |
87 /* Skip leading whitespace */ | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
88 while ( SDL_isspace(*bufp) ) { |
0 | 89 ++bufp; |
90 } | |
91 /* Skip over argument */ | |
92 if ( *bufp == '"' ) { | |
93 ++bufp; | |
94 if ( *bufp ) { | |
95 if ( argv ) { | |
96 argv[argc] = bufp; | |
97 } | |
98 ++argc; | |
99 } | |
100 /* Skip over word */ | |
101 while ( *bufp && (*bufp != '"') ) { | |
102 ++bufp; | |
103 } | |
104 } else { | |
105 if ( *bufp ) { | |
106 if ( argv ) { | |
107 argv[argc] = bufp; | |
108 } | |
109 ++argc; | |
110 } | |
111 /* Skip over word */ | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
112 while ( *bufp && ! SDL_isspace(*bufp) ) { |
0 | 113 ++bufp; |
114 } | |
115 } | |
116 if ( *bufp ) { | |
117 if ( argv ) { | |
118 *bufp = '\0'; | |
119 } | |
120 ++bufp; | |
121 } | |
122 } | |
123 if ( argv ) { | |
124 argv[argc] = NULL; | |
125 } | |
126 return(argc); | |
127 } | |
128 | |
129 /* Remove the output files if there was no output written */ | |
130 static void cleanup_output(void) | |
131 { | |
132 FILE *file; | |
133 int empty; | |
134 | |
135 /* Flush the output in case anything is queued */ | |
136 fclose(stdout); | |
137 fclose(stderr); | |
138 | |
139 /* See if the files have any output in them */ | |
140 file = fopen(STDOUT_FILE, "rb"); | |
141 if ( file ) { | |
142 empty = (fgetc(file) == EOF) ? 1 : 0; | |
143 fclose(file); | |
144 if ( empty ) { | |
145 remove(STDOUT_FILE); | |
146 } | |
147 } | |
148 file = fopen(STDERR_FILE, "rb"); | |
149 if ( file ) { | |
150 empty = (fgetc(file) == EOF) ? 1 : 0; | |
151 fclose(file); | |
152 if ( empty ) { | |
153 remove(STDERR_FILE); | |
154 } | |
155 } | |
156 } | |
157 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
158 #endif //!(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
159 |
0 | 160 static int getCurrentAppName (StrFileName name) { |
161 | |
162 ProcessSerialNumber process; | |
163 ProcessInfoRec process_info; | |
164 FSSpec process_fsp; | |
165 | |
166 process.highLongOfPSN = 0; | |
167 process.lowLongOfPSN = kCurrentProcess; | |
168 process_info.processInfoLength = sizeof (process_info); | |
169 process_info.processName = NULL; | |
170 process_info.processAppSpec = &process_fsp; | |
171 | |
172 if ( noErr != GetProcessInformation (&process, &process_info) ) | |
173 return 0; | |
174 | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
175 SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1); |
0 | 176 return 1; |
177 } | |
178 | |
179 static int getPrefsFile (FSSpec *prefs_fsp, int create) { | |
180 | |
181 /* The prefs file name is the application name, possibly truncated, */ | |
182 /* plus " Preferences */ | |
183 | |
184 #define SUFFIX " Preferences" | |
185 #define MAX_NAME 19 /* 31 - strlen (SUFFIX) */ | |
186 | |
187 short volume_ref_number; | |
188 long directory_id; | |
189 StrFileName prefs_name; | |
190 StrFileName app_name; | |
191 | |
192 /* Get Preferences folder - works with Multiple Users */ | |
193 if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, | |
194 &volume_ref_number, &directory_id) ) | |
195 exit (-1); | |
196 | |
197 if ( ! getCurrentAppName (app_name) ) | |
198 exit (-1); | |
199 | |
200 /* Truncate if name is too long */ | |
201 if (app_name[0] > MAX_NAME ) | |
202 app_name[0] = MAX_NAME; | |
203 | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
204 SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]); |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
205 SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX)); |
0 | 206 prefs_name[0] = app_name[0] + strlen (SUFFIX); |
207 | |
208 /* Make the file spec for prefs file */ | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
209 if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) { |
0 | 210 if ( !create ) |
211 return 0; | |
212 else { | |
213 /* Create the prefs file */ | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
214 SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1); |
0 | 215 prefs_fsp->parID = directory_id; |
216 prefs_fsp->vRefNum = volume_ref_number; | |
217 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
218 FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph |
0 | 219 |
220 if ( noErr != ResError () ) | |
221 return 0; | |
222 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
223 } |
0 | 224 return 1; |
225 } | |
226 | |
227 static int readPrefsResource (PrefsRecord *prefs) { | |
228 | |
229 Handle prefs_handle; | |
230 | |
231 prefs_handle = Get1Resource( 'CLne', 128 ); | |
232 | |
233 if (prefs_handle != NULL) { | |
234 int offset = 0; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
235 // int j = 0; |
0 | 236 |
237 HLock(prefs_handle); | |
238 | |
239 /* Get command line string */ | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
240 SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1); |
0 | 241 |
242 /* Get video driver name */ | |
243 offset += (*prefs_handle)[0] + 1; | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
244 SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1); |
0 | 245 |
246 /* Get save-to-file option (1 or 0) */ | |
247 offset += (*prefs_handle)[offset] + 1; | |
248 prefs->output_to_file = (*prefs_handle)[offset]; | |
249 | |
250 ReleaseResource( prefs_handle ); | |
251 | |
252 return ResError() == noErr; | |
253 } | |
254 | |
255 return 0; | |
256 } | |
257 | |
258 static int writePrefsResource (PrefsRecord *prefs, short resource_file) { | |
259 | |
260 Handle prefs_handle; | |
261 | |
262 UseResFile (resource_file); | |
263 | |
264 prefs_handle = Get1Resource ( 'CLne', 128 ); | |
265 if (prefs_handle != NULL) | |
266 RemoveResource (prefs_handle); | |
267 | |
268 prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 ); | |
269 if (prefs_handle != NULL) { | |
270 | |
271 int offset; | |
272 | |
273 HLock (prefs_handle); | |
274 | |
275 /* Command line text */ | |
276 offset = 0; | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
277 SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1); |
0 | 278 |
279 /* Video driver name */ | |
280 offset += prefs->command_line[0] + 1; | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
281 SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1); |
0 | 282 |
283 /* Output-to-file option */ | |
284 offset += prefs->video_driver_name[0] + 1; | |
285 *( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file; | |
286 *( *((char**)prefs_handle) + offset + 1) = 0; | |
287 | |
288 AddResource (prefs_handle, 'CLne', 128, "\pCommand Line"); | |
289 WriteResource (prefs_handle); | |
290 UpdateResFile (resource_file); | |
291 DisposeHandle (prefs_handle); | |
292 | |
293 return ResError() == noErr; | |
294 } | |
295 | |
296 return 0; | |
297 } | |
298 | |
299 static int readPreferences (PrefsRecord *prefs) { | |
300 | |
301 int no_error = 1; | |
302 FSSpec prefs_fsp; | |
303 | |
304 /* Check for prefs file first */ | |
305 if ( getPrefsFile (&prefs_fsp, 0) ) { | |
306 | |
307 short prefs_resource; | |
308 | |
309 prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm); | |
310 if ( prefs_resource == -1 ) /* this shouldn't happen, but... */ | |
311 return 0; | |
312 | |
313 UseResFile (prefs_resource); | |
314 no_error = readPrefsResource (prefs); | |
315 CloseResFile (prefs_resource); | |
316 } | |
317 | |
318 /* Fall back to application's resource fork (reading only, so this is safe) */ | |
319 else { | |
320 | |
321 no_error = readPrefsResource (prefs); | |
322 } | |
323 | |
324 return no_error; | |
325 } | |
326 | |
327 static int writePreferences (PrefsRecord *prefs) { | |
328 | |
329 int no_error = 1; | |
330 FSSpec prefs_fsp; | |
331 | |
332 /* Get prefs file, create if it doesn't exist */ | |
333 if ( getPrefsFile (&prefs_fsp, 1) ) { | |
334 | |
335 short prefs_resource; | |
336 | |
337 prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm); | |
338 if (prefs_resource == -1) | |
339 return 0; | |
340 no_error = writePrefsResource (prefs, prefs_resource); | |
341 CloseResFile (prefs_resource); | |
342 } | |
343 | |
344 return no_error; | |
345 } | |
346 | |
347 /* This is where execution begins */ | |
348 int main(int argc, char *argv[]) | |
349 { | |
350 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
351 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 352 #pragma unused(argc, argv) |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
353 #endif |
0 | 354 |
355 #define DEFAULT_ARGS "\p" /* pascal string for default args */ | |
356 #define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */ | |
357 #define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */ | |
358 | |
359 #define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */ | |
360 #define VIDEO_ID_TOOLBOX 2 | |
361 | |
362 PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE }; | |
363 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
364 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 365 int nargs; |
366 char **args; | |
367 char *commandLine; | |
368 | |
369 StrFileName appNameText; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
370 #endif |
0 | 371 int videodriver = VIDEO_ID_TOOLBOX; |
372 int settingsChanged = 0; | |
373 | |
374 long i; | |
375 | |
376 /* Kyle's SDL command-line dialog code ... */ | |
377 #if !TARGET_API_MAC_CARBON | |
378 InitGraf (&qd.thePort); | |
379 InitFonts (); | |
380 InitWindows (); | |
381 InitMenus (); | |
382 InitDialogs (nil); | |
383 #endif | |
384 InitCursor (); | |
385 FlushEvents(everyEvent,0); | |
386 #if !TARGET_API_MAC_CARBON | |
387 MaxApplZone (); | |
388 #endif | |
389 MoreMasters (); | |
390 MoreMasters (); | |
391 #if 0 | |
392 /* Intialize SDL, and put up a dialog if we fail */ | |
393 if ( SDL_Init (0) < 0 ) { | |
394 | |
395 #define kErr_OK 1 | |
396 #define kErr_Text 2 | |
397 | |
398 DialogPtr errorDialog; | |
399 short dummyType; | |
400 Rect dummyRect; | |
401 Handle dummyHandle; | |
402 short itemHit; | |
403 | |
404 errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
405 if (errorDialog == NULL) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
406 return -1; |
0 | 407 DrawDialog (errorDialog); |
408 | |
409 GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect); | |
410 SetDialogItemText (dummyHandle, "\pError Initializing SDL"); | |
411 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
412 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
413 SetPort (GetDialogPort(errorDialog)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
414 #else |
0 | 415 SetPort (errorDialog); |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
416 #endif |
0 | 417 do { |
418 ModalDialog (nil, &itemHit); | |
419 } while (itemHit != kErr_OK); | |
420 | |
421 DisposeDialog (errorDialog); | |
422 exit (-1); | |
423 } | |
424 atexit(cleanup_output); | |
425 atexit(SDL_Quit); | |
426 #endif | |
427 | |
428 /* Set up SDL's QuickDraw environment */ | |
429 #if !TARGET_API_MAC_CARBON | |
430 SDL_InitQuickDraw(&qd); | |
431 #endif | |
432 | |
433 if ( readPreferences (&prefs) ) { | |
434 | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
435 if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0) |
0 | 436 videodriver = 1; |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
437 else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0) |
0 | 438 videodriver = 2; |
439 } | |
440 | |
441 if ( CommandKeyIsDown() ) { | |
442 | |
443 #define kCL_OK 1 | |
444 #define kCL_Cancel 2 | |
445 #define kCL_Text 3 | |
446 #define kCL_File 4 | |
447 #define kCL_Video 6 | |
448 | |
449 DialogPtr commandDialog; | |
450 short dummyType; | |
451 Rect dummyRect; | |
452 Handle dummyHandle; | |
453 short itemHit; | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
454 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
455 ControlRef control; |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
456 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
457 |
0 | 458 /* Assume that they will change settings, rather than do exhaustive check */ |
459 settingsChanged = 1; | |
460 | |
461 /* Create dialog and display it */ | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
462 commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
463 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
464 SetPort ( GetDialogPort(commandDialog) ); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
465 #else |
0 | 466 SetPort (commandDialog); |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
467 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
468 |
0 | 469 /* Setup controls */ |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
470 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
471 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
472 SetControlValue (control, prefs.output_to_file); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
473 #else |
0 | 474 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
475 SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file ); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
476 #endif |
0 | 477 |
478 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); | |
479 SetDialogItemText (dummyHandle, prefs.command_line); | |
480 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
481 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
482 GetDialogItemAsControl(commandDialog, kCL_Video, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
483 SetControlValue (control, videodriver); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
484 #else |
0 | 485 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
486 SetControlValue ((ControlRef)dummyHandle, videodriver); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
487 #endif |
0 | 488 |
489 SetDialogDefaultItem (commandDialog, kCL_OK); | |
490 SetDialogCancelItem (commandDialog, kCL_Cancel); | |
491 | |
492 do { | |
493 | |
494 ModalDialog(nil, &itemHit); /* wait for user response */ | |
495 | |
496 /* Toggle command-line output checkbox */ | |
497 if ( itemHit == kCL_File ) { | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
498 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
499 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
500 SetControlValue (control, !GetControlValue(control)); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
501 #else |
0 | 502 GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
503 SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) ); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
504 #endif |
0 | 505 } |
506 | |
507 } while (itemHit != kCL_OK && itemHit != kCL_Cancel); | |
508 | |
509 /* Get control values, even if they did not change */ | |
510 GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */ | |
511 GetDialogItemText (dummyHandle, prefs.command_line); | |
512 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
513 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
514 GetDialogItemAsControl(commandDialog, kCL_File, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
515 prefs.output_to_file = GetControlValue(control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
516 #else |
0 | 517 GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */ |
518 prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
519 #endif |
0 | 520 |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
521 #if TARGET_API_MAC_CARBON |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
522 GetDialogItemAsControl(commandDialog, kCL_Video, &control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
523 videodriver = GetControlValue(control); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
524 #else |
0 | 525 GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect); |
526 videodriver = GetControlValue ((ControlRef)dummyHandle); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
527 #endif |
0 | 528 |
529 DisposeDialog (commandDialog); | |
530 | |
531 if (itemHit == kCL_Cancel ) { | |
532 exit (0); | |
533 } | |
534 } | |
535 | |
536 /* Set pseudo-environment variables for video driver, update prefs */ | |
537 switch ( videodriver ) { | |
538 case VIDEO_ID_DRAWSPROCKET: | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
539 SDL_putenv("SDL_VIDEODRIVER=DSp"); |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
540 SDL_memcpy(prefs.video_driver_name, "\pDSp", 4); |
0 | 541 break; |
542 case VIDEO_ID_TOOLBOX: | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
543 SDL_putenv("SDL_VIDEODRIVER=toolbox"); |
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
544 SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8); |
0 | 545 break; |
546 } | |
547 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
548 #if !(defined(__APPLE__) && defined(__MACH__)) |
0 | 549 /* Redirect standard I/O to files */ |
550 if ( prefs.output_to_file ) { | |
551 freopen (STDOUT_FILE, "w", stdout); | |
552 freopen (STDERR_FILE, "w", stderr); | |
553 } else { | |
554 fclose (stdout); | |
555 fclose (stderr); | |
556 } | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
557 #endif |
0 | 558 |
559 if (settingsChanged) { | |
560 /* Save the prefs, even if they might not have changed (but probably did) */ | |
561 if ( ! writePreferences (&prefs) ) | |
562 fprintf (stderr, "WARNING: Could not save preferences!\n"); | |
563 } | |
564 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
565 #if !(defined(__APPLE__) && defined(__MACH__)) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
566 appNameText[0] = 0; |
0 | 567 getCurrentAppName (appNameText); /* check for error here ? */ |
568 | |
569 commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2); | |
570 if ( commandLine == NULL ) { | |
571 exit(-1); | |
572 } | |
573 | |
574 /* Rather than rewrite ParseCommandLine method, let's replace */ | |
575 /* any spaces in application name with underscores, */ | |
576 /* so that the app name is only 1 argument */ | |
577 for (i = 1; i < 1+appNameText[0]; i++) | |
578 if ( appNameText[i] == ' ' ) appNameText[i] = '_'; | |
579 | |
580 /* Copy app name & full command text to command-line C-string */ | |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
581 SDL_memcpy(commandLine, appNameText + 1, appNameText[0]); |
0 | 582 commandLine[appNameText[0]] = ' '; |
1424
7a610f25c12f
Updated MacOS Classic MPW build
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
583 SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]); |
0 | 584 commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0'; |
585 | |
586 /* Parse C-string into argv and argc */ | |
587 nargs = ParseCommandLine (commandLine, NULL); | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
588 args = (char **)malloc((nargs+1)*(sizeof *args)); |
0 | 589 if ( args == NULL ) { |
590 exit(-1); | |
591 } | |
592 ParseCommandLine (commandLine, args); | |
593 | |
594 /* Run the main application code */ | |
595 SDL_main(nargs, args); | |
596 free (args); | |
597 free (commandLine); | |
598 | |
599 /* Remove useless stdout.txt and stderr.txt */ | |
600 cleanup_output (); | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
601 #else // defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
602 SDL_main(argc, argv); |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
769
diff
changeset
|
603 #endif |
0 | 604 |
605 /* Exit cleanly, calling atexit() functions */ | |
606 exit (0); | |
607 | |
608 /* Never reached, but keeps the compiler quiet */ | |
609 return (0); | |
610 } |