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

Modifications following review from Lu. Win32 modifications are now more localized

This commit is contained in:
Marc Sanfacon 2013-12-05 15:20:53 -05:00
parent 45f9cd116b
commit a47d42ad4b
4 changed files with 50 additions and 67 deletions

View File

@ -16,6 +16,12 @@
using namespace std;
#ifndef _WIN32
# define STAT stat
#else
# define STAT _stat
#endif
namespace pdf2htmlEX {
@ -55,20 +61,13 @@ void TmpFiles::clean()
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 total_size = 0;
#ifndef _WIN32
struct stat st;
#else
struct _stat st;
#endif
struct STAT st;
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) {
#ifndef _WIN32
stat(iter->c_str(), &st);
#else
_stat(iter->c_str(), &st);
#endif
STAT(iter->c_str(), &st);
total_size += st.st_size;
}

View File

@ -45,6 +45,7 @@ ArgParser argparser;
#ifdef _WIN32
# include <iomanip>
# include <libgen.h>
# include <direct.h>
#endif
void deprecated_font_suffix(const char * dummy = nullptr)
@ -70,11 +71,7 @@ void show_version_and_exit(const char * dummy = nullptr)
#if ENABLE_SVG
cerr << " cairo " << cairo_version_string() << endl;
#endif
#ifdef _WIN32
cerr << "Default data-dir: " << param.data_dir << endl;
#else
cerr << "Default data-dir: " << PDF2HTMLEX_DATA_PATH << endl;
#endif
cerr << "Supported image format:";
#ifdef ENABLE_LIBPNG
cerr << " png";
@ -143,7 +140,10 @@ void prepare_directories()
tmp_dir.erase(tmp_dir.size() - 6);
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
}
@ -169,7 +169,7 @@ void parse_options (int argc, char **argv)
.add("embed-image", &param.embed_image, 1, "embed image files into output")
.add("embed-javascript", &param.embed_javascript, 1, "embed JavaScript files into output")
.add("embed-outline", &param.embed_outline, 1, "embed outlines into output")
.add("max-output-size", &param.max_size, -1, "maximum output size, in KB (-1 for no max)")
.add("output-size-limit", &param.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", &param.split_pages, 0, "split pages into separate files")
.add("dest-dir", &param.dest_dir, ".", "specify destination directory")
.add("css-filename", &param.css_filename, "", "filename of the generated css file")
@ -211,11 +211,7 @@ void parse_options (int argc, char **argv)
// misc.
.add("clean-tmp", &param.clean_tmp, 1, "remove temporary files after conversion")
.add("base-tmp-dir", &param.basetmp_dir, param.basetmp_dir, "base temporary directory - will create pdf2htmlEX-XXXXXX under it")
#ifdef _WIN32
.add("data-dir", &param.data_dir, param.data_dir, "specify data directory")
#else
.add("data-dir", &param.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
// .add("css-draw", &param.css_draw, 0, "[experimental and unsupported] CSS drawing")
.add("debug", &param.debug, 0, "print debugging information")
@ -366,6 +362,7 @@ int main(int argc, char **argv)
{
#ifndef _WIN32
param.basetmp_dir = "/tmp";
param.data_dir = PDF2HTMLEX_DATA_PATH;
#else
{
// Under Windows, the default data_dir is under /data in the pdf2htmlEX directory

View File

@ -19,11 +19,6 @@
#include "ffw.h"
#if defined(_WIN32)
#undef printf
#undef vfprintf
#endif
static real EPS=1e-6;
static inline int min(int a, int b)
@ -64,7 +59,7 @@ void ffw_init(int debug)
if ( default_encoding==NULL )
default_encoding=FindOrMakeEncoding("ISO8859-1");
if ( default_encoding==NULL )
default_encoding=&custom; /* In case iconv is broken */
default_encoding=&custom; /* In case iconv is broken */
if(!debug)
{

View File

@ -12,19 +12,17 @@
#include "path.h"
using std::string;
#if defined(_WIN32)
#include <windows.h>
int mkdir(const char *pathname, mode_t mode) {
if (::GetFileAttributes(pathname) == FILE_ATTRIBUTE_DIRECTORY) {
errno = EEXIST;
return -1;
}
return ::CreateDirectory(pathname, NULL) ? 0 : -1;
}
#ifdef _WIN32
# include <direct.h>
# define STAT _stat
# define MKDIR(A, B) mkdir(A)
#else
# define STAT stat
# define MKDIR(A, B) mkdir(A, B)
#endif
using std::string;
namespace pdf2htmlEX {
void create_directories(const string & path)
@ -37,20 +35,14 @@ void create_directories(const string & path)
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(errno == EEXIST)
{
#if defined(_WIN32)
struct _stat32 stat_buf;
if((_stat32(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
struct STAT stat_buf;
if((STAT(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
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;