bug fixes
This commit is contained in:
parent
e93ed788bd
commit
27722e94bc
1 changed files with 38 additions and 51 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#################################
|
#################################
|
||||||
#
|
#
|
||||||
# $Dwarf: yenc.rb,v 1.1 2003/04/18 22:53:25 ward Exp $
|
# $Dwarf: yenc.rb,v 1.2 2003/04/20 16:33:31 ward Exp $
|
||||||
# $Source$
|
# $Source$
|
||||||
#
|
#
|
||||||
# article.rb
|
# article.rb
|
||||||
|
|
@ -11,15 +11,15 @@
|
||||||
|
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
|
||||||
class yEnc
|
class YEnc
|
||||||
|
class << self
|
||||||
|
|
||||||
Debuglevel = 0
|
Debuglevel = 0
|
||||||
|
|
||||||
def ydecode(data, outfile=nil)
|
def ydecode(data, outfile=nil)
|
||||||
if @ymap.empty?
|
@ymap = {}
|
||||||
(-106..255).each do |b|
|
(-106..255).each do |b|
|
||||||
@ymap[b]=((b-42)%256)
|
@ymap[b]=((b-42)%256)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
case data.type.to_s
|
case data.type.to_s
|
||||||
|
|
@ -51,11 +51,11 @@ def _ydecode_line(line)
|
||||||
ostr << @ymap[line[i]]
|
ostr << @ymap[line[i]]
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
return ostr, ostr.length
|
return ostr
|
||||||
end
|
end
|
||||||
|
|
||||||
def _ydecode_file(file, outfile)
|
def _ydecode_file(file, outfile)
|
||||||
mode = 0600
|
mode = 0600 # mode is a bit stupid with yencoding... it don't get it
|
||||||
filename = "unknown"
|
filename = "unknown"
|
||||||
lines = file.pos
|
lines = file.pos
|
||||||
file.pos = 0
|
file.pos = 0
|
||||||
|
|
@ -70,20 +70,22 @@ def _ydecode_file(file, outfile)
|
||||||
if line =~ /^\=ybegin\s+(.*line\=.*)/
|
if line =~ /^\=ybegin\s+(.*line\=.*)/
|
||||||
m = $1
|
m = $1
|
||||||
print "ybegin match; rest: #{m}\n" if Debuglevel > 0
|
print "ybegin match; rest: #{m}\n" if Debuglevel > 0
|
||||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*))\Z/
|
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
|
||||||
totalsize = $8.to_i
|
totalsize = $8.to_i
|
||||||
filename = $10
|
filename = $10
|
||||||
print "found beginning"
|
if Debuglevel > 0
|
||||||
if part != nil
|
print "found beginning"
|
||||||
print " of part #{part}"
|
if part != nil
|
||||||
|
print " of part #{part}"
|
||||||
|
end
|
||||||
|
if total != nil
|
||||||
|
print " of #{total}"
|
||||||
|
end
|
||||||
|
print ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n"
|
||||||
end
|
end
|
||||||
if total != nil
|
|
||||||
print " of #{total}"
|
|
||||||
end
|
|
||||||
print ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n"
|
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
print "not a valid yenc begin line\n"
|
print "not a valid yenc begin line\n"
|
||||||
|
|
@ -96,8 +98,6 @@ def _ydecode_file(file, outfile)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
print " ydecoding...\n"
|
|
||||||
|
|
||||||
while (! file.eof)
|
while (! file.eof)
|
||||||
print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1
|
print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1
|
||||||
line = file.gets
|
line = file.gets
|
||||||
|
|
@ -129,7 +129,7 @@ def _ydecode_file(file, outfile)
|
||||||
if search_begin && line =~ /^\=ybegin\s+(.*)\Z/
|
if search_begin && line =~ /^\=ybegin\s+(.*)\Z/
|
||||||
m = $1
|
m = $1
|
||||||
search_begin = false
|
search_begin = false
|
||||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*))\Z/
|
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
|
||||||
|
|
@ -171,9 +171,10 @@ def _ydecode_file(file, outfile)
|
||||||
# ostr << ymap[line[i]]
|
# ostr << ymap[line[i]]
|
||||||
# i += 1
|
# i += 1
|
||||||
# end
|
# end
|
||||||
ostr, ostrl = _ydecode_line(line)
|
print "line: #{line}" if Debuglevel > 0
|
||||||
|
ostr = _ydecode_line(line)
|
||||||
outfile << ostr
|
outfile << ostr
|
||||||
bytes += ostrl
|
bytes += ostr.length
|
||||||
end
|
end
|
||||||
|
|
||||||
print "No \"=yend\" found!!!\n"
|
print "No \"=yend\" found!!!\n"
|
||||||
|
|
@ -201,7 +202,7 @@ def _ydecode_array(data)
|
||||||
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
|
print "ybegin match; rest: #{m}\n" if Debuglevel > 0
|
||||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*))\Z/
|
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
|
||||||
|
|
@ -222,11 +223,11 @@ def _ydecode_array(data)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
print "ydecoding...\n"
|
|
||||||
|
|
||||||
while (i < data.length)
|
while (i < data.length)
|
||||||
print "at #{i} need to go to #{data.length}\r" if Debuglevel > 1
|
|
||||||
line = data[i]
|
line = data[i]
|
||||||
|
line.chop!
|
||||||
|
print "at #{i} need to go to #{data.length}\n" if Debuglevel > 1
|
||||||
|
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
|
||||||
|
|
@ -261,9 +262,9 @@ def _ydecode_array(data)
|
||||||
# end
|
# end
|
||||||
# decode << ostr
|
# decode << ostr
|
||||||
# bytes += ostr.length
|
# bytes += ostr.length
|
||||||
ostr, ostrl = _ydecode_line(line)
|
ostr = _ydecode_line(line)
|
||||||
decode << ostr
|
decode << ostr
|
||||||
bytes += ostrl
|
bytes += ostr.length
|
||||||
|
|
||||||
# special = 0
|
# special = 0
|
||||||
# str = ""
|
# str = ""
|
||||||
|
|
@ -287,35 +288,21 @@ def _ydecode_array(data)
|
||||||
return mode, filename, dec
|
return mode, filename, dec
|
||||||
end
|
end
|
||||||
|
|
||||||
def ydecode_group(subj, tempdir=nil)
|
|
||||||
group_subjects unless @grouped
|
|
||||||
|
|
||||||
body = get_group_body_first(subj)
|
|
||||||
if body.to_s =~ /=ybegin/
|
|
||||||
print "yencoded!\n" if Debuglevel > 0
|
|
||||||
#if (file and outfile)
|
|
||||||
if (tempdir != nil)
|
|
||||||
file = Tempfile.new("#{tempdir}/riptmp")
|
|
||||||
body.collect{|i| file.print "#{i}\n"}
|
|
||||||
get_group_body_rest(subj, file)
|
|
||||||
mode, filename, result = ydecode(file, outfile)
|
|
||||||
else
|
|
||||||
body.concat(get_group_body_rest(subj))
|
|
||||||
mode, filename, result = ydecode(body)
|
|
||||||
end
|
|
||||||
return mode, filename, result
|
|
||||||
else
|
|
||||||
print "Not yencoded!\n" if Debuglevel > 0
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_yencoded(data)
|
def is_yencoded(data)
|
||||||
if data.to_s =~ /=ybegin/
|
if data.to_s =~ /=ybegin/m
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_filename(data)
|
||||||
|
if data.to_s =~ /=ybegin\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*?\S))\s*$/m
|
||||||
|
return $10
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end # class
|
end # class
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue