Article View: news.software.readers
Article #5033Re: .newsrc Cleanup Program Sought
From: Dana Carson
Date: Thu, 22 Jul 1993 22:00
Date: Thu, 22 Jul 1993 22:00
125 lines
4046 bytes
4046 bytes
In article <22g7un$4f4@amhux3.amherst.edu> twpierce@unix.amherst.edu (Tim Pierce) writes:
>In article <1993Jul19.234609.2029@scic.intel.com>
>sbradley@scic.intel.com (Seth J. Bradley) writes:
>
>>A while back, someone posted a .newsrc cleanup program - I believe it was
>>a Perl script.
>
>This is the one I use. I think Peter da Silva contributed the regexp
>magic. A clever sed hacker could probably use the contents of the
>"while" loop to rewrite this in sed, too.
>
>#!/usr/local/bin/perl
>$HOME = $ENV{HOME};
>$NEWSRC = "$HOME/.newsrc";
>$TMP = "$HOME/.tmpnewsrc";
>
>open (TMP, ">$TMP");
>open (NEWSRC);
>
>while (<NEWSRC>) {
> s/[-,][-,0-9]*[-,]/-/ if /!/;
> print TMP $_;
>}
>
>rename ($NEWSRC, "$HOME/.oldnewsrc");
>rename ($TMP, $NEWSRC);
That is short and fast but has the problem, at least in my mind that
it will compress out marked articles. I may read news differently from
many people but if I M an article I don't want the cleanup to mark ir as
read for me. This is my news cleaning perl script. It just deletes
totally the article string for unread groups since I'll need to do a
catchup if start reading them anyway.
I also was a little paranoid checking for errors, the question with
computers isn't should you be paranoid, but are you paranoid enough.
For this reason it writes the new .newsrc to stdout so you can save it
and do the rename yourself.
-------------------------------------------------------------------------------
#!/usr/local/bin/perl -w
$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:
<1993Jul22.220039.20824@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!math.ohio-state.edu!cs.utexas.edu!uunet!tron!carsonReferences:
<1993Jul19.234609.2029@scic.intel.com> <22g7un$4f4@amhux3.amherst.edu>Show Full Headers
Complete Article Headers
Message-ID: <1993Jul22.220039.20824@tron.bwi.wec.com> Subject: Re: .newsrc Cleanup Program Sought Date: Thu, 22 Jul 1993 22:00:39 GMT From: carson@tron.bwi.wec.com (Dana Carson) References: <1993Jul19.234609.2029@scic.intel.com> <22g7un$4f4@amhux3.amherst.edu> 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!math.ohio-state.edu!cs.utexas.edu!uunet!tron!carson Newsgroups: news.software.readers Organization: Westinghouse Electric Corporation Lines: 126