src/main/windows/SDL_windows_main.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 14 Jul 2013 19:53:50 +0200
changeset 7450 29654d59c439
parent 7356 d1a0bbe64f15
child 7828 1451063c8ecd
permissions -rw-r--r--
Changed use of isspace() to SDL_isspace().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
*/
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     6
#include "SDL_config.h"
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     7
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
     8
#ifdef __WIN32__
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
#include <stdio.h>
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
#include <stdlib.h>
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
1433
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1423
diff changeset
    13
#define WIN32_LEAN_AND_MEAN
bb6839704ed6 SDL_windows.h is no longer necessary
Sam Lantinga <slouken@libsdl.org>
parents: 1423
diff changeset
    14
#include <windows.h>
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1286
diff changeset
    15
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
/* Include the SDL main definition header */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
#include "SDL.h"
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
#include "SDL_main.h"
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
#ifdef main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#  undef main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#endif /* main */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    24
static void
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    25
UnEscapeQuotes(char *arg)
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    26
{
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    27
    char *last = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    28
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    29
    while (*arg) {
6719
c250f633c040 Update VS2012 solution - add missing files; fix some static analysis warnings
Andreas Schiffler <aschiffler@ferzkopp.net>
parents: 6672
diff changeset
    30
        if (*arg == '"' && (last != NULL && *last == '\\')) {
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    31
            char *c_curr = arg;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    32
            char *c_last = last;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    33
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    34
            while (*c_curr) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    35
                *c_last = *c_curr;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    36
                c_last = c_curr;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    37
                c_curr++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    38
            }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    39
            *c_last = '\0';
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    40
        }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    41
        last = arg;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    42
        arg++;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    43
    }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    44
}
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    45
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
/* Parse a command line buffer into arguments */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    47
static int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    48
ParseCommandLine(char *cmdline, char **argv)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    50
    char *bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    51
    char *lastp = NULL;
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    52
    int argc, last_argc;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    54
    argc = last_argc = 0;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    55
    for (bufp = cmdline; *bufp;) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    56
        /* Skip leading whitespace */
7450
29654d59c439 Changed use of isspace() to SDL_isspace().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7356
diff changeset
    57
        while (SDL_isspace(*bufp)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    58
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    59
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    60
        /* Skip over argument */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    61
        if (*bufp == '"') {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    62
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    63
            if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    64
                if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    65
                    argv[argc] = bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    66
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    67
                ++argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    68
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    69
            /* Skip over word */
4511
ae7799d16c87 Daniel Wyatt 2010-03-26 14:52:53 PDT
Sam Lantinga <slouken@libsdl.org>
parents: 2286
diff changeset
    70
            lastp = bufp;
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    71
            while (*bufp && (*bufp != '"' || *lastp == '\\')) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    72
                lastp = bufp;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    73
                ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    74
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    75
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    76
            if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    77
                if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    78
                    argv[argc] = bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    79
                }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    80
                ++argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    81
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    82
            /* Skip over word */
7450
29654d59c439 Changed use of isspace() to SDL_isspace().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7356
diff changeset
    83
            while (*bufp && !SDL_isspace(*bufp)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    84
                ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    85
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    86
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    87
        if (*bufp) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    88
            if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    89
                *bufp = '\0';
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    90
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    91
            ++bufp;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    92
        }
2286
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    93
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    94
        /* Strip out \ from \" sequences */
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    95
        if (argv && last_argc != argc) {
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    96
            UnEscapeQuotes(argv[last_argc]);
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    97
        }
41a6675d8700 Merged fix for bug #503 from SDL 1.2 revision 3487
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    98
        last_argc = argc;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
    99
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   100
    if (argv) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   101
        argv[argc] = NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   102
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   103
    return (argc);
754
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
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
/* Show an error message */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   107
static void
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   108
ShowError(const char *title, const char *message)
754
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
/* 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
   111
#ifdef USE_MESSAGEBOX
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   112
    MessageBox(NULL, message, title, MB_ICONEXCLAMATION | MB_OK);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
#else
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   114
    fprintf(stderr, "%s: %s\n", title, message);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
#endif
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
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
/* Pop up an out of memory message, returns to Windows */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   119
static BOOL
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   120
OutOfMemory(void)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   122
    ShowError("Fatal Error", "Out of memory - aborting");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   123
    return FALSE;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
}
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6044
diff changeset
   126
#if defined(_MSC_VER)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
/* The VC++ compiler needs main defined */
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
#define console_main main
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
#endif
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
/* This is where execution begins [console apps] */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   132
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   133
console_main(int argc, char *argv[])
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   135
    int status;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
7281
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 6719
diff changeset
   137
    SDL_SetMainReady();
cd5516b9263d Added some extra protection to notify the developer if they haven't initialized the application properly.
Sam Lantinga <slouken@libsdl.org>
parents: 6719
diff changeset
   138
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   139
    /* Run the application main() code */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   140
    status = SDL_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   142
    /* Exit cleanly, calling atexit() functions */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   143
    exit(status);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   145
    /* Hush little compiler, don't you cry... */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   146
    return 0;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
}
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
/* This is where execution begins [windowed apps] */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   150
int WINAPI
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   151
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   153
    char **argv;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   154
    int argc;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   155
    char *cmdline;
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   157
    /* Grab the command line */
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   158
    TCHAR *text = GetCommandLine();
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   159
#if UNICODE
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   160
    cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   161
#else
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   162
    cmdline = SDL_strdup(text);
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   163
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   164
    if (cmdline == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   165
        return OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   166
    }
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   168
    /* Parse it into argv and argc */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   169
    argc = ParseCommandLine(cmdline, NULL);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   170
    argv = SDL_stack_alloc(char *, argc + 1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   171
    if (argv == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   172
        return OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   173
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   174
    ParseCommandLine(cmdline, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   176
    /* Run the main program */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   177
    console_main(argc, argv);
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
7356
d1a0bbe64f15 Added missing call to SDL_stack_free().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7281
diff changeset
   179
    SDL_stack_free(argv);
d1a0bbe64f15 Added missing call to SDL_stack_free().
Philipp Wiesemann <philipp.wiesemann@arcor.de>
parents: 7281
diff changeset
   180
6672
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   181
    SDL_free(cmdline);
b61791cd595a Fixed command line parsing for applications defining UNICODE
Sam Lantinga <slouken@libsdl.org>
parents: 6430
diff changeset
   182
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   183
    /* Hush little compiler, don't you cry... */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   184
    return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   185
}
754
623b453a3219 Fixed "dist" make target for newer versions of automake
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
6044
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   187
#endif /* __WIN32__ */
35448a5ea044 Lots of fixes importing SDL source wholesale into a new iOS project
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   188
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1769
diff changeset
   189
/* vi: set ts=4 sw=4 expandtab: */