# $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
# by Yasuo OHBA(SHL Japan Inc. Technology Dept.)
# this is obsolete; use getoptlong
# modified by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
# rewritten by Akinori MUSHA <knu@ruby-lang.org>
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0] and $VERBOSE
# getopts is obsolete. Use GetoptLong.
def getopts(single_options, *options)
single_options.scan(/.:?/) do |opt|
opt, val = arg.split(':', 2)
valopts[opt] = val.empty? ? nil : val
if $1.empty? # xinit -- -bpp 24
opt, val = $1.split('=', 2)
elsif valopts.key? opt # imclean --src +trash
valopts[opt] = val || argv.shift or return nil
elsif boolopts.key? opt # ruby --verbose
if val.empty? # ruby -e 'p $:'
valopts[opt] = argv.shift or return nil
boolopts[opt] = true # ruby -h
boolopts.each do |opt, val|
sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
eval "$OPT_#{sopt} = val"
valopts.each do |opt, val|
sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
eval "$OPT_#{sopt} = val"