comparison src/main/win32/SDL_main.c @ 36:13ee9f4834ea

Windows CE patches contributed by Rainer Loritz
author Sam Lantinga <slouken@lokigames.com>
date Wed, 23 May 2001 23:35:10 +0000
parents ac67f6758d63
children 9ef74357a5fb
comparison
equal deleted inserted replaced
35:d3bc792e136d 36:13ee9f4834ea
17 #include "SDL_main.h" 17 #include "SDL_main.h"
18 #ifdef main 18 #ifdef main
19 #undef main 19 #undef main
20 #endif 20 #endif
21 21
22 /* Do we really not want stdio redirection with Windows CE? */
23 #ifdef _WIN32_WCE
24 #define NO_STDIO_REDIRECT
25 #endif
26
22 /* The standard output files */ 27 /* The standard output files */
23 #define STDOUT_FILE "stdout.txt" 28 #define STDOUT_FILE TEXT("stdout.txt")
24 #define STDERR_FILE "stderr.txt" 29 #define STDERR_FILE TEXT("stderr.txt")
30
31 #ifdef _WIN32_WCE
32 /* seems to be undefined in Win CE although in online help */
33 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
34
35 /* seems to be undefined in Win CE although in online help */
36 char *strrchr(char *str, int c)
37 {
38 char *p;
39
40 /* Skip to the end of the string */
41 p=str;
42 while (*p)
43 p++;
44
45 /* Look for the given character */
46 while ( (p >= str) && (*p != (CHAR)c) )
47 p--;
48
49 /* Return NULL if character not found */
50 if ( p < str ) {
51 p = NULL;
52 }
53 return p;
54 }
55 #endif /* _WIN32_WCE */
25 56
26 /* Parse a command line buffer into arguments */ 57 /* Parse a command line buffer into arguments */
27 static int ParseCommandLine(char *cmdline, char **argv) 58 static int ParseCommandLine(char *cmdline, char **argv)
28 { 59 {
29 char *bufp; 60 char *bufp;
90 ShowError("Fatal Error", "Out of memory - aborting"); 121 ShowError("Fatal Error", "Out of memory - aborting");
91 return FALSE; 122 return FALSE;
92 } 123 }
93 124
94 /* Remove the output files if there was no output written */ 125 /* Remove the output files if there was no output written */
95 static void cleanup_output(void) 126 static void __cdecl cleanup_output(void)
96 { 127 {
128 #ifndef NO_STDIO_REDIRECT
97 FILE *file; 129 FILE *file;
98 int empty; 130 int empty;
131 #endif
99 132
100 /* Flush the output in case anything is queued */ 133 /* Flush the output in case anything is queued */
101 fclose(stdout); 134 fclose(stdout);
102 fclose(stderr); 135 fclose(stderr);
103 136
137 #ifndef NO_STDIO_REDIRECT
104 /* See if the files have any output in them */ 138 /* See if the files have any output in them */
105 file = fopen(STDOUT_FILE, "rb"); 139 file = fopen(STDOUT_FILE, "rb");
106 if ( file ) { 140 if ( file ) {
107 empty = (fgetc(file) == EOF) ? 1 : 0; 141 empty = (fgetc(file) == EOF) ? 1 : 0;
108 fclose(file); 142 fclose(file);
116 fclose(file); 150 fclose(file);
117 if ( empty ) { 151 if ( empty ) {
118 remove(STDERR_FILE); 152 remove(STDERR_FILE);
119 } 153 }
120 } 154 }
121 } 155 #endif
122 156 }
123 #ifdef _MSC_VER /* The VC++ compiler needs main defined */ 157
158 #if defined(_MSC_VER) && !defined(_WIN32_WCE)
159 /* The VC++ compiler needs main defined */
124 #define console_main main 160 #define console_main main
125 #endif 161 #endif
126 162
127 /* This is where execution begins [console apps] */ 163 /* This is where execution begins [console apps] */
128 int console_main(int argc, char *argv[]) 164 int console_main(int argc, char *argv[])
175 /* Exit cleanly, calling atexit() functions */ 211 /* Exit cleanly, calling atexit() functions */
176 exit(0); 212 exit(0);
177 } 213 }
178 214
179 /* This is where execution begins [windowed apps] */ 215 /* This is where execution begins [windowed apps] */
216 #ifdef _WIN32_WCE
217 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
218 #else
180 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) 219 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
220 #endif
181 { 221 {
182 HINSTANCE handle; 222 HINSTANCE handle;
183 char **argv; 223 char **argv;
184 int argc; 224 int argc;
185 char *cmdline; 225 char *cmdline;
226 #ifdef _WIN32_WCE
227 wchar_t *bufp;
228 int nLen;
229 #else
186 char *bufp; 230 char *bufp;
231 #endif
187 #ifndef NO_STDIO_REDIRECT 232 #ifndef NO_STDIO_REDIRECT
188 FILE *newfp; 233 FILE *newfp;
189 #endif 234 #endif
190 235
191 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't 236 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
192 keep them open. This is a hack.. hopefully it will be fixed 237 keep them open. This is a hack.. hopefully it will be fixed
193 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. 238 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
194 */ 239 */
195 handle = LoadLibrary("DDRAW.DLL"); 240 handle = LoadLibrary(TEXT("DDRAW.DLL"));
196 if ( handle != NULL ) { 241 if ( handle != NULL ) {
197 FreeLibrary(handle); 242 FreeLibrary(handle);
198 } 243 }
199 244
200 #ifndef NO_STDIO_REDIRECT 245 #ifndef NO_STDIO_REDIRECT
223 } 268 }
224 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ 269 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */
225 setbuf(stderr, NULL); /* No buffering */ 270 setbuf(stderr, NULL); /* No buffering */
226 #endif /* !NO_STDIO_REDIRECT */ 271 #endif /* !NO_STDIO_REDIRECT */
227 272
273 #ifdef _WIN32_WCE
274 nLen = wcslen(szCmdLine)+128+1;
275 bufp = (wchar_t *)alloca(nLen*2);
276 GetModuleFileName(NULL, bufp, 128);
277 wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen);
278 nLen = wcslen(bufp)+1;
279 cmdline = (char *)alloca(nLen);
280 if ( cmdline == NULL ) {
281 return OutOfMemory();
282 }
283 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
284 #else
228 /* Grab the command line (use alloca() on Windows) */ 285 /* Grab the command line (use alloca() on Windows) */
229 bufp = GetCommandLine(); 286 bufp = GetCommandLine();
230 cmdline = (char *)alloca(strlen(bufp)+1); 287 cmdline = (char *)alloca(strlen(bufp)+1);
231 if ( cmdline == NULL ) { 288 if ( cmdline == NULL ) {
232 return OutOfMemory(); 289 return OutOfMemory();
233 } 290 }
234 strcpy(cmdline, bufp); 291 strcpy(cmdline, bufp);
292 #endif
235 293
236 /* Parse it into argv and argc */ 294 /* Parse it into argv and argc */
237 argc = ParseCommandLine(cmdline, NULL); 295 argc = ParseCommandLine(cmdline, NULL);
238 argv = (char **)alloca((argc+1)*(sizeof *argv)); 296 argv = (char **)alloca((argc+1)*(sizeof *argv));
239 if ( argv == NULL ) { 297 if ( argv == NULL ) {