add_cr.pl revision 55714
1#!/usr/local/bin/perl
2#
3# This adds a copyright message to a souce code file.
4# It also gets the file name correct.
5#
6# perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch]
7#
8
9foreach (@ARGV)
10	{
11	&dofile($_);
12	}
13
14sub dofile
15	{
16	local($file)=@_;
17
18	open(IN,"<$file") || die "unable to open $file:$!\n";
19
20	print STDERR "doing $file\n";
21	@in=<IN>;
22
23	return(1) if ($in[0] =~ / NOCW /);
24
25	@out=();
26	open(OUT,">$file.out") || die "unable to open $file.$$:$!\n";
27	push(@out,"/* $file */\n");
28	if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/))
29		{
30		push(@out,&Copyright);
31		$i=2;
32		@a=grep(/ Copyright \(C\) /,@in);
33		if ($#a >= 0)
34			{
35			while (($i <= $#in) && ($in[$i] ne " */\n"))
36				{ $i++; }
37			$i++ if ($in[$i] eq " */\n");
38
39			while (($i <= $#in) && ($in[$i] =~ /^\s*$/))
40				{ $i++; }
41
42			push(@out,"\n");
43			for ( ; $i <= $#in; $i++)
44				{ push(@out,$in[$i]); }
45			}
46		else
47			{ push(@out,@in); }
48		}
49	else
50		{
51		shift(@in);
52		push(@out,@in);
53		}
54	print OUT @out;
55	close(IN);
56	close(OUT);
57	rename("$file","$file.orig") || die "unable to rename $file:$!\n";
58	rename("$file.out",$file) || die "unable to rename $file.out:$!\n";
59	}
60
61
62
63sub Copyright
64	{
65	return <<'EOF';
66/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
67 * All rights reserved.
68 *
69 * This package is an SSL implementation written
70 * by Eric Young (eay@cryptsoft.com).
71 * The implementation was written so as to conform with Netscapes SSL.
72 *
73 * This library is free for commercial and non-commercial use as long as
74 * the following conditions are aheared to.  The following conditions
75 * apply to all code found in this distribution, be it the RC4, RSA,
76 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
77 * included with this distribution is covered by the same copyright terms
78 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
79 *
80 * Copyright remains Eric Young's, and as such any Copyright notices in
81 * the code are not to be removed.
82 * If this package is used in a product, Eric Young should be given attribution
83 * as the author of the parts of the library used.
84 * This can be in the form of a textual message at program startup or
85 * in documentation (online or textual) provided with the package.
86 *
87 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions
89 * are met:
90 * 1. Redistributions of source code must retain the copyright
91 *    notice, this list of conditions and the following disclaimer.
92 * 2. Redistributions in binary form must reproduce the above copyright
93 *    notice, this list of conditions and the following disclaimer in the
94 *    documentation and/or other materials provided with the distribution.
95 * 3. All advertising materials mentioning features or use of this software
96 *    must display the following acknowledgement:
97 *    "This product includes cryptographic software written by
98 *     Eric Young (eay@cryptsoft.com)"
99 *    The word 'cryptographic' can be left out if the rouines from the library
100 *    being used are not cryptographic related :-).
101 * 4. If you include any Windows specific code (or a derivative thereof) from
102 *    the apps directory (application code) you must include an acknowledgement:
103 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
104 *
105 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
106 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
107 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
108 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
109 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
110 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
111 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
112 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
113 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
114 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
115 * SUCH DAMAGE.
116 *
117 * The licence and distribution terms for any publically available version or
118 * derivative of this code cannot be changed.  i.e. this code cannot simply be
119 * copied and put under another distribution licence
120 * [including the GNU Public Licence.]
121 */
122EOF
123	}
124