aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-01 19:37:31 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-01 19:50:58 +0100
commitb02d37bc0ae0b7af6077637f855be8579c768c22 (patch)
treea1dbfdd033951afcd41e7a7e36dfbaa0dd903776 /libqpdf
parentbc4e2320e7dafea8b6d6b6150c808ed2a98d7d03 (diff)
downloadqpdf-b02d37bc0ae0b7af6077637f855be8579c768c22.tar.zst
Make QPDFArgParser accept const argv
This makes it much more convention to use the initializeFromArgv functions since you can use string literals.
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFArgParser.cc88
-rw-r--r--libqpdf/QPDFJob_argv.cc65
-rw-r--r--libqpdf/QPDFJob_config.cc263
-rw-r--r--libqpdf/QUtil.cc28
-rw-r--r--libqpdf/qpdf/QPDFArgParser.hh38
-rw-r--r--libqpdf/qpdf/auto_job_decl.hh14
-rw-r--r--libqpdf/qpdf/auto_job_init.hh132
-rw-r--r--libqpdf/qpdf/auto_job_json_init.hh130
-rw-r--r--libqpdf/qpdfjob-c.cc7
9 files changed, 391 insertions, 374 deletions
diff --git a/libqpdf/QPDFArgParser.cc b/libqpdf/QPDFArgParser.cc
index 194f5b16..9c735e65 100644
--- a/libqpdf/QPDFArgParser.cc
+++ b/libqpdf/QPDFArgParser.cc
@@ -8,11 +8,10 @@
#include <cstdlib>
QPDFArgParser::Members::Members(
- int argc, char* argv[], char const* progname_env) :
+ int argc, char const* const argv[], char const* progname_env) :
argc(argc),
argv(argv),
- whoami(QUtil::getWhoami(argv[0])),
progname_env(progname_env),
cur_arg(0),
bash_completion(false),
@@ -20,14 +19,18 @@ QPDFArgParser::Members::Members(
option_table(nullptr),
final_check_handler(nullptr)
{
+ auto tmp = QUtil::make_shared_cstr(argv[0]);
+ char* p = QUtil::getWhoami(tmp.get());
// Remove prefix added by libtool for consistency during testing.
- if (strncmp(whoami, "lt-", 3) == 0)
+ if (strncmp(p, "lt-", 3) == 0)
{
- whoami += 3;
+ p += 3;
}
+ whoami = p;
}
-QPDFArgParser::QPDFArgParser(int argc, char* argv[], char const* progname_env) :
+QPDFArgParser::QPDFArgParser(int argc, char const* const argv[],
+ char const* progname_env) :
m(new Members(argc, argv, progname_env))
{
selectHelpOptionTable();
@@ -250,17 +253,17 @@ QPDFArgParser::argCompletionZsh()
}
void
-QPDFArgParser::argHelp(char* p)
+QPDFArgParser::argHelp(std::string const& p)
{
std::cout << getHelp(p);
exit(0);
}
void
-QPDFArgParser::invalidHelpArg(char* p)
+QPDFArgParser::invalidHelpArg(std::string const& p)
{
usage(std::string("unknown help option") +
- (p ? (std::string(" ") + p) : ""));
+ (p.empty() ? "" : (" " + p)));
}
void
@@ -272,7 +275,7 @@ QPDFArgParser::handleArgFileArguments()
this->m->new_argv.push_back(QUtil::make_shared_cstr(this->m->argv[0]));
for (int i = 1; i < this->m->argc; ++i)
{
- char* argfile = 0;
+ char const* argfile = 0;
if ((strlen(this->m->argv[i]) > 1) && (this->m->argv[i][0] == '@'))
{
argfile = 1 + this->m->argv[i];
@@ -295,16 +298,16 @@ QPDFArgParser::handleArgFileArguments()
QUtil::make_shared_cstr(this->m->argv[i]));
}
}
- this->m->argv_ph = std::shared_ptr<char*>(
- new char*[1 + this->m->new_argv.size()],
- std::default_delete<char*[]>());
- this->m->argv = this->m->argv_ph.get();
+ this->m->argv_ph = std::shared_ptr<char const*>(
+ new char const*[1 + this->m->new_argv.size()],
+ std::default_delete<char const*[]>());
for (size_t i = 0; i < this->m->new_argv.size(); ++i)
{
- this->m->argv[i] = this->m->new_argv.at(i).get();
+ this->m->argv_ph.get()[i] = this->m->new_argv.at(i).get();
}
this->m->argc = QIntC::to_int(this->m->new_argv.size());
- this->m->argv[this->m->argc] = 0;
+ this->m->argv_ph.get()[this->m->argc] = nullptr;
+ this->m->argv = this->m->argv_ph.get();
}
void
@@ -400,16 +403,16 @@ QPDFArgParser::handleBashArguments()
}
// Explicitly discard any non-space-terminated word. The "current
// word" is handled specially.
- this->m->bash_argv_ph = std::shared_ptr<char*>(
- new char*[1 + this->m->bash_argv.size()],
- std::default_delete<char*[]>());
- this->m->argv = this->m->bash_argv_ph.get();
+ this->m->bash_argv_ph = std::shared_ptr<char const*>(
+ new char const*[1 + this->m->bash_argv.size()],
+ std::default_delete<char const*[]>());
for (size_t i = 0; i < this->m->bash_argv.size(); ++i)
{
- this->m->argv[i] = this->m->bash_argv.at(i).get();
+ this->m->bash_argv_ph.get()[i] = this->m->bash_argv.at(i).get();
}
this->m->argc = QIntC::to_int(this->m->bash_argv.size());
- this->m->argv[this->m->argc] = 0;
+ this->m->bash_argv_ph.get()[this->m->argc] = nullptr;
+ this->m->argv = this->m->bash_argv_ph.get();
}
void
@@ -424,10 +427,10 @@ QPDFArgParser::usage(std::string const& message)
}
void
-QPDFArgParser::readArgsFromFile(char const* filename)
+QPDFArgParser::readArgsFromFile(std::string const& filename)
{
std::list<std::string> lines;
- if (strcmp(filename, "-") == 0)
+ if (filename == "-")
{
QTC::TC("libtests", "QPDFArgParser read args from stdin");
lines = QUtil::read_lines_from_file(std::cin);
@@ -435,7 +438,7 @@ QPDFArgParser::readArgsFromFile(char const* filename)
else
{
QTC::TC("libtests", "QPDFArgParser read args from file");
- lines = QUtil::read_lines_from_file(filename);
+ lines = QUtil::read_lines_from_file(filename.c_str());
}
for (auto const& line: lines)
{
@@ -547,8 +550,9 @@ QPDFArgParser::parseArgs()
bool help_option = false;
bool end_option = false;
auto oep = this->m->option_table->end();
- char* arg = this->m->argv[this->m->cur_arg];
- char* parameter = nullptr;
+ char const* arg = this->m->argv[this->m->cur_arg];
+ std::string parameter;
+ bool have_parameter = false;
std::string o_arg(arg);
std::string arg_s(arg);
if ((strcmp(arg, "--") == 0) &&
@@ -577,20 +581,25 @@ QPDFArgParser::parseArgs()
{
QTC::TC("libtests", "QPDFArgParser single dash");
}
- if (strlen(arg) > 0)
+
+ // Prevent --=something from being treated as an empty arg
+ // by searching for = from after the first character. We
+ // do this since the empty string in the option table is
+ // for positional arguments. Besides, it doesn't make
+ // sense to have an empty option.
+ arg_s = arg;
+ size_t equal_pos = std::string::npos;
+ if (arg_s.length() > 0)
{
- // Prevent --=something from being treated as an empty
- // arg since the empty string in the option table is
- // for positional arguments.
- parameter = const_cast<char*>(strchr(1 + arg, '='));
+ equal_pos = arg_s.find('=', 1);
}
- if (parameter)
+ if (equal_pos != std::string::npos)
{
- *parameter++ = 0;
+ have_parameter = true;
+ parameter = arg_s.substr(equal_pos + 1);
+ arg_s = arg_s.substr(0, equal_pos);
}
- arg_s = arg;
-
if ((! this->m->bash_completion) &&
(this->m->argc == 2) && (this->m->cur_arg == 1) &&
this->m->help_option_table.count(arg_s))
@@ -629,8 +638,8 @@ QPDFArgParser::parseArgs()
}
OptionEntry& oe = oep->second;
- if ((oe.parameter_needed && (nullptr == parameter)) ||
- ((! oe.choices.empty() && (nullptr != parameter) &&
+ if ((oe.parameter_needed && (! have_parameter)) ||
+ ((! oe.choices.empty() && have_parameter &&
(0 == oe.choices.count(parameter)))))
{
std::string message =
@@ -977,16 +986,15 @@ QPDFArgParser::getTopicHelp(std::string const& name,
}
std::string
-QPDFArgParser::getHelp(char const* topic_or_option)
+QPDFArgParser::getHelp(std::string const& arg)
{
std::ostringstream msg;
- if ((topic_or_option == nullptr) || (strlen(topic_or_option) == 0))
+ if (arg.empty())
{
getTopHelp(msg);
}
else
{
- std::string arg(topic_or_option);
if (arg == "all")
{
getAllHelp(msg);
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index 203e4b27..e2870309 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -39,8 +39,8 @@ namespace
std::shared_ptr<QPDFJob::PagesConfig> c_pages;
std::shared_ptr<QPDFJob::UOConfig> c_uo;
std::shared_ptr<QPDFJob::EncConfig> c_enc;
- std::vector<char*> accumulated_args; // points to member in ap
- char* pages_password;
+ std::vector<std::string> accumulated_args;
+ std::shared_ptr<char> pages_password;
bool gave_input;
bool gave_output;
};
@@ -70,7 +70,7 @@ ArgParser::initOptionTables()
}
void
-ArgParser::argPositional(char* arg)
+ArgParser::argPositional(std::string const& arg)
{
if (! this->gave_input)
{
@@ -84,7 +84,7 @@ ArgParser::argPositional(char* arg)
}
else
{
- usage(std::string("unknown argument ") + arg);
+ usage("unknown argument " + arg);
}
}
@@ -188,7 +188,7 @@ ArgParser::argEncrypt()
}
void
-ArgParser::argEncPositional(char* arg)
+ArgParser::argEncPositional(std::string const& arg)
{
this->accumulated_args.push_back(arg);
size_t n_args = this->accumulated_args.size();
@@ -244,9 +244,9 @@ ArgParser::argPages()
}
void
-ArgParser::argPagesPassword(char* parameter)
+ArgParser::argPagesPassword(std::string const& parameter)
{
- if (this->pages_password != nullptr)
+ if (this->pages_password)
{
QTC::TC("qpdf", "QPDFJob duplicated pages password");
usage("--password already specified for this file");
@@ -256,13 +256,13 @@ ArgParser::argPagesPassword(char* parameter)
QTC::TC("qpdf", "QPDFJob misplaced pages password");
usage("in --pages, --password must immediately follow a file name");
}
- this->pages_password = parameter;
+ this->pages_password = QUtil::make_shared_cstr(parameter);
}
void
-ArgParser::argPagesPositional(char* arg)
+ArgParser::argPagesPositional(std::string const& arg)
{
- if (arg == nullptr)
+ if (arg.empty())
{
if (this->accumulated_args.empty())
{
@@ -274,25 +274,26 @@ ArgParser::argPagesPositional(char* arg)
this->accumulated_args.push_back(arg);
}
- char const* file = this->accumulated_args.at(0);
- char const* range = nullptr;
+ std::string file = this->accumulated_args.at(0);
+ char const* range_p = nullptr;
size_t n_args = this->accumulated_args.size();
if (n_args >= 2)
{
- range = this->accumulated_args.at(1);
+ // will be copied before accumulated_args is cleared
+ range_p = this->accumulated_args.at(1).c_str();
}
// See if the user omitted the range entirely, in which case we
// assume "1-z".
- char* next_file = nullptr;
- if (range == nullptr)
+ std::string next_file;
+ if (range_p == nullptr)
{
- if (arg == nullptr)
+ if (arg.empty())
{
// The filename or password was the last argument
QTC::TC("qpdf", "QPDFJob pages range omitted at end",
- this->pages_password == nullptr ? 0 : 1);
+ this->pages_password ? 0 : 1);
}
else
{
@@ -304,17 +305,17 @@ ArgParser::argPagesPositional(char* arg)
{
try
{
- QUtil::parse_numrange(range, 0);
+ QUtil::parse_numrange(range_p, 0);
}
catch (std::runtime_error& e1)
{
// The range is invalid. Let's see if it's a file.
- if (strcmp(range, ".") == 0)
+ if (strcmp(range_p, ".") == 0)
{
// "." means the input file.
QTC::TC("qpdf", "QPDFJob pages range omitted with .");
}
- else if (QUtil::file_can_be_opened(range))
+ else if (QUtil::file_can_be_opened(range_p))
{
QTC::TC("qpdf", "QPDFJob pages range omitted in middle");
// Yup, it's a file.
@@ -324,18 +325,15 @@ ArgParser::argPagesPositional(char* arg)
// Give the range error
usage(e1.what());
}
- next_file = const_cast<char*>(range);
- range = nullptr;
+ next_file = range_p;
+ range_p = nullptr;
}
}
- if (range == nullptr)
- {
- range = "1-z";
- }
- this->c_pages->pageSpec(file, range, this->pages_password);
+ std::string range(range_p ? range_p : "1-z");
+ this->c_pages->pageSpec(file, range, this->pages_password.get());
this->accumulated_args.clear();
this->pages_password = nullptr;
- if (next_file != nullptr)
+ if (! next_file.empty())
{
this->accumulated_args.push_back(next_file);
}
@@ -344,7 +342,7 @@ ArgParser::argPagesPositional(char* arg)
void
ArgParser::argEndPages()
{
- argPagesPositional(nullptr);
+ argPagesPositional("");
c_pages->endPages();
c_pages = nullptr;
}
@@ -403,7 +401,7 @@ ArgParser::argEnd256BitEncryption()
}
void
-ArgParser::argUOPositional(char* arg)
+ArgParser::argUOPositional(std::string const& arg)
{
c_uo->file(arg);
}
@@ -416,7 +414,7 @@ ArgParser::argEndUnderlayOverlay()
}
void
-ArgParser::argAttPositional(char* arg)
+ArgParser::argAttPositional(std::string const& arg)
{
c_att->file(arg);
}
@@ -429,7 +427,7 @@ ArgParser::argEndAttachment()
}
void
-ArgParser::argCopyAttPositional(char* arg)
+ArgParser::argCopyAttPositional(std::string const& arg)
{
c_copy_att->file(arg);
}
@@ -467,7 +465,8 @@ ArgParser::parseOptions()
}
void
-QPDFJob::initializeFromArgv(int argc, char* argv[], char const* progname_env)
+QPDFJob::initializeFromArgv(int argc, char const* const argv[],
+ char const* progname_env)
{
if (progname_env == nullptr)
{
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index 68eaf5c8..da119b39 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -1,7 +1,6 @@
#include <qpdf/QPDFJob.hh>
#include <qpdf/QUtil.hh>
#include <qpdf/QTC.hh>
-#include <cstring>
void
QPDFJob::Config::checkConfiguration()
@@ -10,7 +9,7 @@ QPDFJob::Config::checkConfiguration()
}
QPDFJob::Config*
-QPDFJob::Config::inputFile(char const* filename)
+QPDFJob::Config::inputFile(std::string const& filename)
{
if (o.m->infilename == 0)
{
@@ -46,7 +45,7 @@ QPDFJob::Config::emptyInput()
}
QPDFJob::Config*
-QPDFJob::Config::outputFile(char const* filename)
+QPDFJob::Config::outputFile(std::string const& filename)
{
if ((o.m->outfilename == 0) && (! o.m->replace_input))
{
@@ -107,35 +106,34 @@ QPDFJob::Config::coalesceContents()
QPDFJob::Config*
QPDFJob::Config::collate()
{
- return collate(nullptr);
+ return collate("");
}
QPDFJob::Config*
-QPDFJob::Config::collate(char const* parameter)
+QPDFJob::Config::collate(std::string const& parameter)
{
- auto n = (((parameter == 0) || (strlen(parameter) == 0)) ? 1 :
- QUtil::string_to_uint(parameter));
+ auto n = (parameter.empty() ? 1 : QUtil::string_to_uint(parameter.c_str()));
o.m->collate = QIntC::to_size(n);
return this;
}
QPDFJob::Config*
-QPDFJob::Config::compressStreams(char const* parameter)
+QPDFJob::Config::compressStreams(std::string const& parameter)
{
o.m->compress_streams_set = true;
- o.m->compress_streams = (strcmp(parameter, "y") == 0);
+ o.m->compress_streams = (parameter == "y");
return this;
}
QPDFJob::Config*
-QPDFJob::Config::compressionLevel(char const* parameter)
+QPDFJob::Config::compressionLevel(std::string const& parameter)
{
- o.m->compression_level = QUtil::string_to_int(parameter);
+ o.m->compression_level = QUtil::string_to_int(parameter.c_str());
return this;
}
QPDFJob::Config*
-QPDFJob::Config::copyEncryption(char const* parameter)
+QPDFJob::Config::copyEncryption(std::string const& parameter)
{
o.m->encryption_file = parameter;
o.m->copy_encryption = true;
@@ -161,7 +159,7 @@ QPDFJob::Config::deterministicId()
}
QPDFJob::Config*
-QPDFJob::Config::encryptionFilePassword(char const* parameter)
+QPDFJob::Config::encryptionFilePassword(std::string const& parameter)
{
o.m->encryption_file_password = QUtil::make_shared_cstr(parameter);
return this;
@@ -182,17 +180,21 @@ QPDFJob::Config::filteredStreamData()
}
QPDFJob::Config*
-QPDFJob::Config::flattenAnnotations(char const* parameter)
+QPDFJob::Config::flattenAnnotations(std::string const& parameter)
{
o.m->flatten_annotations = true;
- if (strcmp(parameter, "screen") == 0)
+ if (parameter == "screen")
{
o.m->flatten_annotations_forbidden |= an_no_view;
}
- else if (strcmp(parameter, "print") == 0)
+ else if (parameter == "print")
{
o.m->flatten_annotations_required |= an_print;
}
+ else if (parameter != "all")
+ {
+ usage("invalid flatten-annotations option");
+ }
return this;
}
@@ -204,7 +206,7 @@ QPDFJob::Config::flattenRotation()
}
QPDFJob::Config*
-QPDFJob::Config::forceVersion(char const* parameter)
+QPDFJob::Config::forceVersion(std::string const& parameter)
{
o.m->force_version = parameter;
return this;
@@ -225,9 +227,9 @@ QPDFJob::Config::ignoreXrefStreams()
}
QPDFJob::Config*
-QPDFJob::Config::iiMinBytes(char const* parameter)
+QPDFJob::Config::iiMinBytes(std::string const& parameter)
{
- o.m->ii_min_bytes = QUtil::string_to_uint(parameter);
+ o.m->ii_min_bytes = QUtil::string_to_uint(parameter.c_str());
return this;
}
@@ -242,27 +244,25 @@ QPDFJob::Config::isEncrypted()
QPDFJob::Config*
QPDFJob::Config::json()
{
- return json(nullptr);
+ return json("");
}
QPDFJob::Config*
-QPDFJob::Config::json(char const* parameter)
+QPDFJob::Config::json(std::string const& parameter)
{
- if (parameter && strlen(parameter))
+ if (parameter.empty())
{
- if (strcmp(parameter, "latest") == 0)
- {
- o.m->json_version = 1;
- }
- else
- {
- o.m->json_version = QUtil::string_to_int(parameter);
- }
+ // The default value is 1 for backward compatibility.
+ o.m->json_version = 1;
}
- else
+ else if (parameter == "latest")
{
o.m->json_version = 1;
}
+ else
+ {
+ o.m->json_version = QUtil::string_to_int(parameter.c_str());
+ }
if (o.m->json_version != 1)
{
usage(std::string("unsupported json version ") + parameter);
@@ -272,31 +272,31 @@ QPDFJob::Config::json(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::jsonKey(char const* parameter)
+QPDFJob::Config::jsonKey(std::string const& parameter)
{
o.m->json_keys.insert(parameter);
return this;
}
QPDFJob::Config*
-QPDFJob::Config::jsonObject(char const* parameter)
+QPDFJob::Config::jsonObject(std::string const& parameter)
{
o.m->json_objects.insert(parameter);
return this;
}
QPDFJob::Config*
-QPDFJob::Config::keepFilesOpen(char const* parameter)
+QPDFJob::Config::keepFilesOpen(std::string const& parameter)
{
o.m->keep_files_open_set = true;
- o.m->keep_files_open = (strcmp(parameter, "y") == 0);
+ o.m->keep_files_open = (parameter == "y");
return this;
}
QPDFJob::Config*
-QPDFJob::Config::keepFilesOpenThreshold(char const* parameter)
+QPDFJob::Config::keepFilesOpenThreshold(std::string const& parameter)
{
- o.m->keep_files_open_threshold = QUtil::string_to_uint(parameter);
+ o.m->keep_files_open_threshold = QUtil::string_to_uint(parameter.c_str());
return this;
}
@@ -315,7 +315,7 @@ QPDFJob::Config::linearize()
}
QPDFJob::Config*
-QPDFJob::Config::linearizePass1(char const* parameter)
+QPDFJob::Config::linearizePass1(std::string const& parameter)
{
o.m->linearize_pass1 = parameter;
return this;
@@ -330,7 +330,7 @@ QPDFJob::Config::listAttachments()
}
QPDFJob::Config*
-QPDFJob::Config::minVersion(char const* parameter)
+QPDFJob::Config::minVersion(std::string const& parameter)
{
o.m->min_version = parameter;
return this;
@@ -358,31 +358,31 @@ QPDFJob::Config::noWarn()
}
QPDFJob::Config*
-QPDFJob::Config::normalizeContent(char const* parameter)
+QPDFJob::Config::normalizeContent(std::string const& parameter)
{
o.m->normalize_set = true;
- o.m->normalize = (strcmp(parameter, "y") == 0);
+ o.m->normalize = (parameter == "y");
return this;
}
QPDFJob::Config*
-QPDFJob::Config::oiMinArea(char const* parameter)
+QPDFJob::Config::oiMinArea(std::string const& parameter)
{
- o.m->oi_min_area = QUtil::string_to_uint(parameter);
+ o.m->oi_min_area = QUtil::string_to_uint(parameter.c_str());
return this;
}
QPDFJob::Config*
-QPDFJob::Config::oiMinHeight(char const* parameter)
+QPDFJob::Config::oiMinHeight(std::string const& parameter)
{
- o.m->oi_min_height = QUtil::string_to_uint(parameter);
+ o.m->oi_min_height = QUtil::string_to_uint(parameter.c_str());
return this;
}
QPDFJob::Config*
-QPDFJob::Config::oiMinWidth(char const* parameter)
+QPDFJob::Config::oiMinWidth(std::string const& parameter)
{
- o.m->oi_min_width = QUtil::string_to_uint(parameter);
+ o.m->oi_min_width = QUtil::string_to_uint(parameter.c_str());
return this;
}
@@ -394,7 +394,7 @@ QPDFJob::Config::optimizeImages()
}
QPDFJob::Config*
-QPDFJob::Config::password(char const* parameter)
+QPDFJob::Config::password(std::string const& parameter)
{
o.m->password = QUtil::make_shared_cstr(parameter);
return this;
@@ -451,7 +451,7 @@ QPDFJob::Config::recompressFlate()
}
QPDFJob::Config*
-QPDFJob::Config::removeAttachment(char const* parameter)
+QPDFJob::Config::removeAttachment(std::string const& parameter)
{
o.m->attachments_to_remove.push_back(parameter);
return this;
@@ -473,7 +473,7 @@ QPDFJob::Config::requiresPassword()
}
QPDFJob::Config*
-QPDFJob::Config::showAttachment(char const* parameter)
+QPDFJob::Config::showAttachment(std::string const& parameter)
{
o.m->attachment_to_show = parameter;
o.m->require_outfile = false;
@@ -530,14 +530,13 @@ QPDFJob::Config::showXref()
QPDFJob::Config*
QPDFJob::Config::splitPages()
{
- return splitPages(nullptr);
+ return splitPages("");
}
QPDFJob::Config*
-QPDFJob::Config::splitPages(char const* parameter)
+QPDFJob::Config::splitPages(std::string const& parameter)
{
- int n = (((parameter == 0) || (strlen(parameter) == 0)) ? 1 :
- QUtil::string_to_int(parameter));
+ int n = (parameter.empty() ? 1 : QUtil::string_to_int(parameter.c_str()));
o.m->split_pages = n;
return this;
}
@@ -592,10 +591,10 @@ QPDFJob::Config::withImages()
}
QPDFJob::Config*
-QPDFJob::Config::passwordFile(char const* parameter)
+QPDFJob::Config::passwordFile(std::string const& parameter)
{
std::list<std::string> lines;
- if (strcmp(parameter, "-") == 0)
+ if (parameter == "-")
{
QTC::TC("qpdf", "QPDFJob_config password stdin");
lines = QUtil::read_lines_from_file(std::cin);
@@ -603,7 +602,7 @@ QPDFJob::Config::passwordFile(char const* parameter)
else
{
QTC::TC("qpdf", "QPDFJob_config password file");
- lines = QUtil::read_lines_from_file(parameter);
+ lines = QUtil::read_lines_from_file(parameter.c_str());
}
if (lines.size() >= 1)
{
@@ -620,21 +619,21 @@ QPDFJob::Config::passwordFile(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::passwordMode(char const* parameter)
+QPDFJob::Config::passwordMode(std::string const& parameter)
{
- if (strcmp(parameter, "bytes") == 0)
+ if (parameter == "bytes")
{
o.m->password_mode = QPDFJob::pm_bytes;
}
- else if (strcmp(parameter, "hex-bytes") == 0)
+ else if (parameter == "hex-bytes")
{
o.m->password_mode = QPDFJob::pm_hex_bytes;
}
- else if (strcmp(parameter, "unicode") == 0)
+ else if (parameter == "unicode")
{
o.m->password_mode = QPDFJob::pm_unicode;
}
- else if (strcmp(parameter, "auto") == 0)
+ else if (parameter == "auto")
{
o.m->password_mode = QPDFJob::pm_auto;
}
@@ -646,18 +645,18 @@ QPDFJob::Config::passwordMode(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::streamData(char const* parameter)
+QPDFJob::Config::streamData(std::string const& parameter)
{
o.m->stream_data_set = true;
- if (strcmp(parameter, "compress") == 0)
+ if (parameter == "compress")
{
o.m->stream_data_mode = qpdf_s_compress;
}
- else if (strcmp(parameter, "preserve") == 0)
+ else if (parameter == "preserve")
{
o.m->stream_data_mode = qpdf_s_preserve;
}
- else if (strcmp(parameter, "uncompress") == 0)
+ else if (parameter == "uncompress")
{
o.m->stream_data_mode = qpdf_s_uncompress;
}
@@ -669,22 +668,22 @@ QPDFJob::Config::streamData(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::decodeLevel(char const* parameter)
+QPDFJob::Config::decodeLevel(std::string const& parameter)
{
o.m->decode_level_set = true;
- if (strcmp(parameter, "none") == 0)
+ if (parameter == "none")
{
o.m->decode_level = qpdf_dl_none;
}
- else if (strcmp(parameter, "generalized") == 0)
+ else if (parameter == "generalized")
{
o.m->decode_level = qpdf_dl_generalized;
}
- else if (strcmp(parameter, "specialized") == 0)
+ else if (parameter == "specialized")
{
o.m->decode_level = qpdf_dl_specialized;
}
- else if (strcmp(parameter, "all") == 0)
+ else if (parameter == "all")
{
o.m->decode_level = qpdf_dl_all;
}
@@ -696,18 +695,18 @@ QPDFJob::Config::decodeLevel(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::objectStreams(char const* parameter)
+QPDFJob::Config::objectStreams(std::string const& parameter)
{
o.m->object_stream_set = true;
- if (strcmp(parameter, "disable") == 0)
+ if (parameter == "disable")
{
o.m->object_stream_mode = qpdf_o_disable;
}
- else if (strcmp(parameter, "preserve") == 0)
+ else if (parameter == "preserve")
{
o.m->object_stream_mode = qpdf_o_preserve;
}
- else if (strcmp(parameter, "generate") == 0)
+ else if (parameter == "generate")
{
o.m->object_stream_mode = qpdf_o_generate;
}
@@ -719,17 +718,17 @@ QPDFJob::Config::objectStreams(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::removeUnreferencedResources(char const* parameter)
+QPDFJob::Config::removeUnreferencedResources(std::string const& parameter)
{
- if (strcmp(parameter, "auto") == 0)
+ if (parameter == "auto")
{
o.m->remove_unreferenced_page_resources = QPDFJob::re_auto;
}
- else if (strcmp(parameter, "yes") == 0)
+ else if (parameter == "yes")
{
o.m->remove_unreferenced_page_resources = QPDFJob::re_yes;
}
- else if (strcmp(parameter, "no") == 0)
+ else if (parameter == "no")
{
o.m->remove_unreferenced_page_resources = QPDFJob::re_no;
}
@@ -741,7 +740,7 @@ QPDFJob::Config::removeUnreferencedResources(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::showObject(char const* parameter)
+QPDFJob::Config::showObject(std::string const& parameter)
{
QPDFJob::parse_object_id(
parameter, o.m->show_trailer, o.m->show_obj, o.m->show_gen);
@@ -750,11 +749,11 @@ QPDFJob::Config::showObject(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::jobJsonFile(char const* parameter)
+QPDFJob::Config::jobJsonFile(std::string const& parameter)
{
PointerHolder<char> file_buf;
size_t size;
- QUtil::read_file_into_memory(parameter, file_buf, size);
+ QUtil::read_file_into_memory(parameter.c_str(), file_buf, size);
try
{
o.initializeFromJson(std::string(file_buf.getPointer(), size), true);
@@ -770,7 +769,7 @@ QPDFJob::Config::jobJsonFile(char const* parameter)
}
QPDFJob::Config*
-QPDFJob::Config::rotate(char const* parameter)
+QPDFJob::Config::rotate(std::string const& parameter)
{
o.parseRotationParameter(parameter);
return this;
@@ -788,21 +787,21 @@ QPDFJob::CopyAttConfig::CopyAttConfig(Config* c) :
}
QPDFJob::CopyAttConfig*
-QPDFJob::CopyAttConfig::file(char const* parameter)
+QPDFJob::CopyAttConfig::file(std::string const& parameter)
{
this->caf.path = parameter;
return this;
}
QPDFJob::CopyAttConfig*
-QPDFJob::CopyAttConfig::prefix(char const* parameter)
+QPDFJob::CopyAttConfig::prefix(std::string const& parameter)
{
this->caf.prefix = parameter;
return this;
}
QPDFJob::CopyAttConfig*
-QPDFJob::CopyAttConfig::password(char const* parameter)
+QPDFJob::CopyAttConfig::password(std::string const& parameter)
{
this->caf.password = parameter;
return this;
@@ -831,28 +830,28 @@ QPDFJob::Config::addAttachment()
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::file(char const* parameter)
+QPDFJob::AttConfig::file(std::string const& parameter)
{
this->att.path = parameter;
return this;
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::key(char const* parameter)
+QPDFJob::AttConfig::key(std::string const& parameter)
{
this->att.key = parameter;
return this;
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::filename(char const* parameter)
+QPDFJob::AttConfig::filename(std::string const& parameter)
{
this->att.filename = parameter;
return this;
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::creationdate(char const* parameter)
+QPDFJob::AttConfig::creationdate(std::string const& parameter)
{
if (! QUtil::pdf_time_to_qpdf_time(parameter))
{
@@ -863,7 +862,7 @@ QPDFJob::AttConfig::creationdate(char const* parameter)
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::moddate(char const* parameter)
+QPDFJob::AttConfig::moddate(std::string const& parameter)
{
if (! QUtil::pdf_time_to_qpdf_time(parameter))
{
@@ -874,9 +873,9 @@ QPDFJob::AttConfig::moddate(char const* parameter)
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::mimetype(char const* parameter)
+QPDFJob::AttConfig::mimetype(std::string const& parameter)
{
- if (strchr(parameter, '/') == nullptr)
+ if (parameter.find('/') == std::string::npos)
{
usage("mime type should be specified as type/subtype");
}
@@ -885,7 +884,7 @@ QPDFJob::AttConfig::mimetype(char const* parameter)
}
QPDFJob::AttConfig*
-QPDFJob::AttConfig::description(char const* parameter)
+QPDFJob::AttConfig::description(std::string const& parameter)
{
this->att.description = parameter;
return this;
@@ -999,7 +998,7 @@ QPDFJob::UOConfig::endUnderlayOverlay()
}
QPDFJob::UOConfig*
-QPDFJob::UOConfig::file(char const* parameter)
+QPDFJob::UOConfig::file(std::string const& parameter)
{
if (! config->o.m->under_overlay->filename.empty())
{
@@ -1013,37 +1012,37 @@ QPDFJob::UOConfig::file(char const* parameter)
}
QPDFJob::UOConfig*
-QPDFJob::UOConfig::to(char const* parameter)
+QPDFJob::UOConfig::to(std::string const& parameter)
{
- config->o.parseNumrange(parameter, 0);
+ config->o.parseNumrange(parameter.c_str(), 0);
config->o.m->under_overlay->to_nr = parameter;
return this;
}
QPDFJob::UOConfig*
-QPDFJob::UOConfig::from(char const* parameter)
+QPDFJob::UOConfig::from(std::string const& parameter)
{
- if (strlen(parameter))
+ if (! parameter.empty())
{
- config->o.parseNumrange(parameter, 0);
+ config->o.parseNumrange(parameter.c_str(), 0);
}
config->o.m->under_overlay->from_nr = parameter;
return this;
}
QPDFJob::UOConfig*
-QPDFJob::UOConfig::repeat(char const* parameter)
+QPDFJob::UOConfig::repeat(std::string const& parameter)
{
- if (strlen(parameter))
+ if (! parameter.empty())
{
- config->o.parseNumrange(parameter, 0);
+ config->o.parseNumrange(parameter.c_str(), 0);
}
config->o.m->under_overlay->repeat_nr = parameter;
return this;
}
QPDFJob::UOConfig*
-QPDFJob::UOConfig::password(char const* parameter)
+QPDFJob::UOConfig::password(std::string const& parameter)
{
config->o.m->under_overlay->password = QUtil::make_shared_cstr(parameter);
return this;
@@ -1086,42 +1085,42 @@ QPDFJob::EncConfig::allowInsecure()
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::accessibility(char const* parameter)
+QPDFJob::EncConfig::accessibility(std::string const& parameter)
{
- config->o.m->r3_accessibility = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_accessibility = (parameter == "y");
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::extract(char const* parameter)
+QPDFJob::EncConfig::extract(std::string const& parameter)
{
if (config->o.m->keylen == 40)
{
- config->o.m->r2_extract = (strcmp(parameter, "y") == 0);
+ config->o.m->r2_extract = (parameter == "y");
}
else
{
- config->o.m->r3_extract = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_extract = (parameter == "y");
}
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::print(char const* parameter)
+QPDFJob::EncConfig::print(std::string const& parameter)
{
if (config->o.m->keylen == 40)
{
- config->o.m->r2_print = (strcmp(parameter, "y") == 0);
+ config->o.m->r2_print = (parameter == "y");
}
- else if (strcmp(parameter, "full") == 0)
+ else if (parameter == "full")
{
config->o.m->r3_print = qpdf_r3p_full;
}
- else if (strcmp(parameter, "low") == 0)
+ else if (parameter == "low")
{
config->o.m->r3_print = qpdf_r3p_low;
}
- else if (strcmp(parameter, "none") == 0)
+ else if (parameter == "none")
{
config->o.m->r3_print = qpdf_r3p_none;
}
@@ -1133,41 +1132,41 @@ QPDFJob::EncConfig::print(char const* parameter)
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::modify(char const* parameter)
+QPDFJob::EncConfig::modify(std::string const& parameter)
{
if (config->o.m->keylen == 40)
{
- config->o.m->r2_modify = (strcmp(parameter, "y") == 0);
+ config->o.m->r2_modify = (parameter == "y");
}
- else if (strcmp(parameter, "all") == 0)
+ else if (parameter == "all")
{
config->o.m->r3_assemble = true;
config->o.m->r3_annotate_and_form = true;
config->o.m->r3_form_filling = true;
config->o.m->r3_modify_other = true;
}
- else if (strcmp(parameter, "annotate") == 0)
+ else if (parameter == "annotate")
{
config->o.m->r3_assemble = true;
config->o.m->r3_annotate_and_form = true;
config->o.m->r3_form_filling = true;
config->o.m->r3_modify_other = false;
}
- else if (strcmp(parameter, "form") == 0)
+ else if (parameter == "form")
{
config->o.m->r3_assemble = true;
config->o.m->r3_annotate_and_form = false;
config->o.m->r3_form_filling = true;
config->o.m->r3_modify_other = false;
}
- else if (strcmp(parameter, "assembly") == 0)
+ else if (parameter == "assembly")
{
config->o.m->r3_assemble = true;
config->o.m->r3_annotate_and_form = false;
config->o.m->r3_form_filling = false;
config->o.m->r3_modify_other = false;
}
- else if (strcmp(parameter, "none") == 0)
+ else if (parameter == "none")
{
config->o.m->r3_assemble = false;
config->o.m->r3_annotate_and_form = false;
@@ -1189,44 +1188,44 @@ QPDFJob::EncConfig::cleartextMetadata()
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::assemble(char const* parameter)
+QPDFJob::EncConfig::assemble(std::string const& parameter)
{
- config->o.m->r3_assemble = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_assemble = (parameter == "y");
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::annotate(char const* parameter)
+QPDFJob::EncConfig::annotate(std::string const& parameter)
{
if (config->o.m->keylen == 40)
{
- config->o.m->r2_annotate = (strcmp(parameter, "y") == 0);
+ config->o.m->r2_annotate = (parameter == "y");
}
else
{
- config->o.m->r3_annotate_and_form = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_annotate_and_form = (parameter == "y");
}
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::form(char const* parameter)
+QPDFJob::EncConfig::form(std::string const& parameter)
{
- config->o.m->r3_form_filling = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_form_filling = (parameter == "y");
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::modifyOther(char const* parameter)
+QPDFJob::EncConfig::modifyOther(std::string const& parameter)
{
- config->o.m->r3_modify_other = (strcmp(parameter, "y") == 0);
+ config->o.m->r3_modify_other = (parameter == "y");
return this;
}
QPDFJob::EncConfig*
-QPDFJob::EncConfig::useAes(char const* parameter)
+QPDFJob::EncConfig::useAes(std::string const& parameter)
{
- config->o.m->use_aes = (strcmp(parameter, "y") == 0);
+ config->o.m->use_aes = (parameter == "y");
return this;
}
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index cfd1bb1e..e8170823 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -2615,9 +2615,9 @@ QUtil::possible_repaired_encodings(std::string supplied)
}
#ifndef QPDF_NO_WCHAR_T
-int
-QUtil::call_main_from_wmain(int argc, wchar_t* argv[],
- std::function<int(int, char*[])> realmain)
+static int
+call_main_from_wmain(bool, int argc, wchar_t const* const argv[],
+ std::function<int(int, char*[])> realmain)
{
// argv contains UTF-16-encoded strings with a 16-bit wchar_t.
// Convert this to UTF-8-encoded strings for compatibility with
@@ -2640,7 +2640,8 @@ QUtil::call_main_from_wmain(int argc, wchar_t* argv[],
utf8_argv.push_back(QUtil::make_shared_cstr(utf8));
}
auto utf8_argv_sp =
- std::shared_ptr<char*>(new char*[1+utf8_argv.size()], std::default_delete<char*[]>());
+ std::shared_ptr<char*>(
+ new char*[1+utf8_argv.size()], std::default_delete<char*[]>());
char** new_argv = utf8_argv_sp.get();
for (size_t i = 0; i < utf8_argv.size(); ++i)
{
@@ -2650,4 +2651,23 @@ QUtil::call_main_from_wmain(int argc, wchar_t* argv[],
new_argv[argc] = 0;
return realmain(argc, new_argv);
}
+
+int
+QUtil::call_main_from_wmain(int argc, wchar_t* argv[],
+ std::function<int(int, char*[])> realmain)
+{
+ return ::call_main_from_wmain(true, argc, argv, realmain);
+}
+
+int
+QUtil::call_main_from_wmain(
+ int argc, wchar_t const* const argv[],
+ std::function<int(int, char const* const[])> realmain)
+{
+ return ::call_main_from_wmain(
+ true, argc, argv, [realmain](int new_argc, char* new_argv[]) {
+ return realmain(new_argc, new_argv);
+ });
+}
+
#endif // QPDF_NO_WCHAR_T
diff --git a/libqpdf/qpdf/QPDFArgParser.hh b/libqpdf/qpdf/QPDFArgParser.hh
index d2515894..cdc850f7 100644
--- a/libqpdf/qpdf/QPDFArgParser.hh
+++ b/libqpdf/qpdf/QPDFArgParser.hh
@@ -21,16 +21,6 @@
// done mostly by automatically-generated code (one-off code for
// qpdf), though the handlers themselves are hand-coded. See
// generate_auto_job at the top of the source tree for details.
-
-// Note about memory: there is code that expects argv to be a char*[],
-// meaning that arguments are writable. Several operations, including
-// reading arguments from a file or parsing a line for bash
-// completion, involve fabricating an argv array. To ensure that the
-// memory is valid and is cleaned up properly, we keep various vectors
-// of smart character pointers that argv points into. In order for
-// those pointers to remain valid, the QPDFArgParser instance must
-// remain in scope for the life of any code that may reference
-// anything from argv.
class QPDFArgParser
{
public:
@@ -38,7 +28,7 @@ class QPDFArgParser
// name of the executable for setting up completion. This may be
// needed if the program is invoked by a wrapper.
QPDF_DLL
- QPDFArgParser(int argc, char* argv[], char const* progname_env);
+ QPDFArgParser(int argc, char const* const argv[], char const* progname_env);
// Calls exit(0) if a help option is given or if in completion
// mode. If there are argument parsing errors, QPDFUsage is
@@ -60,7 +50,7 @@ class QPDFArgParser
// a series of options that end with `--`.
typedef std::function<void()> bare_arg_handler_t;
- typedef std::function<void(char*)> param_arg_handler_t;
+ typedef std::function<void(std::string const&)> param_arg_handler_t;
QPDF_DLL
void selectMainOptionTable();
@@ -163,7 +153,7 @@ class QPDFArgParser
// unknown value returns a string directing the user to run the
// top-level --help option.
QPDF_DLL
- std::string getHelp(char const* topic_or_option);
+ std::string getHelp(std::string const& topic_or_option);
// Convenience methods for adding member functions of a class as
// handlers.
@@ -173,7 +163,7 @@ class QPDFArgParser
return std::bind(std::mem_fn(f), o);
}
template <class T>
- static param_arg_handler_t bindParam(void (T::*f)(char *), T* o)
+ static param_arg_handler_t bindParam(void (T::*f)(std::string const&), T* o)
{
return std::bind(std::mem_fn(f), o, std::placeholders::_1);
}
@@ -238,13 +228,13 @@ class QPDFArgParser
void argCompletionBash();
void argCompletionZsh();
- void argHelp(char*);
- void invalidHelpArg(char*);
+ void argHelp(std::string const&);
+ void invalidHelpArg(std::string const&);
void checkCompletion();
void handleArgFileArguments();
void handleBashArguments();
- void readArgsFromFile(char const* filename);
+ void readArgsFromFile(std::string const& filename);
void doFinalChecks();
void addOptionsToCompletions(option_table_t&);
void addChoicesToCompletions(
@@ -267,12 +257,12 @@ class QPDFArgParser
~Members() = default;
private:
- Members(int argc, char* argv[], char const* progname_env);
+ Members(int argc, char const* const argv[], char const* progname_env);
Members(Members const&) = delete;
int argc;
- char** argv;
- char const* whoami;
+ char const* const* argv;
+ std::string whoami;
std::string progname_env;
int cur_arg;
bool bash_completion;
@@ -287,10 +277,10 @@ class QPDFArgParser
option_table_t* option_table;
std::string option_table_name;
bare_arg_handler_t final_check_handler;
- std::vector<std::shared_ptr<char>> new_argv;
- std::vector<std::shared_ptr<char>> bash_argv;
- std::shared_ptr<char*> argv_ph;
- std::shared_ptr<char*> bash_argv_ph;
+ std::vector<std::shared_ptr<char const>> new_argv;
+ std::vector<std::shared_ptr<char const>> bash_argv;
+ std::shared_ptr<char const*> argv_ph;
+ std::shared_ptr<char const*> bash_argv_ph;
std::map<std::string, HelpTopic> help_topics;
std::map<std::string, HelpTopic> option_help;
std::string help_footer;
diff --git a/libqpdf/qpdf/auto_job_decl.hh b/libqpdf/qpdf/auto_job_decl.hh
index 86b5b293..2671d130 100644
--- a/libqpdf/qpdf/auto_job_decl.hh
+++ b/libqpdf/qpdf/auto_job_decl.hh
@@ -17,7 +17,7 @@ void argCopyright();
void argJsonHelp();
void argShowCrypto();
void argJobJsonHelp();
-void argPositional(char*);
+void argPositional(std::string const&);
void argAddAttachment();
void argCopyAttachmentsFrom();
void argEmpty();
@@ -26,17 +26,17 @@ void argOverlay();
void argPages();
void argReplaceInput();
void argUnderlay();
-void argPagesPositional(char*);
-void argPagesPassword(char *);
+void argPagesPositional(std::string const&);
+void argPagesPassword(std::string const&);
void argEndPages();
-void argEncPositional(char*);
+void argEncPositional(std::string const&);
void argEndEncryption();
void argEnd40BitEncryption();
void argEnd128BitEncryption();
void argEnd256BitEncryption();
-void argUOPositional(char*);
+void argUOPositional(std::string const&);
void argEndUnderlayOverlay();
-void argAttPositional(char*);
+void argAttPositional(std::string const&);
void argEndAttachment();
-void argCopyAttPositional(char*);
+void argCopyAttPositional(std::string const&);
void argEndCopyAttachment();
diff --git a/libqpdf/qpdf/auto_job_init.hh b/libqpdf/qpdf/auto_job_init.hh
index 17ab0848..54506493 100644
--- a/libqpdf/qpdf/auto_job_init.hh
+++ b/libqpdf/qpdf/auto_job_init.hh
@@ -6,7 +6,7 @@
auto b = [this](void (ArgParser::*f)()) {
return QPDFArgParser::bindBare(f, this);
};
-auto p = [this](void (ArgParser::*f)(char *)) {
+auto p = [this](void (ArgParser::*f)(std::string const&)) {
return QPDFArgParser::bindParam(f, this);
};
@@ -79,88 +79,88 @@ this->ap.addBare("underlay", b(&ArgParser::argUnderlay));
this->ap.addBare("verbose", [this](){c_main->verbose();});
this->ap.addBare("warning-exit-0", [this](){c_main->warningExit0();});
this->ap.addBare("with-images", [this](){c_main->withImages();});
-this->ap.addRequiredParameter("compression-level", [this](char *x){c_main->compressionLevel(x);}, "level");
-this->ap.addRequiredParameter("copy-encryption", [this](char *x){c_main->copyEncryption(x);}, "file");
-this->ap.addRequiredParameter("encryption-file-password", [this](char *x){c_main->encryptionFilePassword(x);}, "password");
-this->ap.addRequiredParameter("force-version", [this](char *x){c_main->forceVersion(x);}, "version");
-this->ap.addRequiredParameter("ii-min-bytes", [this](char *x){c_main->iiMinBytes(x);}, "minimum");
-this->ap.addRequiredParameter("job-json-file", [this](char *x){c_main->jobJsonFile(x);}, "file");
-this->ap.addRequiredParameter("json-object", [this](char *x){c_main->jsonObject(x);}, "trailer");
-this->ap.addRequiredParameter("keep-files-open-threshold", [this](char *x){c_main->keepFilesOpenThreshold(x);}, "count");
-this->ap.addRequiredParameter("linearize-pass1", [this](char *x){c_main->linearizePass1(x);}, "filename");
-this->ap.addRequiredParameter("min-version", [this](char *x){c_main->minVersion(x);}, "version");
-this->ap.addRequiredParameter("oi-min-area", [this](char *x){c_main->oiMinArea(x);}, "minimum");
-this->ap.addRequiredParameter("oi-min-height", [this](char *x){c_main->oiMinHeight(x);}, "minimum");
-this->ap.addRequiredParameter("oi-min-width", [this](char *x){c_main->oiMinWidth(x);}, "minimum");
-this->ap.addRequiredParameter("password", [this](char *x){c_main->password(x);}, "password");
-this->ap.addRequiredParameter("password-file", [this](char *x){c_main->passwordFile(x);}, "password");
-this->ap.addRequiredParameter("remove-attachment", [this](char *x){c_main->removeAttachment(x);}, "attachment");
-this->ap.addRequiredParameter("rotate", [this](char *x){c_main->rotate(x);}, "[+|-]angle");
-this->ap.addRequiredParameter("show-attachment", [this](char *x){c_main->showAttachment(x);}, "attachment");
-this->ap.addRequiredParameter("show-object", [this](char *x){c_main->showObject(x);}, "trailer");
-this->ap.addOptionalParameter("collate", [this](char *x){c_main->collate(x);});
-this->ap.addOptionalParameter("split-pages", [this](char *x){c_main->splitPages(x);});
-this->ap.addChoices("compress-streams", [this](char *x){c_main->compressStreams(x);}, true, yn_choices);
-this->ap.addChoices("decode-level", [this](char *x){c_main->decodeLevel(x);}, true, decode_level_choices);
-this->ap.addChoices("flatten-annotations", [this](char *x){c_main->flattenAnnotations(x);}, true, flatten_choices);
-this->ap.addChoices("json-key", [this](char *x){c_main->jsonKey(x);}, true, json_key_choices);
-this->ap.addChoices("keep-files-open", [this](char *x){c_main->keepFilesOpen(x);}, true, yn_choices);
-this->ap.addChoices("normalize-content", [this](char *x){c_main->normalizeContent(x);}, true, yn_choices);
-this->ap.addChoices("object-streams", [this](char *x){c_main->objectStreams(x);}, true, object_streams_choices);
-this->ap.addChoices("password-mode", [this](char *x){c_main->passwordMode(x);}, true, password_mode_choices);
-this->ap.addChoices("remove-unreferenced-resources", [this](char *x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices);
-this->ap.addChoices("stream-data", [this](char *x){c_main->streamData(x);}, true, stream_data_choices);
-this->ap.addChoices("json", [this](char *x){c_main->json(x);}, false, json_version_choices);
+this->ap.addRequiredParameter("compression-level", [this](std::string const& x){c_main->compressionLevel(x);}, "level");
+this->ap.addRequiredParameter("copy-encryption", [this](std::string const& x){c_main->copyEncryption(x);}, "file");
+this->ap.addRequiredParameter("encryption-file-password", [this](std::string const& x){c_main->encryptionFilePassword(x);}, "password");
+this->ap.addRequiredParameter("force-version", [this](std::string const& x){c_main->forceVersion(x);}, "version");
+this->ap.addRequiredParameter("ii-min-bytes", [this](std::string const& x){c_main->iiMinBytes(x);}, "minimum");
+this->ap.addRequiredParameter("job-json-file", [this](std::string const& x){c_main->jobJsonFile(x);}, "file");
+this->ap.addRequiredParameter("json-object", [this](std::string const& x){c_main->jsonObject(x);}, "trailer");
+this->ap.addRequiredParameter("keep-files-open-threshold", [this](std::string const& x){c_main->keepFilesOpenThreshold(x);}, "count");
+this->ap.addRequiredParameter("linearize-pass1", [this](std::string const& x){c_main->linearizePass1(x);}, "filename");
+this->ap.addRequiredParameter("min-version", [this](std::string const& x){c_main->minVersion(x);}, "version");
+this->ap.addRequiredParameter("oi-min-area", [this](std::string const& x){c_main->oiMinArea(x);}, "minimum");
+this->ap.addRequiredParameter("oi-min-height", [this](std::string const& x){c_main->oiMinHeight(x);}, "minimum");
+this->ap.addRequiredParameter("oi-min-width", [this](std::string const& x){c_main->oiMinWidth(x);}, "minimum");
+this->ap.addRequiredParameter("password", [this](std::string const& x){c_main->password(x);}, "password");
+this->ap.addRequiredParameter("password-file", [this](std::string const& x){c_main->passwordFile(x);}, "password");
+this->ap.addRequiredParameter("remove-attachment", [this](std::string const& x){c_main->removeAttachment(x);}, "attachment");
+this->ap.addRequiredParameter("rotate", [this](std::string const& x){c_main->rotate(x);}, "[+|-]angle");
+this->ap.addRequiredParameter("show-attachment", [this](std::string const& x){c_main->showAttachment(x);}, "attachment");
+this->ap.addRequiredParameter("show-object", [this](std::string const& x){c_main->showObject(x);}, "trailer");
+this->ap.addOptionalParameter("collate", [this](std::string const& x){c_main->collate(x);});
+this->ap.addOptionalParameter("split-pages", [this](std::string const& x){c_main->splitPages(x);});
+this->ap.addChoices("compress-streams", [this](std::string const& x){c_main->compressStreams(x);}, true, yn_choices);
+this->ap.addChoices("decode-level", [this](std::string const& x){c_main->decodeLevel(x);}, true, decode_level_choices);
+this->ap.addChoices("flatten-annotations", [this](std::string const& x){c_main->flattenAnnotations(x);}, true, flatten_choices);
+this->ap.addChoices("json-key", [this](std::string const& x){c_main->jsonKey(x);}, true, json_key_choices);
+this->ap.addChoices("keep-files-open", [this](std::string const& x){c_main->keepFilesOpen(x);}, true, yn_choices);
+this->ap.addChoices("normalize-content", [this](std::string const& x){c_main->normalizeContent(x);}, true, yn_choices);
+this->ap.addChoices("object-streams", [this](std::string const& x){c_main->objectStreams(x);}, true, object_streams_choices);
+this->ap.addChoices("password-mode", [this](std::string const& x){c_main->passwordMode(x);}, true, password_mode_choices);
+this->ap.addChoices("remove-unreferenced-resources", [this](std::string const& x){c_main->removeUnreferencedResources(x);}, true, remove_unref_choices);
+this->ap.addChoices("stream-data", [this](std::string const& x){c_main->streamData(x);}, true, stream_data_choices);
+this->ap.addChoices("json", [this](std::string const& x){c_main->json(x);}, false, json_version_choices);
this->ap.registerOptionTable("pages", b(&ArgParser::argEndPages));
this->ap.addPositional(p(&ArgParser::argPagesPositional));
this->ap.addRequiredParameter("password", p(&ArgParser::argPagesPassword), "password");
this->ap.registerOptionTable("encryption", b(&ArgParser::argEndEncryption));
this->ap.addPositional(p(&ArgParser::argEncPositional));
this->ap.registerOptionTable("40-bit encryption", b(&ArgParser::argEnd40BitEncryption));
-this->ap.addChoices("extract", [this](char *x){c_enc->extract(x);}, true, yn_choices);
-this->ap.addChoices("annotate", [this](char *x){c_enc->annotate(x);}, true, yn_choices);
-this->ap.addChoices("print", [this](char *x){c_enc->print(x);}, true, yn_choices);
-this->ap.addChoices("modify", [this](char *x){c_enc->modify(x);}, true, yn_choices);
+this->ap.addChoices("extract", [this](std::string const& x){c_enc->extract(x);}, true, yn_choices);
+this->ap.addChoices("annotate", [this](std::string const& x){c_enc->annotate(x);}, true, yn_choices);
+this->ap.addChoices("print", [this](std::string const& x){c_enc->print(x);}, true, yn_choices);
+this->ap.addChoices("modify", [this](std::string const& x){c_enc->modify(x);}, true, yn_choices);
this->ap.registerOptionTable("128-bit encryption", b(&ArgParser::argEnd128BitEncryption));
this->ap.addBare("cleartext-metadata", [this](){c_enc->cleartextMetadata();});
this->ap.addBare("force-V4", [this](){c_enc->forceV4();});
-this->ap.addChoices("accessibility", [this](char *x){c_enc->accessibility(x);}, true, yn_choices);
-this->ap.addChoices("extract", [this](char *x){c_enc->extract(x);}, true, yn_choices);
-this->ap.addChoices("print", [this](char *x){c_enc->print(x);}, true, print128_choices);
-this->ap.addChoices("assemble", [this](char *x){c_enc->assemble(x);}, true, yn_choices);
-this->ap.addChoices("annotate", [this](char *x){c_enc->annotate(x);}, true, yn_choices);
-this->ap.addChoices("form", [this](char *x){c_enc->form(x);}, true, yn_choices);
-this->ap.addChoices("modify-other", [this](char *x){c_enc->modifyOther(x);}, true, yn_choices);
-this->ap.addChoices("modify", [this](char *x){c_enc->modify(x);}, true, modify128_choices);
-this->ap.addChoices("use-aes", [this](char *x){c_enc->useAes(x);}, true, yn_choices);
+this->ap.addChoices("accessibility", [this](std::string const& x){c_enc->accessibility(x);}, true, yn_choices);
+this->ap.addChoices("extract", [this](std::string const& x){c_enc->extract(x);}, true, yn_choices);
+this->ap.addChoices("print", [this](std::string const& x){c_enc->print(x);}, true, print128_choices);
+this->ap.addChoices("assemble", [this](std::string const& x){c_enc->assemble(x);}, true, yn_choices);
+this->ap.addChoices("annotate", [this](std::string const& x){c_enc->annotate(x);}, true, yn_choices);
+this->ap.addChoices("form", [this](std::string const& x){c_enc->form(x);}, true, yn_choices);
+this->ap.addChoices("modify-other", [this](std::string const& x){c_enc->modifyOther(x);}, true, yn_choices);
+this->ap.addChoices("modify", [this](std::string const& x){c_enc->modify(x);}, true, modify128_choices);
+this->ap.addChoices("use-aes", [this](std::string const& x){c_enc->useAes(x);}, true, yn_choices);
this->ap.registerOptionTable("256-bit encryption", b(&ArgParser::argEnd256BitEncryption));
this->ap.addBare("cleartext-metadata", [this](){c_enc->cleartextMetadata();});
this->ap.addBare("force-R5", [this](){c_enc->forceR5();});
this->ap.addBare("allow-insecure", [this](){c_enc->allowInsecure();});
-this->ap.addChoices("accessibility", [this](char *x){c_enc->accessibility(x);}, true, yn_choices);
-this->ap.addChoices("extract", [this](char *x){c_enc->extract(x);}, true, yn_choices);
-this->ap.addChoices("print", [this](char *x){c_enc->print(x);}, true, print128_choices);
-this->ap.addChoices("assemble", [this](char *x){c_enc->assemble(x);}, true, yn_choices);
-this->ap.addChoices("annotate", [this](char *x){c_enc->annotate(x);}, true, yn_choices);
-this->ap.addChoices("form", [this](char *x){c_enc->form(x);}, true, yn_choices);
-this->ap.addChoices("modify-other", [this](char *x){c_enc->modifyOther(x);}, true, yn_choices);
-this->ap.addChoices("modify", [this](char *x){c_enc->modify(x);}, true, modify128_choices);
+this->ap.addChoices("accessibility", [this](std::string const& x){c_enc->accessibility(x);}, true, yn_choices);
+this->ap.addChoices("extract", [this](std::string const& x){c_enc->extract(x);}, true, yn_choices);
+this->ap.addChoices("print", [this](std::string const& x){c_enc->print(x);}, true, print128_choices);
+this->ap.addChoices("assemble", [this](std::string const& x){c_enc->assemble(x);}, true, yn_choices);
+this->ap.addChoices("annotate", [this](std::string const& x){c_enc->annotate(x);}, true, yn_choices);
+this->ap.addChoices("form", [this](std::string const& x){c_enc->form(x);}, true, yn_choices);
+this->ap.addChoices("modify-other", [this](std::string const& x){c_enc->modifyOther(x);}, true, yn_choices);
+this->ap.addChoices("modify", [this](std::string const& x){c_enc->modify(x);}, true, modify128_choices);
this->ap.registerOptionTable("underlay/overlay", b(&ArgParser::argEndUnderlayOverlay));
this->ap.addPositional(p(&ArgParser::argUOPositional));
-this->ap.addRequiredParameter("to", [this](char *x){c_uo->to(x);}, "page-range");
-this->ap.addRequiredParameter("from", [this](char *x){c_uo->from(x);}, "page-range");
-this->ap.addRequiredParameter("repeat", [this](char *x){c_uo->repeat(x);}, "page-range");
-this->ap.addRequiredParameter("password", [this](char *x){c_uo->password(x);}, "password");
+this->ap.addRequiredParameter("to", [this](std::string const& x){c_uo->to(x);}, "page-range");
+this->ap.addRequiredParameter("from", [this](std::string const& x){c_uo->from(x);}, "page-range");
+this->ap.addRequiredParameter("repeat", [this](std::string const& x){c_uo->repeat(x);}, "page-range");
+this->ap.addRequiredParameter("password", [this](std::string const& x){c_uo->password(x);}, "password");
this->ap.registerOptionTable("attachment", b(&ArgParser::argEndAttachment));
this->ap.addPositional(p(&ArgParser::argAttPositional));
this->ap.addBare("replace", [this](){c_att->replace();});
-this->ap.addRequiredParameter("key", [this](char *x){c_att->key(x);}, "attachment-key");
-this->ap.addRequiredParameter("filename", [this](char *x){c_att->filename(x);}, "filename");
-this->ap.addRequiredParameter("creationdate", [this](char *x){c_att->creationdate(x);}, "creation-date");
-this->ap.addRequiredParameter("moddate", [this](char *x){c_att->moddate(x);}, "modification-date");
-this->ap.addRequiredParameter("mimetype", [this](char *x){c_att->mimetype(x);}, "mime/type");
-this->ap.addRequiredParameter("description", [this](char *x){c_att->description(x);}, "description");
+this->ap.addRequiredParameter("key", [this](std::string const& x){c_att->key(x);}, "attachment-key");
+this->ap.addRequiredParameter("filename", [this](std::string const& x){c_att->filename(x);}, "filename");
+this->ap.addRequiredParameter("creationdate", [this](std::string const& x){c_att->creationdate(x);}, "creation-date");
+this->ap.addRequiredParameter("moddate", [this](std::string const& x){c_att->moddate(x);}, "modification-date");
+this->ap.addRequiredParameter("mimetype", [this](std::string const& x){c_att->mimetype(x);}, "mime/type");
+this->ap.addRequiredParameter("description", [this](std::string const& x){c_att->description(x);}, "description");
this->ap.registerOptionTable("copy attachment", b(&ArgParser::argEndCopyAttachment));
this->ap.addPositional(p(&ArgParser::argCopyAttPositional));
-this->ap.addRequiredParameter("prefix", [this](char *x){c_copy_att->prefix(x);}, "prefix");
-this->ap.addRequiredParameter("password", [this](char *x){c_copy_att->password(x);}, "password");
+this->ap.addRequiredParameter("prefix", [this](std::string const& x){c_copy_att->prefix(x);}, "prefix");
+this->ap.addRequiredParameter("password", [this](std::string const& x){c_copy_att->password(x);}, "password");
diff --git a/libqpdf/qpdf/auto_job_json_init.hh b/libqpdf/qpdf/auto_job_json_init.hh
index 833d5471..01a22167 100644
--- a/libqpdf/qpdf/auto_job_json_init.hh
+++ b/libqpdf/qpdf/auto_job_json_init.hh
@@ -22,7 +22,7 @@ pushKey("password");
setupPassword();
popHandler(); // key: password
pushKey("passwordFile");
-addParameter([this](char const* p) { c_main->passwordFile(p); });
+addParameter([this](std::string const& p) { c_main->passwordFile(p); });
popHandler(); // key: passwordFile
pushKey("empty");
setupEmpty();
@@ -43,19 +43,19 @@ pushKey("newlineBeforeEndstream");
addBare([this]() { c_main->newlineBeforeEndstream(); });
popHandler(); // key: newlineBeforeEndstream
pushKey("normalizeContent");
-addChoices(yn_choices, true, [this](char const* p) { c_main->normalizeContent(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_main->normalizeContent(p); });
popHandler(); // key: normalizeContent
pushKey("streamData");
-addChoices(stream_data_choices, true, [this](char const* p) { c_main->streamData(p); });
+addChoices(stream_data_choices, true, [this](std::string const& p) { c_main->streamData(p); });
popHandler(); // key: streamData
pushKey("compressStreams");
-addChoices(yn_choices, true, [this](char const* p) { c_main->compressStreams(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_main->compressStreams(p); });
popHandler(); // key: compressStreams
pushKey("recompressFlate");
addBare([this]() { c_main->recompressFlate(); });
popHandler(); // key: recompressFlate
pushKey("decodeLevel");
-addChoices(decode_level_choices, true, [this](char const* p) { c_main->decodeLevel(p); });
+addChoices(decode_level_choices, true, [this](std::string const& p) { c_main->decodeLevel(p); });
popHandler(); // key: decodeLevel
pushKey("decrypt");
addBare([this]() { c_main->decrypt(); });
@@ -73,31 +73,31 @@ pushKey("noOriginalObjectIds");
addBare([this]() { c_main->noOriginalObjectIds(); });
popHandler(); // key: noOriginalObjectIds
pushKey("copyEncryption");
-addParameter([this](char const* p) { c_main->copyEncryption(p); });
+addParameter([this](std::string const& p) { c_main->copyEncryption(p); });
popHandler(); // key: copyEncryption
pushKey("encryptionFilePassword");
-addParameter([this](char const* p) { c_main->encryptionFilePassword(p); });
+addParameter([this](std::string const& p) { c_main->encryptionFilePassword(p); });
popHandler(); // key: encryptionFilePassword
pushKey("linearize");
addBare([this]() { c_main->linearize(); });
popHandler(); // key: linearize
pushKey("linearizePass1");
-addParameter([this](char const* p) { c_main->linearizePass1(p); });
+addParameter([this](std::string const& p) { c_main->linearizePass1(p); });
popHandler(); // key: linearizePass1
pushKey("objectStreams");
-addChoices(object_streams_choices, true, [this](char const* p) { c_main->objectStreams(p); });
+addChoices(object_streams_choices, true, [this](std::string const& p) { c_main->objectStreams(p); });
popHandler(); // key: objectStreams
pushKey("minVersion");
-addParameter([this](char const* p) { c_main->minVersion(p); });
+addParameter([this](std::string const& p) { c_main->minVersion(p); });
popHandler(); // key: minVersion
pushKey("forceVersion");
-addParameter([this](char const* p) { c_main->forceVersion(p); });
+addParameter([this](std::string const& p) { c_main->forceVersion(p); });
popHandler(); // key: forceVersion
pushKey("progress");
addBare([this]() { c_main->progress(); });
popHandler(); // key: progress
pushKey("splitPages");
-addParameter([this](char const* p) { c_main->splitPages(p); });
+addParameter([this](std::string const& p) { c_main->splitPages(p); });
popHandler(); // key: splitPages
pushKey("encrypt");
beginDict(bindJSON(&Handlers::beginEncrypt), bindBare(&Handlers::endEncrypt)); // .encrypt
@@ -110,82 +110,82 @@ popHandler(); // key: ownerPassword
pushKey("40bit");
beginDict(bindJSON(&Handlers::beginEncrypt40bit), bindBare(&Handlers::endEncrypt40bit)); // .encrypt.40bit
pushKey("annotate");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->annotate(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->annotate(p); });
popHandler(); // key: annotate
pushKey("extract");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->extract(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->extract(p); });
popHandler(); // key: extract
pushKey("modify");
-addChoices(modify128_choices, true, [this](char const* p) { c_enc->modify(p); });
+addChoices(modify128_choices, true, [this](std::string const& p) { c_enc->modify(p); });
popHandler(); // key: modify
pushKey("print");
-addChoices(print128_choices, true, [this](char const* p) { c_enc->print(p); });
+addChoices(print128_choices, true, [this](std::string const& p) { c_enc->print(p); });
popHandler(); // key: print
popHandler(); // key: 40bit
pushKey("128bit");
beginDict(bindJSON(&Handlers::beginEncrypt128bit), bindBare(&Handlers::endEncrypt128bit)); // .encrypt.128bit
pushKey("accessibility");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->accessibility(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->accessibility(p); });
popHandler(); // key: accessibility
pushKey("annotate");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->annotate(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->annotate(p); });
popHandler(); // key: annotate
pushKey("assemble");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->assemble(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->assemble(p); });
popHandler(); // key: assemble
pushKey("cleartextMetadata");
addBare([this]() { c_enc->cleartextMetadata(); });
popHandler(); // key: cleartextMetadata
pushKey("extract");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->extract(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->extract(p); });
popHandler(); // key: extract
pushKey("form");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->form(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->form(p); });
popHandler(); // key: form
pushKey("modifyOther");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->modifyOther(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->modifyOther(p); });
popHandler(); // key: modifyOther
pushKey("modify");
-addChoices(modify128_choices, true, [this](char const* p) { c_enc->modify(p); });
+addChoices(modify128_choices, true, [this](std::string const& p) { c_enc->modify(p); });
popHandler(); // key: modify
pushKey("print");
-addChoices(print128_choices, true, [this](char const* p) { c_enc->print(p); });
+addChoices(print128_choices, true, [this](std::string const& p) { c_enc->print(p); });
popHandler(); // key: print
pushKey("forceV4");
addBare([this]() { c_enc->forceV4(); });
popHandler(); // key: forceV4
pushKey("useAes");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->useAes(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->useAes(p); });
popHandler(); // key: useAes
popHandler(); // key: 128bit
pushKey("256bit");
beginDict(bindJSON(&Handlers::beginEncrypt256bit), bindBare(&Handlers::endEncrypt256bit)); // .encrypt.256bit
pushKey("accessibility");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->accessibility(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->accessibility(p); });
popHandler(); // key: accessibility
pushKey("annotate");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->annotate(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->annotate(p); });
popHandler(); // key: annotate
pushKey("assemble");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->assemble(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->assemble(p); });
popHandler(); // key: assemble
pushKey("cleartextMetadata");
addBare([this]() { c_enc->cleartextMetadata(); });
popHandler(); // key: cleartextMetadata
pushKey("extract");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->extract(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->extract(p); });
popHandler(); // key: extract
pushKey("form");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->form(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->form(p); });
popHandler(); // key: form
pushKey("modifyOther");
-addChoices(yn_choices, true, [this](char const* p) { c_enc->modifyOther(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_enc->modifyOther(p); });
popHandler(); // key: modifyOther
pushKey("modify");
-addChoices(modify128_choices, true, [this](char const* p) { c_enc->modify(p); });
+addChoices(modify128_choices, true, [this](std::string const& p) { c_enc->modify(p); });
popHandler(); // key: modify
pushKey("print");
-addChoices(print128_choices, true, [this](char const* p) { c_enc->print(p); });
+addChoices(print128_choices, true, [this](std::string const& p) { c_enc->print(p); });
popHandler(); // key: print
pushKey("allowInsecure");
addBare([this]() { c_enc->allowInsecure(); });
@@ -220,7 +220,7 @@ pushKey("showNpages");
addBare([this]() { c_main->showNpages(); });
popHandler(); // key: showNpages
pushKey("showObject");
-addParameter([this](char const* p) { c_main->showObject(p); });
+addParameter([this](std::string const& p) { c_main->showObject(p); });
popHandler(); // key: showObject
pushKey("showPages");
addBare([this]() { c_main->showPages(); });
@@ -235,29 +235,29 @@ pushKey("listAttachments");
addBare([this]() { c_main->listAttachments(); });
popHandler(); // key: listAttachments
pushKey("showAttachment");
-addParameter([this](char const* p) { c_main->showAttachment(p); });
+addParameter([this](std::string const& p) { c_main->showAttachment(p); });
popHandler(); // key: showAttachment
pushKey("json");
-addChoices(json_version_choices, false, [this](char const* p) { c_main->json(p); });
+addChoices(json_version_choices, false, [this](std::string const& p) { c_main->json(p); });
popHandler(); // key: json
pushKey("jsonKey");
beginArray(bindJSON(&Handlers::beginJsonKeyArray), bindBare(&Handlers::endJsonKeyArray)); // .jsonKey[]
-addChoices(json_key_choices, true, [this](char const* p) { c_main->jsonKey(p); });
+addChoices(json_key_choices, true, [this](std::string const& p) { c_main->jsonKey(p); });
popHandler(); // array: .jsonKey[]
popHandler(); // key: jsonKey
pushKey("jsonObject");
beginArray(bindJSON(&Handlers::beginJsonObjectArray), bindBare(&Handlers::endJsonObjectArray)); // .jsonObject[]
-addParameter([this](char const* p) { c_main->jsonObject(p); });
+addParameter([this](std::string const& p) { c_main->jsonObject(p); });
popHandler(); // array: .jsonObject[]
popHandler(); // key: jsonObject
pushKey("allowWeakCrypto");
addBare([this]() { c_main->allowWeakCrypto(); });
popHandler(); // key: allowWeakCrypto
pushKey("keepFilesOpen");
-addChoices(yn_choices, true, [this](char const* p) { c_main->keepFilesOpen(p); });
+addChoices(yn_choices, true, [this](std::string const& p) { c_main->keepFilesOpen(p); });
popHandler(); // key: keepFilesOpen
pushKey("keepFilesOpenThreshold");
-addParameter([this](char const* p) { c_main->keepFilesOpenThreshold(p); });
+addParameter([this](std::string const& p) { c_main->keepFilesOpenThreshold(p); });
popHandler(); // key: keepFilesOpenThreshold
pushKey("noWarn");
addBare([this]() { c_main->noWarn(); });
@@ -272,7 +272,7 @@ pushKey("passwordIsHexKey");
addBare([this]() { c_main->passwordIsHexKey(); });
popHandler(); // key: passwordIsHexKey
pushKey("passwordMode");
-addChoices(password_mode_choices, true, [this](char const* p) { c_main->passwordMode(p); });
+addChoices(password_mode_choices, true, [this](std::string const& p) { c_main->passwordMode(p); });
popHandler(); // key: passwordMode
pushKey("suppressPasswordRecovery");
addBare([this]() { c_main->suppressPasswordRecovery(); });
@@ -284,16 +284,16 @@ pushKey("coalesceContents");
addBare([this]() { c_main->coalesceContents(); });
popHandler(); // key: coalesceContents
pushKey("compressionLevel");
-addParameter([this](char const* p) { c_main->compressionLevel(p); });
+addParameter([this](std::string const& p) { c_main->compressionLevel(p); });
popHandler(); // key: compressionLevel
pushKey("externalizeInlineImages");
addBare([this]() { c_main->externalizeInlineImages(); });
popHandler(); // key: externalizeInlineImages
pushKey("iiMinBytes");
-addParameter([this](char const* p) { c_main->iiMinBytes(p); });
+addParameter([this](std::string const& p) { c_main->iiMinBytes(p); });
popHandler(); // key: iiMinBytes
pushKey("removeUnreferencedResources");
-addChoices(remove_unref_choices, true, [this](char const* p) { c_main->removeUnreferencedResources(p); });
+addChoices(remove_unref_choices, true, [this](std::string const& p) { c_main->removeUnreferencedResources(p); });
popHandler(); // key: removeUnreferencedResources
pushKey("addAttachment");
beginArray(bindJSON(&Handlers::beginAddAttachmentArray), bindBare(&Handlers::endAddAttachmentArray)); // .addAttachment[]
@@ -302,22 +302,22 @@ pushKey("file");
setupAddAttachmentFile();
popHandler(); // key: file
pushKey("creationdate");
-addParameter([this](char const* p) { c_att->creationdate(p); });
+addParameter([this](std::string const& p) { c_att->creationdate(p); });
popHandler(); // key: creationdate
pushKey("description");
-addParameter([this](char const* p) { c_att->description(p); });
+addParameter([this](std::string const& p) { c_att->description(p); });
popHandler(); // key: description
pushKey("filename");
-addParameter([this](char const* p) { c_att->filename(p); });
+addParameter([this](std::string const& p) { c_att->filename(p); });
popHandler(); // key: filename
pushKey("key");
-addParameter([this](char const* p) { c_att->key(p); });
+addParameter([this](std::string const& p) { c_att->key(p); });
popHandler(); // key: key
pushKey("mimetype");
-addParameter([this](char const* p) { c_att->mimetype(p); });
+addParameter([this](std::string const& p) { c_att->mimetype(p); });
popHandler(); // key: mimetype
pushKey("moddate");
-addParameter([this](char const* p) { c_att->moddate(p); });
+addParameter([this](std::string const& p) { c_att->moddate(p); });
popHandler(); // key: moddate
pushKey("replace");
addBare([this]() { c_att->replace(); });
@@ -325,7 +325,7 @@ popHandler(); // key: replace
popHandler(); // array: .addAttachment[]
popHandler(); // key: addAttachment
pushKey("removeAttachment");
-addParameter([this](char const* p) { c_main->removeAttachment(p); });
+addParameter([this](std::string const& p) { c_main->removeAttachment(p); });
popHandler(); // key: removeAttachment
pushKey("copyAttachmentsFrom");
beginArray(bindJSON(&Handlers::beginCopyAttachmentsFromArray), bindBare(&Handlers::endCopyAttachmentsFromArray)); // .copyAttachmentsFrom[]
@@ -337,15 +337,15 @@ pushKey("password");
setupCopyAttachmentsFromPassword();
popHandler(); // key: password
pushKey("prefix");
-addParameter([this](char const* p) { c_copy_att->prefix(p); });
+addParameter([this](std::string const& p) { c_copy_att->prefix(p); });
popHandler(); // key: prefix
popHandler(); // array: .copyAttachmentsFrom[]
popHandler(); // key: copyAttachmentsFrom
pushKey("collate");
-addParameter([this](char const* p) { c_main->collate(p); });
+addParameter([this](std::string const& p) { c_main->collate(p); });
popHandler(); // key: collate
pushKey("flattenAnnotations");
-addChoices(flatten_choices, true, [this](char const* p) { c_main->flattenAnnotations(p); });
+addChoices(flatten_choices, true, [this](std::string const& p) { c_main->flattenAnnotations(p); });
popHandler(); // key: flattenAnnotations
pushKey("flattenRotation");
addBare([this]() { c_main->flattenRotation(); });
@@ -357,13 +357,13 @@ pushKey("keepInlineImages");
addBare([this]() { c_main->keepInlineImages(); });
popHandler(); // key: keepInlineImages
pushKey("oiMinArea");
-addParameter([this](char const* p) { c_main->oiMinArea(p); });
+addParameter([this](std::string const& p) { c_main->oiMinArea(p); });
popHandler(); // key: oiMinArea
pushKey("oiMinHeight");
-addParameter([this](char const* p) { c_main->oiMinHeight(p); });
+addParameter([this](std::string const& p) { c_main->oiMinHeight(p); });
popHandler(); // key: oiMinHeight
pushKey("oiMinWidth");
-addParameter([this](char const* p) { c_main->oiMinWidth(p); });
+addParameter([this](std::string const& p) { c_main->oiMinWidth(p); });
popHandler(); // key: oiMinWidth
pushKey("optimizeImages");
addBare([this]() { c_main->optimizeImages(); });
@@ -386,7 +386,7 @@ pushKey("removePageLabels");
addBare([this]() { c_main->removePageLabels(); });
popHandler(); // key: removePageLabels
pushKey("rotate");
-addParameter([this](char const* p) { c_main->rotate(p); });
+addParameter([this](std::string const& p) { c_main->rotate(p); });
popHandler(); // key: rotate
pushKey("overlay");
beginDict(bindJSON(&Handlers::beginOverlay), bindBare(&Handlers::endOverlay)); // .overlay
@@ -397,13 +397,13 @@ pushKey("password");
setupOverlayPassword();
popHandler(); // key: password
pushKey("from");
-addParameter([this](char const* p) { c_uo->from(p); });
+addParameter([this](std::string const& p) { c_uo->from(p); });
popHandler(); // key: from
pushKey("repeat");
-addParameter([this](char const* p) { c_uo->repeat(p); });
+addParameter([this](std::string const& p) { c_uo->repeat(p); });
popHandler(); // key: repeat
pushKey("to");
-addParameter([this](char const* p) { c_uo->to(p); });
+addParameter([this](std::string const& p) { c_uo->to(p); });
popHandler(); // key: to
popHandler(); // key: overlay
pushKey("underlay");
@@ -415,20 +415,20 @@ pushKey("password");
setupUnderlayPassword();
popHandler(); // key: password
pushKey("from");
-addParameter([this](char const* p) { c_uo->from(p); });
+addParameter([this](std::string const& p) { c_uo->from(p); });
popHandler(); // key: from
pushKey("repeat");
-addParameter([this](char const* p) { c_uo->repeat(p); });
+addParameter([this](std::string const& p) { c_uo->repeat(p); });
popHandler(); // key: repeat
pushKey("to");
-addParameter([this](char const* p) { c_uo->to(p); });
+addParameter([this](std::string const& p) { c_uo->to(p); });
popHandler(); // key: to
popHandler(); // key: underlay
pushKey("warningExit0");
addBare([this]() { c_main->warningExit0(); });
popHandler(); // key: warningExit0
pushKey("jobJsonFile");
-addParameter([this](char const* p) { c_main->jobJsonFile(p); });
+addParameter([this](std::string const& p) { c_main->jobJsonFile(p); });
popHandler(); // key: jobJsonFile
pushKey("preserveUnreferencedResources");
addBare([this]() { c_main->preserveUnreferencedResources(); });
diff --git a/libqpdf/qpdfjob-c.cc b/libqpdf/qpdfjob-c.cc
index 7b3f6b60..e1c76477 100644
--- a/libqpdf/qpdfjob-c.cc
+++ b/libqpdf/qpdfjob-c.cc
@@ -7,9 +7,10 @@
#include <cstdio>
#include <cstring>
-int qpdfjob_run_from_argv(int argc, char* argv[])
+int qpdfjob_run_from_argv(int argc, char const* const argv[])
{
- auto whoami = QUtil::getWhoami(argv[0]);
+ auto whoami_p = QUtil::make_shared_cstr(argv[0]);
+ auto whoami = QUtil::getWhoami(whoami_p.get());
QUtil::setLineBuf(stdout);
QPDFJob j;
@@ -27,7 +28,7 @@ int qpdfjob_run_from_argv(int argc, char* argv[])
}
#ifndef QPDF_NO_WCHAR_T
-int qpdfjob_run_from_wide_argv(int argc, wchar_t* argv[])
+int qpdfjob_run_from_wide_argv(int argc, wchar_t const* const argv[])
{
return QUtil::call_main_from_wmain(argc, argv, qpdfjob_run_from_argv);
}