-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test,doc: enable running embedtest for Windows
- Loading branch information
Showing
7 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "utf8_args.h" | ||
|
||
#ifdef _WIN32 | ||
|
||
#include <malloc.h> | ||
#include <shellapi.h> | ||
#include <windows.h> | ||
|
||
void GetUtf8CommandLineArgs(int* argc, char*** argv) { | ||
int wargc; | ||
wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); | ||
if (wargv == NULL) { | ||
*argc = 0; | ||
*argv = NULL; | ||
return; | ||
} | ||
|
||
*argc = wargc; | ||
*argv = (char**)malloc(wargc * sizeof(char*)); | ||
for (int i = 0; i < wargc; ++i) { | ||
int len = | ||
WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL); | ||
(*argv)[i] = malloc(len); | ||
WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, (*argv)[i], len, NULL, NULL); | ||
} | ||
|
||
LocalFree(wargv); | ||
} | ||
|
||
void FreeUtf8CommandLineArgs(int argc, char** argv) { | ||
for (int i = 0; i < argc; ++i) { | ||
free(argv[i]); | ||
} | ||
free(argv); | ||
} | ||
|
||
#else | ||
|
||
void GetUtf8CommandLineArgs(int* /*argc*/, char*** /*argv*/) { | ||
// Do nothing on non-Windows platforms. | ||
} | ||
|
||
void FreeUtf8CommandLineArgs(int /*argc*/, char** /*argv*/) { | ||
// Do nothing on non-Windows platforms. | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef TEST_EMBEDDING_UTF8_ARGS_H_ | ||
#define TEST_EMBEDDING_UTF8_ARGS_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// Windows does not support UTF-8 command line arguments. | ||
// We must get them using an alternative way. | ||
// This function does nothing on non-Windows platforms. | ||
void GetUtf8CommandLineArgs(int* argc, char*** argv); | ||
|
||
// Free the memory allocated by GetUtf8CommandLineArgs. | ||
void FreeUtf8CommandLineArgs(int argc, char** argv); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // TEST_EMBEDDING_UTF8_ARGS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters