From fe18385ffaa7e5b11db86af1e992c0fb1984609a Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 15 Jul 2009 04:26:32 +0000 Subject: clean up windows portability code, make remaining test suite pass git-svn-id: svn+q:///qpdf/trunk@686 71b93d88-0707-0410-a8cf-f5a4172ac649 --- examples/pdf-bookmarks.cc | 10 ++-------- examples/pdf-mod-info.cc | 25 +++++++++++++++---------- examples/pdf-npages.cc | 11 +++-------- examples/qtest/mod-info.test | 18 ++++++++++++------ 4 files changed, 32 insertions(+), 32 deletions(-) (limited to 'examples') diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc index 4f878211..802cdbac 100644 --- a/examples/pdf-bookmarks.cc +++ b/examples/pdf-bookmarks.cc @@ -163,14 +163,8 @@ void extract_bookmarks(QPDFObjectHandle outlines, std::vector& numbers) int main(int argc, char* argv[]) { - if ((whoami = strrchr(argv[0], '/')) == NULL) - { - whoami = argv[0]; - } - else - { - ++whoami; - } + whoami = QUtil::getWhoami(argv[0]); + // For libtool's sake.... if (strncmp(whoami, "lt-", 3) == 0) { diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc index 7401a571..4e851316 100644 --- a/examples/pdf-mod-info.cc +++ b/examples/pdf-mod-info.cc @@ -77,14 +77,8 @@ int main(int argc, char* argv[]) bool static_id = false; std::map Keys; - if ((whoami = strrchr(argv[0], '/')) == NULL) - { - whoami = argv[0]; - } - else - { - ++whoami; - } + whoami = QUtil::getWhoami(argv[0]); + // For libtool's sake.... if (strncmp(whoami, "lt-", 3) == 0) { @@ -161,6 +155,9 @@ int main(int argc, char* argv[]) usage(); } + std::string fl_tmp = fl_out; + fl_tmp += ".tmp"; + try { QPDF file; @@ -198,13 +195,21 @@ int main(int argc, char* argv[]) fileinfo.replaceKey(it->first, elt); } } - std::string fl_tmp = fl_out; - fl_tmp += ".tmp"; QPDFWriter w(file, fl_tmp.c_str()); w.setStreamDataMode(QPDFWriter::s_preserve); w.setLinearization(true); w.setStaticID(static_id); w.write(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + exit(2); + } + + try + { + (void) unlink(fl_out); QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out)); } diff --git a/examples/pdf-npages.cc b/examples/pdf-npages.cc index b5ef6479..c62d33de 100644 --- a/examples/pdf-npages.cc +++ b/examples/pdf-npages.cc @@ -3,6 +3,7 @@ #include #include +#include static char const* whoami = 0; @@ -15,14 +16,8 @@ void usage() int main(int argc, char* argv[]) { - if ((whoami = strrchr(argv[0], '/')) == NULL) - { - whoami = argv[0]; - } - else - { - ++whoami; - } + whoami = QUtil::getWhoami(argv[0]); + // For libtool's sake.... if (strncmp(whoami, "lt-", 3) == 0) { diff --git a/examples/qtest/mod-info.test b/examples/qtest/mod-info.test index 29a72475..90db6276 100644 --- a/examples/qtest/mod-info.test +++ b/examples/qtest/mod-info.test @@ -18,32 +18,38 @@ cleanup(); $td->runtest("usage #1", {$td->COMMAND => "$prg -in target.pdf"}, {$td->FILE => "usage.out", - $td->EXIT_STATUS => 2}); + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); $td->runtest("usage #2", {$td->COMMAND => "$prg -key abc -val def"}, {$td->FILE => "usage.out", - $td->EXIT_STATUS => 2}); + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); $td->runtest("usage #3", {$td->COMMAND => "$prg -key abc -val def abc"}, {$td->FILE => "usage.out", - $td->EXIT_STATUS => 2}); + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); $td->runtest("usage #4", {$td->COMMAND => "$prg -in source1.pdf -key /date -val 01/01/01 -val 12/12/12"}, {$td->FILE => "usage.out", - $td->EXIT_STATUS => 2}); + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); $td->runtest("dump #1", {$td->COMMAND => "$prg --dump -in files/source1.pdf"}, {$td->FILE => "dump.out", - $td->EXIT_STATUS => 0}); + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); $td->runtest("dump #2", {$td->COMMAND => "$prg --dump -in files/no-info.pdf"}, {$td->STRING => "", - $td->EXIT_STATUS => 0}); + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); $td->runtest("dump #3", {$td->COMMAND => "$prg --dump -in files/empty-info.pdf"}, -- cgit v1.2.3-54-g00ecf