copyright-extractor revision 12651
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] 12636N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 12636N/A# Use is subject to license terms. 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"; 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 # end of comments, stop processing 12636N/A # delete certain types of comments, like emacs mode spec, etc 12636N/A# process a directory or a file recursively: extract the comments 12636N/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 print "DEBUG: attempting to merge\n"; 12636N/A print "DEBUG: lines already processed from 1st text:\n"; 12636N/A print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; 12636N/A print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; 12636N/A print "DEBUG: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; 12636N/A print "DEBUG: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"; 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 print "DEBUG: 1st common line:\n"; 12636N/A # lines1 should be empty, all lines moved to mlines1 12636N/A print "DEBUG: no more common lines.\n"; 12636N/A # only merge if the number of common lines is at least 11 12636N/A # or we are at the end of one of the texts or if at the 12636N/A print "DEBUG: common lines:\n"; 12636N/A print "DEBUG: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; 12636N/A # first the lines from the 1st text 12636N/A # then the lines from the 2nd text 12636N/A # add the common lines to the processed part of the 1st text 12636N/A # add the common lines back to the unprocessed part of the 2nd text 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 # add the normalised lines before the common lines back to 12636N/A # the unprocessed part of the 2nd text 12636N/A # add the normalised common lines back to 12636N/A # try to merge the rest of the texts 12636N/A # repeat the process for the remaining lines 12636N/A # ignore whitespace differences 12636N/A # ignore whitespace differences 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/A-------------------------------------------------------------------- 12636N/A "--------------------------------------------------------------------" . 12636N/A print "\nThe following files were not checked:\n\n";