9162 libpp: this statement may fall through
[unleashed.git] / usr / src / lib / libc / extract-copyright.pl
blobb254abbe45be333fb1742ae27e663ed6e3188504
1 #! /usr/perl5/bin/perl
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms version
6 # 1.0 of the CDDL.
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy is of the CDDL is also available via the Internet
10 # at http://www.illumos.org/license/CDDL.
14 # Copyright 2010 Nexenta Systems, Inc. All rights reserved.
15 # Copyright 2016 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
19 # This extracts all the BSD copyrights (excluding the CDDL licenses)
20 # for use in a THIRDPARTYLICENSE file. It tries hard to avoid duplicates.
23 use strict;
24 use warnings;
25 use File::Find;
27 my %LICENSE = ();
29 sub dofile
31 my $file = shift;
32 my $comment = 0;
33 my @license = ();
34 my @block = ();;
35 my $copyr = 0;
36 open(FILE, $file);
37 while (<FILE>) {
38 if (/^\/\*$/) {
39 $comment = 1;
40 $copyr = 0;
41 @block = ();
42 next;
44 if (!$comment) {
45 next;
48 # We don't want to know about CDDL files. They don't
49 # require an explicit THIRDPARTYLICENSE file.
51 if (/CDDL/) {
52 #print "$file is CDDL.\n";
53 close(FILE);
54 return;
56 if (/Copyright/) {
57 $copyr = 1;
59 if (!/^ \*\//) {
60 push(@block, $_);
61 next;
64 # We have reached the end of the comment now.
66 $comment = 0;
68 # Check to see if we saw a copyright.
69 if (!$copyr) {
70 next;
72 my $line;
73 foreach $line (@block) {
74 chomp $line;
75 $line =~ s/^ \* //;
76 $line =~ s/^ \*//;
77 $line =~ s/^ \*$//;
78 push(@license, $line);
82 if ($#license > 0) {
83 my $lic = join "\n", @license;
84 push (@{$LICENSE{$lic}}, $file);
87 close(FILE);
90 my @FILES;
92 sub wanted {
93 my $path = $File::Find::name;
95 if (!-f $path) {
96 if ($path =~ /\.[chs]$/) {
97 push(@FILES, $path);
102 foreach $a (@ARGV) {
103 if (-d $a) {
104 find(\&wanted, $a);
105 } elsif (-f $a) {
106 push(@FILES, $a);
110 # sort files to get a stable ordering to aid wsdiff(1onbld)
111 @FILES = sort @FILES;
113 foreach $a (@FILES) {
114 dofile($a);
117 foreach my $lic (sort keys %LICENSE) {
118 my @files = @{$LICENSE{$lic}};
119 print "\nThe following files from the C library:\n";
120 foreach my $f (@files) {
121 print(" $f\n");
123 print "are provided under the following terms:\n\n";
124 print "$lic\n";