From 5aebf2c73896798cd701d006a978a6d471a49f68 Mon Sep 17 00:00:00 2001 From: Marc Sanfacon Date: Mon, 13 Jan 2014 20:08:23 -0500 Subject: [PATCH] Make it work on MingW --- CMakeLists.txt | 2 ++ src/TmpFiles.cc | 1 + src/pdf2htmlEX.cc | 6 +++++ src/util/path.cc | 1 + src/util/win32.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++ src/util/win32.h | 30 +++++++++++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 src/util/win32.cc create mode 100644 src/util/win32.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9011200..8d4b67c 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/win32.h + src/util/win32.cc src/ArgParser.h src/ArgParser.cc src/Base64Stream.h diff --git a/src/TmpFiles.cc b/src/TmpFiles.cc index 2ff4956..1cc9e22 100644 --- a/src/TmpFiles.cc +++ b/src/TmpFiles.cc @@ -14,6 +14,7 @@ #include "TmpFiles.h" #include "Param.h" +#include "util/win32.h" using namespace std; diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 33562dd..d683edb 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -35,6 +35,7 @@ #include "util/path.h" #include "util/ffw.h" +#include "util/win32.h" using namespace std; using namespace pdf2htmlEX; @@ -342,8 +343,13 @@ void check_param() int main(int argc, char **argv) { // We need to adjust these directories before parsing the options. +#ifndef _WIN32 param.tmp_dir = "/tmp"; param.data_dir = PDF2HTMLEX_DATA_PATH; +#else + param.data_dir = get_data_dir(argv[0]); + param.tmp_dir = get_tmp_dir(); +#endif parse_options(argc, argv); check_param(); diff --git a/src/util/path.cc b/src/util/path.cc index e0b1b94..15e5200 100644 --- a/src/util/path.cc +++ b/src/util/path.cc @@ -11,6 +11,7 @@ #include #include "path.h" +#include "win32.h" using std::string; diff --git a/src/util/win32.cc b/src/util/win32.cc new file mode 100644 index 0000000..dbd4633 --- /dev/null +++ b/src/util/win32.cc @@ -0,0 +1,57 @@ +/* + * Win32 specific functions + * + * by MarcSanfacon + * 2014.01.13 + */ + +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include + +#include "win32.h" + +char* mkdtemp(char* temp) +{ + if (temp != nullptr) { + bool created = false; + char value[30]; + + srand((unsigned)time(0)); + while (!created) { + int rand_value = (int)((rand() / ((double)RAND_MAX+1.0)) * 1e6); + sprintf(value, "%06d", rand_value); + sprintf(temp + strlen(temp) - 6, "%6.6s", value); + created = _mkdir(temp) == 0; + } + } + + return temp; +} + +namespace pdf2htmlEX { +std::string get_data_dir(char *dir) +{ + // Under Windows, the default data_dir is under /data in the pdf2htmlEX directory + std::stringstream ss; + ss << dirname(dir) << "/data"; + return ss.str(); +} + +std::string get_tmp_dir() +{ + // Under Windows, the temp path is not under /tmp, find it. + char temppath[MAX_PATH]; + ::GetTempPath(MAX_PATH, temppath); + return temppath; +} + +} // namespace pdf2htmlEX; + +#endif //_WIN32 + diff --git a/src/util/win32.h b/src/util/win32.h new file mode 100644 index 0000000..2e1f10e --- /dev/null +++ b/src/util/win32.h @@ -0,0 +1,30 @@ +/* + * Win32 specific functions + * + * by MarcSanfacon + * 2014.01.13 + */ + +#ifndef WIN32_H__ +#define WIN32_H__ + +#ifdef _WIN32 + +#include +#include +#include + +char *mkdtemp(char *temp); + +#define mkdir(A, B) _mkdir(A) +#define stat _stat + +namespace pdf2htmlEX { + std::string get_data_dir(char *dir); + std::string get_tmp_dir(); +} // namespace pdf2htmlEX + +#endif //_WIN32 + +#endif //WIN32_H__ +