do part checking in array decode too
This commit is contained in:
parent
b5761f863e
commit
8843a9d9a2
1 changed files with 38 additions and 55 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#################################
|
#################################
|
||||||
#
|
#
|
||||||
# $Dwarf: yenc.rb,v 1.3 2003/04/20 18:31:17 ward Exp $
|
# $Dwarf: yenc.rb,v 1.4 2003/04/20 20:15:34 ward Exp $
|
||||||
# $Source$
|
# $Source$
|
||||||
#
|
#
|
||||||
# article.rb
|
# article.rb
|
||||||
|
|
@ -61,8 +61,10 @@ def _ydecode_file(file, outfile)
|
||||||
file.pos = 0
|
file.pos = 0
|
||||||
bytes = 0
|
bytes = 0
|
||||||
total = 0
|
total = 0
|
||||||
|
oldpartbegin = 0
|
||||||
oldpartend = 0
|
oldpartend = 0
|
||||||
search_begin = false
|
search_begin = false
|
||||||
|
skip = false
|
||||||
|
|
||||||
while (! file.eof)
|
while (! file.eof)
|
||||||
line = file.gets
|
line = file.gets
|
||||||
|
|
@ -143,11 +145,18 @@ def _ydecode_file(file, outfile)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/
|
if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/
|
||||||
|
skip = false
|
||||||
b = $2
|
b = $2
|
||||||
e = $4
|
e = $4
|
||||||
print " next part begin #{b}, end #{e}\n"
|
print " next part begin #{b}, end #{e}\n"
|
||||||
|
if b.to_i == oldpartbegin && e.to_i == oldpartend
|
||||||
|
print "Skipping duplicate part\n"
|
||||||
|
skip = true
|
||||||
|
next
|
||||||
|
end
|
||||||
if b.to_i == oldpartend + 1
|
if b.to_i == oldpartend + 1
|
||||||
oldpartend = e.to_i
|
oldpartend = e.to_i
|
||||||
|
oldpartbegin = b.to_i
|
||||||
else
|
else
|
||||||
raise PermError, "Parts not continuous! last end #{oldpartend}, begin #{b}"
|
raise PermError, "Parts not continuous! last end #{oldpartend}, begin #{b}"
|
||||||
end
|
end
|
||||||
|
|
@ -160,21 +169,12 @@ def _ydecode_file(file, outfile)
|
||||||
# print "linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
# print "linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# i = 0
|
if !skip
|
||||||
# ll = line.length
|
print "line: #{line}" if Debuglevel > 0
|
||||||
# ostr = ''
|
ostr = _ydecode_line(line)
|
||||||
# while i < ll
|
outfile << ostr
|
||||||
# if line[i] == 0x3d
|
bytes += ostr.length
|
||||||
# i += 1
|
end
|
||||||
# line[i] -= 64
|
|
||||||
# end
|
|
||||||
# ostr << ymap[line[i]]
|
|
||||||
# i += 1
|
|
||||||
# end
|
|
||||||
print "line: #{line}" if Debuglevel > 0
|
|
||||||
ostr = _ydecode_line(line)
|
|
||||||
outfile << ostr
|
|
||||||
bytes += ostr.length
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print "No \"=yend\" found!!!\n"
|
print "No \"=yend\" found!!!\n"
|
||||||
|
|
@ -192,11 +192,6 @@ def _ydecode_array(data)
|
||||||
percent = 0
|
percent = 0
|
||||||
mark = lines/100
|
mark = lines/100
|
||||||
|
|
||||||
# ymap = {}
|
|
||||||
# (-106..255).each do |b|
|
|
||||||
# ymap[b]=((b-42)%256)
|
|
||||||
# end
|
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while (i < data.length)
|
while (i < data.length)
|
||||||
if data[i] =~ /^\=ybegin\s+(.*line\=.*)/
|
if data[i] =~ /^\=ybegin\s+(.*line\=.*)/
|
||||||
|
|
@ -238,8 +233,22 @@ def _ydecode_array(data)
|
||||||
dec = [ decode ]
|
dec = [ decode ]
|
||||||
return mode, filename, dec
|
return mode, filename, dec
|
||||||
end
|
end
|
||||||
if line =~ /^\=ypart.*\Z/
|
if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/
|
||||||
# ignore for now
|
skip = false
|
||||||
|
b = $2
|
||||||
|
e = $4
|
||||||
|
print " next part begin #{b}, end #{e}\n"
|
||||||
|
if b.to_i == oldpartbegin && e.to_i == oldpartend
|
||||||
|
print "Skipping duplicate part\n"
|
||||||
|
skip = true
|
||||||
|
next
|
||||||
|
end
|
||||||
|
if b.to_i == oldpartend + 1
|
||||||
|
oldpartend = e.to_i
|
||||||
|
oldpartbegin = b.to_i
|
||||||
|
else
|
||||||
|
raise PermError, "Parts not continuous! last end #{oldpartend}, begin #{b}"
|
||||||
|
end
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -249,38 +258,12 @@ def _ydecode_array(data)
|
||||||
# print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
# print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n"
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# j = 0
|
if !skip
|
||||||
# ll = line.length
|
print "line: #{line}" if Debuglevel > 0
|
||||||
# ostr = ''
|
ostr = _ydecode_line(line)
|
||||||
# while j < ll
|
decode << ostr
|
||||||
# if line[j] == 0x3d
|
bytes += ostr.length
|
||||||
# j += 1
|
end
|
||||||
# line[j] -= 64
|
|
||||||
# end
|
|
||||||
# ostr << ymap[line[j]]
|
|
||||||
# j += 1
|
|
||||||
# end
|
|
||||||
# decode << ostr
|
|
||||||
# bytes += ostr.length
|
|
||||||
ostr = _ydecode_line(line)
|
|
||||||
decode << ostr
|
|
||||||
bytes += ostr.length
|
|
||||||
|
|
||||||
# special = 0
|
|
||||||
# str = ""
|
|
||||||
# line.each_byte { |b|
|
|
||||||
# if special == 0
|
|
||||||
# if b == 0x3d
|
|
||||||
# special = 1
|
|
||||||
# next
|
|
||||||
# end
|
|
||||||
# else
|
|
||||||
# special = 0
|
|
||||||
# b = (b - 64) % 256
|
|
||||||
# end
|
|
||||||
# str << ((b - 42) % 256).chr
|
|
||||||
# }
|
|
||||||
# decode << str
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print "${i}: no \"=yend\" found!!!\n"
|
print "${i}: no \"=yend\" found!!!\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue