mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-02 22:50:20 +00:00
QPDFJob: generate declarations of trivial config methods
This commit is contained in:
parent
f729a336f7
commit
a87dcba13f
@ -94,6 +94,7 @@ class Main:
|
|||||||
'init': 'libqpdf/qpdf/auto_job_init.hh',
|
'init': 'libqpdf/qpdf/auto_job_init.hh',
|
||||||
'help': 'libqpdf/qpdf/auto_job_help.hh',
|
'help': 'libqpdf/qpdf/auto_job_help.hh',
|
||||||
'schema': 'libqpdf/qpdf/auto_job_schema.hh',
|
'schema': 'libqpdf/qpdf/auto_job_schema.hh',
|
||||||
|
# Others are added in top
|
||||||
}
|
}
|
||||||
SUMS = 'job.sums'
|
SUMS = 'job.sums'
|
||||||
|
|
||||||
@ -116,12 +117,24 @@ class Main:
|
|||||||
return parser.parse_args(args)
|
return parser.parse_args(args)
|
||||||
|
|
||||||
def top(self, options):
|
def top(self, options):
|
||||||
|
with open('job.yml', 'r') as f:
|
||||||
|
data = yaml.safe_load(f.read())
|
||||||
|
self.config_decls = {}
|
||||||
|
for o in data['options']:
|
||||||
|
table = o['table']
|
||||||
|
config = o.get('config', None)
|
||||||
|
if config is not None:
|
||||||
|
self.DESTS[config] = f'include/qpdf/auto_job_{config}.hh'
|
||||||
|
self.config_decls[config] = []
|
||||||
|
if table != 'main':
|
||||||
|
self.config_decls[config].append('QPDF_DLL Config& end();')
|
||||||
|
|
||||||
if self.check_hashes():
|
if self.check_hashes():
|
||||||
exit(0)
|
exit(0)
|
||||||
elif options.check:
|
elif options.check:
|
||||||
exit(f'{whoami}: auto job inputs have changed')
|
exit(f'{whoami}: auto job inputs have changed')
|
||||||
elif options.generate:
|
elif options.generate:
|
||||||
self.generate()
|
self.generate(data)
|
||||||
else:
|
else:
|
||||||
exit(f'{whoami} unknown mode')
|
exit(f'{whoami} unknown mode')
|
||||||
|
|
||||||
@ -289,10 +302,8 @@ class Main:
|
|||||||
'Options without help: ' +
|
'Options without help: ' +
|
||||||
', '.join(self.options_without_help))
|
', '.join(self.options_without_help))
|
||||||
|
|
||||||
def generate(self):
|
def generate(self, data):
|
||||||
warn(f'{whoami}: regenerating auto job files')
|
warn(f'{whoami}: regenerating auto job files')
|
||||||
with open('job.yml', 'r') as f:
|
|
||||||
data = yaml.safe_load(f.read())
|
|
||||||
self.validate(data)
|
self.validate(data)
|
||||||
# Add the built-in help options to tables that we populate as
|
# Add the built-in help options to tables that we populate as
|
||||||
# we read job.yml since we won't encounter these in job.yml
|
# we read job.yml since we won't encounter these in job.yml
|
||||||
@ -318,16 +329,21 @@ class Main:
|
|||||||
print('static constexpr char const* JOB_SCHEMA_DATA = R"(' +
|
print('static constexpr char const* JOB_SCHEMA_DATA = R"(' +
|
||||||
json.dumps(self.schema, indent=2, separators=(',', ': ')) +
|
json.dumps(self.schema, indent=2, separators=(',', ': ')) +
|
||||||
')";', file=f)
|
')";', file=f)
|
||||||
|
for k, v in self.config_decls.items():
|
||||||
|
with write_file(self.DESTS[k]) as f:
|
||||||
|
print(BANNER, file=f)
|
||||||
|
for i in v:
|
||||||
|
print(i, file=f)
|
||||||
|
|
||||||
# Update hashes last to ensure that this will be rerun in the
|
# Update hashes last to ensure that this will be rerun in the
|
||||||
# event of a failure.
|
# event of a failure.
|
||||||
self.update_hashes()
|
self.update_hashes()
|
||||||
# DON'T ADD CODE TO generate AFTER update_hashes
|
# DON'T ADD CODE TO generate AFTER update_hashes
|
||||||
|
|
||||||
def handle_trivial(self, i, identifier, cfg, kind, v):
|
def handle_trivial(self, i, identifier, cfg, prefix, kind, v):
|
||||||
# QXXXQ could potentially generate declarations for config
|
decl_arg = 1
|
||||||
# methods separately by config object
|
|
||||||
if kind == 'bare':
|
if kind == 'bare':
|
||||||
|
decl_arg = 0
|
||||||
self.init.append(f'this->ap.addBare("{i}", '
|
self.init.append(f'this->ap.addBare("{i}", '
|
||||||
f'[this](){{{cfg}->{identifier}();}});')
|
f'[this](){{{cfg}->{identifier}();}});')
|
||||||
elif kind == 'optional_parameter':
|
elif kind == 'optional_parameter':
|
||||||
@ -345,6 +361,14 @@ class Main:
|
|||||||
self.init.append(f'this->ap.addChoices("{i}", '
|
self.init.append(f'this->ap.addChoices("{i}", '
|
||||||
f'[this](char *x){{{cfg}->{identifier}(x);}}'
|
f'[this](char *x){{{cfg}->{identifier}(x);}}'
|
||||||
f', false, {v}_choices);')
|
f', false, {v}_choices);')
|
||||||
|
# Generate declarations for config methods separately by
|
||||||
|
# config object.
|
||||||
|
config_class = prefix + 'Config'
|
||||||
|
arg = ''
|
||||||
|
if decl_arg:
|
||||||
|
arg = 'char const* parameter'
|
||||||
|
self.config_decls[cfg].append(
|
||||||
|
f'QPDF_DLL {config_class}& {identifier}({arg});')
|
||||||
|
|
||||||
def handle_flag(self, i, identifier, kind, v):
|
def handle_flag(self, i, identifier, kind, v):
|
||||||
if kind == 'bare':
|
if kind == 'bare':
|
||||||
@ -417,7 +441,9 @@ class Main:
|
|||||||
for o in data['options']:
|
for o in data['options']:
|
||||||
table = o['table']
|
table = o['table']
|
||||||
config = o.get('config', None)
|
config = o.get('config', None)
|
||||||
table_prefix = o.get('prefix', table)
|
table_prefix = o.get('prefix', '')
|
||||||
|
arg_prefix = 'arg' + table_prefix
|
||||||
|
jdata_prefix = table_prefix or table
|
||||||
if table == 'main':
|
if table == 'main':
|
||||||
self.init.append('this->ap.selectMainOptionTable();')
|
self.init.append('this->ap.selectMainOptionTable();')
|
||||||
elif table == 'help':
|
elif table == 'help':
|
||||||
@ -426,12 +452,10 @@ class Main:
|
|||||||
identifier = self.to_identifier(table, 'argEnd', False)
|
identifier = self.to_identifier(table, 'argEnd', False)
|
||||||
self.init.append(f'this->ap.registerOptionTable("{table}",'
|
self.init.append(f'this->ap.registerOptionTable("{table}",'
|
||||||
f' b(&ArgParser::{identifier}));')
|
f' b(&ArgParser::{identifier}));')
|
||||||
prefix = 'arg' + o.get('prefix', '')
|
|
||||||
if o.get('positional', False):
|
if o.get('positional', False):
|
||||||
identifier = self.to_identifier(i, prefix, False)
|
self.decls.append(f'void {arg_prefix}Positional(char*);')
|
||||||
self.decls.append(f'void {prefix}Positional(char*);')
|
|
||||||
self.init.append('this->ap.addPositional('
|
self.init.append('this->ap.addPositional('
|
||||||
f'p(&ArgParser::{prefix}Positional));')
|
f'p(&ArgParser::{arg_prefix}Positional));')
|
||||||
flags = {}
|
flags = {}
|
||||||
|
|
||||||
for i in o.get('bare', []):
|
for i in o.get('bare', []):
|
||||||
@ -448,21 +472,22 @@ class Main:
|
|||||||
|
|
||||||
for i, [kind, v] in flags.items():
|
for i, [kind, v] in flags.items():
|
||||||
self.options_without_help.add(f'--{i}')
|
self.options_without_help.add(f'--{i}')
|
||||||
add_jdata(i, table_prefix)
|
add_jdata(i, table_prefix or table)
|
||||||
# QXXXQ complex, not_yet
|
# QXXXQ complex, not_yet
|
||||||
if i in complex or i in not_yet or config is None:
|
if i in complex or i in not_yet or config is None:
|
||||||
identifier = self.to_identifier(i, prefix, False)
|
identifier = self.to_identifier(i, arg_prefix, False)
|
||||||
self.handle_flag(i, identifier, kind, v)
|
self.handle_flag(i, identifier, kind, v)
|
||||||
else:
|
else:
|
||||||
identifier = self.to_identifier(i, '', False)
|
identifier = self.to_identifier(i, '', False)
|
||||||
self.handle_trivial(i, identifier, config, kind, v)
|
self.handle_trivial(
|
||||||
|
i, identifier, config, table_prefix, kind, v)
|
||||||
|
|
||||||
if table not in ('main', 'help'):
|
if table not in ('main', 'help'):
|
||||||
identifier = self.to_identifier(table, 'argEnd', False)
|
identifier = self.to_identifier(table, 'argEnd', False)
|
||||||
self.decls.append(f'void {identifier}();')
|
self.decls.append(f'void {identifier}();')
|
||||||
for o in data['options']:
|
for o in data['options']:
|
||||||
table = o['table']
|
table = o['table']
|
||||||
table_prefix = o.get('prefix', table)
|
jdata_prefix = o.get('prefix', table)
|
||||||
if 'from_table' not in o:
|
if 'from_table' not in o:
|
||||||
continue
|
continue
|
||||||
if table == 'main':
|
if table == 'main':
|
||||||
@ -476,7 +501,7 @@ class Main:
|
|||||||
for j in ft['options']:
|
for j in ft['options']:
|
||||||
self.init.append('this->ap.copyFromOtherTable'
|
self.init.append('this->ap.copyFromOtherTable'
|
||||||
f'("{j}", "{other_table}");')
|
f'("{j}", "{other_table}");')
|
||||||
add_jdata(j, table_prefix)
|
add_jdata(j, jdata_prefix or table)
|
||||||
|
|
||||||
def generate_schema(self, data):
|
def generate_schema(self, data):
|
||||||
# XXX check data['json'] against what we know from jdata.
|
# XXX check data['json'] against what we know from jdata.
|
||||||
|
@ -116,11 +116,8 @@ class QPDFJob
|
|||||||
friend class Config;
|
friend class Config;
|
||||||
public:
|
public:
|
||||||
QPDF_DLL CopyAttConfig& filename(char const* parameter);
|
QPDF_DLL CopyAttConfig& filename(char const* parameter);
|
||||||
// QXXXQ auto
|
|
||||||
QPDF_DLL CopyAttConfig& prefix(char const* parameter);
|
# include <qpdf/auto_job_c_copy_att.hh>
|
||||||
QPDF_DLL CopyAttConfig& password(char const* parameter);
|
|
||||||
QPDF_DLL Config& end();
|
|
||||||
// /QXXXQ
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CopyAttConfig(Config&);
|
CopyAttConfig(Config&);
|
||||||
@ -138,74 +135,7 @@ class QPDFJob
|
|||||||
QPDF_DLL
|
QPDF_DLL
|
||||||
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
|
std::shared_ptr<CopyAttConfig> copyAttachmentsFrom();
|
||||||
|
|
||||||
// QXXXQ could potentially generate these declarations
|
# include <qpdf/auto_job_c_main.hh>
|
||||||
QPDF_DLL Config& allowWeakCrypto();
|
|
||||||
QPDF_DLL Config& check();
|
|
||||||
QPDF_DLL Config& checkLinearization();
|
|
||||||
QPDF_DLL Config& coalesceContents();
|
|
||||||
QPDF_DLL Config& collate(char const* parameter);
|
|
||||||
QPDF_DLL Config& compressStreams(char const* parameter);
|
|
||||||
QPDF_DLL Config& compressionLevel(char const* parameter);
|
|
||||||
QPDF_DLL Config& copyEncryption(char const* parameter);
|
|
||||||
QPDF_DLL Config& decrypt();
|
|
||||||
QPDF_DLL Config& deterministicId();
|
|
||||||
QPDF_DLL Config& empty();
|
|
||||||
QPDF_DLL Config& encryptionFilePassword(char const* parameter);
|
|
||||||
QPDF_DLL Config& externalizeInlineImages();
|
|
||||||
QPDF_DLL Config& filteredStreamData();
|
|
||||||
QPDF_DLL Config& flattenAnnotations(char const* parameter);
|
|
||||||
QPDF_DLL Config& flattenRotation();
|
|
||||||
QPDF_DLL Config& forceVersion(char const* parameter);
|
|
||||||
QPDF_DLL Config& generateAppearances();
|
|
||||||
QPDF_DLL Config& ignoreXrefStreams();
|
|
||||||
QPDF_DLL Config& iiMinBytes(char const* parameter);
|
|
||||||
QPDF_DLL Config& isEncrypted();
|
|
||||||
QPDF_DLL Config& json();
|
|
||||||
QPDF_DLL Config& jsonKey(char const* parameter);
|
|
||||||
QPDF_DLL Config& jsonObject(char const* parameter);
|
|
||||||
QPDF_DLL Config& keepFilesOpen(char const* parameter);
|
|
||||||
QPDF_DLL Config& keepFilesOpenThreshold(char const* parameter);
|
|
||||||
QPDF_DLL Config& keepInlineImages();
|
|
||||||
QPDF_DLL Config& linearize();
|
|
||||||
QPDF_DLL Config& linearizePass1(char const* parameter);
|
|
||||||
QPDF_DLL Config& listAttachments();
|
|
||||||
QPDF_DLL Config& minVersion(char const* parameter);
|
|
||||||
QPDF_DLL Config& newlineBeforeEndstream();
|
|
||||||
QPDF_DLL Config& noOriginalObjectIds();
|
|
||||||
QPDF_DLL Config& noWarn();
|
|
||||||
QPDF_DLL Config& normalizeContent(char const* parameter);
|
|
||||||
QPDF_DLL Config& oiMinArea(char const* parameter);
|
|
||||||
QPDF_DLL Config& oiMinHeight(char const* parameter);
|
|
||||||
QPDF_DLL Config& oiMinWidth(char const* parameter);
|
|
||||||
QPDF_DLL Config& optimizeImages();
|
|
||||||
QPDF_DLL Config& password(char const* parameter);
|
|
||||||
QPDF_DLL Config& passwordIsHexKey();
|
|
||||||
QPDF_DLL Config& preserveUnreferenced();
|
|
||||||
QPDF_DLL Config& preserveUnreferencedResources();
|
|
||||||
QPDF_DLL Config& progress();
|
|
||||||
QPDF_DLL Config& qdf();
|
|
||||||
QPDF_DLL Config& rawStreamData();
|
|
||||||
QPDF_DLL Config& recompressFlate();
|
|
||||||
QPDF_DLL Config& removeAttachment(char const* parameter);
|
|
||||||
QPDF_DLL Config& removePageLabels();
|
|
||||||
QPDF_DLL Config& replaceInput();
|
|
||||||
QPDF_DLL Config& requiresPassword();
|
|
||||||
QPDF_DLL Config& showAttachment(char const* parameter);
|
|
||||||
QPDF_DLL Config& showEncryption();
|
|
||||||
QPDF_DLL Config& showEncryptionKey();
|
|
||||||
QPDF_DLL Config& showLinearization();
|
|
||||||
QPDF_DLL Config& showNpages();
|
|
||||||
QPDF_DLL Config& showPages();
|
|
||||||
QPDF_DLL Config& showXref();
|
|
||||||
QPDF_DLL Config& splitPages(char const* parameter);
|
|
||||||
QPDF_DLL Config& staticAesIv();
|
|
||||||
QPDF_DLL Config& staticId();
|
|
||||||
QPDF_DLL Config& suppressPasswordRecovery();
|
|
||||||
QPDF_DLL Config& suppressRecovery();
|
|
||||||
QPDF_DLL Config& verbose();
|
|
||||||
QPDF_DLL Config& warningExit0();
|
|
||||||
QPDF_DLL Config& withImages();
|
|
||||||
// /QXXXQ
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config() = delete;
|
Config() = delete;
|
||||||
|
8
include/qpdf/auto_job_c_copy_att.hh
Normal file
8
include/qpdf/auto_job_c_copy_att.hh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//
|
||||||
|
// 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();
|
||||||
|
QPDF_DLL CopyAttConfig& prefix(char const* parameter);
|
||||||
|
QPDF_DLL CopyAttConfig& password(char const* parameter);
|
71
include/qpdf/auto_job_c_main.hh
Normal file
71
include/qpdf/auto_job_c_main.hh
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
//
|
||||||
|
// 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& allowWeakCrypto();
|
||||||
|
QPDF_DLL Config& check();
|
||||||
|
QPDF_DLL Config& checkLinearization();
|
||||||
|
QPDF_DLL Config& coalesceContents();
|
||||||
|
QPDF_DLL Config& decrypt();
|
||||||
|
QPDF_DLL Config& deterministicId();
|
||||||
|
QPDF_DLL Config& empty();
|
||||||
|
QPDF_DLL Config& externalizeInlineImages();
|
||||||
|
QPDF_DLL Config& filteredStreamData();
|
||||||
|
QPDF_DLL Config& flattenRotation();
|
||||||
|
QPDF_DLL Config& generateAppearances();
|
||||||
|
QPDF_DLL Config& ignoreXrefStreams();
|
||||||
|
QPDF_DLL Config& isEncrypted();
|
||||||
|
QPDF_DLL Config& json();
|
||||||
|
QPDF_DLL Config& keepInlineImages();
|
||||||
|
QPDF_DLL Config& linearize();
|
||||||
|
QPDF_DLL Config& listAttachments();
|
||||||
|
QPDF_DLL Config& newlineBeforeEndstream();
|
||||||
|
QPDF_DLL Config& noOriginalObjectIds();
|
||||||
|
QPDF_DLL Config& noWarn();
|
||||||
|
QPDF_DLL Config& optimizeImages();
|
||||||
|
QPDF_DLL Config& passwordIsHexKey();
|
||||||
|
QPDF_DLL Config& preserveUnreferenced();
|
||||||
|
QPDF_DLL Config& preserveUnreferencedResources();
|
||||||
|
QPDF_DLL Config& progress();
|
||||||
|
QPDF_DLL Config& qdf();
|
||||||
|
QPDF_DLL Config& rawStreamData();
|
||||||
|
QPDF_DLL Config& recompressFlate();
|
||||||
|
QPDF_DLL Config& removePageLabels();
|
||||||
|
QPDF_DLL Config& replaceInput();
|
||||||
|
QPDF_DLL Config& requiresPassword();
|
||||||
|
QPDF_DLL Config& showEncryption();
|
||||||
|
QPDF_DLL Config& showEncryptionKey();
|
||||||
|
QPDF_DLL Config& showLinearization();
|
||||||
|
QPDF_DLL Config& showNpages();
|
||||||
|
QPDF_DLL Config& showPages();
|
||||||
|
QPDF_DLL Config& showXref();
|
||||||
|
QPDF_DLL Config& staticAesIv();
|
||||||
|
QPDF_DLL Config& staticId();
|
||||||
|
QPDF_DLL Config& suppressPasswordRecovery();
|
||||||
|
QPDF_DLL Config& suppressRecovery();
|
||||||
|
QPDF_DLL Config& verbose();
|
||||||
|
QPDF_DLL Config& warningExit0();
|
||||||
|
QPDF_DLL Config& withImages();
|
||||||
|
QPDF_DLL Config& collate(char const* parameter);
|
||||||
|
QPDF_DLL Config& splitPages(char const* parameter);
|
||||||
|
QPDF_DLL Config& compressionLevel(char const* parameter);
|
||||||
|
QPDF_DLL Config& copyEncryption(char const* parameter);
|
||||||
|
QPDF_DLL Config& encryptionFilePassword(char const* parameter);
|
||||||
|
QPDF_DLL Config& forceVersion(char const* parameter);
|
||||||
|
QPDF_DLL Config& iiMinBytes(char const* parameter);
|
||||||
|
QPDF_DLL Config& jsonObject(char const* parameter);
|
||||||
|
QPDF_DLL Config& keepFilesOpenThreshold(char const* parameter);
|
||||||
|
QPDF_DLL Config& linearizePass1(char const* parameter);
|
||||||
|
QPDF_DLL Config& minVersion(char const* parameter);
|
||||||
|
QPDF_DLL Config& oiMinArea(char const* parameter);
|
||||||
|
QPDF_DLL Config& oiMinHeight(char const* parameter);
|
||||||
|
QPDF_DLL Config& oiMinWidth(char const* parameter);
|
||||||
|
QPDF_DLL Config& password(char const* parameter);
|
||||||
|
QPDF_DLL Config& removeAttachment(char const* parameter);
|
||||||
|
QPDF_DLL Config& showAttachment(char const* parameter);
|
||||||
|
QPDF_DLL Config& compressStreams(char const* parameter);
|
||||||
|
QPDF_DLL Config& flattenAnnotations(char const* parameter);
|
||||||
|
QPDF_DLL Config& jsonKey(char const* parameter);
|
||||||
|
QPDF_DLL Config& keepFilesOpen(char const* parameter);
|
||||||
|
QPDF_DLL Config& normalizeContent(char const* parameter);
|
4
job.sums
4
job.sums
@ -1,5 +1,7 @@
|
|||||||
# Generated by generate_auto_job
|
# Generated by generate_auto_job
|
||||||
generate_auto_job e18ae51cee2838fe44c37237a344fb48abe7a6d3f9cfa745d2f1dbc9c294e7b7
|
generate_auto_job 36a09904317400caa4a2434f5b2acd59c20905a28479f45bba5e1fcfc654e697
|
||||||
|
include/qpdf/auto_job_c_copy_att.hh caffae3d1faf2cd92a07ba77da638cce31da3e074a047918834195c0f3ed508a
|
||||||
|
include/qpdf/auto_job_c_main.hh 5fdd9c85aa295a3caec467b9607fe82c874cd3aaeb7806b9d18074f7b96fd085
|
||||||
job.yml 55d272cca0657e1f96ca92f5253edb6c6e24e6ea19e37690446d2111adc13f91
|
job.yml 55d272cca0657e1f96ca92f5253edb6c6e24e6ea19e37690446d2111adc13f91
|
||||||
libqpdf/qpdf/auto_job_decl.hh e9844137bf53345f2c6973378b314a2510ebce83ac8ceb378588cd6afdd87c06
|
libqpdf/qpdf/auto_job_decl.hh e9844137bf53345f2c6973378b314a2510ebce83ac8ceb378588cd6afdd87c06
|
||||||
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
libqpdf/qpdf/auto_job_help.hh 383eea80e2c185ef5295fc126246457a7ceeffea759fdb90bb2e6727532ea538
|
||||||
|
Loading…
Reference in New Issue
Block a user