#!/usr/bin/perl
# checkgroups backend                                             -*- perl -*-

# Process a checkgroups report, as given by C News Cleanup Release.

# Assembled from spare parts of the psl project by Olaf Titz, Nov.95.
# $Id: docheckg,v 1.3 1996/02/23 00:21:38 olaf Exp $

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# ----------------------------------------------------------------------------

require "psl-aux.pl";
&auxinit("docheckgroups");

$tstr = sprintf("%d %s@%s (checkgroups)", time, $logname, $hostname);
$stat="";
$havenew=$havedel=$havechg=0;
while(<>) {
    chop;
    /^$/ && next;
    /^obsolete groups/ && do {
       $stat="del"; next;
    };
    /^new groups/ && do {
       $stat="new"; next;
    };
    /^groups needing moderation/ && do {
       $stat="sta"; next;
    };
    ($g, $f) = split;
    if ($stat eq "new") {
       if (!$active{$g}) {
           &addgroup($g,$f);
           ++$havenew;
       }
    } elsif ($stat eq "del") {
       ++$havedel;
       &delgroup($g);
    } elsif ($stat eq "sta") {
       if ($active{$g}) {
           ++$havechg;
           print LOG "changed status $g $f\n";
           split(/ /,$active{$g});
           $_[2] = $f;
           $active{$g} = join(" ", @_);
       }
    }
}

close TBD;
print LOG "added $havenew, deleted $havedel, changed $havechg groups.\n";
&auxexit($havenew+$havedel+$havechg);
unlink("LOCK");
exit 0;
