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