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