mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
Modifications following code review
This commit is contained in:
parent
5aebf2c738
commit
94ddd697a6
@ -343,11 +343,11 @@ void check_param()
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// We need to adjust these directories before parsing the options.
|
// We need to adjust these directories before parsing the options.
|
||||||
#ifndef _WIN32
|
#ifndef __MINGW32__
|
||||||
param.tmp_dir = "/tmp";
|
param.tmp_dir = "/tmp";
|
||||||
param.data_dir = PDF2HTMLEX_DATA_PATH;
|
param.data_dir = PDF2HTMLEX_DATA_PATH;
|
||||||
#else
|
#else
|
||||||
param.data_dir = get_data_dir(argv[0]);
|
param.data_dir = get_exec_dir(argv[0]);
|
||||||
param.tmp_dir = get_tmp_dir();
|
param.tmp_dir = get_tmp_dir();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -5,53 +5,65 @@
|
|||||||
* 2014.01.13
|
* 2014.01.13
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <time.h>
|
#include <limits.h>
|
||||||
#include <sstream>
|
#include <libgen.h>
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
char* mkdtemp(char* temp)
|
char* mkdtemp(char* temp)
|
||||||
{
|
{
|
||||||
|
char *filename = nullptr;
|
||||||
if (temp != nullptr) {
|
if (temp != nullptr) {
|
||||||
bool created = false;
|
filename = mktemp(temp);
|
||||||
char value[30];
|
if (filename != nullptr) {
|
||||||
|
if (_mkdir(temp) != 0) {
|
||||||
srand((unsigned)time(0));
|
filename = nullptr;
|
||||||
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;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
std::string get_data_dir(char *dir)
|
string get_exec_dir(char *dir)
|
||||||
{
|
{
|
||||||
// Under Windows, the default data_dir is under /data in the pdf2htmlEX directory
|
// Under Windows, the default data_dir is under /data in the pdf2htmlEX directory
|
||||||
std::stringstream ss;
|
string s = dirname(dir);
|
||||||
ss << dirname(dir) << "/data";
|
if (s == ".") {
|
||||||
return ss.str();
|
char* wd(getcwd(nullptr, PATH_MAX));
|
||||||
|
s = wd;
|
||||||
|
free(wd);
|
||||||
|
}
|
||||||
|
s += "/data";
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_tmp_dir()
|
string get_tmp_dir()
|
||||||
{
|
{
|
||||||
// Under Windows, the temp path is not under /tmp, find it.
|
// Under Windows, the temp path is not under /tmp, find it.
|
||||||
char temppath[MAX_PATH];
|
char *tmp = getenv("TMP");
|
||||||
::GetTempPath(MAX_PATH, temppath);
|
if (tmp == nullptr) {
|
||||||
return temppath;
|
tmp = getenv("TEMP");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp == nullptr) {
|
||||||
|
cerr << "Error: Cannot find temporary directory. Export TMP/TEMP variable.";
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(tmp) + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pdf2htmlEX;
|
} // namespace pdf2htmlEX;
|
||||||
|
|
||||||
#endif //_WIN32
|
#endif //__MINGW32__
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@
|
|||||||
#ifndef WIN32_H__
|
#ifndef WIN32_H__
|
||||||
#define WIN32_H__
|
#define WIN32_H__
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef __MINGW32__
|
||||||
|
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <libgen.h>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
char *mkdtemp(char *temp);
|
char *mkdtemp(char *temp);
|
||||||
|
|
||||||
@ -20,11 +18,11 @@ char *mkdtemp(char *temp);
|
|||||||
#define stat _stat
|
#define stat _stat
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
std::string get_data_dir(char *dir);
|
std::string get_exec_dir(char *dir);
|
||||||
std::string get_tmp_dir();
|
std::string get_tmp_dir();
|
||||||
} // namespace pdf2htmlEX
|
} // namespace pdf2htmlEX
|
||||||
|
|
||||||
#endif //_WIN32
|
#endif //__MINGW32__
|
||||||
|
|
||||||
#endif //WIN32_H__
|
#endif //WIN32_H__
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user