Sha256: dba46210143e7fe3b9d9a4f901898fab131ba9159aa015bd515e3a0395fd30f9

Contents?: true

Size: 1.71 KB

Versions: 30

Compression:

Stored size: 1.71 KB

Contents

#include <boost/lexical_cast.hpp>
#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

30 entries across 30 versions & 1 rubygems

Version Path
gosu-0.7.33 GosuImpl/WinMain.cpp
gosu-0.7.32 GosuImpl/WinMain.cpp
gosu-0.7.31 GosuImpl/WinMain.cpp
gosu-0.7.30 GosuImpl/WinMain.cpp
gosu-0.7.29 GosuImpl/WinMain.cpp
gosu-0.7.28 GosuImpl/WinMain.cpp
gosu-0.7.27.1 GosuImpl/WinMain.cpp
gosu-0.7.27 GosuImpl/WinMain.cpp
gosu-0.7.26.1 GosuImpl/WinMain.cpp
gosu-0.7.26 GosuImpl/WinMain.cpp
gosu-0.7.25 GosuImpl/WinMain.cpp
gosu-0.7.24 GosuImpl/WinMain.cpp
gosu-0.7.23 GosuImpl/WinMain.cpp
gosu-0.7.22 GosuImpl/WinMain.cpp
gosu-0.7.21 GosuImpl/WinMain.cpp
gosu-0.7.20 GosuImpl/WinMain.cpp
gosu-0.7.19 GosuImpl/WinMain.cpp
gosu-0.7.18 GosuImpl/WinMain.cpp
gosu-0.7.17 GosuImpl/WinMain.cpp
gosu-0.7.16 GosuImpl/WinMain.cpp