Mercurial > sdl-ios-xcode
annotate src/main/win32/SDL_win32_main.c @ 4372:ca91f36ef3de SDL-1.2
1.2 branch: fixed assembly code register clobbering.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 01 Nov 2009 17:51:39 +0000 |
parents | 8b8314cc34a6 |
children |
rev | line source |
---|---|
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL_main.c, placed in the public domain by Sam Lantinga 4/13/98 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 The WinMain function -- calls your program's main() function |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
1433
bb6839704ed6
SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents:
1423
diff
changeset
|
10 #define WIN32_LEAN_AND_MEAN |
bb6839704ed6
SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents:
1423
diff
changeset
|
11 #include <windows.h> |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1286
diff
changeset
|
12 |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 # define DIR_SEPERATOR TEXT("\\") |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
754
diff
changeset
|
15 # undef _getcwd |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
754
diff
changeset
|
16 # define _getcwd(str,len) wcscpy(str,TEXT("")) |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
754
diff
changeset
|
17 # define setbuf(f,b) |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
754
diff
changeset
|
18 # define setvbuf(w,x,y,z) |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 # define fopen _wfopen |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 # define freopen _wfreopen |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 # define remove(x) DeleteFile(x) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 # define DIR_SEPERATOR TEXT("/") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 # include <direct.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 /* Include the SDL main definition header */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "SDL.h" |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "SDL_main.h" |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #ifdef main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 # ifndef _WIN32_WCE_EMULATION |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 # undef main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 # endif /* _WIN32_WCE_EMULATION */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 #endif /* main */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 /* The standard output files */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 #define STDOUT_FILE TEXT("stdout.txt") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 #define STDERR_FILE TEXT("stderr.txt") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
4246 | 41 /* Set a variable to tell if the stdio redirect has been enabled. */ |
42 static int stdioRedirectEnabled = 0; | |
43 | |
44 #ifdef _WIN32_WCE | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 static wchar_t stdoutPath[MAX_PATH]; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 static wchar_t stderrPath[MAX_PATH]; |
4246 | 47 #else |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 static char stdoutPath[MAX_PATH]; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 static char stderrPath[MAX_PATH]; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 /* seems to be undefined in Win CE although in online help */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 #endif /* _WIN32_WCE < 300 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 |
4118
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
57 static void UnEscapeQuotes( char *arg ) |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
58 { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
59 char *last = NULL; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
60 |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
61 while( *arg ) { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
62 if( *arg == '"' && *last == '\\' ) { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
63 char *c_curr = arg; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
64 char *c_last = last; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
65 |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
66 while( *c_curr ) { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
67 *c_last = *c_curr; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
68 c_last = c_curr; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
69 c_curr++; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
70 } |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
71 *c_last = '\0'; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
72 } |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
73 last = arg; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
74 arg++; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
75 } |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
76 } |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
77 |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 /* Parse a command line buffer into arguments */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 static int ParseCommandLine(char *cmdline, char **argv) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 char *bufp; |
4118
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
82 char *lastp = NULL; |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
83 int argc, last_argc; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
4118
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
85 argc = last_argc = 0; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 for ( bufp = cmdline; *bufp; ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 /* Skip leading whitespace */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 while ( isspace(*bufp) ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 /* Skip over argument */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 if ( *bufp == '"' ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 if ( *bufp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 argv[argc] = bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 ++argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 /* Skip over word */ |
4118
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
101 while ( *bufp && ( *bufp != '"' || *lastp == '\\' ) ) { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
102 lastp = bufp; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 } else { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 if ( *bufp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 argv[argc] = bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 ++argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 /* Skip over word */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 while ( *bufp && ! isspace(*bufp) ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 if ( *bufp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 *bufp = '\0'; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
4118
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
123 |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
124 /* Strip out \ from \" sequences */ |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
125 if( argv && last_argc != argc ) { |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
126 UnEscapeQuotes( argv[last_argc] ); |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
127 } |
3c068a8c016f
Tony White fixed bug #503
Sam Lantinga <slouken@libsdl.org>
parents:
4084
diff
changeset
|
128 last_argc = argc; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 argv[argc] = NULL; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 return(argc); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 /* Show an error message */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 static void ShowError(const char *title, const char *message) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 #ifdef USE_MESSAGEBOX |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 fprintf(stderr, "%s: %s\n", title, message); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 /* Pop up an out of memory message, returns to Windows */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 static BOOL OutOfMemory(void) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 ShowError("Fatal Error", "Out of memory - aborting"); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 return FALSE; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 |
1769 | 154 /* SDL_Quit() shouldn't be used with atexit() directly because |
155 calling conventions may differ... */ | |
156 static void cleanup(void) | |
157 { | |
158 SDL_Quit(); | |
159 } | |
160 | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 /* Remove the output files if there was no output written */ |
4246 | 162 static void cleanup_output(void) { |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 FILE *file; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 int empty; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 /* Flush the output in case anything is queued */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 fclose(stdout); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 fclose(stderr); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 |
4246 | 170 /* Without redirection we're done */ |
171 if (!stdioRedirectEnabled) { | |
172 return; | |
173 } | |
174 | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 /* See if the files have any output in them */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 if ( stdoutPath[0] ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 file = fopen(stdoutPath, TEXT("rb")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 if ( file ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 empty = (fgetc(file) == EOF) ? 1 : 0; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 fclose(file); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 if ( empty ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 remove(stdoutPath); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 if ( stderrPath[0] ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 file = fopen(stderrPath, TEXT("rb")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 if ( file ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 empty = (fgetc(file) == EOF) ? 1 : 0; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 fclose(file); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 if ( empty ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 remove(stderrPath); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 } |
4246 | 196 } |
197 | |
198 /* Redirect the output (stdout and stderr) to a file */ | |
199 static void redirect_output(void) | |
200 { | |
201 DWORD pathlen; | |
202 #ifdef _WIN32_WCE | |
203 wchar_t path[MAX_PATH]; | |
204 #else | |
205 char path[MAX_PATH]; | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 #endif |
4246 | 207 FILE *newfp; |
208 | |
209 pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path)); | |
210 while ( pathlen > 0 && path[pathlen] != '\\' ) { | |
211 --pathlen; | |
212 } | |
213 path[pathlen] = '\0'; | |
214 | |
215 #ifdef _WIN32_WCE | |
216 wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); | |
217 wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | |
218 #else | |
219 SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) ); | |
220 SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | |
221 #endif | |
222 | |
223 /* Redirect standard input and standard output */ | |
224 newfp = freopen(stdoutPath, TEXT("w"), stdout); | |
225 | |
226 #ifndef _WIN32_WCE | |
227 if ( newfp == NULL ) { /* This happens on NT */ | |
228 #if !defined(stdout) | |
229 stdout = fopen(stdoutPath, TEXT("w")); | |
230 #else | |
231 newfp = fopen(stdoutPath, TEXT("w")); | |
232 if ( newfp ) { | |
233 *stdout = *newfp; | |
234 } | |
235 #endif | |
236 } | |
237 #endif /* _WIN32_WCE */ | |
238 | |
239 #ifdef _WIN32_WCE | |
240 wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) ); | |
241 wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) ); | |
242 #else | |
243 SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) ); | |
244 SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) ); | |
245 #endif | |
246 | |
247 newfp = freopen(stderrPath, TEXT("w"), stderr); | |
248 #ifndef _WIN32_WCE | |
249 if ( newfp == NULL ) { /* This happens on NT */ | |
250 #if !defined(stderr) | |
251 stderr = fopen(stderrPath, TEXT("w")); | |
252 #else | |
253 newfp = fopen(stderrPath, TEXT("w")); | |
254 if ( newfp ) { | |
255 *stderr = *newfp; | |
256 } | |
257 #endif | |
258 } | |
259 #endif /* _WIN32_WCE */ | |
260 | |
261 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ | |
262 setbuf(stderr, NULL); /* No buffering */ | |
263 stdioRedirectEnabled = 1; | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 #if defined(_MSC_VER) && !defined(_WIN32_WCE) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 /* The VC++ compiler needs main defined */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 #define console_main main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 /* This is where execution begins [console apps] */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 int console_main(int argc, char *argv[]) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 { |
1472
4aac8563c296
Fixed more Win64 portability issues
Sam Lantinga <slouken@libsdl.org>
parents:
1465
diff
changeset
|
274 size_t n; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 char *bufp, *appname; |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
276 int status; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 /* Get the class name from argv[0] */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 appname = argv[0]; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1286
diff
changeset
|
280 if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) { |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 appname = bufp+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 } else |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1286
diff
changeset
|
283 if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) { |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 appname = bufp+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1286
diff
changeset
|
287 if ( (bufp=SDL_strrchr(appname, '.')) == NULL ) |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1286
diff
changeset
|
288 n = SDL_strlen(appname); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 n = (bufp-appname); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
292 bufp = SDL_stack_alloc(char, n+1); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 if ( bufp == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 } |
1769 | 296 SDL_strlcpy(bufp, appname, n+1); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 appname = bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 /* Load SDL dynamic link library */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 ShowError("WinMain() error", SDL_GetError()); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 return(FALSE); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 atexit(cleanup_output); |
1769 | 305 atexit(cleanup); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 /* Sam: |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 We still need to pass in the application handle so that |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 DirectInput will initialize properly when SDL_RegisterApp() |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 is called later in the video initialization. |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 SDL_SetModuleHandle(GetModuleHandle(NULL)); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 /* Run the application main() code */ |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
315 status = SDL_main(argc, argv); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 /* Exit cleanly, calling atexit() functions */ |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
318 exit(status); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 /* Hush little compiler, don't you cry... */ |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
321 return 0; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 /* This is where execution begins [windowed apps] */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 HINSTANCE handle; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 char **argv; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 int argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 char *cmdline; |
4246 | 335 char *env_str; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 wchar_t *bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 int nLen; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 char *bufp; |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
341 size_t nLen; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 keep them open. This is a hack.. hopefully it will be fixed |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded. |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 handle = LoadLibrary(TEXT("DDRAW.DLL")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 if ( handle != NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 FreeLibrary(handle); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 |
4246 | 353 /* Check for stdio redirect settings and do the redirection */ |
354 if ((env_str = SDL_getenv("SDL_STDIO_REDIRECT"))) { | |
355 if (SDL_atoi(env_str)) { | |
356 redirect_output(); | |
357 } | |
1286
d7bca8c8161e
Use the executable directory, not the current directory, for stdio output files
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
358 } |
4246 | 359 #ifndef NO_STDIO_REDIRECT |
360 else { | |
361 redirect_output(); | |
362 } | |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 nLen = wcslen(szCmdLine)+128+1; |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
367 bufp = SDL_stack_alloc(wchar_t, nLen*2); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 wcscpy (bufp, TEXT("\"")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 GetModuleFileName(NULL, bufp+1, 128-3); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 wcscpy (bufp+wcslen(bufp), TEXT("\" ")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp)); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 nLen = wcslen(bufp)+1; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1433
diff
changeset
|
373 cmdline = SDL_stack_alloc(char, nLen); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 if ( cmdline == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 #else |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
379 /* Grab the command line */ |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 bufp = GetCommandLine(); |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
381 nLen = SDL_strlen(bufp)+1; |
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
382 cmdline = SDL_stack_alloc(char, nLen); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 if ( cmdline == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 } |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
386 SDL_strlcpy(cmdline, bufp, nLen); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 /* Parse it into argv and argc */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 argc = ParseCommandLine(cmdline, NULL); |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
391 argv = SDL_stack_alloc(char*, argc+1); |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 if ( argv == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 ParseCommandLine(cmdline, argv); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 /* Run the main program (after a little SDL initialization) */ |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
398 console_main(argc, argv); |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
399 |
1423
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
400 /* Hush little compiler, don't you cry... */ |
4ed717f9e509
Updated for Visual Studio Express 2005
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
401 return 0; |
754
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 } |