Created
August 19, 2010 16:36
-
-
Save IanVaughan/538311 to your computer and use it in GitHub Desktop.
remove.rb - removes tons of #ifdef defines in code bases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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