williamr/convert_to_eula.pl
changeset 60 e86c659b78a0
parent 59 69e9b8ca3ae9
child 62 7cd69ef87d2a
equal deleted inserted replaced
59:69e9b8ca3ae9 60:e86c659b78a0
    19 use File::Copy;
    19 use File::Copy;
    20 use File::Path;
    20 use File::Path;
    21 
    21 
    22 my $debug = 0;
    22 my $debug = 0;
    23 
    23 
       
    24 my @oldtext = (
       
    25   'terms of the License "Symbian Foundation License v1.0"',
       
    26   'the URL "http://www.symbianfoundation.org/legal/sfl-v10.html"'
       
    27 );
       
    28 my @newtext = (
       
    29   'terms of the License "Symbian Foundation License v1.0" to members and "Symbian Foundation End User License Agreement v1.0" to non-members',
       
    30   'the URL "http://www.symbianfoundation.org/legal/licencesv10.html"'
       
    31 );
       
    32 
       
    33 my @errorfiles = ();
       
    34 
    24 sub map_eula($$$)
    35 sub map_eula($$$)
    25   {
    36   {
    26   my ($file,$shadowdir,$name) = @_;
    37   my ($file,$shadowdir,$name) = @_;
    27   
    38   
    28   open FILE, "<$file" or print "ERROR: Cannot open $file: $!\n" and return "Cannot open";
    39   open FILE, "<$file" or print "ERROR: Cannot open $file: $!\n" and return "Cannot open";
    30   close FILE;
    41   close FILE;
    31   
    42   
    32   my $updated = 0;
    43   my $updated = 0;
    33   my @newlines = ();
    44   my @newlines = ();
    34   while (my $line = shift @lines)
    45   while (my $line = shift @lines)
    35     {
    46     { 
       
    47     if (index($line,$newtext[0]) >= 0)
       
    48       {
       
    49       # file already converted - nothing to do
       
    50       last;
       
    51       }
    36     # under the terms of the License "Symbian Foundation License v1.0"
    52     # under the terms of the License "Symbian Foundation License v1.0"
    37     # which accompanies this distribution, and is available
    53     # which accompanies this distribution, and is available
    38     # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
    54     # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
    39     if ($line =~ /terms of the License "Symbian Foundation License v1.0"/)
    55     my $pos1 = index $line, $oldtext[0];
       
    56     if ($pos1 >= 0)
    40       {
    57       {
    41       my $midline = shift @lines;
    58       my $midline = shift @lines;
    42       my $nextline = shift @lines;
    59       my $urlline = shift @lines;
    43       if ($nextline =~ /the URL "http:\/\/www.symbianfoundation.org\/legal\/sfl-v10.html"/)
    60       my $pos2 = index $urlline, $oldtext[1];
       
    61       if ($pos2 >= 0)
    44         {
    62         {
    45         # Found it - assume that there's only one instance
    63         # Found it - assume that there's only one instance
    46         $line =~ s/Symbian Foundation License v1.0/Symbian End User License v1.0/;
    64         substr $line, $pos1, length($oldtext[0]), $newtext[0];
    47         $nextline =~ s/legal\/sfl-v10.html/legal\/eula-v10.html/;
    65         substr $urlline, $pos2, length($oldtext[1]), $newtext[1];
    48         push @newlines, $line, $midline, $nextline, @lines;
    66         push @newlines, $line, $midline, $urlline;
    49         $updated = 1;
    67         $updated = 1;
    50         last;
    68         last;
    51         }
    69         }
    52       else
    70       else
    53         {
    71         {
    54         print STDERR "Problem in $file: incorrectly formatted >\n$line$nextline\n";
    72         print STDERR "Problem in $file: incorrectly formatted >\n$line$midline$urlline\n";
       
    73         push @errorfiles, $file;
    55         last;
    74         last;
    56         }
    75         }
    57       }
    76       }
    58     push @newlines, $line;
    77     push @newlines, $line;
    59     }
    78     }
    61   return if (!$updated);
    80   return if (!$updated);
    62  
    81  
    63   mkpath($shadowdir, {verbose=>0});
    82   mkpath($shadowdir, {verbose=>0});
    64   move($file, "$shadowdir/$name") or die("Cannot move $file to $shadowdir/$name: $!\n");
    83   move($file, "$shadowdir/$name") or die("Cannot move $file to $shadowdir/$name: $!\n");
    65   open NEWFILE, ">$file" or die("Cannot overwrite $file: $!\n");
    84   open NEWFILE, ">$file" or die("Cannot overwrite $file: $!\n");
    66   print NEWFILE @newlines;
    85   print NEWFILE @newlines, @lines;
    67   close NEWFILE or die("Failed to update $file: $!\n");
    86   close NEWFILE or die("Failed to update $file: $!\n");
    68   print "* updated $file\n";
    87   print "* updated $file\n";
    69   }
    88   }
    70 
    89 
    71 # Process tree
    90 # Process tree
    93     map_eula($newpath, $shadow, $file);
   112     map_eula($newpath, $shadow, $file);
    94     }
   113     }
    95   }
   114   }
    96 
   115 
    97 scan_directory("/epoc32", "/sfl_epoc32");
   116 scan_directory("/epoc32", "/sfl_epoc32");
       
   117 
       
   118 printf "%d problem files\n", scalar @errorfiles;
       
   119 print "\t", join("\n\t", @errorfiles), "\n";
       
   120