add bsd license

This commit is contained in:
Ward Wouts 2003-07-20 20:32:24 +00:00
parent dfd4648b01
commit d62c5c33e5
6 changed files with 130 additions and 33 deletions

View file

@ -1,14 +1,21 @@
#################################
#
# $Dwarf: newsrc.rb,v 1.10 2002/08/01 11:50:09 ward Exp $
# $Dwarf: newsrc.rb,v 1.11 2002/11/05 09:33:41 ward Exp $
# $Source$
#
# newsrc.rb
# ported from Perl code by Ward Wouts
# Copyright (c) 2002, 2003 Ward Wouts <ward@wouts.nl>
#
# (C) 2001, Ward Wouts
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#################################
require "set/intspan"
@ -78,6 +85,7 @@ def save
save_as(@newsrc["file"])
end
# this is not thread safe!
def save_as(file)
if FileTest.exists?("#{file}")
begin
@ -100,6 +108,46 @@ def save_as(file)
newsrc.close
end
def save_group(group)
unless @newsrc.has_key?("file")
@newsrc["file"] = "#{$ENV['HOME']}/.newsrc"
end
save_as(@newsrc["file"], group)
end
# this should be thread safe
def save_group_as(file, group)
if FileTest.exists?("#{file}")
if ( ! File.copy(file, "#{file}.bak") )
print "Can't copy #{file} to #{file}.bak: #{$!}\n"
end
end
begin
newsrc = File.new(file, "r+").flock(File::LOCK_EX)
rescue
print "Can't open ${file}: #{$!}\n"
exit
end
# read file
lines = newsrc.readlines
# pointer -> 0
newsrc.rewind
# write read stuff & replace group
for line in lines
if line =~ /^#{group}(:|!)/
newsrc.print line
else
newsrc.print format(group)
end
end
newsrc.flock(File::LOCK_UN) # what's the right order here?
newsrc.close
end
def format(group)
name = group["name"]
sub = group["subscribed"] ? ':' : '!'
@ -383,6 +431,8 @@ end # module
# [x] parse # parses a single line from a newsrc file
# [x] save
# [x] save_as
# [ ] save_group
# [ ] save_group_as
# [x] format
# [x] export_rc
# [ ] _dump # Formats a Newsrc object to a string. Used for testing