repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / 3rdparty / kallisti5 / licenseReport.rb
blob0d6d5548886bcc7bf4f53f2eed010010f72a17f4
1 #!/bin/env ruby
3 # Source Code License Guesser.
4 # Copyright, 2017 Alexander von Gluck IV. All Rights Reserved
5 # Released under the terms of the MIT license.
7 # Give a file, and I guess the license.
9 # Example Usage:
10 #       
11 #       haiku $ find src -name "*.cpp" -exec ./3rdparty/kallisti5/licenseReport.rb {} \;
14 @file = ARGV.first
15 @licenses = [
16         {"MIT" => ["MIT License", "MIT Licence", "Haiku License", "X11 license"]},
17         {"BSD" => ["express or implied warranties", "provided by the author ``AS IS''", "the software is provided \"AS IS\"", "BSD license", "provided by the author \"as is\""]},
18         {"BeOS Sample Code" => ["be sample code license"]},
19         {"GPL" => ["terms of the GNU General Public License", "GNU L-GPL license", "GPL license", "Free Software Foundation"]},
22 def check_license(filename)
23         license = "unknown"
24         lines = File.foreach(filename).first(30).join("\n")
25         return "empty file" if lines == nil
26         @licenses.each do |entry|
27                 entry.values.first.each do |pattern|
28                         if lines.downcase.include?(pattern.downcase)
29                                 license = entry.keys.first
30                                 break
31                         end
32                 end
33                 break if license != "unknown"
34         end
35         license
36 end
38 puts "#{@file}: #{check_license(@file)}"