Skip to content

Latest commit

 

History

History
610 lines (487 loc) · 16.8 KB

SDL_main.c

File metadata and controls

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