• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1eval '(exit $?0)' && eval 'exec perl -wS -i "$0" ${1+"$@"}'
2  & eval 'exec perl -wS -i "$0" $argv:q'
3    if 0;
4
5# Copyright (C) 2015-2019 by
6# Werner Lemberg.
7#
8# This file is part of the FreeType project, and may only be used, modified,
9# and distributed under the terms of the FreeType project license,
10# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
11# indicate that you have read the license and understand and accept it
12# fully.
13
14# [Note: This script is expected to be called by the shell, which in turn
15#  calls perl automatically.  The nifty start-up code above is based on
16#  gnulib's `update-copyright' script; it is a more portable replacement for
17#  the shebang, using the first `perl' program in the shell's path instead.]
18
19# Usage:
20#
21#   update-copyright-year file1 [file2 ...]
22
23
24# This script handles copyright entries like
25#
26#   Copyright  2000   by
27#   foobar
28#
29# or
30#
31#   /* Copyright 2000,  2001, 2004-2007 by    */
32#   /* foobar                                 */
33#
34# and replaces them uniformly with
35#
36#   Copyright 2000-2015
37#   foobar
38#
39# and
40#
41#   /* Copyright 2000-2015 by                 */
42#   /* foobar                                 */
43#
44# (assuming that the current year is 2015).  As can be seen, the line length
45# is retained if there is non-whitespace after the word `by' on the same
46# line.
47
48use strict;
49
50
51my (undef, undef, undef,
52    undef, undef, $year,
53    undef, undef, undef) = localtime(time);
54$year += 1900;
55
56my $replaced = 0;
57
58
59# Loop over all input files; option `-i' (issued at the very beginning of
60# this script) makes perl edit them in-place.
61while (<>)
62{
63  # Only handle the first copyright notice in a file.
64  if (!$replaced)
65  {
66    # First try: Search multiple copyright years.
67    s {
68        (?<begin>.*)
69        Copyright
70        (?<space1>(\ +
71                   | \ +\(C\)\ +))
72        (?<first>[12][0-9][0-9][0-9])
73        (?<middle>.+)
74        (?<last>[12][0-9][0-9][0-9])
75        (?<space2>\ +)
76        by
77        (?<space3>\ *)
78        (?<end>.*)
79      }
80      {
81        # Fill line to the same length (if appropriate); we skip the middle
82        # part but insert `(C)', three spaces, and `-'.
83        my $space = length($+{space1}) - 1
84                    + length($+{middle}) - 1
85                    + length($+{space2}) - 1
86                    + length($+{space3})
87                    - (length("(C)") + 1);
88
89        print "$+{begin}";
90        print "Copyright\ (C)\ $+{first}-$year\ by";
91        print ' ' x $space if length($+{end});
92        print "$+{end}\n";
93        $replaced = 1;
94      }ex
95    ||
96    # Second try: Search a single copyright year.
97    s {
98        (?<begin>.*)
99        Copyright
100        (?<space1>(\ +
101                   | \ +\(C\)\ +))
102        (?<first>[12][0-9][0-9][0-9])
103        (?<space2>\ +)
104        by
105        (?<space3>\ *)
106        (?<end>.*)
107      }
108      {
109        # Fill line to the same length (if appropriate); we insert three
110        # spaces, a `-', and the current year.
111        my $space = length($+{space1}) - 1
112                    + length($+{space2}) - 1
113                    + length($+{space3})
114                    - (length($year) + 1);
115
116        print "$+{begin}";
117        print "Copyright\ (C)\ $+{first}-$year\ by";
118        # If $space is negative this inserts nothing.
119        print ' ' x $space if length($+{end});
120        print "$+{end}\n";
121        $replaced = 1;
122      }ex
123    ||
124    # Otherwise print line unaltered.
125    print;
126  }
127  else
128  {
129    print;
130  }
131}
132continue
133{
134  # Reset $replaced before processing the next file.
135  $replaced = 0 if eof;
136}
137
138# EOF
139