Commit a7ef572c8485636aeb988f9c912979401c1e2164
1 parent
47f4ebcd
Small enhancement to --pages argument parsing
Showing
5 changed files
with
26 additions
and
4 deletions
ChangeLog
| 1 | +2020-11-09 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Handle "." appearing in --pages not preceded by a numeric range | ||
| 4 | + as a special case in comand-line parsing code. | ||
| 5 | + | ||
| 1 | 2020-11-04 Jay Berkenbilt <ejb@ql.org> | 6 | 2020-11-04 Jay Berkenbilt <ejb@ql.org> |
| 2 | 7 | ||
| 3 | * Ignore the value of the offset/generation field in an xref entry | 8 | * Ignore the value of the offset/generation field in an xref entry |
qpdf/qpdf.cc
| @@ -2877,9 +2877,17 @@ ArgParser::parsePagesOptions() | @@ -2877,9 +2877,17 @@ ArgParser::parsePagesOptions() | ||
| 2877 | // The range is invalid. Let's see if it's a file. | 2877 | // The range is invalid. Let's see if it's a file. |
| 2878 | try | 2878 | try |
| 2879 | { | 2879 | { |
| 2880 | - fclose(QUtil::safe_fopen(range, "rb")); | ||
| 2881 | - // Yup, it's a file. | ||
| 2882 | - QTC::TC("qpdf", "qpdf pages range omitted in middle"); | 2880 | + if (strcmp(range, ".") == 0) |
| 2881 | + { | ||
| 2882 | + // "." means the input file. | ||
| 2883 | + QTC::TC("qpdf", "qpdf pages range omitted with ."); | ||
| 2884 | + } | ||
| 2885 | + else | ||
| 2886 | + { | ||
| 2887 | + fclose(QUtil::safe_fopen(range, "rb")); | ||
| 2888 | + QTC::TC("qpdf", "qpdf pages range omitted in middle"); | ||
| 2889 | + // Yup, it's a file. | ||
| 2890 | + } | ||
| 2883 | range_omitted = true; | 2891 | range_omitted = true; |
| 2884 | } | 2892 | } |
| 2885 | catch (std::runtime_error&) | 2893 | catch (std::runtime_error&) |
qpdf/qpdf.testcov
| @@ -456,3 +456,4 @@ qpdf found shared xobject in leaf 0 | @@ -456,3 +456,4 @@ qpdf found shared xobject in leaf 0 | ||
| 456 | QPDF copy foreign with data 1 | 456 | QPDF copy foreign with data 1 |
| 457 | QPDF copy foreign with foreign_stream 1 | 457 | QPDF copy foreign with foreign_stream 1 |
| 458 | QPDFObjectHandle need_newline 1 | 458 | QPDFObjectHandle need_newline 1 |
| 459 | +qpdf pages range omitted with . 0 |
qpdf/qtest/qpdf.test
| @@ -2093,7 +2093,7 @@ foreach my $f (qw(page_api_2 direct-pages)) | @@ -2093,7 +2093,7 @@ foreach my $f (qw(page_api_2 direct-pages)) | ||
| 2093 | show_ntests(); | 2093 | show_ntests(); |
| 2094 | # ---------- | 2094 | # ---------- |
| 2095 | $td->notify("--- Merging and Splitting ---"); | 2095 | $td->notify("--- Merging and Splitting ---"); |
| 2096 | -$n_tests += 26; | 2096 | +$n_tests += 28; |
| 2097 | 2097 | ||
| 2098 | # Select pages from the same file multiple times including selecting | 2098 | # Select pages from the same file multiple times including selecting |
| 2099 | # twice from an encrypted file and specifying the password only the | 2099 | # twice from an encrypted file and specifying the password only the |
| @@ -2149,6 +2149,14 @@ $td->runtest("merge with implicit ranges", | @@ -2149,6 +2149,14 @@ $td->runtest("merge with implicit ranges", | ||
| 2149 | $td->runtest("check output", | 2149 | $td->runtest("check output", |
| 2150 | {$td->FILE => "a.pdf"}, | 2150 | {$td->FILE => "a.pdf"}, |
| 2151 | {$td->FILE => "merge-implicit-ranges.pdf"}); | 2151 | {$td->FILE => "merge-implicit-ranges.pdf"}); |
| 2152 | +$td->runtest("merge with . and implicit ranges", | ||
| 2153 | + {$td->COMMAND => | ||
| 2154 | + "qpdf minimal.pdf a.pdf --pages minimal.pdf . 1 --" . | ||
| 2155 | + " --static-id"}, | ||
| 2156 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 2157 | +$td->runtest("check output", | ||
| 2158 | + {$td->FILE => "a.pdf"}, | ||
| 2159 | + {$td->FILE => "merge-dot-implicit-ranges.pdf"}); | ||
| 2152 | $td->runtest("merge with multiple labels", | 2160 | $td->runtest("merge with multiple labels", |
| 2153 | {$td->COMMAND => | 2161 | {$td->COMMAND => |
| 2154 | "qpdf --empty a.pdf" . | 2162 | "qpdf --empty a.pdf" . |
qpdf/qtest/qpdf/merge-dot-implicit-ranges.pdf
0 → 100644
No preview for this file type