This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / rt / sbin / license_tag
1 #!/usr/bin/perl
2
3
4 # {{{ BEGIN BPS TAGGED BLOCK
5
6 # COPYRIGHT:
7 #  
8 # This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
9 #                                          <jesse@bestpractical.com>
10
11 # (Except where explicitly superseded by other copyright notices)
12
13
14 # LICENSE:
15
16 # This work is made available to you under the terms of Version 2 of
17 # the GNU General Public License. A copy of that license should have
18 # been provided with this software, but in any event can be snarfed
19 # from www.gnu.org.
20
21 # This work is distributed in the hope that it will be useful, but
22 # WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24 # General Public License for more details.
25
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29
30
31 # CONTRIBUTION SUBMISSION POLICY:
32
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
38
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
47
48 # }}} END BPS TAGGED BLOCK
49 my $LICENSE  = <<'EOL';
50
51 COPYRIGHT:
52  
53 This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
54                                          <jesse@bestpractical.com>
55
56 (Except where explicitly superseded by other copyright notices)
57
58
59 LICENSE:
60
61 This work is made available to you under the terms of Version 2 of
62 the GNU General Public License. A copy of that license should have
63 been provided with this software, but in any event can be snarfed
64 from www.gnu.org.
65
66 This work is distributed in the hope that it will be useful, but
67 WITHOUT ANY WARRANTY; without even the implied warranty of
68 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
69 General Public License for more details.
70
71 You should have received a copy of the GNU General Public License
72 along with this program; if not, write to the Free Software
73 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
74
75
76 CONTRIBUTION SUBMISSION POLICY:
77
78 (The following paragraph is not intended to limit the rights granted
79 to you to modify and distribute this software under the terms of
80 the GNU General Public License and is only of importance to you if
81 you choose to contribute your changes and enhancements to the
82 community by submitting them to Best Practical Solutions, LLC.)
83
84 By intentionally submitting any modifications, corrections or
85 derivatives to this work, or any other work intended for use with
86 Request Tracker, to Best Practical Solutions, LLC, you confirm that
87 you are the copyright holder for those contributions and you grant
88 Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
89 royalty-free, perpetual, license to use, copy, create derivative
90 works based on those contributions, and sublicense and distribute
91 those contributions and any derivatives thereof.
92
93 EOL
94
95 use File::Find;
96
97 my @MAKE = qw(Makefile);
98
99 File::Find::find({ no_chdir => 1, wanted => \&tag_pm}, 'lib');
100 File::Find::find({ no_chdir => 1, wanted => \&tag_mason}, 'html');
101 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'sbin');
102 File::Find::find({ no_chdir => 1, wanted => \&tag_script}, 'bin');
103 tag_makefile ('Makefile.in');
104 tag_makefile ('README');
105
106
107 sub tag_mason {
108         my $pm = $_;
109         next unless (-f $pm);
110         next if ($pm =~ /images/);
111         open(FILE,"<$pm") || die "Failed to open $pm";
112         my $file = (join "", <FILE>); 
113         close (FILE);
114         my $pmlic = $LICENSE;
115         $pmlic =~ s/^/%# /mg;
116
117
118         print "$pm - ";
119         if ($file =~ /^%# {{{ BEGIN BPS TAGGED BLOCK/ms) {
120                 print "has license section";
121              $file =~ s/^%# {{{ BEGIN BPS TAGGED BLOCK(.*?)%# }}} END BPS TAGGED BLOCK/%# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic%# }}} END BPS TAGGED BLOCK/ms;
122              
123
124         } else {
125                 print "no license section";
126              $file ="%# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic%# }}} END BPS TAGGED BLOCK\n". $file;
127         }
128         $file =~ s/%# }}} END BPS TAGGED BLOCK(\n+)/%# }}} END BPS TAGGED BLOCK\n/mg;
129         print "\n";
130         
131         
132
133
134         open (FILE, ">$pm") || die "couldn't write new file";
135         print FILE $file;
136         close FILE;
137
138 }
139
140
141 sub tag_makefile {
142         my $pm = shift;
143         open(FILE,"<$pm") || die "Failed to open $pm";
144         my $file = (join "", <FILE>); 
145         close (FILE);
146         my $pmlic = $LICENSE;
147         $pmlic =~ s/^/# /mg;
148
149
150         print "$pm - ";
151         if ($file =~ /^# {{{ BEGIN BPS TAGGED BLOCK/ms) {
152                 print "has license section";
153              $file =~ s/^# {{{ BEGIN BPS TAGGED BLOCK(.*?)# }}} END BPS TAGGED BLOCK/# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK/ms;
154              
155
156         } else {
157                 print "no license section";
158              $file ="# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK\n". $file;
159         }
160         $file =~ s/# }}} END BPS TAGGED BLOCK(\n+)/# }}} END BPS TAGGED BLOCK\n/mg;
161         print "\n";
162         
163         
164
165
166         open (FILE, ">$pm") || die "couldn't write new file";
167         print FILE $file;
168         close FILE;
169
170 }
171
172
173 sub tag_pm {
174         my $pm = $_;
175         next unless $pm =~ /\.pm/s;
176         open(FILE,"<$pm") || die "Failed to open $pm";
177         my $file = (join "", <FILE>); 
178         close (FILE);
179         my $pmlic = $LICENSE;
180         $pmlic =~ s/^/# /mg;
181
182
183         print "$pm - ";
184         if ($file =~ /^# {{{ BEGIN BPS TAGGED BLOCK/ms) {
185                 print "has license section";
186              $file =~ s/^# {{{ BEGIN BPS TAGGED BLOCK(.*?)# }}} END BPS TAGGED BLOCK/# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK/ms;
187              
188
189         } else {
190                 print "no license section";
191              $file ="# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK\n". $file;
192         }
193         $file =~ s/# }}} END BPS TAGGED BLOCK(\n+)/# }}} END BPS TAGGED BLOCK\n/mg;
194         print "\n";
195         
196         
197
198
199         open (FILE, ">$pm") || die "couldn't write new file $pm";
200         print FILE $file;
201         close FILE;
202
203 }
204
205
206 sub tag_script {
207         my $pm = $_;
208         return unless (-f $pm);
209         open(FILE,"<$pm") || die "Failed to open $pm";
210         my $file = (join "", <FILE>); 
211         close (FILE);
212         my $pmlic = $LICENSE;
213         $pmlic =~ s/^/# /msg;
214
215         print "$pm - ";
216         if ($file =~ /^# {{{ BEGIN BPS TAGGED BLOCK/ms) {
217                 print "has license section";
218              $file =~ s/^# {{{ BEGIN BPS TAGGED BLOCK(.*?)# }}} END BPS TAGGED BLOCK/# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK/ms;
219              
220
221         } else {
222                 print "no license section";
223                 if ($file =~ /^(#!.*?)\n/) {
224
225             my  $lic ="# {{{ BEGIN BPS TAGGED BLOCK\n$pmlic# }}} END BPS TAGGED BLOCK\n";
226                 $file =~ s/^(#!.*?)\n/$1\n$lic/; 
227
228                 } 
229         }
230         $file =~ s/# }}} END BPS TAGGED BLOCK(\n+)/# }}} END BPS TAGGED BLOCK\n/mg;
231         print "\n";
232         
233
234         open (FILE, ">$pm") || die "couldn't write new file";
235         print FILE $file;
236         close FILE;
237
238 }
239