Skip to content

Instantly share code, notes, and snippets.

@msr1k
Created June 29, 2015 10:37
Show Gist options
  • Save msr1k/36e3f4bfe47437269ecd to your computer and use it in GitHub Desktop.
Save msr1k/36e3f4bfe47437269ecd to your computer and use it in GitHub Desktop.
Check file format such as Windows(CR+LF), Xnix(LF), Mac(LF+CR) or something.
# coding: cp932
Dir.glob( "**/*" ) do |f|
next if FileTest.directory? f
next if [
/^.git\// , /^RPC\// , /^Tools\// , /^TivaWare\// , /^.*~$/ , /^.*\.xlsx?$/ , /^.*\.docx?$/ , /^.*\.asta$/ ,
/^.*\.mm$/ , /^.*\.md$/ , /^.*\.lib$/ , /^.*\.pp$/ , /^.*\.obj$/ , /^.*\.mk$/ , /^.*\.dat$/ , /^.*\.out$/ ,
/^.*\.opt$/ , /^.*\.so$/ , /^.*\.dll$/ , /^.*\.exe$/ , /^.*\.bin$/ , /^.*\.xml$/ , /^.*\.png$/
].detect{ |re| f =~ re }
File.open( f, 'rb' ) do |g|
g.binmode
r = g.read rescue :unknown
if r =~ /\r\n/
if r =~ /[^\r]\n/
puts "CR+NL & NL: #{f}"
else
puts "CR+NL : #{f}"
end
else
if r =~ /\r/
puts "CR : #{f}"
elsif r =~ /\n\r/
puts "NL+CR : #{f}"
elsif r == :unknown
puts "UN : #{f}"
else
puts "NL : #{f}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment