Add SSL_client_version() getter function
[openssl.git] / util / copyright.pl
1 #! /usr/bin/env perl
2 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 # Add new copyright and delete old ones.  Used as
10 #   find . -name '*.[ch]' -type f -exec perl -i.bak util/copyright.pl '{}' ';'
11 # This does not do everything that's needed for the consolidation.
12
13 use strict;
14 use warnings;
15
16 # Read a multi-line comments.  If it matches a "fingerprint" of a legacy
17 # copyright block, then just delete it.
18 sub check_comment()
19 {
20     my @lines = ( @_ );
21     my $skipit = 0;
22
23     if ($lines[$#lines] !~ m@\*/@) {
24         while ( <> ) {
25             push @lines, $_;
26             last if m@\*/@;
27             $skipit = 1 if /Copyright remains Eric Young's/i;
28             $skipit = 1 if /Copyright.*The OpenSSL Project/i;
29             $skipit = 1 if /Written by.*for the OpenSSL Project/i;
30         }
31     }
32
33     # Look for a multi-line "written by" comment.
34     if ( ! $skipit ) {
35         my $text = join('', @lines);
36         $skipit = 1 if $text =~ m/Written by.*for the OpenSSL Project/is;
37     }
38
39     print @lines unless $skipit;
40     return $skipit;
41 }
42
43 # Look for leading copyright blocks and process (print/swallow) them.
44 while ( <> ) {
45     if ($. == 1) {
46         my $DATE;
47         # Look for special copyright EAY line at line one.
48         if ( /Copyright.*(199.)-.*Eric Young/ ) {
49             $DATE = $1;
50         } else {
51             # Nope, use when it first existed in git.
52             $DATE=`git log '--pretty=format:%cI' $ARGV | tail -1`;
53             $DATE =~ s/-.*//;
54         }
55         my $YEAR = $DATE ? $DATE : 1995;
56         my $SPAN = $YEAR == 2016 ? "2016" : "${YEAR}-2016";
57         print <<EOF;
58 /*
59  * Copyright ${SPAN} The OpenSSL Project Authors. All Rights Reserved.
60  *
61  * Licensed under the OpenSSL license (the "License").  You may not use
62  * this file except in compliance with the License.  You can obtain a copy
63  * in the file LICENSE in the source distribution or at
64  * https://www.openssl.org/source/license.html
65  */
66
67 EOF
68     }
69     next if m@^$@;
70     last if not m@/\*@;
71     last unless &check_comment($_);
72 }
73
74 if (defined($_)) {
75     print unless m@\*/@;
76
77     # Print rest of file.
78     print while ( <> );
79 }