summaryrefslogtreecommitdiff
path: root/source/tools
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-10-17 16:41:59 +0200
committerTor Andersson <tor.andersson@artifex.com>2017-11-01 13:08:56 +0100
commit1dc763159b03cbd4387713f353f26c890d2c0e52 (patch)
treed43c18deeacd70e23d7e353c8f0c074c87419a34 /source/tools
parentf595e889b91a674eb94db7ca4d832da54f5194cd (diff)
downloadmupdf-1dc763159b03cbd4387713f353f26c890d2c0e52.tar.xz
Add separate fz_close_output step.
Closing flushes output and may throw exceptions. Dropping frees the state and never throws exceptions.
Diffstat (limited to 'source/tools')
-rw-r--r--source/tools/mudraw.c3
-rw-r--r--source/tools/muraster.c1
-rw-r--r--source/tools/pdfextract.c12
-rw-r--r--source/tools/pdfinfo.c11
-rw-r--r--source/tools/pdfpages.c11
-rw-r--r--source/tools/pdfshow.c15
6 files changed, 15 insertions, 38 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index c9c7bb55..e2322266 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -685,6 +685,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
else
fz_run_page(ctx, page, dev, &ctm, cookie);
fz_close_device(ctx, dev);
+ fz_close_output(ctx, out);
}
fz_always(ctx)
{
@@ -1136,6 +1137,7 @@ static void drawpage(fz_context *ctx, fz_document *doc, int pagenum)
char text_buffer[512];
bgprint_flush();
+ fz_close_output(ctx, out);
fz_drop_output(ctx, out);
fz_snprintf(text_buffer, sizeof(text_buffer), output, pagenum);
out = fz_new_output_with_path(ctx, text_buffer, output_append);
@@ -1948,6 +1950,7 @@ int mudraw_main(int argc, char **argv)
}
else
{
+ fz_close_output(ctx, out);
fz_drop_output(ctx, out);
out = NULL;
}
diff --git a/source/tools/muraster.c b/source/tools/muraster.c
index e48b8b09..956d420e 100644
--- a/source/tools/muraster.c
+++ b/source/tools/muraster.c
@@ -1718,6 +1718,7 @@ int main(int argc, char **argv)
}
#endif /* DISABLE_MUTHREADS */
+ fz_close_output(ctx, out);
fz_drop_output(ctx, out);
out = NULL;
diff --git a/source/tools/pdfextract.c b/source/tools/pdfextract.c
index 8c17a980..c6fe92aa 100644
--- a/source/tools/pdfextract.c
+++ b/source/tools/pdfextract.c
@@ -66,21 +66,18 @@ static void
writejpeg(fz_context *ctx, const unsigned char *data, size_t len, const char *file)
{
char buf[1024];
- fz_output *out = NULL;
-
- fz_var(out);
+ fz_output *out;
snprintf(buf, sizeof(buf), "%s.jpg", file);
+ out = fz_new_output_with_path(ctx, buf, 0);
fz_try(ctx)
{
- out = fz_new_output_with_path(ctx, buf, 0);
fz_write_data(ctx, out, data, len);
+ fz_close_output(ctx, out);
}
fz_always(ctx)
- {
fz_drop_output(ctx, out);
- }
fz_catch(ctx)
fz_rethrow(ctx);
}
@@ -199,7 +196,10 @@ static void savefont(pdf_obj *dict, int num)
printf("extracting font %s\n", namebuf);
out = fz_new_output_with_path(ctx, namebuf, 0);
fz_try(ctx)
+ {
fz_write_data(ctx, out, data, len);
+ fz_close_output(ctx, out);
+ }
fz_always(ctx)
fz_drop_output(ctx, out);
fz_catch(ctx)
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c
index 585279b1..ba95db0c 100644
--- a/source/tools/pdfinfo.c
+++ b/source/tools/pdfinfo.c
@@ -1006,7 +1006,6 @@ int pdfinfo_main(int argc, char **argv)
char *password = "";
int show = ALL;
int c;
- fz_output *out = NULL;
int ret;
fz_context *ctx;
@@ -1037,19 +1036,11 @@ int pdfinfo_main(int argc, char **argv)
exit(1);
}
- fz_var(out);
-
ret = 0;
fz_try(ctx)
- {
- out = fz_stdout(ctx);
- pdfinfo_info(ctx, out, filename, password, show, &argv[fz_optind], argc-fz_optind);
- }
+ pdfinfo_info(ctx, fz_stdout(ctx), filename, password, show, &argv[fz_optind], argc-fz_optind);
fz_catch(ctx)
- {
ret = 1;
- }
- fz_drop_output(ctx, out);
fz_drop_context(ctx);
return ret;
}
diff --git a/source/tools/pdfpages.c b/source/tools/pdfpages.c
index 9e8f6050..70f601cd 100644
--- a/source/tools/pdfpages.c
+++ b/source/tools/pdfpages.c
@@ -175,7 +175,6 @@ int pdfpages_main(int argc, char **argv)
char *filename = "";
char *password = "";
int c;
- fz_output *out = NULL;
int ret;
fz_context *ctx;
@@ -200,19 +199,11 @@ int pdfpages_main(int argc, char **argv)
exit(1);
}
- fz_var(out);
-
ret = 0;
fz_try(ctx)
- {
- out = fz_stdout(ctx);
- ret = pdfpages_pages(ctx, out, filename, password, &argv[fz_optind], argc-fz_optind);
- }
+ ret = pdfpages_pages(ctx, fz_stdout(ctx), filename, password, &argv[fz_optind], argc-fz_optind);
fz_catch(ctx)
- {
ret = 1;
- }
- fz_drop_output(ctx, out);
fz_drop_context(ctx);
return ret;
}
diff --git a/source/tools/pdfshow.c b/source/tools/pdfshow.c
index 0ae0fce7..c0358034 100644
--- a/source/tools/pdfshow.c
+++ b/source/tools/pdfshow.c
@@ -231,23 +231,12 @@ fz_print_outline(fz_context *ctx, fz_output *out, fz_outline *outline, int level
static void showoutline(void)
{
fz_outline *outline = fz_load_outline(ctx, (fz_document*)doc);
- fz_output *out = NULL;
-
- fz_var(out);
fz_try(ctx)
- {
- out = fz_stdout(ctx);
- fz_print_outline(ctx, out, outline, 0);
- }
+ fz_print_outline(ctx, fz_stdout(ctx), outline, 0);
fz_always(ctx)
- {
- fz_drop_output(ctx, out);
fz_drop_outline(ctx, outline);
- }
fz_catch(ctx)
- {
fz_rethrow(ctx);
- }
}
int pdfshow_main(int argc, char **argv)
@@ -311,6 +300,8 @@ int pdfshow_main(int argc, char **argv)
}
fz_optind++;
}
+
+ fz_close_output(ctx, out);
}
fz_catch(ctx)
{