Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.