#!/usr/bin/perl -w
#
# $Id: actalm,v 1.2 2002/04/18 09:22:14 cvs Exp $
#
# actalm: PIFIA alarms lister
#
# actalm <alarm>     - toggles (de)activation of given alarm
# actalm -a <alarm>  - forces activation of given alarm
# actalm -d <alarm>  - forces deactivation of given alarm
#

use strict;
use File::Find;
use File::stat;

#------------------------------------------------[ Configuration Section ]----

my $picabasedir = '<#$picaalarms#>';

#-----------------------------------------------------------------------------

my $alarm = shift ;
die "I need at least one parameter!\n" unless $alarm;
my $option = '-t';   # Implicit
if ($alarm =~ /^-[ad]$/) {
   $option = $alarm;
   $alarm  = shift ;
}
$alarm .= '-picacaller';

sub wanted {
   if ($_ eq $alarm) {
      my $st = stat ($_);
      my $perms = $st->mode;
      $option eq '-t' and do {
         if ($perms & 0100) {
            $option = '-d';
         } else {
            $option = '-a';
         }
      };
      $option eq '-a' and $perms |= 0111;
      $option eq '-d' and $perms &= 0666;
      chmod $perms, $_;
   }
};

finddepth \&wanted, $picabasedir;
