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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nico Schlömer
gmsh
Commits
10458ef6
Commit
10458ef6
authored
10 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
first try at implementing GetExecutableName()
parent
e0afcba2
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Common/GmshMessage.cpp
+4
-4
4 additions, 4 deletions
Common/GmshMessage.cpp
Common/OS.cpp
+101
-0
101 additions, 0 deletions
Common/OS.cpp
Common/OS.h
+1
-0
1 addition, 0 deletions
Common/OS.h
Common/StringUtils.cpp
+2
-1
2 additions, 1 deletion
Common/StringUtils.cpp
with
108 additions
and
5 deletions
Common/GmshMessage.cpp
+
4
−
4
View file @
10458ef6
...
@@ -99,19 +99,19 @@ static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
...
@@ -99,19 +99,19 @@ static int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
static
void
addGmshPathToEnvironmentVar
(
const
std
::
string
&
name
)
static
void
addGmshPathToEnvironmentVar
(
const
std
::
string
&
name
)
{
{
std
::
vector
<
std
::
string
>
split
=
SplitFi
leName
(
CTX
::
instance
()
->
argv0
);
std
::
string
gmshPath
=
SplitFileName
(
GetExecutab
leName
(
CTX
::
instance
()
->
argv0
)
)[
0
]
;
std
::
string
path
;
std
::
string
path
;
char
*
tmp
=
getenv
(
name
.
c_str
());
char
*
tmp
=
getenv
(
name
.
c_str
());
if
(
tmp
){
if
(
tmp
){
path
=
tmp
;
path
=
tmp
;
#if defined(WIN32)
#if defined(WIN32)
path
+=
";"
+
split
[
0
]
;
path
+=
";"
+
gmshPath
;
#else
#else
path
+=
":"
+
split
[
0
]
;
path
+=
":"
+
gmshPath
;
#endif
#endif
}
}
else
else
path
=
split
[
0
]
;
path
=
gmshPath
;
SetEnvironmentVar
(
name
.
c_str
(),
path
.
c_str
());
SetEnvironmentVar
(
name
.
c_str
(),
path
.
c_str
());
}
}
...
...
This diff is collapsed.
Click to expand it.
Common/OS.cpp
+
101
−
0
View file @
10458ef6
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#if defined(__APPLE__)
#if defined(__APPLE__)
#include
<sys/sysctl.h>
#include
<sys/sysctl.h>
#include
<mach-o/dyld.h>
#endif
#endif
#if defined(__linux__) && !defined(BUILD_ANDROID)
#if defined(__linux__) && !defined(BUILD_ANDROID)
...
@@ -143,6 +144,68 @@ static unsigned utf8toUtf16(const char* src, unsigned srclen,
...
@@ -143,6 +144,68 @@ static unsigned utf8toUtf16(const char* src, unsigned srclen,
return
count
;
return
count
;
}
}
static
unsigned
utf8FromUtf16
(
char
*
dst
,
unsigned
dstlen
,
const
wchar_t
*
src
,
unsigned
srclen
)
{
unsigned
i
=
0
;
unsigned
count
=
0
;
if
(
dstlen
)
{
for
(;;)
{
unsigned
ucs
;
if
(
i
>=
srclen
)
{
dst
[
count
]
=
0
;
return
count
;}
ucs
=
src
[
i
++
];
if
(
ucs
<
0x80U
)
{
dst
[
count
++
]
=
ucs
;
if
(
count
>=
dstlen
)
{
dst
[
count
-
1
]
=
0
;
break
;}
}
else
if
(
ucs
<
0x800U
)
{
/* 2 bytes */
if
(
count
+
2
>=
dstlen
)
{
dst
[
count
]
=
0
;
count
+=
2
;
break
;}
dst
[
count
++
]
=
0xc0
|
(
ucs
>>
6
);
dst
[
count
++
]
=
0x80
|
(
ucs
&
0x3F
);
}
else
if
(
ucs
>=
0xd800
&&
ucs
<=
0xdbff
&&
i
<
srclen
&&
src
[
i
]
>=
0xdc00
&&
src
[
i
]
<=
0xdfff
)
{
/* surrogate pair */
unsigned
ucs2
=
src
[
i
++
];
ucs
=
0x10000U
+
((
ucs
&
0x3ff
)
<<
10
)
+
(
ucs2
&
0x3ff
);
/* all surrogate pairs turn into 4-byte utf8 */
if
(
count
+
4
>=
dstlen
)
{
dst
[
count
]
=
0
;
count
+=
4
;
break
;}
dst
[
count
++
]
=
0xf0
|
(
ucs
>>
18
);
dst
[
count
++
]
=
0x80
|
((
ucs
>>
12
)
&
0x3F
);
dst
[
count
++
]
=
0x80
|
((
ucs
>>
6
)
&
0x3F
);
dst
[
count
++
]
=
0x80
|
(
ucs
&
0x3F
);
}
else
{
/* all others are 3 bytes: */
if
(
count
+
3
>=
dstlen
)
{
dst
[
count
]
=
0
;
count
+=
3
;
break
;}
dst
[
count
++
]
=
0xe0
|
(
ucs
>>
12
);
dst
[
count
++
]
=
0x80
|
((
ucs
>>
6
)
&
0x3F
);
dst
[
count
++
]
=
0x80
|
(
ucs
&
0x3F
);
}
}
}
/* we filled dst, measure the rest: */
while
(
i
<
srclen
)
{
unsigned
ucs
=
src
[
i
++
];
if
(
ucs
<
0x80U
)
{
count
++
;
}
else
if
(
ucs
<
0x800U
)
{
/* 2 bytes */
count
+=
2
;
}
else
if
(
ucs
>=
0xd800
&&
ucs
<=
0xdbff
&&
i
<
srclen
-
1
&&
src
[
i
+
1
]
>=
0xdc00
&&
src
[
i
+
1
]
<=
0xdfff
)
{
/* surrogate pair */
++
i
;
count
+=
4
;
}
else
{
count
+=
3
;
}
}
return
count
;
}
static
wchar_t
*
wbuf
[
3
]
=
{
NULL
,
NULL
,
NULL
};
static
wchar_t
*
wbuf
[
3
]
=
{
NULL
,
NULL
,
NULL
};
static
void
setwbuf
(
int
i
,
const
char
*
f
)
static
void
setwbuf
(
int
i
,
const
char
*
f
)
...
@@ -312,6 +375,44 @@ int GetProcessId()
...
@@ -312,6 +375,44 @@ int GetProcessId()
#endif
#endif
}
}
std
::
string
GetExecutableName
(
const
std
::
string
&
argv0
)
{
std
::
string
name
=
""
;
#if defined(WIN32) && !defined(__CYGWIN__)
WCHAR
src
[
MAX_PATH
];
DWARD
size
=
GetModuleFileNameW
(
NULL
,
src
,
MAX_PATH
);
if
(
size
){
char
dst
[
MAX_PATH
];
utf8FromUtf16
(
dst
,
MAX_PATH
,
src
,
size
);
name
=
std
::
string
(
dst
);
}
#elif defined(__APPLE__)
char
path
[
PATH_MAX
];
uint32_t
size
=
sizeof
(
path
);
if
(
_NSGetExecutablePath
(
path
,
&
size
)
==
0
){
char
real
[
PATH_MAX
];
if
(
realpath
(
path
,
real
)){
name
=
std
::
string
(
real
);
}
}
#elif defined(__linux__)
char
path
[
PATH_MAX
];
int
s
=
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
));
if
(
s
>
0
){
path
[
s
-
1
]
=
'\0'
;
name
=
std
::
string
(
path
);
}
#endif
if
(
name
.
empty
()){
name
=
argv0
;
printf
(
"Found executable name through argv0 = '%s'
\n
"
,
name
.
c_str
());
}
else
printf
(
"Found executable name = '%s'
\n
"
,
name
.
c_str
());
return
name
;
}
std
::
string
GetHostName
()
std
::
string
GetHostName
()
{
{
char
host
[
256
];
char
host
[
256
];
...
...
This diff is collapsed.
Click to expand it.
Common/OS.h
+
1
−
0
View file @
10458ef6
...
@@ -18,6 +18,7 @@ double Cpu();
...
@@ -18,6 +18,7 @@ double Cpu();
double
TotalRam
();
double
TotalRam
();
long
GetMemoryUsage
();
long
GetMemoryUsage
();
int
GetProcessId
();
int
GetProcessId
();
std
::
string
GetExecutableName
(
const
std
::
string
&
argv0
);
std
::
string
GetHostName
();
std
::
string
GetHostName
();
int
UnlinkFile
(
const
std
::
string
&
fileName
);
int
UnlinkFile
(
const
std
::
string
&
fileName
);
int
StatFile
(
const
std
::
string
&
fileName
);
int
StatFile
(
const
std
::
string
&
fileName
);
...
...
This diff is collapsed.
Click to expand it.
Common/StringUtils.cpp
+
2
−
1
View file @
10458ef6
...
@@ -91,7 +91,8 @@ std::string FixRelativePath(const std::string &reference, const std::string &in)
...
@@ -91,7 +91,8 @@ std::string FixRelativePath(const std::string &reference, const std::string &in)
std
::
vector
<
std
::
string
>
SplitFileName
(
const
std
::
string
&
fileName
)
std
::
vector
<
std
::
string
>
SplitFileName
(
const
std
::
string
&
fileName
)
{
{
// JFR DO NOT CHANGE TO std::vector<std::string> s(3), it segfaults while destructor si called
// JFR DO NOT CHANGE TO std::vector<std::string> s(3), it segfaults while
// destructor si called
std
::
vector
<
std
::
string
>
s
;
s
.
resize
(
3
);
std
::
vector
<
std
::
string
>
s
;
s
.
resize
(
3
);
if
(
fileName
.
size
()){
if
(
fileName
.
size
()){
// returns [path, baseName, extension]
// returns [path, baseName, extension]
...
...
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