summaryrefslogtreecommitdiff
path: root/stream/filt_ahxe.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
committerTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
commitee154f16bd09a43359967f7e7b86c3677c09461d (patch)
tree08896cfa9ff55e05bfe7855965c620d45115d4d5 /stream/filt_ahxe.c
parent460ad7040d67a4a93a153f98095ff952a2b15d37 (diff)
downloadmupdf-ee154f16bd09a43359967f7e7b86c3677c09461d.tar.xz
rename part 1 -- files
Diffstat (limited to 'stream/filt_ahxe.c')
-rw-r--r--stream/filt_ahxe.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/stream/filt_ahxe.c b/stream/filt_ahxe.c
new file mode 100644
index 00000000..c2b882a6
--- /dev/null
+++ b/stream/filt_ahxe.c
@@ -0,0 +1,64 @@
+#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_dropahxe(fz_filter *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;
+}
+