Skip to content

Instantly share code, notes, and snippets.

@movitto
Created January 17, 2017 12:13
Show Gist options
  • Save movitto/6c6d187f7a350c2d71480834892552ab to your computer and use it in GitHub Desktop.
Save movitto/6c6d187f7a350c2d71480834892552ab to your computer and use it in GitHub Desktop.
Unmatched Braces / Preprocessor Finder
#!/usr/bin/ruby
# search for unmatched '{' / '}' pairs and '#ifndef' / '#endif' pairs
# assuming that any given file should have fully matched sets of both
Dir.glob("src/**/*\.[h,cpp]").each { |src|
c = File.read(src)
ob = c.count('{')
cb = c.count('}')
od = c.count('#ifndef')
cd = c.count('#endif')
puts "! #{src}" if ob != cb || od != cd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment