home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
-
- require "timelocal.pl";
-
- $HOME = $ENV{'HOME'};
-
- fork && exit; # avoid nohup behavior
-
- $pid = $$;
- fork || exec('pmeter', 10, $pid) && die "Can't exec pmeter: $!\n";
- # suspend when load average goes over 10
-
- setpriority(0, 0, 16); # set priority unfavorable
-
- $date = shift;
- chop($date = `cat $HOME/.lasthist`) if !$date && -f "$HOME/.lasthist";
- $date = &idate($date);
-
- chdir "/usr/spool/news" || die "Can't cd: $!\n";
-
- select(STDERR); $| = 1;
- select(STDOUT); $| = 1;
-
- &CATCH;
-
- $SIG{'HUP'} = 'CATCH'; # send SIGHUP to switch to new history file
-
- $r = "\r" if -t STDOUT;
-
- $* = 1;
-
- ($dev,$ino,$mode,$nlink,$uid) = stat STDOUT;
- $origuid = $uid;
- for (;;) {
- while (<LOG>) {
- $pos = tell(LOG);
- chop;
- ($messid,$date,$nglist) = split(/\t/);
- next if $nglist =~ /comp\.lang\.perl/;
- next if $nglist =~ /comp\.org\.usenix/;
- next if $nglist =~ /control/;
- next if $nglist =~ /\.binaries\./;
- next if $nglist =~ /fj\./;
- next if $nglist =~ /junk/;
- next if $nglist =~ /comp\.unix\.sysv386/;
- next if $nglist =~ /comp\.unix\.bsd/;
- next if $nglist =~ /comp\.mail\.maps/;
- next if $nglist =~ /\bstats\b/;
- next if $nglist =~ /\bnews\b/;
- next if $nglist =~ /\bconvex\./;
- $date = &idate($date);
- ($ng,$art) = split(m![ /]!,$nglist);
- next if $ng eq 'cancelled';
- $ng =~ y!.!/!;
- open(ART,"$ng/$art") || next;
- next if -s ART > 100000;
- $count = 0;
- ++$slept; # to force quick update after big batch
- $/ = '';
- $header = <ART>;
- $_ = '';
- while (<ART>) {
- study;
-
- &hit,next if /tom[^\000]christiansen/i;
- &hit,next if /\btchrist\b/i;
-
- if (/\bkolstad\b/i) {
- next if /joel/i;
- next if /geoffrey/i;
- &hit;
- next;
- }
- &hit,next if /\blwall\b/i;
- &hit,next if /larry[^\000]wall/i;
- &hit,next if /jeff polk/i;
-
- &hit,next if /usenix/i;
- &hit,next if /\bplum\b/i;
- &hit,next if /\bbsd4\.4\b/i;
- &hit,next if /\bbsdi\b/i;
- &hit,next if /\bcvs\b/i;
- &hit,next if m#bsd/?386#i;
- &hit,next if m#386/?bsd#i;
-
- if (/\bconvex\b/i) {
- next if $` =~ /@$/ || $' =~ /^\.com/ || $' =~ /^[!,]/;
- next if /\bset\b/;
- next if /\blens\b/;
- next if /Convex Computer Corp/i;
- next if /,convex,/;
- next if /concave/;
- next if /polygon/;
- next if /polyhedra/;
- next if /convex hull/;
- &hit;
- next;
- }
-
- if (/\bperl\b/i) {
- next if /Perlman/;
- next if /Perlberg/;
- next if /Daniel Smith/;
- next if /Perl doesn't mind a little pluralism/;
- next if /\.signature/; # damned viruses
- &hit;
- }
- }
- close ART;
- $sleep = 5;
- } continue {
- $/ = "\n";
- }
-
- print STDERR "histlog: caught up$r\n" unless $tailing++;
- sleep $sleep;
- $slept += $sleep;
- if ($date != $lastdate && $slept > 300) {
- ($dev,$ino,$mode,$nlink,$uid,$gid) = stat STDOUT;
- exit unless $uid == $origuid;
- open(LASTDATE,">$HOME/.lasthist");
- print LASTDATE &cdate($date),"\n";
- close LASTDATE;
- $lastdate = $date;
- $slept = 0;
- }
- $sleep++ if $sleep < 120;
- seek(LOG,$pos,0);
- }
-
- sub hit {
- # sig weedings
-
- return if /Larry Wall on "Configure"/;
- return if /But sometimes not.\s+-Larry Wall$/;
-
- # return if $_ eq "Larry Wall\nlwall@jpl-devvax.jpl.nasa.gov\n";
- # return if $_ eq "Larry Wall\nlwall@netlabs.com\n";
-
- ($before,$match,$after) = ($`,$&,$');
- $match =~ s/(.)/_\b$1/g;
- if (length() > 500) {
- $o = rindex($before,"\n");
- $o = rindex($before,"\n",$o - 1) if $o >= 0;
- $o = rindex($before,"\n",$o - 1) if $o >= 0;
- $o = rindex($before,"\n",$o - 1) if $o >= 0;
- if ($o > 0) {
- $before = "...\n" . substr($before, $o + 1);
- }
- $o = index($after,"\n");
- $o = index($after,"\n",$o + 1) if $o >= 0;
- $o = index($after,"\n",$o + 1) if $o >= 0;
- $o = index($after,"\n",$o + 1) if $o >= 0;
- if ($o > 0) {
- $after = substr($after, 0, $o) . "...\n";
- }
- }
- $_ = "$before$match$after";
- unless ($count++) {
- $header =~ /From: (.*)/;
- ($from = $1) =~ s/.*\((.*)\).*/$1/;
- return if $header =~ /From:.*tchrist\@convex/;
- print("$r\n\@$ng/$art \tFrom: $from$r\n") || exit;
- $header =~ /Subject: (.*)/ && print "Subject: $1$r\n";
- $dots = 0;
- # $0 = "histlog " . &cdate($date);
- $header =~ /Newsgroup (.*)/;
- $0 = 'histlog ' . $1 || &cdate($date);
- }
- s/\n/$r\n/g if $r;
- print() || exit;
- $dots = 0;
- }
-
- sub seekdate {
- local($start) = shift;
- if (substr($start,0,4) eq '9999') {
- seek(LOG,0,2);
- $pos = tell(LOG);
- print STDERR "$pid starting at eof...$r\n";
- return;
- }
- ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size,
- $st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks) = stat(LOG);
- for ($offset = $st_size - 100000; $offset > 0; $offset -= 100000) {
- if (seek(LOG,$offset,0)) {
- $_ = <LOG>; # probably starts in middle of a line
- $_ = <LOG>;
- ($messid,$date,$nglist) = split(/\t/);
- $date = &idate($date);
- last if $date < $start;
- }
- else {
- $offset = -1;
- }
- }
- seek(LOG,0,0) if $offset < 0;
- while (<LOG>) {
- ($messid,$date,$nglist) = split(/\t/);
- $date = &idate($date);
- last if $date >= $start;
- }
- $pos = tell(LOG);
- $pct = int($pos * 100 / $st_size);
- print STDERR "$pid starting at $pct% for $start...$r\n";
- }
-
- sub CATCH {
- &openout;
- open(LOG,'/usr/local/lib/news/history') || die "Can't open log: $!\n";
-
- $date = 9999999999 unless $date;
- &seekdate($date);
- $tailing = 0;
- $slept = 300; # force immediate update of lasthist.
- }
-
- sub cdate {
- ($sec,$min,$hr,$mday,$mon,$year) = gmtime($date);
- sprintf("%02d/%02d/%02d %02d:%02d",$mon+1,$mday,$year,$hr,$min);
- }
-
- sub idate {
- $_[0] =~ m#(\d+)/(\d+)/(\d+) (\d+):(\d+)#
- ? &timegm(0, $5, $4, $2, $1-1, $3)
- : $_[0];
- }
-
- sub openout {
- rename("$HOME/tmp/n8", "$HOME/tmp/n9");
- rename("$HOME/tmp/n7", "$HOME/tmp/n8");
- rename("$HOME/tmp/n6", "$HOME/tmp/n7");
- rename("$HOME/tmp/n5", "$HOME/tmp/n6");
- rename("$HOME/tmp/n4", "$HOME/tmp/n5");
- rename("$HOME/tmp/n3", "$HOME/tmp/n4");
- rename("$HOME/tmp/n2", "$HOME/tmp/n3");
- rename("$HOME/tmp/n1", "$HOME/tmp/n2");
- rename("$HOME/tmp/n0", "$HOME/tmp/n1");
- open(STDOUT, ">$HOME/tmp/n0");
- open(STDERR, ">&STDOUT");
- }
-