[X2Go-Commits] [x2goserver] 37/99: x2goserver/lib/x2goupdateoptionsstring: considerably simplify while loop logic that iterates over transformations.

git-admin at x2go.org git-admin at x2go.org
Mon Dec 28 06:10:43 CET 2020


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2goserver.

commit 012b9f6e66060e7495b982a6cf897b125139c276
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sun Nov 8 06:46:27 2020 +0100

    x2goserver/lib/x2goupdateoptionsstring: considerably simplify while loop logic that iterates over transformations.
    
    I have no idea why I thought it had to be so complicated in the first place...
---
 debian/changelog                       |  3 +++
 x2goserver/bin/x2goupdateoptionsstring | 24 ++++++++++++------------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 59e6ac35..295f1d83 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -251,6 +251,9 @@ x2goserver (4.1.0.4-0x2go1.2) UNRELEASED; urgency=medium
        x2goserver/lib/x2goupdateoptionsstring}: update AUTHOR sections with
        proper links.
     - X2Go/Server/Agent/NX/Options.pm: fix nxagent man page link.
+    - x2goserver/lib/x2goupdateoptionsstring: considerably simplify while loop
+      logic that iterates over transformations. I have no idea why I thought
+      it had to be so complicated in the first place...
   * debian/control:
     + Build-depend upon lsb-release for distro version detection.
   * debian/x2goserver.manpages:
diff --git a/x2goserver/bin/x2goupdateoptionsstring b/x2goserver/bin/x2goupdateoptionsstring
index a9749c1c..092c03a1 100755
--- a/x2goserver/bin/x2goupdateoptionsstring
+++ b/x2goserver/bin/x2goupdateoptionsstring
@@ -232,7 +232,7 @@ sub Main {
     $sanitized_options = shift (@{$sanitized_options});
     @program_arguments = @{$sanitized_options};
 
-    my $cur_transform = shift (@program_arguments);
+    my $transformed = 0;
 
     # Nasty trick (to some degree): "do"-blocks are not recognized as loops by
     # Perl, but we could wrap the body in another block, which WILL BE recognized
@@ -240,13 +240,8 @@ sub Main {
     # "last" won't work in such a situation, but rather behave like "next".
     # Worse, the condition will also not be checked in such a case.
     # Thus, we'd better use a real loop.
-    while (1) {
-      # Shall only be relevant for the first run of the loop.
-      if (!(defined ($cur_transform))) {
-        print {*STDERR} "No transformation passed, aborting.\n";
-        $error_detected = 9;
-        last;
-      }
+    while (defined (my $cur_transform = shift (@program_arguments))) {
+      $transformed = 1;
 
       if ($debug) {
         print {*STDERR} 'Parsing current raw transformation option: ' . Dumper ($cur_transform);
@@ -256,7 +251,7 @@ sub Main {
 
       if (!(defined ($interpreted_transform_ref))) {
         print {*STDERR} "Invalid transformation passed, aborting.\n";
-        $error_detected = 10;
+        $error_detected = 9;
         last;
       }
 
@@ -270,7 +265,7 @@ sub Main {
 
       if (!(defined ($intermediate))) {
         print {*STDERR} "Error while transforming intermediate representation, aborting.\n";
-        $error_detected = 11;
+        $error_detected = 10;
         last;
       }
 
@@ -283,14 +278,19 @@ sub Main {
 
       if (!(defined ($sanitized_options))) {
         pod2usage (-exitval => 'NOEXIT');
-        $error_detected = 12;
+        $error_detected = 11;
         last;
       }
 
       $found_separator |= (0 + shift (@{$sanitized_options}));
       $sanitized_options = shift (@{$sanitized_options});
       @program_arguments = @{$sanitized_options};
-    } continue { last unless (defined ($cur_transform = shift (@program_arguments))) };
+    }
+
+    if ((!($error_detected)) && (!($transformed))) {
+      print {*STDERR} "No transformation passed, aborting.\n";
+      $error_detected = 12;
+    }
   }
 
   my $out = undef;

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list