Blame src/tools/update-copyright-year

Packit cf904d
eval '(exit $?0)' && eval 'exec perl -wS -i "$0" ${1+"$@"}'
Packit cf904d
  & eval 'exec perl -wS -i "$0" $argv:q'
Packit cf904d
    if 0;
Packit cf904d
Packit cf904d
# Copyright 2015-2017 by
Packit cf904d
# Werner Lemberg.
Packit cf904d
#
Packit cf904d
# This file is part of the FreeType project, and may only be used, modified,
Packit cf904d
# and distributed under the terms of the FreeType project license,
Packit cf904d
# LICENSE.TXT.  By continuing to use, modify, or distribute this file you
Packit cf904d
# indicate that you have read the license and understand and accept it
Packit cf904d
# fully.
Packit cf904d
Packit cf904d
# [Note: This script is expected to be called by the shell, which in turn
Packit cf904d
#  calls perl automatically.  The nifty start-up code above is based on
Packit cf904d
#  gnulib's `update-copyright' script; it is a more portable replacement for
Packit cf904d
#  the shebang, using the first `perl' program in the shell's path instead.]
Packit cf904d
Packit cf904d
# Usage:
Packit cf904d
#
Packit cf904d
#   update-copyright-year file1 [file2 ...]
Packit cf904d
Packit cf904d
Packit cf904d
# This script handles copyright entries like
Packit cf904d
#
Packit cf904d
#   Copyright  2000   by
Packit cf904d
#   foobar
Packit cf904d
#
Packit cf904d
# or
Packit cf904d
#
Packit cf904d
#   /* Copyright 2000,  2001, 2004-2007 by    */
Packit cf904d
#   /* foobar                                 */
Packit cf904d
#
Packit cf904d
# and replaces them uniformly with
Packit cf904d
#
Packit cf904d
#   Copyright 2000-2015
Packit cf904d
#   foobar
Packit cf904d
#
Packit cf904d
# and
Packit cf904d
#
Packit cf904d
#   /* Copyright 2000-2015 by                 */
Packit cf904d
#   /* foobar                                 */
Packit cf904d
#
Packit cf904d
# (assuming that the current year is 2015).  As can be seen, the line length
Packit cf904d
# is retained if there is non-whitespace after the word `by' on the same
Packit cf904d
# line.
Packit cf904d
Packit cf904d
use strict;
Packit cf904d
Packit cf904d
Packit cf904d
my (undef, undef, undef,
Packit cf904d
    undef, undef, $year,
Packit cf904d
    undef, undef, undef) = localtime(time);
Packit cf904d
$year += 1900;
Packit cf904d
Packit cf904d
my $replaced = 0;
Packit cf904d
Packit cf904d
Packit cf904d
# Loop over all input files; option `-i' (issued at the very beginning of
Packit cf904d
# this script) makes perl edit them in-place.
Packit cf904d
while (<>)
Packit cf904d
{
Packit cf904d
  # Only handle the first copyright notice in a file.
Packit cf904d
  if (!$replaced)
Packit cf904d
  {
Packit cf904d
    # First try: Search multiple copyright years.
Packit cf904d
    s {
Packit cf904d
        (?<begin>.*)
Packit cf904d
        Copyright
Packit cf904d
        (?<space1>\ +)
Packit cf904d
        (?<first>[12][0-9][0-9][0-9])
Packit cf904d
        (?<middle>.+)
Packit cf904d
        (?<last>[12][0-9][0-9][0-9])
Packit cf904d
        (?<space2>\ +)
Packit cf904d
        by
Packit cf904d
        (?<space3>\ *)
Packit cf904d
        (?<end>.*)
Packit cf904d
      }
Packit cf904d
      {
Packit cf904d
        # Fill line to the same length (if appropriate); we skip the middle
Packit cf904d
        # part but insert two spaces and `-'.
Packit cf904d
        my $space = length($+{space1}) - 1
Packit cf904d
                    + length($+{middle}) - 1
Packit cf904d
                    + length($+{space2}) - 1
Packit cf904d
                    + length($+{space3});
Packit cf904d
Packit cf904d
        print "$+{begin}";
Packit cf904d
        print "Copyright\ $+{first}-$year\ by";
Packit cf904d
        print ' ' x $space if length($+{end});
Packit cf904d
        print "$+{end}\n";
Packit cf904d
        $replaced = 1;
Packit cf904d
      }ex
Packit cf904d
    ||
Packit cf904d
    # Second try: Search a single copyright year.
Packit cf904d
    s {
Packit cf904d
        (?<begin>.*)
Packit cf904d
        Copyright
Packit cf904d
        (?<space1>\ +)
Packit cf904d
        (?<first>[12][0-9][0-9][0-9])
Packit cf904d
        (?<space2>\ +)
Packit cf904d
        by
Packit cf904d
        (?<space3>\ *)
Packit cf904d
        (?<end>.*)
Packit cf904d
      }
Packit cf904d
      {
Packit cf904d
        # Fill line to the same length (if appropriate); we insert two
Packit cf904d
        # spaces, a `-', and the current year.
Packit cf904d
        my $space = length($+{space1}) - 1
Packit cf904d
                    + length($+{space2}) - 1
Packit cf904d
                    + length($+{space3})
Packit cf904d
                    - (length($year) + 1);
Packit cf904d
Packit cf904d
        print "$+{begin}";
Packit cf904d
        print "Copyright $+{first}-$year by";
Packit cf904d
        # If $space is negative this inserts nothing.
Packit cf904d
        print ' ' x $space if length($+{end});
Packit cf904d
        print "$+{end}\n";
Packit cf904d
        $replaced = 1;
Packit cf904d
      }ex
Packit cf904d
    ||
Packit cf904d
    # Otherwise print line unaltered.
Packit cf904d
    print;
Packit cf904d
  }
Packit cf904d
  else
Packit cf904d
  {
Packit cf904d
    print;
Packit cf904d
  }
Packit cf904d
}
Packit cf904d
continue
Packit cf904d
{
Packit cf904d
  # Reset $replaced before processing the next file.
Packit cf904d
  $replaced = 0 if eof;
Packit cf904d
}
Packit cf904d
Packit cf904d
# EOF