mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mon Dec 24 17:20:34 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/{mailread.rb,getopts.rb,parsearg.rb}: removed. see [ruby-core:12535], [ruby-dev:31969]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
30f1eb1856
commit
bca0b4075d
4 changed files with 5 additions and 276 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Dec 24 17:20:34 2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
|
||||
|
||||
* lib/{mailread.rb,getopts.rb,parsearg.rb}: removed.
|
||||
see [ruby-core:12535], [ruby-dev:31969].
|
||||
|
||||
Mon Dec 24 17:12:57 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/intern.h, random.c, array.c:
|
||||
|
|
127
lib/getopts.rb
127
lib/getopts.rb
|
@ -1,127 +0,0 @@
|
|||
#
|
||||
# getopts.rb -
|
||||
# $Release Version: $
|
||||
# $Revision$
|
||||
# $Date$
|
||||
# by Yasuo OHBA(SHL Japan Inc. Technology Dept.)
|
||||
#
|
||||
# --
|
||||
# this is obsolete; use getoptlong
|
||||
#
|
||||
# 2000-03-21
|
||||
# modified by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
||||
#
|
||||
# 2002-03-05
|
||||
# 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]
|
||||
|
||||
$RCS_ID=%q$Header$
|
||||
|
||||
# getopts is obsolete. Use GetoptLong.
|
||||
|
||||
def getopts(single_options, *options)
|
||||
boolopts = {}
|
||||
valopts = {}
|
||||
|
||||
#
|
||||
# set defaults
|
||||
#
|
||||
single_options.scan(/.:?/) do |opt|
|
||||
if opt.size == 1
|
||||
boolopts[opt] = false
|
||||
else
|
||||
valopts[opt[0, 1]] = nil
|
||||
end
|
||||
end if single_options
|
||||
|
||||
options.each do |arg|
|
||||
opt, val = arg.split(':', 2)
|
||||
|
||||
if val
|
||||
valopts[opt] = val.empty? ? nil : val
|
||||
else
|
||||
boolopts[opt] = false
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# scan
|
||||
#
|
||||
c = 0
|
||||
argv = ARGV
|
||||
|
||||
while arg = argv.shift
|
||||
case arg
|
||||
when /\A--(.*)/
|
||||
if $1.empty? # xinit -- -bpp 24
|
||||
break
|
||||
end
|
||||
|
||||
opt, val = $1.split('=', 2)
|
||||
|
||||
if opt.size == 1
|
||||
argv.unshift arg
|
||||
return nil
|
||||
elsif valopts.key? opt # imclean --src +trash
|
||||
valopts[opt] = val || argv.shift or return nil
|
||||
elsif boolopts.key? opt # ruby --verbose
|
||||
boolopts[opt] = true
|
||||
else
|
||||
argv.unshift arg
|
||||
return nil
|
||||
end
|
||||
|
||||
c += 1
|
||||
when /\A-(.+)/
|
||||
opts = $1
|
||||
|
||||
until opts.empty?
|
||||
opt = opts.slice!(0, 1)
|
||||
|
||||
if valopts.key? opt
|
||||
val = opts
|
||||
|
||||
if val.empty? # ruby -e 'p $:'
|
||||
valopts[opt] = argv.shift or return nil
|
||||
else # cc -ohello ...
|
||||
valopts[opt] = val
|
||||
end
|
||||
|
||||
c += 1
|
||||
break
|
||||
elsif boolopts.key? opt
|
||||
boolopts[opt] = true # ruby -h
|
||||
c += 1
|
||||
else
|
||||
argv.unshift arg
|
||||
return nil
|
||||
end
|
||||
end
|
||||
else
|
||||
argv.unshift arg
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# set
|
||||
#
|
||||
$OPT = {}
|
||||
|
||||
boolopts.each do |opt, val|
|
||||
$OPT[opt] = val
|
||||
|
||||
sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
|
||||
eval "$OPT_#{sopt} = val"
|
||||
end
|
||||
valopts.each do |opt, val|
|
||||
$OPT[opt] = val
|
||||
|
||||
sopt = opt.gsub(/[^A-Za-z0-9_]/, '_')
|
||||
eval "$OPT_#{sopt} = val"
|
||||
end
|
||||
|
||||
c
|
||||
end
|
|
@ -1,62 +0,0 @@
|
|||
# The Mail class represents an internet mail message (as per RFC822, RFC2822)
|
||||
# with headers and a body.
|
||||
class Mail
|
||||
|
||||
# Create a new Mail where +f+ is either a stream which responds to gets(),
|
||||
# or a path to a file. If +f+ is a path it will be opened.
|
||||
#
|
||||
# The whole message is read so it can be made available through the #header,
|
||||
# #[] and #body methods.
|
||||
#
|
||||
# The "From " line is ignored if the mail is in mbox format.
|
||||
def initialize(f)
|
||||
unless defined? f.gets
|
||||
f = open(f, "r")
|
||||
opened = true
|
||||
end
|
||||
|
||||
@header = {}
|
||||
@body = []
|
||||
begin
|
||||
while line = f.gets()
|
||||
line.chop!
|
||||
next if /^From /=~line # skip From-line
|
||||
break if /^$/=~line # end of header
|
||||
|
||||
if /^(\S+?):\s*(.*)/=~line
|
||||
(attr = $1).capitalize!
|
||||
@header[attr] = $2
|
||||
elsif attr
|
||||
line.sub!(/^\s*/, '')
|
||||
@header[attr] += "\n" + line
|
||||
end
|
||||
end
|
||||
|
||||
return unless line
|
||||
|
||||
while line = f.gets()
|
||||
break if /^From /=~line
|
||||
@body.push(line)
|
||||
end
|
||||
ensure
|
||||
f.close if opened
|
||||
end
|
||||
end
|
||||
|
||||
# Return the headers as a Hash.
|
||||
def header
|
||||
return @header
|
||||
end
|
||||
|
||||
# Return the message body as an Array of lines
|
||||
def body
|
||||
return @body
|
||||
end
|
||||
|
||||
# Return the header corresponding to +field+.
|
||||
#
|
||||
# Matching is case-insensitive.
|
||||
def [](field)
|
||||
@header[field.capitalize]
|
||||
end
|
||||
end
|
|
@ -1,87 +0,0 @@
|
|||
#
|
||||
# parsearg.rb - parse arguments
|
||||
# $Release Version: $
|
||||
# $Revision$
|
||||
# $Date$
|
||||
# by Yasuo OHBA(SHL Japan Inc. Technology Dept.)
|
||||
#
|
||||
# --
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: parsearg is deprecated after Ruby 1.8.1; use optparse instead"
|
||||
|
||||
$RCS_ID=%q$Header$
|
||||
|
||||
require "getopts"
|
||||
|
||||
def printUsageAndExit()
|
||||
if $USAGE
|
||||
eval($USAGE)
|
||||
end
|
||||
exit()
|
||||
end
|
||||
|
||||
def setParenthesis(ex, opt, c)
|
||||
if opt != ""
|
||||
ex = sprintf("%s$OPT_%s%s", ex, opt, c)
|
||||
else
|
||||
ex = sprintf("%s%s", ex, c)
|
||||
end
|
||||
return ex
|
||||
end
|
||||
|
||||
def setOrAnd(ex, opt, c)
|
||||
if opt != ""
|
||||
ex = sprintf("%s$OPT_%s %s%s ", ex, opt, c, c)
|
||||
else
|
||||
ex = sprintf("%s %s%s ", ex, c, c)
|
||||
end
|
||||
return ex
|
||||
end
|
||||
|
||||
def setExpression(ex, opt, op)
|
||||
if !op
|
||||
ex = sprintf("%s$OPT_%s", ex, opt)
|
||||
return ex
|
||||
end
|
||||
case op.chr
|
||||
when "(", ")"
|
||||
ex = setParenthesis(ex, opt, op.chr)
|
||||
when "|", "&"
|
||||
ex = setOrAnd(ex, opt, op.chr)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
return ex
|
||||
end
|
||||
|
||||
# parseArgs is obsolete. Use OptionParser instead.
|
||||
|
||||
def parseArgs(argc, nopt, single_opts, *opts)
|
||||
if (noOptions = getopts(single_opts, *opts)) == nil
|
||||
printUsageAndExit()
|
||||
end
|
||||
if nopt
|
||||
ex = nil
|
||||
pos = 0
|
||||
for o in nopt.split(/[()|&]/)
|
||||
pos += o.length
|
||||
ex = setExpression(ex, o, nopt[pos])
|
||||
pos += 1
|
||||
end
|
||||
begin
|
||||
if !eval(ex)
|
||||
printUsageAndExit()
|
||||
end
|
||||
rescue
|
||||
print "Format Error!! : \"" + nopt + "\"\t[parseArgs]\n"
|
||||
exit!(-1)
|
||||
end
|
||||
end
|
||||
if ARGV.length < argc
|
||||
printUsageAndExit()
|
||||
end
|
||||
return noOptions
|
||||
end
|
Loading…
Reference in a new issue