p format - ruby bug? - dumb program?

K

KONTRA Gergely

Hi!

Can I specify how strings are printed, when using the p function?
I mean with ' or with " ?

---
During running a little program, which detects files with the same
content, I get a ruby bug:
processing dir c:\WINDOWS\SYSTEM\VMM32
processing dir c:\WINDOWS\SYSTEM\CatRoot
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}
processing dir
c:\WINDOWS\SYSTEM\CatRoot\{127D0A1D-4EF2-11D1-8608-00C04FC295EE}
processing dir c:\WINDOWS\SYSTEM\sfp
processing dir c:\WINDOWS\SYSTEM\sfp\tempcats
processing dir c:\WINDOWS\SYSTEM\DirectX
processing dir c:\WINDOWS\SYSTEM\DirectX\Migrate
processing dir c:\WINDOWS\SYSTEM\DirectX\Dinput
processing dir c:\WINDOWS\SYSTEM\Drivers
Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
c:\WINDOWS\SYSTEM
\DirectX\Migrate\vjoyd.vxd
same.rb:4: [BUG] rb_sys_fail() - errno == 0
ruby 1.8.0 (2003-08-04) [i386-mingw32]


abnormal program termination

It is a self-compiled ruby.

The program follows: BTW: can anybody simplify it, or make it clearer.
It seems to work, but I think it can be written more compact...
(I wrote it in python (I don't know python, I just tried it), and the
outputs are different.)
============================================================
$files=Hash.new { [] } # {theSize=>[[fn1,fn2],[fn3]]} fn1 and fn2 have same content

def equalFiles? fn1, fn2
f1=File.open fn1,'r'
f2=File.open fn2,'r'
while chunk1=f1.read(512)
chunk2=f2.read(512)
return false if chunk1!=chunk2
end
return true
end

def processDir(dir='.')
$stderr.print "processing dir #{dir}\n"
Dir.foreach(dir) {|f|
begin
next if f=='.' or f=='..'
fn=dir+'\\'+f
if File.directory? fn
fnprocessDir fn
else
elsesize=File.size fn
fnif
fnif ($files[size]).each{|fn2| # process each segment
segment if equalFiles? fn,fn2[0]
fn2 #fn2.replace fn2.push(fn)
fn fn2<<=fn
fn break nil
nil end
end }
end $files[size]<<=[fn]
fnend
end
rescue
$stderr.print "Ooops #{fn}: #$!\n"
end
}
end

processDir ARGV[0]
puts '='*60
$files.sort.each {|h|
size,arr_size=h
arr_size.each {|segment|
if segment.size>1
print "#{size} -> "
p segment
end
}
}
============================================================
 
N

nobu.nokada

Hi,

At Wed, 13 Aug 2003 03:10:11 +0900,
KONTRA said:
Can I specify how strings are printed, when using the p function?
I mean with ' or with " ?

It is hard coded in String#inspect method, so you have to
override it.

class String
alias __inspect_orig__ inspect
def inspect
s = __inspect_orig__()
s.sub!(/'/, "\\\\'")
s.sub!(/\\"/, '"')
s.gsub!(/(\A"|"\z)/, "'")
end
end
 
K

KONTRA Gergely

Hi!

Can I specify how strings are printed, when using the p function?
I mean with ' or with " ?

---
During running a little program, which detects files with the same
content, I get a ruby bug: [...]
processing dir c:\WINDOWS\SYSTEM\Drivers
Ooops c:\WINDOWS\SYSTEM\VJOYD.VXD: No such file or directory -
c:\WINDOWS\SYSTEM
\DirectX\Migrate\vjoyd.vxd
same.rb:4: [BUG] rb_sys_fail() - errno == 0
ruby 1.8.0 (2003-08-04) [i386-mingw32]


abnormal program termination

code snippet:
def equalFiles? fn1, fn2
f1=File.open fn1,'r'
f2=File.open fn2,'r'
while chunk1=f1.read(512)
chunk2=f2.read(512)
return false if chunk1!=chunk2
end
return true
end

The problem was: files are opened, but none of them are closed
explicitly. The ruby output is a bit misleading. Can it be improved?

Gergo
 
N

nobu.nokada

Hi,

At Thu, 21 Aug 2003 21:09:28 +0900,
KONTRA said:
The problem was: files are opened, but none of them are closed
explicitly. The ruby output is a bit misleading. Can it be improved?

Seems to be due to msvcrt.dll's bug. Usa reported 6.00.8397.0
has no such problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top