diff options
author | sfan5 <sfan5@live.de> | 2023-01-23 00:19:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-23 00:19:30 +0100 |
commit | 87d509e4625df2d76a80f14cab3d420bd58ba20a (patch) | |
tree | 8a17b87abf96312a79f49c05c7c4824766bcb39f /src/porting.cpp | |
parent | 6f5703baf1737ca1d7dd70982e878fd83d288cdd (diff) | |
download | minetest-87d509e4625df2d76a80f14cab3d420bd58ba20a.tar.xz |
Implement --debugger option to improve UX when debugging crashes (#13157)
Diffstat (limited to 'src/porting.cpp')
-rw-r--r-- | src/porting.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/porting.cpp b/src/porting.cpp index 475292b97..629f00c37 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -729,6 +729,38 @@ void attachOrCreateConsole() #endif } +#ifdef _WIN32 +std::string QuoteArgv(const std::string &arg) +{ + // Quoting rules on Windows are batshit insane, can differ between applications + // and there isn't even a stdlib function to deal with it. + // Ref: https://learn.microsoft.com/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way + if (!arg.empty() && arg.find_first_of(" \t\n\v\"") == std::string::npos) + return arg; + + std::string ret; + ret.reserve(arg.size()+2); + ret.push_back('"'); + for (auto it = arg.begin(); it != arg.end(); ++it) { + u32 back = 0; + while (it != arg.end() && *it == '\\') + ++back, ++it; + + if (it == arg.end()) { + ret.append(2 * back, '\\'); + break; + } else if (*it == '"') { + ret.append(2 * back + 1, '\\'); + } else { + ret.append(back, '\\'); + } + ret.push_back(*it); + } + ret.push_back('"'); + return ret; +} +#endif + int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...) { // https://msdn.microsoft.com/en-us/library/bt7tawza.aspx |