mirror of
https://review.haiku-os.org/haiku
synced 2025-01-18 20:48:48 +01:00
39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
|
#!/bin/env ruby
|
||
|
#
|
||
|
# Source Code License Guesser.
|
||
|
# Copyright, 2017 Alexander von Gluck IV. All Rights Reserved
|
||
|
# Released under the terms of the MIT license.
|
||
|
#
|
||
|
# Give a file, and I guess the license.
|
||
|
#
|
||
|
# Example Usage:
|
||
|
#
|
||
|
# haiku $ find src -name "*.cpp" -exec ./3rdparty/kallisti5/licenseReport.rb {} \;
|
||
|
#
|
||
|
|
||
|
@file = ARGV.first
|
||
|
@licenses = [
|
||
|
{"MIT" => ["MIT License", "MIT Licence", "Haiku License", "X11 license"]},
|
||
|
{"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\""]},
|
||
|
{"BeOS Sample Code" => ["be sample code license"]},
|
||
|
{"GPL" => ["terms of the GNU General Public License", "GNU L-GPL license", "GPL license"]},
|
||
|
]
|
||
|
|
||
|
def check_license(filename)
|
||
|
license = "unknown"
|
||
|
lines = File.foreach(filename).first(30).join("\n")
|
||
|
return "empty file" if lines == nil
|
||
|
@licenses.each do |entry|
|
||
|
entry.values.first.each do |pattern|
|
||
|
if lines.downcase.include?(pattern.downcase)
|
||
|
license = entry.keys.first
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
break if license != "unknown"
|
||
|
end
|
||
|
license
|
||
|
end
|
||
|
|
||
|
puts "#{@file}: #{check_license(@file)}"
|