]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/prefTest.pl.in
Remove code that is redudant.
[lyx.git] / lib / scripts / prefTest.pl.in
index 1d8aa90e03237899b5fb8d7723845dd09fa4b422..4e0aab739f05fecd4cc5a7c3da6057676c91731c 100755 (executable)
@@ -2,8 +2,25 @@
 # -*- mode: perl; -*-
 
 use strict;
+use warnings;
 
-# Syntax: ReplaceValuesprefTest.pl [<var1>=<Subst1> [<var2>=<Subst> ...]] [[ctest parameters]]
+# Syntax: prefTest.pl [test|default] [<var1>=<Subst1> [<var2>=<Subst> ...]] [[ctest parameters]]
+# If the first parameter is "test"
+#       allow use of -shell-escape in converters and
+#       allow use of external programs
+# If the first parameter is "default"
+#       remove "-shell-escape" from converters and
+#       forbid use of external programs
+# Else
+#       allow use of -shell-escape in converters and
+#       do not change handling the use of external programs
+############################################################
+
+BEGIN  {
+  unshift(@INC, "@CMAKE_CURRENT_SOURCE_DIR@");
+}
+
+use prefTest;
 
 my $bindir = "@CMAKE_BINARY_DIR@";
 
@@ -12,14 +29,10 @@ my $userdir = "$bindir/Testing/.lyx";
 my %allowedKeys = (
   "use_converter_needauth_forbidden" => ["true", "false"],
   "use_converter_needauth" => ["true", "false"],
+  "allow_geometry_session" => ["false"],
     );
 
-# Bindings used by some tests
-# used file is "$userdir/bind/user.bind"
-my %bindings = (
-  # Empty for now, example below
-  # "A-h" => ["dialog-hide", "findreplaceadv"],
-  );
+my %Converter = ();
 
 chdir($bindir);
 
@@ -27,97 +40,36 @@ chdir($bindir);
 
 my %Subst = ();
 
-my $ctestparams = 0;
 my @ctestpars = ();
-for my $arg (@ARGV) {
-  if ($ctestparams) {
-    push(@ctestpars, $arg);
-  }
-  else {
-    if ($arg =~ /^([^=]+)=(.*)$/) {
-      my $key = $1;
-      my $value = $2;
-      my $valid = 0;
-      if (defined($allowedKeys{$key})) {
-       for my $val (@{$allowedKeys{$key}}) {
-         if ($val eq $value) {
-           $valid = 1;
-           last;
-         }
-       }
-      }
-      if ($valid) {
-       $Subst{$key} = [$value, 0];
-      }
-      else {
-       die("invalid key or value specified in \"$arg\"");
-      }
-    }
-    else {
-      $ctestparams = 1;
-      push(@ctestpars, $arg);
-    }
-  }
-}
 
-if (%Subst) { # Try to do something only if a substitute is requested
-  if (open(FO, '>', "$userdir/preferences.tmp")) {
-    if (open(FI, "$userdir/preferences")) {
-      while (my $l = <FI>) {
-       for my $k (keys %Subst) {
-         if ($l =~ /^\\$k\b/) {
-           $l = "\\$k $Subst{$k}->[0]\n";
-           $Subst{$k}->[1] = 1;
-         }
-       }
-       print FO $l;
-      }
-    }
-    for my $k (keys %Subst) {
-      if ($Subst{$k}->[1] == 0) {
-       print FO "\\$k $Subst{$k}->[0]\n";
-      }
-    }
-    rename("$userdir/preferences.tmp", "$userdir/preferences");
-  }
+my $shell_escapes = 1;
+my $handle_argv = "";
+if (defined($ARGV[0]) && ($ARGV[0] =~ /^(test|default)$/)) {
+  $handle_argv = $1;
+  shift(@ARGV);
 }
 
-if (open(FO, '>', "$userdir/userbind.tmp")) {
-  my %used = ();
-  if (open(FI, "$userdir/bind/user.bind")) {
-    while (my $l = <FI>) {
-      my $found = 0;
-      for my $k (keys %bindings) {
-       if ($l =~ /^\s*\\bind\s+\"$k\"/) {
-         $found = 1;
-         if (! defined($used{$k})) {
-           $used{$k} = 1;
-           $l = "\\bind \"$k\" \"" . join(' ', @{$bindings{$k}}) . "\"\n";
-           print FO $l;
-           last;
-         }
-       }
-       print FO $l if (! $found);
-      }
-    }
-    close(FI);
-  }
-  else {
-    print FO "## This file is automatically generated by lyx\n";
-    print FO "## All modifications will be lost\n";
-    print FO "\n\n";
-    print FO "Format 4\n\n";
-  }
-  for my $k (keys %bindings) {
-    if (! defined($used{$k})) {
-      $used{$k} = 1;
-      my $l = "\\bind \"$k\" \"" . join(' ', @{$bindings{$k}}) . "\"\n";
-      print FO $l;
-    }
-  }
-  close(FO);
-  rename("$userdir/userbind.tmp", "$userdir/bind/user.bind");
+if ($handle_argv eq "test") {
+  @ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
+                              "allow_geometry_session=false",
+                              "use_converter_needauth_forbidden=false",
+                              "use_converter_needauth=false", @ARGV);
+}
+elsif ($handle_argv eq "default") {
+  $shell_escapes = 0;
+  @ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
+                              "allow_geometry_session=false",
+                              "use_converter_needauth_forbidden=true",
+                              "use_converter_needauth=true", @ARGV);
 }
+else {
+  @ctestpars = &getSubstitutes(\%allowedKeys, \%Subst,
+                              "allow_geometry_session=false", @ARGV);
+}
+
+&getConverters($userdir, \%Converter, $shell_escapes);
+
+&applyChanges($userdir, \%Subst, \%Converter, $shell_escapes);
 
 my $res = 0;
 if (@ctestpars) {
@@ -125,3 +77,4 @@ if (@ctestpars) {
 }
 
 exit($res);
+