ruby-changes:30034
From: zzak <ko1@a...>
Date: Sat, 20 Jul 2013 22:41:26 +0900 (JST)
Subject: [ruby-changes:30034] zzak:r42086 (trunk): * sample/*: whitespace patch by Sergio Campama [Fixes GH-364]
zzak 2013-07-20 22:41:02 +0900 (Sat, 20 Jul 2013) New Revision: 42086 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42086 Log: * sample/*: whitespace patch by Sergio Campama [Fixes GH-364] https://github.com/ruby/ruby/pull/364 Modified files: trunk/ChangeLog trunk/sample/cal.rb trunk/sample/coverage.rb trunk/sample/drb/dbiff.rb trunk/sample/drb/dchats.rb trunk/sample/drb/dlogd.rb trunk/sample/drb/http0.rb trunk/sample/drb/http0serv.rb trunk/sample/drb/old_tuplespace.rb trunk/sample/drb/simpletuple.rb trunk/sample/dualstack-fetch.rb trunk/sample/dualstack-httpd.rb trunk/sample/fib.awk trunk/sample/fib.pl trunk/sample/fib.scm trunk/sample/from.rb trunk/sample/mkproto.rb trunk/sample/observ.rb trunk/sample/occur.pl trunk/sample/openssl/c_rehash.rb trunk/sample/openssl/certstore.rb trunk/sample/openssl/crlstore.rb trunk/sample/optparse/opttest.rb trunk/sample/rcs.awk trunk/sample/trojan.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42085) +++ ChangeLog (revision 42086) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jul 20 22:39:56 2013 Zachary Scott <e@z...> + + * sample/*: whitespace patch by Sergio Campama [Fixes GH-364] + https://github.com/ruby/ruby/pull/364 + Sat Jul 20 22:33:13 2013 Zachary Scott <e@z...> * doc/regexp.rdoc: [DOC] Fix typo in example [Fixes GH-365] Index: sample/coverage.rb =================================================================== --- sample/coverage.rb (revision 42085) +++ sample/coverage.rb (revision 42086) @@ -38,7 +38,7 @@ at_exit do https://github.com/ruby/ruby/blob/trunk/sample/coverage.rb#L38 end cov else - p line + p line warn("coverage file corrupted, ignoring: #{ cfile }") break [] end Index: sample/optparse/opttest.rb =================================================================== --- sample/optparse/opttest.rb (revision 42085) +++ sample/optparse/opttest.rb (revision 42086) @@ -22,13 +22,13 @@ ARGV.options do https://github.com/ruby/ruby/blob/trunk/sample/optparse/opttest.rb#L22 # mandatory argument opts.on("-r", "--require=LIBRARY", String, - "require the LIBRARY, before", - "executing your script") {|lib|@library=lib} + "require the LIBRARY, before", + "executing your script") {|lib|@library=lib} # optional argument opts.on("-i", "--inplace=[EXTENSION]", - "edit ARGV files in place", # multiline description - "(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''} + "edit ARGV files in place", # multiline description + "(make backup if EXTENSION supplied)") {|inplace| @inplace = inplace || ''} opts.on("-N=[NUM]", Integer) {|num|@number=num} @@ -37,7 +37,7 @@ ARGV.options do https://github.com/ruby/ruby/blob/trunk/sample/optparse/opttest.rb#L37 # limit argument syntax opts.on("-[0-7]", "-F", "--irs=[OCTAL]", OptionParser::OctalInteger, - "specify record separator", "(\\0, if no argument)") {|irs|@irs=irs} + "specify record separator", "(\\0, if no argument)") {|irs|@irs=irs} # boolean switch(default true) @exec = true @@ -51,7 +51,7 @@ ARGV.options do https://github.com/ruby/ruby/blob/trunk/sample/optparse/opttest.rb#L51 # keyword completion opts.on("--code=CODE", CODES, CODE_ALIASES, "select coding system", - "("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c} + "("+CODES.join(",")+",", " "+CODE_ALIASES.keys.join(",")+")") {|c|@code=c} # optional argument with keyword completion opts.on("--type[=TYPE]", [:text, :binary], "select type(text, binary)") {|t|@type=t} Index: sample/dualstack-httpd.rb =================================================================== --- sample/dualstack-httpd.rb (revision 42085) +++ sample/dualstack-httpd.rb (revision 42086) @@ -29,22 +29,22 @@ end https://github.com/ruby/ruby/blob/trunk/sample/dualstack-httpd.rb#L29 while true as = ls.accept Thread.start do - STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n" - s = as # copy to dynamic variable - str = '' - while line = s.gets - break if line == "\r\n" or line == "\n" - str << line - end - STDERR.print "socket #{myname} got string\n" - s.write("HTTP/1.0 200 OK\n") - s.write("Content-type: text/plain\n\n") - s.write("this is test: my name is #{myname}, you sent:\n") - s.write("---start\n") - s.write(str) - s.write("---end\n") - s.close - STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n" + STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n" + s = as # copy to dynamic variable + str = '' + while line = s.gets + break if line == "\r\n" or line == "\n" + str << line + end + STDERR.print "socket #{myname} got string\n" + s.write("HTTP/1.0 200 OK\n") + s.write("Content-type: text/plain\n\n") + s.write("this is test: my name is #{myname}, you sent:\n") + s.write("---start\n") + s.write(str) + s.write("---end\n") + s.close + STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n" end end end Index: sample/trojan.rb =================================================================== --- sample/trojan.rb (revision 42085) +++ sample/trojan.rb (revision 42086) @@ -7,7 +7,7 @@ for dir in path https://github.com/ruby/ruby/blob/trunk/sample/trojan.rb#L7 for f in d = Dir.open(dir) fpath = File.join(dir, f) if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0 - printf("file %s is writable from other users\n", fpath) + printf("file %s is writable from other users\n", fpath) end end d.close Index: sample/cal.rb =================================================================== --- sample/cal.rb (revision 42085) +++ sample/cal.rb (revision 42086) @@ -71,7 +71,7 @@ class Cal https://github.com/ruby/ruby/blob/trunk/sample/cal.rb#L71 ta = gr.collect{|xs| xs.join(' ')} ca = %w(January February March April May June July - August September October November December)[m - 1] + August September October November December)[m - 1] ca = ca + ' ' + y.to_s if !@opt_y ca = ca.center(@mw) @@ -132,10 +132,10 @@ if __FILE__ == $0 https://github.com/ruby/ruby/blob/trunk/sample/cal.rb#L132 begin GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT], - ['-j', GetoptLong::NO_ARGUMENT], - ['-m', GetoptLong::NO_ARGUMENT], - ['-t', GetoptLong::NO_ARGUMENT], - ['-y', GetoptLong::NO_ARGUMENT]). + ['-j', GetoptLong::NO_ARGUMENT], + ['-m', GetoptLong::NO_ARGUMENT], + ['-t', GetoptLong::NO_ARGUMENT], + ['-y', GetoptLong::NO_ARGUMENT]). each do |opt, arg| case opt when '-c'; cal.opt_c(arg) || raise Index: sample/from.rb =================================================================== --- sample/from.rb (revision 42085) +++ sample/from.rb (revision 42086) @@ -43,8 +43,8 @@ def get_mailfile(user) https://github.com/ruby/ruby/blob/trunk/sample/from.rb#L43 [ENV['SPOOLDIR'], '/usr/spool', '/var/spool', '/usr', '/var'].each do |m| path = "#{m}/mail/#{user}" if File.exist?(path) - file = path - break + file = path + break end end end @@ -64,23 +64,23 @@ def from_main https://github.com/ruby/ruby/blob/trunk/sample/from.rb#L64 mtime = File.mtime(file) open(file, "r") do |f| until f.eof? - header = {} - f.each_line do |line| - next if /^From / =~ line # skip From-line - break if /^$/ =~ line # end of header + header = {} + f.each_line do |line| + next if /^From / =~ line # skip From-line + break if /^$/ =~ line # end of header - if /^(?<attr>\S+?):\s*(?<value>.*)/ =~ line - attr.capitalize! - header[attr] = value - elsif attr - header[attr] += "\n" + line.lstrip - end - end + if /^(?<attr>\S+?):\s*(?<value>.*)/ =~ line + attr.capitalize! + header[attr] = value + elsif attr + header[attr] += "\n" + line.lstrip + end + end - f.each_line do |line| - break if /^From / =~ line - end - outcount += fromout(header['Date'], header['From'], header['Subject']) + f.each_line do |line| + break if /^From / =~ line + end + outcount += fromout(header['Date'], header['From'], header['Subject']) end end File.utime(atime, mtime, file) Index: sample/fib.awk =================================================================== --- sample/fib.awk (revision 42085) +++ sample/fib.awk (revision 42086) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/sample/fib.awk#L1 - function fib(n) { - if ( n<2 ) return n; else return fib(n-2) + fib(n-1) - } +function fib(n) { + if ( n<2 ) return n; else return fib(n-2) + fib(n-1) +} - BEGIN { print fib(20); } +BEGIN { print fib(20); } Index: sample/fib.scm =================================================================== --- sample/fib.scm (revision 42085) +++ sample/fib.scm (revision 42086) @@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/sample/fib.scm#L1 (define (fib n) (if (< n 2) - n - (+ (fib (- n 2)) (fib (- n 1))))) + n + (+ (fib (- n 2)) (fib (- n 1))))) (display (fib 20)) (newline) Index: sample/openssl/crlstore.rb =================================================================== --- sample/openssl/crlstore.rb (revision 42085) +++ sample/openssl/crlstore.rb (revision 42086) @@ -24,22 +24,22 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/crlstore.rb#L24 end unless crlfiles = @c_store.get_crls(ca.subject) if crl = renew_crl(cert, ca) - @c_store.add_crl(crl) - return crl + @c_store.add_crl(crl) + return crl end return nil end crlfiles.each do |crlfile| next unless crl = load_crl(crlfile) if crl.next_update < Time.now - if new_crl = renew_crl(cert, ca) - @c_store.delete_crl(crl) - @c_store.add_crl(new_crl) - crl = new_crl - end + if new_crl = renew_crl(cert, ca) + @c_store.delete_crl(crl) + @c_store.add_crl(new_crl) + crl = new_crl + end end if check_valid(crl, ca) - return crl + return crl end end nil @@ -49,7 +49,7 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/crlstore.rb#L49 @c_store.get_certs(cert.issuer).each do |cafile| ca = load_cert(cafile) if cert.verify(ca.public_key) - return ca + return ca end end nil @@ -58,10 +58,10 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/crlstore.rb#L58 def fetch(location) if /\AURI:(.*)\z/ =~ location begin - c = HTTPAccess2::Client.new(ENV['http_proxy'] || ENV['HTTP_PROXY']) - c.get_content($1) + c = HTTPAccess2::Client.new(ENV['http_proxy'] || ENV['HTTP_PROXY']) + c.get_content($1) rescue NameError, StandardError - nil + nil end else nil @@ -103,10 +103,10 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/crlstore.rb#L103 def renew_crl(cert, ca) if cdp = get_cdp(cert) if new_crl_str = fetch(cdp) - new_crl = load_crl_str(new_crl_str) - if check_valid(new_crl, ca) - return new_crl - end + new_crl = load_crl_str(new_crl_str) + if check_valid(new_crl, ca) + return new_crl + end end end false Index: sample/openssl/certstore.rb =================================================================== --- sample/openssl/certstore.rb (revision 42085) +++ sample/openssl/certstore.rb (revision 42086) @@ -76,27 +76,27 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/certstore.rb#L76 result = @x509store.verify(cert) do |ok, ctx| cert = ctx.current_cert if ctx.current_crl - crl_map[cert.subject] = true + crl_map[cert.subject] = true end if ok - if !ctx.current_crl - if crl = @crl_store.find_crl(cert) - crl_map[cert.subject] = true - if crl.revoked.find { |revoked| revoked.serial == cert.serial } - ok = false - error_string = 'certification revoked' - end - end - end + if !ctx.current_crl + if crl = @crl_store.find_crl(cert) + crl_map[cert.subject] = true + if crl.revoked.find { |revoked| revoked.serial == cert.serial } + ok = false + error_string = 'certification revoked' + end + end + end end error_map[cert.subject] = error_string if error_string ok end error = if result - nil - else - error_map[cert.subject] || @x509store.error_string - end + nil + else + error_map[cert.subject] || @x509store.error_string + end return error, crl_map end @@ -105,13 +105,13 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/certstore.rb#L105 cert = generate_cert(certfile) case guess_cert_type(cert) when CERT_TYPE_SELF_SIGNED - @self_signed_ca << cert + @self_signed_ca << cert when CERT_TYPE_OTHER - @other_ca << cert + @other_ca << cert when CERT_TYPE_EE - @ee << cert + @ee << cert else - raise "Unknown cert type." + raise "Unknown cert type." end end @c_store.get_crls.each do |crlfile| @@ -128,21 +128,21 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/certstore.rb#L128 # Ignores criticality of extensions. It's 'guess'ing. case ext.oid when 'basicConstraints' - /CA:(TRUE|FALSE), pathlen:(\d+)/ =~ ext.value - ca = ($1 == 'TRUE') unless ca + /CA:(TRUE|FALSE), pathlen:(\d+)/ =~ ext.value + ca = ($1 == 'TRUE') unless ca when 'keyUsage' - usage = ext.value.split(/\s*,\s*/) - ca = usage.include?('Certificate Sign') unless ca + usage = ext.value.split(/\s*,\s*/) + ca = usage.include?('Certificate Sign') unless ca when 'nsCertType' - usage = ext.value.split(/\s*,\s*/) - ca = usage.include?('SSL CA') unless ca + usage = ext.value.split(/\s*,\s*/) + ca = usage.include?('SSL CA') unless ca end end if ca if self_signed - CERT_TYPE_SELF_SIGNED + CERT_TYPE_SELF_SIGNED else - CERT_TYPE_OTHER + CERT_TYPE_OTHER end else CERT_TYPE_EE Index: sample/openssl/c_rehash.rb =================================================================== --- sample/openssl/c_rehash.rb (revision 42085) +++ sample/openssl/c_rehash.rb (revision 42086) @@ -54,13 +54,13 @@ class CHashDir https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L54 OpenSSL::X509::Certificate.new(str) rescue begin - OpenSSL::X509::CRL.new(str) + OpenSSL::X509::CRL.new(str) rescue - begin - OpenSSL::X509::Request.new(str) - rescue - nil - end + begin + OpenSSL::X509::Request.new(str) + rescue + nil + end end end end @@ -75,15 +75,15 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L75 Dir.chdir(@dirpath) do delete_symlink Dir.glob('*.pem') do |pemfile| - cert = load_pem_file(pemfile) - case cert - when OpenSSL::X509::Certificate - link_hash_cert(pemfile, cert) - when OpenSSL::X509::CRL - link_hash_crl(pemfile, cert) - else - STDERR.puts("WARNING: #{pemfile} does not contain a certificate or CRL: skipping") unless @silent - end + cert = load_pem_file(pemfile) + case cert + when OpenSSL::X509::Certificate + link_hash_cert(pemfile, cert) + when OpenSSL::X509::CRL + link_hash_crl(pemfile, cert) + else + STDERR.puts("WARNING: #{pemfile} does not contain a certificate or CRL: skipping") unless @silent + end end end end @@ -103,7 +103,7 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L103 } unless filepath unless @silent - STDERR.puts("WARNING: Skipping duplicate certificate #{org_filename}") + STDERR.puts("WARNING: Skipping duplicate certificate #{org_filename}") end else (@cert_cache[name_hash] ||= []) << path(filepath) @@ -118,7 +118,7 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L118 } unless filepath unless @silent - STDERR.puts("WARNING: Skipping duplicate CRL #{org_filename}") + STDERR.puts("WARNING: Skipping duplicate CRL #{org_filename}") end else (@crl_cache[name_hash] ||= []) << path(filepath) @@ -132,7 +132,7 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L132 filepath = yield(idx) break unless FileTest.symlink?(filepath) or FileTest.exist?(filepath) if @fingerprint_cache[filepath] == fingerprint - return false + return false end idx += 1 end @@ -147,7 +147,7 @@ private https://github.com/ruby/ruby/blob/trunk/sample/openssl/c_rehash.rb#L147 File.symlink(from, to) rescue File.open(to, "w") do |f| - f << File.read(from) + f << File.read(from) end end end Index: sample/occur.pl =================================================================== --- sample/occur.pl (revision 42085) +++ sample/occur.pl (revision 42086) @@ -1,9 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/sample/occur.pl#L1 while (<>) { - for (split(/\W+/)) { - $freq{$_}++; - } + for (split(/\W+/)) { + $freq{$_}++; + } } for (sort keys %freq) { - print "$_ -- $freq{$_}\n"; + print "$_ -- $freq{$_}\n"; } Index: sample/mkproto.rb =================================================================== --- sample/mkproto.rb (revision 42085) +++ sample/mkproto.rb (revision 42086) @@ -7,18 +7,18 @@ while line = gets() https://github.com/ruby/ruby/blob/trunk/sample/mkproto.rb#L7 for arg in $4.split(/;\n\s*/) arg.gsub!(/ +/, ' ') if arg =~ /,/ - if arg =~ /(([^*]+) *\** *\w+),/ - type = $2.strip - args.push $1.strip - arg = $' - else - type = "" - end - while arg.sub!(/(\** *\w+)(,|$)/, "") && $~ - args.push type + " " + $1.strip - end + if arg =~ /(([^*]+) *\** *\w+),/ + type = $2.strip + args.push $1.strip + arg = $' + else + type = "" + end + while arg.sub!(/(\** *\w+)(,|$)/, "") && $~ + args.push type + " " + $1.strip + end else - args.push arg.strip + args.push arg.strip end end printf "%s);\n", args.join(', ') Index: sample/observ.rb =================================================================== --- sample/observ.rb (revision 42085) +++ sample/observ.rb (revision 42086) @@ -8,10 +8,10 @@ class Tick https://github.com/ruby/ruby/blob/trunk/sample/observ.rb#L8 def initialize Thread.start do loop do - sleep 0.999 - now = Time.now - changed - notify_observers(now.hour, now.min, now.sec) + sleep 0.999 + now = Time.now + changed + notify_observers(now.hour, now.min, now.sec) end end end Index: sample/dualstack-fetch.rb =================================================================== --- sample/dualstack-fetch.rb (revision 42085) +++ sample/dualstack-fetch.rb (revision 42086) @@ -38,7 +38,7 @@ end https://github.com/ruby/ruby/blob/trunk/sample/dualstack-fetch.rb#L38 STDERR.print "conntecting to #{host} port #{port}\n" c = TCPSocket.new(host, port) dest = Socket.getnameinfo(c.getpeername, - Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV) + Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV) STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n" c.print "GET #{path} HTTP/1.0\n" c.print "Host: #{host}\n" Index: sample/drb/http0serv.rb =================================================================== --- sample/drb/http0serv.rb (revision 42085) +++ sample/drb/http0serv.rb (revision 42086) @@ -8,111 +8,111 @@ module DRb https://github.com/ruby/ruby/blob/trunk/sample/drb/http0serv.rb#L8 def self.open_server(uri, config) unless /^http:/ =~ uri - raise(DRbBadScheme, uri) unless uri =~ /^http:/ - raise(DRbBadURI, 'can\'t parse uri:' + uri) + raise(DRbBadScheme, uri) unless uri =~ /^http:/ + raise(DRbBadURI, 'can\'t parse uri:' + uri) end Server.new(uri, config) end class Callback < WEBrick::HTTPServlet::AbstractServlet def initialize(config, drb) - @config = config - @drb = drb - @queue = Queue.new + @config = config + @drb = drb + @queue = Queue.new end def do_POST(req, res) - @req = req - @res = res - (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/