#!/usr/bin/perl -w
# gpl3ify.pl
# This script applies the GNU GPL v.3 to the specified source file(s).
# Created 27 Sept 2007 by John T. Wodder II
# Last edited 28 Sept 2007 by John Wodder
# See the end of this file for documentation.
use strict;
use Getopt::Std;
my $name = 'Japheth A. Packer-Herl';
my $gpl = "$ENV{HOME}/resources/GPLv3.txt";
my %opts;
getopts('cd:h:n:o:', \%opts);
if ($opts{c}) {
if (defined($gpl) && -e $gpl) {
my $dir = shift || '.';
system("cp $gpl $dir/COPYING");
} else { print "You do not have a copy of the GNU GPL specified.\n" }
exit(0);
}
my $progName = $opts{n} || 'this program';
sub basename($) {
my $file = shift;
$file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!;
return $file;
}
foreach (@ARGV) {
my $input = $opts{o} ? "$_$opts{o}" : ".$_~";
rename $_, $input;
open(INPUT, '<', $input) or do {print STDERR "Error opening $_ for reading: $!\n"; next; };
open(OUTPUT, '>', $_) or do {print STDERR "Error opening $_ for writing: $!\n"; next; };
select OUTPUT;
if ($opts{h}) { print scalar for 1..$opts{h} }
my $perl = /\.pl$/;
print $perl ? '# ' : '/* ', ($progName ne 'this program') ? $progName : basename($_);
print ' - ', $opts{d} if $opts{d};
print "\n", $perl ? '#' : ' ', " Copyright (C) ", (localtime)[5] + 1900, " $name\n\n";
print $perl ? '#' : ' ', " This file is part of $progName.\n\n" if $progName ne 'this program';
my $notice = <.
EOT
$perl ? $notice =~ s/^ /#/gm : $notice =~ s!\n$! */\n!;
print $notice, "\n";
print while ;
unlink $input unless $opts{o};
}
__END__
Switches:
-c - Copy the GPL to the named directory
-n [name] - Specify the name of the program (for use in multi-source file programs). If this switch is missing, the program name is taken to be the basename of the file.
-d [desc] - Specify a short description of the program
-o [exten] - Save a GPL-free version of the source file in "$filename$exten"
-h [number] - Skip the first `number' lines in each file before inserting the GPL notice
The arguments are the source files to modify.
Other notes on using the GNU GPL, v.3:
- If the program has an interactive mode, it should print out a message similar to the following (taken from the end of the GPL) on startup:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
- Details on how to contact you should be included in a README file.
- If code is copied from other programs licensed under the GPL, their copyright notices should be grouped at the top of the file with your copyright notice.
- The copyright notice should list the year(s) that you finished preparing each release.
- If several people wrote the code, list all their names.
- If you are working for or at an institution which could claim the rights to any programs you create while working there, have an administrator sign a copyright disclaimer.