mirror of
https://github.com/qpdf/qpdf.git
synced 2024-05-28 16:00:53 +00:00
QPDFJob: prepare for automatically generated json handlers
This commit is contained in:
parent
7eeaf58bb7
commit
0c8e9e5912
|
@ -23,7 +23,7 @@ namespace
|
|||
{
|
||||
public:
|
||||
ArgParser(QPDFArgParser& ap,
|
||||
std::shared_ptr<QPDFJob::Config> c_main, QPDFJob& o);
|
||||
std::shared_ptr<QPDFJob::Config> c_main);
|
||||
void parseOptions();
|
||||
|
||||
private:
|
||||
|
@ -47,7 +47,7 @@ namespace
|
|||
}
|
||||
|
||||
ArgParser::ArgParser(QPDFArgParser& ap,
|
||||
std::shared_ptr<QPDFJob::Config> c_main, QPDFJob& o) :
|
||||
std::shared_ptr<QPDFJob::Config> c_main) :
|
||||
ap(ap),
|
||||
c_main(c_main),
|
||||
pages_password(nullptr),
|
||||
|
@ -495,7 +495,7 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
|
|||
}
|
||||
QPDFArgParser qap(argc, argv, progname_env);
|
||||
setMessagePrefix(qap.getProgname());
|
||||
ArgParser ap(qap, config(), *this);
|
||||
ArgParser ap(qap, config());
|
||||
qap.addFinalCheck(
|
||||
QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
|
||||
ap.parseOptions();
|
||||
|
|
|
@ -7,6 +7,100 @@
|
|||
|
||||
static JSON JOB_SCHEMA = JSON::parse(QPDFJob::json_job_schema_v1().c_str());
|
||||
|
||||
namespace
|
||||
{
|
||||
class Handlers
|
||||
{
|
||||
public:
|
||||
Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main);
|
||||
void handle(JSON&);
|
||||
|
||||
private:
|
||||
//# include <qpdf/auto_job_json_decl.hh>
|
||||
|
||||
void usage(std::string const& message);
|
||||
void initHandlers();
|
||||
|
||||
JSONHandler& jh;
|
||||
std::shared_ptr<QPDFJob::Config> c_main;
|
||||
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
|
||||
std::shared_ptr<QPDFJob::AttConfig> c_att;
|
||||
std::shared_ptr<QPDFJob::PagesConfig> c_pages;
|
||||
std::shared_ptr<QPDFJob::UOConfig> c_uo;
|
||||
std::shared_ptr<QPDFJob::EncConfig> c_enc;
|
||||
};
|
||||
}
|
||||
|
||||
Handlers::Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main) :
|
||||
jh(jh),
|
||||
c_main(c_main)
|
||||
{
|
||||
initHandlers();
|
||||
}
|
||||
|
||||
void
|
||||
Handlers::initHandlers()
|
||||
{
|
||||
//# include <qpdf/auto_job_json_init.hh>
|
||||
jh.addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
|
||||
auto input = std::make_shared<JSONHandler>();
|
||||
auto input_file = std::make_shared<JSONHandler>();
|
||||
auto input_file_name = std::make_shared<JSONHandler>();
|
||||
auto output = std::make_shared<JSONHandler>();
|
||||
auto output_file = std::make_shared<JSONHandler>();
|
||||
auto output_file_name = std::make_shared<JSONHandler>();
|
||||
auto output_options = std::make_shared<JSONHandler>();
|
||||
auto output_options_qdf = std::make_shared<JSONHandler>();
|
||||
|
||||
input->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
input_file->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output_file->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output_options->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
|
||||
jh.addDictKeyHandler("input", input);
|
||||
input->addDictKeyHandler("file", input_file);
|
||||
input_file->addDictKeyHandler("name", input_file_name);
|
||||
jh.addDictKeyHandler("output", output);
|
||||
output->addDictKeyHandler("file", output_file);
|
||||
output_file->addDictKeyHandler("name", output_file_name);
|
||||
output->addDictKeyHandler("options", output_options);
|
||||
output_options->addDictKeyHandler("qdf", output_options_qdf);
|
||||
|
||||
input_file_name->addStringHandler(
|
||||
[this](std::string const&, std::string const& v) {
|
||||
c_main->inputFile(v.c_str());
|
||||
});
|
||||
output_file_name->addStringHandler(
|
||||
[this](std::string const&, std::string const& v) {
|
||||
c_main->outputFile(v.c_str());
|
||||
});
|
||||
output_options_qdf->addBoolHandler(
|
||||
[this](std::string const&, bool v) {
|
||||
// QXXXQ require v to be true
|
||||
c_main->qdf();
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
Handlers::handle(JSON& j)
|
||||
{
|
||||
jh.handle(".", j);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFJob::initializeFromJson(std::string const& json)
|
||||
{
|
||||
|
@ -25,75 +119,6 @@ QPDFJob::initializeFromJson(std::string const& json)
|
|||
}
|
||||
|
||||
JSONHandler jh;
|
||||
{
|
||||
jh.addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
|
||||
auto input = std::make_shared<JSONHandler>();
|
||||
auto input_file = std::make_shared<JSONHandler>();
|
||||
auto input_file_name = std::make_shared<JSONHandler>();
|
||||
auto output = std::make_shared<JSONHandler>();
|
||||
auto output_file = std::make_shared<JSONHandler>();
|
||||
auto output_file_name = std::make_shared<JSONHandler>();
|
||||
auto output_options = std::make_shared<JSONHandler>();
|
||||
auto output_options_qdf = std::make_shared<JSONHandler>();
|
||||
|
||||
input->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
input_file->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output_file->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
output_options->addDictHandlers(
|
||||
[](std::string const&){},
|
||||
[](std::string const&){});
|
||||
|
||||
jh.addDictKeyHandler("input", input);
|
||||
input->addDictKeyHandler("file", input_file);
|
||||
input_file->addDictKeyHandler("name", input_file_name);
|
||||
jh.addDictKeyHandler("output", output);
|
||||
output->addDictKeyHandler("file", output_file);
|
||||
output_file->addDictKeyHandler("name", output_file_name);
|
||||
output->addDictKeyHandler("options", output_options);
|
||||
output_options->addDictKeyHandler("qdf", output_options_qdf);
|
||||
|
||||
input_file_name->addStringHandler(
|
||||
[this](std::string const&, std::string const& v) {
|
||||
config()->inputFile(v.c_str());
|
||||
});
|
||||
output_file_name->addStringHandler(
|
||||
[this](std::string const&, std::string const& v) {
|
||||
config()->outputFile(v.c_str());
|
||||
});
|
||||
output_options_qdf->addBoolHandler(
|
||||
[this](std::string const&, bool v) {
|
||||
// QXXXQ require v to be true
|
||||
config()->qdf();
|
||||
});
|
||||
}
|
||||
|
||||
// {
|
||||
// "input": {
|
||||
// "file": {
|
||||
// "name": "/home/ejb/source/examples/pdf/minimal.pdf"
|
||||
// }
|
||||
// },
|
||||
// "output": {
|
||||
// "file": {
|
||||
// "name": "/tmp/a.pdf"
|
||||
// },
|
||||
// "options": {
|
||||
// "qdf": true
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
jh.handle(".", j);
|
||||
Handlers h(jh, config());
|
||||
h.handle(j);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user