mirror of
https://github.com/thunderbrewhq/bc.git
synced 2025-12-12 01:52:30 +00:00
feat(os): implement command line argument utilities
This commit is contained in:
parent
2716512a7f
commit
4f8d6e2016
2 changed files with 69 additions and 0 deletions
59
bc/os/CommandLine.cpp
Normal file
59
bc/os/CommandLine.cpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include "bc/os/CommandLine.hpp"
|
||||
#include "bc/Debug.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
// 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));
|
||||
}
|
||||
10
bc/os/CommandLine.hpp
Normal file
10
bc/os/CommandLine.hpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef BC_OS_COMMAND_LINE_HPP
|
||||
#define BC_OS_COMMAND_LINE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
const char* OsGetCommandLine();
|
||||
|
||||
void OsSetCommandLine(int32_t argc, char** argv);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue