Mercurial > octave
changeset 29626:efb5b450ab95
Windows: Support non-ASCII characters in command line arguments for GUI (bug #60535).
* liboctave/wrappers/unistd-wrappers.c (octave_execv_wrapper): Support non-ASCII
characters in path or command line arguments on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 07 May 2021 14:37:26 +0200 |
parents | 6707db623d9d |
children | f114b45ebbc9 |
files | liboctave/wrappers/unistd-wrappers.c |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/wrappers/unistd-wrappers.c Thu May 06 09:37:43 2021 -0700 +++ b/liboctave/wrappers/unistd-wrappers.c Fri May 07 14:37:26 2021 +0200 @@ -252,6 +252,40 @@ char **sanitized_argv = prepare_spawn (argv); +# if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE) + + // count number of arguments + size_t argc; + for (argc = 0; sanitized_argv[argc] != NULL; argc++) + ; + + wchar_t *wfile = u8_to_wchar (file); + const wchar_t **wargv = malloc ((argc + 1) * sizeof (wchar_t *)); + + // convert multibyte UTF-8 strings to wide character strings + for (size_t i_arg = 0; i_arg < argc; i_arg++) + wargv[i_arg] = u8_to_wchar (sanitized_argv[i_arg]); + + wargv[argc] = NULL; + + char **p = sanitized_argv; + while (*p) + free (*p++); + free (sanitized_argv); + + int status = _wspawnv (P_OVERLAY, wfile, wargv); + + // This only happens if _wspawnv fails. + + free (wfile); + const wchar_t **wp = wargv; + // Casting away the const in the loop is ok here. + while (*wp) + free ((wchar_t *) *wp++); + free (wargv); + +# else + int status = spawnv (P_OVERLAY, file, sanitized_argv); // This only happens if spawnv fails. @@ -261,6 +295,8 @@ free (*p++); free (sanitized_argv); +# endif + return status; #else