From 21c897aad0c3edc6e47e88754ab279e0f076cd06 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 25 Jan 2022 11:07:53 -0500 Subject: QPDFJob: convert a flag in other than the main table --- libqpdf/QPDFJob.cc | 4 +- libqpdf/QPDFJob_argv.cc | 33 +++++------ libqpdf/QPDFJob_config.cc | 43 ++++++++++++++ libqpdf/qpdf/auto_job_decl.hh | 1 - libqpdf/qpdf/auto_job_init.hh | 132 +++++++++++++++++++++--------------------- 5 files changed, 125 insertions(+), 88 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 487201f8..ca479812 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -453,10 +453,10 @@ QPDFJob::doIfVerbose( } } -QPDFJob::Config +std::shared_ptr QPDFJob::config() { - return Config(*this); + return std::shared_ptr(new Config(*this)); } void diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc index 1adb34ee..9a78018e 100644 --- a/libqpdf/QPDFJob_argv.cc +++ b/libqpdf/QPDFJob_argv.cc @@ -26,7 +26,8 @@ namespace class ArgParser { public: - ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o); + ArgParser(QPDFArgParser& ap, + std::shared_ptr c_main, QPDFJob& o); void parseOptions(); private: @@ -42,16 +43,18 @@ namespace QPDFArgParser ap; QPDFJob& o; - QPDFJob::Config& jc; + std::shared_ptr c_main; + std::shared_ptr c_copy_att; std::vector accumulated_args; // points to member in ap char* pages_password; }; } -ArgParser::ArgParser(QPDFArgParser& ap, QPDFJob::Config& jc, QPDFJob& o) : +ArgParser::ArgParser(QPDFArgParser& ap, + std::shared_ptr c_main, QPDFJob& o) : ap(ap), o(o), - jc(jc), + c_main(c_main), pages_password(nullptr) { initOptionTables(); @@ -451,7 +454,7 @@ ArgParser::argAddAttachment() void ArgParser::argCopyAttachmentsFrom() { - o.attachments_to_copy.push_back(QPDFJob::CopyAttachmentFrom()); + this->c_copy_att = c_main->copyAttachmentsFrom(); this->ap.selectOptionTable(O_COPY_ATTACHMENT); } @@ -888,28 +891,21 @@ ArgParser::argEndAttachment() void ArgParser::argCopyAttPositional(char* arg) { - o.attachments_to_copy.back().path = arg; -} - -void -ArgParser::argCopyAttPrefix(char* parameter) -{ - o.attachments_to_copy.back().prefix = parameter; + c_copy_att->filename(arg); } void ArgParser::argCopyAttPassword(char* parameter) { - o.attachments_to_copy.back().password = parameter; + // QXXXQ @TRIVIAL + c_copy_att->password(parameter); } void ArgParser::argEndCopyAttachment() { - if (o.attachments_to_copy.back().path.empty()) - { - usage("copy attachments: no path specified"); - } + c_copy_att->end(); + c_copy_att = nullptr; } void @@ -1072,8 +1068,7 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env) } QPDFArgParser qap(argc, argv, progname_env); setMessagePrefix(qap.getProgname()); - auto jc = config(); - ArgParser ap(qap, jc, *this); + ArgParser ap(qap, config(), *this); ap.parseOptions(); } diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc index ac038aa9..923d9302 100644 --- a/libqpdf/QPDFJob_config.cc +++ b/libqpdf/QPDFJob_config.cc @@ -489,3 +489,46 @@ QPDFJob::Config::withImages() o.show_page_images = true; return *this; } + +std::shared_ptr +QPDFJob::Config::copyAttachmentsFrom() +{ + return std::shared_ptr(new CopyAttConfig(*this)); +} + +QPDFJob::CopyAttConfig::CopyAttConfig(Config& c) : + config(c) +{ +} + +QPDFJob::CopyAttConfig& +QPDFJob::CopyAttConfig::filename(char const* parameter) +{ + this->caf.path = parameter; + return *this; +} + +QPDFJob::CopyAttConfig& +QPDFJob::CopyAttConfig::prefix(char const* parameter) +{ + this->caf.prefix = parameter; + return *this; +} + +QPDFJob::CopyAttConfig& +QPDFJob::CopyAttConfig::password(char const* parameter) +{ + this->caf.password = parameter; + return *this; +} + +QPDFJob::Config& +QPDFJob::CopyAttConfig::end() +{ + if (this->caf.path.empty()) + { + throw std::runtime_error("copy attachments: no path specified"); + } + this->config.o.attachments_to_copy.push_back(this->caf); + return this->config; +} diff --git a/libqpdf/qpdf/auto_job_decl.hh b/libqpdf/qpdf/auto_job_decl.hh index b63251b9..8718c3e4 100644 --- a/libqpdf/qpdf/auto_job_decl.hh +++ b/libqpdf/qpdf/auto_job_decl.hh @@ -75,6 +75,5 @@ void argAttMimetype(char *); void argAttDescription(char *); void argEndAttachment(); void argCopyAttPositional(char*); -void argCopyAttPrefix(char *); void argCopyAttPassword(char *); void argEndCopyAttachment(); diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh index d1630014..cba6347d 100644 --- a/libqpdf/qpdf/auto_job_init.hh +++ b/libqpdf/qpdf/auto_job_init.hh @@ -30,82 +30,82 @@ this->ap.addBare("job-json-help", b(&ArgParser::argJobJsonHelp)); this->ap.selectMainOptionTable(); this->ap.addPositional(p(&ArgParser::argPositional)); this->ap.addBare("add-attachment", b(&ArgParser::argAddAttachment)); -this->ap.addBare("allow-weak-crypto", [this](){jc.allowWeakCrypto();}); -this->ap.addBare("check", [this](){jc.check();}); -this->ap.addBare("check-linearization", [this](){jc.checkLinearization();}); -this->ap.addBare("coalesce-contents", [this](){jc.coalesceContents();}); +this->ap.addBare("allow-weak-crypto", [this](){c_main->allowWeakCrypto();}); +this->ap.addBare("check", [this](){c_main->check();}); +this->ap.addBare("check-linearization", [this](){c_main->checkLinearization();}); +this->ap.addBare("coalesce-contents", [this](){c_main->coalesceContents();}); this->ap.addBare("copy-attachments-from", b(&ArgParser::argCopyAttachmentsFrom)); -this->ap.addBare("decrypt", [this](){jc.decrypt();}); -this->ap.addBare("deterministic-id", [this](){jc.deterministicId();}); -this->ap.addBare("empty", [this](){jc.empty();}); +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("encrypt", b(&ArgParser::argEncrypt)); -this->ap.addBare("externalize-inline-images", [this](){jc.externalizeInlineImages();}); -this->ap.addBare("filtered-stream-data", [this](){jc.filteredStreamData();}); -this->ap.addBare("flatten-rotation", [this](){jc.flattenRotation();}); -this->ap.addBare("generate-appearances", [this](){jc.generateAppearances();}); -this->ap.addBare("ignore-xref-streams", [this](){jc.ignoreXrefStreams();}); -this->ap.addBare("is-encrypted", [this](){jc.isEncrypted();}); -this->ap.addBare("json", [this](){jc.json();}); -this->ap.addBare("keep-inline-images", [this](){jc.keepInlineImages();}); -this->ap.addBare("linearize", [this](){jc.linearize();}); -this->ap.addBare("list-attachments", [this](){jc.listAttachments();}); -this->ap.addBare("newline-before-endstream", [this](){jc.newlineBeforeEndstream();}); -this->ap.addBare("no-original-object-ids", [this](){jc.noOriginalObjectIds();}); -this->ap.addBare("no-warn", [this](){jc.noWarn();}); -this->ap.addBare("optimize-images", [this](){jc.optimizeImages();}); +this->ap.addBare("externalize-inline-images", [this](){c_main->externalizeInlineImages();}); +this->ap.addBare("filtered-stream-data", [this](){c_main->filteredStreamData();}); +this->ap.addBare("flatten-rotation", [this](){c_main->flattenRotation();}); +this->ap.addBare("generate-appearances", [this](){c_main->generateAppearances();}); +this->ap.addBare("ignore-xref-streams", [this](){c_main->ignoreXrefStreams();}); +this->ap.addBare("is-encrypted", [this](){c_main->isEncrypted();}); +this->ap.addBare("json", [this](){c_main->json();}); +this->ap.addBare("keep-inline-images", [this](){c_main->keepInlineImages();}); +this->ap.addBare("linearize", [this](){c_main->linearize();}); +this->ap.addBare("list-attachments", [this](){c_main->listAttachments();}); +this->ap.addBare("newline-before-endstream", [this](){c_main->newlineBeforeEndstream();}); +this->ap.addBare("no-original-object-ids", [this](){c_main->noOriginalObjectIds();}); +this->ap.addBare("no-warn", [this](){c_main->noWarn();}); +this->ap.addBare("optimize-images", [this](){c_main->optimizeImages();}); this->ap.addBare("overlay", b(&ArgParser::argOverlay)); this->ap.addBare("pages", b(&ArgParser::argPages)); -this->ap.addBare("password-is-hex-key", [this](){jc.passwordIsHexKey();}); -this->ap.addBare("preserve-unreferenced", [this](){jc.preserveUnreferenced();}); -this->ap.addBare("preserve-unreferenced-resources", [this](){jc.preserveUnreferencedResources();}); -this->ap.addBare("progress", [this](){jc.progress();}); -this->ap.addBare("qdf", [this](){jc.qdf();}); -this->ap.addBare("raw-stream-data", [this](){jc.rawStreamData();}); -this->ap.addBare("recompress-flate", [this](){jc.recompressFlate();}); -this->ap.addBare("remove-page-labels", [this](){jc.removePageLabels();}); -this->ap.addBare("replace-input", [this](){jc.replaceInput();}); -this->ap.addBare("requires-password", [this](){jc.requiresPassword();}); -this->ap.addBare("show-encryption", [this](){jc.showEncryption();}); -this->ap.addBare("show-encryption-key", [this](){jc.showEncryptionKey();}); -this->ap.addBare("show-linearization", [this](){jc.showLinearization();}); -this->ap.addBare("show-npages", [this](){jc.showNpages();}); -this->ap.addBare("show-pages", [this](){jc.showPages();}); -this->ap.addBare("show-xref", [this](){jc.showXref();}); -this->ap.addBare("static-aes-iv", [this](){jc.staticAesIv();}); -this->ap.addBare("static-id", [this](){jc.staticId();}); -this->ap.addBare("suppress-password-recovery", [this](){jc.suppressPasswordRecovery();}); -this->ap.addBare("suppress-recovery", [this](){jc.suppressRecovery();}); +this->ap.addBare("password-is-hex-key", [this](){c_main->passwordIsHexKey();}); +this->ap.addBare("preserve-unreferenced", [this](){c_main->preserveUnreferenced();}); +this->ap.addBare("preserve-unreferenced-resources", [this](){c_main->preserveUnreferencedResources();}); +this->ap.addBare("progress", [this](){c_main->progress();}); +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("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();}); +this->ap.addBare("show-linearization", [this](){c_main->showLinearization();}); +this->ap.addBare("show-npages", [this](){c_main->showNpages();}); +this->ap.addBare("show-pages", [this](){c_main->showPages();}); +this->ap.addBare("show-xref", [this](){c_main->showXref();}); +this->ap.addBare("static-aes-iv", [this](){c_main->staticAesIv();}); +this->ap.addBare("static-id", [this](){c_main->staticId();}); +this->ap.addBare("suppress-password-recovery", [this](){c_main->suppressPasswordRecovery();}); +this->ap.addBare("suppress-recovery", [this](){c_main->suppressRecovery();}); this->ap.addBare("underlay", b(&ArgParser::argUnderlay)); -this->ap.addBare("verbose", [this](){jc.verbose();}); -this->ap.addBare("warning-exit-0", [this](){jc.warningExit0();}); -this->ap.addBare("with-images", [this](){jc.withImages();}); -this->ap.addOptionalParameter("collate", [this](char *x){jc.collate(x);}); -this->ap.addOptionalParameter("split-pages", [this](char *x){jc.splitPages(x);}); -this->ap.addRequiredParameter("compression-level", [this](char *x){jc.compressionLevel(x);}, "level"); -this->ap.addRequiredParameter("copy-encryption", [this](char *x){jc.copyEncryption(x);}, "file"); -this->ap.addRequiredParameter("encryption-file-password", [this](char *x){jc.encryptionFilePassword(x);}, "password"); -this->ap.addRequiredParameter("force-version", [this](char *x){jc.forceVersion(x);}, "version"); -this->ap.addRequiredParameter("ii-min-bytes", [this](char *x){jc.iiMinBytes(x);}, "minimum"); +this->ap.addBare("verbose", [this](){c_main->verbose();}); +this->ap.addBare("warning-exit-0", [this](){c_main->warningExit0();}); +this->ap.addBare("with-images", [this](){c_main->withImages();}); +this->ap.addOptionalParameter("collate", [this](char *x){c_main->collate(x);}); +this->ap.addOptionalParameter("split-pages", [this](char *x){c_main->splitPages(x);}); +this->ap.addRequiredParameter("compression-level", [this](char *x){c_main->compressionLevel(x);}, "level"); +this->ap.addRequiredParameter("copy-encryption", [this](char *x){c_main->copyEncryption(x);}, "file"); +this->ap.addRequiredParameter("encryption-file-password", [this](char *x){c_main->encryptionFilePassword(x);}, "password"); +this->ap.addRequiredParameter("force-version", [this](char *x){c_main->forceVersion(x);}, "version"); +this->ap.addRequiredParameter("ii-min-bytes", [this](char *x){c_main->iiMinBytes(x);}, "minimum"); this->ap.addRequiredParameter("job-json-file", p(&ArgParser::argJobJsonFile), "file"); -this->ap.addRequiredParameter("json-object", [this](char *x){jc.jsonObject(x);}, "trailer"); -this->ap.addRequiredParameter("keep-files-open-threshold", [this](char *x){jc.keepFilesOpenThreshold(x);}, "count"); -this->ap.addRequiredParameter("linearize-pass1", [this](char *x){jc.linearizePass1(x);}, "filename"); -this->ap.addRequiredParameter("min-version", [this](char *x){jc.minVersion(x);}, "version"); -this->ap.addRequiredParameter("oi-min-area", [this](char *x){jc.oiMinArea(x);}, "minimum"); -this->ap.addRequiredParameter("oi-min-height", [this](char *x){jc.oiMinHeight(x);}, "minimum"); -this->ap.addRequiredParameter("oi-min-width", [this](char *x){jc.oiMinWidth(x);}, "minimum"); +this->ap.addRequiredParameter("json-object", [this](char *x){c_main->jsonObject(x);}, "trailer"); +this->ap.addRequiredParameter("keep-files-open-threshold", [this](char *x){c_main->keepFilesOpenThreshold(x);}, "count"); +this->ap.addRequiredParameter("linearize-pass1", [this](char *x){c_main->linearizePass1(x);}, "filename"); +this->ap.addRequiredParameter("min-version", [this](char *x){c_main->minVersion(x);}, "version"); +this->ap.addRequiredParameter("oi-min-area", [this](char *x){c_main->oiMinArea(x);}, "minimum"); +this->ap.addRequiredParameter("oi-min-height", [this](char *x){c_main->oiMinHeight(x);}, "minimum"); +this->ap.addRequiredParameter("oi-min-width", [this](char *x){c_main->oiMinWidth(x);}, "minimum"); this->ap.addRequiredParameter("password", p(&ArgParser::argPassword), "password"); this->ap.addRequiredParameter("password-file", p(&ArgParser::argPasswordFile), "password"); -this->ap.addRequiredParameter("remove-attachment", [this](char *x){jc.removeAttachment(x);}, "attachment"); +this->ap.addRequiredParameter("remove-attachment", [this](char *x){c_main->removeAttachment(x);}, "attachment"); this->ap.addRequiredParameter("rotate", p(&ArgParser::argRotate), "[+|-]angle"); -this->ap.addRequiredParameter("show-attachment", [this](char *x){jc.showAttachment(x);}, "attachment"); +this->ap.addRequiredParameter("show-attachment", [this](char *x){c_main->showAttachment(x);}, "attachment"); this->ap.addRequiredParameter("show-object", p(&ArgParser::argShowObject), "trailer"); -this->ap.addChoices("compress-streams", [this](char *x){jc.compressStreams(x);}, true, yn_choices); +this->ap.addChoices("compress-streams", [this](char *x){c_main->compressStreams(x);}, true, yn_choices); this->ap.addChoices("decode-level", p(&ArgParser::argDecodeLevel), true, decode_level_choices); -this->ap.addChoices("flatten-annotations", [this](char *x){jc.flattenAnnotations(x);}, true, flatten_choices); -this->ap.addChoices("json-key", [this](char *x){jc.jsonKey(x);}, true, json_key_choices); -this->ap.addChoices("keep-files-open", [this](char *x){jc.keepFilesOpen(x);}, true, yn_choices); -this->ap.addChoices("normalize-content", [this](char *x){jc.normalizeContent(x);}, true, yn_choices); +this->ap.addChoices("flatten-annotations", [this](char *x){c_main->flattenAnnotations(x);}, true, flatten_choices); +this->ap.addChoices("json-key", [this](char *x){c_main->jsonKey(x);}, true, json_key_choices); +this->ap.addChoices("keep-files-open", [this](char *x){c_main->keepFilesOpen(x);}, true, yn_choices); +this->ap.addChoices("normalize-content", [this](char *x){c_main->normalizeContent(x);}, true, yn_choices); this->ap.addChoices("object-streams", p(&ArgParser::argObjectStreams), true, object_streams_choices); this->ap.addChoices("password-mode", p(&ArgParser::argPasswordMode), true, password_mode_choices); this->ap.addChoices("remove-unreferenced-resources", p(&ArgParser::argRemoveUnreferencedResources), true, remove_unref_choices); @@ -152,7 +152,7 @@ this->ap.addRequiredParameter("mimetype", p(&ArgParser::argAttMimetype), "mime/t this->ap.addRequiredParameter("description", p(&ArgParser::argAttDescription), "description"); this->ap.registerOptionTable("copy attachment", b(&ArgParser::argEndCopyAttachment)); this->ap.addPositional(p(&ArgParser::argCopyAttPositional)); -this->ap.addRequiredParameter("prefix", p(&ArgParser::argCopyAttPrefix), "prefix"); +this->ap.addRequiredParameter("prefix", [this](char *x){c_copy_att->prefix(x);}, "prefix"); this->ap.addRequiredParameter("password", p(&ArgParser::argCopyAttPassword), "password"); this->ap.selectOptionTable("256-bit encryption"); this->ap.copyFromOtherTable("cleartext-metadata", "128-bit encryption"); -- cgit v1.2.3-54-g00ecf