From 1ddf5b4b4bbc3c00c51aba51ff67be47736f6e88 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 3 Jan 2022 12:16:16 -0500 Subject: QPDFJob increment: get rid of exit, handle verbose Remove all calls to exit() from QPDFJob. Handle code that runs in verbose mode to enable it to make use of output streams and message prefix (whoami) from QPDFJob. This removes temporarily duplicated exit code logic and most access to whoami/std::cout outside of QPDFJob proper. --- include/qpdf/QPDFJob.hh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh index 03b6aa21..89be7c2c 100644 --- a/include/qpdf/QPDFJob.hh +++ b/include/qpdf/QPDFJob.hh @@ -33,6 +33,7 @@ #include #include #include +#include class QPDFWriter; @@ -42,9 +43,23 @@ class QPDFJob QPDF_DLL QPDFJob(); + // 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". + QPDF_DLL + void setMessagePrefix(std::string const&); + + // Override streams that errors and output go to. Defaults are + // std::cout and std::cerr. QPDF_DLL void setOutputStreams(std::ostream* out_stream, std::ostream* err_stream); + // If in verbose mode, call the given function, passing in the + // output stream and message prefix. + QPDF_DLL + void doIfVerbose( + std::function fn); + QPDF_DLL void run(); @@ -63,14 +78,13 @@ class QPDFJob QPDF_DLL bool checkIsEncrypted(); - // Return value is bitwise OR of values from qpdf_encryption_status_e QPDF_DLL unsigned long getEncryptionStatus(); - // QXXXQ From here to END-PUBLIC should all be private + // QXXXQ From here to END-PUBLIC should all be private or + // different somehow public: - QPDF_DLL static JSON json_schema(std::set* keys = 0); QPDF_DLL @@ -165,6 +179,10 @@ class QPDFJob void setWriterOptions(QPDF& pdf, QPDFWriter& w); void doSplitPages(QPDF& pdf, bool& warnings); void writeOutfile(QPDF& pdf); + void doJSON(QPDF& pdf); + void doInspection(QPDF& pdf); + void showEncryption(QPDF& pdf); + void doCheck(QPDF& pdf); enum remove_unref_e { re_auto, re_yes, re_no }; @@ -295,6 +313,7 @@ class QPDFJob Members(); Members(Members const&) = delete; + std::string whoami; bool warnings; bool creates_output; std::ostream* out_stream; -- cgit v1.2.3-54-g00ecf