Created
November 9, 2013 20:31
-
-
Save alk/7389643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| files = Dir["**/*.h"] + Dir["**/*.cc"] + Dir["**/*.hh"] | |
| lic = {} | |
| files.each do |fn| | |
| # puts "fn: #{fn.inspect}" | |
| lines = IO.readlines(fn) | |
| if lines.empty? | |
| # puts "no lines" | |
| next | |
| end | |
| lines.shift if lines[0] =~ /-\*- mode: */i | |
| cpp_comments = [] | |
| while lines[0] && lines[0] =~ %r|\A//| | |
| l = lines.shift | |
| l.force_encoding(Encoding::ASCII_8BIT) | |
| l = l.sub(%r|Copyright \(c\) [0-9]{4,4}|, "Copyright (c) xxxx") | |
| # l = l.sub(%r|Copyright \(c\) 20[0-9][0-9]|, "Copyright (c) xxxx") | |
| cpp_comments << l | |
| break if l == "// ---\n" | |
| end | |
| unless cpp_comments.empty? | |
| (lic[cpp_comments] ||= []) << fn | |
| next | |
| end | |
| if lines[0] && lines[0] =~ %r|/\*| | |
| c_comments = [] | |
| while true | |
| l = lines.shift | |
| l.force_encoding(Encoding::ASCII_8BIT) | |
| l = l.sub(%r|Copyright \(c\) [0-9]{4}|, "Copyright (c) xxxx") | |
| c_comments << l | |
| break if l =~ /\s*\* -+\n/ | |
| break if l =~ %r|\*/| | |
| end | |
| (lic[c_comments] ||= []) << fn | |
| next | |
| end | |
| (lic[["unknown"]] ||= []) << fn | |
| end | |
| lic.to_a.sort.each do |lic, files| | |
| puts "files: #{files.join(" ")}, license:" | |
| print lic.join("") | |
| puts | |
| puts | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment