11#if defined(_WIN32) && !defined(__CYGWIN__)
37#if !defined(_WIN32) || defined(__CYGWIN__)
39static std::map<std::string,std::string>
proc_env = std::map<std::string,std::string>();
53 std::lock_guard<std::mutex> lock(
m_mutex);
54 m_startTimes[std::this_thread::get_id()] = std::chrono::steady_clock::now();
59 std::lock_guard<std::mutex> lock(
m_mutex);
60 std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
64 err(
"SysTimeKeeper stop() called without matching start()\n");
67 double timeSpent =
static_cast<double>(std::chrono::duration_cast<
68 std::chrono::microseconds>(endTime - it->second).count())/1000000.0;
80 std::map<std::thread::id,std::chrono::steady_clock::time_point>
m_startTimes;
108 if (command.
isEmpty())
return 1;
111#if defined(_WIN32) && !defined(__CYGWIN__)
113 QCString fullCmd=commandCorrectedPath;
118 if (fullCmd.
at(0)!=
'"' && fullCmd.
find(
' ')!=-1)
121 fullCmd=
"\""+fullCmd+
"\"";
129#if !defined(_WIN32) || defined(__CYGWIN__)
130 (void)commandHasConsole;
146 execl(
"/bin/sh",
"sh",
"-c",fullCmd.
data(),(
char*)0);
151 while (waitpid(
pid,&status,0 )<0)
167 perror(
"fork error");
172 const char *
const argv[4] = {
"sh",
"-c", fullCmd.
data(), 0 };
173 execve(
"/bin/sh",
const_cast<char * const*
>(argv),
environ);
178 if (waitpid(
pid,&status,0)==-1)
180 if (errno!=EINTR)
return -1;
184 if (WIFEXITED(status))
186 return WEXITSTATUS(status);
197 if (commandHasConsole)
199 return ::system(fullCmd.
data());
209 CoInitializeEx(
nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
211 uint16_t *commandw =
nullptr;
213 uint16_t *argsw =
nullptr;
220 SHELLEXECUTEINFOW sInfo = {
221 sizeof(SHELLEXECUTEINFOW),
222 SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI,
241 if (!ShellExecuteExW(&sInfo))
247 else if (sInfo.hProcess)
249 WaitForSingleObject(sInfo.hProcess,INFINITE);
252 bool retval = GetExitCodeProcess(sInfo.hProcess,&exitCode);
253 CloseHandle(sInfo.hProcess);
256 if (!retval)
return -1;
268#if !defined(_WIN32) || defined(__CYGWIN__)
269 pid =
static_cast<uint32_t
>(getpid());
271 pid =
static_cast<uint32_t
>(GetCurrentProcessId());
276#if !defined(_WIN32) || defined(__CYGWIN__)
284 while(current !=
nullptr)
286 std::string env_var(current);
287 size_t pos = env_var.find(
"=");
288 if(pos != std::string::npos)
290 std::string name = env_var.substr(0,pos);
291 std::string value = env_var.substr(pos + 1);
305#if defined(_WIN32) && !defined(__CYGWIN__)
306 SetEnvironmentVariable(name.
data(),!value.
isEmpty() ? value.
data() :
"");
320#if defined(_WIN32) && !defined(__CYGWIN__)
321 SetEnvironmentVariable(variable.
data(),
nullptr);
340#if defined(_WIN32) && !defined(__CYGWIN__)
341 #define ENV_BUFSIZE 32768
342 LPTSTR pszVal = (LPTSTR) malloc(ENV_BUFSIZE*
sizeof(TCHAR));
343 if (GetEnvironmentVariable(variable.
data(),pszVal,ENV_BUFSIZE) == 0)
return "";
368#if defined(_WIN32) && !defined(__CYGWIN__)
369 uint16_t *fn =
nullptr;
371 uint16_t *m =
nullptr;
373 FILE *result =
nullptr;
374 if (fn_len!=(
size_t)-1 && m_len!=(
size_t)-1)
376 result = _wfopen((
wchar_t*)fn,(
wchar_t*)m);
382 return ::fopen(fileName.
data(),mode.
data());
393#if defined(_WIN32) && !defined(__CYGWIN__)
402#if defined(_WIN32) && !defined(__CYGWIN__)
412 if (fi1.
exists())
return true;
419 while ((idx = paths.
find(listSep,strt)) != -1)
425 if (fi.
exists())
return true;
435 if (fi.
exists())
return true;
442#if defined(_WIN32) && !defined(__CYGWIN__)
443 const char *extensions[] = {
".bat",
".com",
".exe"};
444 for (
int i = 0; i <
sizeof(extensions) /
sizeof(*extensions); i++)
446 if (
ExistsOnPath(fileName + extensions[i]))
return true;
456#if defined(_WIN32) && !defined(__CYGWIN__)
457 static const char *gsexe =
nullptr;
460 const char *gsExec[] = {
"gswin32c.exe",
"gswin64c.exe"};
461 for (
int i = 0; i <
sizeof(gsExec) /
sizeof(*gsExec); i++)
480#if defined(_WIN32) && !defined(__CYGWIN__)
489#if defined(_WIN32) || defined(macintosh) || defined(__MACOSX__) || defined(__APPLE__) || defined(__CYGWIN__)
498 #if defined(_MSC_VER) || defined(__BORLANDC__)
499 return ::_popen(name.
data(),type.
data());
501 return ::popen(name.
data(),type.
data());
507 #if defined(_MSC_VER) || defined(__BORLANDC__)
508 return ::_pclose(stream);
510 return ::pclose(stream);
516 const char *fn = fileName.
data();
518 if (fileName.
length()>1 && isalpha(fileName[0]) && fileName[1]==
':') fn+=2;
520 char const fst = fn[0];
521 if (fst ==
'/')
return true;
523 if (fst ==
'\\')
return true;
538#if defined(_WIN32) && !defined(__CYGWIN__)
539 for (
const auto &path : extraPaths)
541 if (!first) result+=
';';
548 for (
const auto &path : extraPaths)
550 if (!first) result+=
':';
563#if defined(_WIN32) && !defined(__CYGWIN__)
564 _unlink(fileName.
data());
572#if defined(_WIN32) && !defined(__CYGWIN__)
574 TCHAR* buffer =
nullptr;
579 buffer =
new TCHAR[length];
590 const char *needle,
size_t needle_len)
592 const char *
const last_possible = haystack + haystack_len - needle_len;
601 if (haystack_len < needle_len)
608 if (
begin[0] == needle[0] && !memcmp(&
begin[1], needle + 1, needle_len - 1))
619 size_t needle_len = strnlen(needle, haystack_len);
620 if (needle_len < haystack_len || !needle[needle_len])
622 const char *x =
portable_memmem(haystack, haystack_len, needle, needle_len);
623 if (x && !memchr(haystack, 0, x - haystack))
633#if defined(_WIN32) && !defined(__CYGWIN__)
642 if (inputStr.
isEmpty() || outBuf==
nullptr)
return 0;
644 if (handle==
reinterpret_cast<void *
>(-1))
return 0;
645 size_t len = inputStr.
length();
646 uint16_t *buf =
new uint16_t[len+1];
648 size_t inRemains = len;
649 size_t outRemains = len*
sizeof(uint16_t)+2;
650 const char *p = inputStr.
data();
651 portable_iconv(handle,&p,&inRemains,
reinterpret_cast<char **
>(&buf),&outRemains);
661#include "filesystem.hpp"
663namespace fs = ghc::filesystem;
667 std::ios_base::openmode mode = std::ofstream::out | std::ofstream::binary;
668 if (append) mode |= std::ofstream::app;
669#if defined(__clang__) && defined(__MINGW32__)
670 return std::ofstream(fs::path(fileName.
str()).wstring(), mode);
672 return std::ofstream(fs::path(fileName.
str()), mode);
678 std::ios_base::openmode mode = std::ifstream::in | std::ifstream::binary;
679 if (binary) mode |= std::ios::binary;
680 if (openAtEnd) mode |= std::ios::ate;
681#if defined(__clang__) && defined(__MINGW32__)
682 return std::ifstream(fs::path(fileName.
str()).wstring(), mode);
684 return std::ifstream(fs::path(fileName.
str()), mode);
static void print(DebugMask mask, int prio, const char *fmt,...)
static std::string currentDirPath()
static bool setCurrent(const std::string &path)
Minimal replacement for QFileInfo.
This is an alternative implementation of QCString.
int find(char c, int index=0, bool cs=TRUE) const
size_t length() const
Returns the length of the string, not counting the 0-terminator.
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
char & at(size_t i)
Returns a reference to the character at index i.
bool isEmpty() const
Returns TRUE iff the string is empty.
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
const std::string & str() const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
void stop()
ends a timer for this thread, accumulate time difference since start
void start()
start a timer for this thread
double elapsedTime() const
static SysTimeKeeper & instance()
std::map< std::thread::id, std::chrono::steady_clock::time_point > m_startTimes
std::vector< std::string > StringVector
DirIterator begin(DirIterator it) noexcept
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
void correctPath(const StringVector &list)
Correct a possible wrong PATH variable.
bool isAbsolutePath(const QCString &fileName)
FILE * popen(const QCString &name, const QCString &type)
std::ofstream openOutputStream(const QCString &name, bool append=false)
double getSysElapsedTime()
QCString pathListSeparator()
bool checkForExecutable(const QCString &fileName)
void unlink(const QCString &fileName)
const char * ghostScriptCommand()
FILE * fopen(const QCString &fileName, const QCString &mode)
size_t recodeUtf8StringToW(const QCString &inputStr, uint16_t **buf)
bool fileSystemIsCaseSensitive()
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
void setenv(const QCString &variable, const QCString &value)
void unsetenv(const QCString &variable)
const char * commandExtension()
const char * strnstr(const char *haystack, const char *needle, size_t haystack_len)
QCString getenv(const QCString &variable)
static bool ExistsOnPath(const QCString &fileName)
static bool environmentLoaded
static std::map< std::string, std::string > proc_env
static const char * portable_memmem(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len)
Portable versions of functions that are platform dependent.
int portable_iconv_close(void *cd)
size_t portable_iconv(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
void * portable_iconv_open(const char *tocode, const char *fromcode)
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
const char * qPrint(const char *s)
std::chrono::steady_clock::time_point startTime
A bunch of utility functions.