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
This commit is contained in:
Jay Berkenbilt 2009-07-12 22:52:13 +00:00
parent 0b87334a61
commit a9987ab570
19 changed files with 73 additions and 20 deletions

View File

@ -37,6 +37,8 @@ namespace QUtil
// non-null, initializes it with the value of the variable.
bool get_env(std::string const& var, std::string* value = 0);
time_t get_current_time();
// Return a string containing the byte representation of the UTF-8
// encoding for the unicode value passed in.
std::string toUTF8(unsigned long uval);

View File

@ -241,7 +241,7 @@ QPDF::ObjGen::ObjGen(int o = 0, int g = 0) :
}
bool
QPDF::ObjGen::ObjGen::operator<(ObjGen const& rhs) const
QPDF::ObjGen::operator<(ObjGen const& rhs) const
{
return ((this->obj < rhs.obj) ||
((this->obj == rhs.obj) && (this->gen < rhs.gen)));

View File

@ -1110,7 +1110,7 @@ QPDFWriter::generateID()
// the file yet. This scheme should be fine though.
std::string seed;
seed += QUtil::int_to_string((int)time(0));
seed += QUtil::int_to_string((int)QUtil::get_current_time());
seed += " QPDF ";
seed += filename;
seed += " ";

View File

@ -45,7 +45,7 @@ QPDF::trim_user_password(std::string& user_password)
return;
}
char* p = 0;
char const* p = 0;
while ((p = strchr(cstr, '\x28')) != 0)
{
if (memcmp(p, padding_string, len - (p - cstr)) == 0)

View File

@ -624,7 +624,7 @@ QPDF::maxEnd(ObjUser const& ou)
assert(this->obj_user_to_objects.count(ou) > 0);
std::set<ObjGen> const& ogs = this->obj_user_to_objects[ou];
int end = 0;
for (std::set<ObjGen>::iterator iter = ogs.begin();
for (std::set<ObjGen>::const_iterator iter = ogs.begin();
iter != ogs.end(); ++iter)
{
ObjGen const& og = *iter;

View File

@ -141,6 +141,32 @@ QUtil::get_env(std::string const& var, std::string* value)
#endif
}
time_t
QUtil::get_current_time()
{
#ifdef _WIN32
// The procedure to get local time at this resolution comes from
// the Microsoft documentation. It says to convert a SYSTEMTIME
// to a FILETIME, and to copy the FILETIME to a ULARGE_INTEGER.
// The resulting number is the number of 100-nanosecond intervals
// between January 1, 1601 and now. POSIX threads wants a time
// based on January 1, 1970, so we adjust by subtracting the
// number of seconds in that time period from the result we get
// here.
SYSTEMTIME sysnow;
GetSystemTime(&sysnow);
FILETIME filenow;
SystemTimeToFileTime(&sysnow, &filenow);
ULARGE_INTEGER uinow;
uinow.LowPart = filenow.dwLowDateTime;
uinow.HighPart = filenow.dwHighDateTime;
ULONGLONG now = uinow.QuadPart;
return ((now / 10000000LL) - 11644473600LL);
#else
return time(0);
#endif
}
std::string
QUtil::toUTF8(unsigned long uval)
{

View File

@ -5,6 +5,9 @@
#ifndef __PCRE_HH__
#define __PCRE_HH__
#ifdef _WIN32
# define PCRE_STATIC
#endif
#include <pcre.h>
#include <string>

View File

@ -15,7 +15,7 @@ int main()
bool done = false;
while (! done)
{
int len = read(0, buf, sizeof(buf));
int len = fread(buf, 1, sizeof(buf), stdin);
if (len <= 0)
{
done = true;

View File

@ -15,7 +15,7 @@ int main()
bool done = false;
while (! done)
{
int len = read(0, buf, sizeof(buf));
int len = fread(buf, 1, sizeof(buf), stdin);
if (len <= 0)
{
done = true;

View File

@ -1,6 +1,7 @@
#include <qpdf/Pl_LZWDecoder.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
#include <iostream>
#include <stdlib.h>
#include <string.h>
@ -8,21 +9,36 @@
int main(int argc, char* argv[])
{
bool early_code_change = true;
if ((argc == 2) && (strcmp(argv[1], "--no-early-code-change") == 0))
if ((argc == 4) && (strcmp(argv[3], "--no-early-code-change") == 0))
{
early_code_change = false;
}
Pl_StdioFile out("stdout", stdout);
Pl_LZWDecoder decode("decode", &out, early_code_change);
if (argc < 3)
{
std::cerr << "Usage: lzw infile outfile [ --no-early-code-change ]"
<< std::endl;
exit(2);
}
try
{
char* infilename = argv[1];
char* outfilename = argv[2];
FILE* infile = QUtil::fopen_wrapper("open input file",
fopen(infilename, "rb"));
FILE* outfile = QUtil::fopen_wrapper("open output file",
fopen(outfilename, "wb"));
Pl_StdioFile out("output", outfile);
Pl_LZWDecoder decode("decode", &out, early_code_change);
unsigned char buf[10000];
bool done = false;
while (! done)
{
int len = read(0, buf, sizeof(buf));
int len = fread(buf, 1, sizeof(buf), infile);
if (len <= 0)
{
done = true;

View File

@ -17,6 +17,7 @@ $td->runtest("decode",
$td->runtest("partial decode",
{$td->COMMAND => "echo '\@<5skEHbu7\$3~>' | ascii85"},
{$td->STRING => "asdfqwer\n",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(2);

View File

@ -12,6 +12,7 @@ my $td = new TestDriver('bits');
$td->runtest("bits",
{$td->COMMAND => "bits"},
{$td->FILE => "bits.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(1);

View File

@ -12,6 +12,7 @@ my $td = new TestDriver('buffer');
$td->runtest("buffer",
{$td->COMMAND => "buffer"},
{$td->FILE => "buffer.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(1);

View File

@ -12,7 +12,7 @@ my $td = new TestDriver('lzw');
cleanup();
$td->runtest("decode: early code change",
{$td->COMMAND => "lzw < lzw1.in > tmp"},
{$td->COMMAND => "lzw lzw1.in tmp"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
@ -21,7 +21,7 @@ $td->runtest("check output",
{$td->FILE => "lzw1.out"});
$td->runtest("decode: no early code change",
{$td->COMMAND => "lzw --no-early-code-change < lzw2.in > tmp"},
{$td->COMMAND => "lzw lzw2.in tmp --no-early-code-change"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});

View File

@ -12,6 +12,7 @@ my $td = new TestDriver('md5');
$td->runtest("md5",
{$td->COMMAND => "md5"},
{$td->FILE => "md5.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(1);

View File

@ -16,7 +16,7 @@ $td->runtest("PCRE",
$td->NORMALIZE_NEWLINES);
chop(my $supported = `pcre --unicode-classes-supported`);
if ($supported)
if ($supported =~ m/^1/)
{
$td->runtest("unicode character classes",
{$td->COMMAND => "pcre --unicode-classes"},

View File

@ -12,6 +12,7 @@ my $td = new TestDriver('ph');
$td->runtest("PointerHolder",
{$td->COMMAND => "pointer_holder"},
{$td->FILE => "ph.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(1);

View File

@ -12,6 +12,7 @@ my $td = new TestDriver('qutil');
$td->runtest("QUtil",
{$td->COMMAND => "qutil"},
{$td->FILE => "qutil.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->report(1);

View File

@ -532,7 +532,7 @@ int main(int argc, char* argv[])
// Be lax about -arg vs --arg
++arg;
}
char* parameter = strchr(arg, '=');
char* parameter = (char*)strchr(arg, '=');
if (parameter)
{
*parameter++ = 0;