summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-10 11:52:06 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-10 11:52:06 +0000
commit8a1261995ea0b4b68c96ea99cbe3832d8d6f2466 (patch)
tree64e81b5e243aee833bb505d082390bbfac77bddd
parent21495774766472ed7a4c2ac0d80dec76e07df14b (diff)
* ext/socket/mkconstants.rb: refactored to nest properly in statically
and dynamically. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/mkconstants.rb57
2 files changed, 39 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a59a2867f..31ec3b1c2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jan 10 20:50:02 2009 Tanaka Akira <akr@fsij.org>
+
+ * ext/socket/mkconstants.rb: refactored to nest properly in statically
+ and dynamically.
+
Sat Jan 10 20:26:17 2009 Tanaka Akira <akr@fsij.org>
* version.h: make version string succinct:
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 23993f99fa..26a6ef687d 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -66,6 +66,31 @@ def each_name(pat)
}
end
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(define, name, default_value)")
+% if default_value
+#ifndef <%=name%>
+#define <%=name%> <%=default_value%>
+#endif
+ <%=define%>(<%=c_str name%>, <%=name%>);
+% else
+#if defined(<%=name%>)
+ <%=define%>(<%=c_str name%>, <%=name%>);
+#endif
+% end
+EOS
+
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs")
+% each_const {|guard, define, name, default_value|
+% if guard
+#if <%=guard%>
+<%= gen_const_defs_in_guard(define, name, default_value) %>
+#endif
+% else
+<%= gen_const_defs_in_guard(define, name, default_value) %>
+% end
+% }
+EOS
+
def reverse_each_name(pat)
DEFS.reverse_each {|name, default_value|
next if pat !~ name
@@ -104,10 +129,7 @@ def each_names_with_len(pat, prefix_optional=nil)
}
end
-ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func(funcname, pat, prefix_optional, guard=nil)")
-%if guard
-#ifdef <%=guard%>
-%end
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)")
static int
<%=funcname%>(char *str, int len, int *valp)
{
@@ -126,8 +148,15 @@ static int
return -1;
}
}
+EOS
+
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func(funcname, pat, prefix_optional, guard=nil)")
%if guard
+#ifdef <%=guard%>
+<%=gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard)%>
#endif
+%else
+<%=gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard)%>
%end
EOS
@@ -193,25 +222,7 @@ result << ERB.new(<<'EOS', nil, '%').result(binding)
static void
init_constants(VALUE mConst)
{
-% each_const {|guard, define, name, default_value|
-% if guard
-#if <%=guard%>
-% end
-% if default_value
-#ifndef <%=name%>
-#define <%=name%> <%=default_value%>
-#endif
-% else
-#if defined(<%=name%>)
-% end
- <%=define%>(<%=c_str name%>, <%=name%>);
-% unless default_value
-#endif
-% end
-% if guard
-#endif
-% end
-% }
+<%= gen_const_defs %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| gen_hash }.join("\n") %>
}