summaryrefslogtreecommitdiff
path: root/filter/ahxe.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2004-09-27 02:15:04 +0200
committerTor Andersson <tor@ghostscript.com>2004-09-27 02:15:04 +0200
commit6ddde92a3a45e970b05770633dc6a337d5d013c5 (patch)
tree1dec4612d7469839478e72d16d30a0da5755243c /filter/ahxe.c
downloadmupdf-6ddde92a3a45e970b05770633dc6a337d5d013c5.tar.xz
Initial import
Diffstat (limited to 'filter/ahxe.c')
-rw-r--r--filter/ahxe.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/filter/ahxe.c b/filter/ahxe.c
new file mode 100644
index 00000000..e092653b
--- /dev/null
+++ b/filter/ahxe.c
@@ -0,0 +1,65 @@
+#include <fitz.h>
+
+typedef struct fz_ahxe_s fz_ahxe;
+
+struct fz_ahxe_s
+{
+ fz_filter super;
+ int c;
+};
+
+static const char tohex[16] = "0123456789ABCDEF";
+
+fz_error *
+fz_newahxe(fz_filter **fp, fz_obj *params)
+{
+ FZ_NEWFILTER(fz_ahxe, f, ahxe);
+ f->c = 0;
+ return nil;
+}
+
+void
+fz_freeahxe(fz_filter *f)
+{
+ fz_free(f);
+}
+
+fz_error *
+fz_processahxe(fz_filter *filter, fz_buffer *in, fz_buffer *out)
+{
+ fz_ahxe *f = (fz_ahxe*)filter;
+ int a, b, c;
+
+ while (1)
+ {
+ if (in->rp == in->wp)
+ goto needinput;
+
+ if (out->wp + 2 >= out->ep) /* can write 3 bytes from 1 */
+ return fz_ioneedout;
+
+ c = *in->rp++;
+ a = tohex[(c >> 4) & 0x0f];
+ b = tohex[c & 0x0f];
+
+ *out->wp++ = a;
+ *out->wp++ = b;
+
+ f->c += 2;
+ if (f->c == 60) {
+ *out->wp++ = '\n';
+ f->c = 0;
+ }
+ }
+
+needinput:
+ if (in->eof) {
+ if (out->wp == out->ep)
+ return fz_ioneedout;
+ *out->wp++ = '>';
+ out->eof = 1;
+ return fz_iodone;
+ }
+ return fz_ioneedin;
+}
+