Commit 1258054543d2956081c40b3166e9d5043deb6640

Authored by Jay Berkenbilt
1 parent 901e3e4f

QPDFJob: eliminate most access to QPDFJob members from ArgParser

All that's left now is input and output handling.
include/qpdf/auto_job_c_main.hh
... ... @@ -9,7 +9,6 @@ QPDF_DLL Config& checkLinearization();
9 9 QPDF_DLL Config& coalesceContents();
10 10 QPDF_DLL Config& decrypt();
11 11 QPDF_DLL Config& deterministicId();
12   -QPDF_DLL Config& empty();
13 12 QPDF_DLL Config& externalizeInlineImages();
14 13 QPDF_DLL Config& filteredStreamData();
15 14 QPDF_DLL Config& flattenRotation();
... ... @@ -32,7 +31,6 @@ QPDF_DLL Config& qdf();
32 31 QPDF_DLL Config& rawStreamData();
33 32 QPDF_DLL Config& recompressFlate();
34 33 QPDF_DLL Config& removePageLabels();
35   -QPDF_DLL Config& replaceInput();
36 34 QPDF_DLL Config& requiresPassword();
37 35 QPDF_DLL Config& showEncryption();
38 36 QPDF_DLL Config& showEncryptionKey();
... ...
job.sums
... ... @@ -3,13 +3,13 @@ generate_auto_job 0eaf9d7724199a2a0a57732ea100f2eb55aaa8a1eccea99196190ff4b79fd6
3 3 include/qpdf/auto_job_c_att.hh ecc3f8f711b486b491e811176362a90c022eb225ff12157df3a10ca021be87b1
4 4 include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
5 5 include/qpdf/auto_job_c_enc.hh e2e1a163a7ffebbf8af169dc4a28ab00df3b8d229864bca7d203dde8b56f0864
6   -include/qpdf/auto_job_c_main.hh 7f7c0a4d8e640a2d24908af348f7b658ca81d3d8aa5346cf4327f6c1d4021119
  6 +include/qpdf/auto_job_c_main.hh e7f23e24ddbd16b5e7cb720c7da9ef76b89c2e23b5c4eecc5d8e10f0c0d60f4e
7 7 include/qpdf/auto_job_c_pages.hh 79ee6e52a36fedfd0e6ca60bd926bc25a3e975ab6fa984a7e798a48791e8ba86
8 8 include/qpdf/auto_job_c_uo.hh 80404376f19fe57d67421ad0c5fb1755811758c73870df96f081f032b196deff
9   -job.yml c5dbc36d984cdb325b2baf1bd7a788fea58c7054e1da94b107283094da3d102c
10   -libqpdf/qpdf/auto_job_decl.hh 12b96d3201681d9805bc04767ed34f9cd2243e7a5f8930da968518aa22388f36
  9 +job.yml be8cd97408ab17bc83970c1b512cac3d3d3b502afd40d71ec59f66054525e6b1
  10 +libqpdf/qpdf/auto_job_decl.hh 9f79396ec459f191be4c5fe34cf88c265cf47355a1a945fa39169d1c94cf04f6
11 11 libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
12   -libqpdf/qpdf/auto_job_init.hh c9f3c31d7c52f1a5159807763becbf15f039f9aa06e41a14f578ee407462ba94
13   -libqpdf/qpdf/auto_job_schema.hh c33c5953b589993334d49f71f0b6ce4b3a12af6e14a7a925be257de04c05f7d6
  12 +libqpdf/qpdf/auto_job_init.hh 3b6323189480a7d782563c9d2b5bc29b8dcd19c6dcc89840b207e38cb503d3f1
  13 +libqpdf/qpdf/auto_job_schema.hh 16bfde09f71765b0977af31d64b13632d2e6dda184bda79b2b9e45bc354a1677
14 14 manual/_ext/qpdf.py 855fe12de5af7a10bb24be6ecc4d5dff4c84ac58cf388a13be6bbb394346a67d
15 15 manual/cli.rst 68122ff8179c10df3fe6d577adde4973c346f7866ba9a511bab5a6e6f292a6f1
... ...
... ... @@ -68,6 +68,8 @@ options:
68 68 - overlay
69 69 - pages
70 70 - underlay
  71 + - empty
  72 + - replace-input
71 73 positional: true
72 74 bare:
73 75 - add-attachment
... ... @@ -240,6 +242,8 @@ options:
240 242 no-json:
241 243 - preserve-unreferenced-resources
242 244 - job-json-file
  245 + - empty
  246 + - replace-input
