8000 changes from personal modifies -- matz · jruby/ruby@08ec02b · GitHub
[go: up one dir, main page]

Skip to content

Commit 08ec02b

Browse files
author
matz
committed
changes from personal modifies -- matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ceec42b commit 08ec02b

File tree

13 files changed

+100
-85
lines changed

13 files changed

+100
-85
lines changed

.cvsignore

Lines changed: 1 addition & 2 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
.cvsignore
12
parse.c
23
newver.rb
34
ruby
45
miniruby
56
README.fat-patch
6-
configure
77
config.cache
88
config.h
99
config.log
1010
config.status
1111
Makefile
1212
ppack
1313
archive
14-
extmk.rb
1514
*.orig
1615
*.rej
1716
*.bak

ToDo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Language Spec.
2929
* Regexp: make /o thread safe.
3030
* decide if begin with rescue or ensure make do..while loop.
3131
* a +1 to be a+1, not a(+1).
32+
* unify == and eql? again
33+
* to_i returns nil if str contains no digit.
3234

3335
Hacking Interpreter
3436

ext/configsub.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
CONFIG['TEENY'] = $3
1111
end
1212

13-
File.foreach($config || "config.status") do |$_|
14-
next if /^#/
15-
if /^s%@(\w+)@%(.*)%g/
13+
File.foreach($config || "config.status") do |line|
14+
next if /^#/ =~ line
15+
if /^s%@(\w+)@%(.*)%g/ =~ line
1616
name = $1
1717
val = $2 || ""
1818
next if /^(INSTALL|DEFS|configure_input|srcdir)$/ =~ name

