mirror of https://github.com/qpdf/qpdf.git
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.
This commit is contained in:
parent
23b64f8357
commit
bd89aac360
|
@ -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
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <qpdf/PointerHolder.hh>
|
||||
#include <qpdf/QPDF.hh>
|
||||
#include <qpdf/QPDFPageObjectHelper.hh>
|
||||
#include <qpdf/QPDFArgParser.hh>
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
@ -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<QPDFArgParser> ap;
|
||||
};
|
||||
PointerHolder<Members> m;
|
||||
};
|
||||
|
|
|
@ -662,6 +662,12 @@ QPDFArgParser::parseArgs()
|
|||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDFArgParser::getProgname()
|
||||
{
|
||||
return this->m->whoami;
|
||||
}
|
||||
|
||||
void
|
||||
QPDFArgParser::doFinalChecks()
|
||||
{
|
||||
|
|
|
@ -326,6 +326,7 @@ QPDFJob::QPDFJob() :
|
|||
verbose(false),
|
||||
progress(false),
|
||||
suppress_warnings(false),
|
||||
warnings_exit_zero(false),
|
||||
copy_encryption(false),
|
||||
encryption_file(0),
|
||||
encryption_file_password(0),
|
||||
|
@ -528,6 +529,12 @@ QPDFJob::suppressWarnings()
|
|||
return this->suppress_warnings;
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFJob::warningsExitZero()
|
||||
{
|
||||
return this->warnings_exit_zero;
|
||||
}
|
||||
|
||||
bool
|
||||
QPDFJob::checkRequiresPassword()
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -65,6 +65,7 @@ SRCS_libqpdf = \
|
|||
libqpdf/QPDFFileSpecObjectHelper.cc \
|
||||
libqpdf/QPDFFormFieldObjectHelper.cc \
|
||||
libqpdf/QPDFJob.cc \
|
||||
libqpdf/QPDFJob_argv.cc \
|
||||
libqpdf/QPDFMatrix.cc \
|
||||
libqpdf/QPDFNameTreeObjectHelper.cc \
|
||||
libqpdf/QPDFNumberTreeObjectHelper.cc \
|
||||
|
|
2405
qpdf/qpdf.cc
2405
qpdf/qpdf.cc
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,5 @@
|
|||
|
||||
qpdf: --split-pages may not be used when writing to standard output
|
||||
|
||||
Usage: qpdf [options] {infile | --empty} [page_selection_options] outfile
|
||||
For detailed help, run qpdf --help
|
||||
|
||||
|
|
Loading…
Reference in New Issue