Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
483d4b2f
Commit
483d4b2f
authored
11 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
use unicode versions of ShellExecute and CreateProcess
parent
dd964959
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Common/OS.cpp
+14
-7
14 additions, 7 deletions
Common/OS.cpp
with
14 additions
and
7 deletions
Common/OS.cpp
+
14
−
7
View file @
483d4b2f
...
...
@@ -139,14 +139,14 @@ static unsigned utf8toUtf16(const char* src, unsigned srclen,
return
count
;
}
static
wchar_t
*
wbuf
[
2
]
=
{
NULL
,
NULL
};
static
wchar_t
*
wbuf
[
3
]
=
{
NULL
,
NULL
,
NULL
};
static
void
setwbuf
(
int
i
,
const
char
*
f
)
{
// all strings in Gmsh are supposed to be UTF8-encoded, which is natively
// supported by Mac and Linux. Windows does not support UTF-8, but UTF-16
// (through wchar_t), so we need to convert.
if
(
i
!=
0
&&
i
!=
1
)
return
;
if
(
i
<
0
||
i
>
2
)
return
;
size_t
l
=
strlen
(
f
);
unsigned
wn
=
utf8toUtf16
(
f
,
(
unsigned
)
l
,
NULL
,
0
)
+
1
;
wbuf
[
i
]
=
(
wchar_t
*
)
realloc
(
wbuf
[
i
],
sizeof
(
wchar_t
)
*
wn
);
...
...
@@ -170,6 +170,7 @@ FILE *Fopen(const char *f, const char *mode)
const
char
*
GetEnvironmentVar
(
const
char
*
var
)
{
#if defined(WIN32) && !defined(__CYGWIN__)
// Should probably use the Unicode version
const
char
*
tmp
=
getenv
(
var
);
// Don't accept top dir or anything partially expanded like
// c:\Documents and Settings\%USERPROFILE%, etc.
...
...
@@ -185,6 +186,7 @@ const char *GetEnvironmentVar(const char *var)
const
void
SetEnvironmentVar
(
const
char
*
var
,
const
char
*
val
)
{
#if defined(WIN32) && !defined(__CYGWIN__)
// should probably use Unicode version here
_putenv
((
std
::
string
(
var
)
+
"="
+
std
::
string
(
val
)).
c_str
());
#else
setenv
(
var
,
val
,
1
);
...
...
@@ -368,8 +370,10 @@ int SystemCall(const std::string &command, bool blocking)
if
(
isPython
){
Msg
::
Info
(
"Shell opening '%s' with arguments '%s'"
,
exe
.
c_str
(),
args
.
c_str
());
ShellExecute
(
NULL
,
(
char
*
)
"open"
,
(
char
*
)
exe
.
c_str
(),
(
char
*
)
args
.
c_str
(),
NULL
,
0
);
setwbuf
(
0
,
"open"
);
setwbuf
(
1
,
exe
.
c_str
());
setwbuf
(
2
,
args
.
c_str
());
ShellExecuteW
(
NULL
,
wbuf
[
0
],
wbuf
[
1
],
wbuf
[
2
],
NULL
,
0
);
}
else
{
STARTUPINFO
suInfo
;
...
...
@@ -377,8 +381,9 @@ int SystemCall(const std::string &command, bool blocking)
memset
(
&
suInfo
,
0
,
sizeof
(
suInfo
));
suInfo
.
cb
=
sizeof
(
suInfo
);
Msg
::
Info
(
"Calling '%s'"
,
command
.
c_str
());
setwbuf
(
0
,
command
.
c_str
());
if
(
blocking
){
CreateProcess
(
NULL
,
(
char
*
)
command
.
c_str
()
,
NULL
,
NULL
,
FALSE
,
CreateProcess
W
(
NULL
,
wbuf
[
0
]
,
NULL
,
NULL
,
FALSE
,
NORMAL_PRIORITY_CLASS
,
NULL
,
NULL
,
&
suInfo
,
&
prInfo
);
// wait until child process exits.
...
...
@@ -390,7 +395,7 @@ int SystemCall(const std::string &command, bool blocking)
else
{
// DETACHED_PROCESS removes the console (useful if the program to launch
// is a console-mode exe)
CreateProcess
(
NULL
,
(
char
*
)
command
.
c_str
()
,
NULL
,
NULL
,
FALSE
,
CreateProcess
W
(
NULL
,
wbuf
[
0
]
,
NULL
,
NULL
,
FALSE
,
NORMAL_PRIORITY_CLASS
|
DETACHED_PROCESS
,
NULL
,
NULL
,
&
suInfo
,
&
prInfo
);
}
...
...
@@ -400,7 +405,8 @@ int SystemCall(const std::string &command, bool blocking)
if
(
isPython
||
isExe
){
if
(
access
(
exe
.
c_str
(),
X_OK
)){
if
(
isPython
){
Msg
::
Info
(
"Script '%s' is not executable: running with python"
,
exe
.
c_str
());
Msg
::
Info
(
"Script '%s' is not executable: running with python"
,
exe
.
c_str
());
cmd
=
"python "
+
cmd
;
}
else
...
...
@@ -427,6 +433,7 @@ std::string GetCurrentWorkdir()
char
path
[
1024
];
#if defined(WIN32) && !defined(__CYGWIN__)
// should use Unicode version
if
(
!
_getcwd
(
path
,
sizeof
(
path
)))
return
""
;
#else
if
(
!
getcwd
(
path
,
sizeof
(
path
)))
return
""
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment