summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cvsignore3
-rw-r--r--ToDo2
-rw-r--r--ext/configsub.rb6
-rw-r--r--ext/extmk.rb.in12
-rw-r--r--ext/tk/sample/tkbiff.rb16
-rw-r--r--ext/tk/sample/tkfrom.rb14
-rw-r--r--lib/cgi/session.rb4
-rw-r--r--mkconfig.rb20
-rw-r--r--parse.y48
-rw-r--r--sample/fullpath.rb12
-rw-r--r--sample/mkproto.rb4
-rw-r--r--sample/test.rb32
-rw-r--r--sample/uumerge.rb12
13 files changed, 100 insertions, 85 deletions
diff --git a/.cvsignore b/.cvsignore
index 8fcaffddb2..5d66a7287b 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -1,9 +1,9 @@
+.cvsignore
parse.c
newver.rb
ruby
miniruby
README.fat-patch
-configure
config.cache
config.h
config.log
@@ -11,7 +11,6 @@ config.status
Makefile
ppack
archive
-extmk.rb
*.orig
*.rej
*.bak
diff --git a/ToDo b/ToDo
index 5f67a42b25..4062103d29 100644
--- a/ToDo
+++ b/ToDo
@@ -29,6 +29,8 @@ Language Spec.
* Regexp: make /o thread safe.
* decide if begin with rescue or ensure make do..while loop.
* a +1 to be a+1, not a(+1).
+* unify == and eql? again
+* to_i returns nil if str contains no digit.
Hacking Interpreter
diff --git a/ext/configsub.rb b/ext/configsub.rb
index 315cdaf868..0dc525515a 100644
--- a/ext/configsub.rb
+++ b/ext/configsub.rb
@@ -10,9 +10,9 @@ BEGIN {
CONFIG['TEENY'] = $3
end
- File.foreach($config || "config.status") do |$_|
- next if /^#/
- if /^s%@(\w+)@%(.*)%g/
+ File.foreach($config || "config.status") do |line|
+ next if /^#/ =~ line
+ if /^s%@(\w+)@%(.*)%g/ =~ line
name = $1
val = $2 || ""
next if /^(INSTALL|DEFS|configure_input|srcdir)$/ =~ name
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in
index ff6f04b4b6..52debd47cc 100644
--- a/ext/extmk.rb.in
+++ b/ext/extmk.rb.in
@@ -654,15 +654,15 @@ $static_ext = {}
for setup in ["@setup@", "#{$top_srcdir}/ext/@setup@"]
if File.file? setup
f = open(setup)
- while f.gets()
- $_.chomp!
- sub!(/#.*$/, '')
- next if /^\s*$/
- if /^option +nodynamic/
+ while line = f.gets()
+ line.chomp!
+ line.sub!(/#.*$/, '')
+ next if /^\s*$/ =~ line
+ if /^option +nodynamic/ =~ line
$nodynamic = true
next
end
- target = $_.split[0]
+ target = line.split[0]
target = target.downcase if /mswin32/ =~ RUBY_PLATFORM
$static_ext[target] = true
end
diff --git a/ext/tk/sample/tkbiff.rb b/ext/tk/sample/tkbiff.rb
index d2d7bf7beb..ac27184437 100644
--- a/ext/tk/sample/tkbiff.rb
+++ b/ext/tk/sample/tkbiff.rb
@@ -38,11 +38,11 @@ class Mail
def initialize(f)
@header = {}
@body = []
- while f.gets()
- $_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
+ while line = f.gets()
+ line.chop!
+ next if /^From / =~ line # skip From-line
+ break if /^$/ =~ line # end of header
+ if /^(\S+):\s*(.*)/ =~ line
@header[attr = $1.capitalize] = $2
elsif attr
sub(/^\s*/, '')
@@ -50,10 +50,10 @@ class Mail
end
end
- return if ! $_
+ return unless $_
- while f.gets()
- break if /^From /
+ while line = f.gets()
+ break if /^From / =~ line
@body.push($_)
end
end
diff --git a/ext/tk/sample/tkfrom.rb b/ext/tk/sample/tkfrom.rb
index ba0e547799..8c3efb8137 100644
--- a/ext/tk/sample/tkfrom.rb
+++ b/ext/tk/sample/tkfrom.rb
@@ -20,11 +20,11 @@ class Mail
def initialize(f)
@header = {}
@body = []
- while f.gets()
+ while line = f.gets()
$_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
+ next if /^From / =~ line # skip From-line
+ break if /^$/ =~ line # end of header
+ if /^(\S+):\s*(.*)/ =~ line
@header[attr = $1.capitalize] = $2
elsif attr
sub(/^\s*/, '')
@@ -32,10 +32,10 @@ class Mail
end
end
- return if ! $_
+ return unless $_
- while f.gets()
- break if /^From /
+ while line = f.gets()
+ break if /^From / =~ line
@body.push($_)
end
end
diff --git a/lib/cgi/session.rb b/lib/cgi/session.rb
index 48f3496939..30fc8582cb 100644
--- a/lib/cgi/session.rb
+++ b/lib/cgi/session.rb
@@ -54,7 +54,9 @@ class CGI
@output_cookies = [
Cookie::new("name" => session_key,
"value" => id,
- "path" => if ENV["SCRIPT_NAME"] then
+ "path" => if ENV["PATH_INFO"] then
+ File::dirname(ENV["PATH_INFO"])
+ elsif ENV["SCRIPT_NAME"] then
File::dirname(ENV["SCRIPT_NAME"])
else
""
diff --git a/mkconfig.rb b/mkconfig.rb
index 175a4c3b15..78ddaea3fd 100644
--- a/mkconfig.rb
+++ b/mkconfig.rb
@@ -26,18 +26,18 @@ v_fast = []
v_others = []
has_srcdir = false
has_version = false
-File.foreach "config.status" do |$_|
- next if /^#/
- if /^s%@program_transform_name@%s,(.*)%g$/
+File.foreach "config.status" do |line|
+ next if /^#/ =~ line
+ if /^s%@program_transform_name@%s,(.*)%g$/ =~ line
next if $install_name
ptn = $1.sub(/\$\$/, '$').split(/,/) #'
v_fast << " CONFIG[\"ruby_install_name\"] = \"" + "ruby".sub(ptn[0],ptn[1]) + "\"\n"
- elsif /^s%@(\w+)@%(.*)%g/
+ elsif /^s%@(\w+)@%(.*)%g/ =~ line
name = $1
val = $2 || ""
- next if name =~ /^(INSTALL|DEFS|configure_input|srcdir|top_srcdir)$/
- next if $install_name and name =~ /^RUBY_INSTALL_NAME$/
- next if $so_name and name =~ /^RUBY_SO_NAME$/
+ next if /^(INSTALL|DEFS|configure_input|srcdir|top_srcdir)$/ =~ name
+ next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
+ next if $so_name and /^RUBY_SO_NAME$/ =~ name
v = " CONFIG[\"" + name + "\"] = " +
val.sub(/^\s*(.*)\s*$/, '"\1"').gsub(/\$\{?(\w+)\}?/) {
"\#{CONFIG[\\\"#{$1}\\\"]}"
@@ -48,7 +48,7 @@ File.foreach "config.status" do |$_|
v_others << v
end
has_version = true if name == "MAJOR"
- if /DEFS/
+ if /DEFS/ =~ line
val.split(/\s*-D/).each do |i|
if i =~ /(.*)=(\\")?([^\\]*)(\\")?/
key, val = $1, $3
@@ -61,10 +61,10 @@ File.foreach "config.status" do |$_|
end
end
end
- elsif /^ac_given_srcdir=(.*)/
+ elsif /^ac_given_srcdir=(.*)/ =~ line
v_fast << " CONFIG[\"srcdir\"] = \"" + File.expand_path($1) + "\"\n"
has_srcdir = true
- elsif /^ac_given_INSTALL=(.*)/
+ elsif /^ac_given_INSTALL=(.*)/ =~ line
v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
end
# break if /^CEOF/
diff --git a/parse.y b/parse.y
index 94fafdd841..7149818668 100644
--- a/parse.y
+++ b/parse.y
@@ -4387,8 +4387,6 @@ void_stmts(node)
}
}
-static NODE *cond2();
-
static int
assign_in_cond(node)
NODE *node;
@@ -4435,65 +4433,79 @@ assign_in_cond(node)
return 1;
}
+static void
+warn_unless_e_option(str)
+ const char *str;
+{
+ if (strcmp(ruby_sourcefile, "-e") != 0)
+ rb_warning(str);
+}
+
static NODE*
-cond0(node, log)
+cond0(node, logop)
NODE *node;
- int log;
+ int logop;
{
enum node_type type = nd_type(node);
assign_in_cond(node);
switch (type) {
case NODE_DSTR:
- if (log) break;
+ if (logop) break;
nd_set_type(node, NODE_DREGX);
/* fall through */
case NODE_DREGX:
case NODE_DREGX_ONCE:
local_cnt('_');
local_cnt('~');
- rb_warn("string/regex literal in condition");
+ warn_unless_e_option("string/regex literal in condition");
return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
case NODE_DOT2:
case NODE_DOT3:
- node->nd_beg = cond0(node->nd_beg, log);
- node->nd_end = cond0(node->nd_end, log);
+ node->nd_beg = cond0(node->nd_beg, logop);
+ node->nd_end = cond0(node->nd_end, logop);
if (type == NODE_DOT2) nd_set_type(node,NODE_FLIP2);
else if (type == NODE_DOT3) nd_set_type(node, NODE_FLIP3);
node->nd_cnt = local_append(0);
- rb_warn("range literal in condition");
- return node;
+ warn_unless_e_option("range literal in condition");
+ break;
case NODE_STR:
- if (log) break;
+ if (logop) break;
node->nd_lit = rb_reg_new(RSTRING(node->nd_lit)->ptr,RSTRING(node->nd_lit)->len,0);
goto regexp;
case NODE_LIT:
- if (TYPE(node->nd_lit) == T_REGEXP) {
+ switch (TYPE(node->nd_lit)) {
+ case T_REGEXP:
regexp:
nd_set_type(node, NODE_MATCH);
local_cnt('_');
local_cnt('~');
- rb_warn("string/regex literal in condition");
- return node;
+ warn_unless_e_option("string/regex literal in condition");
+ break;
+
+ case T_FIXNUM:
+ if (logop) break;
+ warn_unless_e_option("integer literal in condition");
+ return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
}
}
return node;
}
static NODE*
-cond1(node, log)
+cond1(node, logop)
NODE *node;
- int log;
+ int logop;
{
if (node == 0) return 0;
if (nd_type(node) == NODE_NEWLINE){
- node->nd_next = cond0(node->nd_next, log);
+ node->nd_next = cond0(node->nd_next, logop);
return node;
}
- return cond0(node, log);
+ return cond0(node, logop);
}
static NODE*
diff --git a/sample/fullpath.rb b/sample/fullpath.rb
index ce268e20b9..252e7dc217 100644
--- a/sample/fullpath.rb
+++ b/sample/fullpath.rb
@@ -8,16 +8,16 @@ end
if path == nil
path = ""
-elsif path !~ /\/$/
+elsif path !~ %r|/$|
path += "/"
end
-while gets()
- if /:$/
+while line = gets()
+ case line
+ when /:$/
path = $_.chop.chop + "/"
- elsif /^total/ || /^d/
- elsif /^(.*\d )(.+)$/
+ when /^total/, /^d/
+ when /^(.*\d )(.+)$/
print($1, path, $2, "\n")
end
end
-
diff --git a/sample/mkproto.rb b/sample/mkproto.rb
index 3423a15905..e1d49be3e3 100644
--- a/sample/mkproto.rb
+++ b/sample/mkproto.rb
@@ -1,6 +1,6 @@
$/ = nil
-while gets()
- if /^((void|VALUE|int|char *\*|ID|struct [\w_]+ *\*|st_table *\*) *)?\n([\w\d_]+)\(.*\)\n\s*((.+;\n)*)\{/
+while line = gets()
+ if /^((void|VALUE|int|char *\*|ID|struct [\w_]+ *\*|st_table *\*) *)?\n([\w\d_]+)\(.*\)\n\s*((.+;\n)*)\{/ =~ line
$_ = $'
printf "%s %s(", $2, $3
args = []
diff --git a/sample/test.rb b/sample/test.rb
index 2aa598fe34..3d8ce723cc 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -116,21 +116,21 @@ tmp.close
tmp = open("while_tmp", "r")
test_ok(tmp.kind_of?(File))
-while tmp.gets()
- break if /vt100/
+while line = tmp.gets()
+ break if /vt100/ =~ line
end
-test_ok(!tmp.eof? && /vt100/)
+test_ok(!tmp.eof? && /vt100/ =~ line)
tmp.close
# test next
$bad = false
tmp = open("while_tmp", "r")
-while tmp.gets()
- next if /vt100/;
- $bad = 1 if /vt100/;
+while line = tmp.gets()
+ next if /vt100/ =~ line
+ $bad = 1 if /vt100/ =~ line
end
-test_ok(!(!tmp.eof? || /vt100/ || $bad))
+test_ok(!(!tmp.eof? || /vt100/ =~ line || $bad))
tmp.close
# test redo
@@ -138,13 +138,13 @@ $bad = false
tmp = open("while_tmp", "r")
while tmp.gets()
line = $_
- $_ = gsub(/vt100/, 'VT100')
+ gsub(/vt100/, 'VT100')
if $_ != line
- gsub!('VT100', 'Vt100')
- redo;
+ $_.gsub!('VT100', 'Vt100')
+ redo
end
- $bad = 1 if /vt100/
- $bad = 1 if /VT100/
+ $bad = 1 if /vt100/ =~ $_
+ $bad = 1 if /VT100/ =~ $_
end
test_ok(tmp.eof? && !$bad)
tmp.close
@@ -162,11 +162,11 @@ test_ok(sum == 220)
# test interval
$bad = false
tmp = open("while_tmp", "r")
-while tmp.gets()
- break unless 1..2
- if /vt100/ || /Amiga/ || /paper/
+while line = tmp.gets()
+ break if 3
+ case line
+ when /vt100/, /Amiga/, /paper/
$bad = true
- break
end
end
test_ok(!$bad)
diff --git a/sample/uumerge.rb b/sample/uumerge.rb
index 418323c439..2576bcb864 100644
--- a/sample/uumerge.rb
+++ b/sample/uumerge.rb
@@ -8,8 +8,8 @@ end
$sawbegin = 0
$sawend = 0
-while gets()
- if /^begin\s*(\d*)\s*(\S*)/
+while line = gets()
+ if /^begin\s*(\d*)\s*(\S*)/ =~ line
$mode, $file = $1, $2
$sawbegin+=1
if out_stdout
@@ -25,15 +25,15 @@ end
raise "missing begin" unless $sawbegin
out.binmode
-while gets()
- if /^end/
+while line = gets()
+ if /^end/ =~ line
$sawend+=1
out.close unless out_stdout
File.chmod $mode.oct, $file unless out_stdout
next
end
- sub(/[a-z]+$/, "") # handle stupid trailing lowercase letters
- next if /[a-z]/
+ line.sub!(/[a-z]+$/, "") # handle stupid trailing lowercase letters
+ next if /[a-z]/ =~ line
next if !(((($_[0] - 32) & 077) + 2) / 3 == $_.length / 4)
out << $_.unpack("u") if $sawbegin > $sawend
end