#!/usr/local/bin/perl use Socket; use Getopt::Std; $range = 1000; getopts ('h:u:p:', \%opts); $hostname = $opts{'h'} || 'news.media.kyoto-u.ac.jp'; $username = $opts{'u'}; $password = $opts{'p'}; exit (0) if (@ARGV == 0); tcp_client(S, $hostname, 119); select(S); $|=1; select(STDIN); $|=1; select(STDOUT); $|=1; if ( =~ /^[^2]/) { printf STDERR "Permission Denied.\n"; exit (1); } modereader (); if (!($username eq "") && !($password eq "")) { authinfo ($username, $password); } printf S "group %s\r\n", $ARGV[0]; $_ = ; if ($_ !~ /^2\d\d \d+ (\d+) (\d+)/) { # cannot groupnn chomp; printf STDERR "%s\n", $_; return; } if ($1 > $2 - $xover_range) { printf STDERR "No enough articles %d %d.\n", $1, $2 - $range; } printf S "xover %d-%d\r\n", $2 - $range, $2; $_ = ; if ($_ !~ /^2\d\d/) { # cannot xover chomp; printf STDERR "%s\n", $_; return; } while ($_ = ) { last if ($_ eq ".\r\n"); split ("\t", $_); # printf "%s\n", $_[4]; printf S "head %s\r\n", $_[4]; } while ($_ = ) { last if ($_ eq ".\r\n"); } exit (0); sub modereader () { printf S "mode reader\r\n"; $_ = ; if (/^[^2]/) { printf STDERR "Permission Denied.:%s\n", $_; exit (1); } } sub authinfo ($$) { printf S "authinfo user %s\r\n", $_[0]; $_ = ; if (/^[^3]/) { chomp; printf STDERR "%s\n", $_; exit (1); } printf S "authinfo pass %s\r\n", $_[1]; $_ = ; if (/^[^2]/) { chomp; printf STDERR "%s\n", $_; exit (1); } } sub xover ($) { } sub tcp_client ($;$$) { my ($S, $host, $port) = @_; my $pack = caller; $S = $pack . "::" . $S; $host = $host || "localhost"; $port = $port || 6002; my $proto = getprotobyname('tcp'); socket($S, PF_INET, SOCK_STREAM, $proto); $ent = sockaddr_in($port, inet_aton($host)); connect($S, $ent) || die "connect : $!"; # バッファリングを止める select($S); $| = 1; select(STDOUT); }