Skip to content

Instantly share code, notes, and snippets.

@IanVaughan
Created August 19, 2010 16:36
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 IanVaughan/538311 to your computer and use it in GitHub Desktop.
Save IanVaughan/538311 to your computer and use it in GitHub Desktop.
remove.rb - removes tons of #ifdef defines in code bases
#!/usr/bin/env ruby
class Remover
attr_accessor :remove_words
attr_accessor :error_files
def initialize(path = "")
@remove_words = ['#ifdef RIDEBUG', '#endif']
@error_files = []
end
def get_files (path)
files = Dir.glob(path)
end
def remove_blocks (file)
text = File.read(file)
index = text.index('#ifdef RIDEBUG') # "#ifdef RIDEBUG")
while index
index_end = text.index("#endif")
if index_end and index_end > index
text[index, index_end-index+7] = ""
else
#puts "Found start at #{index} but no end!"
error_files.push file
break
end
index = text.index('#ifdef RIDEBUG') # "#ifdef RIDEBUG")
end
File.open(file, "w") {|file| file.puts text}
end
def go (path)
puts "Getting file list..."
filenames = get_files(path)
filenames.each do |file|
puts "Current file : #{file}"
remove_blocks(file)
end
puts "error files :-"
error_files.each do |name|
puts name
end
end
end
g = Remover.new
#g.go('*.cpp')
g.go('**/**/*.cpp')
g.go('**/**/*.h')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment