mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add --no-warn option to suppress warnings (fixes #232)
This commit is contained in:
parent
60fe8061cb
commit
fb1e29476c
@ -1,5 +1,9 @@
|
||||
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
|
||||
use of memory at a very slight performance cost. The old
|
||||
implementation could cause memory usage to go out of control for
|
||||
|
27
qpdf/qpdf.cc
27
qpdf/qpdf.cc
@ -61,6 +61,7 @@ struct Options
|
||||
split_pages(0),
|
||||
verbose(false),
|
||||
progress(false),
|
||||
suppress_warnings(false),
|
||||
copy_encryption(false),
|
||||
encryption_file(0),
|
||||
encryption_file_password(0),
|
||||
@ -125,6 +126,7 @@ struct Options
|
||||
int split_pages;
|
||||
bool verbose;
|
||||
bool progress;
|
||||
bool suppress_warnings;
|
||||
bool copy_encryption;
|
||||
char const* encryption_file;
|
||||
char const* encryption_file_password;
|
||||
@ -262,6 +264,7 @@ Basic Options\n\
|
||||
--password=password specify a password for accessing encrypted files\n\
|
||||
--verbose provide additional informational output\n\
|
||||
--progress give progress indicators while writing output\n\
|
||||
--no-warn suppress warnings\n\
|
||||
--linearize generated a linearized (web optimized) file\n\
|
||||
--copy-encryption=file copy encryption parameters from specified file\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\
|
||||
\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\
|
||||
errors, qpdf exits with a status of 3.\n\
|
||||
if any errors occurred. If there were warnings but not errors, qpdf\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";
|
||||
|
||||
void usage(std::string const& msg)
|
||||
@ -1676,6 +1680,10 @@ static void parse_options(int argc, char* argv[], Options& o)
|
||||
{
|
||||
o.progress = true;
|
||||
}
|
||||
else if (strcmp(arg, "no-warn") == 0)
|
||||
{
|
||||
o.suppress_warnings = true;
|
||||
}
|
||||
else if (strcmp(arg, "deterministic-id") == 0)
|
||||
{
|
||||
o.deterministic_id = true;
|
||||
@ -1832,6 +1840,10 @@ static void set_qpdf_options(QPDF& pdf, Options& o)
|
||||
{
|
||||
pdf.setPasswordIsHexKey(true);
|
||||
}
|
||||
if (o.suppress_warnings)
|
||||
{
|
||||
pdf.setSuppressWarnings(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_check(QPDF& pdf, Options& o, int& exit_code)
|
||||
@ -2607,9 +2619,14 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
if (! pdf.getWarnings().empty())
|
||||
{
|
||||
std::cerr << whoami << ": operation succeeded with warnings;"
|
||||
<< " resulting file may have some problems" << std::endl;
|
||||
exit(EXIT_WARNING);
|
||||
if (! o.suppress_warnings)
|
||||
{
|
||||
std::cerr << whoami << ": operation succeeded with warnings;"
|
||||
<< " resulting file may have some problems"
|
||||
<< std::endl;
|
||||
}
|
||||
// Still exit with warning code even if warnings were suppressed.
|
||||
exit(EXIT_WARNING);
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
@ -1528,7 +1528,7 @@ my @badfiles = ("not a PDF file", # 1
|
||||
"bad dictionary key", # 36
|
||||
);
|
||||
|
||||
$n_tests += @badfiles + 3;
|
||||
$n_tests += @badfiles + 5;
|
||||
|
||||
# Test 6 contains errors in the free table consistency, but we no
|
||||
# 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->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->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"},
|
||||
{$td->FILE => "c-read-errors.out",
|
||||
|
4
qpdf/qtest/qpdf/bad14-check-no-warn.out
Normal file
4
qpdf/qtest/qpdf/bad14-check-no-warn.out
Normal file
@ -0,0 +1,4 @@
|
||||
checking bad14.pdf
|
||||
PDF Version: 1.3
|
||||
File is not encrypted
|
||||
File is not linearized
|
Loading…
Reference in New Issue
Block a user