2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

windows fixes

git-svn-id: svn+q:///qpdf/trunk@684 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-07-15 03:47:44 +00:00
parent 7acc0498eb
commit a1c0aaf03a
7 changed files with 46 additions and 8 deletions

View File

@ -32,6 +32,9 @@ namespace QUtil
char* copy_string(std::string const&);
// Set stdout to binary mode
void binary_stdout();
// Get the value of an environment variable in a portable fashion.
// Returns true iff the variable is defined. If `value' is
// non-null, initializes it with the value of the variable.

View File

@ -50,6 +50,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
this->filename = "standard output";
QTC::TC("qpdf", "QPDFWriter write to stdout");
file = stdout;
QUtil::binary_stdout();
}
else
{

View File

@ -5,9 +5,11 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifdef _WIN32
#include <Windows.h>
#include <direct.h>
#include <io.h>
#else
#include <unistd.h>
#endif
@ -104,6 +106,14 @@ QUtil::copy_string(std::string const& str)
return result;
}
void
QUtil::binary_stdout()
{
#ifdef _WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
}
bool
QUtil::get_env(std::string const& var, std::string* value)
{

View File

@ -2,6 +2,11 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef _WIN32
# include <io.h>
#endif
#include <qpdf/QUtil.hh>
#include <qpdf/QTC.hh>
@ -15,7 +20,7 @@
static int const EXIT_ERROR = 2;
static int const EXIT_WARNING = 3;
static char const* whoami = 0;
static char* whoami = 0;
// Note: let's not be too noisy about documenting the fact that this
// software purposely fails to enforce the distinction between user
@ -429,7 +434,12 @@ parse_encrypt_options(
int main(int argc, char* argv[])
{
if ((whoami = strrchr(argv[0], '/')) == NULL)
#ifdef _WIN32
char pathsep = '\\';
#else
char pathsep = '/';
#endif
if ((whoami = strrchr(argv[0], pathsep)) == NULL)
{
whoami = argv[0];
}
@ -437,6 +447,13 @@ int main(int argc, char* argv[])
{
++whoami;
}
#ifdef _WIN32
if ((strlen(whoami) > 4) &&
(strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
{
whoami[strlen(whoami) - 4] = '\0';
}
#endif
// For libtool's sake....
if (strncmp(whoami, "lt-", 3) == 0)
{
@ -790,6 +807,7 @@ int main(int argc, char* argv[])
}
else
{
QUtil::binary_stdout();
Pl_StdioFile out("stdout", stdout);
obj.pipeStreamData(&out, filter, normalize, false);
}

View File

@ -267,7 +267,8 @@ for (my $i = 1; $i <= scalar(@goodfiles); ++$i)
$td->runtest("$goodfiles[$i-1]",
{$td->COMMAND => "test_driver $n good$i.pdf"},
{$td->FILE => "good$i.out",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
my $xflags = $goodtest_flags{$i} || '';
check_pdf("create qdf",
"qpdf --static-id -qdf $xflags good$i.pdf",
@ -461,7 +462,8 @@ $td->runtest("unfilterable stream data",
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
" --show-object=8 --filtered-stream-data"},
{$td->FILE => "show-unfilterable.out",
$td->EXIT_STATUS => 2});
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("show-xref-by-id",
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
@ -837,7 +839,8 @@ foreach my $file (@files)
$td->runtest("check status",
{$td->COMMAND => "qpdf --check a.pdf"},
{$td->FILE => "$base.$n.check",
$td->EXIT_STATUS => 0});
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
compare_pdfs($file, "a.pdf");

View File

@ -126,6 +126,7 @@ void runtest(int n, char const* filename)
std::cout << "Raw stream data:" << std::endl;
std::cout.flush();
QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("raw", stdout);
qtest.pipeStreamData(out.getPointer(), false, false, false);
@ -133,6 +134,7 @@ void runtest(int n, char const* filename)
if (qtest.pipeStreamData(0, true, false, false))
{
std::cout.flush();
QUtil::binary_stdout();
out = new Pl_StdioFile("filtered", stdout);
qtest.pipeStreamData(out.getPointer(), true, false, false);
std::cout << std::endl << "End of stream data" << std::endl;
@ -172,6 +174,7 @@ void runtest(int n, char const* filename)
QPDFObjectHandle kids = pages.getKey("/Kids");
QPDFObjectHandle page = kids.getArrayItem(1); // second page
QPDFObjectHandle contents = page.getKey("/Contents");
QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("filtered", stdout);
contents.pipeStreamData(out.getPointer(), true, false, false);
}
@ -183,6 +186,7 @@ void runtest(int n, char const* filename)
QPDFObjectHandle stream = streams.getArrayItem(i);
std::cout << "-- stream " << i << " --" << std::endl;
std::cout.flush();
QUtil::binary_stdout();
PointerHolder<Pl_StdioFile> out =
new Pl_StdioFile("tokenized stream", stdout);
stream.pipeStreamData(out.getPointer(), true, true, false);

View File

@ -1,5 +1,6 @@
#include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_StdioFile.hh>
#include <qpdf/QUtil.hh>
#include <stdio.h>
#include <string.h>
@ -63,9 +64,7 @@ int main(int argc, char* argv[])
usage();
}
#ifdef _WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
QUtil::binary_stdout();
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
Pl_Flate* flate = new Pl_Flate("flate", out, action);