243 247 json:
244 248 # The structure of this section defines what the json input to
245 249 # QPDFJob looks like. If a key starts with underscore or has a value
... ... @@ -249,16 +253,16 @@ json:
249 253 # a "schema" (as in JSON.hh) for the json input to QPDFJob. The
250 254 # leading underscore is removed.
251 255 _input:
  256 + # QXXXQ need to figure out how to specify input and output
252 257 _file:
253 258 _name: "input filename"
254 259 main.password:
255 260 password-file:
256   - empty:
  261 + _empty: "qxxxq empty"
257 262 _output:
258 263 _file:
259 264 _name: "output filename"
260   - replace-input:
261   - split-pages:
  265 + _replace-input: "qxxxq replace input"
262 266 _options:
263 267 qdf:
264 268 preserve-unreferenced:
... ... @@ -280,6 +284,7 @@ json:
280 284 min-version:
281 285 force-version:
282 286 progress:
  287 + split-pages:
283 288 encrypt:
284 289 key-length: "key length: 48, 128, 256"
285 290 user-password: "user password"
... ...
libqpdf/QPDFJob.cc
... ... @@ -626,7 +626,7 @@ void
626 626 QPDFJob::checkConfiguration()
627 627 {
628 628 auto usage = [](char const* msg){
629   - throw std::runtime_error(msg);
  629 + throw QPDFJob::ConfigError(msg);
630 630 };
631 631  
632 632 QPDFJob& o = *this; // QXXXQ
... ...
libqpdf/QPDFJob_argv.cc
... ... @@ -35,7 +35,6 @@ namespace
35 35  
36 36 void usage(std::string const& message);
37 37 void initOptionTables();
38   - void doFinalChecks();
39 38  
40 39 QPDFArgParser ap;
41 40 QPDFJob& o;
... ... @@ -67,8 +66,6 @@ ArgParser::initOptionTables()
67 66 {
68 67  
69 68 # include <qpdf/auto_job_init.hh>
70   - this->ap.addFinalCheck(
71   - QPDFArgParser::bindBare(&ArgParser::doFinalChecks, this));
72 69 // add_help is defined in auto_job_help.hh
73 70 add_help(this->ap);
74 71 }
... ... @@ -91,6 +88,18 @@ ArgParser::argPositional(char* arg)
91 88 }
92 89  
93 90 void
  91 +ArgParser::argEmpty()
  92 +{
  93 + o.infilename = QUtil::make_shared_cstr("");
  94 +}
  95 +
  96 +void
  97 +ArgParser::argReplaceInput()
  98 +{
  99 + o.replace_input = true;
  100 +}
  101 +
  102 +void
