Commit a1c0aaf03adf0344b34dd591f9103479f249e965
1 parent
7acc0498
windows fixes
git-svn-id: svn+q:///qpdf/trunk@684 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
7 changed files
with
46 additions
and
8 deletions
include/qpdf/QUtil.hh
| ... | ... | @@ -32,6 +32,9 @@ namespace QUtil |
| 32 | 32 | |
| 33 | 33 | char* copy_string(std::string const&); |
| 34 | 34 | |
| 35 | + // Set stdout to binary mode | |
| 36 | + void binary_stdout(); | |
| 37 | + | |
| 35 | 38 | // Get the value of an environment variable in a portable fashion. |
| 36 | 39 | // Returns true iff the variable is defined. If `value' is |
| 37 | 40 | // non-null, initializes it with the value of the variable. | ... | ... |
libqpdf/QPDFWriter.cc
libqpdf/QUtil.cc
| ... | ... | @@ -5,9 +5,11 @@ |
| 5 | 5 | #include <ctype.h> |
| 6 | 6 | #include <stdlib.h> |
| 7 | 7 | #include <string.h> |
| 8 | +#include <fcntl.h> | |
| 8 | 9 | #ifdef _WIN32 |
| 9 | 10 | #include <Windows.h> |
| 10 | 11 | #include <direct.h> |
| 12 | +#include <io.h> | |
| 11 | 13 | #else |
| 12 | 14 | #include <unistd.h> |
| 13 | 15 | #endif |
| ... | ... | @@ -104,6 +106,14 @@ QUtil::copy_string(std::string const& str) |
| 104 | 106 | return result; |
| 105 | 107 | } |
| 106 | 108 | |
| 109 | +void | |
| 110 | +QUtil::binary_stdout() | |
| 111 | +{ | |
| 112 | +#ifdef _WIN32 | |
| 113 | + _setmode(_fileno(stdout), _O_BINARY); | |
| 114 | +#endif | |
| 115 | +} | |
| 116 | + | |
| 107 | 117 | bool |
| 108 | 118 | QUtil::get_env(std::string const& var, std::string* value) |
| 109 | 119 | { | ... | ... |
qpdf/qpdf.cc
| ... | ... | @@ -2,6 +2,11 @@ |
| 2 | 2 | #include <iostream> |
| 3 | 3 | #include <string.h> |
| 4 | 4 | #include <stdlib.h> |
| 5 | +#include <fcntl.h> | |
| 6 | + | |
| 7 | +#ifdef _WIN32 | |
| 8 | +# include <io.h> | |
| 9 | +#endif | |
| 5 | 10 | |
| 6 | 11 | #include <qpdf/QUtil.hh> |
| 7 | 12 | #include <qpdf/QTC.hh> |
| ... | ... | @@ -15,7 +20,7 @@ |
| 15 | 20 | static int const EXIT_ERROR = 2; |
| 16 | 21 | static int const EXIT_WARNING = 3; |
| 17 | 22 | |
| 18 | -static char const* whoami = 0; | |
| 23 | +static char* whoami = 0; | |
| 19 | 24 | |
| 20 | 25 | // Note: let's not be too noisy about documenting the fact that this |
| 21 | 26 | // software purposely fails to enforce the distinction between user |
| ... | ... | @@ -429,7 +434,12 @@ parse_encrypt_options( |
| 429 | 434 | |
| 430 | 435 | int main(int argc, char* argv[]) |
| 431 | 436 | { |
| 432 | - if ((whoami = strrchr(argv[0], '/')) == NULL) | |
| 437 | +#ifdef _WIN32 | |
| 438 | + char pathsep = '\\'; | |
| 439 | +#else | |
| 440 | + char pathsep = '/'; | |
| 441 | +#endif | |
| 442 | + if ((whoami = strrchr(argv[0], pathsep)) == NULL) | |
| 433 | 443 | { |
| 434 | 444 | whoami = argv[0]; |
| 435 | 445 | } |
| ... | ... | @@ -437,6 +447,13 @@ int main(int argc, char* argv[]) |
| 437 | 447 | { |
| 438 | 448 | ++whoami; |
| 439 | 449 | } |
| 450 | +#ifdef _WIN32 | |
| 451 | + if ((strlen(whoami) > 4) && | |
| 452 | + (strcmp(whoami + strlen(whoami) - 4, ".exe") == 0)) | |
| 453 | + { | |
| 454 | + whoami[strlen(whoami) - 4] = '\0'; | |
| 455 | + } | |
| 456 | +#endif | |
| 440 | 457 | // For libtool's sake.... |
| 441 | 458 | if (strncmp(whoami, "lt-", 3) == 0) |
| 442 | 459 | { |
| ... | ... | @@ -790,6 +807,7 @@ int main(int argc, char* argv[]) |
| 790 | 807 | } |
| 791 | 808 | else |
| 792 | 809 | { |
| 810 | + QUtil::binary_stdout(); | |
| 793 | 811 | Pl_StdioFile out("stdout", stdout); |
| 794 | 812 | obj.pipeStreamData(&out, filter, normalize, false); |
| 795 | 813 | } | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -267,7 +267,8 @@ for (my $i = 1; $i <= scalar(@goodfiles); ++$i) |
| 267 | 267 | $td->runtest("$goodfiles[$i-1]", |
| 268 | 268 | {$td->COMMAND => "test_driver $n good$i.pdf"}, |
| 269 | 269 | {$td->FILE => "good$i.out", |
| 270 | - $td->EXIT_STATUS => 0}); | |
| 270 | + $td->EXIT_STATUS => 0}, | |
| 271 | + $td->NORMALIZE_NEWLINES); | |
| 271 | 272 | my $xflags = $goodtest_flags{$i} || ''; |
| 272 | 273 | check_pdf("create qdf", |
| 273 | 274 | "qpdf --static-id -qdf $xflags good$i.pdf", |
| ... | ... | @@ -461,7 +462,8 @@ $td->runtest("unfilterable stream data", |
| 461 | 462 | {$td->COMMAND => "qpdf encrypted-with-images.pdf" . |
| 462 | 463 | " --show-object=8 --filtered-stream-data"}, |
| 463 | 464 | {$td->FILE => "show-unfilterable.out", |
| 464 | - $td->EXIT_STATUS => 2}); | |
| 465 | + $td->EXIT_STATUS => 2}, | |
| 466 | + $td->NORMALIZE_NEWLINES); | |
| 465 | 467 | |
| 466 | 468 | $td->runtest("show-xref-by-id", |
| 467 | 469 | {$td->COMMAND => "qpdf encrypted-with-images.pdf" . |
| ... | ... | @@ -837,7 +839,8 @@ foreach my $file (@files) |
| 837 | 839 | $td->runtest("check status", |
| 838 | 840 | {$td->COMMAND => "qpdf --check a.pdf"}, |
| 839 | 841 | {$td->FILE => "$base.$n.check", |
| 840 | - $td->EXIT_STATUS => 0}); | |
| 842 | + $td->EXIT_STATUS => 0}, | |
| 843 | + $td->NORMALIZE_NEWLINES); | |
| 841 | 844 | |
| 842 | 845 | compare_pdfs($file, "a.pdf"); |
| 843 | 846 | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -126,6 +126,7 @@ void runtest(int n, char const* filename) |
| 126 | 126 | |
| 127 | 127 | std::cout << "Raw stream data:" << std::endl; |
| 128 | 128 | std::cout.flush(); |
| 129 | + QUtil::binary_stdout(); | |
| 129 | 130 | PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("raw", stdout); |
| 130 | 131 | qtest.pipeStreamData(out.getPointer(), false, false, false); |
| 131 | 132 | |
| ... | ... | @@ -133,6 +134,7 @@ void runtest(int n, char const* filename) |
| 133 | 134 | if (qtest.pipeStreamData(0, true, false, false)) |
| 134 | 135 | { |
| 135 | 136 | std::cout.flush(); |
| 137 | + QUtil::binary_stdout(); | |
| 136 | 138 | out = new Pl_StdioFile("filtered", stdout); |
| 137 | 139 | qtest.pipeStreamData(out.getPointer(), true, false, false); |
| 138 | 140 | std::cout << std::endl << "End of stream data" << std::endl; |
| ... | ... | @@ -172,6 +174,7 @@ void runtest(int n, char const* filename) |
| 172 | 174 | QPDFObjectHandle kids = pages.getKey("/Kids"); |
| 173 | 175 | QPDFObjectHandle page = kids.getArrayItem(1); // second page |
| 174 | 176 | QPDFObjectHandle contents = page.getKey("/Contents"); |
| 177 | + QUtil::binary_stdout(); | |
| 175 | 178 | PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("filtered", stdout); |
| 176 | 179 | contents.pipeStreamData(out.getPointer(), true, false, false); |
| 177 | 180 | } |
| ... | ... | @@ -183,6 +186,7 @@ void runtest(int n, char const* filename) |
| 183 | 186 | QPDFObjectHandle stream = streams.getArrayItem(i); |
| 184 | 187 | std::cout << "-- stream " << i << " --" << std::endl; |
| 185 | 188 | std::cout.flush(); |
| 189 | + QUtil::binary_stdout(); | |
| 186 | 190 | PointerHolder<Pl_StdioFile> out = |
| 187 | 191 | new Pl_StdioFile("tokenized stream", stdout); |
| 188 | 192 | stream.pipeStreamData(out.getPointer(), true, true, false); | ... | ... |
zlib-flate/zlib-flate.cc
| 1 | 1 | #include <qpdf/Pl_Flate.hh> |
| 2 | 2 | #include <qpdf/Pl_StdioFile.hh> |
| 3 | +#include <qpdf/QUtil.hh> | |
| 3 | 4 | |
| 4 | 5 | #include <stdio.h> |
| 5 | 6 | #include <string.h> |
| ... | ... | @@ -63,9 +64,7 @@ int main(int argc, char* argv[]) |
| 63 | 64 | usage(); |
| 64 | 65 | } |
| 65 | 66 | |
| 66 | -#ifdef _WIN32 | |
| 67 | - _setmode(_fileno(stdout), _O_BINARY); | |
| 68 | -#endif | |
| 67 | + QUtil::binary_stdout(); | |
| 69 | 68 | Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout); |
| 70 | 69 | Pl_Flate* flate = new Pl_Flate("flate", out, action); |
| 71 | 70 | ... | ... |