浏览该文件的文档.
8 #if defined(_WIN32) && !defined(__CYGWIN__)
14 #include <sys/types.h>
33 #if !defined(_WIN32) || defined(__CYGWIN__)
35 static std::map<std::string,std::string>
proc_env = std::map<std::string,std::string>();
45 if (command.
isEmpty())
return 1;
47 #if defined(_WIN32) && !defined(__CYGWIN__)
49 QCString fullCmd=commandCorrectedPath;
54 if (fullCmd.
at(0)!=
'"' && fullCmd.
find(
' ')!=-1)
57 fullCmd=
"\""+fullCmd+
"\"";
65 #if !defined(_WIN32) || defined(__CYGWIN__)
66 (void)commandHasConsole;
70 #ifdef _OS_SOLARIS // for Solaris we use vfork since it is more memory efficient
82 execl(
"/bin/sh",
"sh",
"-c",fullCmd.
data(),(
char*)0);
87 while (waitpid(
pid,&status,0 )<0)
98 #else // Other Unices just use fork
103 perror(
"fork error");
108 const char * argv[4];
111 argv[2] = fullCmd.
data();
113 execve(
"/bin/sh",(
char *
const *)argv,
environ);
118 if (waitpid(
pid,&status,0)==-1)
120 if (errno!=EINTR)
return -1;
124 if (WIFEXITED(status))
126 return WEXITSTATUS(status);
134 #endif // !_OS_SOLARIS
136 #else // Win32 specific
137 if (commandHasConsole)
149 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
151 uint16_t *commandw = NULL;
153 uint16_t *argsw = NULL;
160 SHELLEXECUTEINFOW sInfo = {
161 sizeof(SHELLEXECUTEINFOW),
162 SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI,
181 if (!ShellExecuteExW(&sInfo))
187 else if (sInfo.hProcess)
189 WaitForSingleObject(sInfo.hProcess,INFINITE);
192 if (!GetExitCodeProcess(sInfo.hProcess,&exitCode))
196 CloseHandle(sInfo.hProcess);
210 #if !defined(_WIN32) || defined(__CYGWIN__)
211 pid = (
unsigned int)getpid();
213 pid = (
unsigned int)GetCurrentProcessId();
218 #if !defined(_WIN32) || defined(__CYGWIN__)
226 while(current != NULL)
228 std::string env_var(current);
229 size_t pos = env_var.find(
"=");
230 if(pos != std::string::npos)
232 std::string name = env_var.substr(0,pos);
233 std::string value = env_var.substr(pos + 1);
248 #if defined(_WIN32) && !defined(__CYGWIN__)
249 SetEnvironmentVariable(name.
data(),!value.
isEmpty() ? value.
data() :
"");
262 #if defined(_WIN32) && !defined(__CYGWIN__)
263 SetEnvironmentVariable(variable.
data(),0);
281 #if defined(_WIN32) && !defined(__CYGWIN__)
302 #if defined(__MINGW32__)
303 return fseeko64(f,offset,whence);
304 #elif defined(_WIN32) && !defined(__CYGWIN__)
305 return _fseeki64(f,offset,whence);
307 return fseeko(f,offset,whence);
313 #if defined(__MINGW32__)
315 #elif defined(_WIN32) && !defined(__CYGWIN__)
324 #if defined(_WIN32) && !defined(__CYGWIN__)
330 if (fn_len!=(
size_t)-1 && m_len!=(
size_t)-1)
332 result = _wfopen((
wchar_t*)fn,(
wchar_t*)m);
349 #if defined(_WIN32) && !defined(__CYGWIN__)
358 #if defined(_WIN32) && !defined(__CYGWIN__)
368 if (fi1.
exists())
return true;
375 while ((idx = paths.
find(listSep,strt)) != -1)
381 if (fi.
exists())
return true;
391 if (fi.
exists())
return true;
398 #if defined(_WIN32) && !defined(__CYGWIN__)
399 char *extensions[] = {
".bat",
".com",
".exe"};
400 for (
int i = 0; i <
sizeof(extensions) /
sizeof(*extensions); i++)
402 if (
ExistsOnPath(fileName + extensions[i]))
return true;
412 #if defined(_WIN32) && !defined(__CYGWIN__)
413 static char *gsexe = NULL;
416 char *gsExec[] = {
"gswin32c.exe",
"gswin64c.exe"};
417 for (
int i = 0; i <
sizeof(gsExec) /
sizeof(*gsExec); i++)
436 #if defined(_WIN32) && !defined(__CYGWIN__)
445 #if defined(_WIN32) || defined(macintosh) || defined(__MACOSX__) || defined(__APPLE__) || defined(__CYGWIN__)
454 #if defined(_MSC_VER) || defined(__BORLANDC__)
455 return ::_popen(name.
data(),type.
data());
463 #if defined(_MSC_VER) || defined(__BORLANDC__)
464 return ::_pclose(stream);
477 std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now();
479 std::chrono::microseconds>(endTime -
g_startTime).count()/1000000.0;
489 #if defined(_WIN32) && !defined(__CYGWIN__)
498 const char *fn = fileName.
data();
500 if (fileName.
length()>1 &&
isalpha(fileName[0]) && fileName[1]==
':') fn+=2;
502 char const fst = fn[0];
503 if (fst ==
'/')
return true;
505 if (fst ==
'\\')
return true;
517 #if defined(_WIN32) && !defined(__CYGWIN__)
527 #if defined(_WIN32) && !defined(__CYGWIN__)
528 _unlink(fileName.
data());
536 #if defined(_WIN32) && !defined(__CYGWIN__)
538 TCHAR* buffer = NULL;
543 buffer =
new TCHAR[length];
554 const char *needle,
size_t needle_len)
556 const char *
const last_possible = haystack + haystack_len - needle_len;
565 if (haystack_len < needle_len)
572 if (
begin[0] == needle[0] && !memcmp(&
begin[1], needle + 1, needle_len - 1))
583 size_t needle_len = strnlen(needle, haystack_len);
584 if (needle_len < haystack_len || !needle[needle_len])
586 const char *x =
portable_memmem(haystack, haystack_len, needle, needle_len);
587 if (x && !memchr(haystack, 0, x - haystack))
597 #if defined(_WIN32) && !defined(__CYGWIN__)
606 if (inputStr.
isEmpty() || outBuf==0)
return 0;
608 if (handle==(
void *)(-1))
return 0;
609 size_t len = inputStr.
length();
610 uint16_t *buf =
new uint16_t[len+1];
612 size_t inRemains = len;
613 size_t outRemains = len*
sizeof(uint16_t)+2;
614 const char *p = inputStr.
data();
static bool isalpha(char c)
static std::string currentDirPath()
size_t portable_iconv(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
FILE * popen(const QCString &name, const QCString &type)
bool fileSystemIsCaseSensitive()
FILE * fopen(const QCString &fileName, const QCString &mode)
uint length() const
Returns the length of the string, not counting the 0-terminator.
bool isEmpty() const
Returns TRUE iff the string is empty
static bool environmentLoaded
static bool ExistsOnPath(const QCString &fileName)
char & at(size_t i)
Returns a reference to the character at index i.
void * portable_iconv_open(const char *tocode, const char *fromcode)
int find(char c, int index=0, bool cs=TRUE) const
size_t recodeUtf8StringToW(const QCString &inputStr, uint16_t **buf)
DirIterator begin(DirIterator it) noexcept
QCString getenv(const QCString &variable)
void unsetenv(const QCString &variable)
const char * strnstr(const char *haystack, const char *needle, size_t haystack_len)
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
const char * ghostScriptCommand()
static void print(DebugMask mask, int prio, const char *fmt,...)
void correct_path()
Correct a possible wrong PATH variable
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
static bool setCurrent(const std::string &path)
double getSysElapsedTime()
static double g_sysElapsedTime
static const char * portable_memmem(const char *haystack, size_t haystack_len, const char *needle, size_t needle_len)
static std::chrono::steady_clock::time_point g_startTime
QCString pathListSeparator()
portable_off_t fseek(FILE *f, portable_off_t offset, int whence)
bool checkForExecutable(const QCString &fileName)
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
static std::map< std::string, std::string > proc_env
Minimal replacement for QFileInfo.
const char * qPrint(const char *s)
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string
void setenv(const QCString &variable, const QCString &value)
bool isAbsolutePath(const QCString &fileName)
const char * commandExtension()
Portable versions of functions that are platform dependent.
int portable_iconv_close(void *cd)
void unlink(const QCString &fileName)
A bunch of utility functions.
portable_off_t ftell(FILE *f)
This is an alternative implementation of QCString.