some more ydecode hacking
This commit is contained in:
parent
ffe0a85311
commit
e1a489354b
1 changed files with 59 additions and 36 deletions
|
|
@ -49,6 +49,7 @@ def initialize(nntpservers, groupname, newsrc="~/.newsrc")
|
|||
del_server(server)
|
||||
end
|
||||
}
|
||||
@ymap = {}
|
||||
end
|
||||
|
||||
def reconnect(server)
|
||||
|
|
@ -693,6 +694,12 @@ end
|
|||
#######################################################################
|
||||
|
||||
def ydecode(data, outfile=nil)
|
||||
if @ymap.empty?
|
||||
(-106..255).each do |b|
|
||||
@ymap[b]=((b-42)%256)
|
||||
end
|
||||
end
|
||||
|
||||
case data.type.to_s
|
||||
when "Array"
|
||||
print "Calling _ydecode_array\n" if Debuglevel>0
|
||||
|
|
@ -710,6 +717,21 @@ def ydecode(data, outfile=nil)
|
|||
return mode, filename, body
|
||||
end
|
||||
|
||||
def _ydecode_line(line)
|
||||
i = 0
|
||||
ll = line.length
|
||||
ostr = ''
|
||||
while i < ll
|
||||
if line[i] == 0x3d
|
||||
i += 1
|
||||
line[i] -= 64
|
||||
end
|
||||
ostr << @ymap[line[i]]
|
||||
i += 1
|
||||
end
|
||||
return ostr, ostr.length
|
||||
end
|
||||
|
||||
def _ydecode_file(file, outfile)
|
||||
mode = 0600
|
||||
filename = "unknown"
|
||||
|
|
@ -718,11 +740,7 @@ def _ydecode_file(file, outfile)
|
|||
bytes = 0
|
||||
total = 0
|
||||
oldpartend = 0
|
||||
|
||||
ymap = {}
|
||||
(-106..255).each do |b|
|
||||
ymap[b]=((b-42)%256)
|
||||
end
|
||||
search_begin = false
|
||||
|
||||
while (! file.eof)
|
||||
line = file.gets
|
||||
|
|
@ -782,13 +800,13 @@ def _ydecode_file(file, outfile)
|
|||
end
|
||||
return mode, filename
|
||||
end
|
||||
search_begin = 1
|
||||
search_begin = true
|
||||
bytes = 0
|
||||
next
|
||||
end
|
||||
if search_begin && line =~ /^\=ybegin\s+(.*)\Z/
|
||||
m = $1
|
||||
search_begin = 0
|
||||
search_begin = false
|
||||
if m =~ /^\s*(part\=(\d+)\s+)?(total\=(\d+)\s+)?(line\=(\d+))(\s*size\=(\d+))(\s*name=(.*))\Z/
|
||||
part = $2.to_i
|
||||
total = $4.to_i
|
||||
|
|
@ -799,7 +817,7 @@ def _ydecode_file(file, outfile)
|
|||
end
|
||||
next
|
||||
end
|
||||
if search_begin == 1
|
||||
if search_begin == true
|
||||
next
|
||||
end
|
||||
if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/
|
||||
|
|
@ -820,19 +838,20 @@ def _ydecode_file(file, outfile)
|
|||
# print "linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||
# end
|
||||
|
||||
i = 0
|
||||
ll = line.length
|
||||
ostr = ''
|
||||
while i < ll
|
||||
if line[i] == 0x3d
|
||||
i += 1
|
||||
line[i] -= 64
|
||||
end
|
||||
ostr << ymap[line[i]]
|
||||
i += 1
|
||||
end
|
||||
# i = 0
|
||||
# ll = line.length
|
||||
# ostr = ''
|
||||
# while i < ll
|
||||
# if line[i] == 0x3d
|
||||
# i += 1
|
||||
# line[i] -= 64
|
||||
# end
|
||||
# ostr << ymap[line[i]]
|
||||
# i += 1
|
||||
# end
|
||||
ostr, ostrl = _ydecode_line(line)
|
||||
outfile << ostr
|
||||
bytes += ostr.length
|
||||
bytes += ostrl
|
||||
end
|
||||
|
||||
print "No \"=yend\" found!!!\n"
|
||||
|
|
@ -846,13 +865,14 @@ def _ydecode_array(data)
|
|||
filename = "unknown"
|
||||
c = 0
|
||||
lines = data.length
|
||||
bytes = 0
|
||||
percent = 0
|
||||
mark = lines/100
|
||||
|
||||
ymap = {}
|
||||
(-106..255).each do |b|
|
||||
ymap[b]=((b-42)%256)
|
||||
end
|
||||
# ymap = {}
|
||||
# (-106..255).each do |b|
|
||||
# ymap[b]=((b-42)%256)
|
||||
# end
|
||||
|
||||
i = 0
|
||||
while (i < data.length)
|
||||
|
|
@ -906,19 +926,22 @@ def _ydecode_array(data)
|
|||
# print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||
# end
|
||||
|
||||
i = 0
|
||||
ll = line.length
|
||||
ostr = ''
|
||||
while i < ll
|
||||
if line[i] == 0x3d
|
||||
i += 1
|
||||
line[i] -= 64
|
||||
end
|
||||
ostr << ymap[line[i]]
|
||||
i += 1
|
||||
end
|
||||
# j = 0
|
||||
# ll = line.length
|
||||
# ostr = ''
|
||||
# while j < ll
|
||||
# if line[j] == 0x3d
|
||||
# j += 1
|
||||
# line[j] -= 64
|
||||
# end
|
||||
# ostr << ymap[line[j]]
|
||||
# j += 1
|
||||
# end
|
||||
# decode << ostr
|
||||
# bytes += ostr.length
|
||||
ostr, ostrl = _ydecode_line(line)
|
||||
decode << ostr
|
||||
bytes += ostr.length
|
||||
bytes += ostrl
|
||||
|
||||
# special = 0
|
||||
# str = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue