* ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb,

lib/shellwords.rb: get rid of shadowing outer local variable.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2006-10-09 14:41:24 +00:00
Родитель c009be97e8
Коммит 88d6c083ea
6 изменённых файлов: 45 добавлений и 43 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Oct 9 23:40:58 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb, lib/fileutils.rb, lib/mkmf.rb, lib/optparse.rb,
lib/shellwords.rb: get rid of shadowing outer local variable.
Mon Oct 9 22:56:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org> Mon Oct 9 22:56:12 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/rexml/encoding.rb (REXML::Encoding::check_encoding): spaces * lib/rexml/encoding.rb (REXML::Encoding::check_encoding): spaces

Просмотреть файл

@ -220,7 +220,6 @@ end
def parse_args() def parse_args()
$mflags = [] $mflags = []
opts = nil
$optparser ||= OptionParser.new do |opts| $optparser ||= OptionParser.new do |opts|
opts.on('-n') {$dryrun = true} opts.on('-n') {$dryrun = true}
opts.on('--[no-]extension [EXTS]', Array) do |v| opts.on('--[no-]extension [EXTS]', Array) do |v|
@ -259,7 +258,7 @@ def parse_args()
rescue OptionParser::InvalidOption => e rescue OptionParser::InvalidOption => e
retry if /^--/ =~ e.args[0] retry if /^--/ =~ e.args[0]
$optparser.warn(e) $optparser.warn(e)
abort opts.to_s abort $optparser.to_s
end end
$destdir ||= '' $destdir ||= ''
@ -331,7 +330,8 @@ MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtim
# get static-link modules # get static-link modules
$static_ext = {} $static_ext = {}
if $extstatic if $extstatic
$extstatic.each do |target| $extstatic.each do |t|
target = t
target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM
$static_ext[target] = $static_ext.size $static_ext[target] = $static_ext.size
end end
@ -368,12 +368,12 @@ if $extension
exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")} exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")}
else else
withes, withouts = %w[--with --without].collect {|w| withes, withouts = %w[--with --without].collect {|w|
if not (w = %w[-extensions -ext].collect {|opt|arg_config(w+opt)}).any? if not (w = %w[-extensions -ext].collect {|o|arg_config(w+o)}).any?
proc {false} proc {false}
elsif (w = w.grep(String)).empty? elsif (w = w.grep(String)).empty?
proc {true} proc {true}
else else
w.collect {|opt| opt.split(/,/)}.flatten.method(:any?) w.collect {|o| o.split(/,/)}.flatten.method(:any?)
end end
} }
cond = proc {|ext| cond = proc {|ext|
@ -461,7 +461,7 @@ unless $extlist.empty?
void Init_ext _((void))\n{\n char *src;#$extinit} void Init_ext _((void))\n{\n char *src;#$extinit}
} }
if !modified?(extinit.c, MTIMES) || IO.read(extinit.c) != src if !modified?(extinit.c, MTIMES) || IO.read(extinit.c) != src
open(extinit.c, "w") {|f| f.print src} open(extinit.c, "w") {|fe| fe.print src}
end end
$extobjs = "ext/#{extinit.o} " + $extobjs $extobjs = "ext/#{extinit.o} " + $extobjs
@ -485,8 +485,8 @@ else
FileUtils.rm_f(extinit.to_a) FileUtils.rm_f(extinit.to_a)
end end
rubies = [] rubies = []
%w[RUBY RUBYW STATIC_RUBY].each {|r| %w[RUBY RUBYW STATIC_RUBY].each {|n|
n = r r = n
if r = arg_config("--"+r.downcase) || config_string(r+"_INSTALL_NAME") if r = arg_config("--"+r.downcase) || config_string(r+"_INSTALL_NAME")
rubies << Config.expand(r+=EXEEXT) rubies << Config.expand(r+=EXEEXT)
$mflags << "#{n}=#{r}" $mflags << "#{n}=#{r}"

Просмотреть файл

@ -212,11 +212,11 @@ module FileUtils
stack.push path stack.push path
path = File.dirname(path) path = File.dirname(path)
end end
stack.reverse_each do |path| stack.reverse_each do |dir|
begin begin
fu_mkdir path, options[:mode] fu_mkdir dir, options[:mode]
rescue SystemCallError => err rescue SystemCallError => err
raise unless File.directory?(path) raise unless File.directory?(dir)
end end
end end
end end

Просмотреть файл

@ -108,7 +108,7 @@ end
def map_dir(dir, map = nil) def map_dir(dir, map = nil)
map ||= INSTALL_DIRS map ||= INSTALL_DIRS
map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)}
end end
topdir = File.dirname(libdir = File.dirname(__FILE__)) topdir = File.dirname(libdir = File.dirname(__FILE__))
@ -501,7 +501,8 @@ def install_files(mfile, ifiles, map = nil, srcprefix = nil)
len = srcdir.size len = srcdir.size
end end
f = nil f = nil
Dir.glob(files) do |f| Dir.glob(files) do |fx|
f = fx
f[0..len] = "" if len f[0..len] = "" if len
d = File.dirname(f) d = File.dirname(f)
d.sub!(prefix, "") if prefix d.sub!(prefix, "") if prefix
@ -967,11 +968,11 @@ def dir_config(target, idefault=nil, ldefault=nil)
idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : [] idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : []
if defaults if defaults
idirs.concat(defaults.collect {|dir| dir + "/include"}) idirs.concat(defaults.collect {|d| d + "/include"})
idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR) idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR)
end end
unless idirs.empty? unless idirs.empty?
idirs.collect! {|dir| "-I" + dir} idirs.collect! {|d| "-I" + d}
idirs -= Shellwords.shellwords($CPPFLAGS) idirs -= Shellwords.shellwords($CPPFLAGS)
unless idirs.empty? unless idirs.empty?
$CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ") $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ")
@ -980,7 +981,7 @@ def dir_config(target, idefault=nil, ldefault=nil)
ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : [] ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : []
if defaults if defaults
ldirs.concat(defaults.collect {|dir| dir + "/lib"}) ldirs.concat(defaults.collect {|d| d + "/lib"})
ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR) ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR)
end end
$LIBPATH = ldirs | $LIBPATH $LIBPATH = ldirs | $LIBPATH
@ -1177,7 +1178,7 @@ def create_makefile(target, srcprefix = nil)
$objs.push(obj) unless $objs.index(obj) $objs.push(obj) unless $objs.index(obj)
end end
elsif !(srcs = $srcs) elsif !(srcs = $srcs)
srcs = $objs.collect {|obj| obj.sub(/\.o\z/, '.c')} srcs = $objs.collect {|o| o.sub(/\.o\z/, '.c')}
end end
$srcs = srcs $srcs = srcs
for i in $objs for i in $objs
@ -1282,7 +1283,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
dirs << dir dirs << dir
mfile.print "pre-install-rb#{sfx}: #{dir}\n" mfile.print "pre-install-rb#{sfx}: #{dir}\n"
end end
files.each do |f| for f in files
dest = "#{dir}/#{File.basename(f)}" dest = "#{dir}/#{File.basename(f)}"
mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("install-rb#{sfx}: #{dest}\n")
mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ") mfile.print("#{dest}: #{f}\n\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) ")
@ -1303,7 +1304,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
end end
end end
dirs.unshift(sodir) if target and !dirs.include?(sodir) dirs.unshift(sodir) if target and !dirs.include?(sodir)
dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"} dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"}
mfile.print <<-SITEINSTALL mfile.print <<-SITEINSTALL
@ -1379,7 +1380,7 @@ site-install-rb: install-rb
implicit = [[m[1], m[2]], [m.post_match]] implicit = [[m[1], m[2]], [m.post_match]]
next next
elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line
line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {|*m| RULE_SUBST % m} line.gsub!(%r"(?<=\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)", &RULE_SUBST.method(:%))
end end
depout << line depout << line
end end
@ -1408,7 +1409,7 @@ site-install-rb: install-rb
else else
headers = %w[ruby.h defines.h] headers = %w[ruby.h defines.h]
if RULE_SUBST if RULE_SUBST
headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}} headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
end end
headers << $config_h if $config_h headers << $config_h if $config_h
headers << "$(RUBY_EXTCONF_H)" if $extconf_h headers << "$(RUBY_EXTCONF_H)" if $extconf_h
@ -1508,13 +1509,13 @@ EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
hdr = [] hdr = []
config_string('COMMON_MACROS') do |s| config_string('COMMON_MACROS') do |s|
Shellwords.shellwords(s).each do |s| Shellwords.shellwords(s).each do |w|
/(.*?)(?:=(.*))/ =~ s /(.*?)(?:=(.*))/ =~ w
hdr << "#define #$1 #$2" hdr << "#define #$1 #$2"
end end
end end
config_string('COMMON_HEADERS') do |s| config_string('COMMON_HEADERS') do |s|
Shellwords.shellwords(s).each {|s| hdr << "#include <#{s}>"} Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"}
end end
COMMON_HEADERS = hdr.join("\n") COMMON_HEADERS = hdr.join("\n")
COMMON_LIBS = config_string('COMMON_LIBS', &split) || [] COMMON_LIBS = config_string('COMMON_LIBS', &split) || []
@ -1537,7 +1538,7 @@ LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L"%s"'
RPATHFLAG = config_string('RPATHFLAG') || '' RPATHFLAG = config_string('RPATHFLAG') || ''
LIBARG = config_string('LIBARG') || '-l%s' LIBARG = config_string('LIBARG') || '-l%s'
sep = config_string('BUILD_FILE_SEPARATOR') {|sep| ":/=#{sep}" if sep != "/"} || "" sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if sep != "/"} || ""
CLEANINGS = " CLEANINGS = "
clean: clean:
@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) @-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep})

Просмотреть файл

@ -221,7 +221,7 @@ class OptionParser
def complete(key, icase = false, pat = nil) def complete(key, icase = false, pat = nil)
pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), pat ||= Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'),
icase) icase)
canon, sw, k, v, cn = nil canon, sw, cn = nil
candidates = [] candidates = []
each do |k, *v| each do |k, *v|
(if Regexp === k (if Regexp === k
@ -349,7 +349,7 @@ class OptionParser
if conv if conv
val = conv.call(*val) val = conv.call(*val)
else else
val = proc {|val| val}.call(*val) val = proc {|v| v}.call(*val)
end end
return arg, block, val return arg, block, val
end end
@ -368,7 +368,7 @@ class OptionParser
# +indent+:: Prefix string indents all summarized lines. # +indent+:: Prefix string indents all summarized lines.
# #
def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "") def summarize(sdone = [], ldone = [], width = 1, max = width - 1, indent = "")
sopts, lopts, s = [], [], nil sopts, lopts = [], [], nil
@short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short @short.each {|s| sdone.fetch(s) {sopts << s}; sdone[s] = true} if @short
@long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long @long.each {|s| ldone.fetch(s) {lopts << s}; ldone[s] = true} if @long
return if sopts.empty? and lopts.empty? # completely hidden return if sopts.empty? and lopts.empty? # completely hidden
@ -384,9 +384,9 @@ class OptionParser
end end
left[0] << arg if arg left[0] << arg if arg
mlen = left.collect {|s| s.length}.max.to_i mlen = left.collect {|ss| ss.length}.max.to_i
while mlen > width and l = left.shift while mlen > width and l = left.shift
mlen = left.collect {|s| s.length}.max.to_i if l.length == mlen mlen = left.collect {|ss| ss.length}.max.to_i if l.length == mlen
yield(indent + l) yield(indent + l)
end end
@ -453,7 +453,7 @@ class OptionParser
raise MissingArgument if argv.empty? raise MissingArgument if argv.empty?
arg = argv.shift arg = argv.shift
end end
conv_arg(*parse_arg(arg) {|*exc| raise(*exc)}) conv_arg(*parse_arg(arg, &method(:raise)))
end end
end end
@ -557,7 +557,6 @@ class OptionParser
# +nlopts+:: Negated long style options list. # +nlopts+:: Negated long style options list.
# #
def update(sw, sopts, lopts, nsw = nil, nlopts = nil) def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
o = nil
sopts.each {|o| @short[o] = sw} if sopts sopts.each {|o| @short[o] = sw} if sopts
lopts.each {|o| @long[o] = sw} if lopts lopts.each {|o| @long[o] = sw} if lopts
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
@ -1063,7 +1062,6 @@ class OptionParser
default_style = Switch::NoArgument default_style = Switch::NoArgument
default_pattern = nil default_pattern = nil
klass = nil klass = nil
o = nil
n, q, a = nil n, q, a = nil
opts.each do |o| opts.each do |o|
@ -1097,7 +1095,7 @@ class OptionParser
else else
raise ArgumentError, "argument pattern given twice" raise ArgumentError, "argument pattern given twice"
end end
o.each {|(o, *v)| pattern[o] = v.fetch(0) {o}} o.each {|pat, *v| pattern[pat] = v.fetch(0) {pat}}
when Module when Module
raise ArgumentError, "unsupported argument type: #{o}" raise ArgumentError, "unsupported argument type: #{o}"
when *ArgumentStyle.keys when *ArgumentStyle.keys
@ -1246,8 +1244,8 @@ class OptionParser
# :nodoc: # :nodoc:
def parse_in_order(argv = default_argv, setter = nil, &nonopt) def parse_in_order(argv = default_argv, setter = nil, &nonopt)
opt, arg, sw, val, rest = nil opt, arg, val, rest = nil
nonopt ||= proc {|arg| throw :terminate, arg} nonopt ||= proc {|a| throw :terminate, a}
argv.unshift(arg) if arg = catch(:terminate) { argv.unshift(arg) if arg = catch(:terminate) {
while arg = argv.shift while arg = argv.shift
case arg case arg
@ -1301,7 +1299,8 @@ class OptionParser
# non-option argument # non-option argument
else else
catch(:prune) do catch(:prune) do
visit(:each_option) do |sw| visit(:each_option) do |sw0|
sw = sw0
sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg) sw.block.call(arg) if Switch === sw and sw.match_nonswitch?(arg)
end end
nonopt.call(arg) nonopt.call(arg)
@ -1332,8 +1331,7 @@ class OptionParser
# #
def permute!(argv = default_argv) def permute!(argv = default_argv)
nonopts = [] nonopts = []
arg = nil order!(argv, &nonopts.method(:<<))
order!(argv) {|arg| nonopts << arg}
argv[0, 0] = nonopts argv[0, 0] = nonopts
argv argv
end end
@ -1410,7 +1408,6 @@ class OptionParser
# +block+. # +block+.
# #
def visit(id, *args, &block) def visit(id, *args, &block)
el = nil
@stack.reverse_each do |el| @stack.reverse_each do |el|
el.send(id, *args, &block) el.send(id, *args, &block)
end end
@ -1443,7 +1440,7 @@ class OptionParser
search(typ, opt) {|sw| return [sw, opt]} # exact match or... search(typ, opt) {|sw| return [sw, opt]} # exact match or...
end end
raise AmbiguousOption, catch(:ambiguous) { raise AmbiguousOption, catch(:ambiguous) {
visit(:complete, typ, opt, icase, *pat) {|opt, *sw| return sw} visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
raise InvalidOption, opt raise InvalidOption, opt
} }
end end
@ -1562,7 +1559,7 @@ class OptionParser
# #
accept(Array) do |s,| accept(Array) do |s,|
if s if s
s = s.split(',').collect {|s| s unless s.empty?} s = s.split(',').collect {|ss| ss unless ss.empty?}
end end
s s
end end

Просмотреть файл

@ -28,7 +28,6 @@ module Shellwords
def shellwords(line) def shellwords(line)
words = [] words = []
field = '' field = ''
word = sq = dq = esc = garbage = sep = nil
line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
|word, sq, dq, esc, garbage, sep| |word, sq, dq, esc, garbage, sep|
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage