diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-09-10 19:11:27 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2020-09-10 19:11:27 +0200 |
commit | 7e9455b3b15671ff99ed168638c405e2acedb6df (patch) | |
tree | 444e59ece236e09dc153f665e42160aeb0208c24 /backend/pixma/scripts/pixma_gen_options.py | |
parent | bc8a517abd2e11e1435f4ef042cfcc8648b62ef7 (diff) | |
parent | bce41b3c37c2a68e7dab234ce0247755a61ceb40 (diff) |
Merge branch 'release/debian/1.0.31-1_experimental1' into masterdebian/1.0.31-1_experimental1
Diffstat (limited to 'backend/pixma/scripts/pixma_gen_options.py')
-rwxr-xr-x | backend/pixma/scripts/pixma_gen_options.py | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/backend/pixma/scripts/pixma_gen_options.py b/backend/pixma/scripts/pixma_gen_options.py index c4c75e0..cee2c58 100755 --- a/backend/pixma/scripts/pixma_gen_options.py +++ b/backend/pixma/scripts/pixma_gen_options.py @@ -1,6 +1,8 @@ #!/usr/bin/env python +from __future__ import print_function import sys,os,re +import functools class Error(Exception): pass @@ -181,40 +183,35 @@ def parseFile(f): def genHeader(options): - print """ -typedef union { - SANE_Word w; - SANE_Int i; - SANE_Bool b; - SANE_Fixed f; - SANE_String s; - void *ptr; -} option_value_t; -""" - print 'typedef enum {' + print ("\ntypedef union {") + print (" SANE_Word w;") + print (" SANE_Int i;") + print (" SANE_Bool b;") + print (" SANE_Fixed f;") + print (" SANE_String s;") + print (" void *ptr;") + print ("} option_value_t;") + print ("\ntypedef enum {") for o in options: - print ' %(cname_opt)s,' % o - print ' ' + opt_prefix + 'last' - print '} option_t;' - print """ + print (" %(cname_opt)s," % o) + print (" " + opt_prefix + "last") + print ("} option_t;") -typedef struct { - SANE_Option_Descriptor sod; - option_value_t val,def; - SANE_Word info; -} option_descriptor_t; + print ("\ntypedef struct {") + print (" SANE_Option_Descriptor sod;") + print (" option_value_t val,def;") + print (" SANE_Word info;") + print ("} option_descriptor_t;") - -struct pixma_sane_t; -static int build_option_descriptors(struct pixma_sane_t *ss); -""" + print ("\nstruct pixma_sane_t;") + print ("static int build_option_descriptors(struct pixma_sane_t *ss);\n") def genMinMaxRange(n, t, r): if t == 'SANE_TYPE_FIXED': r = ['SANE_FIX(%s)' % x for x in r] - print 'static const SANE_Range ' + n + ' = ' - print ' { ' + r[0] + ',' + r[1] + ',' + r[2] + ' };' + print ("static const SANE_Range " + n + " =") + print (" { " + r[0] + "," + r[1] + "," + r[2] + " };") def genList(n, t, l): @@ -227,13 +224,14 @@ def genList(n, t, l): elif t == 'SANE_TYPE_STRING': etype = 'SANE_String_Const' l = ['SANE_I18N("%s")' % x for x in l] + ['NULL'] - print 'static const %s %s[%d] = {' % (etype, n, len(l)) + print ("static const %s %s[%d] = {" % (etype, n, len(l))) for x in l[0:-1]: - print '\t' + x + ',' - print '\t' + l[-1] + ' };' + print ("\t" + x + ",") + print ("\t" + l[-1] + " };") def genConstraints(options): + print ("") for o in options: if 'constraint' not in o: continue c = o['constraint'] @@ -243,7 +241,6 @@ def genConstraints(options): genMinMaxRange(oname, otype, c) elif isinstance(c, list): genList(oname, otype, c) - print def buildCodeVerbatim(o): for f in ('name', 'title', 'desc', 'type', 'unit', 'size', 'cap', @@ -283,12 +280,12 @@ def ccode(o): o['code_size'] = code if ('code_cap' not in o) and ('cap' in o): - o['code_cap'] = reduce(lambda a,b: a+'|'+b, o['cap']) + o['code_cap'] = functools.reduce(lambda a,b: a+'|'+b, o['cap']) else: o['code_cap'] = '0' if ('code_info' not in o) and ('info' in o): - o['code_info'] = reduce(lambda a,b: a+'|'+b, o['info']) + o['code_info'] = functools.reduce(lambda a,b: a+'|'+b, o['info']) else: o['code_info'] = '0' @@ -335,22 +332,21 @@ def ccode(o): return o def genBuildOptions(options): - print """ -static -int find_string_in_list(SANE_String_Const str, const SANE_String_Const *list) -{ - int i; - for (i = 0; list[i] && strcmp(str, list[i]) != 0; i++) {} - return i; -} - -static -int build_option_descriptors(struct pixma_sane_t *ss) -{ - SANE_Option_Descriptor *sod; - option_descriptor_t *opt; - - memset(OPT_IN_CTX, 0, sizeof(OPT_IN_CTX));""" + print ("\nstatic") + print ("int find_string_in_list(SANE_String_Const str, const SANE_String_Const *list)") + print ("{") + print (" int i;") + print (" for (i = 0; list[i] && strcmp(str, list[i]) != 0; i++) {}") + print (" return i;") + print ("}") + print ("") + print ("static") + print ("int build_option_descriptors(struct pixma_sane_t *ss)") + print ("{") + print (" SANE_Option_Descriptor *sod;") + print (" option_descriptor_t *opt;") + print ("") + print (" memset(OPT_IN_CTX, 0, sizeof(OPT_IN_CTX));") for o in options: o = ccode(o) @@ -370,10 +366,9 @@ int build_option_descriptors(struct pixma_sane_t *ss) ' OPT_IN_CTX[%(cname_opt)s].info = %(code_info)s;\n' \ '%(full_code_default)s' sys.stdout.write(code % o) - print - print ' return 0;\n' - print '}' - print + print ("") + print (" return 0;") + print ("}\n") g = Struct() g.ngroups = 0 @@ -381,7 +376,8 @@ opt_prefix = 'opt_' con_prefix = 'constraint_' cnameMap = createCNameMap() options = parseFile(sys.stdin) -print "/* Automatically generated from pixma_sane.c */" +print ("/* DO NOT EDIT THIS FILE! */") +print ("/* Automatically generated from pixma.c */") if (len(sys.argv) == 2) and (sys.argv[1] == 'h'): genHeader(options) else: |