diff options
author | V3n3RiX <venerix@koprulu.sector> | 2025-01-25 06:47:12 +0000 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2025-01-25 06:47:12 +0000 |
commit | 4dec849539ecb0ceab14d66af84960f01b9a284c (patch) | |
tree | 70e3b3443839fd480586c6a3bc5f95ac0087603d /dev-perl/Image-Sane | |
parent | f1e6490ffadd8d677960342b348f2b08492dd5f6 (diff) |
gentoo auto-resync : 25:01:2025 - 06:47:11
Diffstat (limited to 'dev-perl/Image-Sane')
-rw-r--r-- | dev-perl/Image-Sane/Image-Sane-5.0.0-r1.ebuild | 39 | ||||
-rw-r--r-- | dev-perl/Image-Sane/Manifest | 2 | ||||
-rw-r--r-- | dev-perl/Image-Sane/files/Image-Sane-5.0.0-perl-5.38.patch | 807 |
3 files changed, 848 insertions, 0 deletions
diff --git a/dev-perl/Image-Sane/Image-Sane-5.0.0-r1.ebuild b/dev-perl/Image-Sane/Image-Sane-5.0.0-r1.ebuild new file mode 100644 index 000000000000..87814103470e --- /dev/null +++ b/dev-perl/Image-Sane/Image-Sane-5.0.0-r1.ebuild @@ -0,0 +1,39 @@ +# Copyright 1999-2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DIST_VERSION=5 +DIST_AUTHOR=RATCLIFFE +DIST_EXAMPLES=( "examples/*" ) +inherit perl-module + +DESCRIPTION="Access SANE-compatible scanners from Perl" + +SLOT="0" +KEYWORDS="~amd64 ~arm64 ~riscv ~x86" +IUSE="test" +RESTRICT="!test? ( test )" + +RDEPEND=" + dev-perl/Exception-Class + dev-perl/Readonly + >=media-gfx/sane-backends-1.0.19 +" +DEPEND="${RDEPEND} +" +BDEPEND="${RDEPEND} + dev-perl/ExtUtils-Depends + dev-perl/ExtUtils-PkgConfig + test? ( + dev-perl/Test-Requires + dev-perl/Try-Tiny + virtual/imagemagick-tools + ) +" + +PERL_RM_FILES=( t/{90_MANIFEST,91_critic,pod}.t ) + +PATCHES=( + "${FILESDIR}"/${PN}-5.0.0-perl-5.38.patch +) diff --git a/dev-perl/Image-Sane/Manifest b/dev-perl/Image-Sane/Manifest index 4aa0cf66542a..757ba56c93d4 100644 --- a/dev-perl/Image-Sane/Manifest +++ b/dev-perl/Image-Sane/Manifest @@ -1,3 +1,5 @@ +AUX Image-Sane-5.0.0-perl-5.38.patch 29346 BLAKE2B 6c88f99c9d8285e40fb6654dc25e1828750de058ff5de73e547e14b376fd1b5b127a9f4aea6f981386e544c265876ca0248644b0e782073b9ba5804e1251ef1e SHA512 5cf5c11518f2e19f2eae224cca76e4a7e79b1aa03334eb0126e57993f1e0199d940a5f01decb95ed93a4374b45f989b1b2d4b433369c0897d6e607918242f77e DIST Image-Sane-5.tar.gz 47781 BLAKE2B 7d2457a89c061f7f160ddd8321feab4611548e10158fe77bd64406fd1d1bc534d67664be59ff73d872b264d9baa947847ea3ebe47057f700d3b05ec8e9ea36b6 SHA512 b2c9aec6d6ff598284df495c15cb33c9126364b2551d421580c0f2085a1b102bc5758f81f4f857bf6e098eab0a1945d39b8996d22ece23475296362b1f6a640b +EBUILD Image-Sane-5.0.0-r1.ebuild 727 BLAKE2B 46a269cd525a6e1f0052bb16666611be2fd5677e494ad16246ec6042a237536c0507e8788a2bab83a100788392b634fbb330f73814e094d7c1e91e0f778d304e SHA512 d0add2e175a0d8b023c80f170a15f56f63bac32ec2e39f752ee657208f723a4af3f2ca91afc6087227002fd3033d0f948c5ebd0e893eff9810b43fa3b2faa4ce EBUILD Image-Sane-5.0.0.ebuild 669 BLAKE2B bc37bb3eb8b132492e41ebd81bf8662a3992bf25df70f03ae7da99d2f11dc578b9f76ab60ac4126698cc68b4a0a5aaab6ec38e8b09670d455d0ceb52b165cba3 SHA512 8cb3fc94ffec6e0e2e14311e97ebcaa5671777f9b86182408c8a97d3305f3dcf4af0b7ef2624444bf768ff6a433764d59646d5e203c6e8f956eb9f7e9b3af91d MISC metadata.xml 459 BLAKE2B 5d7752999d62f001fc83a77298fc05c5a16813b2a9dbc80b96d4caf5dc59b8e4bec863e19e2e22dc8fbca5b1acbd04765359d8fe10e73ccf7d9375801d5d9140 SHA512 c90eed832febe1b246219cfc9e5cc2bb57de96e3e1401f751501d4ee31d0bd806c5e3f0c03449cfda61a7bb17cfe8ced317d648fe978ebefca1f0ab4a49e4705 diff --git a/dev-perl/Image-Sane/files/Image-Sane-5.0.0-perl-5.38.patch b/dev-perl/Image-Sane/files/Image-Sane-5.0.0-perl-5.38.patch new file mode 100644 index 000000000000..6eeecd8e15c8 --- /dev/null +++ b/dev-perl/Image-Sane/files/Image-Sane-5.0.0-perl-5.38.patch @@ -0,0 +1,807 @@ +https://bugs.gentoo.org/928247 +https://rt.cpan.org/Public/Bug/Display.html?id=148487 + +From bfa253f8e185509cd4b63509a58a415b6abc929d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> +Date: Wed, 21 Jun 2023 15:54:40 +0200 +Subject: [PATCH] Replace deprecated given and when operators +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Perl 5.37.11 depracated "given" and "when" keywords and scheduled +them, together with a smart match operator, for removal in Perl 5.42. + +This lead to t/81_scanimage-perl.t failures: + + # Failed test '--device=test --test 2>&1' + # at t/81_scanimage-perl.t line 42. + # got: 'scanimage: scanning image of size 157x196 pixels at 8 bits/pixel + # scanimage: acquiring gray frame, 8 bits/sample + # scanimage: reading one scanline, 157 bytes... PASS + # scanimage: reading one byte... PASS + <...> + # ' + # expected: 'given is deprecated at examples/scanimage line 125. + # when is deprecated at examples/scanimage line 126. + # when is deprecated at examples/scanimage line 129. + <...> + +This patch rewrites the code not to use "given" and "when". + +CPAN RT#148487 + +Signed-off-by: Petr Písař <ppisar@redhat.com> +--- a/examples/scanadf-perl ++++ b/examples/scanadf-perl +@@ -2,8 +2,6 @@ + + use warnings; + use strict; +-use feature 'switch'; +-no if $] >= 5.018, warnings => 'experimental::smartmatch'; + use Sane; + use Data::Dumper; + use Getopt::Long qw(:config no_ignore_case pass_through); +@@ -126,25 +124,23 @@ sub sighandler { + sub print_unit { + my ($unit) = @_; + +- given ($unit) { +- when (SANE_UNIT_PIXEL) { +- printstdout('pel'); +- } +- when (SANE_UNIT_BIT) { +- printstdout('bit'); +- } +- when (SANE_UNIT_MM) { +- printstdout('mm'); +- } +- when (SANE_UNIT_DPI) { +- printstdout('dpi'); +- } +- when (SANE_UNIT_PERCENT) { +- printstdout(q{%}); +- } +- when (SANE_UNIT_MICROSECOND) { +- printstdout('us'); +- } ++ if ( $unit == SANE_UNIT_PIXEL) { ++ printstdout('pel'); ++ } ++ elsif ( $unit == SANE_UNIT_BIT ) { ++ printstdout('bit'); ++ } ++ elsif ( $unit == SANE_UNIT_MM ) { ++ printstdout('mm'); ++ } ++ elsif ( $unit == SANE_UNIT_DPI ) { ++ printstdout('dpi'); ++ } ++ elsif ( $unit == SANE_UNIT_PERCENT ) { ++ printstdout(q{%}); ++ } ++ elsif ( $unit == SANE_UNIT_MICROSECOND) { ++ printstdout('us'); + } + return; + } +@@ -283,28 +279,26 @@ sub print_current_option_value { + { + my $string_format = '%g'; + if ( $opt->{type} == SANE_TYPE_INT ) { $string_format = '%d' } +- given ( $opt->{name} ) { +- when (SANE_NAME_SCAN_TL_X) { +- $tl_x = $val; +- printf $string_format, $tl_x; +- } +- when (SANE_NAME_SCAN_TL_Y) { +- $tl_y = $val; +- printf $string_format, $tl_y; +- } +- when (SANE_NAME_SCAN_BR_X) { +- $br_x = $val; +- $w_x = $br_x - $tl_x; +- printf $string_format, $w_x; +- } +- when (SANE_NAME_SCAN_BR_Y) { +- $br_y = $val; +- $h_y = $br_y - $tl_y; +- printf $string_format, $h_y; +- } +- default { +- printf $string_format, $val; +- } ++ if ( $opt->{name} eq SANE_NAME_SCAN_TL_X ) { ++ $tl_x = $val; ++ printf $string_format, $tl_x; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_TL_Y ) { ++ $tl_y = $val; ++ printf $string_format, $tl_y; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_BR_X ) { ++ $br_x = $val; ++ $w_x = $br_x - $tl_x; ++ printf $string_format, $w_x; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_BR_Y) { ++ $br_y = $val; ++ $h_y = $br_y - $tl_y; ++ printf $string_format, $h_y; ++ } ++ else { ++ printf $string_format, $val; + } + } + elsif ( $opt->{type} == SANE_TYPE_STRING ) { +@@ -508,34 +502,32 @@ sub update_geometry { + and ( $opt->{unit} == SANE_UNIT_MM || $opt->{unit} == SANE_UNIT_PIXEL ) + ) + { +- given ( $opt->{name} ) { +- when (SANE_NAME_SCAN_TL_X) { +- $window[2] = $i; +- $opt->{name} = 'l'; +- } +- when (SANE_NAME_SCAN_TL_Y) { +- $window[3] = $i; ## no critic (ProhibitMagicNumbers) +- $opt->{name} = 't'; +- } +- when (SANE_NAME_SCAN_BR_X) { +- $window[0] = $i; +- $opt->{name} = 'x'; +- $window_option[0] = $opt; +- $window_option[0]->{title} = 'Scan width'; +- $window_option[0]->{desc} = 'Width of scanning area.'; +- if ( !$window_val_user[0] ) { +- $window_val[0] = $device->get_option($i); +- } ++ if ( $opt->{name} eq SANE_NAME_SCAN_TL_X ) { ++ $window[2] = $i; ++ $opt->{name} = 'l'; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_TL_Y ) { ++ $window[3] = $i; ## no critic (ProhibitMagicNumbers) ++ $opt->{name} = 't'; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_BR_X ) { ++ $window[0] = $i; ++ $opt->{name} = 'x'; ++ $window_option[0] = $opt; ++ $window_option[0]->{title} = 'Scan width'; ++ $window_option[0]->{desc} = 'Width of scanning area.'; ++ if ( !$window_val_user[0] ) { ++ $window_val[0] = $device->get_option($i); + } +- when (SANE_NAME_SCAN_BR_Y) { +- $window[1] = $i; +- $opt->{name} = 'y'; +- $window_option[1] = $opt; +- $window_option[1]->{title} = 'Scan height'; +- $window_option[1]->{desc} = 'Height of scanning area.'; +- if ( !$window_val_user[1] ) { +- $window_val[1] = $device->get_option($i); +- } ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_BR_Y ) { ++ $window[1] = $i; ++ $opt->{name} = 'y'; ++ $window_option[1] = $opt; ++ $window_option[1]->{title} = 'Scan height'; ++ $window_option[1]->{desc} = 'Height of scanning area.'; ++ if ( !$window_val_user[1] ) { ++ $window_val[1] = $device->get_option($i); + } + } + } +@@ -604,40 +596,38 @@ sub process_backend_option { + } + + my $value; +- given ( $opt->{type} ) { +- when (SANE_TYPE_BOOL) { +- $value = 1; # no argument means option is set +- if ($optarg) { +- if ( $optarg =~ /^yes$/ixsm ) { +- $value = 1; +- } +- elsif ( $optarg =~ /^no$/ixsm ) { +- $value = 0; +- } +- else { +- die ++ if ( $opt->{type} == SANE_TYPE_BOOL ) { ++ $value = 1; # no argument means option is set ++ if ($optarg) { ++ if ( $optarg =~ /^yes$/ixsm ) { ++ $value = 1; ++ } ++ elsif ( $optarg =~ /^no$/ixsm ) { ++ $value = 0; ++ } ++ else { ++ die + "$prog_name: option --$opt->{name}: bad option value `$optarg'\n"; +- } + } + } +- when ( +- $opt->{type} == SANE_TYPE_INT +- or $opt->{type} == SANE_TYPE_FIXED +- ) +- { +- my @vector = parse_vector( $opt, $optarg ); +- $value = \@vector; +- } +- when (SANE_TYPE_STRING) { +- $value = $optarg; +- } +- when (SANE_TYPE_BUTTON) { +- $value = 0; # value doesn't matter +- } +- default { +- warn "$prog_name: duh, got unknown option type $opt->{type}\n"; +- return; +- } ++ } ++ elsif ( ++ $opt->{type} == SANE_TYPE_INT ++ or $opt->{type} == SANE_TYPE_FIXED ++ ) ++ { ++ my @vector = parse_vector( $opt, $optarg ); ++ $value = \@vector; ++ } ++ elsif ( $opt->{type} == SANE_TYPE_STRING ) { ++ $value = $optarg; ++ } ++ elsif ( $opt->{type} == SANE_TYPE_BUTTON ) { ++ $value = 0; # value doesn't matter ++ } ++ else { ++ warn "$prog_name: duh, got unknown option type $opt->{type}\n"; ++ return; + } + set_option( $device, $optnum, $value ); + return; +@@ -1050,30 +1040,28 @@ sub process_arguments { + next; + } + if ( defined $options{$ch} ) { +- given ($ch) { +- when ('x') { +- $window_val_user[0] = 1; +- ( $window_val[0] ) = +- parse_vector( $window_option[0], $options{x} ); +- } +- when ('y') { +- $window_val_user[1] = 1; +- ( $window_val[1] ) = +- parse_vector( $window_option[1], $options{y} ); +- } +- when ('l') { # tl-x +- process_backend_option( $device, $window[2], $options{l} ); +- } +- when ('t') { # tl-y +- process_backend_option( +- $device, $window[3], ## no critic (ProhibitMagicNumbers) +- $options{t} +- ); +- } +- default { +- process_backend_option( $device, $option_number{$ch}, +- $options{$ch} ); +- } ++ if ( $ch eq 'x' ) { ++ $window_val_user[0] = 1; ++ ( $window_val[0] ) = ++ parse_vector( $window_option[0], $options{x} ); ++ } ++ elsif ( $ch eq 'y' ) { ++ $window_val_user[1] = 1; ++ ( $window_val[1] ) = ++ parse_vector( $window_option[1], $options{y} ); ++ } ++ elsif ( $ch eq 'l' ) { # tl-x ++ process_backend_option( $device, $window[2], $options{l} ); ++ } ++ elsif ( $ch eq 't' ) { # tl-y ++ process_backend_option( ++ $device, $window[3], ## no critic (ProhibitMagicNumbers) ++ $options{t} ++ ); ++ } ++ else { ++ process_backend_option( $device, $option_number{$ch}, ++ $options{$ch} ); + } + } + } +--- a/examples/scanimage-perl ++++ b/examples/scanimage-perl +@@ -2,14 +2,12 @@ + + use warnings; + use strict; +-use feature 'switch'; + use Image::Sane ':all'; + use Try::Tiny; + use Getopt::Long qw(:config no_ignore_case pass_through); + use File::Basename; + use IO::Handle; + use English qw( -no_match_vars ); # for $PROGRAM_NAME +-no if $] >= 5.018, warnings => 'experimental::smartmatch'; + use sigtrap qw/handler sighandler normal-signals/; + use Readonly; + Readonly my $BUFFER_SIZE => ( 32 * 1024 ); # default size +@@ -122,25 +120,23 @@ sub sighandler { + sub print_unit { + my ($unit) = @_; + +- given ($unit) { +- when (SANE_UNIT_PIXEL) { +- printstdout('pel'); +- } +- when (SANE_UNIT_BIT) { +- printstdout('bit'); +- } +- when (SANE_UNIT_MM) { +- printstdout('mm'); +- } +- when (SANE_UNIT_DPI) { +- printstdout('dpi'); +- } +- when (SANE_UNIT_PERCENT) { +- printstdout(q{%}); +- } +- when (SANE_UNIT_MICROSECOND) { +- printstdout('us'); +- } ++ if ($unit == SANE_UNIT_PIXEL) { ++ printstdout('pel'); ++ } ++ elsif ($unit == SANE_UNIT_BIT) { ++ printstdout('bit'); ++ } ++ elsif ($unit == SANE_UNIT_MM) { ++ printstdout('mm'); ++ } ++ elsif ($unit == SANE_UNIT_DPI) { ++ printstdout('dpi'); ++ } ++ elsif ($unit == SANE_UNIT_PERCENT) { ++ printstdout(q{%}); ++ } ++ elsif ($unit == SANE_UNIT_MICROSECOND) { ++ printstdout('us'); + } + return; + } +@@ -243,69 +239,67 @@ sub print_option { + + sub print_option_choices { + my ($opt) = @_; +- given ( $opt->{type} ) { +- when (SANE_TYPE_BOOL) { +- printstdout('[=('); +- if ( $opt->{cap} & SANE_CAP_AUTOMATIC ) { printstdout('auto|') } +- printstdout('yes|no)]'); +- } +- when (SANE_TYPE_BUTTON) { } +- default { +- printstdout($SPACE); +- if ( $opt->{cap} & SANE_CAP_AUTOMATIC ) { +- printstdout('auto|'); ++ if ( $opt->{type} == SANE_TYPE_BOOL ) { ++ printstdout('[=('); ++ if ( $opt->{cap} & SANE_CAP_AUTOMATIC ) { printstdout('auto|') } ++ printstdout('yes|no)]'); ++ } ++ elsif ( $opt->{type} == SANE_TYPE_BUTTON ) { ++ } ++ else { ++ printstdout($SPACE); ++ if ( $opt->{cap} & SANE_CAP_AUTOMATIC ) { ++ printstdout('auto|'); ++ } ++ if ( $opt->{constraint_type} == SANE_CONSTRAINT_NONE ) { ++ if ( $opt->{type} == SANE_TYPE_INT ) { ++ printstdout('<int>'); + } +- given ( $opt->{constraint_type} ) { +- when (SANE_CONSTRAINT_NONE) { +- if ( $opt->{type} == SANE_TYPE_INT ) { +- printstdout('<int>'); +- } +- elsif ( $opt->{type} == SANE_TYPE_FIXED ) { +- printstdout('<float>'); +- } +- elsif ( $opt->{type} == SANE_TYPE_STRING ) { +- printstdout('<string>'); +- } +- if ( $opt->{max_values} > 1 ) { printstdout(',...') } +- } +- when (SANE_CONSTRAINT_RANGE) { +- my $string_format = '%g..%g'; +- if ( $opt->{type} == SANE_TYPE_INT ) { +- $string_format = '%d..%d'; +- } +- if ( $opt->{name} eq 'x' ) { +- printf $string_format, $opt->{constraint}{min}, +- $opt->{constraint}{max} - $tl_x; +- } +- elsif ( $opt->{name} eq 'y' ) { +- printf $string_format, $opt->{constraint}{min}, +- $opt->{constraint}{max} - $tl_y; +- } +- else { +- printf $string_format, $opt->{constraint}{min}, +- $opt->{constraint}{max}; +- } +- print_unit( $opt->{unit} ); +- if ( $opt->{max_values} > 1 ) { printstdout(',...') } +- if ( $opt->{constraint}{quant} ) { +- printstdout(" (in steps of $opt->{constraint}{quant})"); +- } +- } +- when ( SANE_CONSTRAINT_STRING_LIST | SANE_CONSTRAINT_WORD_LIST ) +- { +- for my $i ( 0 .. $#{ $opt->{constraint} } ) { +- if ( $i > 0 ) { printstdout(q{|}) } +- my $string_format = +- $opt->{type} == SANE_TYPE_FIXED ? '%g' : '%s'; ++ elsif ( $opt->{type} == SANE_TYPE_FIXED ) { ++ printstdout('<float>'); ++ } ++ elsif ( $opt->{type} == SANE_TYPE_STRING ) { ++ printstdout('<string>'); ++ } ++ if ( $opt->{max_values} > 1 ) { printstdout(',...') } ++ } ++ elsif ( $opt->{constraint_type} == SANE_CONSTRAINT_RANGE ) { ++ my $string_format = '%g..%g'; ++ if ( $opt->{type} == SANE_TYPE_INT ) { ++ $string_format = '%d..%d'; ++ } ++ if ( $opt->{name} eq 'x' ) { ++ printf $string_format, $opt->{constraint}{min}, ++ $opt->{constraint}{max} - $tl_x; ++ } ++ elsif ( $opt->{name} eq 'y' ) { ++ printf $string_format, $opt->{constraint}{min}, ++ $opt->{constraint}{max} - $tl_y; ++ } ++ else { ++ printf $string_format, $opt->{constraint}{min}, ++ $opt->{constraint}{max}; ++ } ++ print_unit( $opt->{unit} ); ++ if ( $opt->{max_values} > 1 ) { printstdout(',...') } ++ if ( $opt->{constraint}{quant} ) { ++ printstdout(" (in steps of $opt->{constraint}{quant})"); ++ } ++ } ++ elsif ( $opt->{constraint_type} == SANE_CONSTRAINT_STRING_LIST || ++ $opt->{constraint_type} == SANE_CONSTRAINT_WORD_LIST ) ++ { ++ for my $i ( 0 .. $#{ $opt->{constraint} } ) { ++ if ( $i > 0 ) { printstdout(q{|}) } ++ my $string_format = ++ $opt->{type} == SANE_TYPE_FIXED ? '%g' : '%s'; + +- printf $string_format, $opt->{constraint}[$i]; +- } +- if ( $opt->{constraint_type} == SANE_CONSTRAINT_WORD_LIST ) +- { +- print_unit( $opt->{unit} ); +- if ( $opt->{max_values} > 1 ) { printstdout(',...') } +- } +- } ++ printf $string_format, $opt->{constraint}[$i]; ++ } ++ if ( $opt->{constraint_type} == SANE_CONSTRAINT_WORD_LIST ) ++ { ++ print_unit( $opt->{unit} ); ++ if ( $opt->{max_values} > 1 ) { printstdout(',...') } + } + } + } +@@ -326,26 +320,24 @@ sub print_current_option_value { + { + my $string_format = '%g'; + if ( $opt->{type} == SANE_TYPE_INT ) { $string_format = '%d' } +- given ( $opt->{name} ) { +- when ('l') { +- $tl_x = $val; +- printf $string_format, $tl_x; +- } +- when ('t') { +- $tl_y = $val; +- printf $string_format, $tl_y; +- } +- when ('x') { +- $br_x = $val; +- printf $string_format, $br_x - $tl_x; +- } +- when ('y') { +- $br_y = $val; +- printf $string_format, $br_y - $tl_y; +- } +- default { +- printf $string_format, $val; +- } ++ if ( $opt->{name} eq 'l' ) { ++ $tl_x = $val; ++ printf $string_format, $tl_x; ++ } ++ elsif ( $opt->{name} eq 't' ) { ++ $tl_y = $val; ++ printf $string_format, $tl_y; ++ } ++ elsif ( $opt->{name} eq 'x' ) { ++ $br_x = $val; ++ printf $string_format, $br_x - $tl_x; ++ } ++ elsif ( $opt->{name} eq 'y' ) { ++ $br_y = $val; ++ printf $string_format, $br_y - $tl_y; ++ } ++ else { ++ printf $string_format, $val; + } + } + elsif ( $opt->{type} == SANE_TYPE_STRING ) { +@@ -562,33 +554,31 @@ sub update_geometry { + and ( $opt->{unit} == SANE_UNIT_MM or $opt->{unit} == SANE_UNIT_PIXEL ) + ) + { +- given ( $opt->{name} ) { +- when (SANE_NAME_SCAN_BR_X) { +- $window[0] = $i; +- $opt->{name} = 'x'; +- $window_option[0] = $opt; +- $window_option[0]->{title} = 'Scan width'; +- $window_option[0]->{desc} = 'Width of scan-area.'; +- $window_option[0]->{name} = 'x'; +- } +- when (SANE_NAME_SCAN_BR_Y) { +- $window[1] = $i; +- $opt->{name} = 'y'; +- $window_option[1] = $opt; +- $window_option[1]->{title} = 'Scan height'; +- $window_option[1]->{desc} = 'Height of scan-area.'; +- $window_option[1]->{name} = 'y'; +- } +- when (SANE_NAME_SCAN_TL_X) { +- $window[2] = $i; +- $window_option[2] = $opt; +- $window_option[2]->{name} = 'l'; +- } +- when (SANE_NAME_SCAN_TL_Y) { +- $window[$I_TL_Y] = $i; +- $window_option[$I_TL_Y] = $opt; +- $window_option[$I_TL_Y]->{name} = 't'; +- } ++ if ( $opt->{name} eq SANE_NAME_SCAN_BR_X ) { ++ $window[0] = $i; ++ $opt->{name} = 'x'; ++ $window_option[0] = $opt; ++ $window_option[0]->{title} = 'Scan width'; ++ $window_option[0]->{desc} = 'Width of scan-area.'; ++ $window_option[0]->{name} = 'x'; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_BR_Y ) { ++ $window[1] = $i; ++ $opt->{name} = 'y'; ++ $window_option[1] = $opt; ++ $window_option[1]->{title} = 'Scan height'; ++ $window_option[1]->{desc} = 'Height of scan-area.'; ++ $window_option[1]->{name} = 'y'; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_TL_X ) { ++ $window[2] = $i; ++ $window_option[2] = $opt; ++ $window_option[2]->{name} = 'l'; ++ } ++ elsif ( $opt->{name} eq SANE_NAME_SCAN_TL_Y ) { ++ $window[$I_TL_Y] = $i; ++ $window_option[$I_TL_Y] = $opt; ++ $window_option[$I_TL_Y]->{name} = 't'; + } + } + return; +@@ -663,40 +653,38 @@ sub process_backend_option { + } + + my $value; +- given ( $opt->{type} ) { +- when (SANE_TYPE_BOOL) { +- $value = 1; # no argument means option is set +- if ($optarg) { +- if ( $optarg =~ /^yes$/xsmi ) { +- $value = 1; +- } +- elsif ( $optarg =~ /^no$/xsmi ) { +- $value = 0; +- } +- else { +- die ++ if ( $opt->{type} == SANE_TYPE_BOOL ) { ++ $value = 1; # no argument means option is set ++ if ($optarg) { ++ if ( $optarg =~ /^yes$/xsmi ) { ++ $value = 1; ++ } ++ elsif ( $optarg =~ /^no$/xsmi ) { ++ $value = 0; ++ } ++ else { ++ die + "$prog_name: option --$opt->{name}: bad option value `$optarg'\n"; +- } + } + } +- when ( +- $opt->{type} == SANE_TYPE_INT +- or $opt->{type} == SANE_TYPE_FIXED +- ) +- { +- my @vector = parse_vector( $opt, $optarg ); +- $value = \@vector; +- } +- when (SANE_TYPE_STRING) { +- $value = $optarg; +- } +- when (SANE_TYPE_BUTTON) { +- $value = 0; # value doesn't matter +- } +- default { +- warn "$prog_name: duh, got unknown option type $opt->{type}\n"; +- return; +- } ++ } ++ elsif ( ++ $opt->{type} == SANE_TYPE_INT ++ or $opt->{type} == SANE_TYPE_FIXED ++ ) ++ { ++ my @vector = parse_vector( $opt, $optarg ); ++ $value = \@vector; ++ } ++ elsif ( $opt->{type} == SANE_TYPE_STRING ) { ++ $value = $optarg; ++ } ++ elsif ( $opt->{type} == SANE_TYPE_BUTTON) { ++ $value = 0; # value doesn't matter ++ } ++ else { ++ warn "$prog_name: duh, got unknown option type $opt->{type}\n"; ++ return; + } + set_option( $device, $optnum, $value ); + return; +@@ -1149,29 +1137,19 @@ sub scan_pages { + printstderr( sprintf " (scanner status = %d)\n", $status ); + } + +- given ($status) { +- when (SANE_STATUS_EOF) { +- if ($batch) { +- +- # close output file by redirecting, do not close stdout here! +- if ( +- open $fh, '>', ## no critic (RequireBriefOpen) +- '/dev/null' and STDOUT->fdopen( $fh, '>' ) +- ) +- { +- +- # let the fully scanned file show up +- if ( not rename $part_path, $path ) { +- printstderr("cannot rename $part_path to $path\n"); +- try { +- $device->cancel; +- } +- catch {}; +- return SANE_STATUS_ACCESS_DENIED; +- } +- } +- else { +- printstderr("cannot open /dev/null\n"); ++ if ( $status == SANE_STATUS_EOF ) { ++ if ($batch) { ++ ++ # close output file by redirecting, do not close stdout here! ++ if ( ++ open $fh, '>', ## no critic (RequireBriefOpen) ++ '/dev/null' and STDOUT->fdopen( $fh, '>' ) ++ ) ++ { ++ ++ # let the fully scanned file show up ++ if ( not rename $part_path, $path ) { ++ printstderr("cannot rename $part_path to $path\n"); + try { + $device->cancel; + } +@@ -1179,15 +1157,23 @@ sub scan_pages { + return SANE_STATUS_ACCESS_DENIED; + } + } +- } +- when (SANE_STATUS_GOOD) { +- if ($batch) { +- close $fh or warn "cannot close file\n"; +- unlink $part_path; ++ else { ++ printstderr("cannot open /dev/null\n"); ++ try { ++ $device->cancel; ++ } ++ catch {}; ++ return SANE_STATUS_ACCESS_DENIED; + } +- last; + } + } ++ elsif ( $status == SANE_STATUS_GOOD ) { ++ if ($batch) { ++ close $fh or warn "cannot close file\n"; ++ unlink $part_path; ++ } ++ last; ++ } + $n += $batch_increment; + + if ( not ok_for_next_page() ) { last } +@@ -1422,28 +1408,26 @@ sub process_arguments { + next; + } + if ( defined $options{$ch} ) { +- given ($ch) { +- when ('x') { +- $window_val_user[0] = 1; +- ( $window_val[0] ) = +- parse_vector( $window_option[0], $options{x} ); +- } +- when ('y') { +- $window_val_user[1] = 1; +- ( $window_val[1] ) = +- parse_vector( $window_option[1], $options{y} ); +- } +- when ('l') { # tl-x +- process_backend_option( $device, $window[2], $options{l} ); +- } +- when ('t') { # tl-y +- process_backend_option( $device, $window[$I_TL_Y], +- $options{t} ); +- } +- default { +- process_backend_option( $device, $option_number{$ch}, +- $options{$ch} ); +- } ++ if ( $ch eq 'x' ) { ++ $window_val_user[0] = 1; ++ ( $window_val[0] ) = ++ parse_vector( $window_option[0], $options{x} ); ++ } ++ elsif ( $ch eq 'y' ) { ++ $window_val_user[1] = 1; ++ ( $window_val[1] ) = ++ parse_vector( $window_option[1], $options{y} ); ++ } ++ elsif ( $ch eq 'l') { # tl-x ++ process_backend_option( $device, $window[2], $options{l} ); ++ } ++ elsif ( $ch eq 't') { # tl-y ++ process_backend_option( $device, $window[$I_TL_Y], ++ $options{t} ); ++ } ++ else { ++ process_backend_option( $device, $option_number{$ch}, ++ $options{$ch} ); + } + } + } +-- +2.41.0 |