bring some sanity into output_data

This commit is contained in:
Ward Wouts 2003-04-18 21:39:29 +00:00
parent 45257627f3
commit 7c354b7ba7

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.40 2003/03/21 12:51:21 ward Exp $
# $Dwarf: ripnews.rb,v 1.41 2003/04/18 21:06:51 ward Exp $
# $Source$
require 'date'
@ -290,26 +290,23 @@ def output_data(subject, mode, filename="", body="")
group = @articles.get_groupname
print " mode: #{mode}\n" if Debuglevel > 0
print " Filename: '#{filename}'\n" if Debuglevel > 0
# de-crap subject...
subject.sub!(/\s*$/, "")
subject.sub!(/^[\s\.!-]*/, "")
# decide on a filename
if @config[group].has_key?("-L") and @config[group]["-L"]
print "longname\n" if Debuglevel > 1
outfile = subject
while outfile.length > @maxfilelength
outfile = outfile[0...-1]
end
outfile = outfile[0...@maxfilelength]
elsif @config[group].has_key?("-C") and @config[group]["-C"]
print "combinedname\n" if Debuglevel > 1
outfile = outfile[0...@maxfilelength-filename.length-3]
outfile = "#{subject} [#{filename}]"
sub2 = subject
while outfile.length > @maxfilelength
lastlength = outfile.length
sub2 = sub2[0...-1]
outfile = "#{sub2} [#{filename}]" # this is going to loop if the #{filename} is too long :(
if outfile.length == lastlength
if outfile.length > @maxfilelength
outfile = filename
while outfile.length > @maxfilelength
outfile = outfile[0...-1]
end
end
outfile = outfile[0...@maxfilelength]
end
else
print "shortname\n" if Debuglevel > 1
@ -318,6 +315,8 @@ def output_data(subject, mode, filename="", body="")
outfile = outfile[0...-1]
end
end
# do the actual saving
if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body)
@articles.group_update_newsrc(subject)
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
@ -328,20 +327,24 @@ def check_ext(group, filename, mode)
print " filename: #{filename}\n";
case mode
when "s"
######## debuging
print " sould have extension: #{@config[group]["-S"]}\n";
if ( @config[group].has_key?("-S") && filename =~ /\.(#{@config[group]["-S"]})$/ )
print " extension matches\n"
else
print " extension doesn't match\n"
end
######## /debuging
return @config[group].has_key?("-S") ? ( filename =~ /\.(#{@config[group]["-S"]})$/ ) : true
when "m"
######## debuging
print " sould have extension: #{@config[group]["-M"]}\n";
if ( @config[group].has_key?("-S") && filename =~ /\.(#{@config[group]["-M"]})$/ )
print " extension matches\n"
else
print " extension doesn't match\n"
end
######## /debuging
return @config[group].has_key?("-M") ? ( filename =~ /\.(#{@config[group]["-M"]})$/ ) : true
else
print "Illegal mode \"#{mode}\" in check_ext\n"