Move get_Command_line_args function into WIN32 define macro (to allow building on Linux).
This commit is contained in:
parent
110857949d
commit
fa4d1be9c4
@ -3011,33 +3011,32 @@ int main(char**args,const int argn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_command_line_args( int * argc, char *** argv )
|
||||
{
|
||||
// Get the command line arguments as wchar_t strings
|
||||
wchar_t ** wargv = CommandLineToArgvW( GetCommandLineW(), argc );
|
||||
if (!wargv) { *argc = 0; *argv = NULL; return; }
|
||||
|
||||
// Count the number of bytes necessary to store the UTF-8 versions of those strings
|
||||
int n = 0;
|
||||
for (int i = 0; i < *argc; i++)
|
||||
n += WideCharToMultiByte( CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL ) + 1;
|
||||
|
||||
// Allocate the argv[] array + all the UTF-8 strings
|
||||
*argv = (char**)(malloc( (*argc + 1) * sizeof(char *) + n ));
|
||||
if (!*argv) { *argc = 0; return; }
|
||||
|
||||
// Convert all wargv[] --> argv[]
|
||||
char * arg = (char *)&((*argv)[*argc + 1]);
|
||||
for (int i = 0; i < *argc; i++)
|
||||
{
|
||||
(*argv)[i] = arg;
|
||||
arg += WideCharToMultiByte( CP_UTF8, 0, wargv[i], -1, arg, n, NULL, NULL ) + 1;
|
||||
}
|
||||
(*argv)[*argc] = NULL;
|
||||
}
|
||||
|
||||
#ifndef _DEBUG
|
||||
#ifdef _WIN32
|
||||
void get_command_line_args( int * argc, char *** argv )
|
||||
{
|
||||
// Get the command line arguments as wchar_t strings
|
||||
wchar_t ** wargv = CommandLineToArgvW( GetCommandLineW(), argc );
|
||||
if (!wargv) { *argc = 0; *argv = NULL; return; }
|
||||
|
||||
// Count the number of bytes necessary to store the UTF-8 versions of those strings
|
||||
int n = 0;
|
||||
for (int i = 0; i < *argc; i++)
|
||||
n += WideCharToMultiByte( CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL ) + 1;
|
||||
|
||||
// Allocate the argv[] array + all the UTF-8 strings
|
||||
*argv = (char**)(malloc( (*argc + 1) * sizeof(char *) + n ));
|
||||
if (!*argv) { *argc = 0; return; }
|
||||
|
||||
// Convert all wargv[] --> argv[]
|
||||
char * arg = (char *)&((*argv)[*argc + 1]);
|
||||
for (int i = 0; i < *argc; i++)
|
||||
{
|
||||
(*argv)[i] = arg;
|
||||
arg += WideCharToMultiByte( CP_UTF8, 0, wargv[i], -1, arg, n, NULL, NULL ) + 1;
|
||||
}
|
||||
(*argv)[*argc] = NULL;
|
||||
}
|
||||
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
|
||||
int argc;
|
||||
char ** argv;
|
||||
|
Loading…
x
Reference in New Issue
Block a user