From d797d4707564bd9c0e1536d1d6355945aa1be740 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 29 Jul 2010 23:17:46 +0000 Subject: Use chained reader like interface for filters instead of process interface. --- apps/pdfapp.c | 2 +- apps/pdfclean.c | 6 +++--- apps/pdfextract.c | 11 ++++++----- apps/pdfshow.c | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 5a2d2322..1393d4e3 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -106,7 +106,7 @@ void pdfapp_open(pdfapp_t *app, char *filename, int fd) error = pdf_openxrefwithstream(&app->xref, file, NULL); if (error) pdfapp_error(app, fz_rethrow(error, "cannot open document '%s'", filename)); - fz_dropstream(file); + fz_close(file); /* * Handle encrypted PDF files diff --git a/apps/pdfclean.c b/apps/pdfclean.c index 27c8693c..aca76e2a 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -380,7 +380,7 @@ static void copystream(fz_obj *obj, int num, int gen) fprintf(out, "%d %d obj\n", num, gen); fz_fprintobj(out, obj, !doexpand); fprintf(out, "stream\n"); - fwrite(buf->rp, 1, buf->wp - buf->rp, out); + fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); fz_dropbuffer(buf); @@ -400,14 +400,14 @@ static void expandstream(fz_obj *obj, int num, int gen) fz_dictdels(newdict, "Filter"); fz_dictdels(newdict, "DecodeParms"); - newlen = fz_newint(buf->wp - buf->rp); + newlen = fz_newint(buf->len); fz_dictputs(newdict, "Length", newlen); fz_dropobj(newlen); fprintf(out, "%d %d obj\n", num, gen); fz_fprintobj(out, newdict, !doexpand); fprintf(out, "stream\n"); - fwrite(buf->rp, 1, buf->wp - buf->rp, out); + fwrite(buf->data, 1, buf->len, out); fprintf(out, "endstream\nendobj\n\n"); fz_dropobj(newdict); diff --git a/apps/pdfextract.c b/apps/pdfextract.c index e0da93e6..cb10e117 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -92,8 +92,8 @@ static void savefont(fz_obj *dict, int num) fz_obj *obj; char *ext = ""; FILE *f; - unsigned char *p; char *fontname = "font"; + int n; obj = fz_dictgets(dict, "FontName"); if (obj) @@ -148,13 +148,14 @@ static void savefont(fz_obj *dict, int num) f = fopen(name, "wb"); if (f == NULL) - die(fz_throw("Error creating image file")); + die(fz_throw("Error creating font file")); - for (p = buf->rp; p < buf->wp; p ++) - fprintf(f, "%c", *p); + n = fwrite(buf, 1, buf->len, f); + if (n < buf->len) + die(fz_throw("Error writing font file")); if (fclose(f) < 0) - die(fz_throw("Error closing image file")); + die(fz_throw("Error closing font file")); fz_dropbuffer(buf); } diff --git a/apps/pdfshow.c b/apps/pdfshow.c index cb15fd99..b05f6013 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -111,9 +111,9 @@ static void showstream(int num, int gen) while (1) { - error = fz_read(&n, stm, buf, sizeof buf); - if (error) - die(error); + n = fz_read(stm, buf, sizeof buf); + if (n < 0) + die(n); if (n == 0) break; if (showbinary) @@ -122,7 +122,7 @@ static void showstream(int num, int gen) showsafe(buf, n); } - fz_dropstream(stm); + fz_close(stm); } static void showobject(int num, int gen) -- cgit v1.2.3