From bd89aac36020f3a289c1624f2e00ec3d3d932a49 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 5 Jan 2022 17:20:20 -0500 Subject: QPDFJob increment: move arg parsing into QPDFJob Move ArgParser from qpdf.cc into QPDFJob.cc. It still works with millions of public member variables, but now qpdf.cc is minimal and just calls stable library functions. --- include/qpdf/QPDFArgParser.hh | 5 +++++ include/qpdf/QPDFJob.hh | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'include') diff --git a/include/qpdf/QPDFArgParser.hh b/include/qpdf/QPDFArgParser.hh index 2c46c4e0..e5b2c490 100644 --- a/include/qpdf/QPDFArgParser.hh +++ b/include/qpdf/QPDFArgParser.hh @@ -73,6 +73,11 @@ class QPDFArgParser QPDF_DLL void parseArgs(); + // Return the program name as the last path element of the program + // executable. + QPDF_DLL + std::string getProgname(); + // Methods for registering arguments. QPDFArgParser starts off // with the main option table selected. You can add handlers for // arguments in the current option table, and you can select which diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 660f691f..f2e3a019 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,29 @@ class QPDFJob QPDF_DLL QPDFJob(); + // Initialize a QPDFJob object from argv. The progname_env + // argument is the name of an environment variable which, if set, + // overrides the name of the executable for purposes of generating + // the --completion options. See QPDFArgParser for details. If a + // null pointer is passed in, the default value of + // "QPDF_EXECUTABLE" is used. This is used by the QPDF cli, which + // just initializes a QPDFJob from argv, calls run(), and handles + // errors and exit status issues. You can perform much of the cli + // functionality programmatically in this way rather than using + // the regular API. This is exposed in the C API, which makes it + // easier to get certain high-level qpdf functionality from other + // languages. If there are any command-line errors, this method + // will throw QPDFArgParser::Usage which is derived from + // std::runtime_error. Other exceptions may be thrown in some + // cases. Note that argc, and argv should be UTF-8 encoded. If you + // are calling this from a Windows Unicode-aware main (wmain), see + // QUtil::call_main_from_wmain for information about converting + // arguments to UTF-8. This method will mutate arguments that are + // passed to it. + QPDF_DLL + void initializeFromArgv(int argc, char* argv[], + char const* progname_env = nullptr); + // Set name that is used to prefix verbose messages, progress // messages, and other things that the library writes to output // and error streams on the caller's behalf. Defaults to "qpdf". @@ -73,6 +97,9 @@ class QPDFJob QPDF_DLL bool suppressWarnings(); + QPDF_DLL + bool warningsExitZero(); + QPDF_DLL bool checkRequiresPassword(); @@ -180,6 +207,7 @@ class QPDFJob bool verbose; bool progress; bool suppress_warnings; + bool warnings_exit_zero; bool copy_encryption; char const* encryption_file; char const* encryption_file_password; @@ -367,6 +395,7 @@ class QPDFJob std::ostream* cout; std::ostream* cerr; unsigned long encryption_status; + PointerHolder ap; }; PointerHolder m; }; -- cgit v1.2.3-54-g00ecf