Mercurial > sdl-ios-xcode
annotate src/main/win32/SDL_main.c @ 545:8406511f850e
Save the full pathname for stdout.txt and stderr.txt
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Nov 2002 19:30:44 +0000 |
parents | 6b34c9dcf74c |
children | 0ac20b67c2c7 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 | |
3 | |
4 The WinMain function -- calls your program's main() function | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include <ctype.h> | |
10 #include <stdlib.h> | |
11 | |
12 #include <windows.h> | |
13 #include <malloc.h> /* For _alloca() */ | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
14 #include <io.h> /* For _getcwd() */ |
0 | 15 |
16 /* Include the SDL main definition header */ | |
17 #include "SDL.h" | |
18 #include "SDL_main.h" | |
19 #ifdef main | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
20 #ifndef _WIN32_WCE_EMULATION |
0 | 21 #undef main |
22 #endif | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
23 #endif |
0 | 24 |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
25 /* Do we really not want stdio redirection with Windows CE? */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
26 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
27 #define NO_STDIO_REDIRECT |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
28 #endif |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
29 |
0 | 30 /* The standard output files */ |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
31 #define STDOUT_FILE TEXT("stdout.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
32 #define STDERR_FILE TEXT("stderr.txt") |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
33 |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
34 #ifndef NO_STDIO_REDIRECT |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
35 static char stdoutPath[MAX_PATH]; |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
36 static char stderrPath[MAX_PATH]; |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
37 #endif |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
38 |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
39 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
40 /* seems to be undefined in Win CE although in online help */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
41 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
42 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
43 /* seems to be undefined in Win CE although in online help */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
44 char *strrchr(char *str, int c) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
45 { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
46 char *p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
47 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
48 /* Skip to the end of the string */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
49 p=str; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
50 while (*p) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
51 p++; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
52 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
53 /* Look for the given character */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
54 while ( (p >= str) && (*p != (CHAR)c) ) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
55 p--; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
56 |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
57 /* Return NULL if character not found */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
58 if ( p < str ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
59 p = NULL; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
60 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
61 return p; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
62 } |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
63 #endif /* _WIN32_WCE < 300 */ |
0 | 64 |
65 /* Parse a command line buffer into arguments */ | |
66 static int ParseCommandLine(char *cmdline, char **argv) | |
67 { | |
68 char *bufp; | |
69 int argc; | |
70 | |
71 argc = 0; | |
72 for ( bufp = cmdline; *bufp; ) { | |
73 /* Skip leading whitespace */ | |
74 while ( isspace(*bufp) ) { | |
75 ++bufp; | |
76 } | |
77 /* Skip over argument */ | |
78 if ( *bufp == '"' ) { | |
79 ++bufp; | |
80 if ( *bufp ) { | |
81 if ( argv ) { | |
82 argv[argc] = bufp; | |
83 } | |
84 ++argc; | |
85 } | |
86 /* Skip over word */ | |
87 while ( *bufp && (*bufp != '"') ) { | |
88 ++bufp; | |
89 } | |
90 } else { | |
91 if ( *bufp ) { | |
92 if ( argv ) { | |
93 argv[argc] = bufp; | |
94 } | |
95 ++argc; | |
96 } | |
97 /* Skip over word */ | |
98 while ( *bufp && ! isspace(*bufp) ) { | |
99 ++bufp; | |
100 } | |
101 } | |
102 if ( *bufp ) { | |
103 if ( argv ) { | |
104 *bufp = '\0'; | |
105 } | |
106 ++bufp; | |
107 } | |
108 } | |
109 if ( argv ) { | |
110 argv[argc] = NULL; | |
111 } | |
112 return(argc); | |
113 } | |
114 | |
115 /* Show an error message */ | |
116 static void ShowError(const char *title, const char *message) | |
117 { | |
118 /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ | |
119 #ifdef USE_MESSAGEBOX | |
120 MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); | |
121 #else | |
122 fprintf(stderr, "%s: %s\n", title, message); | |
123 #endif | |
124 } | |
125 | |
126 /* Pop up an out of memory message, returns to Windows */ | |
127 static BOOL OutOfMemory(void) | |
128 { | |
129 ShowError("Fatal Error", "Out of memory - aborting"); | |
130 return FALSE; | |
131 } | |
132 | |
133 /* Remove the output files if there was no output written */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
134 static void __cdecl cleanup_output(void) |
0 | 135 { |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
136 #ifndef NO_STDIO_REDIRECT |
0 | 137 FILE *file; |
138 int empty; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
139 #endif |
0 | 140 |
141 /* Flush the output in case anything is queued */ | |
142 fclose(stdout); | |
143 fclose(stderr); | |
144 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
145 #ifndef NO_STDIO_REDIRECT |
0 | 146 /* See if the files have any output in them */ |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
147 file = fopen(stdoutPath, "rb"); |
0 | 148 if ( file ) { |
149 empty = (fgetc(file) == EOF) ? 1 : 0; | |
150 fclose(file); | |
151 if ( empty ) { | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
152 remove(stdoutPath); |
0 | 153 } |
154 } | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
155 file = fopen(stderrPath, "rb"); |
0 | 156 if ( file ) { |
157 empty = (fgetc(file) == EOF) ? 1 : 0; | |
158 fclose(file); | |
159 if ( empty ) { | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
160 remove(stderrPath); |
0 | 161 } |
162 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
163 #endif |
0 | 164 } |
165 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
166 #if defined(_MSC_VER) && !defined(_WIN32_WCE) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
167 /* The VC++ compiler needs main defined */ |
0 | 168 #define console_main main |
169 #endif | |
170 | |
171 /* This is where execution begins [console apps] */ | |
172 int console_main(int argc, char *argv[]) | |
173 { | |
174 int n; | |
175 char *bufp, *appname; | |
176 | |
177 /* Get the class name from argv[0] */ | |
178 appname = argv[0]; | |
179 if ( (bufp=strrchr(argv[0], '\\')) != NULL ) { | |
180 appname = bufp+1; | |
181 } else | |
182 if ( (bufp=strrchr(argv[0], '/')) != NULL ) { | |
183 appname = bufp+1; | |
184 } | |
185 | |
186 if ( (bufp=strrchr(appname, '.')) == NULL ) | |
187 n = strlen(appname); | |
188 else | |
189 n = (bufp-appname); | |
190 | |
191 bufp = (char *)alloca(n+1); | |
192 if ( bufp == NULL ) { | |
193 return OutOfMemory(); | |
194 } | |
195 strncpy(bufp, appname, n); | |
196 bufp[n] = '\0'; | |
197 appname = bufp; | |
198 | |
199 /* Load SDL dynamic link library */ | |
200 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { | |
201 ShowError("WinMain() error", SDL_GetError()); | |
202 return(FALSE); | |
203 } | |
204 atexit(cleanup_output); | |
205 atexit(SDL_Quit); | |
206 | |
15
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
207 #ifndef DISABLE_VIDEO |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
208 #if 0 |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
209 /* Create and register our class * |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
210 DJM: If we do this here, the user nevers gets a chance to |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
211 putenv(SDL_WINDOWID). This is already called later by |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
212 the (DIB|DX5)_CreateWindow function, so it should be |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
213 safe to comment it out here. |
0 | 214 if ( SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, |
215 GetModuleHandle(NULL)) < 0 ) { | |
216 ShowError("WinMain() error", SDL_GetError()); | |
217 exit(1); | |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
218 }*/ |
149
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
219 #else |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
220 /* Sam: |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
221 We still need to pass in the application handle so that |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
222 DirectInput will initialize properly when SDL_RegisterApp() |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
223 is called later in the video initialization. |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
224 */ |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
225 SDL_SetModuleHandle(GetModuleHandle(NULL)); |
0e66fd980014
Fixed compile errors and added call to SDL_SetModuleHandle() in WinMain()
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
226 #endif /* 0 */ |
15
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
227 #endif /* !DISABLE_VIDEO */ |
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
228 |
ac67f6758d63
Don't try to register the app if video code is disabled
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
229 /* Run the application main() code */ |
0 | 230 SDL_main(argc, argv); |
231 | |
232 /* Exit cleanly, calling atexit() functions */ | |
233 exit(0); | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
234 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
235 /* Hush little compiler, don't you cry... */ |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
149
diff
changeset
|
236 return(0); |
0 | 237 } |
238 | |
239 /* This is where execution begins [windowed apps] */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
240 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
241 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
242 #else |
0 | 243 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
244 #endif |
0 | 245 { |
246 HINSTANCE handle; | |
247 char **argv; | |
248 int argc; | |
249 char *cmdline; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
250 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
251 wchar_t *bufp; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
252 int nLen; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
253 #else |
0 | 254 char *bufp; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
255 #endif |
0 | 256 #ifndef NO_STDIO_REDIRECT |
257 FILE *newfp; | |
258 #endif | |
259 | |
260 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't | |
261 keep them open. This is a hack.. hopefully it will be fixed | |
262 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. | |
263 */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
264 handle = LoadLibrary(TEXT("DDRAW.DLL")); |
0 | 265 if ( handle != NULL ) { |
266 FreeLibrary(handle); | |
267 } | |
268 | |
269 #ifndef NO_STDIO_REDIRECT | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
270 _getcwd( stdoutPath, sizeof( stdoutPath ) ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
271 strcat( stdoutPath, "/" STDOUT_FILE ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
272 |
0 | 273 /* Redirect standard input and standard output */ |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
274 newfp = freopen(stdoutPath, "w", stdout); |
0 | 275 if ( newfp == NULL ) { /* This happens on NT */ |
276 #if !defined(stdout) | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
277 stdout = fopen(stdoutPath, "w"); |
0 | 278 #else |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
279 newfp = fopen(stdoutPath, "w"); |
0 | 280 if ( newfp ) { |
281 *stdout = *newfp; | |
282 } | |
283 #endif | |
284 } | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
285 |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
286 _getcwd( stderrPath, sizeof( stderrPath ) ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
287 strcat( stderrPath, "/" STDERR_FILE ); |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
288 |
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
289 newfp = freopen(stderrPath, "w", stderr); |
0 | 290 if ( newfp == NULL ) { /* This happens on NT */ |
291 #if !defined(stderr) | |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
292 stderr = fopen(stderrPath, "w"); |
0 | 293 #else |
545
8406511f850e
Save the full pathname for stdout.txt and stderr.txt
Sam Lantinga <slouken@libsdl.org>
parents:
505
diff
changeset
|
294 newfp = fopen(stderrPath, "w"); |
0 | 295 if ( newfp ) { |
296 *stderr = *newfp; | |
297 } | |
298 #endif | |
299 } | |
300 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ | |
301 setbuf(stderr, NULL); /* No buffering */ | |
302 #endif /* !NO_STDIO_REDIRECT */ | |
303 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
304 #ifdef _WIN32_WCE |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
305 nLen = wcslen(szCmdLine)+128+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
306 bufp = (wchar_t *)alloca(nLen*2); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
307 wcscpy (bufp, TEXT("\"")); |
504
8c4a35e3c507
Fixed SDL_main.c on Windows CE with applications containing spaces in their names.
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
308 GetModuleFileName(NULL, bufp+1, 128-3); |
505
6b34c9dcf74c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
504
diff
changeset
|
309 wcscpy (bufp+wcslen(bufp), TEXT("\" ")); |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
310 wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
311 nLen = wcslen(bufp)+1; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
312 cmdline = (char *)alloca(nLen); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
313 if ( cmdline == NULL ) { |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
314 return OutOfMemory(); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
315 } |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
316 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
317 #else |
0 | 318 /* Grab the command line (use alloca() on Windows) */ |
319 bufp = GetCommandLine(); | |
320 cmdline = (char *)alloca(strlen(bufp)+1); | |
321 if ( cmdline == NULL ) { | |
322 return OutOfMemory(); | |
323 } | |
324 strcpy(cmdline, bufp); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
15
diff
changeset
|
325 #endif |
0 | 326 |
327 /* Parse it into argv and argc */ | |
328 argc = ParseCommandLine(cmdline, NULL); | |
329 argv = (char **)alloca((argc+1)*(sizeof *argv)); | |
330 if ( argv == NULL ) { | |
331 return OutOfMemory(); | |
332 } | |
333 ParseCommandLine(cmdline, argv); | |
334 | |
335 /* Run the main program (after a little SDL initialization) */ | |
336 return(console_main(argc, argv)); | |
337 } |