This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / dist-3.0at70b / pl / copyright.pl
1 ;# $Id: copyright.pl,v 3.0 1993/08/18 12:10:51 ram Exp $
2 ;#
3 ;#  Copyright (c) 1991-1993, Raphael Manfredi
4 ;#  
5 ;#  You may redistribute only under the terms of the Artistic Licence,
6 ;#  as specified in the README file that comes with the distribution.
7 ;#  You may reuse parts of this distribution only within the terms of
8 ;#  that same Artistic Licence; a copy of which may be found at the root
9 ;#  of the source tree for dist 3.0.
10 ;#
11 ;# $Log: copyright.pl,v $
12 ;# Revision 3.0  1993/08/18  12:10:51  ram
13 ;# Baseline for dist 3.0 netwide release.
14 ;#
15 ;#
16 ;# Copyright expansion. The @COPYRIGHT@ symbol is expanded the first time
17 ;# it is seen in a file, and before the $Log RCS marker is reached. The
18 ;# automaton needs to be reset for each file.
19 ;#
20 package copyright;
21
22 # Read in copyright file
23 sub init {
24         local($file) = @_;              # Copyright file
25         undef @copyright;
26         open(COPYRIGHT, $file) || die "Can't open $file: $!\n";
27         chop(@copyright = <COPYRIGHT>);
28         close COPYRIGHT;
29 }
30
31 # Reset the automaton for a new file.
32 sub reset {
33         $copyright_seen = @copyright ? 0 : 1;
34         $marker_seen = 0;
35 }
36
37 # Filter file, line by line, and expand the copyright string. The @COPYRIGHT@
38 # symbol may be preceded by some random comment. A leader can be defined and
39 # will be pre-pended to all the input lines.
40 sub filter {
41         local($line, $leader) = @_;             # Leader is optional
42         return $leader . $line if $copyright_seen || $marker_seen;
43         $marker_seen = 1 if $line =~ /\$Log[:\$]/;
44         $copyright_seen = 1 if $line =~ /\@COPYRIGHT\@/;
45         return $leader . $line unless $copyright_seen;
46         local($comment, $trailer) = $line =~ /^(.*)\@COPYRIGHT\@\s*(.*)/;
47         $comment = $leader . $comment;
48         $comment . join("\n$comment", @copyright) . "\n";
49 }
50
51 # Filter output of $cmd redirected into $file by expanding copyright, if any.
52 sub expand {
53         local($cmd, $file) = @_;
54         if (@copyright) {
55                 open(CMD,"$cmd|") || die "Can't start '$cmd': $!\n";
56                 open(OUT, ">$file") || die "Can't create $file: $!\n";
57                 &reset;
58                 local($_);
59                 while (<CMD>) {
60                         print OUT &filter($_);
61                 }
62                 close OUT;
63                 close CMD;
64         } else {
65                 system "$cmd > $file";
66                 die "Command '$cmd' failed!" if $?;
67         }
68 }
69
70 package main;
71