From ad38bc6ecb80ddeb562841b33258dd53659b1da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 24 Aug 2020 18:44:51 +0200 Subject: New upstream version 1.0.31 --- backend/pixma/scripts/pixma_gen_options.py | 102 ++++++++++++++--------------- 1 file changed, 49 insertions(+), 53 deletions(-) (limited to 'backend/pixma/scripts') 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: -- cgit v1.2.3