From ee491036a41c1dbc6fb7fb196dbd139f1ddf124a Mon Sep 17 00:00:00 2001 From: des Date: Mon, 18 Sep 2006 20:26:19 +0000 Subject: [PATCH] A tool to add the BSD license to the top of a source file or script. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1081 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-tools/licensify/licensify.pl | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 varnish-tools/licensify/licensify.pl diff --git a/varnish-tools/licensify/licensify.pl b/varnish-tools/licensify/licensify.pl new file mode 100755 index 00000000..c80603cf --- /dev/null +++ b/varnish-tools/licensify/licensify.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Verdens Gang AS +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +use strict; +use vars qw($FIRSTYEAR $LICENSE); + +$FIRSTYEAR = 2006; + +$LICENSE = +"Copyright (c) YYYY Verdens Gang AS +Copyright (c) YYYY Linpro AS +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + +"; + +sub licensify($) { + my $fn = shift; + + local *FILE; + local $/; + my $contents; + my $first; + my $prefix; + my $license; + + open(FILE, "<", $fn) + or die("$fn: $!\n"); + $contents = ; + close(FILE); + + return unless $contents =~ m/^(\.\\\"|\/\*|\#!\/[^\n]+\n\#)(-?)\n/s; + return if $2; + $first = $1; + if ($first =~ /^\#/) { + $prefix = "#"; + } elsif ($first =~ /\/\*/) { + $prefix = " *"; + } else { + $prefix = $first; + } + ($license = $LICENSE) =~ s/^/$prefix /gm; + $license =~ s/[\t ]+$//gm; + $contents =~ s/^(\Q$first\E)\n/$1-\n$license/s; + + open(FILE, ">", $fn) + or die("$fn: $!\n"); + print(FILE $contents); + close(FILE); +} + +MAIN:{ + my @tm = localtime(time()); + my $year = 1900 + $tm[5]; + $year = "$FIRSTYEAR-$year" + unless ($year == $FIRSTYEAR); + $LICENSE =~ s/YYYY/$year/g; + foreach (@ARGV) { + licensify($_); + } +} -- 2.39.5