summaryrefslogtreecommitdiff
path: root/ext/etc/mkconstants.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/etc/mkconstants.rb')
-rw-r--r--ext/etc/mkconstants.rb32
1 files changed, 22 insertions, 10 deletions
diff --git a/ext/etc/mkconstants.rb b/ext/etc/mkconstants.rb
index a752d64519..a766560a8a 100644
--- a/ext/etc/mkconstants.rb
+++ b/ext/etc/mkconstants.rb
@@ -35,6 +35,12 @@ opt.def_option('-H FILE', 'specify output header file') {|filename|
opt.parse!
+CONST_PREFIXES = {
+ 'SC' => 'for Etc.sysconf; See <tt>man sysconf</tt>',
+ 'CS' => 'for Etc.confstr; See <tt>man constr</tt>',
+ 'PC' => 'for IO#pathconf; See <tt>man fpathconf</tt>',
+}
+
h = {}
COMMENTS = {}
@@ -49,6 +55,13 @@ DATA.each_line {|s|
next
end
h[name] = default_value
+ if additional = CONST_PREFIXES[name[/\A_([A-Z]+)_/, 1]]
+ if comment&.match(/\w\z/)
+ comment << " " << additional
+ else
+ (comment ||= String.new) << " " << additional.sub(/\A\w/) {$&.upcase}
+ end
+ end
COMMENTS[name] = comment if comment
}
DEFS = h.to_a
@@ -66,15 +79,11 @@ def each_name(pat)
}
end
-erb_new = lambda do |src, safe, trim|
- if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
- ERB.new(src, trim_mode: trim)
- else
- ERB.new(src, safe, trim)
- end
+erb_new = lambda do |src, trim|
+ ERB.new(src, trim_mode: trim)
end
-erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_decls")
+erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_decls")
% each_const {|name, default_value|
#if !defined(<%=name%>)
# if defined(HAVE_CONST_<%=name.upcase%>)
@@ -88,7 +97,7 @@ erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_decls")
% }
EOS
-erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs")
+erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_defs")
% each_const {|name, default_value|
#if defined(<%=name%>)
% if comment = COMMENTS[name]
@@ -99,13 +108,13 @@ erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs")
% }
EOS
-header_result = erb_new.call(<<'EOS', nil, '%').result(binding)
+header_result = erb_new.call(<<'EOS', '%').result(binding)
/* autogenerated file */
<%= gen_const_decls %>
EOS
-result = erb_new.call(<<'EOS', nil, '%').result(binding)
+result = erb_new.call(<<'EOS', '%').result(binding)
/* autogenerated file */
#ifdef HAVE_LONG_LONG
@@ -123,6 +132,9 @@ result = erb_new.call(<<'EOS', nil, '%').result(binding)
static void
init_constants(VALUE mod)
{
+#if 0
+ mod = rb_define_module("Etc");
+#endif
<%= gen_const_defs %>
}
EOS