#!/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 re
+ading: $!\n"; next; };
open(OUTPUT, '>', $_) or do {print STDERR "Error opening $_ for writi
+ng: $!\n"; next; };
select OUTPUT;
if ($opts{h}) { print scalar <INPUT> 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] + 1
+900, " $name\n\n";
print $perl ? '#' : ' ', " This file is part of $progName.\n\n" if $
+progName ne 'this program';
my $notice = <<EOT;
\u$progName is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published b
+y
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
\u$progName is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with $progName. If not, see <http://www.gnu.org/licenses/>.
EOT
$perl ? $notice =~ s/^ /#/gm : $notice =~ s!\n$! */\n!;
print $notice, "\n";
print while <INPUT>;
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 inser
+ting 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 messa
+ge similar to the following (taken from the end of the GPL) on startu
+p:
<program> Copyright (C) <year> <name of author>
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 prep
+aring 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 r
+ights to any programs you create while working there, have an adminis
+trator sign a copyright disclaimer.
|