1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement --debugger option to improve UX when debugging crashes (#13157)

This commit is contained in:
sfan5 2023-01-23 00:19:30 +01:00 committed by GitHub
parent 6f5703baf1
commit 87d509e462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 193 additions and 17 deletions

View file

@ -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