williamr/convert_to_eula.pl
changeset 74 df789c4e291d
parent 71 59ba21437bf0
child 88 d22c49c5048f
equal deleted inserted replaced
73:421d5a95c85a 74:df789c4e291d
    29   'terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members',
    29   'terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members',
    30   'the URL "http://www.symbianfoundation.org/legal/licencesv10.html"'
    30   'the URL "http://www.symbianfoundation.org/legal/licencesv10.html"'
    31 );
    31 );
    32 
    32 
    33 my @errorfiles = ();
    33 my @errorfiles = ();
       
    34 my @multinoticefiles = ();
    34 
    35 
    35 sub map_eula($$$)
    36 sub map_eula($$$)
    36   {
    37   {
    37   my ($file,$shadowdir,$name) = @_;
    38   my ($file,$shadowdir,$name) = @_;
    38   
    39   
    40   my @lines = <FILE>;
    41   my @lines = <FILE>;
    41   close FILE;
    42   close FILE;
    42   
    43   
    43   my $updated = 0;
    44   my $updated = 0;
    44   my @newlines = ();
    45   my @newlines = ();
    45   my $index = 1;
       
    46   while (my $line = shift @lines)
    46   while (my $line = shift @lines)
    47     { 
    47     { 
    48 	if (index($line,$newtext[0]) >= 0)
       
    49     {
       
    50       # file already converted - nothing to do
       
    51 	  push @newlines, $line;
       
    52 	  next;
       
    53 	  #last;
       
    54     }
       
    55     # under the terms of the License "Symbian Foundation License v1.0"
    48     # under the terms of the License "Symbian Foundation License v1.0"
    56     # which accompanies this distribution, and is available
    49     # which accompanies this distribution, and is available
    57     # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
    50     # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
    58     my $pos1 = index $line, $oldtext[0];
    51     my $pos1 = index $line, $oldtext[0];
    59     if ($pos1 >= 0)
    52     if ($pos1 >= 0)
    60       {
    53       {
       
    54       # be careful - oldtext is a prefix of newtext!
       
    55       if (index($line, $newtext[0]) >= 0)
       
    56         {
       
    57         # line already converted - nothing to do
       
    58         push @newlines, $line;
       
    59         next;
       
    60         }
    61       my $midline = shift @lines;
    61       my $midline = shift @lines;
    62       my $urlline = shift @lines;
    62       my $urlline = shift @lines;
    63 	  $index+=2;
       
    64       my $pos2 = index $urlline, $oldtext[1];
    63       my $pos2 = index $urlline, $oldtext[1];
    65       if ($pos2 >= 0)
    64       if ($pos2 >= 0)
    66         {
    65         {
    67         # Found it - assume that there's only one instance
    66         # Found it - assume that there's only one instance
    68         substr $line, $pos1, length($oldtext[0]), $newtext[0];
    67         substr $line, $pos1, length($oldtext[0]), $newtext[0];
    69         substr $urlline, $pos2, length($oldtext[1]), $newtext[1];
    68         substr $urlline, $pos2, length($oldtext[1]), $newtext[1];
    70         push @newlines, $line, $midline, $urlline;
    69         push @newlines, $line, $midline, $urlline;
    71         $updated = 1;
    70         $updated += 1;
    72         next;
    71         next;
    73         #last;
       
    74         }
    72         }
    75       else
    73       else
    76         {
    74         {
    77 			if(!$updated)
    75         if(!$updated)
    78 			{
    76           {
    79 				print STDERR "Problem in $file at $index: incorrectly formatted >\n$line$midline$urlline\n";
    77           my $lineno = 1 + (scalar @newlines);
    80 				push @errorfiles, $file;
    78           print STDERR "Problem in $file at $lineno: incorrectly formatted >\n$line$midline$urlline\n";
    81 			}	
    79           push @errorfiles, $file;
       
    80           }	
    82         last;
    81         last;
    83         }
    82         }
    84       }
    83       }
    85     push @newlines, $line;
    84     push @newlines, $line;
    86 	$index+=1;
       
    87     }
    85     }
    88 
    86 
    89   return if (!$updated);
    87   return if (!$updated);
       
    88   
       
    89   if ($updated > 1)
       
    90     {
       
    91     push @multinoticefiles, $file;
       
    92     print "! found $updated SFL notices in $file\n";
       
    93     }
    90  
    94  
    91   mkpath($shadowdir, {verbose=>0});
    95   mkpath($shadowdir, {verbose=>0});
    92   move($file, "$shadowdir/$name") or die("Cannot move $file to $shadowdir/$name: $!\n");
    96   move($file, "$shadowdir/$name") or die("Cannot move $file to $shadowdir/$name: $!\n");
    93   open NEWFILE, ">$file" or die("Cannot overwrite $file: $!\n");
    97   open NEWFILE, ">$file" or die("Cannot overwrite $file: $!\n");
    94   print NEWFILE @newlines, @lines;
    98   print NEWFILE @newlines, @lines;
   125 scan_directory("/epoc32", "/sfl_epoc32");
   129 scan_directory("/epoc32", "/sfl_epoc32");
   126 
   130 
   127 printf "%d problem files\n", scalar @errorfiles;
   131 printf "%d problem files\n", scalar @errorfiles;
   128 print "\t", join("\n\t", @errorfiles), "\n";
   132 print "\t", join("\n\t", @errorfiles), "\n";
   129 
   133 
       
   134 printf "%d files with multiple notices\n", scalar @multinoticefiles;
       
   135 print "\t", join("\n\t", @multinoticefiles), "\n";
       
   136