5 # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
6 # by Yasuo OHBA(SHL Japan Inc. Technology Dept.)
9 # this is obsolete; use getoptlong
12 # modified by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
15 # rewritten by Akinori MUSHA <knu@ruby-lang.org>
18 warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0] and $VERBOSE
22 # getopts is obsolete. Use GetoptLong.
24 def getopts(single_options, *options)
31 single_options.scan(/.:?/) do |opt|
35 valopts[opt[0, 1]] = nil
40 opt, val = arg.split(':', 2)
43 valopts[opt] = val.empty? ? nil : val
55 while arg = argv.shift
58 if $1.empty? # xinit -- -bpp 24
62 opt, val = $1.split('=', 2)
67 elsif valopts.key? opt # imclean --src +trash
68 valopts[opt] = val || argv.shift or return nil
69 elsif boolopts.key? opt # ruby --verbose
81 opt = opts.slice!(0, 1)
86 if val.empty? # ruby -e 'p $:'
87 valopts[opt] = argv.shift or return nil
94 elsif boolopts.key? opt
95 boolopts[opt] = true # ruby -h
113 boolopts.each do |opt, val|
116 sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
117 eval "$OPT_#{sopt} = val"
119 valopts.each do |opt, val|
122 sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
123 eval "$OPT_#{sopt} = val"