home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume31
/
pgnews
/
part01
/
pgnews
Wrap
Text File
|
1992-07-16
|
5KB
|
159 lines
#! /usr/bin/perl
#/****************************************************
#*****************************************************
#**
#** SOURCE NAME | pgnews, (Perl Get News)
#** |
#** SYNOPSIS | pgnews
#** |
#** DESCRIPTION | pgnews goes to a specified NNTP server
#** | and retrieves news articles by newsgroup
#** | and saves them to a specified file in
#** | mailbox format.
#** | Please see the NOTES section.
#** |
#** CHANGES | Programmer: Date: Reason/Comments
#** | Jeffrey B. McGough 09-05-91 initial
#** | Jeffrey B. McGough 09-06-91 Added select (see FIXES)
#** | Jeffrey B. McGough 10-06-91 Fixed erronious end of article
#** | Jeffrey B. McGough 07-09-92 Fixed dup article bug
#** |
#** NOTES | Pgnews needs a file named .pgnews to read
#** | its newsgroup, last message, and savefile from.
#** | .pgnews format is:
#** | newsgroup number savefile
#** | Example:
#** | comp.unix.wizards 7800 cuw
#** | comp.unix.shell 3203 cus
#** | comp.unix.questions 546 cuq
#** |
#** | comp.unix.wizards will be saved to file cuw in
#** | mailbox format starting at article 7800 etc.
#** |
#** FIXES | 09-06-91: added select on S to keep the client
#** | from getting out of sync.
#** | Jeffrey B. McGough mcgough@wrdis01.af.mil
#** |
#** | 10-06-91: Fixed an overlooked END of ARTICLE
#** | bug... Thanks to a member(s) of the issos
#** | group at Ohio State.
#** | Jeffrey B. McGough mcgough@wrdis01.af.mil
#** |
#** | 07-09-92: Fixed a duplicate article bug
#** | pointed out to me by kenr@bridge.cc.rochester.edu
#** | and gort@bridge.cc.rochester.edu. Thanks
#** | for the help with the fix.
#** | Jeffrey B. McGough mcgough@wrdis01.af.mil
#** |
#****************************************************/
require 'sys/socket.ph'; # The way I coded the sockets is this necessary?
$port = 119; # For NNTP
# HOSTNAME for the server...
#$host = 'localhost';
$host = 'emory.mathcs.emory.edu';
# Pack format...
$sockaddr = 'S n a4 x8';
$DOMAIN = 2;
$STYLE = 1;
$newsfile = '.pgnews';
$nnewsfile = '.pgnews.new';
$rin = $rout = '';
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $hostaddr) = gethostbyname($host);
$sock = pack($sockaddr, $DOMAIN, $port, $hostaddr);
socket(S, $DOMAIN, $STYLE, $proto) || die $!;
connect(S, $sock) || die $!;
select(S); $| = 1; select(STDOUT);
#set up for select
vec($rin, fileno(S), 1) = 1;
#this select will block until the server gives us something.
select($rout=$rin, undef, undef, undef);
$_ = <S>; #Read one line to see if we got a good connection.
if ($_ !~ /^2../)
{
print;
die "Service unavailable";
}
open(GRP, "< $newsfile") || die "Could not open $newsfile: $!";
open(NGRP, "> $nnewsfile") || die "Could not open $nnewsfile: $!";
select(NGRP); $| = 1; select(STDOUT);
while(<GRP>)
{
chop;
($grp, $lgot, $file) = split;
print(S "group $grp\n");
#this select will block until the server gives us something.
select($rout=$rin, undef, undef, undef);
$_ = <S>; #Make sure the group change worked...
($stat, $num, $first, $last) = split;
if( $stat !~ /^2../ )
{
print;
warn "Bad group";
print(NGRP "$grp $lgot $file\n");
next;
}
# good group open output file...
open(OUTFILE, ">>$file") || die "Could not open $file";
if ( $first > $lgot )
{
$lgot = $first;
}
if ( $lgot <= $last )
{
foreach $art ($lgot..$last)
{
print(S "article $art\n");
#this select will block until the server gives us something.
select($rout=$rin, undef, undef, undef);
$_ = <S>; #get error if one exists
if($_ !~ /^2../)
{
print;
warn "No article by that number";
}
else
{
do
{
$lgot = $art;
$_ = <S>;
s/^Path:/From/;
s/\r//;
if( $_ ne ".\n")
{
s/^\.//;
print OUTFILE;
s/^\./../;
}
else
{
print OUTFILE "\n";
}
} until $_ eq ".\n";
}
}
}
else
{
$lgot -= 1;
}
close(OUTFILE);
$lgot += 1;
print(NGRP "$grp $lgot $file\n");
}
close(NGRP);
close(GRP);
system("mv $nnewsfile $newsfile");
print( S "quit\n");
close(S);