From 9a4ef8c95dd00d276d36d8e56f4cc6e1c75774fc Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 24 Feb 2018 23:50:32 -0500 Subject: Separate copyright notice from --version option --- qpdf/qpdf.cc | 20 +++++++++++++++----- qpdf/qtest/qpdf.test | 7 ++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 74285bcd..a23d640f 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -225,6 +225,9 @@ provided last take precedence.\n\ Basic Options\n\ -------------\n\ \n\ +--version show version of qpdf\n\ +--copyright show qpdf's copyright and license information\n\ +--help show command-line argument help\n\ --password=password specify a password for accessing encrypted files\n\ --verbose provide additional informational output\n\ --linearize generated a linearized (web optimized) file\n\ @@ -1188,16 +1191,23 @@ static void read_args_from_file(char const* filename, static void handle_help_version(int argc, char* argv[]) { + // Make sure the outpu looks right on an 80-column display. + if ((argc == 2) && ((strcmp(argv[1], "--version") == 0) || (strcmp(argv[1], "-version") == 0))) { - // make_dist looks for the line of code here that actually - // prints the version number, so read make_dist if you change - // anything other than the version number. Don't worry about - // the numbers. That's just a guide to 80 columns so that the - // help message looks right on an 80-column display. + std::cout + << whoami << " version " << QPDF::QPDFVersion() << std::endl + << "Run " << whoami << " --copyright to see copyright and license information." + << std::endl; + exit(0); + } + if ((argc == 2) && + ((strcmp(argv[1], "--copyright") == 0) || + (strcmp(argv[1], "-copyright") == 0))) + { // 1 2 3 4 5 6 7 8 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 std::cout diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 9e6c1a87..c6e39fb8 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -250,12 +250,17 @@ foreach my $d (@bug_tests) show_ntests(); # ---------- $td->notify("--- Library version ---"); -$n_tests += 2; +$n_tests += 3; $td->runtest("qpdf version", {$td->COMMAND => "qpdf --version"}, {$td->REGEXP => "qpdf version \\S+\n.*", $td->EXIT_STATUS => 0}, $td->NORMALIZE_NEWLINES); +$td->runtest("qpdf copyright contains version too", + {$td->COMMAND => "qpdf --copyright"}, + {$td->REGEXP => "(?s)qpdf version \\S+\n.*Apache.*", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); $td->runtest("C API: qpdf version", {$td->COMMAND => "qpdf-ctest --version"}, {$td->REGEXP => "qpdf-ctest version \\S+\n", -- cgit v1.2.3-54-g00ecf