comparison src/main/win32/SDL_main.c @ 575:1f6438c8df2c

Applied Corona688's patch for output redirection on Windows CE
author Sam Lantinga <slouken@libsdl.org>
date Tue, 21 Jan 2003 04:15:21 +0000
parents 0ac20b67c2c7
children
comparison
equal deleted inserted replaced
574:64fe373be3dc 575:1f6438c8df2c
1 /* 1 /*
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98
3 3
4 The WinMain function -- calls your program's main() function 4 The WinMain function -- calls your program's main() function
5 */ 5 */
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 #include <ctype.h> 9 #include <ctype.h>
10 #include <stdlib.h> 10 #include <stdlib.h>
11 11
12 #include <windows.h> 12 #include <windows.h>
13 #include <malloc.h> /* For _alloca() */ 13 #include <malloc.h> /* For _alloca() */
14 #include <io.h> /* For _getcwd() */ 14
15 #ifdef _WIN32_WCE
16 # define DIR_SEPERATOR TEXT("\\")
17 # define _getcwd(str,len) wcscpy(str,DIR_SEPERATOR);
18 # define setbuf(x)
19 # define setvbuf(x)
20 # define fopen _wfopen
21 # define freopen _wfreopen
22 # define remove(x) DeleteFile(x)
23 # define strcat wcscat
24 #else
25 # define DIR_SEPERATOR TEXT("/")
26 # include <direct.h>
27 #endif
15 28
16 /* Include the SDL main definition header */ 29 /* Include the SDL main definition header */
17 #include "SDL.h" 30 #include "SDL.h"
18 #include "SDL_main.h" 31 #include "SDL_main.h"
32
19 #ifdef main 33 #ifdef main
20 #ifndef _WIN32_WCE_EMULATION 34 # ifndef _WIN32_WCE_EMULATION
21 #undef main 35 # undef main
22 #endif 36 # endif /* _WIN32_WCE_EMULATION */
23 #endif 37 #endif /* main */
24
25 /* Do we really not want stdio redirection with Windows CE? */
26 #ifdef _WIN32_WCE
27 #define NO_STDIO_REDIRECT
28 #endif
29 38
30 /* The standard output files */ 39 /* The standard output files */
31 #define STDOUT_FILE TEXT("stdout.txt") 40 #define STDOUT_FILE TEXT("stdout.txt")
32 #define STDERR_FILE TEXT("stderr.txt") 41 #define STDERR_FILE TEXT("stderr.txt")
33 42
34 #ifndef NO_STDIO_REDIRECT 43 #ifndef NO_STDIO_REDIRECT
35 static char stdoutPath[MAX_PATH]; 44 # ifdef _WIN32_WCE
36 static char stderrPath[MAX_PATH]; 45 static wchar_t stdoutPath[MAX_PATH];
46 static wchar_t stderrPath[MAX_PATH];
47 # else
48 static char stdoutPath[MAX_PATH];
49 static char stderrPath[MAX_PATH];
50 # endif
37 #endif 51 #endif
38 52
39 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 53 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
40 /* seems to be undefined in Win CE although in online help */ 54 /* seems to be undefined in Win CE although in online help */
41 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) 55 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
143 fclose(stderr); 157 fclose(stderr);
144 158
145 #ifndef NO_STDIO_REDIRECT 159 #ifndef NO_STDIO_REDIRECT
146 /* See if the files have any output in them */ 160 /* See if the files have any output in them */
147 if ( stdoutPath[0] ) { 161 if ( stdoutPath[0] ) {
148 file = fopen(stdoutPath, "rb"); 162 file = fopen(stdoutPath, TEXT("rb"));
149 if ( file ) { 163 if ( file ) {
150 empty = (fgetc(file) == EOF) ? 1 : 0; 164 empty = (fgetc(file) == EOF) ? 1 : 0;
151 fclose(file); 165 fclose(file);
152 if ( empty ) { 166 if ( empty ) {
153 remove(stdoutPath); 167 remove(stdoutPath);
154 } 168 }
155 } 169 }
156 } 170 }
157 if ( stderrPath[0] ) { 171 if ( stderrPath[0] ) {
158 file = fopen(stderrPath, "rb"); 172 file = fopen(stderrPath, TEXT("rb"));
159 if ( file ) { 173 if ( file ) {
160 empty = (fgetc(file) == EOF) ? 1 : 0; 174 empty = (fgetc(file) == EOF) ? 1 : 0;
161 fclose(file); 175 fclose(file);
162 if ( empty ) { 176 if ( empty ) {
163 remove(stderrPath); 177 remove(stderrPath);
270 FreeLibrary(handle); 284 FreeLibrary(handle);
271 } 285 }
272 286
273 #ifndef NO_STDIO_REDIRECT 287 #ifndef NO_STDIO_REDIRECT
274 _getcwd( stdoutPath, sizeof( stdoutPath ) ); 288 _getcwd( stdoutPath, sizeof( stdoutPath ) );
275 strcat( stdoutPath, "/" STDOUT_FILE ); 289 strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
276 290
277 /* Redirect standard input and standard output */ 291 /* Redirect standard input and standard output */
278 newfp = freopen(stdoutPath, "w", stdout); 292 newfp = freopen(stdoutPath, TEXT("w"), stdout);
293
294 #ifndef _WIN32_WCE
279 if ( newfp == NULL ) { /* This happens on NT */ 295 if ( newfp == NULL ) { /* This happens on NT */
280 #if !defined(stdout) 296 #if !defined(stdout)
281 stdout = fopen(stdoutPath, "w"); 297 stdout = fopen(stdoutPath, TEXT("w"));
282 #else 298 #else
283 newfp = fopen(stdoutPath, "w"); 299 newfp = fopen(stdoutPath, TEXT("w"));
284 if ( newfp ) { 300 if ( newfp ) {
285 *stdout = *newfp; 301 *stdout = *newfp;
286 } 302 }
287 #endif 303 #endif
288 } 304 }
305 #endif /* _WIN32_WCE */
289 306
290 _getcwd( stderrPath, sizeof( stderrPath ) ); 307 _getcwd( stderrPath, sizeof( stderrPath ) );
291 strcat( stderrPath, "/" STDERR_FILE ); 308 strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
292 309
293 newfp = freopen(stderrPath, "w", stderr); 310 newfp = freopen(stderrPath, TEXT("w"), stderr);
311 #ifndef _WIN32_WCE
294 if ( newfp == NULL ) { /* This happens on NT */ 312 if ( newfp == NULL ) { /* This happens on NT */
295 #if !defined(stderr) 313 #if !defined(stderr)
296 stderr = fopen(stderrPath, "w"); 314 stderr = fopen(stderrPath, TEXT("w"));
297 #else 315 #else
298 newfp = fopen(stderrPath, "w"); 316 newfp = fopen(stderrPath, TEXT("w"));
299 if ( newfp ) { 317 if ( newfp ) {
300 *stderr = *newfp; 318 *stderr = *newfp;
301 } 319 }
302 #endif 320 #endif
303 } 321 }
322 #endif /* _WIN32_WCE */
323
304 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ 324 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */
305 setbuf(stderr, NULL); /* No buffering */ 325 setbuf(stderr, NULL); /* No buffering */
306 #endif /* !NO_STDIO_REDIRECT */ 326 #endif /* !NO_STDIO_REDIRECT */
307 327
308 #ifdef _WIN32_WCE 328 #ifdef _WIN32_WCE