Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

executable file 64 lines (59 sloc) 1.189 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/usr/bin/perl

$license_file = shift @ARGV;

open LICENSE, "<$license_file" or die "Can't read license file $license_file";

@license = <LICENSE>;

if( $ARGV[0] eq "-" ) {
  while( <STDIN> ) {
    @line_files = split( /\s/, $_ );
    push( @files, @line_files );
  }
}
else {
  @files = @ARGV;
}

while (@files) {
  $file = shift @files;
  open FILE, "<$file" or die "Can't open file $file for reading";
  $tmp = "$file.relicense";
  open TMP, ">$tmp" or die "Can't open file $tmp for writing";
  while ( <FILE> ) {
    print TMP;
    if( /^(.*)__BEGIN_LICENSE__/ ) {
      $prefix = $1;
      last;
    }
  }
  if( eof FILE ) {
    close FILE;
    close TMP;
    unlink $tmp;
    next;
  }
  print TMP $prefix."\n";
  foreach (@license) {
    print TMP $prefix.$_;
  }
  print TMP $prefix."\n";
  while( <FILE> ) {
    if( /__END_LICENSE__/ ) {
      print TMP;
      last;
    }
  }
  if( eof FILE ) {
    print "Error: End of license not found while relicensing $file\n";
    close FILE;
    close TMP;
    unlink $tmp;
    next;
  }
  while( <FILE> ) {
    print TMP;
  }
  close FILE;
  close TMP;
  print "Relicensing $file";
  unlink $file;
  rename $tmp, $file;
  print "\n";
}
Something went wrong with that request. Please try again.