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$
|
||||
#
|
||||
# article.rb
|
||||
|
|
@ -11,15 +11,15 @@
|
|||
|
||||
require 'tempfile'
|
||||
|
||||
class yEnc
|
||||
class YEnc
|
||||
class << self
|
||||
|
||||
Debuglevel = 0
|
||||
|
||||
def ydecode(data, outfile=nil)
|
||||
if @ymap.empty?
|
||||
(-106..255).each do |b|
|
||||
@ymap[b]=((b-42)%256)
|
||||
end
|
||||
@ymap = {}
|
||||
(-106..255).each do |b|
|
||||
@ymap[b]=((b-42)%256)
|
||||
end
|
||||
|
||||
case data.type.to_s
|
||||
|
|
@ -51,11 +51,11 @@ def _ydecode_line(line)
|
|||
ostr << @ymap[line[i]]
|
||||
i += 1
|
||||
end
|
||||
return ostr, ostr.length
|
||||
return ostr
|
||||
end
|
||||
|
||||
def _ydecode_file(file, outfile)
|
||||
mode = 0600
|
||||
mode = 0600 # mode is a bit stupid with yencoding... it don't get it
|
||||
filename = "unknown"
|
||||
lines = file.pos
|
||||
file.pos = 0
|
||||
|
|
@ -70,20 +70,22 @@ def _ydecode_file(file, outfile)
|
|||
if line =~ /^\=ybegin\s+(.*line\=.*)/
|
||||
m = $1
|
||||
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
|
||||
total = $4.to_i
|
||||
linesize = $6.to_i
|
||||
totalsize = $8.to_i
|
||||
filename = $10
|
||||
print "found beginning"
|
||||
if part != nil
|
||||
print " of part #{part}"
|
||||
if Debuglevel > 0
|
||||
print "found beginning"
|
||||
if part != nil
|
||||
print " of part #{part}"
|
||||
end
|
||||
if total != nil
|
||||
print " of #{total}"
|
||||
end
|
||||
print ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n"
|
||||
end
|
||||
if total != nil
|
||||
print " of #{total}"
|
||||
end
|
||||
print ", linesize = #{linesize}, size = #{totalsize}, filename = #{filename}\n"
|
||||
break
|
||||
else
|
||||
print "not a valid yenc begin line\n"
|
||||
|
|
@ -96,8 +98,6 @@ def _ydecode_file(file, outfile)
|
|||
return false
|
||||
end
|
||||
|
||||
print " ydecoding...\n"
|
||||
|
||||
while (! file.eof)
|
||||
print "at #{file.pos} need to go to #{lines}\n" if Debuglevel > 1
|
||||
line = file.gets
|
||||
|
|
@ -129,7 +129,7 @@ def _ydecode_file(file, outfile)
|
|||
if search_begin && line =~ /^\=ybegin\s+(.*)\Z/
|
||||
m = $1
|
||||
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
|
||||
total = $4.to_i
|
||||
linesize = $6.to_i
|
||||
|
|
@ -171,9 +171,10 @@ def _ydecode_file(file, outfile)
|
|||
# ostr << ymap[line[i]]
|
||||
# i += 1
|
||||
# end
|
||||
ostr, ostrl = _ydecode_line(line)
|
||||
print "line: #{line}" if Debuglevel > 0
|
||||
ostr = _ydecode_line(line)
|
||||
outfile << ostr
|
||||
bytes += ostrl
|
||||
bytes += ostr.length
|
||||
end
|
||||
|
||||
print "No \"=yend\" found!!!\n"
|
||||
|
|
@ -201,7 +202,7 @@ def _ydecode_array(data)
|
|||
if data[i] =~ /^\=ybegin\s+(.*line\=.*)/
|
||||
m = $1
|
||||
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
|
||||
total = $4.to_i
|
||||
linesize = $6.to_i
|
||||
|
|
@ -222,11 +223,11 @@ def _ydecode_array(data)
|
|||
return false
|
||||
end
|
||||
|
||||
print "ydecoding...\n"
|
||||
|
||||
while (i < data.length)
|
||||
print "at #{i} need to go to #{data.length}\r" if Debuglevel > 1
|
||||
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
|
||||
if line =~ /^\=yend(\s+size=(\d+))(\s+crc32=(\S+))?/
|
||||
size = $2.to_i
|
||||
|
|
@ -261,9 +262,9 @@ def _ydecode_array(data)
|
|||
# end
|
||||
# decode << ostr
|
||||
# bytes += ostr.length
|
||||
ostr, ostrl = _ydecode_line(line)
|
||||
ostr = _ydecode_line(line)
|
||||
decode << ostr
|
||||
bytes += ostrl
|
||||
bytes += ostr.length
|
||||
|
||||
# special = 0
|
||||
# str = ""
|
||||
|
|
@ -287,35 +288,21 @@ def _ydecode_array(data)
|
|||
return mode, filename, dec
|
||||
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)
|
||||
if data.to_s =~ /=ybegin/
|
||||
if data.to_s =~ /=ybegin/m
|
||||
return true
|
||||
else
|
||||
return false
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue