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 | 37 | // non-null, initializes it with the value of the variable. |
| 38 | 38 | bool get_env(std::string const& var, std::string* value = 0); |
| 39 | 39 | |
| 40 | + time_t get_current_time(); | |
| 41 | + | |
| 40 | 42 | // Return a string containing the byte representation of the UTF-8 |
| 41 | 43 | // encoding for the unicode value passed in. |
| 42 | 44 | std::string toUTF8(unsigned long uval); | ... | ... |
libqpdf/QPDF.cc
| ... | ... | @@ -241,7 +241,7 @@ QPDF::ObjGen::ObjGen(int o = 0, int g = 0) : |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | bool |
| 244 | -QPDF::ObjGen::ObjGen::operator<(ObjGen const& rhs) const | |
| 244 | +QPDF::ObjGen::operator<(ObjGen const& rhs) const | |
| 245 | 245 | { |
| 246 | 246 | return ((this->obj < rhs.obj) || |
| 247 | 247 | ((this->obj == rhs.obj) && (this->gen < rhs.gen))); | ... | ... |
libqpdf/QPDFWriter.cc
| ... | ... | @@ -1110,7 +1110,7 @@ QPDFWriter::generateID() |
| 1110 | 1110 | // the file yet. This scheme should be fine though. |
| 1111 | 1111 | |
| 1112 | 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 | 1114 | seed += " QPDF "; |
| 1115 | 1115 | seed += filename; |
| 1116 | 1116 | seed += " "; | ... | ... |
libqpdf/QPDF_encryption.cc
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -624,7 +624,7 @@ QPDF::maxEnd(ObjUser const& ou) |
| 624 | 624 | assert(this->obj_user_to_objects.count(ou) > 0); |
| 625 | 625 | std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou]; |
| 626 | 626 | int end = 0; |
| 627 | - for (std::set<ObjGen>::iterator iter = ogs.begin(); | |
| 627 | + for (std::set<ObjGen>::const_iterator iter = ogs.begin(); | |
| 628 | 628 | iter != ogs.end(); ++iter) |
| 629 | 629 | { |
| 630 | 630 | ObjGen const& og = *iter; | ... | ... |
libqpdf/QUtil.cc
| ... | ... | @@ -141,6 +141,32 @@ QUtil::get_env(std::string const& var, std::string* value) |
| 141 | 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 | 170 | std::string |
| 145 | 171 | QUtil::toUTF8(unsigned long uval) |
| 146 | 172 | { | ... | ... |
libqpdf/qpdf/PCRE.hh
libtests/ascii85.cc
libtests/hex.cc
libtests/lzw.cc
| 1 | 1 | #include <qpdf/Pl_LZWDecoder.hh> |
| 2 | 2 | |
| 3 | 3 | #include <qpdf/Pl_StdioFile.hh> |
| 4 | +#include <qpdf/QUtil.hh> | |
| 4 | 5 | #include <iostream> |
| 5 | 6 | #include <stdlib.h> |
| 6 | 7 | #include <string.h> |
| ... | ... | @@ -8,21 +9,36 @@ |
| 8 | 9 | int main(int argc, char* argv[]) |
| 9 | 10 | { |
| 10 | 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 | 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 | 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 | 37 | unsigned char buf[10000]; |
| 22 | 38 | bool done = false; |
| 23 | 39 | while (! done) |
| 24 | 40 | { |
| 25 | - int len = read(0, buf, sizeof(buf)); | |
| 41 | + int len = fread(buf, 1, sizeof(buf), infile); | |
| 26 | 42 | if (len <= 0) |
| 27 | 43 | { |
| 28 | 44 | done = true; | ... | ... |
libtests/qtest/ascii85.test
| ... | ... | @@ -17,6 +17,7 @@ $td->runtest("decode", |
| 17 | 17 | $td->runtest("partial decode", |
| 18 | 18 | {$td->COMMAND => "echo '\@<5skEHbu7\$3~>' | ascii85"}, |
| 19 | 19 | {$td->STRING => "asdfqwer\n", |
| 20 | - $td->EXIT_STATUS => 0}); | |
| 20 | + $td->EXIT_STATUS => 0}, | |
| 21 | + $td->NORMALIZE_NEWLINES); | |
| 21 | 22 | |
| 22 | 23 | $td->report(2); | ... | ... |
libtests/qtest/bits.test
libtests/qtest/buffer.test
libtests/qtest/lzw.test
| ... | ... | @@ -12,7 +12,7 @@ my $td = new TestDriver('lzw'); |
| 12 | 12 | cleanup(); |
| 13 | 13 | |
| 14 | 14 | $td->runtest("decode: early code change", |
| 15 | - {$td->COMMAND => "lzw < lzw1.in > tmp"}, | |
| 15 | + {$td->COMMAND => "lzw lzw1.in tmp"}, | |
| 16 | 16 | {$td->STRING => "", |
| 17 | 17 | $td->EXIT_STATUS => 0}); |
| 18 | 18 | |
| ... | ... | @@ -21,7 +21,7 @@ $td->runtest("check output", |
| 21 | 21 | {$td->FILE => "lzw1.out"}); |
| 22 | 22 | |
| 23 | 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 | 25 | {$td->STRING => "", |
| 26 | 26 | $td->EXIT_STATUS => 0}); |
| 27 | 27 | ... | ... |
libtests/qtest/md5.test
libtests/qtest/pcre.test
| ... | ... | @@ -16,7 +16,7 @@ $td->runtest("PCRE", |
| 16 | 16 | $td->NORMALIZE_NEWLINES); |
| 17 | 17 | |
| 18 | 18 | chop(my $supported = `pcre --unicode-classes-supported`); |
| 19 | -if ($supported) | |
| 19 | +if ($supported =~ m/^1/) | |
| 20 | 20 | { |
| 21 | 21 | $td->runtest("unicode character classes", |
| 22 | 22 | {$td->COMMAND => "pcre --unicode-classes"}, | ... | ... |
libtests/qtest/ph.test
libtests/qtest/qutil.test
qpdf/qpdf.cc