94 103 ArgParser::argVersion()
95 104 {
96 105 auto whoami = this->ap.getProgname();
... ... @@ -247,10 +256,6 @@ ArgParser::argEncPositional(char* arg)
247 256 void
248 257 ArgParser::argPages()
249 258 {
250   - if (! o.page_specs.empty())
251   - {
252   - usage("the --pages may only be specified one time");
253   - }
254 259 this->accumulated_args.clear();
255 260 this->c_pages = c_main->pages();
256 261 this->ap.selectOptionTable(O_PAGES);
... ... @@ -480,19 +485,6 @@ ArgParser::parseOptions()
480 485 }
481 486  
482 487 void
483   -ArgParser::doFinalChecks()
484   -{
485   - try
486   - {
487   - o.checkConfiguration();
488   - }
489   - catch (std::runtime_error& e)
490   - {
491   - usage(e.what());
492   - }
493   -}
494   -
495   -void
496 488 QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
497 489 {
498 490 if (progname_env == nullptr)
... ... @@ -502,6 +494,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
502 494 QPDFArgParser qap(argc, argv, progname_env);
503 495 setMessagePrefix(qap.getProgname());
504 496 ArgParser ap(qap, config(), *this);
  497 + qap.addFinalCheck(
  498 + QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
505 499 ap.parseOptions();
506 500 }
507 501  
... ...
libqpdf/QPDFJob_config.cc
... ... @@ -89,13 +89,6 @@ QPDFJob::Config::deterministicId()
89 89 }
90 90  
91 91 QPDFJob::Config&
92   -QPDFJob::Config::empty()
93   -{
94   - o.infilename = QUtil::make_shared_cstr("");
95   - return *this;
96   -}
97   -
98   -QPDFJob::Config&
99 92 QPDFJob::Config::encryptionFilePassword(char const* parameter)
100 93 {
101 94 o.encryption_file_password = QUtil::make_shared_cstr(parameter);
... ... @@ -376,13 +369,6 @@ QPDFJob::Config::removePageLabels()
376 369 }
377 370  
378 371 QPDFJob::Config&
379   -QPDFJob::Config::replaceInput()
380   -{
381   - o.replace_input = true;
382   - return *this;
383   -}
384   -
385   -QPDFJob::Config&
386 372 QPDFJob::Config::requiresPassword()
387 373 {
388 374 o.check_requires_password = true;
... ... @@ -860,6 +846,10 @@ QPDFJob::PagesConfig::PagesConfig(Config&amp; c) :
860 846 std::shared_ptr<QPDFJob::PagesConfig>
861 847 QPDFJob::Config::pages()
862 848 {
  849 + if (! o.page_specs.empty())
  850 + {
  851 + usage("--pages may only be specified one time");
  852 + }
863 853 return std::shared_ptr<PagesConfig>(new PagesConfig(*this));
864 854 }
865 855  
... ...
libqpdf/qpdf/auto_job_decl.hh
... ... @@ -20,9 +20,11 @@ void argJobJsonHelp();
20 20 void argPositional(char*);
21 21 void argAddAttachment();
22 22 void argCopyAttachmentsFrom();
  23 +void argEmpty();
23 24 void argEncrypt();
24 25 void argOverlay();
25 26 void argPages();
  27 +void argReplaceInput();
26 28 void argUnderlay();
27 29 void argPagesPositional(char*);
28 30 void argPagesPassword(char *);
... ...
libqpdf/qpdf/auto_job_init.hh
... ... @@ -37,7 +37,7 @@ this-&gt;ap.addBare(&quot;coalesce-contents&quot;, [this](){c_main-&gt;coalesceContents();});
37 37 this->ap.addBare("copy-attachments-from", b(&ArgParser::argCopyAttachmentsFrom));
38 38 this->ap.addBare("decrypt", [this](){c_main->decrypt();});
39 39 this->ap.addBare("deterministic-id", [this](){c_main->deterministicId();});
40   -this->ap.addBare("empty", [this](){c_main->empty();});
  40 +this->ap.addBare("empty", b(&ArgParser::argEmpty));
41 41 this->ap.addBare("encrypt", b(&ArgParser::argEncrypt));
42 42 this->ap.addBare("externalize-inline-images", [this](){c_main->externalizeInlineImages();});
43 43 this->ap.addBare("filtered-stream-data", [this](){c_main->filteredStreamData();});
... ... @@ -63,7 +63,7 @@ this-&gt;ap.addBare(&quot;qdf&quot;, [this](){c_main-&gt;qdf();});
63 63 this->ap.addBare("raw-stream-data", [this](){c_main->rawStreamData();});
64 64 this->ap.addBare("recompress-flate", [this](){c_main->recompressFlate();});
65 65 this->ap.addBare("remove-page-labels", [this](){c_main->removePageLabels();});
66   -this->ap.addBare("replace-input", [this](){c_main->replaceInput();});
  66 +this->ap.addBare("replace-input", b(&ArgParser::argReplaceInput));
67 67 this->ap.addBare("requires-password", [this](){c_main->requiresPassword();});
68 68 this->ap.addBare("show-encryption", [this](){c_main->showEncryption();});
69 69 this->ap.addBare("show-encryption-key", [this](){c_main->showEncryptionKey();});
... ...
libqpdf/qpdf/auto_job_schema.hh
... ... @@ -5,14 +5,13 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
5 5 "password": "specify password",
6 6 "passwordFile": "read password from a file"
7 7 },
8   - "empty": "empty input file"
  8 + "empty": "qxxxq empty"
9 9 },
10 10 "output": {
11 11 "file": {
12 12 "name": "output filename"
13 13 },
14   - "replaceInput": "replace input with output",
15   - "splitPages": "write pages to separate files",
  14 + "replaceInput": "qxxxq replace input",
16 15 "options": {
17 16 "qdf": "enable viewing PDF code in a text editor",
18 17 "preserveUnreferenced": "preserve unreferenced objects",
... ... @@ -34,6 +33,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R&quot;({
34 33 "minVersion": "set minimum PDF version",
35 34 "forceVersion": "set output PDF version",
36 35 "progress": "show progress when writing",
  36 + "splitPages": "write pages to separate files",
37 37 "encrypt": {
38 38 "keyLength": "key length: 48, 128, 256",
39 39 "userPassword": "user password",
... ...