Created
August 13, 2013 08:53
-
-
Save rasefon/6219200 to your computer and use it in GitHub Desktop.
This file contains 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
$dist_dir = ARGV[0] | |
$total_line_count = 0 | |
$blank_line_count = 0 | |
$code_line_count = 0 | |
$src_exts = [".h", ".c", ".rb"] | |
$exclude_dirs = [".", ".."] | |
def traverse(entry) | |
entries = Dir.entries(entry) | |
$exclude_dirs.each { |ed| entries.delete(ed) } | |
Dir.chdir(entry) do | |
entries.each do |e| | |
unless File.directory?(e) | |
if $src_exts.include?(File.extname(e)) | |
File.open(e, 'r', :external_encoding => Encoding::UTF_8) do |f| | |
begin | |
lines = f.readlines | |
lines.each do |line| | |
if /^\s*$/ =~ line | |
$blank_line_count += 1 | |
else | |
$code_line_count += 1 | |
end | |
end | |
$total_line_count += lines.size | |
rescue | |
puts "#{Dir.pwd}/#{e}" | |
end | |
end | |
end | |
else | |
traverse(e) | |
end | |
end | |
end | |
end | |
traverse($dist_dir) if Dir.exists?($dist_dir) | |
puts "total lines: #{$total_line_count}" | |
puts "blank lines: #{$blank_line_count}" | |
puts "code lines: #{$code_line_count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment