williamr/convert_to_eula.pl
changeset 88 d22c49c5048f
parent 74 df789c4e291d
child 115 5bbdda50c091
equal deleted inserted replaced
79:ce6215be051a 88:d22c49c5048f
    56         {
    56         {
    57         # line already converted - nothing to do
    57         # line already converted - nothing to do
    58         push @newlines, $line;
    58         push @newlines, $line;
    59         next;
    59         next;
    60         }
    60         }
    61       my $midline = shift @lines;
    61 	  my @midlines = ();
    62       my $urlline = shift @lines;
    62       my $nextline;
       
    63 	  my $midlinecount = 1;
       
    64 	  while ($nextline = shift @lines)
       
    65 		{
       
    66 		if ($nextline !~ /^\s$/)
       
    67 		  {
       
    68 		  # non-blank line
       
    69 		  last if ($midlinecount == 0);
       
    70 		  $midlinecount -= 1;
       
    71 		  # keep going
       
    72 		  }
       
    73 		push @midlines, $nextline;
       
    74 		}
       
    75       my $urlline = $nextline;
    63       my $pos2 = index $urlline, $oldtext[1];
    76       my $pos2 = index $urlline, $oldtext[1];
    64       if ($pos2 >= 0)
    77       if ($pos2 >= 0)
    65         {
    78         {
    66         # Found it - assume that there's only one instance
    79         # Found it - assume that there's only one instance
    67         substr $line, $pos1, length($oldtext[0]), $newtext[0];
    80         substr $line, $pos1, length($oldtext[0]), $newtext[0];
    68         substr $urlline, $pos2, length($oldtext[1]), $newtext[1];
    81         substr $urlline, $pos2, length($oldtext[1]), $newtext[1];
    69         push @newlines, $line, $midline, $urlline;
    82         push @newlines, $line, @midlines, $urlline;
    70         $updated += 1;
    83         $updated += 1;
    71         next;
    84         next;
    72         }
    85         }
    73       else
    86       else
    74         {
    87         {
    75         if(!$updated)
    88         if(!$updated)
    76           {
    89           {
    77           my $lineno = 1 + (scalar @newlines);
    90           my $lineno = 1 + (scalar @newlines);
    78           print STDERR "Problem in $file at $lineno: incorrectly formatted >\n$line$midline$urlline\n";
    91           print STDERR "Problem in $file at $lineno: incorrectly formatted >\n$line", join("",@midlines), "$urlline\n";
    79           push @errorfiles, $file;
    92           push @errorfiles, $file;
    80           }	
    93           }	
    81         last;
    94         last;
    82         }
    95         }
    83       }
    96       }