r1081 - in trunk/varnish-tools: . licensify

des at projects.linpro.no des at projects.linpro.no
Mon Sep 18 22:26:20 CEST 2006


Author: des
Date: 2006-09-18 22:26:19 +0200 (Mon, 18 Sep 2006)
New Revision: 1081

Added:
   trunk/varnish-tools/licensify/
   trunk/varnish-tools/licensify/licensify.pl
Log:
A tool to add the BSD license to the top of a source file or script.

Added: trunk/varnish-tools/licensify/licensify.pl
===================================================================
--- trunk/varnish-tools/licensify/licensify.pl	2006-09-18 19:47:30 UTC (rev 1080)
+++ trunk/varnish-tools/licensify/licensify.pl	2006-09-18 20:26:19 UTC (rev 1081)
@@ -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 = <FILE>;
+    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($_);
+    }
+}


Property changes on: trunk/varnish-tools/licensify/licensify.pl
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id




More information about the varnish-commit mailing list