Commit 6e70d99b58caf545061038c3bd574dfdab2b1c7d
1 parent
cb684ec4
QPDFJob increment: generate choices variables in init
Showing
4 changed files
with
44 additions
and
36 deletions
generate_auto_job
| ... | ... | @@ -22,6 +22,7 @@ class Main: |
| 22 | 22 | SOURCES = [whoami, 'job.yml'] |
| 23 | 23 | DESTS = { |
| 24 | 24 | 'decl': 'libqpdf/qpdf/auto_job_decl.hh', |
| 25 | + 'init': 'libqpdf/qpdf/auto_job_init.hh', | |
| 25 | 26 | } |
| 26 | 27 | SUMS = 'job.sums' |
| 27 | 28 | |
| ... | ... | @@ -93,6 +94,7 @@ class Main: |
| 93 | 94 | data = yaml.safe_load(f.read()) |
| 94 | 95 | self.validate(data) |
| 95 | 96 | self.generate_decl(data) |
| 97 | + self.generate_init(data) | |
| 96 | 98 | |
| 97 | 99 | # Update hashes last to ensure that this will be rerun in the |
| 98 | 100 | # event of a failure. |
| ... | ... | @@ -135,6 +137,15 @@ class Main: |
| 135 | 137 | i = self.to_identifier(table, 'O_', True) |
| 136 | 138 | print(f'static constexpr char const* {i} = "{table}";', file=f) |
| 137 | 139 | |
| 140 | + def generate_init(self, data): | |
| 141 | + with open(self.DESTS['init'], 'w') as f: | |
| 142 | + print(BANNER, file=f) | |
| 143 | + for k, v in data['choices'].items(): | |
| 144 | + print(f'char const* {k}_choices[] = {{', file=f, end='') | |
| 145 | + for i in v: | |
| 146 | + print(f'"{i}", ', file=f, end='') | |
| 147 | + print('0};', file=f) | |
| 148 | + | |
| 138 | 149 | |
| 139 | 150 | if __name__ == '__main__': |
| 140 | 151 | try: | ... | ... |
job.sums
| 1 | 1 | # Generated by generate_auto_job |
| 2 | -generate_auto_job e0cbb20dade91ebbab5907a53ba83ed3bb4b6cf4bfa75304a4b88e23906fbb6c | |
| 2 | +generate_auto_job 82410a924077d975acc27240f7b167cd32e1c358b8b2ea40161e607ee2ac0599 | |
| 3 | 3 | job.yml 8c66b75eb06be65dfa40058a52cbc0bc18627a3aade5b3d4e034543605c93298 |
| 4 | 4 | libqpdf/qpdf/auto_job_decl.hh b098ee02ec853f47850b6421cc72b08c608f303f74f01d0b3ce3df52cecd5ffa |
| 5 | +libqpdf/qpdf/auto_job_init.hh 0640167b8d550030c086851408b842e2a93c86577253d78f1b7d41d4ca695bd9 | ... | ... |
libqpdf/QPDFJob_argv.cc
| ... | ... | @@ -188,6 +188,8 @@ ArgParser::initOptionTable() |
| 188 | 188 | |
| 189 | 189 | this->ap.addFinalCheck(b(&ArgParser::doFinalChecks)); |
| 190 | 190 | |
| 191 | +# include <qpdf/auto_job_init.hh> | |
| 192 | + | |
| 191 | 193 | this->ap.selectHelpOptionTable(); |
| 192 | 194 | this->ap.addBare("help", b(&ArgParser::argHelp)); |
| 193 | 195 | this->ap.addBare("version", b(&ArgParser::argVersion)); |
| ... | ... | @@ -196,7 +198,6 @@ ArgParser::initOptionTable() |
| 196 | 198 | this->ap.addBare("show-crypto", b(&ArgParser::argShowCrypto)); |
| 197 | 199 | |
| 198 | 200 | this->ap.selectMainOptionTable(); |
| 199 | - char const* yn[] = {"y", "n", 0}; | |
| 200 | 201 | this->ap.addPositional(p(&ArgParser::argPositional)); |
| 201 | 202 | this->ap.addRequiredParameter("password", |
| 202 | 203 | p(&ArgParser::argPassword), "password"); |
| ... | ... | @@ -208,8 +209,6 @@ ArgParser::initOptionTable() |
| 208 | 209 | this->ap.addBare("password-is-hex-key", b(&ArgParser::argPasswordIsHexKey)); |
| 209 | 210 | this->ap.addBare("suppress-password-recovery", |
| 210 | 211 | b(&ArgParser::argSuppressPasswordRecovery)); |
| 211 | - char const* password_mode_choices[] = | |
| 212 | - {"bytes", "hex-bytes", "unicode", "auto", 0}; | |
| 213 | 212 | this->ap.addRequiredChoices("password-mode", |
| 214 | 213 | p(&ArgParser::argPasswordMode), password_mode_choices); |
| 215 | 214 | this->ap.addRequiredParameter("copy-encryption", |
| ... | ... | @@ -218,8 +217,6 @@ ArgParser::initOptionTable() |
| 218 | 217 | p(&ArgParser::argEncryptionFilePassword), "password"); |
| 219 | 218 | this->ap.addRequiredParameter("rotate", |
| 220 | 219 | p(&ArgParser::argRotate), "[+|-]angle:page-range"); |
| 221 | - char const* stream_data_choices[] = | |
| 222 | - {"compress", "preserve", "uncompress", 0}; | |
| 223 | 220 | this->ap.addOptionalParameter("collate",p(&ArgParser::argCollate)); |
| 224 | 221 | this->ap.addBare("flatten-rotation", b(&ArgParser::argFlattenRotation)); |
| 225 | 222 | this->ap.addBare("list-attachments", b(&ArgParser::argListAttachments)); |
| ... | ... | @@ -233,19 +230,15 @@ ArgParser::initOptionTable() |
| 233 | 230 | this->ap.addRequiredChoices("stream-data", |
| 234 | 231 | p(&ArgParser::argStreamData), stream_data_choices); |
| 235 | 232 | this->ap.addRequiredChoices("compress-streams", |
| 236 | - p(&ArgParser::argCompressStreams), yn); | |
| 233 | + p(&ArgParser::argCompressStreams), yn_choices); | |
| 237 | 234 | this->ap.addBare("recompress-flate", b(&ArgParser::argRecompressFlate)); |
| 238 | 235 | this->ap.addRequiredParameter("compression-level", |
| 239 | 236 | p(&ArgParser::argCompressionLevel), "level"); |
| 240 | - char const* decode_level_choices[] = | |
| 241 | - {"none", "generalized", "specialized", "all", 0}; | |
| 242 | 237 | this->ap.addRequiredChoices("decode-level", |
| 243 | 238 | p(&ArgParser::argDecodeLevel), decode_level_choices); |
| 244 | 239 | this->ap.addRequiredChoices("normalize-content", |
| 245 | - p(&ArgParser::argNormalizeContent), yn); | |
| 240 | + p(&ArgParser::argNormalizeContent), yn_choices); | |
| 246 | 241 | this->ap.addBare("suppress-recovery", b(&ArgParser::argSuppressRecovery)); |
| 247 | - char const* object_streams_choices[] = { | |
| 248 | - "disable", "preserve", "generate", 0}; | |
| 249 | 242 | this->ap.addRequiredChoices("object-streams", |
| 250 | 243 | p(&ArgParser::argObjectStreams), object_streams_choices); |
| 251 | 244 | this->ap.addBare( |
| ... | ... | @@ -256,19 +249,16 @@ ArgParser::initOptionTable() |
| 256 | 249 | this->ap.addBare( |
| 257 | 250 | "preserve-unreferenced-resources", |
| 258 | 251 | b(&ArgParser::argPreserveUnreferencedResources)); |
| 259 | - char const* remove_unref_choices[] = { | |
| 260 | - "auto", "yes", "no", 0}; | |
| 261 | 252 | this->ap.addRequiredChoices("remove-unreferenced-resources", |
| 262 | 253 | p(&ArgParser::argRemoveUnreferencedResources), remove_unref_choices); |
| 263 | 254 | this->ap.addRequiredChoices("keep-files-open", |
| 264 | - p(&ArgParser::argKeepFilesOpen), yn); | |
| 255 | + p(&ArgParser::argKeepFilesOpen), yn_choices); | |
| 265 | 256 | this->ap.addRequiredParameter("keep-files-open-threshold", |
| 266 | 257 | p(&ArgParser::argKeepFilesOpenThreshold), "count"); |
| 267 | 258 | this->ap.addBare("newline-before-endstream", b(&ArgParser::argNewlineBeforeEndstream)); |
| 268 | 259 | this->ap.addRequiredParameter("linearize-pass1", |
| 269 | 260 | p(&ArgParser::argLinearizePass1), "filename"); |
| 270 | 261 | this->ap.addBare("coalesce-contents", b(&ArgParser::argCoalesceContents)); |
| 271 | - char const* flatten_choices[] = {"all", "print", "screen", 0}; | |
| 272 | 262 | this->ap.addRequiredChoices("flatten-annotations", |
| 273 | 263 | p(&ArgParser::argFlattenAnnotations), flatten_choices); |
| 274 | 264 | this->ap.addBare("generate-appearances", b(&ArgParser::argGenerateAppearances)); |
| ... | ... | @@ -298,12 +288,6 @@ ArgParser::initOptionTable() |
| 298 | 288 | this->ap.addBare("show-pages", b(&ArgParser::argShowPages)); |
| 299 | 289 | this->ap.addBare("with-images", b(&ArgParser::argWithImages)); |
| 300 | 290 | this->ap.addBare("json", b(&ArgParser::argJson)); |
| 301 | - // QXXXQ | |
| 302 | - // The list of selectable top-level keys id duplicated in three | |
| 303 | - // places: json_schema, do_json, and initOptionTable. | |
| 304 | - char const* json_key_choices[] = { | |
| 305 | - "objects", "objectinfo", "pages", "pagelabels", "outlines", | |
| 306 | - "acroform", "encrypt", "attachments", 0}; | |
| 307 | 291 | this->ap.addRequiredChoices("json-key", |
| 308 | 292 | p(&ArgParser::argJsonKey), json_key_choices); |
| 309 | 293 | this->ap.addRequiredParameter("json-object", |
| ... | ... | @@ -340,34 +324,31 @@ ArgParser::initOptionTable() |
| 340 | 324 | this->ap.registerOptionTable(O_ENCRYPTION, b(&ArgParser::argEndEncrypt)); |
| 341 | 325 | this->ap.addPositional(p(&ArgParser::argEncryptPositional)); |
| 342 | 326 | this->ap.registerOptionTable(O_40_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); |
| 343 | - this->ap.addRequiredChoices("extract",p(&ArgParser::arg40Extract), yn); | |
| 344 | - this->ap.addRequiredChoices("annotate",p(&ArgParser::arg40Annotate), yn); | |
| 345 | - this->ap.addRequiredChoices("print",p(&ArgParser::arg40Print), yn); | |
| 346 | - this->ap.addRequiredChoices("modify",p(&ArgParser::arg40Modify), yn); | |
| 327 | + this->ap.addRequiredChoices("extract",p(&ArgParser::arg40Extract), yn_choices); | |
| 328 | + this->ap.addRequiredChoices("annotate",p(&ArgParser::arg40Annotate), yn_choices); | |
| 329 | + this->ap.addRequiredChoices("print",p(&ArgParser::arg40Print), yn_choices); | |
| 330 | + this->ap.addRequiredChoices("modify",p(&ArgParser::arg40Modify), yn_choices); | |
| 347 | 331 | this->ap.registerOptionTable(O_128_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); |
| 348 | 332 | this->ap.registerOptionTable(O_256_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); |
| 349 | 333 | for (char const* k: {O_128_BIT_ENCRYPTION, O_256_BIT_ENCRYPTION}) |
| 350 | 334 | { |
| 351 | 335 | this->ap.selectOptionTable(k); |
| 352 | 336 | this->ap.addRequiredChoices("accessibility", |
| 353 | - p(&ArgParser::arg128Accessibility), yn); | |
| 354 | - this->ap.addRequiredChoices("extract", p(&ArgParser::arg128Extract), yn); | |
| 355 | - char const* print128_choices[] = {"full", "low", "none", 0}; | |
| 337 | + p(&ArgParser::arg128Accessibility), yn_choices); | |
| 338 | + this->ap.addRequiredChoices("extract", p(&ArgParser::arg128Extract), yn_choices); | |
| 356 | 339 | this->ap.addRequiredChoices("print", |
| 357 | 340 | p(&ArgParser::arg128Print), print128_choices); |
| 358 | - this->ap.addRequiredChoices("assemble",p(&ArgParser::arg128Assemble), yn); | |
| 359 | - this->ap.addRequiredChoices("annotate",p(&ArgParser::arg128Annotate), yn); | |
| 360 | - this->ap.addRequiredChoices("form",p(&ArgParser::arg128Form), yn); | |
| 361 | - this->ap.addRequiredChoices("modify-other",p(&ArgParser::arg128ModOther), yn); | |
| 362 | - char const* modify128_choices[] = | |
| 363 | - {"all", "annotate", "form", "assembly", "none", 0}; | |
| 341 | + this->ap.addRequiredChoices("assemble",p(&ArgParser::arg128Assemble), yn_choices); | |
| 342 | + this->ap.addRequiredChoices("annotate",p(&ArgParser::arg128Annotate), yn_choices); | |
| 343 | + this->ap.addRequiredChoices("form",p(&ArgParser::arg128Form), yn_choices); | |
| 344 | + this->ap.addRequiredChoices("modify-other",p(&ArgParser::arg128ModOther), yn_choices); | |
| 364 | 345 | this->ap.addRequiredChoices("modify", |
| 365 | 346 | p(&ArgParser::arg128Modify), modify128_choices); |
| 366 | 347 | this->ap.addBare("cleartext-metadata", b(&ArgParser::arg128ClearTextMetadata)); |
| 367 | 348 | } |
| 368 | 349 | |
| 369 | 350 | this->ap.selectOptionTable(O_128_BIT_ENCRYPTION); |
| 370 | - this->ap.addRequiredChoices("use-aes",p(&ArgParser::arg128UseAes), yn); | |
| 351 | + this->ap.addRequiredChoices("use-aes",p(&ArgParser::arg128UseAes), yn_choices); | |
| 371 | 352 | this->ap.addBare("force-V4", b(&ArgParser::arg128ForceV4)); |
| 372 | 353 | |
| 373 | 354 | this->ap.selectOptionTable(O_256_BIT_ENCRYPTION); | ... | ... |
libqpdf/qpdf/auto_job_init.hh
0 → 100644
| 1 | +// | |
| 2 | +// This file is automatically generated by generate_auto_job. | |
| 3 | +// Edits will be automatically overwritten if the build is | |
| 4 | +// run in maintainer mode. | |
| 5 | +// | |
| 6 | +char const* yn_choices[] = {"y", "n", 0}; | |
| 7 | +char const* password_mode_choices[] = {"bytes", "hex-bytes", "unicode", "auto", 0}; | |
| 8 | +char const* stream_data_choices[] = {"compress", "preserve", "uncompress", 0}; | |
| 9 | +char const* decode_level_choices[] = {"none", "generalized", "specialized", "all", 0}; | |
| 10 | +char const* object_streams_choices[] = {"disable", "preserve", "generate", 0}; | |
| 11 | +char const* remove_unref_choices[] = {"auto", "yes", "no", 0}; | |
| 12 | +char const* flatten_choices[] = {"all", "print", "screen", 0}; | |
| 13 | +char const* json_key_choices[] = {"acroform", "attachments", "encrypt", "objectinfo", "objects", "outlines", "pagelabels", "pages", 0}; | |
| 14 | +char const* print128_choices[] = {"full", "low", "none", 0}; | |
| 15 | +char const* modify128_choices[] = {"all", "annotate", "form", "assembly", "none", 0}; | ... | ... |