diff options
| author | Ben Murdoch <benm@google.com> | 2011-05-05 14:36:32 +0100 | 
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2011-05-10 15:38:30 +0100 | 
| commit | f05b935882198ccf7d81675736e3aeb089c5113a (patch) | |
| tree | 4ea0ca838d9ef1b15cf17ddb3928efb427c7e5a1 /Tools/Scripts/clean-header-guards | |
| parent | 60fbdcc62bced8db2cb1fd233cc4d1e4ea17db1b (diff) | |
| download | external_webkit-f05b935882198ccf7d81675736e3aeb089c5113a.zip external_webkit-f05b935882198ccf7d81675736e3aeb089c5113a.tar.gz external_webkit-f05b935882198ccf7d81675736e3aeb089c5113a.tar.bz2  | |
Merge WebKit at r74534: Initial merge by git.
Change-Id: I6ccd1154fa1b19c2ec2a66878eb675738735f1eb
Diffstat (limited to 'Tools/Scripts/clean-header-guards')
| -rwxr-xr-x | Tools/Scripts/clean-header-guards | 53 | 
1 files changed, 53 insertions, 0 deletions
diff --git a/Tools/Scripts/clean-header-guards b/Tools/Scripts/clean-header-guards new file mode 100755 index 0000000..2bad046 --- /dev/null +++ b/Tools/Scripts/clean-header-guards @@ -0,0 +1,53 @@ +#!/usr/bin/ruby + +require 'find' +require 'optparse' + +options = {} +OptionParser.new do |opts| +  opts.banner = "Usage: clean-header-guards [options]" +   +  opts.on("--prefix [PREFIX]", "Append a header prefix to all guards") do |prefix| +    options[:prefix] = prefix +  end +end.parse! + +IgnoredFilenamePatterns = [ +  # ignore headers which are known not to have guard +  /WebCorePrefix/,  +  /ForwardingHeaders/, +  %r|bindings/objc|,  +  /vcproj/, # anything inside a vcproj is in the windows wasteland +   +  # we don't own any of these headers +  %r|icu/unicode|, +  %r|platform/graphics/cairo|, +  %r|platform/image-decoders|, +   +  /config.h/ # changing this one sounds scary +].freeze + +IgnoreFileNamesPattern = Regexp.union(*IgnoredFilenamePatterns).freeze + +Find::find(".") do |filename| +  next unless filename =~ /\.h$/ +  next if filename.match(IgnoreFileNamesPattern) +   +  File.open(filename, "r+") do |file| +    contents = file.read +    match_results = contents.match(/#ifndef (\S+)\n#define \1/s) +    if match_results +      current_guard = match_results[1] +      new_guard = File.basename(filename).sub('.', '_') +      new_guard = options[:prefix] + '_' + new_guard  if options[:prefix] +      contents.gsub!(/#{current_guard}\b/, new_guard) +    else +      puts "Ignoring #{filename}, failed to find existing header guards." +    end +    tmp_filename = filename + ".tmp" +    File.open(tmp_filename, "w+") do |new_file| +      new_file.write(contents) +    end +    File.rename tmp_filename, filename +  end +end  | 
