2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

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

This commit is contained in:
Jay Berkenbilt 2018-08-12 22:20:40 -04:00
parent 60fe8061cb
commit fb1e29476c
4 changed files with 39 additions and 6 deletions

View File

@ -1,5 +1,9 @@
2018-08-12 Jay Berkenbilt <ejb@ql.org> 2018-08-12 Jay Berkenbilt <ejb@ql.org>
* qpdf command line: add --no-warn option to suppress issuing
warning messages. If there are any conditions that would have
caused warnings to be issued, the exit status is still 3.
* Rewrite the internals of Pl_Buffer to be much more efficient in * Rewrite the internals of Pl_Buffer to be much more efficient in
use of memory at a very slight performance cost. The old use of memory at a very slight performance cost. The old
implementation could cause memory usage to go out of control for implementation could cause memory usage to go out of control for

View File

@ -61,6 +61,7 @@ struct Options
split_pages(0), split_pages(0),
verbose(false), verbose(false),
progress(false), progress(false),
suppress_warnings(false),
copy_encryption(false), copy_encryption(false),
encryption_file(0), encryption_file(0),
encryption_file_password(0), encryption_file_password(0),
@ -125,6 +126,7 @@ struct Options
int split_pages; int split_pages;
bool verbose; bool verbose;
bool progress; bool progress;
bool suppress_warnings;
bool copy_encryption; bool copy_encryption;
char const* encryption_file; char const* encryption_file;
char const* encryption_file_password; char const* encryption_file_password;
@ -262,6 +264,7 @@ Basic Options\n\
--password=password specify a password for accessing encrypted files\n\ --password=password specify a password for accessing encrypted files\n\
--verbose provide additional informational output\n\ --verbose provide additional informational output\n\
--progress give progress indicators while writing output\n\ --progress give progress indicators while writing output\n\
--no-warn suppress warnings\n\
--linearize generated a linearized (web optimized) file\n\ --linearize generated a linearized (web optimized) file\n\
--copy-encryption=file copy encryption parameters from specified file\n\ --copy-encryption=file copy encryption parameters from specified file\n\
--encryption-file-password=password\n\ --encryption-file-password=password\n\
@ -515,8 +518,9 @@ page content stream. This attempt will be made even if it is not a\n\
page content stream, in which case it will produce unusable results.\n\ page content stream, in which case it will produce unusable results.\n\
\n\ \n\
Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n\ Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n\
if any errors occurred. In --check mode, if there were warnings but not\n\ if any errors occurred. If there were warnings but not errors, qpdf\n\
errors, qpdf exits with a status of 3.\n\ exits with a status of 3. If warnings would have been issued but --no-warn\n\
was given, an exit status of 3 is still used.\n\
\n"; \n";
void usage(std::string const& msg) void usage(std::string const& msg)
@ -1676,6 +1680,10 @@ static void parse_options(int argc, char* argv[], Options& o)
{ {
o.progress = true; o.progress = true;
} }
else if (strcmp(arg, "no-warn") == 0)
{
o.suppress_warnings = true;
}
else if (strcmp(arg, "deterministic-id") == 0) else if (strcmp(arg, "deterministic-id") == 0)
{ {
o.deterministic_id = true; o.deterministic_id = true;
@ -1832,6 +1840,10 @@ static void set_qpdf_options(QPDF& pdf, Options& o)
{ {
pdf.setPasswordIsHexKey(true); pdf.setPasswordIsHexKey(true);
} }
if (o.suppress_warnings)
{
pdf.setSuppressWarnings(true);
}
} }
static void do_check(QPDF& pdf, Options& o, int& exit_code) static void do_check(QPDF& pdf, Options& o, int& exit_code)
@ -2606,9 +2618,14 @@ int main(int argc, char* argv[])
write_outfile(pdf, o); write_outfile(pdf, o);
} }
if (! pdf.getWarnings().empty()) if (! pdf.getWarnings().empty())
{
if (! o.suppress_warnings)
{ {
std::cerr << whoami << ": operation succeeded with warnings;" std::cerr << whoami << ": operation succeeded with warnings;"
<< " resulting file may have some problems" << std::endl; << " resulting file may have some problems"
<< std::endl;
}
// Still exit with warning code even if warnings were suppressed.
exit(EXIT_WARNING); exit(EXIT_WARNING);
} }
} }

View File

@ -1528,7 +1528,7 @@ my @badfiles = ("not a PDF file", # 1
"bad dictionary key", # 36 "bad dictionary key", # 36
); );
$n_tests += @badfiles + 3; $n_tests += @badfiles + 5;
# Test 6 contains errors in the free table consistency, but we no # Test 6 contains errors in the free table consistency, but we no
# longer have any consistency check for this since it is not important # longer have any consistency check for this since it is not important
@ -1552,6 +1552,14 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i)
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
} }
$td->runtest("Suppress warnings",
{$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 3});
$td->runtest("Suppress warnings with --check",
{$td->COMMAND => "qpdf --check --no-warn bad14.pdf"},
{$td->FILE => "bad14-check-no-warn.out",
$td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("C API: errors", $td->runtest("C API: errors",
{$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"}, {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"},
{$td->FILE => "c-read-errors.out", {$td->FILE => "c-read-errors.out",

View File

@ -0,0 +1,4 @@
checking bad14.pdf
PDF Version: 1.3
File is not encrypted
File is not linearized