annotate src/main/win32/SDL_main.c @ 617:86e0385b8f96

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