OLD | NEW |
---|---|
1 #!/usr/bin/perl -w | 1 #!/usr/bin/perl -w |
2 # This script was originally based on the script of the same name from | 2 # This script was originally based on the script of the same name from |
3 # the KDE SDK (by dfaure@kde.org) | 3 # the KDE SDK (by dfaure@kde.org) |
4 # | 4 # |
5 # This version is | 5 # This version is |
6 # Copyright (C) 2007, 2008 Adam D. Barratt | 6 # Copyright (C) 2007, 2008 Adam D. Barratt |
7 # Copyright (C) 2012 Francesco Poli | 7 # Copyright (C) 2012 Francesco Poli |
8 # | 8 # |
9 # This program is free software; you can redistribute it and/or modify | 9 # This program is free software; you can redistribute it and/or modify |
10 # it under the terms of the GNU General Public License as published by | 10 # it under the terms of the GNU General Public License as published by |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 (?:^|/)(?:DEADJOE|\.cvsignore|\.arch-inventory|\.bzrignore|\.gitignore)$| | 157 (?:^|/)(?:DEADJOE|\.cvsignore|\.arch-inventory|\.bzrignore|\.gitignore)$| |
158 # File or directory names that should be ignored | 158 # File or directory names that should be ignored |
159 (?:^|/)(?:CVS|RCS|\.deps|\{arch\}|\.arch-ids|\.svn|\.hg|_darcs|\.git| | 159 (?:^|/)(?:CVS|RCS|\.deps|\{arch\}|\.arch-ids|\.svn|\.hg|_darcs|\.git| |
160 \.shelf|_MTN|\.bzr(?:\.backup|tags)?)(?:$|/.*$) | 160 \.shelf|_MTN|\.bzr(?:\.backup|tags)?)(?:$|/.*$) |
161 '; | 161 '; |
162 | 162 |
163 # Take out comments and newlines | 163 # Take out comments and newlines |
164 $default_ignore_regex =~ s/^#.*$//mg; | 164 $default_ignore_regex =~ s/^#.*$//mg; |
165 $default_ignore_regex =~ s/\n//sg; | 165 $default_ignore_regex =~ s/\n//sg; |
166 | 166 |
167 my $default_check_regex = '\.(c(c|pp|xx)?|h(h|pp|xx)?|f(77|90)?|p(l|m)|xs|sh|php |py(|x)|rb|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?)$'; | 167 my $default_check_regex = '\.(c(c|pp|xx)?|h(h|pp|xx)?|f(77|90)?|p(l|m)|xs|sh|php |py(|x)|rb|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?|js|html|pac|mm |asm|idl)$'; |
Paweł Hajdan Jr.
2013/01/29 09:29:38
nit: Please move "mm" case near existing "m", chan
| |
168 | 168 |
169 my $modified_conf_msg; | 169 my $modified_conf_msg; |
170 | 170 |
171 my ($opt_verbose, $opt_lines, $opt_noconf, $opt_ignore_regex, $opt_check_regex) | 171 my ($opt_verbose, $opt_lines, $opt_noconf, $opt_ignore_regex, $opt_check_regex) |
172 = ('', '', '', '', ''); | 172 = ('', '', '', '', ''); |
173 my $opt_recursive = 0; | 173 my $opt_recursive = 0; |
174 my $opt_copyright = 0; | 174 my $opt_copyright = 0; |
175 my $opt_machine = 0; | 175 my $opt_machine = 0; |
176 my ($opt_help, $opt_version); | 176 my ($opt_help, $opt_version); |
177 my $def_lines = 60; | 177 my $def_lines = 60; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 push @files, $file unless $file =~ m%$opt_ignore_regex%; | 281 push @files, $file unless $file =~ m%$opt_ignore_regex%; |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 while (@files) { | 285 while (@files) { |
286 my $file = shift @files; | 286 my $file = shift @files; |
287 my $content = ''; | 287 my $content = ''; |
288 my $copyright_match; | 288 my $copyright_match; |
289 my $copyright = ''; | 289 my $copyright = ''; |
290 my $license = ''; | 290 my $license = ''; |
291 my $line; | |
291 my %copyrights; | 292 my %copyrights; |
292 | 293 |
293 open (F, "<$file") or die "Unable to access $file\n"; | 294 open (F, "<$file") or die "Unable to access $file\n"; |
294 while (<F>) { | 295 while (<F>) { |
295 last if ($. > $opt_lines); | 296 unless ($. > $opt_lines) { |
296 $content .= $_; | 297 $content .= $_; |
298 next unless ($opt_copyright); | |
299 } else { | |
300 last unless ($opt_copyright); | |
301 } | |
302 $line = $_; | |
303 # Remove C / C++ strings to avoid false positives. | |
304 if (index($line, '"') != -1) { | |
305 $line =~ s/"[^"\\]*(?:\\.[^"\\]*)*"//g; | |
306 } | |
307 $copyright_match = parse_copyright($line); | |
308 if ($copyright_match) { | |
309 $copyrights{lc("$copyright_match")} = "$copyright_match"; | |
310 } | |
297 } | 311 } |
298 close(F); | 312 close(F); |
299 | 313 |
300 $copyright = join(" / ", values %copyrights); | 314 $copyright = join(" / ", values %copyrights); |
301 | 315 |
302 print qq(----- $file header -----\n$content----- end header -----\n\n) | 316 print qq(----- $file header -----\n$content----- end header -----\n\n) |
303 if $opt_verbose; | 317 if $opt_verbose; |
304 | 318 |
305 # Remove Fortran comments | 319 # Remove Fortran comments |
306 $content =~ s/^[cC] //gm; | 320 $content =~ s/^[cC] //gm; |
(...skipping 12 matching lines...) Expand all Loading... | |
319 print "$file: "; | 333 print "$file: "; |
320 print "*No copyright* " unless $copyright; | 334 print "*No copyright* " unless $copyright; |
321 print $license . "\n"; | 335 print $license . "\n"; |
322 print " [Copyright: " . $copyright . "]\n" | 336 print " [Copyright: " . $copyright . "]\n" |
323 if $copyright and $opt_copyright; | 337 if $copyright and $opt_copyright; |
324 print "\n" if $opt_copyright; | 338 print "\n" if $opt_copyright; |
325 } | 339 } |
326 } | 340 } |
327 | 341 |
328 sub parse_copyright($) { | 342 sub parse_copyright($) { |
343 | |
344 my $line = $_[0]; | |
345 my $uc_line = uc($line); | |
346 # Fast bailout, uses the same patterns as the regexp. | |
347 return '' if (index($uc_line, 'COPYRIGHT') == -1 && | |
348 index($uc_line, 'COPR.') == -1 && | |
349 index($uc_line, '\x{00a9}') == -1 && | |
350 index($uc_line, '\xc2\xa9') == -1 && | |
351 index($uc_line, '(C)') == -1); | |
352 | |
329 my $copyright = ''; | 353 my $copyright = ''; |
330 my $match; | 354 my $match; |
331 | 355 |
332 my $copyright_indicator_regex = ' | 356 my $copyright_indicator_regex = ' |
333 (?:copyright # The full word | 357 (?:copyright # The full word |
334 |copr\. # Legally-valid abbreviation | 358 |copr\. # Legally-valid abbreviation |
335 |\x{00a9} # Unicode character COPYRIGHT SIGN | 359 |\x{00a9} # Unicode character COPYRIGHT SIGN |
336 |\xc2\xa9 # Unicode copyright sign encoded in iso8859 | 360 |\xc2\xa9 # Unicode copyright sign encoded in iso8859 |
337 |\(c\) # Legally-null representation of sign | 361 |\(c\) # Legally-null representation of sign |
338 )'; | 362 )'; |
339 my $copyright_disindicator_regex = ' | 363 my $copyright_disindicator_regex = ' |
340 \b(?:info(?:rmation)? # Discussing copyright information | 364 \b(?:info(?:rmation)? # Discussing copyright information |
341 |notice # Discussing the notice | 365 |notice # Discussing the notice |
342 |and|or # Part of a sentence | 366 |and|or # Part of a sentence |
343 )\b'; | 367 )\b'; |
344 | 368 |
345 if (m%$copyright_indicator_regex(?::\s*|\s+)(\S.*)$%ix) { | 369 if ($line =~ m%\W$copyright_indicator_regex(?::\s*|\s+)(\w.*)$%ix) { |
346 $match = $1; | 370 $match = $1; |
347 | 371 |
348 # Ignore lines matching "see foo for copyright information" etc. | 372 # Ignore lines matching "see foo for copyright information" etc. |
349 if ($match !~ m%^\s*$copyright_disindicator_regex%ix) { | 373 if ($match !~ m%^\s*$copyright_disindicator_regex%ix) { |
350 # De-cruft | 374 # De-cruft |
351 $match =~ s/([,.])?\s*$//; | 375 $match =~ s/([,.])?\s*$//; |
352 $match =~ s/$copyright_indicator_regex//igx; | 376 $match =~ s/$copyright_indicator_regex//igx; |
353 $match =~ s/^\s+//; | 377 $match =~ s/^\s+//; |
354 $match =~ s/\s{2,}/ /g; | 378 $match =~ s/\s{2,}/ /g; |
355 $match =~ s/\\@/@/g; | 379 $match =~ s/\\@/@/g; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 | 421 |
398 This program comes with ABSOLUTELY NO WARRANTY. | 422 This program comes with ABSOLUTELY NO WARRANTY. |
399 You are free to redistribute this code under the terms of the | 423 You are free to redistribute this code under the terms of the |
400 GNU General Public License, version 2, or (at your option) any | 424 GNU General Public License, version 2, or (at your option) any |
401 later version. | 425 later version. |
402 EOF | 426 EOF |
403 } | 427 } |
404 | 428 |
405 sub parselicense($) { | 429 sub parselicense($) { |
406 my ($licensetext) = @_; | 430 my ($licensetext) = @_; |
431 my $upcase_licensetext = uc($licensetext); | |
407 | 432 |
408 my $gplver = ""; | 433 my $gplver = ""; |
409 my $extrainfo = ""; | 434 my $extrainfo = ""; |
410 my $license = ""; | 435 my $license = ""; |
411 | 436 |
412 if ($licensetext =~ /version ([^, ]+?)[.,]? (?:\(?only\)?.? )?(?:of the GNU (Affero )?(Lesser |Library )?General Public License )?(as )?published by the Fre e Software Foundation/i or | 437 if ($licensetext =~ /version ([^, ]+?)[.,]? (?:\(?only\)?.? )?(?:of the GNU (Affero )?(Lesser |Library )?General Public License )?(as )?published by the Fre e Software Foundation/i or |
413 $licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public Lic ense (?:as )?published by the Free Software Foundation; version ([^, ]+?)[.,]? / i) { | 438 $licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public Lic ense (?:as )?published by the Free Software Foundation; version ([^, ]+?)[.,]? / i) { |
414 | 439 |
415 $gplver = " (v$1)"; | 440 $gplver = " (v$1)"; |
416 } elsif ($licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Publi c License, version (\d+(?:\.\d+)?)[ \.]/) { | 441 } elsif ($licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Publi c License, version (\d+(?:\.\d+)?)[ \.]/) { |
417 $gplver = " (v$1)"; | 442 $gplver = " (v$1)"; |
418 } elsif ($licensetext =~ /either version ([^ ]+)(?: of the License)?, or \(a t your option\) any later version/) { | 443 } elsif ($licensetext =~ /either version ([^ ]+)(?: of the License)?, or \(a t your option\) any later version/) { |
419 $gplver = " (v$1 or later)"; | 444 $gplver = " (v$1 or later)"; |
420 } | 445 } |
421 | 446 |
422 if ($licensetext =~ /permission (?:is (also granted|given))? to link (the co de of )?this program with (any edition of )?(Qt|the Qt library)/i) { | 447 if ($licensetext =~ /permission (?:is (also granted|given))? to link (the co de of )?this program with (any edition of )?(Qt|the Qt library)/i) { |
423 $extrainfo = " (with Qt exception)$extrainfo" | 448 $extrainfo = " (with Qt exception)$extrainfo" |
424 } | 449 } |
425 | 450 |
426 if ($licensetext =~ /(All changes made in this file will be lost|DO NOT (EDI T|delete this file)|Generated (automatically|by|from)|generated.*file)/i) { | 451 # The regexp is slow. First, do a quick check using index. |
427 » $license = "GENERATED FILE"; | 452 if (index($upcase_licensetext, 'ALL CHANGES MADE IN THIS FILE WILL BE LOST') != -1 || |
453 index($upcase_licensetext, 'DO NOT EDIT') != -1 || | |
454 index($upcase_licensetext, 'DO NOT DELETE') != -1 || | |
455 index($upcase_licensetext, 'GENERATED') != -1) { | |
456 if ($licensetext =~ /(All changes made in this file will be lost|DO NOT (EDIT|delete this file)|Generated (at|automatically|data|by|from)|Automatically generated|\Wgenerated\s+(?:\w+\s+)*file\W)/i) { | |
457 $license = "GENERATED FILE"; | |
458 } | |
428 } | 459 } |
429 | 460 |
430 if ($licensetext =~ /is (free software.? you can redistribute it and\/or mod ify it|licensed) under the terms of (version [^ ]+ of )?the (GNU (Library |Lesse r )General Public License|LGPL)/i) { | 461 if ($licensetext =~ /is (free software.? you can redistribute it and\/or mod ify it|licensed) under the terms of (version [^ ]+ of )?the (GNU (Library |Lesse r )General Public License|LGPL)/i) { |
431 $license = "LGPL$gplver$extrainfo $license"; | 462 $license = "LGPL$gplver$extrainfo $license"; |
432 } | 463 } |
433 | 464 |
434 if ($licensetext =~ /is free software.? you (can|may) redistribute it and\/o r modify it under the terms of (?:version [^ ]+ (?:\(?only\)? )?of )?the GNU Gen eral Public License/i) { | 465 if ($licensetext =~ /is free software.? you (can|may) redistribute it and\/o r modify it under the terms of (?:version [^ ]+ (?:\(?only\)? )?of )?the GNU Gen eral Public License/i) { |
435 $license = "GPL$gplver$extrainfo $license"; | 466 $license = "GPL$gplver$extrainfo $license"; |
436 } elsif ($licensetext =~ /is distributed under the terms of the GNU General Public License,/ | 467 } elsif ($licensetext =~ /is distributed under the terms of the GNU General Public License,/ |
437 and length $gplver) { | 468 and length $gplver) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 return $license; | 609 return $license; |
579 } | 610 } |
580 | 611 |
581 sub fatal($) { | 612 sub fatal($) { |
582 my ($pack,$file,$line); | 613 my ($pack,$file,$line); |
583 ($pack,$file,$line) = caller(); | 614 ($pack,$file,$line) = caller(); |
584 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d; | 615 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d; |
585 $msg =~ s/\n\n$/\n/; | 616 $msg =~ s/\n\n$/\n/; |
586 die $msg; | 617 die $msg; |
587 } | 618 } |
OLD | NEW |