This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch master in repository x2goserver. commit 5517537c1174eefab820f4c14bbe4d8651e406e2 Author: Mihai Moldovan <ionic@ionic.de> Date: Wed Dec 12 09:49:22 2018 +0100 x2goserver/lib/x2goupdateoptionsstring: add helper function for transform string interpretation. --- debian/changelog | 2 ++ x2goserver/lib/x2goupdateoptionsstring | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/debian/changelog b/debian/changelog index bb6bea6..e7d59b9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -44,6 +44,8 @@ x2goserver (4.1.0.4-0x2go1) UNRELEASED; urgency=medium - x2goserver/lib/x2goupdateoptionsstring: ignore some very noisy Perl::Critic warnings that we're going to ignore anyway. - x2goserver/lib/x2goupdateoptionsstring: fix interpolated string warning. + - x2goserver/lib/x2goupdateoptionsstring: add helper function for + transform string interpretation. * debian/control: + Build-depend upon lsb-release for distro version detection. * debian/x2goserver.manpages: diff --git a/x2goserver/lib/x2goupdateoptionsstring b/x2goserver/lib/x2goupdateoptionsstring index 9f64bfd..811bf6d 100755 --- a/x2goserver/lib/x2goupdateoptionsstring +++ b/x2goserver/lib/x2goupdateoptionsstring @@ -28,6 +28,7 @@ use English qw (-no_match_vars); use Getopt::Long; use Pod::Usage; use Storable qw (dclone); +use Switch qw (fallthrough); use Data::Dumper qw (Dumper); # Accepts an option string and returns a reference to an array of hashes @@ -616,6 +617,56 @@ sub transform_intermediate { return $ret; } +# Helper function "interpreting" a transformation string. +# +# Takes the raw transformation string as its only parameter. +# +# Returns an array reference containing two elements: the transformation mode +# and a sanitized version of the transformation string, suitable for passing to +# transform_intermediate (). +# +# On error, returns undef. +sub interpret_transform { + my $ret = undef; + + my $transform = shift; + + if (defined ($transform)) { + my $mode = 0; + my $sanitized_transform = $transform; + + # Check if non-empty, empty transform strings can only mean an + # append/modify operation. + if ($transform) { + switch (substr ($transform, 0, 1)) { + case (q{-}) { + # Option starts with a dash, so must be a removal + # operation. + $mode = 1; + } + case (q{+}) { + # Options starting with a plus character are add/modify + # operations. The default mode option here is fine, but + # we'll need to strip the initial character. + # Careful: switch-fallthrough, even for the previous + # case(s)! + $sanitized_transform = substr ($sanitized_transform, 1); + last; + } + else { + # Everything else does not feature an explicit modifier, + # so we can take the transformation string verbatim. + # No need to actually do anything here, handled by the + # initialization. + } + } + } + # Set up return value accordingly. + $ret = [ $mode, $sanitized_transform ]; + } + return $ret; +} + Getopt::Long::Configure('gnu_getopt', 'no_auto_abbrev'); my $help = 0; -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git