aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-26 19:39:22 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commit1258054543d2956081c40b3166e9d5043deb6640 (patch)
tree16e862c888e780f84c45cfa218cdc4c56b80a418
parent901e3e4fbfb22566c44c5ab305c93f70c7b0aa49 (diff)
downloadqpdf-1258054543d2956081c40b3166e9d5043deb6640.tar.zst
QPDFJob: eliminate most access to QPDFJob members from ArgParser
All that's left now is input and output handling.
-rw-r--r--include/qpdf/auto_job_c_main.hh2
-rw-r--r--job.sums10
-rw-r--r--job.yml11
-rw-r--r--libqpdf/QPDFJob.cc2
-rw-r--r--libqpdf/QPDFJob_argv.cc34
-rw-r--r--libqpdf/QPDFJob_config.cc18
-rw-r--r--libqpdf/qpdf/auto_job_decl.hh2
-rw-r--r--libqpdf/qpdf/auto_job_init.hh4
-rw-r--r--libqpdf/qpdf/auto_job_schema.hh6
9 files changed, 39 insertions, 50 deletions
diff --git a/include/qpdf/auto_job_c_main.hh b/include/qpdf/auto_job_c_main.hh
index eb0f18be..3e6bdf69 100644
--- a/include/qpdf/auto_job_c_main.hh
+++ b/include/qpdf/auto_job_c_main.hh
@@ -9,7 +9,6 @@ QPDF_DLL Config& checkLinearization();
QPDF_DLL Config& coalesceContents();
QPDF_DLL Config& decrypt();
QPDF_DLL Config& deterministicId();
-QPDF_DLL Config& empty();
QPDF_DLL Config& externalizeInlineImages();
QPDF_DLL Config& filteredStreamData();
QPDF_DLL Config& flattenRotation();
@@ -32,7 +31,6 @@ QPDF_DLL Config& qdf();
QPDF_DLL Config& rawStreamData();
QPDF_DLL Config& recompressFlate();
QPDF_DLL Config& removePageLabels();
-QPDF_DLL Config& replaceInput();
QPDF_DLL Config& requiresPassword();
QPDF_DLL Config& showEncryption();
QPDF_DLL Config& showEncryptionKey();
diff --git a/job.sums b/job.sums
index 8ee1f969..1fcb243a 100644
--- a/job.sums
+++ b/job.sums
@@ -3,13 +3,13 @@ generate_auto_job 0eaf9d7724199a2a0a57732ea100f2eb55aaa8a1eccea99196190ff4b79fd6
include/qpdf/auto_job_c_att.hh ecc3f8f711b486b491e811176362a90c022eb225ff12157df3a10ca021be87b1
include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
include/qpdf/auto_job_c_enc.hh e2e1a163a7ffebbf8af169dc4a28ab00df3b8d229864bca7d203dde8b56f0864
-include/qpdf/auto_job_c_main.hh 7f7c0a4d8e640a2d24908af348f7b658ca81d3d8aa5346cf4327f6c1d4021119
+include/qpdf/auto_job_c_main.hh e7f23e24ddbd16b5e7cb720c7da9ef76b89c2e23b5c4eecc5d8e10f0c0d60f4e
include/qpdf/auto_job_c_pages.hh 79ee6e52a36fedfd0e6ca60bd926bc25a3e975ab6fa984a7e798a48791e8ba86
include/qpdf/auto_job_c_uo.hh 80404376f19fe57d67421ad0c5fb1755811758c73870df96f081f032b196deff
-job.yml c5dbc36d984cdb325b2baf1bd7a788fea58c7054e1da94b107283094da3d102c
-libqpdf/qpdf/auto_job_decl.hh 12b96d3201681d9805bc04767ed34f9cd2243e7a5f8930da968518aa22388f36
+job.yml be8cd97408ab17bc83970c1b512cac3d3d3b502afd40d71ec59f66054525e6b1
+libqpdf/qpdf/auto_job_decl.hh 9f79396ec459f191be4c5fe34cf88c265cf47355a1a945fa39169d1c94cf04f6
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
-libqpdf/qpdf/auto_job_init.hh c9f3c31d7c52f1a5159807763becbf15f039f9aa06e41a14f578ee407462ba94
-libqpdf/qpdf/auto_job_schema.hh c33c5953b589993334d49f71f0b6ce4b3a12af6e14a7a925be257de04c05f7d6
+libqpdf/qpdf/auto_job_init.hh 3b6323189480a7d782563c9d2b5bc29b8dcd19c6dcc89840b207e38cb503d3f1
+libqpdf/qpdf/auto_job_schema.hh 16bfde09f71765b0977af31d64b13632d2e6dda184bda79b2b9e45bc354a1677
manual/_ext/qpdf.py 855fe12de5af7a10bb24be6ecc4d5dff4c84ac58cf388a13be6bbb394346a67d
manual/cli.rst 68122ff8179c10df3fe6d577adde4973c346f7866ba9a511bab5a6e6f292a6f1
diff --git a/job.yml b/job.yml
index 1778dd18..171d1981 100644
--- a/job.yml
+++ b/job.yml
@@ -68,6 +68,8 @@ options:
- overlay
- pages
- underlay
+ - empty
+ - replace-input
positional: true
bare:
- add-attachment
@@ -240,6 +242,8 @@ options:
no-json:
- preserve-unreferenced-resources
- job-json-file
+ - empty
+ - replace-input
json:
# The structure of this section defines what the json input to
# QPDFJob looks like. If a key starts with underscore or has a value
@@ -249,16 +253,16 @@ json:
# a "schema" (as in JSON.hh) for the json input to QPDFJob. The
# leading underscore is removed.
_input:
+ # QXXXQ need to figure out how to specify input and output
_file:
_name: "input filename"
main.password:
password-file:
- empty:
+ _empty: "qxxxq empty"
_output:
_file:
_name: "output filename"
- replace-input:
- split-pages:
+ _replace-input: "qxxxq replace input"
_options:
qdf:
preserve-unreferenced:
@@ -280,6 +284,7 @@ json:
min-version:
force-version:
progress:
+ split-pages:
encrypt:
key-length: "key length: 48, 128, 256"
user-password: "user password"
diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc
index 025b7224..28f5f8c6 100644
--- a/libqpdf/QPDFJob.cc
+++ b/libqpdf/QPDFJob.cc
@@ -626,7 +626,7 @@ void
QPDFJob::checkConfiguration()
{
auto usage = [](char const* msg){
- throw std::runtime_error(msg);
+ throw QPDFJob::ConfigError(msg);
};
QPDFJob& o = *this; // QXXXQ
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index 8882a7d7..c4a7834a 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -35,7 +35,6 @@ namespace
void usage(std::string const& message);
void initOptionTables();
- void doFinalChecks();
QPDFArgParser ap;
QPDFJob& o;
@@ -67,8 +66,6 @@ ArgParser::initOptionTables()
{
# include <qpdf/auto_job_init.hh>
- this->ap.addFinalCheck(
- QPDFArgParser::bindBare(&ArgParser::doFinalChecks, this));
// add_help is defined in auto_job_help.hh
add_help(this->ap);
}
@@ -91,6 +88,18 @@ ArgParser::argPositional(char* arg)
}
void
+ArgParser::argEmpty()
+{
+ o.infilename = QUtil::make_shared_cstr("");
+}
+
+void
+ArgParser::argReplaceInput()
+{
+ o.replace_input = true;
+}
+
+void
ArgParser::argVersion()
{
auto whoami = this->ap.getProgname();
@@ -247,10 +256,6 @@ ArgParser::argEncPositional(char* arg)
void
ArgParser::argPages()
{
- if (! o.page_specs.empty())
- {
- usage("the --pages may only be specified one time");
- }
this->accumulated_args.clear();
this->c_pages = c_main->pages();
this->ap.selectOptionTable(O_PAGES);
@@ -480,19 +485,6 @@ ArgParser::parseOptions()
}
void
-ArgParser::doFinalChecks()
-{
- try
- {
- o.checkConfiguration();
- }
- catch (std::runtime_error& e)
- {
- usage(e.what());
- }
-}
-
-void
QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
{
if (progname_env == nullptr)
@@ -502,6 +494,8 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
QPDFArgParser qap(argc, argv, progname_env);
setMessagePrefix(qap.getProgname());
ArgParser ap(qap, config(), *this);
+ qap.addFinalCheck(
+ QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
ap.parseOptions();
}
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index 85aa3a3b..9eb03ae3 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -89,13 +89,6 @@ QPDFJob::Config::deterministicId()
}
QPDFJob::Config&
-QPDFJob::Config::empty()
-{
- o.infilename = QUtil::make_shared_cstr("");
- return *this;
-}
-
-QPDFJob::Config&
QPDFJob::Config::encryptionFilePassword(char const* parameter)
{
o.encryption_file_password = QUtil::make_shared_cstr(parameter);
@@ -376,13 +369,6 @@ QPDFJob::Config::removePageLabels()
}
QPDFJob::Config&
-QPDFJob::Config::replaceInput()
-{
- o.replace_input = true;
- return *this;
-}
-
-QPDFJob::Config&
QPDFJob::Config::requiresPassword()
{
o.check_requires_password = true;
@@ -860,6 +846,10 @@ QPDFJob::PagesConfig::PagesConfig(Config& c) :
std::shared_ptr<QPDFJob::PagesConfig>
QPDFJob::Config::pages()
{
+ if (! o.page_specs.empty())
+ {
+ usage("--pages may only be specified one time");
+ }
return std::shared_ptr<PagesConfig>(new PagesConfig(*this));
}
diff --git a/libqpdf/qpdf/auto_job_decl.hh b/libqpdf/qpdf/auto_job_decl.hh
index 1f868187..86b5b293 100644
--- a/libqpdf/qpdf/auto_job_decl.hh
+++ b/libqpdf/qpdf/auto_job_decl.hh
@@ -20,9 +20,11 @@ void argJobJsonHelp();
void argPositional(char*);
void argAddAttachment();
void argCopyAttachmentsFrom();
+void argEmpty();
void argEncrypt();
void argOverlay();
void argPages();
+void argReplaceInput();
void argUnderlay();
void argPagesPositional(char*);
void argPagesPassword(char *);
diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh
index 7fc044dc..b6750f43 100644
--- a/libqpdf/qpdf/auto_job_init.hh
+++ b/libqpdf/qpdf/auto_job_init.hh
@@ -37,7 +37,7 @@ this->ap.addBare("coalesce-contents", [this](){c_main->coalesceContents();});
this->ap.addBare("copy-attachments-from", b(&ArgParser::argCopyAttachmentsFrom));
this->ap.addBare("decrypt", [this](){c_main->decrypt();});
this->ap.addBare("deterministic-id", [this](){c_main->deterministicId();});
-this->ap.addBare("empty", [this](){c_main->empty();});
+this->ap.addBare("empty", b(&ArgParser::argEmpty));
this->ap.addBare("encrypt", b(&ArgParser::argEncrypt));
this->ap.addBare("externalize-inline-images", [this](){c_main->externalizeInlineImages();});
this->ap.addBare("filtered-stream-data", [this](){c_main->filteredStreamData();});
@@ -63,7 +63,7 @@ this->ap.addBare("qdf", [this](){c_main->qdf();});
this->ap.addBare("raw-stream-data", [this](){c_main->rawStreamData();});
this->ap.addBare("recompress-flate", [this](){c_main->recompressFlate();});
this->ap.addBare("remove-page-labels", [this](){c_main->removePageLabels();});
-this->ap.addBare("replace-input", [this](){c_main->replaceInput();});
+this->ap.addBare("replace-input", b(&ArgParser::argReplaceInput));
this->ap.addBare("requires-password", [this](){c_main->requiresPassword();});
this->ap.addBare("show-encryption", [this](){c_main->showEncryption();});
this->ap.addBare("show-encryption-key", [this](){c_main->showEncryptionKey();});
diff --git a/libqpdf/qpdf/auto_job_schema.hh b/libqpdf/qpdf/auto_job_schema.hh
index 376d0c19..bab83daa 100644
--- a/libqpdf/qpdf/auto_job_schema.hh
+++ b/libqpdf/qpdf/auto_job_schema.hh
@@ -5,14 +5,13 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({
"password": "specify password",
"passwordFile": "read password from a file"
},
- "empty": "empty input file"
+ "empty": "qxxxq empty"
},
"output": {
"file": {
"name": "output filename"
},
- "replaceInput": "replace input with output",
- "splitPages": "write pages to separate files",
+ "replaceInput": "qxxxq replace input",
"options": {
"qdf": "enable viewing PDF code in a text editor",
"preserveUnreferenced": "preserve unreferenced objects",
@@ -34,6 +33,7 @@ static constexpr char const* JOB_SCHEMA_DATA = R"({
"minVersion": "set minimum PDF version",
"forceVersion": "set output PDF version",
"progress": "show progress when writing",
+ "splitPages": "write pages to separate files",
"encrypt": {
"keyLength": "key length: 48, 128, 256",
"userPassword": "user password",