12636N/A# Script for extracting copyright and licensing information from source code 12636N/A# The contents of this file are subject to the terms of the 12636N/A# Common Development and Distribution License, Version 1.0 only 12636N/A# (the "License"). You may not use this file except in compliance 12636N/A# See the License for the specific language governing permissions 12636N/A# and limitations under the License. 12636N/A# When distributing Covered Code, include this CDDL HEADER in each 12636N/A# If applicable, add the following below this CDDL HEADER, with the 12636N/A# fields enclosed by brackets "[]" replaced with your own identifying 12636N/A# information: Portions Copyright [yyyy] [name of copyright owner] 19915N/A# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 12636N/A print "copyright-extractor [options] <source directory>\n"; 12636N/A print " Print raw comments only, do not attempt to merge,\n"; 12636N/A print " only unify identical comments.\n"; 12636N/A print " -c, --copyright-first\n"; 12636N/A print " Attempt to move copyright statements to the start of the\n"; 12636N/A print " Note: when using this option, there is a chance that\n"; 12636N/A print " lines get mixed up if a copyright statement extends to\n"; 12636N/A print " more than one line.\n"; 12701N/A print " only merge if there are at least n consecutive identical\n"; 12636N/A print " Add the disclaimer about GPLv2 to the beginning of the\n"; 12636N/A print " Print a list of files that were not checked\n"; 12636N/A print " Print this usage information\n"; 12636N/A print " Turn on debug output.\n"; 12636N/A print "Try --help for usage.\n"; 12636N/A# a very simple file type check based on the file name 12636N/A# fname: the file name to classify 12636N/A# Returns: one of the above contants 12636N/A # some more file names to ignore 12636N/A # FIXME: could do something smart here 12636N/A# return 1 if the string includes words that suggest that the string 12636N/A# is some sort of legal text. If none of these words appear in the 12636N/A# string, this program will ignore it and assume that it's some other 12636N/A# comment that happens to be at the beginning of the file 12636N/A # delete certain types of comments, like emacs mode spec, etc 12636N/A # add to blurb if not the start of the blurb 12636N/A # delete certain types of comments, like emacs mode spec, etc 13093N/A # add to blurb if not the start of the blurb 13093N/A # delete certain types of comments, like emacs mode spec, etc 12636N/A# process a directory or a file recursively: extract the comments 20126N/A# from the beginning of each file and save them in %blurbs 12636N/A # directory -> process recursively 12636N/A # regular file -> identify file type and read comments 12636N/A# return the number of lines in str 12636N/A# return 1 if str is a member of the list, 0 otherwise 12636N/A# Args: references to lists of strings (lines of the texts) 12636N/A# ml1: lines from the first text already processed 12636N/A# l1: remaining lines of the 1st text 12636N/A# nl1: remaining normalised lines of the 1st text 12636N/A# l2: remaining lines of the 2nd text 12636N/A# nl2: remaining normalised lines of the 1st text 12636N/A push (@merged_lines, @mlines1); 12636N/A push (@merged_lines, @mlines1); 12636N/A # first save the lines only appearing in lines1, 12636N/A # stop at the first 2 common lines that are not empty 12636N/A # now save the lines appearing in lines2 before the common line 12636N/A # now save the first common line 12636N/A # lines1 should be empty, all lines moved to mlines1 12636N/A push (@merged_lines, @mlines1); 12636N/A push (@merged_lines, @mlines2); 12636N/A # or we are at the end of one of the texts or if at the 12636N/A (not @lines1) or (not @lines2) or 12636N/A foreach my $l (@common_lines) { 12636N/A print "DEBUG: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; 12636N/A # first the lines from the 1st text 12636N/A push (@merged_lines, @mlines1); 12636N/A # then the lines from the 2nd text 12636N/A push (@merged_lines, @mlines2); 12636N/A push (@merged_lines, @common_lines); 12636N/A # add the common lines to the processed part of the 1st text 12636N/A push (@mlines1, @common_lines); 12636N/A # add the common lines back to the unprocessed part of the 2nd text 12636N/A unshift (@lines2, @common_lines); 12636N/A # add the lines before the common lines back to the unprocessed 12636N/A # add the normalised common lines back to 12636N/A # the unprocessed part of the 2nd text 12636N/A unshift (@norm_lines2, @ncommon_lines); 12636N/A # add the normalised lines before the common lines back to 12636N/A # the unprocessed part of the 2nd text 12636N/A unshift (@norm_lines2, @nmlines2); 12636N/A # add the normalised common lines back to 12636N/A # try to merge the rest of the texts 12636N/A my @more_merged_lines = do_merge_comments (\@mlines1, 12636N/A \@lines1, \@norm_lines1, \@lines2, \@norm_lines2); 12636N/A push (@merged_lines, @more_merged_lines); 12636N/A # repeat the process for the remaining lines 12636N/A my @more_merged_lines = do_merge_comments (\@l1, 12636N/A \@lines1, \@norm_lines1, \@lines2, \@norm_lines2); 12636N/A push (@merged_lines, @more_merged_lines); 12636N/A # ignore whitespace differences 12636N/A # ignore whitespace differences 12636N/A my @merged_lines = do_merge_comments (\@l0, \@lines1, \@norm_lines1, 12636N/A if ($line =~ /^\s*(copyright|\(c\)|©|author:|all rights reserved)/i) { 12636N/A @copyright_lines = sort (@copyright_lines); 12636N/A @copyright_lines = uniq (@copyright_lines); 20126N/A if ($blurb =~ /\b(gpl|lgpl|gnu\s+(library\s+|lesser\s+|)general\s+public\s+license)\b/si) { 20126N/A @all_comments = (keys %comments); 12636N/A my @temp_all_comments = @all_comments; 12636N/A while ($i <= $#temp_all_comments) { 12636N/A for (my $j = $i+1; $j <= $#temp_all_comments; $j++) { 12636N/A # if more than 10 lines or more than 25% saved then 12636N/A print "DEBUG*****************************************\n"; 12636N/A print "++++++++++++++++++++++++++++++++++++++++++++++\n"; 12636N/A print "==============================================\n"; 12636N/A print "*****************************************DEBUG\n"; 12636N/AFor the avoidance of doubt, except that if any license choice other 19125N/Athan GPL or LGPL is available it will apply instead, Oracle elects to 12636N/Ause only the General Public License version 2 (GPLv2) at this time 12636N/Afor any software where a choice of GPL license versions is made 12636N/Aavailable with the language indicating that GPLv2 or any later 12636N/Aversion may be used, or where a choice of which version of the GPL 12636N/Ais applied is otherwise unspecified. 12636N/A-------------------------------------------------------------------- 12636N/A "--------------------------------------------------------------------" .