summaryrefslogtreecommitdiff
path: root/ext/socket/mkconstants.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/mkconstants.rb')
-rw-r--r--ext/socket/mkconstants.rb30
1 files changed, 29 insertions, 1 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 589e3b2bb3..948eda8be1 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -1,4 +1,24 @@
-$out ||= $stdout
+require 'optparse'
+
+opt = OptionParser.new
+
+opt.def_option('-h', 'help') {
+ puts opt
+ exit 0
+}
+
+opt_o = nil
+opt.def_option('-o FILE', 'specify output file') {|filename|
+ opt_o = filename
+}
+
+$out = ''
+def $out.puts(str="")
+ str += "\n" if /\n\z/ !~ str
+ self << str
+end
+
+opt.parse!
# workaround for NetBSD, OpenBSD and etc.
$out.puts("#define pseudo_AF_FTIP pseudo_AF_RTIP")
@@ -23,6 +43,14 @@ DATA.each_line do |s|
end
end
+if opt_o
+ File.open(opt_o, 'w') {|f|
+ f << $out
+ }
+else
+ $stdout << $out
+end
+
__END__
SOCK_STREAM