Commit 6e70d99b58caf545061038c3bd574dfdab2b1c7d

Authored by Jay Berkenbilt
1 parent cb684ec4

QPDFJob increment: generate choices variables in init

generate_auto_job
@@ -22,6 +22,7 @@ class Main: @@ -22,6 +22,7 @@ class Main:
22 SOURCES = [whoami, 'job.yml'] 22 SOURCES = [whoami, 'job.yml']
23 DESTS = { 23 DESTS = {
24 'decl': 'libqpdf/qpdf/auto_job_decl.hh', 24 'decl': 'libqpdf/qpdf/auto_job_decl.hh',
  25 + 'init': 'libqpdf/qpdf/auto_job_init.hh',
25 } 26 }
26 SUMS = 'job.sums' 27 SUMS = 'job.sums'
27 28
@@ -93,6 +94,7 @@ class Main: @@ -93,6 +94,7 @@ class Main:
93 data = yaml.safe_load(f.read()) 94 data = yaml.safe_load(f.read())
94 self.validate(data) 95 self.validate(data)
95 self.generate_decl(data) 96 self.generate_decl(data)
  97 + self.generate_init(data)
96 98
97 # Update hashes last to ensure that this will be rerun in the 99 # Update hashes last to ensure that this will be rerun in the
98 # event of a failure. 100 # event of a failure.
@@ -135,6 +137,15 @@ class Main: @@ -135,6 +137,15 @@ class Main:
135 i = self.to_identifier(table, 'O_', True) 137 i = self.to_identifier(table, 'O_', True)
136 print(f'static constexpr char const* {i} = "{table}";', file=f) 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 if __name__ == '__main__': 150 if __name__ == '__main__':
140 try: 151 try:
job.sums
1 # Generated by generate_auto_job 1 # Generated by generate_auto_job
2 -generate_auto_job e0cbb20dade91ebbab5907a53ba83ed3bb4b6cf4bfa75304a4b88e23906fbb6c 2 +generate_auto_job 82410a924077d975acc27240f7b167cd32e1c358b8b2ea40161e607ee2ac0599
3 job.yml 8c66b75eb06be65dfa40058a52cbc0bc18627a3aade5b3d4e034543605c93298 3 job.yml 8c66b75eb06be65dfa40058a52cbc0bc18627a3aade5b3d4e034543605c93298
4 libqpdf/qpdf/auto_job_decl.hh b098ee02ec853f47850b6421cc72b08c608f303f74f01d0b3ce3df52cecd5ffa 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,6 +188,8 @@ ArgParser::initOptionTable()
188 188
189 this->ap.addFinalCheck(b(&ArgParser::doFinalChecks)); 189 this->ap.addFinalCheck(b(&ArgParser::doFinalChecks));
190 190
  191 +# include <qpdf/auto_job_init.hh>
  192 +
191 this->ap.selectHelpOptionTable(); 193 this->ap.selectHelpOptionTable();
192 this->ap.addBare("help", b(&ArgParser::argHelp)); 194 this->ap.addBare("help", b(&ArgParser::argHelp));
193 this->ap.addBare("version", b(&ArgParser::argVersion)); 195 this->ap.addBare("version", b(&ArgParser::argVersion));
@@ -196,7 +198,6 @@ ArgParser::initOptionTable() @@ -196,7 +198,6 @@ ArgParser::initOptionTable()
196 this->ap.addBare("show-crypto", b(&ArgParser::argShowCrypto)); 198 this->ap.addBare("show-crypto", b(&ArgParser::argShowCrypto));
197 199
198 this->ap.selectMainOptionTable(); 200 this->ap.selectMainOptionTable();
199 - char const* yn[] = {"y", "n", 0};  
200 this->ap.addPositional(p(&ArgParser::argPositional)); 201 this->ap.addPositional(p(&ArgParser::argPositional));
201 this->ap.addRequiredParameter("password", 202 this->ap.addRequiredParameter("password",
202 p(&ArgParser::argPassword), "password"); 203 p(&ArgParser::argPassword), "password");
@@ -208,8 +209,6 @@ ArgParser::initOptionTable() @@ -208,8 +209,6 @@ ArgParser::initOptionTable()
208 this->ap.addBare("password-is-hex-key", b(&ArgParser::argPasswordIsHexKey)); 209 this->ap.addBare("password-is-hex-key", b(&ArgParser::argPasswordIsHexKey));
209 this->ap.addBare("suppress-password-recovery", 210 this->ap.addBare("suppress-password-recovery",
210 b(&ArgParser::argSuppressPasswordRecovery)); 211 b(&ArgParser::argSuppressPasswordRecovery));
211 - char const* password_mode_choices[] =  
212 - {"bytes", "hex-bytes", "unicode", "auto", 0};  
213 this->ap.addRequiredChoices("password-mode", 212 this->ap.addRequiredChoices("password-mode",
214 p(&ArgParser::argPasswordMode), password_mode_choices); 213 p(&ArgParser::argPasswordMode), password_mode_choices);
215 this->ap.addRequiredParameter("copy-encryption", 214 this->ap.addRequiredParameter("copy-encryption",
@@ -218,8 +217,6 @@ ArgParser::initOptionTable() @@ -218,8 +217,6 @@ ArgParser::initOptionTable()
218 p(&ArgParser::argEncryptionFilePassword), "password"); 217 p(&ArgParser::argEncryptionFilePassword), "password");
219 this->ap.addRequiredParameter("rotate", 218 this->ap.addRequiredParameter("rotate",
220 p(&ArgParser::argRotate), "[+|-]angle:page-range"); 219 p(&ArgParser::argRotate), "[+|-]angle:page-range");
221 - char const* stream_data_choices[] =  
222 - {"compress", "preserve", "uncompress", 0};  
223 this->ap.addOptionalParameter("collate",p(&ArgParser::argCollate)); 220 this->ap.addOptionalParameter("collate",p(&ArgParser::argCollate));
224 this->ap.addBare("flatten-rotation", b(&ArgParser::argFlattenRotation)); 221 this->ap.addBare("flatten-rotation", b(&ArgParser::argFlattenRotation));
225 this->ap.addBare("list-attachments", b(&ArgParser::argListAttachments)); 222 this->ap.addBare("list-attachments", b(&ArgParser::argListAttachments));
@@ -233,19 +230,15 @@ ArgParser::initOptionTable() @@ -233,19 +230,15 @@ ArgParser::initOptionTable()
233 this->ap.addRequiredChoices("stream-data", 230 this->ap.addRequiredChoices("stream-data",
234 p(&ArgParser::argStreamData), stream_data_choices); 231 p(&ArgParser::argStreamData), stream_data_choices);
235 this->ap.addRequiredChoices("compress-streams", 232 this->ap.addRequiredChoices("compress-streams",
236 - p(&ArgParser::argCompressStreams), yn); 233 + p(&ArgParser::argCompressStreams), yn_choices);
237 this->ap.addBare("recompress-flate", b(&ArgParser::argRecompressFlate)); 234 this->ap.addBare("recompress-flate", b(&ArgParser::argRecompressFlate));
238 this->ap.addRequiredParameter("compression-level", 235 this->ap.addRequiredParameter("compression-level",
239 p(&ArgParser::argCompressionLevel), "level"); 236 p(&ArgParser::argCompressionLevel), "level");
240 - char const* decode_level_choices[] =  
241 - {"none", "generalized", "specialized", "all", 0};  
242 this->ap.addRequiredChoices("decode-level", 237 this->ap.addRequiredChoices("decode-level",
243 p(&ArgParser::argDecodeLevel), decode_level_choices); 238 p(&ArgParser::argDecodeLevel), decode_level_choices);
244 this->ap.addRequiredChoices("normalize-content", 239 this->ap.addRequiredChoices("normalize-content",
245 - p(&ArgParser::argNormalizeContent), yn); 240 + p(&ArgParser::argNormalizeContent), yn_choices);
246 this->ap.addBare("suppress-recovery", b(&ArgParser::argSuppressRecovery)); 241 this->ap.addBare("suppress-recovery", b(&ArgParser::argSuppressRecovery));
247 - char const* object_streams_choices[] = {  
248 - "disable", "preserve", "generate", 0};  
249 this->ap.addRequiredChoices("object-streams", 242 this->ap.addRequiredChoices("object-streams",
250 p(&ArgParser::argObjectStreams), object_streams_choices); 243 p(&ArgParser::argObjectStreams), object_streams_choices);
251 this->ap.addBare( 244 this->ap.addBare(
@@ -256,19 +249,16 @@ ArgParser::initOptionTable() @@ -256,19 +249,16 @@ ArgParser::initOptionTable()
256 this->ap.addBare( 249 this->ap.addBare(
257 "preserve-unreferenced-resources", 250 "preserve-unreferenced-resources",
258 b(&ArgParser::argPreserveUnreferencedResources)); 251 b(&ArgParser::argPreserveUnreferencedResources));
259 - char const* remove_unref_choices[] = {  
260 - "auto", "yes", "no", 0};  
261 this->ap.addRequiredChoices("remove-unreferenced-resources", 252 this->ap.addRequiredChoices("remove-unreferenced-resources",
262 p(&ArgParser::argRemoveUnreferencedResources), remove_unref_choices); 253 p(&ArgParser::argRemoveUnreferencedResources), remove_unref_choices);
263 this->ap.addRequiredChoices("keep-files-open", 254 this->ap.addRequiredChoices("keep-files-open",
264 - p(&ArgParser::argKeepFilesOpen), yn); 255 + p(&ArgParser::argKeepFilesOpen), yn_choices);
265 this->ap.addRequiredParameter("keep-files-open-threshold", 256 this->ap.addRequiredParameter("keep-files-open-threshold",
266 p(&ArgParser::argKeepFilesOpenThreshold), "count"); 257 p(&ArgParser::argKeepFilesOpenThreshold), "count");
267 this->ap.addBare("newline-before-endstream", b(&ArgParser::argNewlineBeforeEndstream)); 258 this->ap.addBare("newline-before-endstream", b(&ArgParser::argNewlineBeforeEndstream));
268 this->ap.addRequiredParameter("linearize-pass1", 259 this->ap.addRequiredParameter("linearize-pass1",
269 p(&ArgParser::argLinearizePass1), "filename"); 260 p(&ArgParser::argLinearizePass1), "filename");
270 this->ap.addBare("coalesce-contents", b(&ArgParser::argCoalesceContents)); 261 this->ap.addBare("coalesce-contents", b(&ArgParser::argCoalesceContents));
271 - char const* flatten_choices[] = {"all", "print", "screen", 0};  
272 this->ap.addRequiredChoices("flatten-annotations", 262 this->ap.addRequiredChoices("flatten-annotations",
273 p(&ArgParser::argFlattenAnnotations), flatten_choices); 263 p(&ArgParser::argFlattenAnnotations), flatten_choices);
274 this->ap.addBare("generate-appearances", b(&ArgParser::argGenerateAppearances)); 264 this->ap.addBare("generate-appearances", b(&ArgParser::argGenerateAppearances));
@@ -298,12 +288,6 @@ ArgParser::initOptionTable() @@ -298,12 +288,6 @@ ArgParser::initOptionTable()
298 this->ap.addBare("show-pages", b(&ArgParser::argShowPages)); 288 this->ap.addBare("show-pages", b(&ArgParser::argShowPages));
299 this->ap.addBare("with-images", b(&ArgParser::argWithImages)); 289 this->ap.addBare("with-images", b(&ArgParser::argWithImages));
300 this->ap.addBare("json", b(&ArgParser::argJson)); 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 this->ap.addRequiredChoices("json-key", 291 this->ap.addRequiredChoices("json-key",
308 p(&ArgParser::argJsonKey), json_key_choices); 292 p(&ArgParser::argJsonKey), json_key_choices);
309 this->ap.addRequiredParameter("json-object", 293 this->ap.addRequiredParameter("json-object",
@@ -340,34 +324,31 @@ ArgParser::initOptionTable() @@ -340,34 +324,31 @@ ArgParser::initOptionTable()
340 this->ap.registerOptionTable(O_ENCRYPTION, b(&ArgParser::argEndEncrypt)); 324 this->ap.registerOptionTable(O_ENCRYPTION, b(&ArgParser::argEndEncrypt));
341 this->ap.addPositional(p(&ArgParser::argEncryptPositional)); 325 this->ap.addPositional(p(&ArgParser::argEncryptPositional));
342 this->ap.registerOptionTable(O_40_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); 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 this->ap.registerOptionTable(O_128_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); 331 this->ap.registerOptionTable(O_128_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt));
348 this->ap.registerOptionTable(O_256_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt)); 332 this->ap.registerOptionTable(O_256_BIT_ENCRYPTION, b(&ArgParser::argEndEncrypt));
349 for (char const* k: {O_128_BIT_ENCRYPTION, O_256_BIT_ENCRYPTION}) 333 for (char const* k: {O_128_BIT_ENCRYPTION, O_256_BIT_ENCRYPTION})
350 { 334 {
351 this->ap.selectOptionTable(k); 335 this->ap.selectOptionTable(k);
352 this->ap.addRequiredChoices("accessibility", 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 this->ap.addRequiredChoices("print", 339 this->ap.addRequiredChoices("print",
357 p(&ArgParser::arg128Print), print128_choices); 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 this->ap.addRequiredChoices("modify", 345 this->ap.addRequiredChoices("modify",
365 p(&ArgParser::arg128Modify), modify128_choices); 346 p(&ArgParser::arg128Modify), modify128_choices);
366 this->ap.addBare("cleartext-metadata", b(&ArgParser::arg128ClearTextMetadata)); 347 this->ap.addBare("cleartext-metadata", b(&ArgParser::arg128ClearTextMetadata));
367 } 348 }
368 349
369 this->ap.selectOptionTable(O_128_BIT_ENCRYPTION); 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 this->ap.addBare("force-V4", b(&ArgParser::arg128ForceV4)); 352 this->ap.addBare("force-V4", b(&ArgParser::arg128ForceV4));
372 353
373 this->ap.selectOptionTable(O_256_BIT_ENCRYPTION); 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};