Article View: news.software.readers
Article #4368Re: trn & newsrc file getting unreasonable
From: Dana Carson
Date: Fri, 04 Jun 1993 22:14
Date: Fri, 04 Jun 1993 22:14
92 lines
3213 bytes
3213 bytes
Here is a little perl script I wrote that clean you .newsrc without
deleting article numbers of articles that you marked to look at later
unless they have expired off your system. It's a first attempt to write
a perl program rather then a one-liner so it can be improved I'm sure.
It seems to work however and I tested the obvious error conditions, no
directory, no articles, no list etc.
------------------------------------------------------------------------
#!/usr/local/bin/perl
$NEWSDIR = "/usr/spool/news/";
if ($ARGV[0] ) {
open(rcfile,$ARGV[0]) || die "Can't open $ARGV[0]";
}
else {
open(rcfile,".newsrc") || die "Can't open .newsrc";
}
while (<rcfile>) {
($group, $seen) = split;
print $group, " ";
# if we read this group we need to trim expired gaps
# if not an empty list will work
if ($group =~ /:/) {
( $GROUPDIR = $group ) =~ s;\.;/;g ;
$GROUPDIR =~ s;:;/;g ;
if (!opendir(CURDIR, $NEWSDIR . $GROUPDIR)) {
print " \n";
next;
}
@filenames = readdir(CURDIR);
closedir(CURDIR);
#find the ones that are numeric and therefore probably articles
@articles = ();
for (@filenames) {
if(/^\d+$/) {
push(@articles,$_);
}
}
@articles = sort bynumber @articles;
# if there are no articles go on to next group
if (!defined($articles[0])) {
print $seen,"\n";
next;
}
$curlow = $articles[0];
#break up the seen list
@seen = split(/,/,$seen);
while (@seen) {
#find any gaps where the articles have expired
#close up the gaps
if ($seen[0] =~ /-/) {
($clow,$chigh) = split(/-/,$seen[0]);
last if $clow > $curlow;
if ($chigh < $curlow) {
shift(@seen);
next;
}
else {
$curlow = $chigh;
shift(@seen);
last;
}
}
else {
last if $seen[0] > $curlow;
shift(@seen);
}
}
@nlist = "1-".$curlow;
@nlist = (@nlist,@seen);
print join(",",@nlist);
#write out the updated seen list
}
print "\n";
}
sub bynumber {
$a <=> $b;
}
----------------------------------------------------------------------
--
Dana Carson
Westinghouse Electronic Systems Group Mail Stop 1615
net: carson@tron.bwi.wec.com |
...!uunet!tron!carson | This message on recycled bits.
AT&T: (410) 765-3513 |
WIN: 285-3513 |
Technical Details
Message-ID:
<1993Jun4.221433.1052@tron.bwi.wec.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!gatech!swrinde!cs.utexas.edu!uunet!tron!carsonReferences:
<C7JqHq.Mn7@chinet.chinet.com> <1ttj26$9o@adv.win.tue.nl> <1993Jun3.151848.19271@cs.wisc.edu> <C83BCC.A7p@dutiws.twi.tudelft.nl>Show Full Headers
Complete Article Headers
Message-ID: <1993Jun4.221433.1052@tron.bwi.wec.com> Subject: Re: trn & newsrc file getting unreasonable Date: Fri, 4 Jun 1993 22:14:33 GMT From: carson@tron.bwi.wec.com (Dana Carson) References: <C7JqHq.Mn7@chinet.chinet.com> <1ttj26$9o@adv.win.tue.nl> <1993Jun3.151848.19271@cs.wisc.edu> <C83BCC.A7p@dutiws.twi.tudelft.nl> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!gatech!swrinde!cs.utexas.edu!uunet!tron!carson Newsgroups: news.software.readers Summary: a perl clean news that keeps marked articles Keywords: perl newsrc Organization: Westinghouse Electric Corporation Lines: 93