Skip to content

Instantly share code, notes, and snippets.

@zaingz
Created January 11, 2016 11:49
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 zaingz/bdcccfe4584bffd21e7e to your computer and use it in GitHub Desktop.
Save zaingz/bdcccfe4584bffd21e7e to your computer and use it in GitHub Desktop.
This SCRIPT finds all the .h files in a current directory and add include guard macro on the basis of filename.
def update_file(file_name, incl)
file = File.open(file_name, "r")
data = file.read
file.close
unless data.include? "#ifndef"
final_data = "#ifndef #{incl}\n#define #{incl}\n#{data}\n#endif\n/*Include guards add by Zain*/"
file = File.open(file_name, "w+")
file.write(final_data)
file.close
end
end
Dir.glob("**/*.h") do |file_name|
file_name.gsub(/([^\/]*)$/).each do |x|
if x != ""
update_file(file_name, x.gsub(/[.]/,"_").upcase)
else
next
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment