Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Created August 18, 2014 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixpulvis/f8e8b64df64ae1514437 to your computer and use it in GitHub Desktop.
Save nixpulvis/f8e8b64df64ae1514437 to your computer and use it in GitHub Desktop.
Simple unused #define finder.
#!/usr/bin/env ruby
require 'pp'
if ARGV[0]
# Collect defines.
defines = {}
Dir.glob("#{ARGV[0]}/**/*.{c,h}") do |path|
File.open(path, "r") do |file|
file.each_line do |line|
if line =~ /^#define\s*(\S*)\s*.*$/
defines[$1] = false
end
end
end
end
# Find uses.
Dir.glob("#{ARGV[0]}/**/*.{c,h}") do |path|
File.open(path, "r") do |file|
file.each_line do |line|
unless line =~ /#define/
defines.each do |k,v|
defines[k] = v || line.include?(k)
end
end
end
end
end
# Print unused.
defines.select { |k,v| v == false }.each do |k,v|
puts k
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment