comparison src/main/win32/SDL_win32_main.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents d7bca8c8161e
children c71e05b4dc2e
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
3 3
4 The WinMain function -- calls your program's main() function 4 The WinMain function -- calls your program's main() function
5 */ 5 */
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <stdlib.h> 8 #include <stdlib.h>
11 9
12 #include <windows.h> 10 #include "SDL_windows.h"
13 #include <malloc.h> /* For _alloca() */ 11
12 #include "SDL_stdlib.h"
13 #include "SDL_string.h"
14 14
15 #ifdef _WIN32_WCE 15 #ifdef _WIN32_WCE
16 # define DIR_SEPERATOR TEXT("\\") 16 # define DIR_SEPERATOR TEXT("\\")
17 # undef _getcwd 17 # undef _getcwd
18 # define _getcwd(str,len) wcscpy(str,TEXT("")) 18 # define _getcwd(str,len) wcscpy(str,TEXT(""))
54 #if defined(_WIN32_WCE) && _WIN32_WCE < 300 54 #if defined(_WIN32_WCE) && _WIN32_WCE < 300
55 /* seems to be undefined in Win CE although in online help */ 55 /* seems to be undefined in Win CE although in online help */
56 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t')) 56 #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
57 57
58 /* seems to be undefined in Win CE although in online help */ 58 /* seems to be undefined in Win CE although in online help */
59 char *strrchr(char *str, int c) 59 char *SDL_strrchr(char *str, int c)
60 { 60 {
61 char *p; 61 char *p;
62 62
63 /* Skip to the end of the string */ 63 /* Skip to the end of the string */
64 p=str; 64 p=str;
193 int n; 193 int n;
194 char *bufp, *appname; 194 char *bufp, *appname;
195 195
196 /* Get the class name from argv[0] */ 196 /* Get the class name from argv[0] */
197 appname = argv[0]; 197 appname = argv[0];
198 if ( (bufp=strrchr(argv[0], '\\')) != NULL ) { 198 if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) {
199 appname = bufp+1; 199 appname = bufp+1;
200 } else 200 } else
201 if ( (bufp=strrchr(argv[0], '/')) != NULL ) { 201 if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) {
202 appname = bufp+1; 202 appname = bufp+1;
203 } 203 }
204 204
205 if ( (bufp=strrchr(appname, '.')) == NULL ) 205 if ( (bufp=SDL_strrchr(appname, '.')) == NULL )
206 n = strlen(appname); 206 n = SDL_strlen(appname);
207 else 207 else
208 n = (bufp-appname); 208 n = (bufp-appname);
209 209
210 bufp = (char *)alloca(n+1); 210 bufp = (char *)alloca(n+1);
211 if ( bufp == NULL ) { 211 if ( bufp == NULL ) {
212 return OutOfMemory(); 212 return OutOfMemory();
213 } 213 }
214 strncpy(bufp, appname, n); 214 SDL_strncpy(bufp, appname, n);
215 bufp[n] = '\0'; 215 bufp[n] = '\0';
216 appname = bufp; 216 appname = bufp;
217 217
218 /* Load SDL dynamic link library */ 218 /* Load SDL dynamic link library */
219 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) { 219 if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
296 while ( pathlen > 0 && path[pathlen] != '\\' ) { 296 while ( pathlen > 0 && path[pathlen] != '\\' ) {
297 --pathlen; 297 --pathlen;
298 } 298 }
299 path[pathlen] = '\0'; 299 path[pathlen] = '\0';
300 300
301 strcpy( stdoutPath, path ); 301 SDL_strcpy( stdoutPath, path );
302 strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE ); 302 SDL_strcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE );
303 303
304 /* Redirect standard input and standard output */ 304 /* Redirect standard input and standard output */
305 newfp = freopen(stdoutPath, TEXT("w"), stdout); 305 newfp = freopen(stdoutPath, TEXT("w"), stdout);
306 306
307 #ifndef _WIN32_WCE 307 #ifndef _WIN32_WCE
315 } 315 }
316 #endif 316 #endif
317 } 317 }
318 #endif /* _WIN32_WCE */ 318 #endif /* _WIN32_WCE */
319 319
320 strcpy( stderrPath, path ); 320 SDL_strcpy( stderrPath, path );
321 strcat( stderrPath, DIR_SEPERATOR STDERR_FILE ); 321 SDL_strcat( stderrPath, DIR_SEPERATOR STDERR_FILE );
322 322
323 newfp = freopen(stderrPath, TEXT("w"), stderr); 323 newfp = freopen(stderrPath, TEXT("w"), stderr);
324 #ifndef _WIN32_WCE 324 #ifndef _WIN32_WCE
325 if ( newfp == NULL ) { /* This happens on NT */ 325 if ( newfp == NULL ) { /* This happens on NT */
326 #if !defined(stderr) 326 #if !defined(stderr)
352 } 352 }
353 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL); 353 WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
354 #else 354 #else
355 /* Grab the command line (use alloca() on Windows) */ 355 /* Grab the command line (use alloca() on Windows) */
356 bufp = GetCommandLine(); 356 bufp = GetCommandLine();
357 cmdline = (char *)alloca(strlen(bufp)+1); 357 cmdline = (char *)alloca(SDL_strlen(bufp)+1);
358 if ( cmdline == NULL ) { 358 if ( cmdline == NULL ) {
359 return OutOfMemory(); 359 return OutOfMemory();
360 } 360 }
361 strcpy(cmdline, bufp); 361 SDL_strcpy(cmdline, bufp);
362 #endif 362 #endif
363 363
364 /* Parse it into argv and argc */ 364 /* Parse it into argv and argc */
365 argc = ParseCommandLine(cmdline, NULL); 365 argc = ParseCommandLine(cmdline, NULL);
366 argv = (char **)alloca((argc+1)*(sizeof *argv)); 366 argv = (char **)alloca((argc+1)*(sizeof *argv));