🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #22909

Re: shell script to clean up .newsrc files?

#22909
From: Larry W. Virden
Date: Sat, 15 Jun 1996 00:00
102 lines
3098 bytes

I have one script, BUT, it does not work as well as it should.  I can
share the one that has been hacked on, if some of you hard cores out 
there can help hack on it to make it better...


: # use perl
        eval 'exec perl -w -S $0 "$@"'
                if $runnning_under_some_shell;

#Author:carson@tron.bwi.wec.com (Dana Carson)
#Date: Wed, 16 Nov 1994 23:44:27 GMT
#Modified by: Larry W. Virden, to apply algorithm to all newsgroups
#Date: Mon, 21 Nov 1994

$NEWSDIR = "/usr/spool/news/";
if (!open(CURDIR,$NEWSDIR) ) {
	$NEWSDIR = "/var/spool/news/";
} else {
	closedir(CURDIR);
}

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
		( $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;
}

-- 
:s Larry W. Virden                 INET: lvirden@cas.org
:s <URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
:s Unless explicitly stated to the contrary, nothing in this posting should
:s be construed as representing my employer's opinions.

Technical Details
Message-ID: <4pu830$nd6@srv13s4.cas.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <4ppmh7$rr1@panix3.panix.com>

Show Full Headers
Complete Article Headers
Message-ID: <4pu830$nd6@srv13s4.cas.org>
Subject: Re: shell script to clean up .newsrc files?
Date: Sat, 15 Jun 1996 00:00:00 +0000
From: lwv26@cas.org (Larry W. Virden)
References: <4ppmh7$rr1@panix3.panix.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 160307482
Content-type: text/plain; charset=US-ASCII
Organization: Nedriv Software and Shoe Shiners, Uninc.
Mime-version: 1.0
Reply-to: lvirden@cas.org
Newsgroups: news.software.readers
Originator: lwv26@cas.org (Larry W. Virden)