1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

Merge pull request #285 from marcsanfacon/master

Make it work on MingW
This commit is contained in:
Lu Wang 2014-01-16 00:27:14 -08:00
commit 949d11ae1c
6 changed files with 111 additions and 0 deletions

View File

@ -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

View File

@ -15,6 +15,10 @@
#include "TmpFiles.h"
#include "Param.h"
#ifdef __MINGW32__
#include "util/mingw.h"
#endif
using namespace std;
namespace pdf2htmlEX {

View File

@ -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();

64
src/util/mingw.cc Normal file
View File

@ -0,0 +1,64 @@
/*
* Win32 specific functions
*
* by MarcSanfacon
* 2014.01.13
*/
#ifdef __MINGW32__
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <limits.h>
#include <libgen.h>
#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__

28
src/util/mingw.h Normal file
View File

@ -0,0 +1,28 @@
/*
* Win32 specific functions
*
* by MarcSanfacon
* 2014.01.13
*/
#ifndef MINGW_H__
#define MINGW_H__
#ifdef __MINGW32__
#include <io.h>
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__

View File

@ -12,6 +12,10 @@
#include "path.h"
#ifdef __MINGW32__
#include "util/mingw.h"
#endif
using std::string;
namespace pdf2htmlEX {