P format - ruby bug? - dumb program?

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
}
}


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

Hi,

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

···

At Wed, 13 Aug 2003 03:10:11 +0900, KONTRA Gergely wrote:


Nobu Nakada

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

···

On 0813, KONTRA Gergely wrote:

±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

Hi,

···

At Thu, 21 Aug 2003 21:09:28 +0900, KONTRA Gergely wrote:

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.


Nobu Nakada