Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /** |
michael@0 | 2 | * On Windows, a Unicode argument is passed as UTF-16 using ShellExecuteExW. |
michael@0 | 3 | * On other platforms, it is passed as UTF-8 |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | static const int args_length = 4; |
michael@0 | 7 | #if defined(XP_WIN) && defined(_MSC_VER) |
michael@0 | 8 | #define _UNICODE |
michael@0 | 9 | #include <tchar.h> |
michael@0 | 10 | #include <stdio.h> |
michael@0 | 11 | |
michael@0 | 12 | static const _TCHAR* expected_utf16[args_length] = { |
michael@0 | 13 | // Latin-1 |
michael@0 | 14 | L"M\xF8z\xEEll\xE5", |
michael@0 | 15 | // Cyrillic |
michael@0 | 16 | L"\x41C\x43E\x437\x438\x43B\x43B\x430", |
michael@0 | 17 | // Bengali |
michael@0 | 18 | L"\x9AE\x9CB\x99C\x9BF\x9B2\x9BE", |
michael@0 | 19 | // Cuneiform |
michael@0 | 20 | L"\xD808\xDE2C\xD808\xDF63\xD808\xDDB7" |
michael@0 | 21 | }; |
michael@0 | 22 | |
michael@0 | 23 | int wmain(int argc, _TCHAR* argv[]) { |
michael@0 | 24 | printf("argc = %d\n", argc); |
michael@0 | 25 | |
michael@0 | 26 | if (argc != args_length + 1) |
michael@0 | 27 | return -1; |
michael@0 | 28 | |
michael@0 | 29 | for (int i = 1; i < argc; ++i) { |
michael@0 | 30 | printf("expected[%d]: ", i - 1); |
michael@0 | 31 | for (size_t j = 0; j < _tcslen(expected_utf16[i - 1]); ++j) { |
michael@0 | 32 | printf("%x ", *(expected_utf16[i - 1] + j)); |
michael@0 | 33 | } |
michael@0 | 34 | printf("\n"); |
michael@0 | 35 | |
michael@0 | 36 | printf("argv[%d]: ", i); |
michael@0 | 37 | for (size_t j = 0; j < _tcslen(argv[i]); ++j) { |
michael@0 | 38 | printf("%x ", *(argv[i] + j)); |
michael@0 | 39 | } |
michael@0 | 40 | printf("\n"); |
michael@0 | 41 | |
michael@0 | 42 | if (_tcscmp(expected_utf16[i - 1], argv[i])) { |
michael@0 | 43 | return i; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | return 0; |
michael@0 | 48 | } |
michael@0 | 49 | #else |
michael@0 | 50 | #include <string.h> |
michael@0 | 51 | #include <stdio.h> |
michael@0 | 52 | |
michael@0 | 53 | static const char* expected_utf8[args_length] = { |
michael@0 | 54 | // Latin-1 |
michael@0 | 55 | "M\xC3\xB8z\xC3\xAEll\xC3\xA5", |
michael@0 | 56 | // Cyrillic |
michael@0 | 57 | "\xD0\x9C\xD0\xBE\xD0\xB7\xD0\xB8\xD0\xBB\xD0\xBB\xD0\xB0", |
michael@0 | 58 | // Bengali |
michael@0 | 59 | "\xE0\xA6\xAE\xE0\xA7\x8B\xE0\xA6\x9C\xE0\xA6\xBF\xE0\xA6\xB2\xE0\xA6\xBE", |
michael@0 | 60 | // Cuneiform |
michael@0 | 61 | "\xF0\x92\x88\xAC\xF0\x92\x8D\xA3\xF0\x92\x86\xB7" |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | int main(int argc, char* argv[]) { |
michael@0 | 65 | if (argc != args_length + 1) |
michael@0 | 66 | return -1; |
michael@0 | 67 | |
michael@0 | 68 | for (int i = 1; i < argc; ++i) { |
michael@0 | 69 | printf("argv[%d] = %s; expected = %s\n", i, argv[i], expected_utf8[i - 1]); |
michael@0 | 70 | if (strcmp(expected_utf8[i - 1], argv[i])) { |
michael@0 | 71 | return i; |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | return 0; |
michael@0 | 76 | } |
michael@0 | 77 | #endif |