From bca0b4075d53194b09ed5edef95d9ba9c3f6e62a Mon Sep 17 00:00:00 2001 From: nahi Date: Mon, 24 Dec 2007 08:23:09 +0000 Subject: Mon Dec 24 17:20:34 2007 NAKAMURA, Hiroshi * 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 --- lib/getopts.rb | 127 -------------------------------------------------------- lib/mailread.rb | 62 --------------------------- lib/parsearg.rb | 87 -------------------------------------- 3 files changed, 276 deletions(-) delete mode 100644 lib/getopts.rb delete mode 100644 lib/mailread.rb delete mode 100644 lib/parsearg.rb (limited to 'lib') diff --git a/lib/getopts.rb b/lib/getopts.rb deleted file mode 100644 index 4f39ca995a..0000000000 --- a/lib/getopts.rb +++ /dev/null @@ -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 -# -# 2002-03-05 -# rewritten by Akinori MUSHA -# - -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 diff --git a/lib/mailread.rb b/lib/mailread.rb deleted file mode 100644 index 08b33c92a4..0000000000 --- a/lib/mailread.rb +++ /dev/null @@ -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 diff --git a/lib/parsearg.rb b/lib/parsearg.rb deleted file mode 100644 index cab2dba789..0000000000 --- a/lib/parsearg.rb +++ /dev/null @@ -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 -- cgit v1.2.3