From 12f1eb15ca3fed6310402847559a7c99d3c77847 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 2 Apr 2022 17:14:10 -0400 Subject: Programmatically apply new formatting to code Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done --- libqpdf/QPDFJob_argv.cc | 164 +++++++++++++++++------------------------------- 1 file changed, 58 insertions(+), 106 deletions(-) (limited to 'libqpdf/QPDFJob_argv.cc') diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index b1e3da1c..969af7db 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -2,32 +2,31 @@ // See "HOW TO ADD A COMMAND-LINE ARGUMENT" in README-maintainer. -#include -#include -#include #include #include +#include #include #include +#include +#include -#include -#include -#include +#include #include +#include #include -#include +#include +#include namespace { class ArgParser { public: - ArgParser(QPDFArgParser& ap, - std::shared_ptr c_main); + ArgParser(QPDFArgParser& ap, std::shared_ptr c_main); void parseOptions(); private: -# include +#include void usage(std::string const& message); void initOptionTables(); @@ -44,10 +43,10 @@ namespace bool gave_input; bool gave_output; }; -} +} // namespace -ArgParser::ArgParser(QPDFArgParser& ap, - std::shared_ptr c_main) : +ArgParser::ArgParser( + QPDFArgParser& ap, std::shared_ptr c_main) : ap(ap), c_main(c_main), pages_password(nullptr), @@ -62,33 +61,27 @@ ArgParser::ArgParser(QPDFArgParser& ap, void ArgParser::initOptionTables() { - -# include - this->ap.addFinalCheck([this](){c_main->checkConfiguration();}); +#include + this->ap.addFinalCheck([this]() { c_main->checkConfiguration(); }); // add_help is defined in auto_job_help.hh add_help(this->ap); // Special case: ignore -- at the top level. This undocumented // behavior is for backward compatibility; it was unintentionally // the case prior to 10.6, and some users were relying on it. this->ap.selectMainOptionTable(); - this->ap.addBare("--", [](){}); + this->ap.addBare("--", []() {}); } void ArgParser::argPositional(std::string const& arg) { - if (! this->gave_input) - { + if (!this->gave_input) { c_main->inputFile(arg); this->gave_input = true; - } - else if (! this->gave_output) - { + } else if (!this->gave_output) { c_main->outputFile(arg); this->gave_output = true; - } - else - { + } else { usage("unknown argument " + arg); } } @@ -111,10 +104,10 @@ void ArgParser::argVersion() { auto whoami = this->ap.getProgname(); - std::cout - << whoami << " version " << QPDF::QPDFVersion() << std::endl - << "Run " << whoami << " --copyright to see copyright and license information." - << std::endl; + std::cout << whoami << " version " << QPDF::QPDFVersion() << std::endl + << "Run " << whoami + << " --copyright to see copyright and license information." + << std::endl; } void @@ -174,10 +167,8 @@ ArgParser::argShowCrypto() auto crypto = QPDFCryptoProvider::getRegisteredImpls(); std::string default_crypto = QPDFCryptoProvider::getDefaultProvider(); std::cout << default_crypto << std::endl; - for (auto const& iter: crypto) - { - if (iter != default_crypto) - { + for (auto const& iter : crypto) { + if (iter != default_crypto) { std::cout << iter << std::endl; } } @@ -187,8 +178,7 @@ void ArgParser::argEncrypt() { this->accumulated_args.clear(); - if (this->ap.isCompleting() && this->ap.argsLeft() == 0) - { + if (this->ap.isCompleting() && this->ap.argsLeft() == 0) { this->ap.insertCompletion("user-password"); } this->ap.selectOptionTable(O_ENCRYPTION); @@ -199,16 +189,11 @@ ArgParser::argEncPositional(std::string const& arg) { this->accumulated_args.push_back(arg); size_t n_args = this->accumulated_args.size(); - if (n_args < 3) - { - if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) - { - if (n_args == 1) - { + if (n_args < 3) { + if (this->ap.isCompleting() && (this->ap.argsLeft() == 0)) { + if (n_args == 1) { this->ap.insertCompletion("owner-password"); - } - else if (n_args == 2) - { + } else if (n_args == 2) { this->ap.insertCompletion("40"); this->ap.insertCompletion("128"); this->ap.insertCompletion("256"); @@ -220,23 +205,16 @@ ArgParser::argEncPositional(std::string const& arg) std::string owner_password = this->accumulated_args.at(1); std::string len_str = this->accumulated_args.at(2); int keylen = 0; - if (len_str == "40") - { + if (len_str == "40") { keylen = 40; this->ap.selectOptionTable(O_40_BIT_ENCRYPTION); - } - else if (len_str == "128") - { + } else if (len_str == "128") { keylen = 128; this->ap.selectOptionTable(O_128_BIT_ENCRYPTION); - } - else if (len_str == "256") - { + } else if (len_str == "256") { keylen = 256; this->ap.selectOptionTable(O_256_BIT_ENCRYPTION); - } - else - { + } else { usage("encryption key length must be 40, 128, or 256"); } this->c_enc = c_main->encrypt(keylen, user_password, owner_password); @@ -253,13 +231,11 @@ ArgParser::argPages() void ArgParser::argPagesPassword(std::string const& parameter) { - if (this->pages_password) - { + if (this->pages_password) { QTC::TC("qpdf", "QPDFJob duplicated pages password"); usage("--password already specified for this file"); } - if (this->accumulated_args.size() != 1) - { + if (this->accumulated_args.size() != 1) { QTC::TC("qpdf", "QPDFJob misplaced pages password"); usage("in --pages, --password must immediately follow a file name"); } @@ -269,15 +245,11 @@ ArgParser::argPagesPassword(std::string const& parameter) void ArgParser::argPagesPositional(std::string const& arg) { - if (arg.empty()) - { - if (this->accumulated_args.empty()) - { + if (arg.empty()) { + if (this->accumulated_args.empty()) { return; } - } - else - { + } else { this->accumulated_args.push_back(arg); } @@ -285,8 +257,7 @@ ArgParser::argPagesPositional(std::string const& arg) char const* range_p = nullptr; size_t n_args = this->accumulated_args.size(); - if (n_args >= 2) - { + if (n_args >= 2) { // will be copied before accumulated_args is cleared range_p = this->accumulated_args.at(1).c_str(); } @@ -294,41 +265,29 @@ ArgParser::argPagesPositional(std::string const& arg) // See if the user omitted the range entirely, in which case we // assume "1-z". std::string next_file; - if (range_p == nullptr) - { - if (arg.empty()) - { + if (range_p == nullptr) { + if (arg.empty()) { // The filename or password was the last argument - QTC::TC("qpdf", "QPDFJob pages range omitted at end", - this->pages_password ? 0 : 1); - } - else - { + QTC::TC( + "qpdf", + "QPDFJob pages range omitted at end", + this->pages_password ? 0 : 1); + } else { // We need to accumulate some more arguments return; } - } - else - { - try - { + } else { + try { QUtil::parse_numrange(range_p, 0); - } - catch (std::runtime_error& e1) - { + } catch (std::runtime_error& e1) { // The range is invalid. Let's see if it's a file. - if (strcmp(range_p, ".") == 0) - { + if (strcmp(range_p, ".") == 0) { // "." means the input file. QTC::TC("qpdf", "QPDFJob pages range omitted with ."); - } - else if (QUtil::file_can_be_opened(range_p)) - { + } else if (QUtil::file_can_be_opened(range_p)) { QTC::TC("qpdf", "QPDFJob pages range omitted in middle"); // Yup, it's a file. - } - else - { + } else { // Give the range error usage(e1.what()); } @@ -340,8 +299,7 @@ ArgParser::argPagesPositional(std::string const& arg) this->c_pages->pageSpec(file, range, this->pages_password.get()); this->accumulated_args.clear(); this->pages_password = nullptr; - if (! next_file.empty()) - { + if (!next_file.empty()) { this->accumulated_args.push_back(next_file); } } @@ -461,27 +419,21 @@ ArgParser::usage(std::string const& message) void ArgParser::parseOptions() { - try - { + try { this->ap.parseArgs(); - } - catch (std::runtime_error& e) - { + } catch (std::runtime_error& e) { usage(e.what()); } } void -QPDFJob::initializeFromArgv(char const* const argv[], - char const* progname_env) +QPDFJob::initializeFromArgv(char const* const argv[], char const* progname_env) { - if (progname_env == nullptr) - { + if (progname_env == nullptr) { progname_env = "QPDF_EXECUTABLE"; } int argc = 0; - for (auto k = argv; *k; ++k) - { + for (auto k = argv; *k; ++k) { ++argc; } QPDFArgParser qap(argc, argv, progname_env); -- cgit v1.2.3-54-g00ecf