aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-26 01:01:10 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commit41c5af8f2664cef36d4a1253ba5251603a937605 (patch)
tree60109db66fc61d98eb833eef252ec7e9ac54fbef
parent9373881cca0c781c66b2b50b962bdbc26364abe5 (diff)
downloadqpdf-41c5af8f2664cef36d4a1253ba5251603a937605.tar.zst
QPDFJob: convert pages
-rwxr-xr-xgenerate_auto_job17
-rw-r--r--include/qpdf/QPDFJob.hh41
-rw-r--r--include/qpdf/auto_job_c_pages.hh6
-rw-r--r--job.sums5
-rw-r--r--job.yml10
-rw-r--r--libqpdf/QPDFJob_argv.cc10
-rw-r--r--libqpdf/QPDFJob_config.cc31
7 files changed, 88 insertions, 32 deletions
diff --git a/generate_auto_job b/generate_auto_job
index 94695277..b4a45bad 100755
--- a/generate_auto_job
+++ b/generate_auto_job
@@ -33,17 +33,6 @@ def write_file(filename):
# QXXXQ
-# These need manual handlers.
-complex = set([
- 'add-attachment',
- 'copy-attachments-from',
- 'encrypt',
- 'overlay',
- 'pages',
- 'underlay',
-])
-
-# QXXXQ
# These are trivial but not in main and so need a different config
# object. Some are in more than one table.
not_yet = set([
@@ -466,8 +455,8 @@ class Main:
for i, [kind, v] in flags.items():
self.options_without_help.add(f'--{i}')
add_jdata(i, table_prefix or table)
- # QXXXQ complex, not_yet
- if i in complex or i in not_yet or config is None:
+ # QXXXQ not_yet
+ if i in not_yet or config is None or i in o.get('manual', []):
identifier = self.to_identifier(i, arg_prefix, False)
self.handle_flag(i, identifier, kind, v)
else:
@@ -581,7 +570,7 @@ class Main:
['choices', 'options', 'no-json', 'json']))
for o in data['options']:
self.check_keys('top', o, set(
- ['table', 'prefix', 'config', 'bare', 'positional',
+ ['table', 'prefix', 'config', 'manual', 'bare', 'positional',
'optional_parameter', 'required_parameter',
'required_choices', 'optional_choices', 'from_table']))
diff --git a/include/qpdf/QPDFJob.hh b/include/qpdf/QPDFJob.hh
index 853f7969..5d29e34e 100644
--- a/include/qpdf/QPDFJob.hh
+++ b/include/qpdf/QPDFJob.hh
@@ -135,6 +135,17 @@ class QPDFJob
bool replace;
};
+ struct PageSpec
+ {
+ PageSpec(std::string const& filename,
+ char const* password,
+ std::string const& range);
+
+ std::string filename;
+ std::shared_ptr<char> password;
+ std::string range;
+ };
+
public:
class Config;
@@ -172,6 +183,24 @@ class QPDFJob
CopyAttachmentFrom caf;
};
+ class PagesConfig
+ {
+ friend class QPDFJob;
+ friend class Config;
+ public:
+ PagesConfig& pageSpec(std::string const& filename,
+ char const* password,
+ std::string const& range);
+
+# include <qpdf/auto_job_c_pages.hh>
+
+ private:
+ PagesConfig(Config&);
+ PagesConfig(PagesConfig const&) = delete;
+
+ Config& config;
+ };
+
// Configuration is performed by calling methods XXX QXXXQ document
class Config
{
@@ -180,6 +209,7 @@ class QPDFJob
QPDF_DLL
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
std::shared_ptr<AttConfig> addAttachment();
+ std::shared_ptr<PagesConfig> pages();
# include <qpdf/auto_job_c_main.hh>
@@ -243,17 +273,6 @@ class QPDFJob
static void parse_object_id(
std::string const& objspec, bool& trailer, int& obj, int& gen);
- struct PageSpec
- {
- PageSpec(std::string const& filename,
- char const* password,
- std::string const& range);
-
- std::string filename;
- std::shared_ptr<char> password;
- std::string range;
- };
-
struct RotationSpec
{
RotationSpec(int angle = 0, bool relative = false) :
diff --git a/include/qpdf/auto_job_c_pages.hh b/include/qpdf/auto_job_c_pages.hh
new file mode 100644
index 00000000..0d81c336
--- /dev/null
+++ b/include/qpdf/auto_job_c_pages.hh
@@ -0,0 +1,6 @@
+//
+// This file is automatically generated by generate_auto_job.
+// Edits will be automatically overwritten if the build is
+// run in maintainer mode.
+//
+QPDF_DLL Config& end();
diff --git a/job.sums b/job.sums
index 78fc450a..4eaaeb76 100644
--- a/job.sums
+++ b/job.sums
@@ -1,9 +1,10 @@
# Generated by generate_auto_job
-generate_auto_job d9f75a50dd4e503ede676bad54f80f856de096da7f3ad0e4594b0d09a6e1215d
+generate_auto_job 66e43cdb4ae166d020be19fcc6f8e9f0445c4de6a5395ff5aff511b89763c4e1
include/qpdf/auto_job_c_att.hh ecc3f8f711b486b491e811176362a90c022eb225ff12157df3a10ca021be87b1
include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
include/qpdf/auto_job_c_main.hh 5fdd9c85aa295a3caec467b9607fe82c874cd3aaeb7806b9d18074f7b96fd085
-job.yml e649f7dbb3748584f338b330043336ce4a4d51a34b00b42caa89dcfbc7bdcb84
+include/qpdf/auto_job_c_pages.hh 79ee6e52a36fedfd0e6ca60bd926bc25a3e975ab6fa984a7e798a48791e8ba86
+job.yml 4cd60df0caa74b68cc39352910a8381c3411248bc3edef69f9d16d75e807f451
libqpdf/qpdf/auto_job_decl.hh 38f7462e34fea7d46d5e5519ac1742be6e57ea6f66c47b37d5425f3a2b9ca536
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
libqpdf/qpdf/auto_job_init.hh b49d839078d84398142f8f14bdae8a71f44fbff13cdf7b350b84ef2410aaa6a3
diff --git a/job.yml b/job.yml
index 01ad3630..1b379e3d 100644
--- a/job.yml
+++ b/job.yml
@@ -61,6 +61,13 @@ options:
- job-json-help
- table: main
config: c_main
+ manual:
+ - add-attachment
+ - copy-attachments-from
+ - encrypt
+ - overlay
+ - pages
+ - underlay
positional: true
bare:
- add-attachment
@@ -148,8 +155,11 @@ options:
remove-unreferenced-resources: remove_unref
stream-data: stream_data
- table: pages
+ config: c_pages
prefix: Pages
positional: true
+ manual:
+ - password
required_parameter:
password: password
- table: encryption
diff --git a/libqpdf/QPDFJob_argv.cc b/libqpdf/QPDFJob_argv.cc
index a32818ba..063f77d8 100644
--- a/libqpdf/QPDFJob_argv.cc
+++ b/libqpdf/QPDFJob_argv.cc
@@ -46,6 +46,7 @@ namespace
std::shared_ptr<QPDFJob::Config> c_main;
std::shared_ptr<QPDFJob::CopyAttConfig> c_copy_att;
std::shared_ptr<QPDFJob::AttConfig> c_att;
+ std::shared_ptr<QPDFJob::PagesConfig> c_pages;
std::vector<char*> accumulated_args; // points to member in ap
char* pages_password;
};
@@ -310,6 +311,7 @@ ArgParser::argPages()
usage("the --pages may only be specified one time");
}
this->accumulated_args.clear();
+ this->c_pages = c_main->pages();
this->ap.selectOptionTable(O_PAGES);
}
@@ -402,7 +404,7 @@ ArgParser::argPagesPositional(char* arg)
{
range = "1-z";
}
- o.page_specs.push_back(QPDFJob::PageSpec(file, this->pages_password, range));
+ this->c_pages->pageSpec(file, this->pages_password, range);
this->accumulated_args.clear();
this->pages_password = nullptr;
if (next_file != nullptr)
@@ -415,10 +417,8 @@ void
ArgParser::argEndPages()
{
argPagesPositional(nullptr);
- if (o.page_specs.empty())
- {
- usage("--pages: no page specifications given");
- }
+ c_pages->end();
+ c_pages = nullptr;
}
void
diff --git a/libqpdf/QPDFJob_config.cc b/libqpdf/QPDFJob_config.cc
index 7342aeea..c4961fd3 100644
--- a/libqpdf/QPDFJob_config.cc
+++ b/libqpdf/QPDFJob_config.cc
@@ -657,3 +657,34 @@ QPDFJob::AttConfig::end()
this->config.o.attachments_to_add.push_back(this->att);
return this->config;
}
+
+QPDFJob::PagesConfig::PagesConfig(Config& c) :
+ config(c)
+{
+}
+
+std::shared_ptr<QPDFJob::PagesConfig>
+QPDFJob::Config::pages()
+{
+ return std::shared_ptr<PagesConfig>(new PagesConfig(*this));
+}
+
+QPDFJob::Config&
+QPDFJob::PagesConfig::end()
+{
+ if (this->config.o.page_specs.empty())
+ {
+ throw QPDFJob::ConfigError("--pages: no page specifications given");
+ }
+ return this->config;
+}
+
+QPDFJob::PagesConfig&
+QPDFJob::PagesConfig::pageSpec(std::string const& filename,
+ char const* password,
+ std::string const& range)
+{
+ this->config.o.page_specs.push_back(
+ QPDFJob::PageSpec(filename, password, range));
+ return *this;
+}