|
2 | 2 | #include <windows.h> |
3 | 3 | #include <shlwapi.h> |
4 | 4 |
|
| 5 | +#include <cstdio> |
| 6 | +#include <clocale> |
5 | 7 | #include <cstring> |
6 | 8 | #include <iostream> |
7 | 9 | #include <vector> |
| 10 | +#include <io.h> |
| 11 | +#include <fcntl.h> |
8 | 12 |
|
9 | 13 | #include "exceptions.hh" |
10 | 14 | #include "gas.hh" |
11 | 15 | #include "platform.hh" |
12 | 16 |
|
13 | 17 | using namespace xamarin::android::gas; |
14 | 18 |
|
| 19 | +namespace { |
| 20 | + void log_cp_info(std::wstring label, UINT cp) |
| 21 | + { |
| 22 | + std::wcout << L" " << label << L" code page:" << std::endl; |
| 23 | + std::wcout << L" ID: " << cp << std::endl; |
| 24 | + |
| 25 | + CPINFOEX cpinfo; |
| 26 | + BOOL result = GetCPInfoEx(cp, 0, &cpinfo); |
| 27 | + if (!result) { |
| 28 | + std::wcout << L" failed to obtain more information about the code page" << std::endl; |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + std::wcout |
| 33 | + << L" Maximum character size: " << cpinfo.MaxCharSize << std::endl |
| 34 | + << L" Localized name: " << cpinfo.CodePageName << std::endl; |
| 35 | + } |
| 36 | + |
| 37 | + void log_cli_arg(int index, const wchar_t* arg) |
| 38 | + { |
| 39 | + std::wcout << L" [" << index << L"] " << std::endl; |
| 40 | + std::wcout << std::endl; |
| 41 | + std::wstring ws(arg); |
| 42 | + std::wcout << L" As C string (direct): " << ws << std::endl; |
| 43 | + std::wcout << L" As hex bytes: " << std::hex << std::setw(4) << std::setfill(L'0'); |
| 44 | + |
| 45 | + const wchar_t* p = arg; |
| 46 | + while (p != nullptr && *p != 0) { |
| 47 | + auto ch = static_cast<uint16_t>(*p); |
| 48 | + std::wcout << ch << " "; |
| 49 | + p++; |
| 50 | + } |
| 51 | + std::wcout << std::endl; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +void Gas::dump_command_line_args (int argc, wchar_t **argv) |
| 56 | +{ |
| 57 | + std::wcout << L"Active code pages information" << std::endl; |
| 58 | + log_cp_info(L"OS", GetACP()); |
| 59 | + std::wcout << std::endl; |
| 60 | + log_cp_info(L"OEM", GetOEMCP()); |
| 61 | + std::wcout << std::endl; |
| 62 | + |
| 63 | + std::wcout << L"Command line arguments (" << argc << "):" << std::endl; |
| 64 | + for (int i = 0; i < argc; i++) { |
| 65 | + log_cli_arg(i, argv[i]); |
| 66 | + } |
| 67 | + std::wcout << L"================================" << std::endl << std::endl; |
| 68 | +} |
| 69 | + |
| 70 | +void Gas::platform_setup() |
| 71 | +{ |
| 72 | + // Windows needs that magic to make stdout work with wchar_t and friends |
| 73 | + constexpr char cp_utf16le[] = ".1200"; // UTF-16 little-endian locale. |
| 74 | + setlocale(LC_ALL, cp_utf16le); |
| 75 | + _setmode(_fileno(stdout), _O_WTEXT); |
| 76 | +} |
| 77 | + |
15 | 78 | void Gas::determine_program_dir (std::vector<platform::string> args) |
16 | 79 | { |
17 | 80 | TCHAR buffer[MAX_PATH + 1]{}; |
|
0 commit comments