From 8843a9d9a2fd9e7818568e7ecb3ee1b17bd704d8 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Sun, 20 Apr 2003 21:31:12 +0000 Subject: [PATCH] do part checking in array decode too --- trunk/ripnews/encode/yenc.rb | 93 +++++++++++++++--------------------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/trunk/ripnews/encode/yenc.rb b/trunk/ripnews/encode/yenc.rb index d42329d..ed92222 100644 --- a/trunk/ripnews/encode/yenc.rb +++ b/trunk/ripnews/encode/yenc.rb @@ -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$ # # article.rb @@ -61,8 +61,10 @@ def _ydecode_file(file, outfile) file.pos = 0 bytes = 0 total = 0 + oldpartbegin = 0 oldpartend = 0 search_begin = false + skip = false while (! file.eof) line = file.gets @@ -143,11 +145,18 @@ def _ydecode_file(file, outfile) next end if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/ + 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 @@ -160,21 +169,12 @@ 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 - print "line: #{line}" if Debuglevel > 0 - ostr = _ydecode_line(line) - outfile << ostr - bytes += ostr.length + if !skip + print "line: #{line}" if Debuglevel > 0 + ostr = _ydecode_line(line) + outfile << ostr + bytes += ostr.length + end end print "No \"=yend\" found!!!\n" @@ -192,11 +192,6 @@ def _ydecode_array(data) percent = 0 mark = lines/100 -# ymap = {} -# (-106..255).each do |b| -# ymap[b]=((b-42)%256) -# end - i = 0 while (i < data.length) if data[i] =~ /^\=ybegin\s+(.*line\=.*)/ @@ -238,8 +233,22 @@ def _ydecode_array(data) dec = [ decode ] return mode, filename, dec end - if line =~ /^\=ypart.*\Z/ - # ignore for now + if line =~ /^=ypart\s+(\s*begin=(\d+))(\s+end=(\d+))/ + 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 end @@ -249,38 +258,12 @@ def _ydecode_array(data) # print "#{i}: linesize mismatch, was #{line.length}, should be #{linesize}...\n" # 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 = _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 + if !skip + print "line: #{line}" if Debuglevel > 0 + ostr = _ydecode_line(line) + decode << ostr + bytes += ostr.length + end end print "${i}: no \"=yend\" found!!!\n"