rubyfy
This commit is contained in:
parent
beeeefe317
commit
0c2d69676e
1 changed files with 26 additions and 26 deletions
|
|
@ -36,17 +36,17 @@ def ydecode(data, outfile=nil)
|
|||
|
||||
case data.class.to_s
|
||||
when "Array"
|
||||
print "Calling _ydecode_array\n" if Debuglevel>0
|
||||
puts "Calling _ydecode_array" if Debuglevel>0
|
||||
mode, filename, body = _ydecode_array(data)
|
||||
when "File", "Tempfile"
|
||||
unless outfile
|
||||
print "ydecode: need outfile\n"
|
||||
puts "ydecode: need outfile"
|
||||
exit
|
||||
end
|
||||
print "Calling _ydecode_file\n" if Debuglevel>0
|
||||
puts "Calling _ydecode_file" if Debuglevel>0
|
||||
mode, filename, body = _ydecode_file(data, outfile)
|
||||
else
|
||||
print "Funny stuff in ydecode. Data of class \"#{data.class.to_s}\"\n"
|
||||
puts "Funny stuff in ydecode. Data of class \"#{data.class.to_s}\""
|
||||
end
|
||||
return mode, filename, body
|
||||
end
|
||||
|
|
@ -92,7 +92,7 @@ def _ydecode_file(file, outfile)
|
|||
print "line: #{line}" if Debuglevel > 0
|
||||
if line =~ /^\=ybegin\s+(.*line\=.*)/
|
||||
m = $1
|
||||
print "ybegin match; rest: #{m}\n" if Debuglevel > 0
|
||||
puts "ybegin match; rest: #{m}" if Debuglevel > 0
|
||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*?\S))\s*$/
|
||||
part = $2.to_i
|
||||
total = $4.to_i
|
||||
|
|
@ -107,22 +107,22 @@ def _ydecode_file(file, outfile)
|
|||
if total != nil
|
||||
print " of #{total}"
|
||||
end
|
||||
print ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n"
|
||||
puts ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}"
|
||||
end
|
||||
break
|
||||
else
|
||||
print "not a valid yenc begin line\n"
|
||||
puts "not a valid yenc begin line"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if file.eof
|
||||
print "Not yencoded!\n"
|
||||
puts "Not yencoded!"
|
||||
return false
|
||||
end
|
||||
|
||||
while (! file.eof)
|
||||
print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1
|
||||
puts "at #{file.pos} need to go to #{lines}" if Debuglevel > 1
|
||||
line = file.gets
|
||||
line.chop!
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ def _ydecode_file(file, outfile)
|
|||
part = $4.to_i
|
||||
crc = $6
|
||||
if size != bytes
|
||||
print "#{Thread.current.inspect} part size mismatch, is #{bytes}, should be #{size}\n"
|
||||
puts "#{Thread.current.inspect} part size mismatch, is #{bytes}, should be #{size}"
|
||||
end
|
||||
if part == nil
|
||||
return mode, filename
|
||||
|
|
@ -141,7 +141,7 @@ def _ydecode_file(file, outfile)
|
|||
total += bytes
|
||||
if total >= totalsize
|
||||
if total != totalsize
|
||||
print "#{Thread.current.inspect} total size mismatch, is #{total}, should be #{totalsize}\n"
|
||||
puts "#{Thread.current.inspect} total size mismatch, is #{total}, should be #{totalsize}"
|
||||
end
|
||||
return mode, filename
|
||||
end
|
||||
|
|
@ -158,7 +158,7 @@ def _ydecode_file(file, outfile)
|
|||
linesize = $6.to_i
|
||||
totalsize = $8.to_i
|
||||
filename = $10
|
||||
print "found beginning of part #{part}, linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n" if Debuglevel > 0
|
||||
puts "found beginning of part #{part}, linesize = #{linesize}, size = #{totalsize}, filename = #{filename}" if Debuglevel > 0
|
||||
end
|
||||
next
|
||||
end
|
||||
|
|
@ -169,9 +169,9 @@ def _ydecode_file(file, outfile)
|
|||
skip = false
|
||||
b = $2
|
||||
e = $4
|
||||
print " #{Thread.current.inspect} next part begin #{b}, end #{e}\n"
|
||||
puts " #{Thread.current.inspect} next part begin #{b}, end #{e}"
|
||||
if b.to_i == oldpartbegin && e.to_i == oldpartend
|
||||
print "Skipping duplicate part\n"
|
||||
puts "Skipping duplicate part"
|
||||
skip = true
|
||||
next
|
||||
end
|
||||
|
|
@ -187,7 +187,7 @@ def _ydecode_file(file, outfile)
|
|||
# This seems to be a common 'error' - maybe I misunderstand the spec or
|
||||
# something
|
||||
# if line.length != linesize
|
||||
# print "linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||
# puts "linesize mismatch, was #{line.length}, should be #{linesize}..."
|
||||
# end
|
||||
|
||||
if !skip
|
||||
|
|
@ -198,7 +198,7 @@ def _ydecode_file(file, outfile)
|
|||
end
|
||||
end
|
||||
|
||||
print "No \"=yend\" found!!!\n"
|
||||
puts "No \"=yend\" found!!!"
|
||||
return mode, filename, outfile
|
||||
end
|
||||
|
||||
|
|
@ -218,25 +218,25 @@ def _ydecode_array(data)
|
|||
while (i < data.length)
|
||||
if data[i] =~ /^\=ybegin\s+(.*line\=.*)/
|
||||
m = $1
|
||||
print "ybegin match; rest: #{m}\n" if Debuglevel > 0
|
||||
puts "ybegin match; rest: #{m}" if Debuglevel > 0
|
||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*?\S))\s*$/
|
||||
part = $2.to_i
|
||||
total = $4.to_i
|
||||
linesize = $6.to_i
|
||||
size = $8.to_i
|
||||
filename = $10
|
||||
print "found beginning, linesize = #{linesize}, size = #{size}, filename = #{filename}\n" if Debuglevel > 0
|
||||
puts "found beginning, linesize = #{linesize}, size = #{size}, filename = #{filename}" if Debuglevel > 0
|
||||
i += 1
|
||||
break
|
||||
else
|
||||
print "not a valid yenc begin line\n"
|
||||
puts "not a valid yenc begin line"
|
||||
end
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
||||
unless (i < data.length)
|
||||
print "Not yencoded!\n"
|
||||
puts "Not yencoded!"
|
||||
return false
|
||||
end
|
||||
|
||||
|
|
@ -244,14 +244,14 @@ def _ydecode_array(data)
|
|||
line = data[i]
|
||||
line.chomp!("\n")
|
||||
line.chomp!("\r")
|
||||
print "at #{i} need to go to #{data.length}\n" if Debuglevel > 1
|
||||
puts "at #{i} need to go to #{data.length}" if Debuglevel > 1
|
||||
print "line: #{line}" if Debuglevel > 0
|
||||
i += 1
|
||||
if line =~ /^\=yend(\s+size=(\d+))(\s+crc32=(\S+))?/
|
||||
size = $2.to_i
|
||||
crc = $4
|
||||
if size != decode.length
|
||||
print "#{Thread.current.inspect} size mismatch, was #{decode.length}, should be #{size}\n"
|
||||
puts "#{Thread.current.inspect} size mismatch, was #{decode.length}, should be #{size}"
|
||||
end
|
||||
dec = [ decode ]
|
||||
return mode, filename, dec
|
||||
|
|
@ -260,9 +260,9 @@ def _ydecode_array(data)
|
|||
skip = false
|
||||
b = $2
|
||||
e = $4
|
||||
print " #{Thread.current.inspect} next part begin #{b}, end #{e}\n"
|
||||
puts " #{Thread.current.inspect} next part begin #{b}, end #{e}"
|
||||
if b.to_i == oldpartbegin && e.to_i == oldpartend
|
||||
print "Skipping duplicate part\n"
|
||||
puts "Skipping duplicate part"
|
||||
skip = true
|
||||
next
|
||||
end
|
||||
|
|
@ -278,7 +278,7 @@ def _ydecode_array(data)
|
|||
# This seems to be a common 'error' - maybe I misunderstand the spec or
|
||||
# something
|
||||
# if line.length != linesize
|
||||
# print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||
# puts "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}..."
|
||||
# end
|
||||
|
||||
if !skip
|
||||
|
|
@ -289,7 +289,7 @@ def _ydecode_array(data)
|
|||
end
|
||||
end
|
||||
|
||||
print "${i}: no \"=yend\" found!!!\n"
|
||||
puts "${i}: no \"=yend\" found!!!"
|
||||
dec = [ decode ]
|
||||
return mode, filename, dec
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue