mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
Modifications following review from Lu. Win32 modifications are now more localized
This commit is contained in:
parent
45f9cd116b
commit
a47d42ad4b
@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
# define STAT stat
|
||||||
|
#else
|
||||||
|
# define STAT _stat
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
|
|
||||||
|
|
||||||
@ -55,20 +61,13 @@ void TmpFiles::clean()
|
|||||||
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
|
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the total size of the temporary files in bytes
|
||||||
double TmpFiles::get_total_size() const
|
double TmpFiles::get_total_size() const
|
||||||
{
|
{
|
||||||
double total_size = 0;
|
double total_size = 0;
|
||||||
#ifndef _WIN32
|
struct STAT st;
|
||||||
struct stat st;
|
|
||||||
#else
|
|
||||||
struct _stat st;
|
|
||||||
#endif
|
|
||||||
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) {
|
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) {
|
||||||
#ifndef _WIN32
|
STAT(iter->c_str(), &st);
|
||||||
stat(iter->c_str(), &st);
|
|
||||||
#else
|
|
||||||
_stat(iter->c_str(), &st);
|
|
||||||
#endif
|
|
||||||
total_size += st.st_size;
|
total_size += st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ ArgParser argparser;
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# include <iomanip>
|
# include <iomanip>
|
||||||
# include <libgen.h>
|
# include <libgen.h>
|
||||||
|
# include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void deprecated_font_suffix(const char * dummy = nullptr)
|
void deprecated_font_suffix(const char * dummy = nullptr)
|
||||||
@ -70,11 +71,7 @@ void show_version_and_exit(const char * dummy = nullptr)
|
|||||||
#if ENABLE_SVG
|
#if ENABLE_SVG
|
||||||
cerr << " cairo " << cairo_version_string() << endl;
|
cerr << " cairo " << cairo_version_string() << endl;
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
|
||||||
cerr << "Default data-dir: " << param.data_dir << endl;
|
cerr << "Default data-dir: " << param.data_dir << endl;
|
||||||
#else
|
|
||||||
cerr << "Default data-dir: " << PDF2HTMLEX_DATA_PATH << endl;
|
|
||||||
#endif
|
|
||||||
cerr << "Supported image format:";
|
cerr << "Supported image format:";
|
||||||
#ifdef ENABLE_LIBPNG
|
#ifdef ENABLE_LIBPNG
|
||||||
cerr << " png";
|
cerr << " png";
|
||||||
@ -143,7 +140,10 @@ void prepare_directories()
|
|||||||
|
|
||||||
tmp_dir.erase(tmp_dir.size() - 6);
|
tmp_dir.erase(tmp_dir.size() - 6);
|
||||||
param.tmp_dir = tmp_dir + ss.str();
|
param.tmp_dir = tmp_dir + ss.str();
|
||||||
::CreateDirectory(param.tmp_dir.c_str(), NULL);
|
if (mkdir(param.tmp_dir.c_str())) {
|
||||||
|
cerr << "Cannot create temp directory (" << param.tmp_dir << "): " << strerror(errno) << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ void parse_options (int argc, char **argv)
|
|||||||
.add("embed-image", ¶m.embed_image, 1, "embed image files into output")
|
.add("embed-image", ¶m.embed_image, 1, "embed image files into output")
|
||||||
.add("embed-javascript", ¶m.embed_javascript, 1, "embed JavaScript files into output")
|
.add("embed-javascript", ¶m.embed_javascript, 1, "embed JavaScript files into output")
|
||||||
.add("embed-outline", ¶m.embed_outline, 1, "embed outlines into output")
|
.add("embed-outline", ¶m.embed_outline, 1, "embed outlines into output")
|
||||||
.add("max-output-size", ¶m.max_size, -1, "maximum output size, in KB (-1 for no max)")
|
.add("output-size-limit", ¶m.max_size, -1, "Limit the output size, in KB (-1 for no limit). This is only an estimate, the output may be bigger")
|
||||||
.add("split-pages", ¶m.split_pages, 0, "split pages into separate files")
|
.add("split-pages", ¶m.split_pages, 0, "split pages into separate files")
|
||||||
.add("dest-dir", ¶m.dest_dir, ".", "specify destination directory")
|
.add("dest-dir", ¶m.dest_dir, ".", "specify destination directory")
|
||||||
.add("css-filename", ¶m.css_filename, "", "filename of the generated css file")
|
.add("css-filename", ¶m.css_filename, "", "filename of the generated css file")
|
||||||
@ -211,11 +211,7 @@ void parse_options (int argc, char **argv)
|
|||||||
// misc.
|
// misc.
|
||||||
.add("clean-tmp", ¶m.clean_tmp, 1, "remove temporary files after conversion")
|
.add("clean-tmp", ¶m.clean_tmp, 1, "remove temporary files after conversion")
|
||||||
.add("base-tmp-dir", ¶m.basetmp_dir, param.basetmp_dir, "base temporary directory - will create pdf2htmlEX-XXXXXX under it")
|
.add("base-tmp-dir", ¶m.basetmp_dir, param.basetmp_dir, "base temporary directory - will create pdf2htmlEX-XXXXXX under it")
|
||||||
#ifdef _WIN32
|
|
||||||
.add("data-dir", ¶m.data_dir, param.data_dir, "specify data directory")
|
.add("data-dir", ¶m.data_dir, param.data_dir, "specify data directory")
|
||||||
#else
|
|
||||||
.add("data-dir", ¶m.data_dir, PDF2HTMLEX_DATA_PATH, "specify data directory")
|
|
||||||
#endif
|
|
||||||
// TODO: css drawings are hidden on print, for annot links, need to fix it for other drawings
|
// TODO: css drawings are hidden on print, for annot links, need to fix it for other drawings
|
||||||
// .add("css-draw", ¶m.css_draw, 0, "[experimental and unsupported] CSS drawing")
|
// .add("css-draw", ¶m.css_draw, 0, "[experimental and unsupported] CSS drawing")
|
||||||
.add("debug", ¶m.debug, 0, "print debugging information")
|
.add("debug", ¶m.debug, 0, "print debugging information")
|
||||||
@ -366,6 +362,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
param.basetmp_dir = "/tmp";
|
param.basetmp_dir = "/tmp";
|
||||||
|
param.data_dir = PDF2HTMLEX_DATA_PATH;
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
// 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
|
||||||
|
@ -19,11 +19,6 @@
|
|||||||
|
|
||||||
#include "ffw.h"
|
#include "ffw.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#undef printf
|
|
||||||
#undef vfprintf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static real EPS=1e-6;
|
static real EPS=1e-6;
|
||||||
|
|
||||||
static inline int min(int a, int b)
|
static inline int min(int a, int b)
|
||||||
@ -64,7 +59,7 @@ void ffw_init(int debug)
|
|||||||
if ( default_encoding==NULL )
|
if ( default_encoding==NULL )
|
||||||
default_encoding=FindOrMakeEncoding("ISO8859-1");
|
default_encoding=FindOrMakeEncoding("ISO8859-1");
|
||||||
if ( default_encoding==NULL )
|
if ( default_encoding==NULL )
|
||||||
default_encoding=&custom; /* In case iconv is broken */
|
default_encoding=&custom; /* In case iconv is broken */
|
||||||
|
|
||||||
if(!debug)
|
if(!debug)
|
||||||
{
|
{
|
||||||
|
@ -12,19 +12,17 @@
|
|||||||
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
using std::string;
|
#ifdef _WIN32
|
||||||
|
# include <direct.h>
|
||||||
#if defined(_WIN32)
|
# define STAT _stat
|
||||||
#include <windows.h>
|
# define MKDIR(A, B) mkdir(A)
|
||||||
int mkdir(const char *pathname, mode_t mode) {
|
#else
|
||||||
if (::GetFileAttributes(pathname) == FILE_ATTRIBUTE_DIRECTORY) {
|
# define STAT stat
|
||||||
errno = EEXIST;
|
# define MKDIR(A, B) mkdir(A, B)
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return ::CreateDirectory(pathname, NULL) ? 0 : -1;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
|
|
||||||
void create_directories(const string & path)
|
void create_directories(const string & path)
|
||||||
@ -37,20 +35,14 @@ void create_directories(const string & path)
|
|||||||
create_directories(path.substr(0, idx));
|
create_directories(path.substr(0, idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = mkdir(path.c_str(), S_IRWXU);
|
int r = MKDIR(path.c_str(), S_IRWXU);
|
||||||
if(r != 0)
|
if(r != 0)
|
||||||
{
|
{
|
||||||
if(errno == EEXIST)
|
if(errno == EEXIST)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
struct STAT stat_buf;
|
||||||
struct _stat32 stat_buf;
|
if((STAT(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||||
if((_stat32(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
|
||||||
return;
|
return;
|
||||||
#else
|
|
||||||
struct stat stat_buf;
|
|
||||||
if((stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw string("Cannot create directory: ") + path;
|
throw string("Cannot create directory: ") + path;
|
||||||
|
Loading…
Reference in New Issue
Block a user