Commit 53d8e916b75b983c18d4611e91d6e74cb51a49ec

Authored by Jay Berkenbilt
1 parent 5f128b9a

Interpret . in --pages as a shortcut for the primary file

ChangeLog
  1 +2019-01-12 Jay Berkenbilt <ejb@ql.org>
  2 +
  3 + * In --pages, allow "." as a replacement for the current input
  4 + file, making it possible to say "qpdf A.pdf --pages . 1-3 --"
  5 + instead of having to repeat the input filename.
  6 +
1 7 2019-01-10 Jay Berkenbilt <ejb@ql.org>
2 8  
3 9 * Add new configure option --enable-avoid-windows-handle, which
... ...
manual/qpdf-manual.xml
... ... @@ -956,6 +956,11 @@ make
956 956 selection flags.
957 957 </para>
958 958 <para>
  959 + Starting with qpf 8.4, the special input file name
  960 + &ldquo;<filename>.</filename>&rdquo; can be used shortcut for the
  961 + primary input filename.
  962 + </para>
  963 + <para>
959 964 For each file that pages should be taken from, specify the file, a
960 965 password needed to open the file (if any), and a page range. The
961 966 password needs to be given only once per file. If any of the
... ... @@ -1075,7 +1080,7 @@ make
1075 1080 <filename>infile.pdf</filename> while preserving all metadata
1076 1081 associated with that file, you could use
1077 1082  
1078   - <programlisting><command>qpdf</command> <option>infile.pdf --pages infile.pdf 1-5 -- outfile.pdf</option>
  1083 + <programlisting><command>qpdf</command> <option>infile.pdf --pages . 1-5 -- outfile.pdf</option>
1079 1084 </programlisting>
1080 1085 If you wanted pages 1 through 5 from
1081 1086 <filename>infile.pdf</filename> but you wanted the rest of the
... ... @@ -1087,7 +1092,7 @@ make
1087 1092 <filename>file1.pdf</filename> and pages 11&ndash;15 from
1088 1093 <filename>file2.pdf</filename> in reverse, you would run
1089 1094  
1090   - <programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 file2.pdf 15-11 -- outfile.pdf</option>
  1095 + <programlisting><command>qpdf</command> <option>file1.pdf --pages file1.pdf 1-5 . 15-11 -- outfile.pdf</option>
1091 1096 </programlisting>
1092 1097 If, for some reason, you wanted to take the first page of an
1093 1098 encrypted file called <filename>encrypted.pdf</filename> with
... ...
qpdf/qpdf.cc
... ... @@ -1092,7 +1092,8 @@ ArgParser::argHelp()
1092 1092 << "password needs to be given only once per file. If any of the input\n"
1093 1093 << "files are the same as the primary input file or the file used to copy\n"
1094 1094 << "encryption parameters (if specified), you do not need to repeat the\n"
1095   - << "password here. The same file can be repeated multiple times. All\n"
  1095 + << "password here. The same file can be repeated multiple times. The\n"
  1096 + << "filename \".\" may be used to refer to the current input file. All\n"
1096 1097 << "non-page data (info, outlines, page numbers, etc. are taken from the\n"
1097 1098 << "primary input file. To discard this, use --empty as the primary\n"
1098 1099 << "input.\n"
... ... @@ -3676,6 +3677,17 @@ static void handle_page_specs(QPDF&amp; pdf, Options&amp; o)
3676 3677 // Parse all page specifications and translate them into lists of
3677 3678 // actual pages.
3678 3679  
  3680 + // Handle "." as a shortcut for the input file
  3681 + for (std::vector<PageSpec>::iterator iter = o.page_specs.begin();
  3682 + iter != o.page_specs.end(); ++iter)
  3683 + {
  3684 + PageSpec& page_spec = *iter;
  3685 + if (page_spec.filename == ".")
  3686 + {
  3687 + page_spec.filename = o.infilename;
  3688 + }
  3689 + }
  3690 +
3679 3691 if (! o.keep_files_open_set)
3680 3692 {
3681 3693 // Count the number of distinct files to determine whether we
... ...
qpdf/qtest/qpdf.test
... ... @@ -1692,11 +1692,10 @@ $td-&gt;runtest(&quot;check output&quot;,
1692 1692 {$td->FILE => "a.pdf"},
1693 1693 {$td->FILE => "merge-multiple-labels.pdf"});
1694 1694  
1695   -$td->runtest("split with shared resources",
  1695 +$td->runtest("split with shared resources", # QXXXQ
1696 1696 {$td->COMMAND =>
1697 1697 "qpdf --qdf --static-id" .
1698   - " shared-images.pdf --pages" .
1699   - " shared-images.pdf 1,3" .
  1698 + " shared-images.pdf --pages . 1,3" .
1700 1699 " ./shared-images.pdf 1,2 -- a.pdf"},
1701 1700 {$td->STRING => "", $td->EXIT_STATUS => 0});
1702 1701 $td->runtest("check output",
... ... @@ -1706,8 +1705,7 @@ $td-&gt;runtest(&quot;check output&quot;,
1706 1705 $td->runtest("shared resources relevant errors",
1707 1706 {$td->COMMAND =>
1708 1707 "qpdf --qdf --static-id" .
1709   - " shared-images-errors.pdf --pages" .
1710   - " shared-images-errors.pdf 2 -- a.pdf"},
  1708 + " shared-images-errors.pdf --pages . 2 -- a.pdf"},
1711 1709 {$td->FILE => "shared-images-errors-2.out",
1712 1710 $td->EXIT_STATUS => 3},
1713 1711 $td->NORMALIZE_NEWLINES);
... ... @@ -1718,8 +1716,7 @@ $td-&gt;runtest(&quot;check output&quot;,
1718 1716 $td->runtest("shared resources irrelevant errors",
1719 1717 {$td->COMMAND =>
1720 1718 "qpdf --qdf --static-id" .
1721   - " shared-images-errors.pdf --pages" .
1722   - " shared-images-errors.pdf 1 -- a.pdf"},
  1719 + " shared-images-errors.pdf --pages . 1 -- a.pdf"},
1723 1720 {$td->FILE => "shared-images-errors-1.out",
1724 1721 $td->EXIT_STATUS => 3},
1725 1722 $td->NORMALIZE_NEWLINES);
... ... @@ -1730,8 +1727,7 @@ $td-&gt;runtest(&quot;check output&quot;,
1730 1727 $td->runtest("don't remove shared resources",
1731 1728 {$td->COMMAND =>
1732 1729 "qpdf --qdf --static-id --preserve-unreferenced-resources" .
1733   - " shared-images.pdf --pages" .
1734   - " shared-images.pdf 1,3 -- a.pdf"},
  1730 + " shared-images.pdf --pages . 1,3 -- a.pdf"},
1735 1731 {$td->STRING => "", $td->EXIT_STATUS => 0});
1736 1732 $td->runtest("check output",
1737 1733 {$td->FILE => "a.pdf"},
... ...