aboutsummaryrefslogtreecommitdiffstats
path: root/zlib-flate
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
committerJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
commit9a0b88bf7777c153dc46ace22db74ef24d51583a (patch)
treef567ac1cf2bf5071a611eb49323a935b6ac938ff /zlib-flate
downloadqpdf-9a0b88bf7777c153dc46ace22db74ef24d51583a.tar.zst
update release date to actual daterelease-qpdf-2.0
git-svn-id: svn+q:///qpdf/trunk@599 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'zlib-flate')
-rw-r--r--zlib-flate/Makefile1
-rw-r--r--zlib-flate/build.mk22
-rw-r--r--zlib-flate/qtest/1.compressedbin0 -> 193 bytes
-rw-r--r--zlib-flate/qtest/1.uncompressed5
-rw-r--r--zlib-flate/qtest/zf.test26
-rw-r--r--zlib-flate/zlib-flate.cc92
6 files changed, 146 insertions, 0 deletions
diff --git a/zlib-flate/Makefile b/zlib-flate/Makefile
new file mode 100644
index 00000000..90899055
--- /dev/null
+++ b/zlib-flate/Makefile
@@ -0,0 +1 @@
+include ../make/proxy.mk
diff --git a/zlib-flate/build.mk b/zlib-flate/build.mk
new file mode 100644
index 00000000..57d2c98c
--- /dev/null
+++ b/zlib-flate/build.mk
@@ -0,0 +1,22 @@
+TARGETS_zlib-flate = \
+ zlib-flate/$(OUTPUT_DIR)/zlib-flate
+
+$(TARGETS_zlib-flate): $(TARGETS_libqpdf)
+
+INCLUDES_zlib-flate = include
+
+SRCS_zlib-flate = zlib-flate/zlib-flate.cc
+
+# -----
+
+OBJS_zlib-flate = $(call src_to_obj,$(SRCS_zlib-flate))
+
+ifeq ($(GENDEPS),1)
+-include $(call obj_to_dep,$(OBJS_zlib-flate))
+endif
+
+$(OBJS_zlib-flate): zlib-flate/$(OUTPUT_DIR)/%.o: zlib-flate/%.cc
+ $(call compile,$<,$(INCLUDES_zlib-flate))
+
+zlib-flate/$(OUTPUT_DIR)/zlib-flate: $(OBJS_zlib-flate)
+ $(call makebin,$(OBJS_zlib-flate),$@)
diff --git a/zlib-flate/qtest/1.compressed b/zlib-flate/qtest/1.compressed
new file mode 100644
index 00000000..3d05ab1c
--- /dev/null
+++ b/zlib-flate/qtest/1.compressed
Binary files differ
diff --git a/zlib-flate/qtest/1.uncompressed b/zlib-flate/qtest/1.uncompressed
new file mode 100644
index 00000000..0446561f
--- /dev/null
+++ b/zlib-flate/qtest/1.uncompressed
@@ -0,0 +1,5 @@
+Once upon a time there lived three qowws. They didn't like poridge
+much, so they had salad for breakfast. Goldilocks, upon breaking and
+entering, found this to be distasteful and so she just went away
+without eating any. This somewhat short-circuited the story. The
+End.
diff --git a/zlib-flate/qtest/zf.test b/zlib-flate/qtest/zf.test
new file mode 100644
index 00000000..39271e16
--- /dev/null
+++ b/zlib-flate/qtest/zf.test
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+require 5.008;
+BEGIN { $^W = 1; }
+use strict;
+
+require TestDriver;
+
+my $td = new TestDriver('zlib-flate');
+
+$td->runtest("compress",
+ {$td->COMMAND => "zlib-flate -compress < 1.uncompressed"},
+ {$td->FILE => "1.compressed",
+ $td->EXIT_STATUS => 0});
+
+$td->runtest("uncompress",
+ {$td->COMMAND => "zlib-flate -uncompress < 1.compressed"},
+ {$td->FILE => "1.uncompressed",
+ $td->EXIT_STATUS => 0});
+
+$td->runtest("error",
+ {$td->COMMAND => "zlib-flate -uncompress < 1.uncompressed"},
+ {$td->REGEXP => "flate: inflate: data: .*\n",
+ $td->EXIT_STATUS => 2},
+ $td->NORMALIZE_NEWLINES);
+
+$td->report(3);
diff --git a/zlib-flate/zlib-flate.cc b/zlib-flate/zlib-flate.cc
new file mode 100644
index 00000000..33a3cdd9
--- /dev/null
+++ b/zlib-flate/zlib-flate.cc
@@ -0,0 +1,92 @@
+
+#include <qpdf/Pl_Flate.hh>
+#include <qpdf/Pl_StdioFile.hh>
+
+#include <stdio.h>
+#include <string.h>
+#include <iostream>
+#include <stdlib.h>
+#include <unistd.h>
+
+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();
+ }
+
+ 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)
+ {
+ int len = read(0, buf, sizeof(buf));
+ 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;
+}