]> git.lyx.org Git - lyx.git/blob - lib/scripts/prefTest.pl.in
3a4829c55caeadddf3f5d1819b2106c61bbb6f13
[lyx.git] / lib / scripts / prefTest.pl.in
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 use strict;
5 use warnings;
6
7 # Syntax: prefTest.pl [<var1>=<Subst1> [<var2>=<Subst> ...]] [[ctest parameters]]
8
9 my $bindir = "@CMAKE_BINARY_DIR@";
10
11 my $userdir = "$bindir/Testing/.lyx";
12
13 my %allowedKeys = (
14   "use_converter_needauth_forbidden" => ["true", "false"],
15   "use_converter_needauth" => ["true", "false"],
16   "allow_geometry_session" => ["false"],
17     );
18
19 chdir($bindir);
20
21 # Parse Arguments for strings to substitute
22
23 my %Subst = ();
24
25 my $ctestparams = 0;
26 my @ctestpars = ();
27 for my $arg ("allow_geometry_session=false", @ARGV) {
28   if ($ctestparams) {
29     push(@ctestpars, $arg);
30   }
31   else {
32     if ($arg =~ /^([^=]+)=(.*)$/) {
33       my $key = $1;
34       my $value = $2;
35       my $valid = 0;
36       if (defined($allowedKeys{$key})) {
37         for my $val (@{$allowedKeys{$key}}) {
38           if ($val eq $value) {
39             $valid = 1;
40             last;
41           }
42         }
43       }
44       if ($valid) {
45         $Subst{$key} = [$value, 0];
46       }
47       else {
48         die("invalid key or value specified in \"$arg\"");
49       }
50     }
51     else {
52       $ctestparams = 1;
53       push(@ctestpars, $arg);
54     }
55   }
56 }
57
58 if (%Subst) { # Try to do something only if a substitute is requested
59   if (open(FO, '>', "$userdir/preferences.tmp")) {
60     if (open(FI, "$userdir/preferences")) {
61       while (my $l = <FI>) {
62         for my $k (keys %Subst) {
63           if ($l =~ /^\\$k\b/) {
64             $l = "\\$k $Subst{$k}->[0]\n";
65             $Subst{$k}->[1] = 1;
66           }
67         }
68         print FO $l;
69       }
70     }
71     for my $k (keys %Subst) {
72       if ($Subst{$k}->[1] == 0) {
73         print FO "\\$k $Subst{$k}->[0]\n";
74       }
75     }
76     rename("$userdir/preferences.tmp", "$userdir/preferences");
77   }
78 }
79
80 my $res = 0;
81 if (@ctestpars) {
82   $res = system("ctest", @ctestpars);
83 }
84
85 exit($res);