mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +00:00
clean up windows portability code, make remaining test suite pass
git-svn-id: svn+q:///qpdf/trunk@686 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
parent
86f2d3449c
commit
fe18385ffa
@ -163,14 +163,8 @@ void extract_bookmarks(QPDFObjectHandle outlines, std::vector<int>& numbers)
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if ((whoami = strrchr(argv[0], '/')) == NULL)
|
||||
{
|
||||
whoami = argv[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
++whoami;
|
||||
}
|
||||
whoami = QUtil::getWhoami(argv[0]);
|
||||
|
||||
// For libtool's sake....
|
||||
if (strncmp(whoami, "lt-", 3) == 0)
|
||||
{
|
||||
|
@ -77,14 +77,8 @@ int main(int argc, char* argv[])
|
||||
bool static_id = false;
|
||||
std::map<std::string, std::string> Keys;
|
||||
|
||||
if ((whoami = strrchr(argv[0], '/')) == NULL)
|
||||
{
|
||||
whoami = argv[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
++whoami;
|
||||
}
|
||||
whoami = QUtil::getWhoami(argv[0]);
|
||||
|
||||
// For libtool's sake....
|
||||
if (strncmp(whoami, "lt-", 3) == 0)
|
||||
{
|
||||
@ -161,6 +155,9 @@ int main(int argc, char* argv[])
|
||||
usage();
|
||||
}
|
||||
|
||||
std::string fl_tmp = fl_out;
|
||||
fl_tmp += ".tmp";
|
||||
|
||||
try
|
||||
{
|
||||
QPDF file;
|
||||
@ -198,13 +195,21 @@ int main(int argc, char* argv[])
|
||||
fileinfo.replaceKey(it->first, elt);
|
||||
}
|
||||
}
|
||||
std::string fl_tmp = fl_out;
|
||||
fl_tmp += ".tmp";
|
||||
QPDFWriter w(file, fl_tmp.c_str());
|
||||
w.setStreamDataMode(QPDFWriter::s_preserve);
|
||||
w.setLinearization(true);
|
||||
w.setStaticID(static_id);
|
||||
w.write();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
exit(2);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
(void) unlink(fl_out);
|
||||
QUtil::os_wrapper("rename " + fl_tmp + " " + std::string(fl_out),
|
||||
rename(fl_tmp.c_str(), fl_out));
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QUtil.hh>
|
||||
|
||||
static char const* whoami = 0;
|
||||
|
||||
@ -15,14 +16,8 @@ void usage()
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if ((whoami = strrchr(argv[0], '/')) == NULL)
|
||||
{
|
||||
whoami = argv[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
++whoami;
|
||||
}
|
||||
whoami = QUtil::getWhoami(argv[0]);
|
||||
|
||||
// For libtool's sake....
|
||||
if (strncmp(whoami, "lt-", 3) == 0)
|
||||
{
|
||||
|
@ -18,32 +18,38 @@ cleanup();
|
||||
$td->runtest("usage #1",
|
||||
{$td->COMMAND => "$prg -in target.pdf"},
|
||||
{$td->FILE => "usage.out",
|
||||
$td->EXIT_STATUS => 2});
|
||||
$td->EXIT_STATUS => 2},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("usage #2",
|
||||
{$td->COMMAND => "$prg -key abc -val def"},
|
||||
{$td->FILE => "usage.out",
|
||||
$td->EXIT_STATUS => 2});
|
||||
$td->EXIT_STATUS => 2},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("usage #3",
|
||||
{$td->COMMAND => "$prg -key abc -val def abc"},
|
||||
{$td->FILE => "usage.out",
|
||||
$td->EXIT_STATUS => 2});
|
||||
$td->EXIT_STATUS => 2},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("usage #4",
|
||||
{$td->COMMAND => "$prg -in source1.pdf -key /date -val 01/01/01 -val 12/12/12"},
|
||||
{$td->FILE => "usage.out",
|
||||
$td->EXIT_STATUS => 2});
|
||||
$td->EXIT_STATUS => 2},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("dump #1",
|
||||
{$td->COMMAND => "$prg --dump -in files/source1.pdf"},
|
||||
{$td->FILE => "dump.out",
|
||||
$td->EXIT_STATUS => 0});
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("dump #2",
|
||||
{$td->COMMAND => "$prg --dump -in files/no-info.pdf"},
|
||||
{$td->STRING => "",
|
||||
$td->EXIT_STATUS => 0});
|
||||
$td->EXIT_STATUS => 0},
|
||||
$td->NORMALIZE_NEWLINES);
|
||||
|
||||
$td->runtest("dump #3",
|
||||
{$td->COMMAND => "$prg --dump -in files/empty-info.pdf"},
|
||||
|
@ -32,8 +32,12 @@ namespace QUtil
|
||||
|
||||
char* copy_string(std::string const&);
|
||||
|
||||
// Set stdout to binary mode
|
||||
// Set stdin, stdout to binary mode
|
||||
void binary_stdout();
|
||||
void binary_stdin();
|
||||
|
||||
// May modify argv0
|
||||
char* getWhoami(char* argv0);
|
||||
|
||||
// Get the value of an environment variable in a portable fashion.
|
||||
// Returns true iff the variable is defined. If `value' is
|
||||
|
@ -114,6 +114,41 @@ QUtil::binary_stdout()
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
QUtil::binary_stdin()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
#endif
|
||||
}
|
||||
|
||||
char*
|
||||
QUtil::getWhoami(char* argv0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char pathsep = '\\';
|
||||
#else
|
||||
char pathsep = '/';
|
||||
#endif
|
||||
char* whoami = 0;
|
||||
if ((whoami = strrchr(argv0, pathsep)) == NULL)
|
||||
{
|
||||
whoami = argv0;
|
||||
}
|
||||
else
|
||||
{
|
||||
++whoami;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if ((strlen(whoami) > 4) &&
|
||||
(strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
|
||||
{
|
||||
whoami[strlen(whoami) - 4] = '\0';
|
||||
}
|
||||
#endif
|
||||
return whoami;
|
||||
}
|
||||
|
||||
bool
|
||||
QUtil::get_env(std::string const& var, std::string* value)
|
||||
{
|
||||
|
@ -7,12 +7,6 @@
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 4)
|
||||
|
28
qpdf/qpdf.cc
28
qpdf/qpdf.cc
@ -4,10 +4,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <io.h>
|
||||
#endif
|
||||
|
||||
#include <qpdf/QUtil.hh>
|
||||
#include <qpdf/QTC.hh>
|
||||
#include <qpdf/Pl_StdioFile.hh>
|
||||
@ -20,7 +16,7 @@
|
||||
static int const EXIT_ERROR = 2;
|
||||
static int const EXIT_WARNING = 3;
|
||||
|
||||
static char* whoami = 0;
|
||||
static char const* whoami = 0;
|
||||
|
||||
// Note: let's not be too noisy about documenting the fact that this
|
||||
// software purposely fails to enforce the distinction between user
|
||||
@ -434,26 +430,8 @@ parse_encrypt_options(
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char pathsep = '\\';
|
||||
#else
|
||||
char pathsep = '/';
|
||||
#endif
|
||||
if ((whoami = strrchr(argv[0], pathsep)) == NULL)
|
||||
{
|
||||
whoami = argv[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
++whoami;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if ((strlen(whoami) > 4) &&
|
||||
(strcmp(whoami + strlen(whoami) - 4, ".exe") == 0))
|
||||
{
|
||||
whoami[strlen(whoami) - 4] = '\0';
|
||||
}
|
||||
#endif
|
||||
whoami = QUtil::getWhoami(argv[0]);
|
||||
|
||||
// For libtool's sake....
|
||||
if (strncmp(whoami, "lt-", 3) == 0)
|
||||
{
|
||||
|
@ -7,11 +7,6 @@
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef _WIN32
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
static char const* whoami = 0;
|
||||
|
||||
@ -65,6 +60,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
QUtil::binary_stdout();
|
||||
QUtil::binary_stdin();
|
||||
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
|
||||
Pl_Flate* flate = new Pl_Flate("flate", out, action);
|
||||
|
||||
@ -74,7 +70,7 @@ int main(int argc, char* argv[])
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user