🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #12872

Re: Looking for tool to clean up newsrc file

#12872
From: Dana Carson
Date: Wed, 16 Nov 1994 23:44
89 lines
2970 bytes
   Here is a perl script that does pretty much what you want.  Like you
I wasn't happy with losing the fact that I'd marked articles to come
back to.  Hope this helps.  You may need to customize $NEWSDIR
everything else I think is OK.
--cut here-------------------------------------------------------------
#!/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;
}

--cut here-------------------------------------------------------------
--
Dana Carson
Westinghouse Electronic Systems Group  Mail Stop 1615
net: carson@tron.bwi.wec.com     | This message on recycled bits.
AT&T: (410) 765-3513             |
WIN:  285-3513                   |
Technical Details
Message-ID: <1994Nov16.234427.5265@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!nntp.gmd.de!newsserver.jvnc.net!darwin.sura.net!haven.umd.edu!news.umbc.edu!europa.eng.gtefsd.com!news.mathworks.com!usenet.eel.ufl.edu!news-feed-1.peachnet.edu!gatech!howland.reston.ans.net!pipex!uunet!tron!carson
References: <1994Nov15.190054.28819@chemabs.uucp>

Show Full Headers
Complete Article Headers
Message-ID: <1994Nov16.234427.5265@tron.bwi.wec.com>
Subject: Re: Looking for tool to clean up newsrc file
Date: Wed, 16 Nov 1994 23:44:27 GMT
From: carson@tron.bwi.wec.com (Dana Carson)
References: <1994Nov15.190054.28819@chemabs.uucp>
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!nntp.gmd.de!newsserver.jvnc.net!darwin.sura.net!haven.umd.edu!news.umbc.edu!europa.eng.gtefsd.com!news.mathworks.com!usenet.eel.ufl.edu!news-feed-1.peachnet.edu!gatech!howland.reston.ans.net!pipex!uunet!tron!carson
Newsgroups: news.software.readers
Organization: Westinghouse Electric Corporation
Lines: 90