Commit a9987ab57042ce755261492d93cb54d9ff10fc35
1 parent
0b87334a
Fix a few compiler errors reported correctly my MSVC 9.0.
Fix libtests test suites to pass on Windows, mostly by dealing with ascii vs. binary and NL vs. CRNL change ($td->NORMALIZE_NEWLINES). Convert some test suites to use fread instead of read. PCRE.hh: define PCRE_STATIC if on Windows. Provide cross-platform function for getting current time instead of using time(0). git-svn-id: svn+q:///qpdf/trunk@678 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
19 changed files
with
73 additions
and
20 deletions
include/qpdf/QUtil.hh
| @@ -37,6 +37,8 @@ namespace QUtil | @@ -37,6 +37,8 @@ namespace QUtil | ||
| 37 | // non-null, initializes it with the value of the variable. | 37 | // non-null, initializes it with the value of the variable. |
| 38 | bool get_env(std::string const& var, std::string* value = 0); | 38 | bool get_env(std::string const& var, std::string* value = 0); |
| 39 | 39 | ||
| 40 | + time_t get_current_time(); | ||
| 41 | + | ||
| 40 | // Return a string containing the byte representation of the UTF-8 | 42 | // Return a string containing the byte representation of the UTF-8 |
| 41 | // encoding for the unicode value passed in. | 43 | // encoding for the unicode value passed in. |
| 42 | std::string toUTF8(unsigned long uval); | 44 | std::string toUTF8(unsigned long uval); |
libqpdf/QPDF.cc
| @@ -241,7 +241,7 @@ QPDF::ObjGen::ObjGen(int o = 0, int g = 0) : | @@ -241,7 +241,7 @@ QPDF::ObjGen::ObjGen(int o = 0, int g = 0) : | ||
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | bool | 243 | bool |
| 244 | -QPDF::ObjGen::ObjGen::operator<(ObjGen const& rhs) const | 244 | +QPDF::ObjGen::operator<(ObjGen const& rhs) const |
| 245 | { | 245 | { |
| 246 | return ((this->obj < rhs.obj) || | 246 | return ((this->obj < rhs.obj) || |
| 247 | ((this->obj == rhs.obj) && (this->gen < rhs.gen))); | 247 | ((this->obj == rhs.obj) && (this->gen < rhs.gen))); |
libqpdf/QPDFWriter.cc
| @@ -1110,7 +1110,7 @@ QPDFWriter::generateID() | @@ -1110,7 +1110,7 @@ QPDFWriter::generateID() | ||
| 1110 | // the file yet. This scheme should be fine though. | 1110 | // the file yet. This scheme should be fine though. |
| 1111 | 1111 | ||
| 1112 | std::string seed; | 1112 | std::string seed; |
| 1113 | - seed += QUtil::int_to_string((int)time(0)); | 1113 | + seed += QUtil::int_to_string((int)QUtil::get_current_time()); |
| 1114 | seed += " QPDF "; | 1114 | seed += " QPDF "; |
| 1115 | seed += filename; | 1115 | seed += filename; |
| 1116 | seed += " "; | 1116 | seed += " "; |
libqpdf/QPDF_encryption.cc
| @@ -45,7 +45,7 @@ QPDF::trim_user_password(std::string& user_password) | @@ -45,7 +45,7 @@ QPDF::trim_user_password(std::string& user_password) | ||
| 45 | return; | 45 | return; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - char* p = 0; | 48 | + char const* p = 0; |
| 49 | while ((p = strchr(cstr, '\x28')) != 0) | 49 | while ((p = strchr(cstr, '\x28')) != 0) |
| 50 | { | 50 | { |
| 51 | if (memcmp(p, padding_string, len - (p - cstr)) == 0) | 51 | if (memcmp(p, padding_string, len - (p - cstr)) == 0) |
libqpdf/QPDF_linearization.cc
| @@ -624,7 +624,7 @@ QPDF::maxEnd(ObjUser const& ou) | @@ -624,7 +624,7 @@ QPDF::maxEnd(ObjUser const& ou) | ||
| 624 | assert(this->obj_user_to_objects.count(ou) > 0); | 624 | assert(this->obj_user_to_objects.count(ou) > 0); |
| 625 | std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou]; | 625 | std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou]; |
| 626 | int end = 0; | 626 | int end = 0; |
| 627 | - for (std::set<ObjGen>::iterator iter = ogs.begin(); | 627 | + for (std::set<ObjGen>::const_iterator iter = ogs.begin(); |
| 628 | iter != ogs.end(); ++iter) | 628 | iter != ogs.end(); ++iter) |
| 629 | { | 629 | { |
| 630 | ObjGen const& og = *iter; | 630 | ObjGen const& og = *iter; |
libqpdf/QUtil.cc
| @@ -141,6 +141,32 @@ QUtil::get_env(std::string const& var, std::string* value) | @@ -141,6 +141,32 @@ QUtil::get_env(std::string const& var, std::string* value) | ||
| 141 | #endif | 141 | #endif |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | +time_t | ||
| 145 | +QUtil::get_current_time() | ||
| 146 | +{ | ||
| 147 | +#ifdef _WIN32 | ||
| 148 | + // The procedure to get local time at this resolution comes from | ||
| 149 | + // the Microsoft documentation. It says to convert a SYSTEMTIME | ||
| 150 | + // to a FILETIME, and to copy the FILETIME to a ULARGE_INTEGER. | ||
| 151 | + // The resulting number is the number of 100-nanosecond intervals | ||
| 152 | + // between January 1, 1601 and now. POSIX threads wants a time | ||
| 153 | + // based on January 1, 1970, so we adjust by subtracting the | ||
| 154 | + // number of seconds in that time period from the result we get | ||
| 155 | + // here. | ||
| 156 | + SYSTEMTIME sysnow; | ||
| 157 | + GetSystemTime(&sysnow); | ||
| 158 | + FILETIME filenow; | ||
| 159 | + SystemTimeToFileTime(&sysnow, &filenow); | ||
| 160 | + ULARGE_INTEGER uinow; | ||
| 161 | + uinow.LowPart = filenow.dwLowDateTime; | ||
| 162 | + uinow.HighPart = filenow.dwHighDateTime; | ||
| 163 | + ULONGLONG now = uinow.QuadPart; | ||
| 164 | + return ((now / 10000000LL) - 11644473600LL); | ||
| 165 | +#else | ||
| 166 | + return time(0); | ||
| 167 | +#endif | ||
| 168 | +} | ||
| 169 | + | ||
| 144 | std::string | 170 | std::string |
| 145 | QUtil::toUTF8(unsigned long uval) | 171 | QUtil::toUTF8(unsigned long uval) |
| 146 | { | 172 | { |
libqpdf/qpdf/PCRE.hh
libtests/ascii85.cc
| @@ -15,7 +15,7 @@ int main() | @@ -15,7 +15,7 @@ int main() | ||
| 15 | bool done = false; | 15 | bool done = false; |
| 16 | while (! done) | 16 | while (! done) |
| 17 | { | 17 | { |
| 18 | - int len = read(0, buf, sizeof(buf)); | 18 | + int len = fread(buf, 1, sizeof(buf), stdin); |
| 19 | if (len <= 0) | 19 | if (len <= 0) |
| 20 | { | 20 | { |
| 21 | done = true; | 21 | done = true; |
libtests/hex.cc
| @@ -15,7 +15,7 @@ int main() | @@ -15,7 +15,7 @@ int main() | ||
| 15 | bool done = false; | 15 | bool done = false; |
| 16 | while (! done) | 16 | while (! done) |
| 17 | { | 17 | { |
| 18 | - int len = read(0, buf, sizeof(buf)); | 18 | + int len = fread(buf, 1, sizeof(buf), stdin); |
| 19 | if (len <= 0) | 19 | if (len <= 0) |
| 20 | { | 20 | { |
| 21 | done = true; | 21 | done = true; |
libtests/lzw.cc
| 1 | #include <qpdf/Pl_LZWDecoder.hh> | 1 | #include <qpdf/Pl_LZWDecoder.hh> |
| 2 | 2 | ||
| 3 | #include <qpdf/Pl_StdioFile.hh> | 3 | #include <qpdf/Pl_StdioFile.hh> |
| 4 | +#include <qpdf/QUtil.hh> | ||
| 4 | #include <iostream> | 5 | #include <iostream> |
| 5 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 6 | #include <string.h> | 7 | #include <string.h> |
| @@ -8,21 +9,36 @@ | @@ -8,21 +9,36 @@ | ||
| 8 | int main(int argc, char* argv[]) | 9 | int main(int argc, char* argv[]) |
| 9 | { | 10 | { |
| 10 | bool early_code_change = true; | 11 | bool early_code_change = true; |
| 11 | - if ((argc == 2) && (strcmp(argv[1], "--no-early-code-change") == 0)) | 12 | + if ((argc == 4) && (strcmp(argv[3], "--no-early-code-change") == 0)) |
| 12 | { | 13 | { |
| 13 | early_code_change = false; | 14 | early_code_change = false; |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | - Pl_StdioFile out("stdout", stdout); | ||
| 17 | - Pl_LZWDecoder decode("decode", &out, early_code_change); | 17 | + if (argc < 3) |
| 18 | + { | ||
| 19 | + std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]" | ||
| 20 | + << std::endl; | ||
| 21 | + exit(2); | ||
| 22 | + } | ||
| 18 | 23 | ||
| 19 | try | 24 | try |
| 20 | { | 25 | { |
| 26 | + char* infilename = argv[1]; | ||
| 27 | + char* outfilename = argv[2]; | ||
| 28 | + | ||
| 29 | + FILE* infile = QUtil::fopen_wrapper("open input file", | ||
| 30 | + fopen(infilename, "rb")); | ||
| 31 | + FILE* outfile = QUtil::fopen_wrapper("open output file", | ||
| 32 | + fopen(outfilename, "wb")); | ||
| 33 | + | ||
| 34 | + Pl_StdioFile out("output", outfile); | ||
| 35 | + Pl_LZWDecoder decode("decode", &out, early_code_change); | ||
| 36 | + | ||
| 21 | unsigned char buf[10000]; | 37 | unsigned char buf[10000]; |
| 22 | bool done = false; | 38 | bool done = false; |
| 23 | while (! done) | 39 | while (! done) |
| 24 | { | 40 | { |
| 25 | - int len = read(0, buf, sizeof(buf)); | 41 | + int len = fread(buf, 1, sizeof(buf), infile); |
| 26 | if (len <= 0) | 42 | if (len <= 0) |
| 27 | { | 43 | { |
| 28 | done = true; | 44 | done = true; |
libtests/qtest/ascii85.test
| @@ -17,6 +17,7 @@ $td->runtest("decode", | @@ -17,6 +17,7 @@ $td->runtest("decode", | ||
| 17 | $td->runtest("partial decode", | 17 | $td->runtest("partial decode", |
| 18 | {$td->COMMAND => "echo '\@<5skEHbu7\$3~>' | ascii85"}, | 18 | {$td->COMMAND => "echo '\@<5skEHbu7\$3~>' | ascii85"}, |
| 19 | {$td->STRING => "asdfqwer\n", | 19 | {$td->STRING => "asdfqwer\n", |
| 20 | - $td->EXIT_STATUS => 0}); | 20 | + $td->EXIT_STATUS => 0}, |
| 21 | + $td->NORMALIZE_NEWLINES); | ||
| 21 | 22 | ||
| 22 | $td->report(2); | 23 | $td->report(2); |
libtests/qtest/bits.test
| @@ -12,6 +12,7 @@ my $td = new TestDriver('bits'); | @@ -12,6 +12,7 @@ my $td = new TestDriver('bits'); | ||
| 12 | $td->runtest("bits", | 12 | $td->runtest("bits", |
| 13 | {$td->COMMAND => "bits"}, | 13 | {$td->COMMAND => "bits"}, |
| 14 | {$td->FILE => "bits.out", | 14 | {$td->FILE => "bits.out", |
| 15 | - $td->EXIT_STATUS => 0}); | 15 | + $td->EXIT_STATUS => 0}, |
| 16 | + $td->NORMALIZE_NEWLINES); | ||
| 16 | 17 | ||
| 17 | $td->report(1); | 18 | $td->report(1); |
libtests/qtest/buffer.test
| @@ -12,6 +12,7 @@ my $td = new TestDriver('buffer'); | @@ -12,6 +12,7 @@ my $td = new TestDriver('buffer'); | ||
| 12 | $td->runtest("buffer", | 12 | $td->runtest("buffer", |
| 13 | {$td->COMMAND => "buffer"}, | 13 | {$td->COMMAND => "buffer"}, |
| 14 | {$td->FILE => "buffer.out", | 14 | {$td->FILE => "buffer.out", |
| 15 | - $td->EXIT_STATUS => 0}); | 15 | + $td->EXIT_STATUS => 0}, |
| 16 | + $td->NORMALIZE_NEWLINES); | ||
| 16 | 17 | ||
| 17 | $td->report(1); | 18 | $td->report(1); |
libtests/qtest/lzw.test
| @@ -12,7 +12,7 @@ my $td = new TestDriver('lzw'); | @@ -12,7 +12,7 @@ my $td = new TestDriver('lzw'); | ||
| 12 | cleanup(); | 12 | cleanup(); |
| 13 | 13 | ||
| 14 | $td->runtest("decode: early code change", | 14 | $td->runtest("decode: early code change", |
| 15 | - {$td->COMMAND => "lzw < lzw1.in > tmp"}, | 15 | + {$td->COMMAND => "lzw lzw1.in tmp"}, |
| 16 | {$td->STRING => "", | 16 | {$td->STRING => "", |
| 17 | $td->EXIT_STATUS => 0}); | 17 | $td->EXIT_STATUS => 0}); |
| 18 | 18 | ||
| @@ -21,7 +21,7 @@ $td->runtest("check output", | @@ -21,7 +21,7 @@ $td->runtest("check output", | ||
| 21 | {$td->FILE => "lzw1.out"}); | 21 | {$td->FILE => "lzw1.out"}); |
| 22 | 22 | ||
| 23 | $td->runtest("decode: no early code change", | 23 | $td->runtest("decode: no early code change", |
| 24 | - {$td->COMMAND => "lzw --no-early-code-change < lzw2.in > tmp"}, | 24 | + {$td->COMMAND => "lzw lzw2.in tmp --no-early-code-change"}, |
| 25 | {$td->STRING => "", | 25 | {$td->STRING => "", |
| 26 | $td->EXIT_STATUS => 0}); | 26 | $td->EXIT_STATUS => 0}); |
| 27 | 27 |
libtests/qtest/md5.test
| @@ -12,6 +12,7 @@ my $td = new TestDriver('md5'); | @@ -12,6 +12,7 @@ my $td = new TestDriver('md5'); | ||
| 12 | $td->runtest("md5", | 12 | $td->runtest("md5", |
| 13 | {$td->COMMAND => "md5"}, | 13 | {$td->COMMAND => "md5"}, |
| 14 | {$td->FILE => "md5.out", | 14 | {$td->FILE => "md5.out", |
| 15 | - $td->EXIT_STATUS => 0}); | 15 | + $td->EXIT_STATUS => 0}, |
| 16 | + $td->NORMALIZE_NEWLINES); | ||
| 16 | 17 | ||
| 17 | $td->report(1); | 18 | $td->report(1); |
libtests/qtest/pcre.test
| @@ -16,7 +16,7 @@ $td->runtest("PCRE", | @@ -16,7 +16,7 @@ $td->runtest("PCRE", | ||
| 16 | $td->NORMALIZE_NEWLINES); | 16 | $td->NORMALIZE_NEWLINES); |
| 17 | 17 | ||
| 18 | chop(my $supported = `pcre --unicode-classes-supported`); | 18 | chop(my $supported = `pcre --unicode-classes-supported`); |
| 19 | -if ($supported) | 19 | +if ($supported =~ m/^1/) |
| 20 | { | 20 | { |
| 21 | $td->runtest("unicode character classes", | 21 | $td->runtest("unicode character classes", |
| 22 | {$td->COMMAND => "pcre --unicode-classes"}, | 22 | {$td->COMMAND => "pcre --unicode-classes"}, |
libtests/qtest/ph.test
| @@ -12,6 +12,7 @@ my $td = new TestDriver('ph'); | @@ -12,6 +12,7 @@ my $td = new TestDriver('ph'); | ||
| 12 | $td->runtest("PointerHolder", | 12 | $td->runtest("PointerHolder", |
| 13 | {$td->COMMAND => "pointer_holder"}, | 13 | {$td->COMMAND => "pointer_holder"}, |
| 14 | {$td->FILE => "ph.out", | 14 | {$td->FILE => "ph.out", |
| 15 | - $td->EXIT_STATUS => 0}); | 15 | + $td->EXIT_STATUS => 0}, |
| 16 | + $td->NORMALIZE_NEWLINES); | ||
| 16 | 17 | ||
| 17 | $td->report(1); | 18 | $td->report(1); |
libtests/qtest/qutil.test
| @@ -12,6 +12,7 @@ my $td = new TestDriver('qutil'); | @@ -12,6 +12,7 @@ my $td = new TestDriver('qutil'); | ||
| 12 | $td->runtest("QUtil", | 12 | $td->runtest("QUtil", |
| 13 | {$td->COMMAND => "qutil"}, | 13 | {$td->COMMAND => "qutil"}, |
| 14 | {$td->FILE => "qutil.out", | 14 | {$td->FILE => "qutil.out", |
| 15 | - $td->EXIT_STATUS => 0}); | 15 | + $td->EXIT_STATUS => 0}, |
| 16 | + $td->NORMALIZE_NEWLINES); | ||
| 16 | 17 | ||
| 17 | $td->report(1); | 18 | $td->report(1); |
qpdf/qpdf.cc
| @@ -532,7 +532,7 @@ int main(int argc, char* argv[]) | @@ -532,7 +532,7 @@ int main(int argc, char* argv[]) | ||
| 532 | // Be lax about -arg vs --arg | 532 | // Be lax about -arg vs --arg |
| 533 | ++arg; | 533 | ++arg; |
| 534 | } | 534 | } |
| 535 | - char* parameter = strchr(arg, '='); | 535 | + char* parameter = (char*)strchr(arg, '='); |
| 536 | if (parameter) | 536 | if (parameter) |
| 537 | { | 537 | { |
| 538 | *parameter++ = 0; | 538 | *parameter++ = 0; |