Sha256: 2e7f9b689e7af531f418a72712feb68e1f9f3bc89282103e4f5972aefbe36f16

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

#include <windows.h>
#include <exception>
#include <string>
#include <vector>
using namespace std;

// IMPR: Check for security issues. I hacked this together.
vector<string> splitCmdLine()
{
    vector<string> result;

    const char* cmdLine = ::GetCommandLineA();

    const char* argBegin = 0;
    bool isQuotedArg = false;

    while (*cmdLine)
    {
        if (*cmdLine == '"')
        {
            if (argBegin == 0)
            {
                argBegin = cmdLine + 1;
                isQuotedArg = true;
            }
            else if (isQuotedArg)
            {
                result.push_back(std::string(argBegin, cmdLine));
                argBegin = 0;
            }
        }
        else if (!isspace(*cmdLine) && argBegin == 0)
        {
            argBegin = cmdLine;
            isQuotedArg = false;
        }
        else if (isspace(*cmdLine) && argBegin != 0 && !isQuotedArg)
        {
            result.push_back(std::string(argBegin, cmdLine + 1));
            argBegin = 0;
        }
        ++cmdLine;
    }

    if (argBegin != 0)
        result.push_back(argBegin);

    return result;
}

int main(int argc, char* argv[]);

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    try
    {
        vector<string> arguments = splitCmdLine();
        vector<char*> argv(arguments.size());
        for (unsigned i = 0; i < argv.size(); ++i)
            argv[i] = const_cast<char*>(arguments[i].c_str());
	    return main(argv.size(), &argv[0]);
    }
    catch (const std::exception& e)
    {
        ::MessageBoxA(0, e.what(), "Uncaught Exception", MB_OK | MB_ICONERROR);
        return EXIT_FAILURE;
    }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gosu-0.7.45 GosuImpl/WinMain.cpp
gosu-0.7.44 GosuImpl/WinMain.cpp
gosu-0.7.43 GosuImpl/WinMain.cpp
gosu-0.7.41 GosuImpl/WinMain.cpp
gosu-0.7.40 GosuImpl/WinMain.cpp
gosu-0.7.39 GosuImpl/WinMain.cpp
gosu-0.7.38 GosuImpl/WinMain.cpp
gosu-0.7.37 GosuImpl/WinMain.cpp
gosu-0.7.36.2 GosuImpl/WinMain.cpp
gosu-0.7.35 GosuImpl/WinMain.cpp