Switched to spaces

This commit is contained in:
NeGate 2022-06-02 22:04:02 -04:00
parent 4b7f9dad52
commit 4b8d8692e5
1 changed files with 36 additions and 36 deletions

View File

@ -12,54 +12,54 @@ DECLSPEC_IMPORT LPWSTR GetCommandLineW();
DECLSPEC_IMPORT LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs); DECLSPEC_IMPORT LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
static size_t count_wide_chars(const wchar_t* str) { static size_t count_wide_chars(const wchar_t* str) {
size_t len = 0; size_t len = 0;
while (str[len] != 0) len++; while (str[len] != 0) len++;
return len; return len;
} }
static bool convert_wide_chars_to_ansi(char* out, const wchar_t* str, size_t len) { static bool convert_wide_chars_to_ansi(char* out, const wchar_t* str, size_t len) {
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
wchar_t ch = *str++; wchar_t ch = *str++;
if (ch <= 0 && ch > 0x7F) { if (ch <= 0 && ch > 0x7F) {
*out++ = 0; *out++ = 0;
return false; return false;
} }
*out++ = ch; *out++ = ch;
} }
*out++ = 0; *out++ = 0;
return true; return true;
} }
void mainCRTStartup() { void mainCRTStartup() {
HANDLE heap = GetProcessHeap(); HANDLE heap = GetProcessHeap();
if (heap == NULL) { if (heap == NULL) {
ExitProcess(-42069); ExitProcess(-42069);
} }
int arg_count; int arg_count;
LPWSTR* args_wide = CommandLineToArgvW(GetCommandLineW(), &arg_count); LPWSTR* args_wide = CommandLineToArgvW(GetCommandLineW(), &arg_count);
if (!args_wide) { if (!args_wide) {
ExitProcess(-69420); ExitProcess(-69420);
} }
char** args = HeapAlloc(heap, 0, arg_count * sizeof(char*)); char** args = HeapAlloc(heap, 0, arg_count * sizeof(char*));
if (arg_count == 0) { if (arg_count == 0) {
arg_count = 1; arg_count = 1;
args[0] = ""; args[0] = "";
} }
// Convert wide chars into ANSI // Convert wide chars into ANSI
for (int i = 0; i < arg_count; i++) { for (int i = 0; i < arg_count; i++) {
size_t wide_len = count_wide_chars(args_wide[i]) + 1; size_t wide_len = count_wide_chars(args_wide[i]) + 1;
args[i] = HeapAlloc(heap, 0, wide_len); args[i] = HeapAlloc(heap, 0, wide_len);
convert_wide_chars_to_ansi(args[i], args_wide[i], wide_len); convert_wide_chars_to_ansi(args[i], args_wide[i], wide_len);
} }
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
int exit_code = main(arg_count, args); int exit_code = main(arg_count, args);
ExitProcess(exit_code); ExitProcess(exit_code);
} }