Commit fb1e29476c6b40ce08fbb59925da7d120099c00c

Authored by Jay Berkenbilt
1 parent 60fe8061

Add --no-warn option to suppress warnings (fixes #232)

ChangeLog
1 1 2018-08-12 Jay Berkenbilt <ejb@ql.org>
2 2  
  3 + * qpdf command line: add --no-warn option to suppress issuing
  4 + warning messages. If there are any conditions that would have
  5 + caused warnings to be issued, the exit status is still 3.
  6 +
3 7 * Rewrite the internals of Pl_Buffer to be much more efficient in
4 8 use of memory at a very slight performance cost. The old
5 9 implementation could cause memory usage to go out of control for
... ...
qpdf/qpdf.cc
... ... @@ -61,6 +61,7 @@ struct Options
61 61 split_pages(0),
62 62 verbose(false),
63 63 progress(false),
  64 + suppress_warnings(false),
64 65 copy_encryption(false),
65 66 encryption_file(0),
66 67 encryption_file_password(0),
... ... @@ -125,6 +126,7 @@ struct Options
125 126 int split_pages;
126 127 bool verbose;
127 128 bool progress;
  129 + bool suppress_warnings;
128 130 bool copy_encryption;
129 131 char const* encryption_file;
130 132 char const* encryption_file_password;
... ... @@ -262,6 +264,7 @@ Basic Options\n\
262 264 --password=password specify a password for accessing encrypted files\n\
263 265 --verbose provide additional informational output\n\
264 266 --progress give progress indicators while writing output\n\
  267 +--no-warn suppress warnings\n\
265 268 --linearize generated a linearized (web optimized) file\n\
266 269 --copy-encryption=file copy encryption parameters from specified file\n\
267 270 --encryption-file-password=password\n\
... ... @@ -515,8 +518,9 @@ page content stream. This attempt will be made even if it is not a\n\
515 518 page content stream, in which case it will produce unusable results.\n\
516 519 \n\
517 520 Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n\
518   -if any errors occurred. In --check mode, if there were warnings but not\n\
519   -errors, qpdf exits with a status of 3.\n\
  521 +if any errors occurred. If there were warnings but not errors, qpdf\n\
  522 +exits with a status of 3. If warnings would have been issued but --no-warn\n\
  523 +was given, an exit status of 3 is still used.\n\
520 524 \n";
521 525  
522 526 void usage(std::string const& msg)
... ... @@ -1676,6 +1680,10 @@ static void parse_options(int argc, char* argv[], Options&amp; o)
1676 1680 {
1677 1681 o.progress = true;
1678 1682 }
  1683 + else if (strcmp(arg, "no-warn") == 0)
  1684 + {
  1685 + o.suppress_warnings = true;
  1686 + }
1679 1687 else if (strcmp(arg, "deterministic-id") == 0)
1680 1688 {
1681 1689 o.deterministic_id = true;
... ... @@ -1832,6 +1840,10 @@ static void set_qpdf_options(QPDF&amp; pdf, Options&amp; o)
1832 1840 {
1833 1841 pdf.setPasswordIsHexKey(true);
1834 1842 }
  1843 + if (o.suppress_warnings)
  1844 + {
  1845 + pdf.setSuppressWarnings(true);
  1846 + }
1835 1847 }
1836 1848  
1837 1849 static void do_check(QPDF& pdf, Options& o, int& exit_code)
... ... @@ -2607,9 +2619,14 @@ int main(int argc, char* argv[])
2607 2619 }
2608 2620 if (! pdf.getWarnings().empty())
2609 2621 {
2610   - std::cerr << whoami << ": operation succeeded with warnings;"
2611   - << " resulting file may have some problems" << std::endl;
2612   - exit(EXIT_WARNING);
  2622 + if (! o.suppress_warnings)
  2623 + {
  2624 + std::cerr << whoami << ": operation succeeded with warnings;"
  2625 + << " resulting file may have some problems"
  2626 + << std::endl;
  2627 + }
  2628 + // Still exit with warning code even if warnings were suppressed.
  2629 + exit(EXIT_WARNING);
2613 2630 }
2614 2631 }
2615 2632 catch (std::exception& e)
... ...
qpdf/qtest/qpdf.test
... ... @@ -1528,7 +1528,7 @@ my @badfiles = (&quot;not a PDF file&quot;, # 1
1528 1528 "bad dictionary key", # 36
1529 1529 );
1530 1530  
1531   -$n_tests += @badfiles + 3;
  1531 +$n_tests += @badfiles + 5;
1532 1532  
1533 1533 # Test 6 contains errors in the free table consistency, but we no
1534 1534 # longer have any consistency check for this since it is not important
... ... @@ -1552,6 +1552,14 @@ for (my $i = 1; $i &lt;= scalar(@badfiles); ++$i)
1552 1552 $td->NORMALIZE_NEWLINES);
1553 1553 }
1554 1554  
  1555 +$td->runtest("Suppress warnings",
  1556 + {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"},
  1557 + {$td->STRING => "", $td->EXIT_STATUS => 3});
  1558 +$td->runtest("Suppress warnings with --check",
  1559 + {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"},
  1560 + {$td->FILE => "bad14-check-no-warn.out",
  1561 + $td->EXIT_STATUS => 3},
  1562 + $td->NORMALIZE_NEWLINES);
1555 1563 $td->runtest("C API: errors",
1556 1564 {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"},
1557 1565 {$td->FILE => "c-read-errors.out",
... ...
qpdf/qtest/qpdf/bad14-check-no-warn.out 0 → 100644
  1 +checking bad14.pdf
  2 +PDF Version: 1.3
  3 +File is not encrypted
  4 +File is not linearized
... ...