Created
January 11, 2016 11:49
-
-
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.
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
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