diff options
author | Jay Berkenbilt <ejb@ql.org> | 2022-01-06 19:23:15 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2022-01-30 19:11:03 +0100 |
commit | c3e9b64e7fde8499f8543503bdfeeeb65512dcd7 (patch) | |
tree | ce49196b844d1889d33885817f3f2c6e234dd5f5 /generate_auto_job | |
parent | 6e70d99b58caf545061038c3bd574dfdab2b1c7d (diff) | |
download | qpdf-c3e9b64e7fde8499f8543503bdfeeeb65512dcd7.tar.zst |
QPDFJob increment: generate handler declarations
Diffstat (limited to 'generate_auto_job')
-rwxr-xr-x | generate_auto_job | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/generate_auto_job b/generate_auto_job index e2d465b7..1be26453 100755 --- a/generate_auto_job +++ b/generate_auto_job @@ -93,8 +93,12 @@ class Main: with open('job.yml', 'r') as f: data = yaml.safe_load(f.read()) self.validate(data) - self.generate_decl(data) - self.generate_init(data) + with open(self.DESTS['decl'], 'w') as f: + print(BANNER, file=f) + self.generate_decl(data, f) + with open(self.DESTS['init'], 'w') as f: + print(BANNER, file=f) + self.generate_init(data, f) # Update hashes last to ensure that this will be rerun in the # event of a failure. @@ -113,7 +117,7 @@ class Main: self.check_keys('top', data, set(['choices', 'options'])) for o in data['options']: self.check_keys('top', o, set( - ['table', 'bare', 'positional', + ['table', 'prefix', 'bare', 'positional', 'optional_parameter', 'required_parameter', 'required_choices', 'from_table'])) @@ -123,28 +127,46 @@ class Main: identifier = identifier.upper() else: identifier = identifier.lower() - identifier = re.sub('_([a-z])', lambda x: x.group(1).upper(), - identifier) + identifier = re.sub(r'(?:^|_)([a-z])', + lambda x: x.group(1).upper(), + identifier).replace('_', '') return prefix + identifier - def generate_decl(self, data): - with open(self.DESTS['decl'], 'w') as f: - print(BANNER, file=f) - for o in data['options']: - table = o['table'] - if table in ('main', 'help'): - continue - i = self.to_identifier(table, 'O_', True) - print(f'static constexpr char const* {i} = "{table}";', file=f) - - def generate_init(self, data): - with open(self.DESTS['init'], 'w') as f: - print(BANNER, file=f) - for k, v in data['choices'].items(): - print(f'char const* {k}_choices[] = {{', file=f, end='') - for i in v: - print(f'"{i}", ', file=f, end='') - print('0};', file=f) + def generate_decl(self, data, f): + for o in data['options']: + table = o['table'] + if table in ('main', 'help'): + continue + i = self.to_identifier(table, 'O_', True) + print(f'static constexpr char const* {i} = "{table}";', file=f) + print('', file=f) + for o in data['options']: + table = o['table'] + prefix = 'arg' + o.get('prefix', '') + if o.get('positional', False): + print(f'void {prefix}Positional(char*);', file=f) + for i in o.get('bare', []): + identifier = self.to_identifier(i, prefix, False) + print(f'void {identifier}();', file=f) + for i in o.get('optional_parameter', []): + identifier = self.to_identifier(i, prefix, False) + print(f'void {identifier}(char *);', file=f) + for i in o.get('required_parameter', {}): + identifier = self.to_identifier(i, prefix, False) + print(f'void {identifier}(char *);', file=f) + for i in o.get('required_choices', {}): + identifier = self.to_identifier(i, prefix, False) + print(f'void {identifier}(char *);', file=f) + if table not in ('main', 'help'): + identifier = self.to_identifier(table, 'argEnd', False) + print(f'void {identifier}();', file=f) + + def generate_init(self, data, f): + for k, v in data['choices'].items(): + print(f'char const* {k}_choices[] = {{', file=f, end='') + for i in v: + print(f'"{i}", ', file=f, end='') + print('0};', file=f) if __name__ == '__main__': |