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());
203 uint16_t* fullCmdW =
nullptr;
206 STARTUPINFOW sStartupInfo;
207 std::memset(&sStartupInfo, 0,
sizeof(sStartupInfo));
208 sStartupInfo.cb =
sizeof(sStartupInfo);
209 sStartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
210 sStartupInfo.wShowWindow = SW_HIDE;
212 PROCESS_INFORMATION sProcessInfo;
213 std::memset(&sProcessInfo, 0,
sizeof(sProcessInfo));
217 reinterpret_cast<wchar_t*
>(fullCmdW),
231 else if (sProcessInfo.hProcess)
233 WaitForSingleObject(sProcessInfo.hProcess,INFINITE);
236 bool retval = GetExitCodeProcess(sProcessInfo.hProcess,&exitCode);
237 CloseHandle(sProcessInfo.hProcess);
238 CloseHandle(sProcessInfo.hThread);
240 if (!retval)
return -1;
252#if !defined(_WIN32) || defined(__CYGWIN__)
253 pid =
static_cast<uint32_t
>(getpid());
255 pid =
static_cast<uint32_t
>(GetCurrentProcessId());
260#if !defined(_WIN32) || defined(__CYGWIN__)
268 while(current !=
nullptr)
270 std::string env_var(current);
271 size_t pos = env_var.find(
"=");
272 if(pos != std::string::npos)
274 std::string name = env_var.substr(0,pos);
275 std::string value = env_var.substr(pos + 1);
289#if defined(_WIN32) && !defined(__CYGWIN__)
290 SetEnvironmentVariable(name.
data(),!value.
isEmpty() ? value.
data() :
"");
304#if defined(_WIN32) && !defined(__CYGWIN__)
305 SetEnvironmentVariable(variable.
data(),
nullptr);
324#if defined(_WIN32) && !defined(__CYGWIN__)
325 #define ENV_BUFSIZE 32768
326 LPTSTR pszVal = (LPTSTR) malloc(ENV_BUFSIZE*
sizeof(TCHAR));
327 if (GetEnvironmentVariable(variable.
data(),pszVal,ENV_BUFSIZE) == 0)
return "";
352#if defined(_WIN32) && !defined(__CYGWIN__)
353 uint16_t *fn =
nullptr;
355 uint16_t *m =
nullptr;
357 FILE *result =
nullptr;
358 if (fn_len!=(
size_t)-1 && m_len!=(
size_t)-1)
360 result = _wfopen((
wchar_t*)fn,(
wchar_t*)m);
366 return ::fopen(fileName.
data(),mode.
data());
377#if defined(_WIN32) && !defined(__CYGWIN__)
386#if defined(_WIN32) && !defined(__CYGWIN__)
396 if (fi1.
exists())
return true;
403 while ((idx = paths.
find(listSep,strt)) != -1)
409 if (fi.
exists())
return true;
419 if (fi.
exists())
return true;
426#if defined(_WIN32) && !defined(__CYGWIN__)
427 const char *extensions[] = {
".bat",
".com",
".exe"};
428 for (
int i = 0; i <
sizeof(extensions) /
sizeof(*extensions); i++)
430 if (
ExistsOnPath(fileName + extensions[i]))
return true;
440#if defined(_WIN32) && !defined(__CYGWIN__)
441 static const char *gsexe =
nullptr;
444 const char *gsExec[] = {
"gswin32c.exe",
"gswin64c.exe"};
445 for (
int i = 0; i <
sizeof(gsExec) /
sizeof(*gsExec); i++)
464#if defined(_WIN32) && !defined(__CYGWIN__)
473#if defined(_WIN32) || defined(macintosh) || defined(__MACOSX__) || defined(__APPLE__) || defined(__CYGWIN__)
482 #if defined(_MSC_VER) || defined(__BORLANDC__)
483 return ::_popen(name.
data(),type.
data());
485 return ::popen(name.
data(),type.
data());
491 #if defined(_MSC_VER) || defined(__BORLANDC__)
492 return ::_pclose(stream);
494 return ::pclose(stream);
500 const char *fn = fileName.
data();
502 if (fileName.
length()>1 && isalpha(fileName[0]) && fileName[1]==
':') fn+=2;
504 char const fst = fn[0];
505 if (fst ==
'/')
return true;
507 if (fst ==
'\\')
return true;
522#if defined(_WIN32) && !defined(__CYGWIN__)
523 for (
const auto &path : extraPaths)
525 if (!first) result+=
';';
532 for (
const auto &path : extraPaths)
534 if (!first) result+=
':';
547#if defined(_WIN32) && !defined(__CYGWIN__)
548 _unlink(fileName.
data());
556#if defined(_WIN32) && !defined(__CYGWIN__)
558 TCHAR* buffer =
nullptr;
563 buffer =
new TCHAR[length];
574 const char *needle,
size_t needle_len)
576 const char *
const last_possible = haystack + haystack_len - needle_len;
585 if (haystack_len < needle_len)
592 if (
begin[0] == needle[0] && !memcmp(&
begin[1], needle + 1, needle_len - 1))
603 size_t needle_len = strnlen(needle, haystack_len);
604 if (needle_len < haystack_len || !needle[needle_len])
606 const char *x =
portable_memmem(haystack, haystack_len, needle, needle_len);
607 if (x && !memchr(haystack, 0, x - haystack))
617#if defined(_WIN32) && !defined(__CYGWIN__)
626 if (inputStr.
isEmpty() || outBuf==
nullptr)
return 0;
628 if (handle==
reinterpret_cast<void *
>(-1))
return 0;
629 size_t len = inputStr.
length();
630 uint16_t *buf =
new uint16_t[len+1];
632 size_t inRemains = len;
633 size_t outRemains = len*
sizeof(uint16_t)+2;
634 const char *p = inputStr.
data();
635 portable_iconv(handle,&p,&inRemains,
reinterpret_cast<char **
>(&buf),&outRemains);
645#include "filesystem.hpp"
647namespace fs = ghc::filesystem;
651 std::ios_base::openmode mode = std::ofstream::out | std::ofstream::binary;
652 if (append) mode |= std::ofstream::app;
653#if defined(__clang__) && defined(__MINGW32__)
654 return std::ofstream(fs::path(fileName.
str()).wstring(), mode);
656 return std::ofstream(fs::path(fileName.
str()), mode);
662 std::ios_base::openmode mode = std::ifstream::in | std::ifstream::binary;
663 if (binary) mode |= std::ios::binary;
664 if (openAtEnd) mode |= std::ios::ate;
665#if defined(__clang__) && defined(__MINGW32__)
666 return std::ifstream(fs::path(fileName.
str()).wstring(), mode);
668 return std::ifstream(fs::path(fileName.
str()), mode);
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
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
std::chrono::steady_clock::time_point startTime
A bunch of utility functions.