1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/mkconstants.rb: refine family_to_int.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-01-01 08:03:36 +00:00
parent 0c838b4947
commit 7454eab701
2 changed files with 28 additions and 5 deletions

View file

@ -1,3 +1,7 @@
Thu Jan 1 17:01:50 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/mkconstants.rb: refine family_to_int.
Thu Jan 1 16:48:07 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/mkconstants.rb: generate family_to_int().

View file

@ -64,6 +64,17 @@ def each_name(pat)
}
end
def each_names_with_len(pat)
h = {}
DEFS.each {|name, default_value|
next if pat !~ name
(h[name.length] ||= []) << name
}
h.keys.sort.each {|len|
yield h[len], len
}
end
result << ERB.new(<<'EOS', nil, '%').result(binding)
static void
init_constants(VALUE mConst)
@ -89,13 +100,21 @@ init_constants(VALUE mConst)
static int
family_to_int(char *str, int len)
{
% each_name(/\A[AP]F_/) {|name|
switch (len) {
% each_names_with_len(/\A[AP]F_/) {|names, len|
case <%=len%>:
% names.each {|name|
#ifdef <%=name%>
% size = name.bytesize
if (len == <%=size%> && memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
% size = name.bytesize
if (memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
#endif
% }
return -1;
% }
return -1;
% }
default:
return -1;
}
}
EOS