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 # | 7 # |
8 # This program is free software; you can redistribute it and/or modify | 8 # This program is free software; you can redistribute it and/or modify |
9 # it under the terms of the GNU General Public License as published by | 9 # it under the terms of the GNU General Public License as published by |
10 # the Free Software Foundation; either version 2 of the License, or | 10 # the Free Software Foundation; either version 2 of the License, or |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 my $content = ''; | 270 my $content = ''; |
271 my $copyright_match; | 271 my $copyright_match; |
272 my $copyright = ''; | 272 my $copyright = ''; |
273 my $license = ''; | 273 my $license = ''; |
274 my %copyrights; | 274 my %copyrights; |
275 | 275 |
276 open (F, "<$file") or die "Unable to access $file\n"; | 276 open (F, "<$file") or die "Unable to access $file\n"; |
277 while (<F>) { | 277 while (<F>) { |
278 last if ($. > $opt_lines); | 278 last if ($. > $opt_lines); |
279 $content .= $_; | 279 $content .= $_; |
280 $copyright_match = parse_copyright($_); | |
281 if ($copyright_match) { | |
282 $copyrights{lc("$copyright_match")} = "$copyright_match"; | |
283 } | |
284 } | 280 } |
285 close(F); | 281 close(F); |
286 | 282 |
287 $copyright = join(" / ", values %copyrights); | 283 $copyright = join(" / ", values %copyrights); |
288 | 284 |
289 print qq(----- $file header -----\n$content----- end header -----\n\n) | 285 print qq(----- $file header -----\n$content----- end header -----\n\n) |
290 if $opt_verbose; | 286 if $opt_verbose; |
291 | 287 |
292 $content =~ tr/\t\r\n/ /; | 288 $content =~ tr/\t\r\n/ /; |
293 # Remove C / C++ comments | 289 # Remove C / C++ comments |
294 $content =~ s#(\*/|/[/*])##g; | 290 $content =~ s#(\*/|/[/*])##g; |
295 $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd; | 291 $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd; |
296 $content =~ s/ c //g; # Remove fortran comments | 292 $content =~ s/ c //g; # Remove fortran comments |
297 $content =~ tr/ //s; | 293 $content =~ tr/ //s; |
298 | 294 |
299 $license = parselicense($content); | 295 $license = parselicense($content); |
300 print "$file: "; | 296 print "$file: "; |
301 print "*No copyright* " unless $copyright; | |
302 print $license . "\n"; | 297 print $license . "\n"; |
303 print " [Copyright: " . $copyright . "]\n" | 298 print " [Copyright: " . $copyright . "]\n" |
304 if $copyright and $opt_copyright; | 299 if $copyright and $opt_copyright; |
305 print "\n" if $opt_copyright; | 300 print "\n" if $opt_copyright; |
306 } | 301 } |
307 | 302 |
308 sub parse_copyright($) { | 303 sub parse_copyright($) { |
309 my $copyright = ''; | 304 my $copyright = ''; |
310 my $match; | 305 my $match; |
311 | 306 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if ($licensetext =~ /version ([^ ]+) (?:\(?only\)?.? )?(?:of the GNU (Affero
)?General Public License )?as published by the Free Software Foundation/i or | 386 if ($licensetext =~ /version ([^ ]+) (?:\(?only\)?.? )?(?:of the GNU (Affero
)?General Public License )?as published by the Free Software Foundation/i or |
392 $licensetext =~ /GNU (?:Affero )?General Public License as published by
the Free Software Foundation; version ([^ ]+) /i) { | 387 $licensetext =~ /GNU (?:Affero )?General Public License as published by
the Free Software Foundation; version ([^ ]+) /i) { |
393 | 388 |
394 $gplver = " (v$1)"; | 389 $gplver = " (v$1)"; |
395 } elsif ($licensetext =~ /GNU (Affero ?)General Public License, version ([^
]+?)[ .]/) { | 390 } elsif ($licensetext =~ /GNU (Affero ?)General Public License, version ([^
]+?)[ .]/) { |
396 $gplver = " (v$1)"; | 391 $gplver = " (v$1)"; |
397 } elsif ($licensetext =~ /either version ([^ ]+) of the License, or \(at you
r option\) any later version/) { | 392 } elsif ($licensetext =~ /either version ([^ ]+) of the License, or \(at you
r option\) any later version/) { |
398 $gplver = " (v$1 or later)"; | 393 $gplver = " (v$1 or later)"; |
399 } | 394 } |
400 | 395 |
401 if ($licensetext =~ /(?:675 Mass Ave|59 Temple Place|51 Franklin Steet|02139
|02111-1307)/i) { | |
402 $extrainfo = " (with incorrect FSF address)$extrainfo"; | |
403 } | |
404 | |
405 if ($licensetext =~ /permission (?:is (also granted|given))? to link (the co
de of )?this program with (any edition of )?(Qt|the Qt library)/i) { | 396 if ($licensetext =~ /permission (?:is (also granted|given))? to link (the co
de of )?this program with (any edition of )?(Qt|the Qt library)/i) { |
406 $extrainfo = " (with Qt exception)$extrainfo" | 397 $extrainfo = " (with Qt exception)$extrainfo" |
407 } | 398 } |
408 | 399 |
409 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) { | 400 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) { |
410 $license = "GENERATED FILE"; | 401 $license = "GENERATED FILE"; |
411 } | 402 } |
412 | 403 |
413 if ($licensetext =~ /is free software.? you can redistribute it and\/or modi
fy it under the terms of the (GNU (Library|Lesser) General Public License|LGPL)/
i) { | 404 if ($licensetext =~ /is free software.? you can redistribute it and\/or modi
fy it under the terms of the (GNU (Library|Lesser) General Public License|LGPL)/
i) { |
414 $license = "LGPL$gplver$extrainfo $license"; | 405 $license = "LGPL$gplver$extrainfo $license"; |
415 } | 406 } |
416 | 407 |
417 if ($licensetext =~ /is free software.? you can redistribute it and\/or modi
fy it under the terms of the (GNU Affero General Public License|AGPL)/i) { | |
418 $license = "AGPL$gplver$extrainfo $license"; | |
419 } | |
420 | |
421 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) { | 408 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) { |
422 $license = "GPL$gplver$extrainfo $license"; | 409 $license = "GPL$gplver$extrainfo $license"; |
423 } | 410 } elsif ($licensetext =~ /is distributed under the terms of the GNU General
Public License,/ |
424 | |
425 if ($licensetext =~ /is distributed under the terms of the GNU General Publi
c License,/ | |
426 and length $gplver) { | 411 and length $gplver) { |
427 $license = "GPL$gplver$extrainfo $license"; | 412 $license = "GPL$gplver$extrainfo $license"; |
428 } | 413 } elsif ($licensetext =~ /is distributed.*terms.*GPL/) { |
429 | |
430 if ($licensetext =~ /is distributed.*terms.*GPL/) { | |
431 $license = "GPL (unversioned/unknown version) $license"; | 414 $license = "GPL (unversioned/unknown version) $license"; |
432 } | 415 } |
433 | 416 |
434 if ($licensetext =~ /This file is part of the .*Qt GUI Toolkit. This file ma
y be distributed under the terms of the Q Public License as defined/) { | 417 if ($licensetext =~ /This file is part of the .*Qt GUI Toolkit. This file ma
y be distributed under the terms of the Q Public License as defined/) { |
435 $license = "QPL (part of Qt) $license"; | 418 $license = "QPL (part of Qt) $license"; |
436 } elsif ($licensetext =~ /may be distributed under the terms of the Q Public
License as defined/) { | 419 } elsif ($licensetext =~ /may be distributed under the terms of the Q Public
License as defined/) { |
437 $license = "QPL $license"; | 420 $license = "QPL $license"; |
438 } | 421 } |
439 | 422 |
440 if ($licensetext =~ /opensource\.org\/licenses\/mit-license\.php/) { | 423 if ($licensetext =~ /opensource\.org\/licenses\/mit-license\.php/) { |
441 $license = "MIT/X11 (BSD like) $license"; | 424 $license = "MIT/X11 (BSD like) $license"; |
442 } elsif ($licensetext =~ /Permission is hereby granted, free of charge, to a
ny person obtaining a copy of this software and associated documentation files \
(the Software\), to deal in the Software/) { | 425 } elsif ($licensetext =~ /Permission is hereby granted, free of charge, to a
ny person obtaining a copy of this software and associated documentation files \
(the Software\), to deal in the Software/) { |
443 $license = "MIT/X11 (BSD like) $license"; | 426 $license = "MIT/X11 (BSD like) $license"; |
444 } | 427 } |
445 | 428 |
446 if ($licensetext =~ /Permission to use, copy, modify, and(\/or)? distribute
this software for any purpose with or without fee is hereby granted, provided.*
copyright notice.*permission notice.*all copies/) { | 429 if ($licensetext =~ /Permission to use, copy, modify, and(\/or)? distribute
this software for any purpose with or without fee is hereby granted, provided.*
copyright notice.*permission notice.*all copies/) { |
447 $license = "ISC $license"; | 430 $license = "ISC $license"; |
448 } | 431 } |
449 | 432 |
450 if ($licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR IM
PLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCH
ANTABILITY/) { | 433 if ($licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR IM
PLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCH
ANTABILITY/) { |
451 » if ($licensetext =~ /All advertising materials mentioning features or us
e of this software must display the following acknowledge?ment.*This product inc
ludes software developed by/i) { | 434 » if ($licensetext =~ /All advertising materials mentioning features or us
e of this software must display the following/) { |
452 $license = "BSD (4 clause) $license"; | 435 $license = "BSD (4 clause) $license"; |
453 » } elsif ($licensetext =~ /(The name of .*? may not|Neither the names? of
.*? nor the names of (its|their) contributors may) be used to endorse or promot
e products derived from this software/i) { | 436 » } elsif ($licensetext =~ /be used to endorse or promote products derived
from this software/) { |
454 $license = "BSD (3 clause) $license"; | 437 $license = "BSD (3 clause) $license"; |
455 » } elsif ($licensetext =~ /Redistributions of source code must retain the
above copyright notice/i) { | 438 » } elsif ($licensetext =~ /Redistributions of source code must retain the
above copyright notice/) { |
456 $license = "BSD (2 clause) $license"; | 439 $license = "BSD (2 clause) $license"; |
457 } else { | 440 } else { |
458 $license = "BSD $license"; | 441 $license = "BSD $license"; |
459 } | 442 } |
460 } | 443 } elsif ($licensetext =~ /Use of this source code is governed by a BSD-style
license/) { |
461 | |
462 if ($licensetext =~ /Use of this source code is governed by a BSD-style lice
nse/) { | |
463 $license = "BSD-like $license"; | 444 $license = "BSD-like $license"; |
464 } elsif ($licensetext =~ /BSD terms apply.*see.*COPYING.*for details/) { | 445 } elsif ($licensetext =~ /BSD terms apply/) { |
465 $license = "BSD-like $license"; | 446 $license = "BSD-like $license"; |
466 } | 447 } |
467 | 448 |
468 if ($licensetext =~ /Mozilla Public License Version ([^ ]+)/) { | 449 if ($licensetext =~ /Mozilla Public License Version ([^ ]+)/) { |
469 $license = "MPL (v$1) $license"; | 450 $license = "MPL (v$1) $license"; |
470 } | 451 } |
471 | 452 |
472 if ($licensetext =~ /Released under the terms of the Artistic License ([^ ]+
)/) { | 453 if ($licensetext =~ /Released under the terms of the Artistic License ([^ ]+
)/) { |
473 $license = "Artistic (v$1) $license"; | 454 $license = "Artistic (v$1) $license"; |
474 } | 455 } |
(...skipping 19 matching lines...) Expand all Loading... |
494 } | 475 } |
495 | 476 |
496 if ($licensetext =~ /under the terms of the CeCILL-([^ ]+) /) { | 477 if ($licensetext =~ /under the terms of the CeCILL-([^ ]+) /) { |
497 $license = "CeCILL-$1 $license"; | 478 $license = "CeCILL-$1 $license"; |
498 } | 479 } |
499 | 480 |
500 if ($licensetext =~ /under the SGI Free Software License B/) { | 481 if ($licensetext =~ /under the SGI Free Software License B/) { |
501 $license = "SGI Free Software License B $license"; | 482 $license = "SGI Free Software License B $license"; |
502 } | 483 } |
503 | 484 |
504 if ($licensetext =~ /is.*in the public domain|disclaims copyright/i) { | 485 if ($licensetext =~ /in the public domain/i) { |
505 $license = "Public domain"; | 486 $license = "Public domain"; |
506 } | 487 } |
507 | 488 |
508 if ($licensetext =~ /terms of the Common Development and Distribution Licens
e(, Version ([^(]+))? \(the License\)/) { | 489 if ($licensetext =~ /terms of the Common Development and Distribution Licens
e(, Version ([^(]+))? \(the License\)/) { |
509 $license = "CDDL " . ($1 ? "(v$2) " : '') . $license; | 490 $license = "CDDL " . ($1 ? "(v$2) " : '') . $license; |
510 } | 491 } |
511 | 492 |
512 if ($licensetext =~ /Microsoft Permissive License \(Ms-PL\)/) { | 493 if ($licensetext =~ /Microsoft Permissive License \(Ms-PL\)/) { |
513 $license = "Ms-PL $license"; | 494 $license = "Ms-PL $license"; |
514 } | 495 } |
515 | 496 |
516 if ($licensetext =~ /Permission is hereby granted, free of charge, to any pe
rson or organization obtaining a copy of the software and accompanying documenta
tion covered by this license \(the \"Software\"\)/ or | 497 if ($licensetext =~ /Permission is hereby granted, free of charge, to any pe
rson or organization obtaining a copy of the software and accompanying documenta
tion covered by this license \(the \"Software\"\)/ or |
517 $licensetext =~ /Boost Software License([ ,-]+Version ([^ ]+)?(\.))/i) { | 498 $licensetext =~ /Boost Software License([ ,-]+Version ([^ ]+)?(\.))/i) { |
518 $license = "BSL " . ($1 ? "(v$2) " : '') . $license; | 499 $license = "BSL " . ($1 ? "(v$2) " : '') . $license; |
519 } | 500 } |
520 | 501 |
521 if ($licensetext =~ /PYTHON SOFTWARE FOUNDATION LICENSE (VERSION ([^ ]+))/i)
{ | 502 if ($licensetext =~ /PYTHON SOFTWARE FOUNDATION LICENSE (VERSION ([^ ]+))/i)
{ |
522 $license = "PSF " . ($1 ? "(v$2) " : '') . $license; | 503 $license = "PSF " . ($1 ? "(v$2) " : '') . $license; |
523 } | 504 } |
524 | 505 |
525 if ($licensetext =~ /The origin of this software must not be misrepresented.
*Altered source versions must be plainly marked as such.*This notice may not be
removed or altered from any source distribution/ or | 506 if ($licensetext =~ /The origin of this software must not be misrepresented.
*Altered source versions must be plainly marked as such.*This notice may not be
removed or altered from any source distribution/ or |
526 $licensetext =~ /see copyright notice in zlib\.h/) { | 507 $licensetext =~ /see copyright notice in zlib\.h/) { |
527 $license = "zlib/libpng $license"; | 508 $license = "zlib/libpng $license"; |
528 } elsif ($licensetext =~ /This code is released under the libpng license/) { | 509 } elsif ($licensetext =~ /This code is released under the libpng license/) { |
529 $license = "libpng $license"; | 510 $license = "libpng $license"; |
530 } | 511 } |
531 | 512 |
532 if ($licensetext =~ /Do What The Fuck You Want To Public License, Version ([
^, ]+)/i) { | |
533 $license = "WTFPL (v$1)"; | |
534 } | |
535 | |
536 if ($licensetext =~ /Do what The Fuck You Want To Public License/i) { | |
537 $license = "WTFPL"; | |
538 } | |
539 | |
540 if ($licensetext =~ /(License WTFPL|Under (the|a) WTFPL)/i) { | |
541 $license = "WTFPL"; | |
542 } | |
543 | |
544 $license = "UNKNOWN" if (!length($license)); | 513 $license = "UNKNOWN" if (!length($license)); |
545 | 514 |
546 return $license; | 515 return $license; |
547 } | 516 } |
548 | 517 |
549 sub fatal($) { | 518 sub fatal($) { |
550 my ($pack,$file,$line); | 519 my ($pack,$file,$line); |
551 ($pack,$file,$line) = caller(); | 520 ($pack,$file,$line) = caller(); |
552 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d; | 521 (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d; |
553 $msg =~ s/\n\n$/\n/; | 522 $msg =~ s/\n\n$/\n/; |
554 die $msg; | 523 die $msg; |
555 } | 524 } |
OLD | NEW |