2008-04-29 12:55:25 +00:00
|
|
|
#include <qpdf/Pl_Flate.hh>
|
|
|
|
#include <qpdf/Pl_StdioFile.hh>
|
2009-07-15 03:47:44 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
2009-07-13 00:08:55 +00:00
|
|
|
#include <fcntl.h>
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
static char const* whoami = 0;
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
std::cerr << "Usage: " << whoami << " { -uncompress | -compress }"
|
|
|
|
<< std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
if ((whoami = strrchr(argv[0], '/')) == NULL)
|
|
|
|
{
|
|
|
|
whoami = argv[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++whoami;
|
|
|
|
}
|
|
|
|
// For libtool's sake....
|
|
|
|
if (strncmp(whoami, "lt-", 3) == 0)
|
|
|
|
{
|
|
|
|
whoami += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((argc == 2) && (strcmp(argv[1], "--version") == 0))
|
|
|
|
{
|
|
|
|
std::cout << whoami << " version 1.0" << std::endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
Pl_Flate::action_e action = Pl_Flate::a_inflate;
|
|
|
|
|
|
|
|
if ((strcmp(argv[1], "-uncompress") == 0))
|
|
|
|
{
|
|
|
|
// okay
|
|
|
|
}
|
|
|
|
else if ((strcmp(argv[1], "-compress") == 0))
|
|
|
|
{
|
|
|
|
action = Pl_Flate::a_deflate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2009-07-15 03:47:44 +00:00
|
|
|
QUtil::binary_stdout();
|
2009-07-15 04:26:32 +00:00
|
|
|
QUtil::binary_stdin();
|
2008-04-29 12:55:25 +00:00
|
|
|
Pl_StdioFile* out = new Pl_StdioFile("stdout", stdout);
|
|
|
|
Pl_Flate* flate = new Pl_Flate("flate", out, action);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
unsigned char buf[10000];
|
|
|
|
bool done = false;
|
|
|
|
while (! done)
|
|
|
|
{
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t len = fread(buf, 1, sizeof(buf), stdin);
|
2008-04-29 12:55:25 +00:00
|
|
|
if (len <= 0)
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flate->write(buf, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flate->finish();
|
|
|
|
delete flate;
|
|
|
|
delete out;
|
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|