[Webkit-unassigned] [Bug 12284] Clean up the header guards

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Jan 15 15:52:10 PST 2007


http://bugs.webkit.org/show_bug.cgi?id=12284





------- Comment #14 from macdome at opendarwin.org  2007-01-15 15:52 PDT -------
I'll explain some of the ruby-isms in this script:

+options = {}
+OptionParser.new do |opts|

I'm not sure why ruby invented yet another OptionParser.  But yeah, it's pretty
cool.  More powerful (and in some ways easier to use) than getoptlong once you
get used to it.

Like so many things in ruby, it uses a block (the do, end block) and passes an
object to that block (in the |args, go, here|).  the .new method calls "yield"
to call that block with arguments.


+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

I'm making an array of regexps there.  Then "freezing" it as a constant.  The
freeze part is not absolutely required, but recommended.

+IgnoreFileNamesPattern = Regexp.union(*IgnoredFilenamePatterns).freeze

*array means "expand this array as though it were passed as arguments"
Regexp.union makes one big compiled regexp out of the array of regexps

+    match_results = contents.match(/#ifndef (\S+)\n#define \1/s)

This is a "MatchData" object, the objectified version of $0, $1, etc. (although
those work in Ruby too)


+      new_guard = options[:prefix] + '_' + new_guard  if options[:prefix]

:foo is a "symbol" in ruby, an atomic string, basically.  string.to_sym and
symbol.to_s can be used to convert back and forth.

+      contents.gsub!(current_guard, new_guard)

All methods with ! at the end of their name modify the caller.  (all methods
with ? return a bool)

+      puts "Ignoring #{filename}, failed to find existing header guards."

#{} is the ruby way of variable substitution in strings.


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list