Commit 79187e585a7c1ac26fe8b2a347a9546885a973e5
1 parent
160e869d
QPDFJob: begin configuration API with verbose
Showing
4 changed files
with
49 additions
and
9 deletions
include/qpdf/QPDFJob.hh
| @@ -97,6 +97,30 @@ class QPDFJob | @@ -97,6 +97,30 @@ class QPDFJob | ||
| 97 | QPDF_DLL | 97 | QPDF_DLL |
| 98 | bool createsOutput() const; | 98 | bool createsOutput() const; |
| 99 | 99 | ||
| 100 | + // CONFIGURATION | ||
| 101 | + // (implemented in QPDFJob_config.cc) | ||
| 102 | + | ||
| 103 | + // Configuration is performed by calling methods XXX QXXXQ document | ||
| 104 | + class Config | ||
| 105 | + { | ||
| 106 | + friend class QPDFJob; | ||
| 107 | + public: | ||
| 108 | + QPDF_DLL | ||
| 109 | + Config& verbose(bool); | ||
| 110 | + | ||
| 111 | + private: | ||
| 112 | + Config() = delete; | ||
| 113 | + Config(QPDFJob& job) : | ||
| 114 | + o(job) | ||
| 115 | + { | ||
| 116 | + } | ||
| 117 | + QPDFJob& o; | ||
| 118 | + }; | ||
| 119 | + friend class Config; | ||
| 120 | + | ||
| 121 | + QPDF_DLL | ||
| 122 | + Config config(); | ||
| 123 | + | ||
| 100 | // QXXXQ set options -- implemented in QPDFJob_options.cc | 124 | // QXXXQ set options -- implemented in QPDFJob_options.cc |
| 101 | 125 | ||
| 102 | // QXXXQ these will not be in the final interface | 126 | // QXXXQ these will not be in the final interface |
| @@ -220,7 +244,6 @@ class QPDFJob | @@ -220,7 +244,6 @@ class QPDFJob | ||
| 220 | bool linearize; | 244 | bool linearize; |
| 221 | bool decrypt; | 245 | bool decrypt; |
| 222 | int split_pages; | 246 | int split_pages; |
| 223 | - bool verbose; | ||
| 224 | bool progress; | 247 | bool progress; |
| 225 | bool suppress_warnings; | 248 | bool suppress_warnings; |
| 226 | bool warnings_exit_zero; | 249 | bool warnings_exit_zero; |
| @@ -410,6 +433,7 @@ class QPDFJob | @@ -410,6 +433,7 @@ class QPDFJob | ||
| 410 | std::ostream* cout; | 433 | std::ostream* cout; |
| 411 | std::ostream* cerr; | 434 | std::ostream* cerr; |
| 412 | unsigned long encryption_status; | 435 | unsigned long encryption_status; |
| 436 | + bool verbose; | ||
| 413 | }; | 437 | }; |
| 414 | std::shared_ptr<Members> m; | 438 | std::shared_ptr<Members> m; |
| 415 | }; | 439 | }; |
libqpdf/QPDFJob.cc
| @@ -324,7 +324,8 @@ QPDFJob::Members::Members() : | @@ -324,7 +324,8 @@ QPDFJob::Members::Members() : | ||
| 324 | warnings(false), | 324 | warnings(false), |
| 325 | cout(&std::cout), | 325 | cout(&std::cout), |
| 326 | cerr(&std::cerr), | 326 | cerr(&std::cerr), |
| 327 | - encryption_status(0) | 327 | + encryption_status(0), |
| 328 | + verbose(false) | ||
| 328 | { | 329 | { |
| 329 | } | 330 | } |
| 330 | 331 | ||
| @@ -333,7 +334,6 @@ QPDFJob::QPDFJob() : | @@ -333,7 +334,6 @@ QPDFJob::QPDFJob() : | ||
| 333 | linearize(false), | 334 | linearize(false), |
| 334 | decrypt(false), | 335 | decrypt(false), |
| 335 | split_pages(0), | 336 | split_pages(0), |
| 336 | - verbose(false), | ||
| 337 | progress(false), | 337 | progress(false), |
| 338 | suppress_warnings(false), | 338 | suppress_warnings(false), |
| 339 | warnings_exit_zero(false), | 339 | warnings_exit_zero(false), |
| @@ -447,12 +447,18 @@ void | @@ -447,12 +447,18 @@ void | ||
| 447 | QPDFJob::doIfVerbose( | 447 | QPDFJob::doIfVerbose( |
| 448 | std::function<void(std::ostream&, std::string const& prefix)> fn) | 448 | std::function<void(std::ostream&, std::string const& prefix)> fn) |
| 449 | { | 449 | { |
| 450 | - if (this->verbose && (this->m->cout != nullptr)) | 450 | + if (this->m->verbose && (this->m->cout != nullptr)) |
| 451 | { | 451 | { |
| 452 | fn(*(this->m->cout), this->m->message_prefix); | 452 | fn(*(this->m->cout), this->m->message_prefix); |
| 453 | } | 453 | } |
| 454 | } | 454 | } |
| 455 | 455 | ||
| 456 | +QPDFJob::Config | ||
| 457 | +QPDFJob::config() | ||
| 458 | +{ | ||
| 459 | + return Config(*this); | ||
| 460 | +} | ||
| 461 | + | ||
| 456 | void | 462 | void |
| 457 | QPDFJob::run() | 463 | QPDFJob::run() |
| 458 | { | 464 | { |
| @@ -596,7 +602,7 @@ QPDFJob::checkConfiguration() | @@ -596,7 +602,7 @@ QPDFJob::checkConfiguration() | ||
| 596 | usage("--split-pages may not be used when" | 602 | usage("--split-pages may not be used when" |
| 597 | " writing to standard output"); | 603 | " writing to standard output"); |
| 598 | } | 604 | } |
| 599 | - if (o.verbose) | 605 | + if (this->m->verbose) |
| 600 | { | 606 | { |
| 601 | usage("--verbose may not be used when" | 607 | usage("--verbose may not be used when" |
| 602 | " writing to standard output"); | 608 | " writing to standard output"); |
libqpdf/QPDFJob_argv.cc
| @@ -26,7 +26,7 @@ namespace | @@ -26,7 +26,7 @@ namespace | ||
| 26 | class ArgParser | 26 | class ArgParser |
| 27 | { | 27 | { |
| 28 | public: | 28 | public: |
| 29 | - ArgParser(QPDFArgParser& ap, QPDFJob& o); | 29 | + ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o); |
| 30 | void parseOptions(); | 30 | void parseOptions(); |
| 31 | 31 | ||
| 32 | private: | 32 | private: |
| @@ -42,14 +42,16 @@ namespace | @@ -42,14 +42,16 @@ namespace | ||
| 42 | 42 | ||
| 43 | QPDFArgParser ap; | 43 | QPDFArgParser ap; |
| 44 | QPDFJob& o; | 44 | QPDFJob& o; |
| 45 | + QPDFJob::Config& jc; | ||
| 45 | std::vector<char*> accumulated_args; // points to member in ap | 46 | std::vector<char*> accumulated_args; // points to member in ap |
| 46 | char* pages_password; | 47 | char* pages_password; |
| 47 | }; | 48 | }; |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | -ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob& o) : | 51 | +ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o) : |
| 51 | ap(ap), | 52 | ap(ap), |
| 52 | o(o), | 53 | o(o), |
| 54 | + jc(jc), | ||
| 53 | pages_password(nullptr) | 55 | pages_password(nullptr) |
| 54 | { | 56 | { |
| 55 | initOptionTables(); | 57 | initOptionTables(); |
| @@ -803,7 +805,7 @@ void | @@ -803,7 +805,7 @@ void | ||
| 803 | ArgParser::argVerbose() | 805 | ArgParser::argVerbose() |
| 804 | { | 806 | { |
| 805 | // QXXXQ @TRIVIAL | 807 | // QXXXQ @TRIVIAL |
| 806 | - o.verbose = true; | 808 | + jc.verbose(true); |
| 807 | } | 809 | } |
| 808 | 810 | ||
| 809 | void | 811 | void |
| @@ -1558,7 +1560,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | @@ -1558,7 +1560,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) | ||
| 1558 | } | 1560 | } |
| 1559 | QPDFArgParser qap(argc, argv, progname_env); | 1561 | QPDFArgParser qap(argc, argv, progname_env); |
| 1560 | setMessagePrefix(qap.getProgname()); | 1562 | setMessagePrefix(qap.getProgname()); |
| 1561 | - ArgParser ap(qap, *this); | 1563 | + auto jc = config(); |
| 1564 | + ArgParser ap(qap, jc, *this); | ||
| 1562 | ap.parseOptions(); | 1565 | ap.parseOptions(); |
| 1563 | } | 1566 | } |
| 1564 | 1567 |