From 508def2a5c9203a69007dee3efff6d15d1b999f1 Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 14 Jun 2024 15:12:57 +0000 Subject: [PATCH] Replace deprecated given/when and smartmatch operator in Perl scripts. --- regress/sys/kern/sosplice/funcs.pl | 105 +++++++++++++------------- regress/usr.sbin/httpd/tests/funcs.pl | 18 ++--- regress/usr.sbin/relayd/funcs.pl | 27 ++++--- regress/usr.sbin/syslogd/funcs.pl | 14 ++-- 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/regress/sys/kern/sosplice/funcs.pl b/regress/sys/kern/sosplice/funcs.pl index 43d484ae5a0..9b9c901cb13 100644 --- a/regress/sys/kern/sosplice/funcs.pl +++ b/regress/sys/kern/sosplice/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.9 2017/11/08 22:14:02 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.10 2024/06/14 15:12:57 bluhm Exp $ # Copyright (c) 2010-2017 Alexander Bluhm # @@ -16,8 +16,6 @@ use strict; use warnings; -no warnings 'experimental::smartmatch'; -use feature 'switch'; use Errno; use Digest::MD5; use IO::Socket qw(sockatmark); @@ -40,13 +38,11 @@ sub write_stream { $ctx->add($char); print $char or die ref($self), " print failed: $!"; - given ($char) { - when(/9/) { $char = 'A' } - when(/Z/) { $char = 'a' } - when(/z/) { $char = "\n" } - when(/\n/) { print STDERR "."; $char = '0' } - default { $char++ } - } + if ($char =~ /9/) { $char = 'A' } + elsif ($char =~ /Z/) { $char = 'a' } + elsif ($char =~ /z/) { $char = "\n" } + elsif ($char =~ /\n/) { print STDERR "."; $char = '0' } + else { $char++ } if ($self->{sleep}) { IO::Handle::flush(\*STDOUT); sleep $self->{sleep}; @@ -73,28 +69,31 @@ sub write_oob { my $char = '0'; for (my $i = 1; $i < $len; $i++) { $msg .= $char; - given ($char) { - when(/9/) { - $ctx->add("[$char]"); - defined(send(STDOUT, $msg, MSG_OOB)) - or die ref($self), " send OOB failed: $!"; - # If tcp urgent data is sent too fast, - # it may get overwritten and lost. - sleep .1; - $msg = ""; - $char = 'A'; - } - when(/Z/) { $ctx->add($char); $char = 'a' } - when(/z/) { $ctx->add($char); $char = "\n" } - when(/\n/) { - $ctx->add($char); - defined(send(STDOUT, $msg, 0)) - or die ref($self), " send failed: $!"; - print STDERR "."; - $msg = ""; - $char = '0'; - } - default { $ctx->add($char); $char++ } + if ($char =~ /9/) { + $ctx->add("[$char]"); + defined(send(STDOUT, $msg, MSG_OOB)) + or die ref($self), " send OOB failed: $!"; + # If tcp urgent data is sent too fast, + # it may get overwritten and lost. + sleep .1; + $msg = ""; + $char = 'A'; + } elsif ($char =~ /Z/) { + $ctx->add($char); + $char = 'a'; + } elsif ($char =~ /z/) { + $ctx->add($char); + $char = "\n"; + } elsif ($char =~ /\n/) { + $ctx->add($char); + defined(send(STDOUT, $msg, 0)) + or die ref($self), " send failed: $!"; + print STDERR "."; + $msg = ""; + $char = '0'; + } else { + $ctx->add($char); + $char++; } } if ($len) { @@ -125,13 +124,11 @@ sub write_datagram { for (my $i = 1; $i < $l; $i++) { $ctx->add($char); $string .= $char; - given ($char) { - when(/9/) { $char = 'A' } - when(/Z/) { $char = 'a' } - when(/z/) { $char = "\n" } - when(/\n/) { $char = '0' } - default { $char++ } - } + if ($char =~ /9/) { $char = 'A' } + elsif ($char =~ /Z/) { $char = 'a' } + elsif ($char =~ /z/) { $char = "\n" } + elsif ($char =~ /\n/) { $char = '0' } + else { $char++ } } if ($l) { $ctx->add("\n"); @@ -311,10 +308,12 @@ sub relay_copy { my $self = shift; my $protocol = $self->{protocol} || "tcp"; - given ($protocol) { - when (/tcp/) { relay_copy_stream($self, @_) } - when (/udp/) { relay_copy_datagram($self, @_) } - default { die ref($self), " unknown protocol name: $protocol" } + if ($protocol =~ /tcp/) { + relay_copy_stream($self, @_); + } elsif ($protocol =~ /udp/) { + relay_copy_datagram($self, @_); + } else { + die ref($self), " unknown protocol name: $protocol"; } } @@ -437,10 +436,12 @@ sub relay_splice { my $self = shift; my $protocol = $self->{protocol} || "tcp"; - given ($protocol) { - when (/tcp/) { relay_splice_stream($self, @_) } - when (/udp/) { relay_splice_datagram($self, @_) } - default { die ref($self), " unknown protocol name: $protocol" } + if ($protocol =~ /tcp/) { + relay_splice_stream($self, @_); + } elsif ($protocol =~ /udp/) { + relay_splice_datagram($self, @_); + } else { + die ref($self), " unknown protocol name: $protocol"; } } @@ -448,10 +449,12 @@ sub relay { my $self = shift; my $forward = $self->{forward}; - given ($forward) { - when (/copy/) { relay_copy($self, @_) } - when (/splice/) { relay_splice($self, @_) } - default { die ref($self), " unknown forward name: $forward" } + if ($forward =~ /copy/) { + relay_copy($self, @_); + } elsif ($forward =~ /splice/) { + relay_splice($self, @_); + } else { + die ref($self), " unknown forward name: $forward"; } my $soerror; diff --git a/regress/usr.sbin/httpd/tests/funcs.pl b/regress/usr.sbin/httpd/tests/funcs.pl index 76c7ff44db1..84c96f18832 100644 --- a/regress/usr.sbin/httpd/tests/funcs.pl +++ b/regress/usr.sbin/httpd/tests/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.9 2021/12/22 15:54:01 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.10 2024/06/14 15:12:57 bluhm Exp $ # Copyright (c) 2010-2021 Alexander Bluhm # @@ -16,10 +16,9 @@ use strict; use warnings; -no warnings 'experimental::smartmatch'; -use feature 'switch'; use Errno; use Digest::MD5; +use POSIX; use Socket; use Socket6; use IO::Socket; @@ -63,13 +62,11 @@ sub write_char { $ctx->add($char); print $char or die ref($self), " print failed: $!"; - given ($char) { - when(/9/) { $char = 'A' } - when(/Z/) { $char = 'a' } - when(/z/) { $char = "\n" } - when(/\n/) { print STDERR "."; $char = '0' } - default { $char++ } - } + if ($char =~ /9/) { $char = 'A' } + elsif ($char =~ /Z/) { $char = 'a' } + elsif ($char =~ /z/) { $char = "\n" } + elsif ($char =~ /\n/) { print STDERR "."; $char = '0' } + else { $char++ } if ($self->{sleep}) { IO::Handle::flush(\*STDOUT); sleep $self->{sleep}; @@ -313,7 +310,6 @@ sub read_multipart { print STDERR "LEN: ", $len, "\n"; print STDERR "MD5: ", $ctx->hexdigest, "\n"; - } sub errignore { diff --git a/regress/usr.sbin/relayd/funcs.pl b/regress/usr.sbin/relayd/funcs.pl index fcb49ffd635..694a1c8ae07 100644 --- a/regress/usr.sbin/relayd/funcs.pl +++ b/regress/usr.sbin/relayd/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.25 2021/12/22 11:50:28 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.26 2024/06/14 15:12:57 bluhm Exp $ # Copyright (c) 2010-2021 Alexander Bluhm # @@ -16,8 +16,6 @@ use strict; use warnings; -no warnings 'experimental::smartmatch'; -use feature 'switch'; use Errno; use Digest::MD5; use Socket; @@ -125,13 +123,11 @@ sub write_char { $ctx->add($char); print $char or die ref($self), " print failed: $!"; - given ($char) { - when(/9/) { $char = 'A' } - when(/Z/) { $char = 'a' } - when(/z/) { $char = "\n" } - when(/\n/) { print STDERR "."; $char = '0' } - default { $char++ } - } + if ($char =~ /9/) { $char = 'A' } + elsif ($char =~ /Z/) { $char = 'a' } + elsif ($char =~ /z/) { $char = "\n" } + elsif ($char =~ /\n/) { print STDERR "."; $char = '0' } + else { $char++ } if ($self->{sleep}) { IO::Handle::flush(\*STDOUT); sleep $self->{sleep}; @@ -521,6 +517,15 @@ sub check_logs { and die "relayd lost child"; } +sub array_eq { + my ($a, $b) = @_; + return if @$a != @$b; + for (my $i = 0; $i < @$a; $i++) { + return if $$a[$i] ne $$b[$i]; + } + return 1; +} + sub check_len { my ($c, $r, $s, %args) = @_; @@ -531,7 +536,7 @@ sub check_len { unless $args{client}{nocheck}; @slen = $s->loggrep(qr/^LEN: /) or die "no server len" unless $args{server}{nocheck}; - !@clen || !@slen || @clen ~~ @slen + !@clen || !@slen || array_eq \@clen, \@slen or die "client: @clen", "server: @slen", "len mismatch"; !defined($args{len}) || !$clen[0] || $clen[0] eq "LEN: $args{len}\n" or die "client: $clen[0]", "len $args{len} expected"; diff --git a/regress/usr.sbin/syslogd/funcs.pl b/regress/usr.sbin/syslogd/funcs.pl index 171dc5531c8..d0bacab8980 100644 --- a/regress/usr.sbin/syslogd/funcs.pl +++ b/regress/usr.sbin/syslogd/funcs.pl @@ -1,4 +1,4 @@ -# $OpenBSD: funcs.pl,v 1.40 2022/03/25 14:15:10 bluhm Exp $ +# $OpenBSD: funcs.pl,v 1.41 2024/06/14 15:12:57 bluhm Exp $ # Copyright (c) 2010-2021 Alexander Bluhm # @@ -16,8 +16,6 @@ use strict; use warnings; -no warnings 'experimental::smartmatch'; -use feature 'switch'; use Errno; use List::Util qw(first); use Socket; @@ -152,12 +150,10 @@ sub generate_chars { my $char = '0'; for (my $i = 0; $i < $len; $i++) { $msg .= $char; - given ($char) { - when(/9/) { $char = 'A' } - when(/Z/) { $char = 'a' } - when(/z/) { $char = '0' } - default { $char++ } - } + if ($char =~ /9/) { $char = 'A' } + elsif ($char =~ /Z/) { $char = 'a' } + elsif ($char =~ /z/) { $char = '0' } + else { $char++ } } return $msg; } -- 2.20.1