mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
windows fixes
git-svn-id: svn+q:///qpdf/trunk@684 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
7acc0498eb
commit
a1c0aaf03a
@ -32,6 +32,9 @@ namespace QUtil
|
|||||||
|
|
||||||
char* copy_string(std::string const&);
|
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.
|
// Get the value of an environment variable in a portable fashion.
|
||||||
// Returns true iff the variable is defined. If `value' is
|
// Returns true iff the variable is defined. If `value' is
|
||||||
// non-null, initializes it with the value of the variable.
|
// non-null, initializes it with the value of the variable.
|
||||||
|
@ -50,6 +50,7 @@ QPDFWriter::QPDFWriter(QPDF& pdf, char const* filename) :
|
|||||||
this->filename = "standard output";
|
this->filename = "standard output";
|
||||||
QTC::TC("qpdf", "QPDFWriter write to stdout");
|
QTC::TC("qpdf", "QPDFWriter write to stdout");
|
||||||
file = stdout;
|
file = stdout;
|
||||||
|
QUtil::binary_stdout();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,11 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include <io.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
@ -104,6 +106,14 @@ QUtil::copy_string(std::string const& str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
QUtil::binary_stdout()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
_setmode(_fileno(stdout), _O_BINARY);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
QUtil::get_env(std::string const& var, std::string* value)
|
QUtil::get_env(std::string const& var, std::string* value)
|
||||||
{
|
{
|
||||||
|
22
qpdf/qpdf.cc
22
qpdf/qpdf.cc
@ -2,6 +2,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
# include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <qpdf/QUtil.hh>
|
#include <qpdf/QUtil.hh>
|
||||||
#include <qpdf/QTC.hh>
|
#include <qpdf/QTC.hh>
|
||||||
@ -15,7 +20,7 @@
|
|||||||
static int const EXIT_ERROR = 2;
|
static int const EXIT_ERROR = 2;
|
||||||
static int const EXIT_WARNING = 3;
|
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
|
// Note: let's not be too noisy about documenting the fact that this
|
||||||
// software purposely fails to enforce the distinction between user
|
// software purposely fails to enforce the distinction between user
|
||||||
@ -429,7 +434,12 @@ parse_encrypt_options(
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
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];
|
whoami = argv[0];
|
||||||
}
|
}
|
||||||
@ -437,6 +447,13 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
++whoami;
|
++whoami;
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
|
if ((strlen(whoami) > 4) &&
|
||||||
|
(strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
|
||||||
|
{
|
||||||
|
whoami[strlen(whoami) - 4] = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
// For libtool's sake....
|
// For libtool's sake....
|
||||||
if (strncmp(whoami, "lt-", 3) == 0)
|
if (strncmp(whoami, "lt-", 3) == 0)
|
||||||
{
|
{
|
||||||
@ -790,6 +807,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QUtil::binary_stdout();
|
||||||
Pl_StdioFile out("stdout", stdout);
|
Pl_StdioFile out("stdout", stdout);
|
||||||
obj.pipeStreamData(&out, filter, normalize, false);
|
obj.pipeStreamData(&out, filter, normalize, false);
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,8 @@ for (my $i = 1; $i <= scalar(@goodfiles); ++$i)
|
|||||||
$td->runtest("$goodfiles[$i-1]",
|
$td->runtest("$goodfiles[$i-1]",
|
||||||
{$td->COMMAND => "test_driver $n good$i.pdf"},
|
{$td->COMMAND => "test_driver $n good$i.pdf"},
|
||||||
{$td->FILE => "good$i.out",
|
{$td->FILE => "good$i.out",
|
||||||
$td->EXIT_STATUS => 0});
|
$td->EXIT_STATUS => 0},
|
||||||
|
$td->NORMALIZE_NEWLINES);
|
||||||
my $xflags = $goodtest_flags{$i} || '';
|
my $xflags = $goodtest_flags{$i} || '';
|
||||||
check_pdf("create qdf",
|
check_pdf("create qdf",
|
||||||
"qpdf --static-id -qdf $xflags good$i.pdf",
|
"qpdf --static-id -qdf $xflags good$i.pdf",
|
||||||
@ -461,7 +462,8 @@ $td->runtest("unfilterable stream data",
|
|||||||
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
|
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
|
||||||
" --show-object=8 --filtered-stream-data"},
|
" --show-object=8 --filtered-stream-data"},
|
||||||
{$td->FILE => "show-unfilterable.out",
|
{$td->FILE => "show-unfilterable.out",
|
||||||
$td->EXIT_STATUS => 2});
|
$td->EXIT_STATUS => 2},
|
||||||
|
$td->NORMALIZE_NEWLINES);
|
||||||
|
|
||||||
$td->runtest("show-xref-by-id",
|
$td->runtest("show-xref-by-id",
|
||||||
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
|
{$td->COMMAND => "qpdf encrypted-with-images.pdf" .
|
||||||
@ -837,7 +839,8 @@ foreach my $file (@files)
|
|||||||
$td->runtest("check status",
|
$td->runtest("check status",
|
||||||
{$td->COMMAND => "qpdf --check a.pdf"},
|
{$td->COMMAND => "qpdf --check a.pdf"},
|
||||||
{$td->FILE => "$base.$n.check",
|
{$td->FILE => "$base.$n.check",
|
||||||
$td->EXIT_STATUS => 0});
|
$td->EXIT_STATUS => 0},
|
||||||
|
$td->NORMALIZE_NEWLINES);
|
||||||
|
|
||||||
compare_pdfs($file, "a.pdf");
|
compare_pdfs($file, "a.pdf");
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ void runtest(int n, char const* filename)
|
|||||||
|
|
||||||
std::cout << "Raw stream data:" << std::endl;
|
std::cout << "Raw stream data:" << std::endl;
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
QUtil::binary_stdout();
|
||||||
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("raw", stdout);
|
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("raw", stdout);
|
||||||
qtest.pipeStreamData(out.getPointer(), false, false, false);
|
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))
|
if (qtest.pipeStreamData(0, true, false, false))
|
||||||
{
|
{
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
QUtil::binary_stdout();
|
||||||
out = new Pl_StdioFile("filtered", stdout);
|
out = new Pl_StdioFile("filtered", stdout);
|
||||||
qtest.pipeStreamData(out.getPointer(), true, false, false);
|
qtest.pipeStreamData(out.getPointer(), true, false, false);
|
||||||
std::cout << std::endl << "End of stream data" << std::endl;
|
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 kids = pages.getKey("/Kids");
|
||||||
QPDFObjectHandle page = kids.getArrayItem(1); // second page
|
QPDFObjectHandle page = kids.getArrayItem(1); // second page
|
||||||
QPDFObjectHandle contents = page.getKey("/Contents");
|
QPDFObjectHandle contents = page.getKey("/Contents");
|
||||||
|
QUtil::binary_stdout();
|
||||||
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("filtered", stdout);
|
PointerHolder<Pl_StdioFile> out = new Pl_StdioFile("filtered", stdout);
|
||||||
contents.pipeStreamData(out.getPointer(), true, false, false);
|
contents.pipeStreamData(out.getPointer(), true, false, false);
|
||||||
}
|
}
|
||||||
@ -183,6 +186,7 @@ void runtest(int n, char const* filename)
|
|||||||
QPDFObjectHandle stream = streams.getArrayItem(i);
|
QPDFObjectHandle stream = streams.getArrayItem(i);
|
||||||
std::cout << "-- stream " << i << " --" << std::endl;
|
std::cout << "-- stream " << i << " --" << std::endl;
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
QUtil::binary_stdout();
|
||||||
PointerHolder<Pl_StdioFile> out =
|
PointerHolder<Pl_StdioFile> out =
|
||||||
new Pl_StdioFile("tokenized stream", stdout);
|
new Pl_StdioFile("tokenized stream", stdout);
|
||||||
stream.pipeStreamData(out.getPointer(), true, true, false);
|
stream.pipeStreamData(out.getPointer(), true, true, false);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <qpdf/Pl_Flate.hh>
|
#include <qpdf/Pl_Flate.hh>
|
||||||
#include <qpdf/Pl_StdioFile.hh>
|
#include <qpdf/Pl_StdioFile.hh>
|
||||||
|
#include <qpdf/QUtil.hh>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -63,9 +64,7 @@ int main(int argc, char* argv[])
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
QUtil::binary_stdout();
|
||||||
_setmode(_fileno(stdout), _O_BINARY);
|
|
||||||
#endif
|
|
||||||
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
|
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
|
||||||
Pl_Flate* flate = new Pl_Flate("flate", out, action);
|
Pl_Flate* flate = new Pl_Flate("flate", out, action);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user