copyright-extractor revision 12660
0N/A# Script for extracting copyright and licensing information from source code 0N/A# The contents of this file are subject to the terms of the 0N/A# Common Development and Distribution License, Version 1.0 only 0N/A# (the "License"). You may not use this file except in compliance 0N/A# See the License for the specific language governing permissions 0N/A# and limitations under the License. 0N/A# When distributing Covered Code, include this CDDL HEADER in each 2362N/A# If applicable, add the following below this CDDL HEADER, with the 2362N/A# fields enclosed by brackets "[]" replaced with your own identifying 2362N/A# information: Portions Copyright [yyyy] [name of copyright owner] 0N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 0N/A# Use is subject to license terms. 0N/A print "copyright-extractor [options] <source directory>\n"; 5661N/A print " Print raw comments only, do not attempt to merge,\n"; 5661N/A print " only unify identical comments.\n"; 5661N/A print " -c, --copyright-first\n"; 0N/A print " Attempt to move copyright statements to the start of the\n"; 5661N/A print " Note: when using this option, there is a chance that\n"; 5661N/A print " lines get mixed up if a copyright statement extends to\n"; 0N/A print " more than one line.\n"; 5661N/A print " Add the disclaimer about GPLv2 to the beginning of the\n"; 5661N/A print " Print a list of files that were not checked\n"; 5661N/A print " Print this usage information\n"; 0N/A print " -d n, --debug=n\n"; 0N/A print " Turn on debug output.\n"; print "Unknown option: $arg\n"; print "Try --help for usage.\n"; 'h|help' => sub { usage (); exit (0); }, # a very simple file type check based on the file name # fname: the file name to classify # Returns: one of the above contants # some file names to ignore # some more file names to ignore # FIXME: could do something smart here # return 1 if the string includes words that suggest that the string # is some sort of legal text. If none of these words appear in the # string, this program will ignore it and assume that it's some other # comment that happens to be at the beginning of the file # delete certain types of comments, like emacs mode spec, etc $line =~ s/^\s*-\*-.*-\*-\s*$//; } elsif ($line =~ /^\/\//) { } elsif ($line =~ /^( \*|\*)/) { if ($line =~ /^\s*\/\*(.*)\*\//) { $line =~ s/^\s*\/\*(.*)\*\//$1/g; } elsif ($line =~ /^\s*\/\*/) { } elsif ($line =~ /^\/\//) { # add to blurb if not the start of the blurb # end of comments, stop processing # delete certain types of comments, like emacs mode spec, etc $line =~ s/^\s*-\*-.*-\*-\s*$//; $line =~ s/^\s*\**\s*\@-type\@\s*$//; # process a directory or a file recursively: extract the comments # from the beginning of each file and save them in @blurbs # directory -> process recursively # regular file -> identify file type and read comments # return the number of lines in str # return 1 if str is a member of the list, 0 otherwise # Args: references to lists of strings (lines of the texts) # ml1: lines from the first text already processed # l1: remaining lines of the 1st text # nl1: remaining normalised lines of the 1st text # l2: remaining lines of the 2nd text # nl2: remaining normalised lines of the 1st text # Return: list of merged lines print "DEBUG: attempting to merge\n"; print "DEBUG: lines already processed from 1st text:\n"; print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; print "DEBUG: 1st text:\n"; print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; print "DEBUG: 2nd text:\n"; print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; print "DEBUG: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"; # first save the lines only appearing in lines1, # stop at the first 2 common lines that are not empty # now save the lines appearing in lines2 before the common line # now save the first common line print "DEBUG: 1st common line:\n"; # no common lines were found # lines1 should be empty, all lines moved to mlines1 print "DEBUG: no more common lines.\n"; print "DEBUG: common line:\n"; # only merge if the number of common lines is at least 11 # or we are at the end of one of the texts or if at the # beginning of the 2nd text print "DEBUG: common lines:\n"; print "DEBUG: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; # first the lines from the 1st text # then the lines from the 2nd text # finally the common lines # add the common lines to the processed part of the 1st text # add the common lines back to the unprocessed part of the 2nd text # add the lines before the common lines back to the unprocessed # add the normalised common lines back to # the unprocessed part of the 2nd text # add the normalised lines before the common lines back to # the unprocessed part of the 2nd text # add the normalised common lines back to # try to merge the rest of the texts # repeat the process for the remaining lines # ignore whitespace differences # ignore whitespace differences # if more than 10 lines or more than 25% saved then # keep the merged comments print "DEBUG*****************************************\n"; print "++++++++++++++++++++++++++++++++++++++++++++++\n"; print "==============================================\n"; print "*****************************************DEBUG\n"; -------------------------------------------------------------------- "--------------------------------------------------------------------" . print "\nThe following files were not checked:\n\n";