2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-12 23:22:21 +00:00

QPDFJob: add checkConfiguration to Config

This commit is contained in:
Jay Berkenbilt 2022-01-29 09:01:20 -05:00
parent 0c8e9e5912
commit 8a9100f674
5 changed files with 21 additions and 13 deletions

View File

@ -35,7 +35,8 @@ int main(int argc, char* argv[])
->pages() ->pages()
->pageSpec(".", "1-z") ->pageSpec(".", "1-z")
->endPages() ->endPages()
->qdf(); ->qdf()
->checkConfiguration();
j.run(); j.run();
} }
catch (std::exception& e) catch (std::exception& e)

View File

@ -90,8 +90,9 @@ class QPDFJob
// Check to make sure no contradictory options have been // Check to make sure no contradictory options have been
// specified. This is called automatically after initializing from // specified. This is called automatically after initializing from
// argv or json and is also called by run, but you can call it // argv or json and is also called by run, but you can call it
// manually as well. It throws a Usage exception if there are any // manually as well. It throws a QPDFUsage exception if there are
// errors. // any errors. This Config object (see CONFIGURATION) also has a
// checkConfiguration method which calls this one.
QPDF_DLL QPDF_DLL
void checkConfiguration(); void checkConfiguration();
@ -272,6 +273,10 @@ class QPDFJob
{ {
friend class QPDFJob; friend class QPDFJob;
public: public:
// Proxy to QPDFJob::checkConfiguration()
QPDF_DLL
void checkConfiguration();
QPDF_DLL QPDF_DLL
Config* inputFile(char const* filename); Config* inputFile(char const* filename);
QPDF_DLL QPDF_DLL

View File

@ -64,6 +64,7 @@ ArgParser::initOptionTables()
{ {
# include <qpdf/auto_job_init.hh> # include <qpdf/auto_job_init.hh>
this->ap.addFinalCheck([this](){c_main->checkConfiguration();});
// add_help is defined in auto_job_help.hh // add_help is defined in auto_job_help.hh
add_help(this->ap); add_help(this->ap);
} }
@ -496,7 +497,5 @@ QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
QPDFArgParser qap(argc, argv, progname_env); QPDFArgParser qap(argc, argv, progname_env);
setMessagePrefix(qap.getProgname()); setMessagePrefix(qap.getProgname());
ArgParser ap(qap, config()); ArgParser ap(qap, config());
qap.addFinalCheck(
QPDFArgParser::bindBare(&QPDFJob::checkConfiguration, this));
ap.parseOptions(); ap.parseOptions();
} }

View File

@ -3,6 +3,12 @@
#include <qpdf/QTC.hh> #include <qpdf/QTC.hh>
#include <cstring> #include <cstring>
void
QPDFJob::Config::checkConfiguration()
{
o.checkConfiguration();
}
QPDFJob::Config* QPDFJob::Config*
QPDFJob::Config::inputFile(char const* filename) QPDFJob::Config::inputFile(char const* filename)
{ {

View File

@ -12,7 +12,7 @@ namespace
class Handlers class Handlers
{ {
public: public:
Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main); Handlers(std::shared_ptr<QPDFJob::Config> c_main);
void handle(JSON&); void handle(JSON&);
private: private:
@ -21,7 +21,7 @@ namespace
void usage(std::string const& message); void usage(std::string const& message);
void initHandlers(); void initHandlers();
JSONHandler& jh; JSONHandler jh;
std::shared_ptr<QPDFJob::Config> c_main; std::shared_ptr<QPDFJob::Config> c_main;
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att; std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
std::shared_ptr<QPDFJob::AttConfig> c_att; std::shared_ptr<QPDFJob::AttConfig> c_att;
@ -31,8 +31,7 @@ namespace
}; };
} }
Handlers::Handlers(JSONHandler& jh, std::shared_ptr<QPDFJob::Config> c_main) : Handlers::Handlers(std::shared_ptr<QPDFJob::Config> c_main) :
jh(jh),
c_main(c_main) c_main(c_main)
{ {
initHandlers(); initHandlers();
@ -44,7 +43,7 @@ Handlers::initHandlers()
//# include <qpdf/auto_job_json_init.hh> //# include <qpdf/auto_job_json_init.hh>
jh.addDictHandlers( jh.addDictHandlers(
[](std::string const&){}, [](std::string const&){},
[](std::string const&){}); [this](std::string const&){c_main->checkConfiguration();});
auto input = std::make_shared<JSONHandler>(); auto input = std::make_shared<JSONHandler>();
auto input_file = std::make_shared<JSONHandler>(); auto input_file = std::make_shared<JSONHandler>();
@ -118,7 +117,5 @@ QPDFJob::initializeFromJson(std::string const& json)
throw std::runtime_error(msg.str()); throw std::runtime_error(msg.str());
} }
JSONHandler jh; Handlers(config()).handle(j);
Handlers h(jh, config());
h.handle(j);
} }