home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / newsclip / histlog next >
Encoding:
Text File  |  1993-07-14  |  6.0 KB  |  242 lines

  1. #!/usr/local/bin/perl
  2.  
  3. require "timelocal.pl";
  4.  
  5. $HOME = $ENV{'HOME'};
  6.  
  7. fork && exit;            # avoid nohup behavior
  8.  
  9. $pid = $$;
  10. fork || exec('pmeter', 10, $pid) && die "Can't exec pmeter: $!\n";
  11.                 # suspend when load average goes over 10
  12.  
  13. setpriority(0, 0, 16);        # set priority unfavorable
  14.  
  15. $date = shift;
  16. chop($date = `cat $HOME/.lasthist`) if !$date && -f "$HOME/.lasthist";
  17. $date = &idate($date);
  18.  
  19. chdir "/usr/spool/news" || die "Can't cd: $!\n";
  20.  
  21. select(STDERR); $| = 1;
  22. select(STDOUT); $| = 1;
  23.  
  24. &CATCH;
  25.  
  26. $SIG{'HUP'} = 'CATCH';        # send SIGHUP to switch to new history file
  27.  
  28. $r = "\r" if -t STDOUT;
  29.  
  30. $* = 1;
  31.  
  32. ($dev,$ino,$mode,$nlink,$uid) = stat STDOUT;
  33. $origuid = $uid;
  34. for (;;) {
  35.     while (<LOG>) {
  36.     $pos = tell(LOG);
  37.     chop;
  38.     ($messid,$date,$nglist) = split(/\t/);
  39.     next if $nglist =~ /comp\.lang\.perl/;
  40.     next if $nglist =~ /comp\.org\.usenix/;
  41.     next if $nglist =~ /control/;
  42.     next if $nglist =~ /\.binaries\./;
  43.     next if $nglist =~ /fj\./;
  44.     next if $nglist =~ /junk/;
  45.     next if $nglist =~ /comp\.unix\.sysv386/;
  46.     next if $nglist =~ /comp\.unix\.bsd/;
  47.     next if $nglist =~ /comp\.mail\.maps/;
  48.     next if $nglist =~ /\bstats\b/;
  49.     next if $nglist =~ /\bnews\b/;
  50.     next if $nglist =~ /\bconvex\./;
  51.     $date = &idate($date);
  52.     ($ng,$art) = split(m![ /]!,$nglist);
  53.     next if $ng eq 'cancelled';
  54.     $ng =~ y!.!/!;
  55.     open(ART,"$ng/$art") || next;
  56.     next if -s ART > 100000;
  57.     $count = 0;
  58.     ++$slept;        # to force quick update after big batch
  59.     $/ = '';
  60.     $header = <ART>;
  61.     $_ = '';
  62.     while (<ART>) {
  63.         study;
  64.  
  65.         &hit,next if /tom[^\000]christiansen/i;
  66.         &hit,next if /\btchrist\b/i;
  67.  
  68.         if (/\bkolstad\b/i) {
  69.         next if /joel/i;
  70.         next if /geoffrey/i;
  71.         &hit;
  72.         next;
  73.         }
  74.         &hit,next if /\blwall\b/i;
  75.         &hit,next if /larry[^\000]wall/i;
  76.         &hit,next if /jeff polk/i;
  77.  
  78.         &hit,next if /usenix/i;
  79.         &hit,next if /\bplum\b/i;
  80.         &hit,next if /\bbsd4\.4\b/i;
  81.         &hit,next if /\bbsdi\b/i;
  82.         &hit,next if /\bcvs\b/i;
  83.         &hit,next if m#bsd/?386#i;
  84.         &hit,next if m#386/?bsd#i;
  85.  
  86.         if (/\bconvex\b/i) {
  87.         next if $` =~ /@$/ || $' =~ /^\.com/ || $' =~ /^[!,]/;
  88.         next if /\bset\b/;
  89.         next if /\blens\b/;
  90.         next if /Convex Computer Corp/i;
  91.         next if /,convex,/;
  92.         next if /concave/;
  93.         next if /polygon/;
  94.         next if /polyhedra/;
  95.         next if /convex hull/;
  96.         &hit;
  97.         next;
  98.         }
  99.  
  100.         if (/\bperl\b/i) {
  101.         next if /Perlman/;              
  102.         next if /Perlberg/;              
  103.         next if /Daniel Smith/;
  104.         next if /Perl doesn't mind a little pluralism/;
  105.         next if /\.signature/; # damned viruses
  106.         &hit;
  107.         }
  108.     }
  109.     close ART;
  110.     $sleep = 5;
  111.     } continue {
  112.     $/ = "\n";
  113.     }
  114.  
  115.     print STDERR "histlog: caught up$r\n" unless $tailing++;
  116.     sleep $sleep;
  117.     $slept += $sleep;
  118.     if ($date != $lastdate && $slept > 300) {
  119.     ($dev,$ino,$mode,$nlink,$uid,$gid) = stat STDOUT;
  120.     exit unless $uid == $origuid;
  121.     open(LASTDATE,">$HOME/.lasthist");
  122.     print LASTDATE &cdate($date),"\n";
  123.     close LASTDATE;
  124.     $lastdate = $date;
  125.     $slept = 0;
  126.     }
  127.     $sleep++ if $sleep < 120;
  128.     seek(LOG,$pos,0);
  129. }
  130.  
  131. sub hit {
  132.     # sig weedings
  133.  
  134.     return if /Larry Wall on "Configure"/;  
  135.     return if /But sometimes not.\s+-Larry Wall$/;      
  136.  
  137.     # return if $_ eq "Larry Wall\nlwall@jpl-devvax.jpl.nasa.gov\n";
  138.     # return if $_ eq "Larry Wall\nlwall@netlabs.com\n";
  139.  
  140.     ($before,$match,$after) = ($`,$&,$');
  141.     $match =~ s/(.)/_\b$1/g;
  142.     if (length() > 500) {
  143.     $o = rindex($before,"\n");
  144.     $o = rindex($before,"\n",$o - 1) if $o >= 0;
  145.     $o = rindex($before,"\n",$o - 1) if $o >= 0;
  146.     $o = rindex($before,"\n",$o - 1) if $o >= 0;
  147.     if ($o > 0) {
  148.         $before = "...\n" . substr($before, $o + 1);
  149.     }
  150.     $o = index($after,"\n");
  151.     $o = index($after,"\n",$o + 1) if $o >= 0;
  152.     $o = index($after,"\n",$o + 1) if $o >= 0;
  153.     $o = index($after,"\n",$o + 1) if $o >= 0;
  154.     if ($o > 0) {
  155.         $after = substr($after, 0, $o) . "...\n";
  156.     }
  157.     }
  158.     $_ = "$before$match$after";
  159.     unless ($count++) {
  160.     $header =~ /From: (.*)/;
  161.     ($from = $1) =~ s/.*\((.*)\).*/$1/;
  162.     return if $header =~ /From:.*tchrist\@convex/;
  163.     print("$r\n\@$ng/$art  \tFrom: $from$r\n") || exit;
  164.     $header =~ /Subject: (.*)/ && print "Subject: $1$r\n";
  165.     $dots = 0;
  166.     # $0 = "histlog " . &cdate($date);
  167.     $header =~ /Newsgroup (.*)/;
  168.     $0 = 'histlog ' . $1 || &cdate($date);
  169.     }
  170.     s/\n/$r\n/g if $r;
  171.     print() || exit;
  172.     $dots = 0;
  173. }
  174.  
  175. sub seekdate {
  176.     local($start) = shift;
  177.     if (substr($start,0,4) eq '9999') {
  178.     seek(LOG,0,2);
  179.     $pos = tell(LOG);
  180.     print STDERR "$pid starting at eof...$r\n";
  181.     return;
  182.     }
  183.     ($st_dev,$st_ino,$st_mode,$st_nlink,$st_uid,$st_gid,$st_rdev,$st_size,
  184.     $st_atime,$st_mtime,$st_ctime,$st_blksize,$st_blocks) = stat(LOG);
  185.     for ($offset = $st_size - 100000; $offset > 0; $offset -= 100000) {
  186.     if (seek(LOG,$offset,0)) {
  187.         $_ = <LOG>;            # probably starts in middle of a line
  188.         $_ = <LOG>;
  189.         ($messid,$date,$nglist) = split(/\t/);
  190.         $date = &idate($date);
  191.         last if $date < $start;
  192.     }
  193.     else {
  194.         $offset = -1;
  195.     }
  196.     }
  197.     seek(LOG,0,0) if $offset < 0;
  198.     while (<LOG>) {
  199.     ($messid,$date,$nglist) = split(/\t/);
  200.     $date = &idate($date);
  201.     last if $date >= $start;
  202.     }
  203.     $pos = tell(LOG);
  204.     $pct = int($pos * 100 / $st_size);
  205.     print STDERR "$pid starting at $pct% for $start...$r\n";
  206. }
  207.  
  208. sub CATCH {
  209.     &openout;
  210.     open(LOG,'/usr/local/lib/news/history') || die "Can't open log: $!\n";
  211.  
  212.     $date = 9999999999 unless $date;
  213.     &seekdate($date);
  214.     $tailing = 0;
  215.     $slept = 300;        # force immediate update of lasthist.
  216. }
  217.  
  218. sub cdate {
  219.     ($sec,$min,$hr,$mday,$mon,$year) = gmtime($date);
  220.     sprintf("%02d/%02d/%02d %02d:%02d",$mon+1,$mday,$year,$hr,$min);
  221. }
  222.  
  223. sub idate {
  224.     $_[0] =~ m#(\d+)/(\d+)/(\d+) (\d+):(\d+)#
  225.       ? &timegm(0, $5, $4, $2, $1-1, $3)
  226.       : $_[0];
  227. }
  228.  
  229. sub openout {
  230.     rename("$HOME/tmp/n8", "$HOME/tmp/n9");
  231.     rename("$HOME/tmp/n7", "$HOME/tmp/n8");
  232.     rename("$HOME/tmp/n6", "$HOME/tmp/n7");
  233.     rename("$HOME/tmp/n5", "$HOME/tmp/n6");
  234.     rename("$HOME/tmp/n4", "$HOME/tmp/n5");
  235.     rename("$HOME/tmp/n3", "$HOME/tmp/n4");
  236.     rename("$HOME/tmp/n2", "$HOME/tmp/n3");
  237.     rename("$HOME/tmp/n1", "$HOME/tmp/n2");
  238.     rename("$HOME/tmp/n0", "$HOME/tmp/n1");
  239.     open(STDOUT, ">$HOME/tmp/n0");
  240.     open(STDERR, ">&STDOUT");
  241. }
  242.