Mercurial > sdl-ios-xcode
annotate src/main/win32/SDL_win32_main.c @ 754:623b453a3219
Fixed "dist" make target for newer versions of automake
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 14 Dec 2003 06:25:53 +0000 |
parents | |
children | ed57c876700d |
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 <string.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 #include <ctype.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 #include <windows.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 #include <malloc.h> /* For _alloca() */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 # define DIR_SEPERATOR TEXT("\\") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 # define _getcwd(str,len) wcscpy(str,DIR_SEPERATOR); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 # define setbuf(x) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 # define setvbuf(x) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 # define fopen _wfopen |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 # define freopen _wfreopen |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 # define remove(x) DeleteFile(x) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 # define strcat wcscat |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 # define DIR_SEPERATOR TEXT("/") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 # include <direct.h> |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 /* Include the SDL main definition header */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "SDL.h" |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #include "SDL_main.h" |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #ifdef main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 # ifndef _WIN32_WCE_EMULATION |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 # undef main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 # endif /* _WIN32_WCE_EMULATION */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 #endif /* main */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 /* The standard output files */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 #define STDOUT_FILE TEXT("stdout.txt") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 #define STDERR_FILE TEXT("stderr.txt") |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 #ifndef NO_STDIO_REDIRECT |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 # ifdef _WIN32_WCE |
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]; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 # else |
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 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 #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
|
54 /* 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
|
55 #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
|
56 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 /* 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
|
58 char *strrchr(char *str, int c) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 char *p; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 /* Skip to the end of the string */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 p=str; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 while (*p) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 p++; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 /* Look for the given character */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 while ( (p >= str) && (*p != (CHAR)c) ) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 p--; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 /* Return NULL if character not found */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 if ( p < str ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 p = NULL; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 return p; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 #endif /* _WIN32_WCE < 300 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 /* 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
|
80 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
|
81 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 char *bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 int argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 argc = 0; |
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 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 while ( *bufp && (*bufp != '"') ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } else { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 if ( *bufp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 argv[argc] = bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 ++argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 /* Skip over word */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 while ( *bufp && ! isspace(*bufp) ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 } |
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 if ( *bufp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 *bufp = '\0'; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 ++bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 if ( argv ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 argv[argc] = NULL; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 return(argc); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 /* Show an error message */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 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
|
131 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 /* 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
|
133 #ifdef USE_MESSAGEBOX |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 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
|
135 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 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
|
137 #endif |
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 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 /* 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
|
141 static BOOL OutOfMemory(void) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 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
|
144 return FALSE; |
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 /* Remove the output files if there was no output written */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 static void __cdecl cleanup_output(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 #ifndef NO_STDIO_REDIRECT |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 FILE *file; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 int empty; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 /* 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
|
156 fclose(stdout); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 fclose(stderr); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 #ifndef NO_STDIO_REDIRECT |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 /* 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
|
161 if ( stdoutPath[0] ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 file = fopen(stdoutPath, TEXT("rb")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 if ( file ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 empty = (fgetc(file) == EOF) ? 1 : 0; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 fclose(file); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 if ( empty ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 remove(stdoutPath); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 if ( stderrPath[0] ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 file = fopen(stderrPath, TEXT("rb")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 if ( file ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 empty = (fgetc(file) == EOF) ? 1 : 0; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 fclose(file); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 if ( empty ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 remove(stderrPath); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 } |
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 #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
|
185 /* The VC++ compiler needs main defined */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 #define console_main main |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 /* 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
|
190 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
|
191 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 int n; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 char *bufp, *appname; |
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 /* 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
|
196 appname = argv[0]; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 if ( (bufp=strrchr(argv[0], '\\')) != NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 appname = bufp+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 } else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 if ( (bufp=strrchr(argv[0], '/')) != NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 appname = bufp+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 if ( (bufp=strrchr(appname, '.')) == NULL ) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 n = strlen(appname); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 n = (bufp-appname); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 bufp = (char *)alloca(n+1); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 if ( bufp == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 strncpy(bufp, appname, n); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 bufp[n] = '\0'; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 appname = bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 /* Load SDL dynamic link library */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 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
|
219 ShowError("WinMain() error", SDL_GetError()); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 return(FALSE); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 atexit(cleanup_output); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 atexit(SDL_Quit); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 #ifndef DISABLE_VIDEO |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 #if 0 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 /* Create and register our class * |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 DJM: If we do this here, the user nevers gets a chance to |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 putenv(SDL_WINDOWID). This is already called later by |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 the (DIB|DX5)_CreateWindow function, so it should be |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 safe to comment it out here. |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 if ( SDL_RegisterApp(appname, CS_BYTEALIGNCLIENT, |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 GetModuleHandle(NULL)) < 0 ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 ShowError("WinMain() error", SDL_GetError()); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 exit(1); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 }*/ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 /* Sam: |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 SDL_SetModuleHandle(GetModuleHandle(NULL)); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 #endif /* 0 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 #endif /* !DISABLE_VIDEO */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 /* Run the application main() code */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 SDL_main(argc, argv); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 /* Exit cleanly, calling atexit() functions */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 exit(0); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 /* Hush little compiler, don't you cry... */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 return(0); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 /* 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
|
258 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 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
|
260 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 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
|
262 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 HINSTANCE handle; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 char **argv; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 int argc; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 char *cmdline; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 wchar_t *bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 int nLen; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 char *bufp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 #ifndef NO_STDIO_REDIRECT |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 FILE *newfp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 #endif |
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 /* 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
|
279 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
|
280 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
|
281 */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 handle = LoadLibrary(TEXT("DDRAW.DLL")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 if ( handle != NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 FreeLibrary(handle); |
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 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 #ifndef NO_STDIO_REDIRECT |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 _getcwd( stdoutPath, sizeof( stdoutPath ) ); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE ); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 /* Redirect standard input and standard output */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 newfp = freopen(stdoutPath, TEXT("w"), stdout); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 #ifndef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 if ( newfp == NULL ) { /* This happens on NT */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 #if !defined(stdout) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 stdout = fopen(stdoutPath, TEXT("w")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 newfp = fopen(stdoutPath, TEXT("w")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 if ( newfp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 *stdout = *newfp; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 #endif /* _WIN32_WCE */ |
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 _getcwd( stderrPath, sizeof( stderrPath ) ); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 strcat( stderrPath, DIR_SEPERATOR STDERR_FILE ); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 newfp = freopen(stderrPath, TEXT("w"), stderr); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 #ifndef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 if ( newfp == NULL ) { /* This happens on NT */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 #if !defined(stderr) |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 stderr = fopen(stderrPath, TEXT("w")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 newfp = fopen(stderrPath, TEXT("w")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 if ( newfp ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 *stderr = *newfp; |
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 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 #endif /* _WIN32_WCE */ |
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 setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 setbuf(stderr, NULL); /* No buffering */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 #endif /* !NO_STDIO_REDIRECT */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 #ifdef _WIN32_WCE |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 nLen = wcslen(szCmdLine)+128+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 bufp = (wchar_t *)alloca(nLen*2); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 wcscpy (bufp, TEXT("\"")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 GetModuleFileName(NULL, bufp+1, 128-3); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 wcscpy (bufp+wcslen(bufp), TEXT("\" ")); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 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
|
335 nLen = wcslen(bufp)+1; |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 cmdline = (char *)alloca(nLen); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 if ( cmdline == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 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
|
341 #else |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 /* Grab the command line (use alloca() on Windows) */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 bufp = GetCommandLine(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 cmdline = (char *)alloca(strlen(bufp)+1); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 if ( cmdline == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 return OutOfMemory(); |
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 strcpy(cmdline, bufp); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 #endif |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 /* Parse it into argv and argc */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 argc = ParseCommandLine(cmdline, NULL); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 argv = (char **)alloca((argc+1)*(sizeof *argv)); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 if ( argv == NULL ) { |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 return OutOfMemory(); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 } |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 ParseCommandLine(cmdline, argv); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 /* Run the main program (after a little SDL initialization) */ |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 return(console_main(argc, argv)); |
623b453a3219
Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 } |