apply version 2.7 copyright
[jalview.git] / utils / patchGt.pl
1 #*******************************************************************************
2 # Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 # Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
4 #
5 # This file is part of Jalview.
6 #
7 # Jalview is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License 
9 # as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10 #
11 # Jalview is distributed in the hope that it will be useful, but 
12 # WITHOUT ANY WARRANTY; without even the implied warranty 
13 # of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14 # PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17 #*******************************************************************************
18 #!/bin/perl
19
20 use strict;
21 use Env qw($GTID);
22
23 defined($GTID) or $GTID="UA-9060947-1";
24 my $SCRIPT = <<FOO;
25 <body>
26 <script type="text/javascript">
27     var gaJsHost = (("https:" == document.location.protocol) ?
28         "https://ssl." : "http://www.");
29     document.write(unescape("%3Cscript src=\'" + gaJsHost +
30         "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
31 </script>
32 <script type="text/javascript">
33 try{
34     var pageTracker = _gat._getTracker("'$GTID'");
35     pageTracker._trackPageview();
36 } catch(err) {}
37 </script>
38 FOO
39                 
40 while (scalar @ARGV)
41 {
42     my $f=shift @ARGV;
43     if (-f $f) {
44         if (system("grep","-v","-q",'"'.$GTID.'"',$f)) {
45             if (open OF,">$f.".$GTID) {
46                 if (open IF,"$f") {
47                 while (<IF>) {
48                     if ($_=~m!<body>!) {
49                         $_=~s!<body>!$SCRIPT!;
50                     } else {
51 #                       $_=~s!href="([~"]+)"!href="$1" onclick="
52                     }
53                     print OF $_;
54                 }
55                 close(IF);
56                 close(OF);
57                 rename($f,$f.".old.".$GTID) or die("Couldn't rename $f to $f".".old.".$GTID,$@);
58                 rename($f.".$GTID",$f) or die("Couldn't rename $f.".$GTID." to $f",$@);
59                 unlink($f.".old.".$GTID) or die("Couldn't delete ".$f.".old.".$GTID,$@);
60                 } else {
61                     warn("Can't open $f for reading.",$@);
62                 }
63             } else {
64                 warn("Couldn't open new edited file $f.$GTID",$@);
65             }
66         }
67     }
68 }
69