aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/qpdf/QPDFJob.hh9
-rw-r--r--libqpdf/QPDFJob_argv.cc24
-rw-r--r--libqpdf/QPDFJob_config.cc66
3 files changed, 90 insertions, 9 deletions
diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh
index e1f96835..90c778b4 100644
--- a/include/qpdf/QPDFJob.hh
+++ b/include/qpdf/QPDFJob.hh
@@ -244,6 +244,15 @@ class QPDFJob
friend class QPDFJob;
public:
QPDF_DLL
+ Config& inputFile(char const* filename);
+ QPDF_DLL
+ Config& emptyInput();
+ QPDF_DLL
+ Config& outputFile(char const* filename);
+ QPDF_DLL
+ Config& replaceInput();
+
+ QPDF_DLL
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
QPDF_DLL
std::shared_ptr<AttConfig> addAttachment();
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index c4a7834a..71654e65 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -37,7 +37,6 @@ namespace
void initOptionTables();
QPDFArgParser ap;
- QPDFJob& o;
std::shared_ptr<QPDFJob::Config> c_main;
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
std::shared_ptr<QPDFJob::AttConfig> c_att;
@@ -46,15 +45,18 @@ namespace
std::shared_ptr<QPDFJob::EncConfig> c_enc;
std::vector<char*> accumulated_args; // points to member in ap
char* pages_password;
+ bool gave_input;
+ bool gave_output;
};
}
ArgParser::ArgParser(QPDFArgParser& ap,
std::shared_ptr<QPDFJob::Config> c_main, QPDFJob& o) :
ap(ap),
- o(o),
c_main(c_main),
- pages_password(nullptr)
+ pages_password(nullptr),
+ gave_input(false),
+ gave_output(false)
{
initOptionTables();
}
@@ -73,13 +75,15 @@ ArgParser::initOptionTables()
void
ArgParser::argPositional(char* arg)
{
- if (o.infilename == 0)
+ if (! this->gave_input)
{
- o.infilename = QUtil::make_shared_cstr(arg);
+ c_main->inputFile(arg);
+ this->gave_input = true;
}
- else if (o.outfilename == 0)
+ else if (! this->gave_output)
{
- o.outfilename = QUtil::make_shared_cstr(arg);
+ c_main->outputFile(arg);
+ this->gave_output = true;
}
else
{
@@ -90,13 +94,15 @@ ArgParser::argPositional(char* arg)
void
ArgParser::argEmpty()
{
- o.infilename = QUtil::make_shared_cstr("");
+ c_main->emptyInput();
+ this->gave_input = true;
}
void
ArgParser::argReplaceInput()
{
- o.replace_input = true;
+ c_main->replaceInput();
+ this->gave_output = true;
}
void
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index 9eb03ae3..ad578130 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -9,6 +9,72 @@ static void usage(std::string const& msg)
}
QPDFJob::Config&
+QPDFJob::Config::inputFile(char const* filename)
+{
+ if (o.infilename == 0)
+ {
+ o.infilename = QUtil::make_shared_cstr(filename);
+ }
+ else
+ {
+ usage("input file has already been given");
+ }
+ return *this;
+}
+
+QPDFJob::Config&
+QPDFJob::Config::emptyInput()
+{
+ if (o.infilename == 0)
+ {
+ // QXXXQ decide whether to fix this or just leave the comment:
+ // Various places in QPDFJob.cc know that the empty string for
+ // infile means empty. This means that passing "" as the
+ // argument to inputFile, or equivalently using "" as a
+ // positional command-line argument would be the same as
+ // --empty. This probably isn't worth blocking or coding
+ // around, but it would be better if we had a tighter way of
+ // knowing that the input file is empty.
+ o.infilename = QUtil::make_shared_cstr("");
+ }
+ else
+ {
+ usage("empty input can't be used"
+ " since input file has already been given");
+ }
+ return *this;
+}
+
+QPDFJob::Config&
+QPDFJob::Config::outputFile(char const* filename)
+{
+ if ((o.outfilename == 0) && (! o.replace_input))
+ {
+ o.outfilename = QUtil::make_shared_cstr(filename);
+ }
+ else
+ {
+ usage("output file has already been given");
+ }
+ return *this;
+}
+
+QPDFJob::Config&
+QPDFJob::Config::replaceInput()
+{
+ if ((o.outfilename == 0) && (! o.replace_input))
+ {
+ o.replace_input = true;
+ }
+ else
+ {
+ usage("replace-input can't be used"
+ " since output file has already been given");
+ }
+ return *this;
+}
+
+QPDFJob::Config&
QPDFJob::Config::allowWeakCrypto()
{
o.allow_weak_crypto = true;