mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 15:17:29 +00:00
QPDFJob: move input/output handling into config
This commit is contained in:
parent
ac56e013d6
commit
2c7b583b3a
@ -243,6 +243,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
|
||||
|
@ -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
|
||||
|
@ -8,6 +8,72 @@ static void usage(std::string const& msg)
|
||||
throw QPDFJob::ConfigError(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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user