summaryrefslogtreecommitdiff
path: root/ext/socket/mkconstants.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 08:38:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 08:38:14 +0000
commit9787d4faaeff4fff798fff6803758f467cb72e7e (patch)
tree745475bca7b2cc50145b76fcc418031567a010d8 /ext/socket/mkconstants.rb
parent009ad25fdd60c3d3067f881dbce706735bb5b6fd (diff)
* ext/socket/mkconstants.rb: generate socktype_to_int.
* ext/socket/socket.c (setup_domain_and_type): use socktype_to_int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/mkconstants.rb')
-rw-r--r--ext/socket/mkconstants.rb38
1 files changed, 24 insertions, 14 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index e11c9c3..6c6be0f 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -75,6 +75,24 @@ def each_names_with_len(pat)
}
end
+ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int(str_var, len_var, pat)")
+ switch (<%=len_var%>) {
+% each_names_with_len(pat) {|names, len|
+ case <%=len%>:
+% names.each {|name|
+#ifdef <%=name%>
+% size = name.bytesize
+ if (memcmp(<%=str_var%>, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
+#endif
+% }
+ return -1;
+
+% }
+ default:
+ return -1;
+ }
+EOS
+
result << ERB.new(<<'EOS', nil, '%').result(binding)
static void
init_constants(VALUE mConst)
@@ -100,21 +118,13 @@ init_constants(VALUE mConst)
static int
family_to_int(char *str, int len)
{
- switch (len) {
-% each_names_with_len(/\A[AP]F_/) {|names, len|
- case <%=len%>:
-% names.each {|name|
-#ifdef <%=name%>
-% size = name.bytesize
- if (memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
-#endif
-% }
- return -1;
+<%= gen_name_to_int("str", "len", /\A[AP]F_/) %>
+}
-% }
- default:
- return -1;
- }
+static int
+socktype_to_int(char *str, int len)
+{
+<%= gen_name_to_int("str", "len", /\ASOCK_/) %>
}
EOS