diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2012-05-09 22:42:27 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-05-10 13:38:25 +0100 |
commit | b0beab3eecdb1681f5fb8a163278803aad852b81 (patch) | |
tree | 3edb033c6d7e92e38e4c31d6394d9a357fac6ea6 /apps/mupdfclean.c | |
parent | 2d6f26cd8b09523fa29d97436801c27bec1832f4 (diff) | |
download | mupdf-b0beab3eecdb1681f5fb8a163278803aad852b81.tar.xz |
Clamp page numbers given to mupdfclean.
Also make page specification parsing in all tools look similar.
Diffstat (limited to 'apps/mupdfclean.c')
-rw-r--r-- | apps/mupdfclean.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c index dac36c51..f1e43b2d 100644 --- a/apps/mupdfclean.c +++ b/apps/mupdfclean.c @@ -60,17 +60,18 @@ static void retainpages(int argc, char **argv) /* Retain pages specified */ while (argc - fz_optind) { - int page, spage, epage; + int page, spage, epage, pagecount; char *spec, *dash; char *pagelist = argv[fz_optind]; + pagecount = pdf_count_pages(xref); spec = fz_strsep(&pagelist, ","); while (spec) { dash = strchr(spec, '-'); if (dash == spec) - spage = epage = pdf_count_pages(xref); + spage = epage = pagecount; else spage = epage = atoi(spec); @@ -79,16 +80,14 @@ static void retainpages(int argc, char **argv) if (strlen(dash) > 1) epage = atoi(dash + 1); else - epage = pdf_count_pages(xref); + epage = pagecount; } if (spage > epage) page = spage, spage = epage, epage = page; - if (spage < 1) - spage = 1; - if (epage > pdf_count_pages(xref)) - epage = pdf_count_pages(xref); + spage = CLAMP(spage, 1, pagecount); + epage = CLAMP(epage, 1, pagecount); for (page = spage; page <= epage; page++) { |