src/main/win32/SDL_win32_main.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
child 1718 ed4d4f1ea201
     1.1 --- a/src/main/win32/SDL_win32_main.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/main/win32/SDL_win32_main.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -55,7 +55,7 @@
     1.4  
     1.5  /* Parse a command line buffer into arguments */
     1.6  static int
     1.7 -ParseCommandLine (char *cmdline, char **argv)
     1.8 +ParseCommandLine(char *cmdline, char **argv)
     1.9  {
    1.10      char *bufp;
    1.11      int argc;
    1.12 @@ -63,7 +63,7 @@
    1.13      argc = 0;
    1.14      for (bufp = cmdline; *bufp;) {
    1.15          /* Skip leading whitespace */
    1.16 -        while (isspace (*bufp)) {
    1.17 +        while (isspace(*bufp)) {
    1.18              ++bufp;
    1.19          }
    1.20          /* Skip over argument */
    1.21 @@ -87,7 +87,7 @@
    1.22                  ++argc;
    1.23              }
    1.24              /* Skip over word */
    1.25 -            while (*bufp && !isspace (*bufp)) {
    1.26 +            while (*bufp && !isspace(*bufp)) {
    1.27                  ++bufp;
    1.28              }
    1.29          }
    1.30 @@ -106,35 +106,35 @@
    1.31  
    1.32  /* Show an error message */
    1.33  static void
    1.34 -ShowError (const char *title, const char *message)
    1.35 +ShowError(const char *title, const char *message)
    1.36  {
    1.37  /* If USE_MESSAGEBOX is defined, you need to link with user32.lib */
    1.38  #ifdef USE_MESSAGEBOX
    1.39 -    MessageBox (NULL, message, title, MB_ICONEXCLAMATION | MB_OK);
    1.40 +    MessageBox(NULL, message, title, MB_ICONEXCLAMATION | MB_OK);
    1.41  #else
    1.42 -    fprintf (stderr, "%s: %s\n", title, message);
    1.43 +    fprintf(stderr, "%s: %s\n", title, message);
    1.44  #endif
    1.45  }
    1.46  
    1.47  /* Pop up an out of memory message, returns to Windows */
    1.48  static BOOL
    1.49 -OutOfMemory (void)
    1.50 +OutOfMemory(void)
    1.51  {
    1.52 -    ShowError ("Fatal Error", "Out of memory - aborting");
    1.53 +    ShowError("Fatal Error", "Out of memory - aborting");
    1.54      return FALSE;
    1.55  }
    1.56  
    1.57  /* SDL_Quit() shouldn't be used with atexit() directly because
    1.58     calling conventions may differ... */
    1.59  static void
    1.60 -cleanup (void)
    1.61 +cleanup(void)
    1.62  {
    1.63 -    SDL_Quit ();
    1.64 +    SDL_Quit();
    1.65  }
    1.66  
    1.67  /* Remove the output files if there was no output written */
    1.68  static void
    1.69 -cleanup_output (void)
    1.70 +cleanup_output(void)
    1.71  {
    1.72  #ifndef NO_STDIO_REDIRECT
    1.73      FILE *file;
    1.74 @@ -142,28 +142,28 @@
    1.75  #endif
    1.76  
    1.77      /* Flush the output in case anything is queued */
    1.78 -    fclose (stdout);
    1.79 -    fclose (stderr);
    1.80 +    fclose(stdout);
    1.81 +    fclose(stderr);
    1.82  
    1.83  #ifndef NO_STDIO_REDIRECT
    1.84      /* See if the files have any output in them */
    1.85      if (stdoutPath[0]) {
    1.86 -        file = fopen (stdoutPath, TEXT ("rb"));
    1.87 +        file = fopen(stdoutPath, TEXT("rb"));
    1.88          if (file) {
    1.89 -            empty = (fgetc (file) == EOF) ? 1 : 0;
    1.90 -            fclose (file);
    1.91 +            empty = (fgetc(file) == EOF) ? 1 : 0;
    1.92 +            fclose(file);
    1.93              if (empty) {
    1.94 -                remove (stdoutPath);
    1.95 +                remove(stdoutPath);
    1.96              }
    1.97          }
    1.98      }
    1.99      if (stderrPath[0]) {
   1.100 -        file = fopen (stderrPath, TEXT ("rb"));
   1.101 +        file = fopen(stderrPath, TEXT("rb"));
   1.102          if (file) {
   1.103 -            empty = (fgetc (file) == EOF) ? 1 : 0;
   1.104 -            fclose (file);
   1.105 +            empty = (fgetc(file) == EOF) ? 1 : 0;
   1.106 +            fclose(file);
   1.107              if (empty) {
   1.108 -                remove (stderrPath);
   1.109 +                remove(stderrPath);
   1.110              }
   1.111          }
   1.112      }
   1.113 @@ -177,7 +177,7 @@
   1.114  
   1.115  /* This is where execution begins [console apps] */
   1.116  int
   1.117 -console_main (int argc, char *argv[])
   1.118 +console_main(int argc, char *argv[])
   1.119  {
   1.120      size_t n;
   1.121      char *bufp, *appname;
   1.122 @@ -185,44 +185,44 @@
   1.123  
   1.124      /* Get the class name from argv[0] */
   1.125      appname = argv[0];
   1.126 -    if ((bufp = SDL_strrchr (argv[0], '\\')) != NULL) {
   1.127 +    if ((bufp = SDL_strrchr(argv[0], '\\')) != NULL) {
   1.128          appname = bufp + 1;
   1.129 -    } else if ((bufp = SDL_strrchr (argv[0], '/')) != NULL) {
   1.130 +    } else if ((bufp = SDL_strrchr(argv[0], '/')) != NULL) {
   1.131          appname = bufp + 1;
   1.132      }
   1.133  
   1.134 -    if ((bufp = SDL_strrchr (appname, '.')) == NULL)
   1.135 -        n = SDL_strlen (appname);
   1.136 +    if ((bufp = SDL_strrchr(appname, '.')) == NULL)
   1.137 +        n = SDL_strlen(appname);
   1.138      else
   1.139          n = (bufp - appname);
   1.140  
   1.141 -    bufp = SDL_stack_alloc (char, n + 1);
   1.142 +    bufp = SDL_stack_alloc(char, n + 1);
   1.143      if (bufp == NULL) {
   1.144 -        return OutOfMemory ();
   1.145 +        return OutOfMemory();
   1.146      }
   1.147 -    SDL_strlcpy (bufp, appname, n + 1);
   1.148 +    SDL_strlcpy(bufp, appname, n + 1);
   1.149      appname = bufp;
   1.150  
   1.151      /* Load SDL dynamic link library */
   1.152 -    if (SDL_Init (SDL_INIT_NOPARACHUTE) < 0) {
   1.153 -        ShowError ("WinMain() error", SDL_GetError ());
   1.154 +    if (SDL_Init(SDL_INIT_NOPARACHUTE) < 0) {
   1.155 +        ShowError("WinMain() error", SDL_GetError());
   1.156          return (FALSE);
   1.157      }
   1.158 -    atexit (cleanup_output);
   1.159 -    atexit (cleanup);
   1.160 +    atexit(cleanup_output);
   1.161 +    atexit(cleanup);
   1.162  
   1.163      /* Sam:
   1.164         We still need to pass in the application handle so that
   1.165         DirectInput will initialize properly when SDL_RegisterApp()
   1.166         is called later in the video initialization.
   1.167       */
   1.168 -    SDL_SetModuleHandle (GetModuleHandle (NULL));
   1.169 +    SDL_SetModuleHandle(GetModuleHandle(NULL));
   1.170  
   1.171      /* Run the application main() code */
   1.172 -    status = SDL_main (argc, argv);
   1.173 +    status = SDL_main(argc, argv);
   1.174  
   1.175      /* Exit cleanly, calling atexit() functions */
   1.176 -    exit (status);
   1.177 +    exit(status);
   1.178  
   1.179      /* Hush little compiler, don't you cry... */
   1.180      return 0;
   1.181 @@ -231,10 +231,10 @@
   1.182  /* This is where execution begins [windowed apps] */
   1.183  #ifdef _WIN32_WCE
   1.184  int WINAPI
   1.185 -WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
   1.186 +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
   1.187  #else
   1.188  int WINAPI
   1.189 -WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
   1.190 +WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
   1.191  #endif
   1.192  {
   1.193      HINSTANCE handle;
   1.194 @@ -262,36 +262,35 @@
   1.195         keep them open.  This is a hack.. hopefully it will be fixed 
   1.196         someday.  DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
   1.197       */
   1.198 -    handle = LoadLibrary (TEXT ("DDRAW.DLL"));
   1.199 +    handle = LoadLibrary(TEXT("DDRAW.DLL"));
   1.200      if (handle != NULL) {
   1.201 -        FreeLibrary (handle);
   1.202 +        FreeLibrary(handle);
   1.203      }
   1.204  #ifndef NO_STDIO_REDIRECT
   1.205 -    pathlen = GetModuleFileName (NULL, path, SDL_arraysize (path));
   1.206 +    pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path));
   1.207      while (pathlen > 0 && path[pathlen] != '\\') {
   1.208          --pathlen;
   1.209      }
   1.210      path[pathlen] = '\0';
   1.211  
   1.212  #ifdef _WIN32_WCE
   1.213 -    wcsncpy (stdoutPath, path, SDL_arraysize (stdoutPath));
   1.214 -    wcsncat (stdoutPath, DIR_SEPERATOR STDOUT_FILE,
   1.215 -             SDL_arraysize (stdoutPath));
   1.216 +    wcsncpy(stdoutPath, path, SDL_arraysize(stdoutPath));
   1.217 +    wcsncat(stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath));
   1.218  #else
   1.219 -    SDL_strlcpy (stdoutPath, path, SDL_arraysize (stdoutPath));
   1.220 -    SDL_strlcat (stdoutPath, DIR_SEPERATOR STDOUT_FILE,
   1.221 -                 SDL_arraysize (stdoutPath));
   1.222 +    SDL_strlcpy(stdoutPath, path, SDL_arraysize(stdoutPath));
   1.223 +    SDL_strlcat(stdoutPath, DIR_SEPERATOR STDOUT_FILE,
   1.224 +                SDL_arraysize(stdoutPath));
   1.225  #endif
   1.226  
   1.227      /* Redirect standard input and standard output */
   1.228 -    newfp = freopen (stdoutPath, TEXT ("w"), stdout);
   1.229 +    newfp = freopen(stdoutPath, TEXT("w"), stdout);
   1.230  
   1.231  #ifndef _WIN32_WCE
   1.232      if (newfp == NULL) {        /* This happens on NT */
   1.233  #if !defined(stdout)
   1.234 -        stdout = fopen (stdoutPath, TEXT ("w"));
   1.235 +        stdout = fopen(stdoutPath, TEXT("w"));
   1.236  #else
   1.237 -        newfp = fopen (stdoutPath, TEXT ("w"));
   1.238 +        newfp = fopen(stdoutPath, TEXT("w"));
   1.239          if (newfp) {
   1.240              *stdout = *newfp;
   1.241          }
   1.242 @@ -300,22 +299,21 @@
   1.243  #endif /* _WIN32_WCE */
   1.244  
   1.245  #ifdef _WIN32_WCE
   1.246 -    wcsncpy (stderrPath, path, SDL_arraysize (stdoutPath));
   1.247 -    wcsncat (stderrPath, DIR_SEPERATOR STDOUT_FILE,
   1.248 -             SDL_arraysize (stdoutPath));
   1.249 +    wcsncpy(stderrPath, path, SDL_arraysize(stdoutPath));
   1.250 +    wcsncat(stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath));
   1.251  #else
   1.252 -    SDL_strlcpy (stderrPath, path, SDL_arraysize (stderrPath));
   1.253 -    SDL_strlcat (stderrPath, DIR_SEPERATOR STDERR_FILE,
   1.254 -                 SDL_arraysize (stderrPath));
   1.255 +    SDL_strlcpy(stderrPath, path, SDL_arraysize(stderrPath));
   1.256 +    SDL_strlcat(stderrPath, DIR_SEPERATOR STDERR_FILE,
   1.257 +                SDL_arraysize(stderrPath));
   1.258  #endif
   1.259  
   1.260 -    newfp = freopen (stderrPath, TEXT ("w"), stderr);
   1.261 +    newfp = freopen(stderrPath, TEXT("w"), stderr);
   1.262  #ifndef _WIN32_WCE
   1.263      if (newfp == NULL) {        /* This happens on NT */
   1.264  #if !defined(stderr)
   1.265 -        stderr = fopen (stderrPath, TEXT ("w"));
   1.266 +        stderr = fopen(stderrPath, TEXT("w"));
   1.267  #else
   1.268 -        newfp = fopen (stderrPath, TEXT ("w"));
   1.269 +        newfp = fopen(stderrPath, TEXT("w"));
   1.270          if (newfp) {
   1.271              *stderr = *newfp;
   1.272          }
   1.273 @@ -323,44 +321,44 @@
   1.274      }
   1.275  #endif /* _WIN32_WCE */
   1.276  
   1.277 -    setvbuf (stdout, NULL, _IOLBF, BUFSIZ);     /* Line buffered */
   1.278 -    setbuf (stderr, NULL);      /* No buffering */
   1.279 +    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);      /* Line buffered */
   1.280 +    setbuf(stderr, NULL);       /* No buffering */
   1.281  #endif /* !NO_STDIO_REDIRECT */
   1.282  
   1.283  #ifdef _WIN32_WCE
   1.284 -    nLen = wcslen (szCmdLine) + 128 + 1;
   1.285 -    bufp = SDL_stack_alloc (wchar_t, nLen * 2);
   1.286 -    wcscpy (bufp, TEXT ("\""));
   1.287 -    GetModuleFileName (NULL, bufp + 1, 128 - 3);
   1.288 -    wcscpy (bufp + wcslen (bufp), TEXT ("\" "));
   1.289 -    wcsncpy (bufp + wcslen (bufp), szCmdLine, nLen - wcslen (bufp));
   1.290 -    nLen = wcslen (bufp) + 1;
   1.291 -    cmdline = SDL_stack_alloc (char, nLen);
   1.292 +    nLen = wcslen(szCmdLine) + 128 + 1;
   1.293 +    bufp = SDL_stack_alloc(wchar_t, nLen * 2);
   1.294 +    wcscpy(bufp, TEXT("\""));
   1.295 +    GetModuleFileName(NULL, bufp + 1, 128 - 3);
   1.296 +    wcscpy(bufp + wcslen(bufp), TEXT("\" "));
   1.297 +    wcsncpy(bufp + wcslen(bufp), szCmdLine, nLen - wcslen(bufp));
   1.298 +    nLen = wcslen(bufp) + 1;
   1.299 +    cmdline = SDL_stack_alloc(char, nLen);
   1.300      if (cmdline == NULL) {
   1.301 -        return OutOfMemory ();
   1.302 +        return OutOfMemory();
   1.303      }
   1.304 -    WideCharToMultiByte (CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
   1.305 +    WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
   1.306  #else
   1.307      /* Grab the command line */
   1.308 -    bufp = GetCommandLine ();
   1.309 -    nLen = SDL_strlen (bufp) + 1;
   1.310 -    cmdline = SDL_stack_alloc (char, nLen);
   1.311 +    bufp = GetCommandLine();
   1.312 +    nLen = SDL_strlen(bufp) + 1;
   1.313 +    cmdline = SDL_stack_alloc(char, nLen);
   1.314      if (cmdline == NULL) {
   1.315 -        return OutOfMemory ();
   1.316 +        return OutOfMemory();
   1.317      }
   1.318 -    SDL_strlcpy (cmdline, bufp, nLen);
   1.319 +    SDL_strlcpy(cmdline, bufp, nLen);
   1.320  #endif
   1.321  
   1.322      /* Parse it into argv and argc */
   1.323 -    argc = ParseCommandLine (cmdline, NULL);
   1.324 -    argv = SDL_stack_alloc (char *, argc + 1);
   1.325 +    argc = ParseCommandLine(cmdline, NULL);
   1.326 +    argv = SDL_stack_alloc(char *, argc + 1);
   1.327      if (argv == NULL) {
   1.328 -        return OutOfMemory ();
   1.329 +        return OutOfMemory();
   1.330      }
   1.331 -    ParseCommandLine (cmdline, argv);
   1.332 +    ParseCommandLine(cmdline, argv);
   1.333  
   1.334      /* Run the main program (after a little SDL initialization) */
   1.335 -    console_main (argc, argv);
   1.336 +    console_main(argc, argv);
   1.337  
   1.338      /* Hush little compiler, don't you cry... */
   1.339      return 0;