From 5fab160e05cdf5fd8acfc20388687449f4b8c78f Mon Sep 17 00:00:00 2001 From: Marc Sanfacon Date: Thu, 9 Jan 2014 08:14:12 -0500 Subject: [PATCH] Modifications following code review Fixed rmdir under Windows/MINGW --- CMakeLists.txt | 2 +- src/HTMLRenderer/general.cc | 2 +- src/Param.h | 7 ++----- src/TmpFiles.cc | 5 ++++- src/pdf2htmlEX.cc | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39663a5..9011200 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,7 +158,7 @@ endif() include(CheckCXXCompilerFlag) check_cxx_compiler_flag("${CMAKE_CXX_FLAGS}" CXX0X_SUPPORT) if(NOT CXX0X_SUPPORT) - message(FATAL_ERROR "Error: you compiler does not support C++0x, please update it.") + message(FATAL_ERROR "Error: your compiler does not support C++0x, please update it.") endif() diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 94cf02d..9c85a97 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -109,7 +109,7 @@ void HTMLRenderer::process(PDFDoc *doc) int page_count = (param.last_page - param.first_page + 1); for(int i = param.first_page; i <= param.last_page ; ++i) { - if (param.max_size != -1 && tmp_files.get_total_size() > param.max_size * 1024) { + if (param.tmp_file_size_limit != -1 && tmp_files.get_total_size() > param.tmp_file_size_limit * 1024) { cerr << "Stop processing, reach max size\n"; break; } diff --git a/src/Param.h b/src/Param.h index 4816f72..dc08c6a 100644 --- a/src/Param.h +++ b/src/Param.h @@ -31,7 +31,7 @@ struct Param int embed_javascript; int embed_outline; int split_pages; - int max_size; + int tmp_file_size_limit; std::string dest_dir; std::string css_filename; std::string page_filename; @@ -70,14 +70,11 @@ struct Param // misc. int clean_tmp; std::string data_dir; - std::string basetmp_dir; + std::string tmp_dir; int css_draw; int debug; std::string input_filename, output_filename; - - // not a paramater - std::string tmp_dir; }; } // namespace pdf2htmlEX diff --git a/src/TmpFiles.cc b/src/TmpFiles.cc index 903b206..ac143bd 100644 --- a/src/TmpFiles.cc +++ b/src/TmpFiles.cc @@ -18,8 +18,11 @@ using namespace std; #ifndef _WIN32 # define STAT stat +# define RMDIR rmdir #else +# include # define STAT _stat +# define RMDIR _rmdir #endif namespace pdf2htmlEX { @@ -56,7 +59,7 @@ void TmpFiles::clean() cerr << "Remove temporary file: " << fn << endl; } - remove(param.tmp_dir.c_str()); + RMDIR(param.tmp_dir.c_str()); if(param.debug) cerr << "Remove temporary directory: " << param.tmp_dir << endl; } diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 9d55e0c..3c316ac 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -114,11 +114,11 @@ void embed_parser (const char * str) void prepare_directories() { - std::string tmp_dir = param.basetmp_dir + "/pdf2htmlEX-XXXXXX"; + std::string tmp_dir = param.tmp_dir + "/pdf2htmlEX-XXXXXX"; #ifndef _WIN32 errno = 0; - auto_ptr pBuf(new char[tmp_dir.size() + 1]); + unique_ptr pBuf(new char[tmp_dir.size() + 1]); strcpy(pBuf.get(), tmp_dir.c_str()); auto p = mkdtemp(pBuf.get()); if(p == nullptr) @@ -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-javascript", ¶m.embed_javascript, 1, "embed JavaScript files into output") .add("embed-outline", ¶m.embed_outline, 1, "embed outlines into output") - .add("tmp-file-size-limit", ¶m.max_size, -1, "Limit the temporary file output size, in KB (-1 for no limit). This is only an estimate, the output may be bigger") + .add("tmp-file-size-limit", ¶m.tmp_file_size_limit, -1, "Limit the temporary file 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("dest-dir", ¶m.dest_dir, ".", "specify destination directory") .add("css-filename", ¶m.css_filename, "", "filename of the generated css file") @@ -210,7 +210,7 @@ void parse_options (int argc, char **argv) // misc. .add("clean-tmp", ¶m.clean_tmp, 1, "remove temporary files after conversion") - .add("tmp-dir", ¶m.basetmp_dir, param.basetmp_dir, "specify the location of tempory directory.") + .add("tmp-dir", ¶m.tmp_dir, param.tmp_dir, "specify the location of tempory directory.") .add("data-dir", ¶m.data_dir, param.data_dir, "specify data directory") // 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") @@ -362,7 +362,7 @@ int main(int argc, char **argv) { // We need to adjust these directories before parsing the options. #ifndef _WIN32 - param.basetmp_dir = "/tmp"; + param.tmp_dir = "/tmp"; param.data_dir = PDF2HTMLEX_DATA_PATH; #else { @@ -374,7 +374,7 @@ int main(int argc, char **argv) // Under Windows, the temp path is not under /tmp, find it. char temppath[MAX_PATH]; ::GetTempPath(MAX_PATH, temppath); - param.basetmp_dir = temppath; + param.tmp_dir = temppath; } #endif