src/main/win32/SDL_win32_main.c
branchSDL-1.3
changeset 1718 ed4d4f1ea201
parent 1668 4da1ee79c9af
     1.1 --- a/src/main/win32/SDL_win32_main.c	Tue Jun 27 04:59:10 2006 +0000
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Tue Jun 27 07:46:36 2006 +0000
     1.3 @@ -10,20 +10,6 @@
     1.4  #define WIN32_LEAN_AND_MEAN
     1.5  #include <windows.h>
     1.6  
     1.7 -#ifdef _WIN32_WCE
     1.8 -# define DIR_SEPERATOR TEXT("\\")
     1.9 -# undef _getcwd
    1.10 -# define _getcwd(str,len)	wcscpy(str,TEXT(""))
    1.11 -# define setbuf(f,b)
    1.12 -# define setvbuf(w,x,y,z)
    1.13 -# define fopen		_wfopen
    1.14 -# define freopen	_wfreopen
    1.15 -# define remove(x)	DeleteFile(x)
    1.16 -#else
    1.17 -# define DIR_SEPERATOR TEXT("/")
    1.18 -# include <direct.h>
    1.19 -#endif
    1.20 -
    1.21  /* Include the SDL main definition header */
    1.22  #include "SDL.h"
    1.23  #include "SDL_main.h"
    1.24 @@ -34,20 +20,6 @@
    1.25  # endif /* _WIN32_WCE_EMULATION */
    1.26  #endif /* main */
    1.27  
    1.28 -/* The standard output files */
    1.29 -#define STDOUT_FILE	TEXT("stdout.txt")
    1.30 -#define STDERR_FILE	TEXT("stderr.txt")
    1.31 -
    1.32 -#ifndef NO_STDIO_REDIRECT
    1.33 -# ifdef _WIN32_WCE
    1.34 -static wchar_t stdoutPath[MAX_PATH];
    1.35 -static wchar_t stderrPath[MAX_PATH];
    1.36 -# else
    1.37 -static char stdoutPath[MAX_PATH];
    1.38 -static char stderrPath[MAX_PATH];
    1.39 -# endif
    1.40 -#endif
    1.41 -
    1.42  #if defined(_WIN32_WCE) && _WIN32_WCE < 300
    1.43  /* seems to be undefined in Win CE although in online help */
    1.44  #define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
    1.45 @@ -124,52 +96,6 @@
    1.46      return FALSE;
    1.47  }
    1.48  
    1.49 -/* SDL_Quit() shouldn't be used with atexit() directly because
    1.50 -   calling conventions may differ... */
    1.51 -static void
    1.52 -cleanup(void)
    1.53 -{
    1.54 -    SDL_Quit();
    1.55 -}
    1.56 -
    1.57 -/* Remove the output files if there was no output written */
    1.58 -static void
    1.59 -cleanup_output(void)
    1.60 -{
    1.61 -#ifndef NO_STDIO_REDIRECT
    1.62 -    FILE *file;
    1.63 -    int empty;
    1.64 -#endif
    1.65 -
    1.66 -    /* Flush the output in case anything is queued */
    1.67 -    fclose(stdout);
    1.68 -    fclose(stderr);
    1.69 -
    1.70 -#ifndef NO_STDIO_REDIRECT
    1.71 -    /* See if the files have any output in them */
    1.72 -    if (stdoutPath[0]) {
    1.73 -        file = fopen(stdoutPath, TEXT("rb"));
    1.74 -        if (file) {
    1.75 -            empty = (fgetc(file) == EOF) ? 1 : 0;
    1.76 -            fclose(file);
    1.77 -            if (empty) {
    1.78 -                remove(stdoutPath);
    1.79 -            }
    1.80 -        }
    1.81 -    }
    1.82 -    if (stderrPath[0]) {
    1.83 -        file = fopen(stderrPath, TEXT("rb"));
    1.84 -        if (file) {
    1.85 -            empty = (fgetc(file) == EOF) ? 1 : 0;
    1.86 -            fclose(file);
    1.87 -            if (empty) {
    1.88 -                remove(stderrPath);
    1.89 -            }
    1.90 -        }
    1.91 -    }
    1.92 -#endif
    1.93 -}
    1.94 -
    1.95  #if defined(_MSC_VER) && !defined(_WIN32_WCE)
    1.96  /* The VC++ compiler needs main defined */
    1.97  #define console_main main
    1.98 @@ -179,45 +105,8 @@
    1.99  int
   1.100  console_main(int argc, char *argv[])
   1.101  {
   1.102 -    size_t n;
   1.103 -    char *bufp, *appname;
   1.104      int status;
   1.105  
   1.106 -    /* Get the class name from argv[0] */
   1.107 -    appname = argv[0];
   1.108 -    if ((bufp = SDL_strrchr(argv[0], '\\')) != NULL) {
   1.109 -        appname = bufp + 1;
   1.110 -    } else if ((bufp = SDL_strrchr(argv[0], '/')) != NULL) {
   1.111 -        appname = bufp + 1;
   1.112 -    }
   1.113 -
   1.114 -    if ((bufp = SDL_strrchr(appname, '.')) == NULL)
   1.115 -        n = SDL_strlen(appname);
   1.116 -    else
   1.117 -        n = (bufp - appname);
   1.118 -
   1.119 -    bufp = SDL_stack_alloc(char, n + 1);
   1.120 -    if (bufp == NULL) {
   1.121 -        return OutOfMemory();
   1.122 -    }
   1.123 -    SDL_strlcpy(bufp, appname, n + 1);
   1.124 -    appname = bufp;
   1.125 -
   1.126 -    /* Load SDL dynamic link library */
   1.127 -    if (SDL_Init(SDL_INIT_NOPARACHUTE) < 0) {
   1.128 -        ShowError("WinMain() error", SDL_GetError());
   1.129 -        return (FALSE);
   1.130 -    }
   1.131 -    atexit(cleanup_output);
   1.132 -    atexit(cleanup);
   1.133 -
   1.134 -    /* Sam:
   1.135 -       We still need to pass in the application handle so that
   1.136 -       DirectInput will initialize properly when SDL_RegisterApp()
   1.137 -       is called later in the video initialization.
   1.138 -     */
   1.139 -    SDL_SetModuleHandle(GetModuleHandle(NULL));
   1.140 -
   1.141      /* Run the application main() code */
   1.142      status = SDL_main(argc, argv);
   1.143  
   1.144 @@ -229,24 +118,12 @@
   1.145  }
   1.146  
   1.147  /* This is where execution begins [windowed apps] */
   1.148 -#ifdef _WIN32_WCE
   1.149  int WINAPI
   1.150 -WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
   1.151 -#else
   1.152 -int WINAPI
   1.153 -WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
   1.154 -#endif
   1.155 +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
   1.156  {
   1.157 -    HINSTANCE handle;
   1.158      char **argv;
   1.159      int argc;
   1.160      char *cmdline;
   1.161 -    DWORD pathlen;
   1.162 -#ifdef _WIN32_WCE
   1.163 -    wchar_t path[MAX_PATH];
   1.164 -#else
   1.165 -    char path[MAX_PATH];
   1.166 -#endif
   1.167  #ifdef _WIN32_WCE
   1.168      wchar_t *bufp;
   1.169      int nLen;
   1.170 @@ -254,76 +131,6 @@
   1.171      char *bufp;
   1.172      size_t nLen;
   1.173  #endif
   1.174 -#ifndef NO_STDIO_REDIRECT
   1.175 -    FILE *newfp;
   1.176 -#endif
   1.177 -
   1.178 -    /* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
   1.179 -       keep them open.  This is a hack.. hopefully it will be fixed 
   1.180 -       someday.  DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
   1.181 -     */
   1.182 -    handle = LoadLibrary(TEXT("DDRAW.DLL"));
   1.183 -    if (handle != NULL) {
   1.184 -        FreeLibrary(handle);
   1.185 -    }
   1.186 -#ifndef NO_STDIO_REDIRECT
   1.187 -    pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path));
   1.188 -    while (pathlen > 0 && path[pathlen] != '\\') {
   1.189 -        --pathlen;
   1.190 -    }
   1.191 -    path[pathlen] = '\0';
   1.192 -
   1.193 -#ifdef _WIN32_WCE
   1.194 -    wcsncpy(stdoutPath, path, SDL_arraysize(stdoutPath));
   1.195 -    wcsncat(stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath));
   1.196 -#else
   1.197 -    SDL_strlcpy(stdoutPath, path, SDL_arraysize(stdoutPath));
   1.198 -    SDL_strlcat(stdoutPath, DIR_SEPERATOR STDOUT_FILE,
   1.199 -                SDL_arraysize(stdoutPath));
   1.200 -#endif
   1.201 -
   1.202 -    /* Redirect standard input and standard output */
   1.203 -    newfp = freopen(stdoutPath, TEXT("w"), stdout);
   1.204 -
   1.205 -#ifndef _WIN32_WCE
   1.206 -    if (newfp == NULL) {        /* This happens on NT */
   1.207 -#if !defined(stdout)
   1.208 -        stdout = fopen(stdoutPath, TEXT("w"));
   1.209 -#else
   1.210 -        newfp = fopen(stdoutPath, TEXT("w"));
   1.211 -        if (newfp) {
   1.212 -            *stdout = *newfp;
   1.213 -        }
   1.214 -#endif
   1.215 -    }
   1.216 -#endif /* _WIN32_WCE */
   1.217 -
   1.218 -#ifdef _WIN32_WCE
   1.219 -    wcsncpy(stderrPath, path, SDL_arraysize(stdoutPath));
   1.220 -    wcsncat(stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath));
   1.221 -#else
   1.222 -    SDL_strlcpy(stderrPath, path, SDL_arraysize(stderrPath));
   1.223 -    SDL_strlcat(stderrPath, DIR_SEPERATOR STDERR_FILE,
   1.224 -                SDL_arraysize(stderrPath));
   1.225 -#endif
   1.226 -
   1.227 -    newfp = freopen(stderrPath, TEXT("w"), stderr);
   1.228 -#ifndef _WIN32_WCE
   1.229 -    if (newfp == NULL) {        /* This happens on NT */
   1.230 -#if !defined(stderr)
   1.231 -        stderr = fopen(stderrPath, TEXT("w"));
   1.232 -#else
   1.233 -        newfp = fopen(stderrPath, TEXT("w"));
   1.234 -        if (newfp) {
   1.235 -            *stderr = *newfp;
   1.236 -        }
   1.237 -#endif
   1.238 -    }
   1.239 -#endif /* _WIN32_WCE */
   1.240 -
   1.241 -    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);      /* Line buffered */
   1.242 -    setbuf(stderr, NULL);       /* No buffering */
   1.243 -#endif /* !NO_STDIO_REDIRECT */
   1.244  
   1.245  #ifdef _WIN32_WCE
   1.246      nLen = wcslen(szCmdLine) + 128 + 1;
   1.247 @@ -357,7 +164,7 @@
   1.248      }
   1.249      ParseCommandLine(cmdline, argv);
   1.250  
   1.251 -    /* Run the main program (after a little SDL initialization) */
   1.252 +    /* Run the main program */
   1.253      console_main(argc, argv);
   1.254  
   1.255      /* Hush little compiler, don't you cry... */