diff --git a/bc/os/CommandLine.cpp b/bc/os/CommandLine.cpp new file mode 100644 index 0000000..ef0bf48 --- /dev/null +++ b/bc/os/CommandLine.cpp @@ -0,0 +1,59 @@ +#include "bc/os/CommandLine.hpp" +#include "bc/Debug.hpp" + +#include +#include + +// Variables + +char commandline[1024] = {0}; + +// Functions + +const char* OsGetCommandLine() { +#if defined(WHOA_SYSTEM_WIN) + return GetCommandLine(); +#endif + +#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX) + return commandline; +#endif +} + +std::string QuoteArgument(std::string argument) { + std::string result = ""; + + result += "\""; + result += argument; + result += "\""; + + return result; +} + +std::string CheckArgument(std::string argument) { + for (size_t i = 0; i < argument.length(); i++) { + switch (argument.at(i)) { + case '\"': + case ' ': + return QuoteArgument(argument); + } + } + + return argument; +} + +void OsSetCommandLine(int32_t argc, char** argv) { + int32_t i; + std::string result = ""; + + while (i < argc) { + if (i > 0) { + result += " "; + } + + result += CheckArgument(argv[i]); + i++; + } + + strncpy(commandline, result.c_str(), sizeof(commandline)); +} diff --git a/bc/os/CommandLine.hpp b/bc/os/CommandLine.hpp new file mode 100644 index 0000000..53ccd3a --- /dev/null +++ b/bc/os/CommandLine.hpp @@ -0,0 +1,10 @@ +#ifndef BC_OS_COMMAND_LINE_HPP +#define BC_OS_COMMAND_LINE_HPP + +#include + +const char* OsGetCommandLine(); + +void OsSetCommandLine(int32_t argc, char** argv); + +#endif