ext/extmk.rb.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,15 @@ $static_ext = {}
654654
for setup in ["@setup@", "#{$top_srcdir}/ext/@setup@"]
655655
if File.file? setup
656656
f = open(setup)
657-
while f.gets()
658-
$_.chomp!
659-
sub!(/#.*$/, '')
660-
next if /^\s*$/
661-
if /^option +nodynamic/
657+
while line = f.gets()
658+
line.chomp!
659+
line.sub!(/#.*$/, '')
660+
next if /^\s*$/ =~ line
661+
if /^option +nodynamic/ =~ line
662662
$nodynamic = true
663663
next
664664
end
665-
target = $_.split[0]
665+
target = line.split[0]
666666
target = target.downcase if /mswin32/ =~ RUBY_PLATFORM
667667
$static_ext[target] = true
668668
end

ext/tk/sample/tkbiff.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ def Mail.new(f)
3838
def initialize(f)
3939
@header = {}
4040
@body = []
41-
while f.gets()
42-
$_.chop!
43-
next if /^From / # skip From-line
44-
break if /^$/ # end of header
45-
if /^(\S+):\s*(.*)/
41+
while line = f.gets()
42+
line.chop!
43+
next if /^From / =~ line # skip From-line
44+
break if /^$/ =~ line # end of header
45+
if /^(\S+):\s*(.*)/ =~ line
4646
@header[attr = $1.capitalize] = $2
4747
elsif attr
4848
sub(/^\s*/, '')
4949
@header[attr] += "\n" + $_
5050
end
5151
end
5252

53-
return if ! $_
53+
return unless $_
5454

55-
while f.gets()
56-
break if /^From /
55+
while line = f.gets()
56+
break if /^From / =~ line
5757
@body.push($_)
5858
end
5959
end

ext/tk/sample/tkfrom.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ def Mail.new(f)
2020
def initialize(f)
2121
@header = {}
2222
@body = []
23-
while f.gets()
23+
while line = f.gets()
2424
$_.chop!
25-
next if /^From / # skip From-line
26-
break if /^$/ # end of header
27-
if /^(\S+):\s*(.*)/
25+
next if /^From / =~ line # skip From-line
26+
break if /^$/ =~ line # end of header
27+
if /^(\S+):\s*(.*)/ =~ line
2828
@header[attr = $1.capitalize] = $2
2929
elsif attr
3030
sub(/^\s*/, '')
3131
@header[attr] += "\n" + $_
3232
end
3333
end
3434

35-
return if ! $_
35+
return unless $_
3636

37-
while f.gets()
38-
break if /^From /
37+
while line = f.gets()
38+
break if /^From / =~ line
3939
@body.push($_)
4040
end
4141
end

lib/cgi/session.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def initialize(request, option={})
5454
@output_cookies = [
5555
Cookie::new("name" => session_key,
5656
"value" => id,
57-
"path" => if ENV["SCRIPT_NAME"] then
57+
"path" => if ENV["PATH_INFO"] then
58+
File::dirname(ENV["PATH_INFO"])
59+
elsif ENV["SCRIPT_NAME"] then
5860
File::dirname(ENV["SCRIPT_NAME"])
5961
else
6062
""

mkconfig.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ module Config
2626
v_others = []
2727
has_srcdir = false
2828
has_version = false
29-
File.foreach "config.status" do |$_|
30-
next if /^#/
31-
if /^s%@program_transform_name@%s,(.*)%g$/
29+
File.foreach "config.status" do |line|
30+
next if /^#/ =~ line
31+
if /^s%@program_transform_name@%s,(.*)%g$/ =~ line
3232
next if $install_name
3333
ptn = $1.sub(/\$\$/, '$').split(/,/) #'
3434
v_fast << " CONFIG[\"ruby_install_name\"] = \"" + "ruby".sub(ptn[0],ptn[1]) + "\"\n"
35-
elsif /^s%@(\w+)@%(.*)%g/
35+
elsif /^s%@(\w+)@%(.*)%g/ =~ line
3636
name = $1
3737
val = $2 || ""
38-
next if name =~ /^(INSTALL|DEFS|configure_input|srcdir|top_srcdir)$/
39-
next if $install_name and name =~ /^RUBY_INSTALL_NAME$/
40-
next if $so_name and name =~ /^RUBY_SO_NAME$/
38+
next if /^(INSTALL|DEFS|configure_input|srcdir|top_srcdir)$/ =~ name
39+
next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
40+
next if $so_name and /^RUBY_SO_NAME$/ =~ name
4141
v = " CONFIG[\"" + name + "\"] = " +
4242
val.sub(/^\s*(.*)\s*$/, '"\1"').gsub(/\$\{?(\w+)\}?/) {
4343
"\#{CONFIG[\\\"#{$1}\\\"]}"
@@ -48,7 +48,7 @@ module Config
4848
v_others << v
4949
end
5050
has_version = true if name == "MAJOR"
51-
if /DEFS/
51+
if /DEFS/ =~ line
5252
val.split(/\s*-D/).each do |i|
5353
if i =~ /(.*)=(\\")?([^\\]*)(\\")?/
5454
key, val = $1, $3
@@ -61,10 +61,10 @@ module Config
6161
end
6262
end
6363
end
64-
elsif /^ac_given_srcdir=(.*)/
64+
elsif /^ac_given_srcdir=(.*)/ =~ line
6565
v_fast << " CONFIG[\"srcdir\"] = \"" + File.expand_path($1) + "\"\n"
6666
has_srcdir = true
67-
elsif /^ac_given_INSTALL=(.*)/
67+
elsif /^ac_given_INSTALL=(.*)/ =~ line
6868
v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
6969
end
7070
# break if /^CEOF/

parse.y

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,8 +4387,6 @@ void_stmts(node)
43874387
}
43884388
}
43894389

4390-
static NODE *cond2();
4391-
43924390
static int
43934391
assign_in_cond(node)
43944392
NODE *node;
@@ -4435,65 +4433,79 @@ assign_in_cond(node)
44354433
return 1;
44364434
}
44374435

4436+
static void
4437+
warn_unless_e_option(str)
4438+
const char *str;
4439+
{
4440+
if (strcmp(ruby_sourcefile, "-e") != 0)
4441+
rb_warning(str);
4442+
}
4443+
44384444
static NODE*
4439-
cond0(node, log)
4445+
cond0(node, logop)
44404446
NODE *node;
4441-
int log;
4447+
int logop;
44424448
{
44434449
enum node_type type = nd_type(node);
44444450

44454451
assign_in_cond(node);
44464452
switch (type) {
44474453
case NODE_DSTR:
4448-
if (log) break;
4454+
if (logop) break;
44494455
nd_set_type(node, NODE_DREGX);
44504456
/* fall through */
44514457
case NODE_DREGX:
44524458
case NODE_DREGX_ONCE:
44534459
local_cnt('_');
44544460
local_cnt('~');
4455-
rb_warn("string/regex literal in condition");
4461+
warn_unless_e_option("string/regex literal in condition");
44564462
return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
44574463

44584464
case NODE_DOT2:
44594465
case NODE_DOT3:
4460-
node->nd_beg = cond0(node->nd_beg, log);
4461-
node->nd_end = cond0(node->nd_end, log);
4466+
node->nd_beg = cond0(node->nd_beg, logop);
4467+
node->nd_end = cond0(node->nd_end, logop);
44624468
if (type == NODE_DOT2) nd_set_type(node,NODE_FLIP2);
44634469
else if (type == NODE_DOT3) nd_set_type(node, NODE_FLIP3);
44644470
node->nd_cnt = local_append(0);
4465-
rb_warn("range literal in condition");
4466-
return node;
4471+
warn_unless_e_option("range literal in condition");
4472+
break;
44674473

44684474
case NODE_STR:
4469-
if (log) break;
4475+
if (logop) break;
44704476
node->nd_lit = rb_reg_new(RSTRING(node->nd_lit)->ptr,RSTRING(node->nd_lit)->len,0);
44714477
goto regexp;
44724478

44734479
case NODE_LIT:
4474-
if (TYPE(node->nd_lit) == T_REGEXP) {
4480+
switch (TYPE(node->nd_lit)) {
4481+
case T_REGEXP:
44754482
regexp:
44764483
nd_set_type(node, NODE_MATCH);
44774484
local_cnt('_');
44784485
local_cnt('~');
4479-
rb_warn("string/regex literal in condition");
4480-
return node;
4486+
warn_unless_e_option("string/regex literal in condition");
4487+
break;
4488+
4489+
case T_FIXNUM:
4490+
if (logop) break;
4491+
warn_unless_e_option("integer literal in condition");
4492+
return call_op(node,tEQ,1,NEW_GVAR(rb_intern("$.")));
44814493
}
44824494
}
44834495
return node;
44844496
}
44854497

44864498
static NODE*
4487-
cond1(node, log)
4499+
cond1(node, logop)
44884500
NODE *node;
4489-
int log;
4501+
int logop;
44904502
{
44914503
if (node == 0) return 0;
44924504
if (nd_type(node) == NODE_NEWLINE){
4493-
node->nd_next = cond0(node->nd_next, log);
4505+
node->nd_next = cond0(node->nd_next, logop);
44944506
return node;
44954507
}
4496-
return cond0(node, log);
4508+
return cond0(node, logop);
44974509
}
44984510

44994511
static NODE*

sample/fullpath.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
if path == nil
1010
path = ""
11-
elsif path !~ /\/$/
11+
elsif path !~ %r|/$|
1212
path += "/"
1313
end
1414

15-
while gets()
16-
if /:$/
15+
while line = gets()
16+
case line
17+
when /:$/
1718
path = $_.chop.chop + "/"
18-
elsif /^total/ || /^d/
19-
elsif /^(.*\d )(.+)$/
19+
when /^total/, /^d/
20+
when /^(.*\d )(.+)$/
2021
print($1, path, $2, "\n")
2122
end
2223
end
23-

sample/mkproto.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$/ = nil
2-
while gets()
3-
if /^((void|VALUE|int|char *\*|ID|struct [\w_]+ *\*|st_table *\*) *)?\n([\w\d_]+)\(.*\)\n\s*((.+;\n)*)\{/
2+
while line = gets()
3+
if /^((void|VALUE|int|char *\*|ID|struct [\w_]+ *\*|st_table *\*) *)?\n([\w\d_]+)\(.*\)\n\s*((.+;\n)*)\{/ =~ line
44
$_ = $'
55
printf "%s %s(", $2, $3
66
args = []

sample/test.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,35 @@ def test_ok(cond)
116116
tmp = open("while_tmp", "r")
117117
test_ok(tmp.kind_of?(File))
118118

119-
while tmp.gets()
120-
break if /vt100/
119+
while line = tmp.gets()
120+
break if /vt100/ =~ line
121121
end
122122

123-
test_ok(!tmp.eof? && /vt100/)
123+
test_ok(!tmp.eof? && /vt100/ =~ line)
124124
tmp.close
125125

126126
# test next
127127
$bad = false
128128
tmp = open("while_tmp", "r")
129-
while tmp.gets()
130-
next if /vt100/;
131-
$bad = 1 if /vt100/;
129+
while line = tmp.gets()
130+
next if /vt100/ =~ line
131+
$bad = 1 if /vt100/ =~ line
132132
end
133-
test_ok(!(!tmp.eof? || /vt100/ || $bad))
133+
test_ok(!(!tmp.eof? || /vt100/ =~ line || $bad))
134134
tmp.close
135135

136136
# test redo
137137
$bad = false
138138
tmp = open("while_tmp", "r")
139139
while tmp.gets()
140140
line = $_
141-
$_ = gsub(/vt100/, 'VT100')
141+
gsub(/vt100/, 'VT100')
142142
if $_ != line
143-
gsub!('VT100', 'Vt100')
144-
redo;
143+
$_.gsub!('VT100', 'Vt100')
144+
redo
145145
end
146-
$bad = 1 if /vt100/
147-
$bad = 1 if /VT100/
146+
$bad = 1 if /vt100/ =~ $_
147+
$bad = 1 if /VT100/ =~ $_
148148
end
149149
test_ok(tmp.eof? && !$bad)
150150
tmp.close
@@ -162,11 +162,11 @@ def test_ok(cond)
162162
# test interval
163163
$bad = false
164164
tmp = open("while_tmp", "r")
165-
while tmp.gets()
166-
break unless 1..2
167-
if /vt100/ || /Amiga/ || /paper/
165+
while line = tmp.gets()
166+
break if 3
167+
case line
168+
when /vt100/, /Amiga/, /paper/
168169
$bad = true
169-
break
170170
end
171171
end
172172
test_ok(!$bad)

0 commit comments

Comments
 (0)
0