11#if defined(_WIN32) && !defined(__CYGWIN__)
36#if !defined(_WIN32) || defined(__CYGWIN__)
38static std::map<std::string,std::string>
proc_env = std::map<std::string,std::string>();
52 std::lock_guard<std::mutex> lock(
m_mutex);
53 m_startTimes[std::this_thread::get_id()] = std::chrono::steady_clock::now();
58 std::lock_guard<std::mutex> lock(
m_mutex);
59 std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
63 err(
"SysTimeKeeper stop() called without matching start()\n");
66 double timeSpent =
static_cast<double>(std::chrono::duration_cast<
67 std::chrono::microseconds>(endTime - it->second).count())/1000000.0;
79 std::map<std::thread::id,std::chrono::steady_clock::time_point>
m_startTimes;
107 if (command.
isEmpty())
return 1;
110#if defined(_WIN32) && !defined(__CYGWIN__)
112 QCString fullCmd=commandCorrectedPath;
117 if (fullCmd.
at(0)!=
'"' && fullCmd.
find(
' ')!=-1)
120 fullCmd=
"\""+fullCmd+
"\"";
128#if !defined(_WIN32) || defined(__CYGWIN__)
129 (void)commandHasConsole;
145 execl(
"/bin/sh",
"sh",
"-c",fullCmd.
data(),(
char*)0);
150 while (waitpid(
pid,&status,0 )<0)
166 perror(
"fork error");
171 const char *
const argv[4] = {
"sh",
"-c", fullCmd.
data(), 0 };
172 execve(
"/bin/sh",
const_cast<char * const*
>(argv),
environ);
177 if (waitpid(
pid,&status,0)==-1)
179 if (errno!=EINTR)
return -1;
183 if (WIFEXITED(status))
185 return WEXITSTATUS(status);
196 if (commandHasConsole)
198 return ::system(fullCmd.
data());
202 uint16_t* fullCmdW =
nullptr;
205 STARTUPINFOW sStartupInfo;
206 std::memset(&sStartupInfo, 0,
sizeof(sStartupInfo));
207 sStartupInfo.cb =
sizeof(sStartupInfo);
208 sStartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
209 sStartupInfo.wShowWindow = SW_HIDE;
211 PROCESS_INFORMATION sProcessInfo;
212 std::memset(&sProcessInfo, 0,
sizeof(sProcessInfo));
216 reinterpret_cast<wchar_t*
>(fullCmdW),
230 else if (sProcessInfo.hProcess)
232 WaitForSingleObject(sProcessInfo.hProcess,INFINITE);
235 bool retval = GetExitCodeProcess(sProcessInfo.hProcess,&exitCode);
236 CloseHandle(sProcessInfo.hProcess);
237 CloseHandle(sProcessInfo.hThread);
239 if (!retval)
return -1;
251#if !defined(_WIN32) || defined(__CYGWIN__)
252 pid =
static_cast<uint32_t
>(getpid());
254 pid =
static_cast<uint32_t
>(GetCurrentProcessId());
259#if !defined(_WIN32) || defined(__CYGWIN__)
267 while(current !=
nullptr)
269 std::string env_var(current);
270 size_t pos = env_var.find(
"=");
271 if(pos != std::string::npos)
273 std::string name = env_var.substr(0,pos);
274 std::string value = env_var.substr(pos + 1);
288#if defined(_WIN32) && !defined(__CYGWIN__)
289 SetEnvironmentVariable(name.
data(),!value.
isEmpty() ? value.
data() :
"");
303#if defined(_WIN32) && !defined(__CYGWIN__)
304 SetEnvironmentVariable(variable.
data(),
nullptr);
323#if defined(_WIN32) && !defined(__CYGWIN__)
324 #define ENV_BUFSIZE 32768
325 LPTSTR pszVal = (LPTSTR) malloc(ENV_BUFSIZE*
sizeof(TCHAR));
326 if (GetEnvironmentVariable(variable.
data(),pszVal,ENV_BUFSIZE) == 0)
return "";
351#if defined(_WIN32) && !defined(__CYGWIN__)
352 uint16_t *fn =
nullptr;
354 uint16_t *m =
nullptr;
356 FILE *result =
nullptr;
357 if (fn_len!=(
size_t)-1 && m_len!=(
size_t)-1)
359 result = _wfopen((
wchar_t*)fn,(
wchar_t*)m);
365 return ::fopen(fileName.
data(),mode.
data());
376#if defined(_WIN32) && !defined(__CYGWIN__)
385#if defined(_WIN32) && !defined(__CYGWIN__)
395 if (fi1.
exists())
return true;
402 while ((idx = paths.
find(listSep,strt)) != -1)
408 if (fi.
exists())
return true;
418 if (fi.
exists())
return true;
425#if defined(_WIN32) && !defined(__CYGWIN__)
426 const char *extensions[] = {
".bat",
".com",
".exe"};
427 for (
int i = 0; i <
sizeof(extensions) /
sizeof(*extensions); i++)
429 if (
ExistsOnPath(fileName + extensions[i]))
return true;
439#if defined(_WIN32) && !defined(__CYGWIN__)
440 static const char *gsexe =
nullptr;
443 const char *gsExec[] = {
"gswin32c.exe",
"gswin64c.exe"};
444 for (
int i = 0; i <
sizeof(gsExec) /
sizeof(*gsExec); i++)
463#if defined(_WIN32) && !defined(__CYGWIN__)
472#if defined(_WIN32) || defined(macintosh) || defined(__MACOSX__) || defined(__APPLE__) || defined(__CYGWIN__)
481 #if defined(_MSC_VER) || defined(__BORLANDC__)
482 return ::_popen(name.
data(),type.
data());
484 return ::popen(name.
data(),type.
data());
490 #if defined(_MSC_VER) || defined(__BORLANDC__)
491 return ::_pclose(stream);
493 return ::pclose(stream);
499 const char *fn = fileName.
data();
501 if (fileName.
length()>1 && isalpha(fileName[0]) && fileName[1]==
':') fn+=2;
503 char const fst = fn[0];
504 if (fst ==
'/')
return true;
506 if (fst ==
'\\')
return true;
521#if defined(_WIN32) && !defined(__CYGWIN__)
522 for (
const auto &path : extraPaths)
524 if (!first) result+=
';';
531 for (
const auto &path : extraPaths)
533 if (!first) result+=
':';
546#if defined(_WIN32) && !defined(__CYGWIN__)
547 _unlink(fileName.
data());
555#if defined(_WIN32) && !defined(__CYGWIN__)
557 TCHAR* buffer =
nullptr;
562 buffer =
new TCHAR[length];
573 const char *needle,
size_t needle_len)
575 const char *
const last_possible = haystack + haystack_len - needle_len;
584 if (haystack_len < needle_len)
591 if (
begin[0] == needle[0] && !memcmp(&
begin[1], needle + 1, needle_len - 1))
602 size_t needle_len = strnlen(needle, haystack_len);
603 if (needle_len < haystack_len || !needle[needle_len])
605 const char *x =
portable_memmem(haystack, haystack_len, needle, needle_len);
606 if (x && !memchr(haystack, 0, x - haystack))
616#if defined(_WIN32) && !defined(__CYGWIN__)
625 if (inputStr.
isEmpty() || outBuf==
nullptr)
return 0;
627 if (handle==
reinterpret_cast<void *
>(-1))
return 0;
628 size_t len = inputStr.
length();
629 uint16_t *buf =
new uint16_t[len+1];
631 size_t inRemains = len;
632 size_t outRemains = len*
sizeof(uint16_t)+2;
633 const char *p = inputStr.
data();
634 portable_iconv(handle,&p,&inRemains,
reinterpret_cast<char **
>(&buf),&outRemains);
644#include "filesystem.hpp"
646namespace fs = ghc::filesystem;
650 std::ios_base::openmode mode = std::ofstream::out | std::ofstream::binary;
651 if (append) mode |= std::ofstream::app;
652#if defined(__clang__) && defined(__MINGW32__)
653 return std::ofstream(fs::path(fileName.
str()).wstring(), mode);
655 return std::ofstream(fs::path(fileName.
str()), mode);
661 std::ios_base::openmode mode = std::ifstream::in | std::ifstream::binary;
662 if (binary) mode |= std::ios::binary;
663 if (openAtEnd) mode |= std::ios::ate;
664#if defined(__clang__) && defined(__MINGW32__)
665 return std::ifstream(fs::path(fileName.
str()).wstring(), mode);
667 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.