diff --git a/CMakeLists.txt b/CMakeLists.txt index 9011200..0286e98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,8 @@ set(PDF2HTMLEX_SRC ${PDF2HTMLEX_SRC} src/util/path.cc src/util/unicode.h src/util/unicode.cc + src/util/mingw.h + src/util/mingw.cc src/ArgParser.h src/ArgParser.cc src/Base64Stream.h diff --git a/src/TmpFiles.cc b/src/TmpFiles.cc index 2ff4956..cecd90d 100644 --- a/src/TmpFiles.cc +++ b/src/TmpFiles.cc @@ -15,6 +15,10 @@ #include "TmpFiles.h" #include "Param.h" +#ifdef __MINGW32__ +#include "util/mingw.h" +#endif + using namespace std; namespace pdf2htmlEX { diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 3963716..9c7282c 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -36,6 +36,10 @@ #include "util/path.h" #include "util/ffw.h" +#ifdef __MINGW32__ +#include "util/mingw.h" +#endif + using namespace std; using namespace pdf2htmlEX; @@ -335,8 +339,13 @@ void check_param() int main(int argc, char **argv) { // We need to adjust these directories before parsing the options. +#if defined(__MINGW32__) + param.data_dir = get_exec_dir(argv[0]); + param.tmp_dir = get_tmp_dir(); +#else param.tmp_dir = "/tmp"; param.data_dir = PDF2HTMLEX_DATA_PATH; +#endif parse_options(argc, argv); check_param(); diff --git a/src/util/mingw.cc b/src/util/mingw.cc new file mode 100644 index 0000000..5d75be0 --- /dev/null +++ b/src/util/mingw.cc @@ -0,0 +1,64 @@ +/* + * Win32 specific functions + * + * by MarcSanfacon + * 2014.01.13 + */ + +#ifdef __MINGW32__ + +#include +#include +#include +#include +#include +#include + +#include "mingw.h" + +using namespace std; + +char* mkdtemp(char* temp) +{ + char *filename = nullptr; + if (temp != nullptr) { + filename = mktemp(temp); + if (filename != nullptr) { + if (_mkdir(temp) != 0) { + filename = nullptr; + } + } + } + + return filename; +} + +namespace pdf2htmlEX { +string get_exec_dir(char *dir) +{ + // Under Windows, the default data_dir is under /data in the pdf2htmlEX directory + string s = dirname(dir); + if (s == ".") { + char* wd(getcwd(nullptr, PATH_MAX)); + s = wd; + free(wd); + } + s += "/data"; + return s; +} + +string get_tmp_dir() +{ + // Under Windows, the temp path is not under /tmp, find it. + char *tmp = getenv("TMP"); + if (tmp == nullptr) { + tmp = getenv("TEMP"); + } + + return tmp != nullptr ? string(tmp) + "/" : "/"; +} + +} // namespace pdf2htmlEX; + +#endif //__MINGW32__ + diff --git a/src/util/mingw.h b/src/util/mingw.h new file mode 100644 index 0000000..f7a3b52 --- /dev/null +++ b/src/util/mingw.h @@ -0,0 +1,28 @@ +/* + * Win32 specific functions + * + * by MarcSanfacon + * 2014.01.13 + */ + +#ifndef MINGW_H__ +#define MINGW_H__ + +#ifdef __MINGW32__ + +#include + +char *mkdtemp(char *temp); + +#define mkdir(A, B) _mkdir(A) +#define stat _stat + +namespace pdf2htmlEX { + std::string get_exec_dir(char *dir); + std::string get_tmp_dir(); +} // namespace pdf2htmlEX + +#endif //__MINGW32__ + +#endif //MINGW_H__ + diff --git a/src/util/path.cc b/src/util/path.cc index e0b1b94..4d451f6 100644 --- a/src/util/path.cc +++ b/src/util/path.cc @@ -12,6 +12,10 @@ #include "path.h" +#ifdef __MINGW32__ +#include "util/mingw.h" +#endif + using std::string; namespace pdf2htmlEX {