fixed compilation probs
[spider.git] / perl / CmdAlias.pm
index e5f6686ab05811e500603b470364806f923809b0..1f418967c30cae00ca096045b25bc35462cbc089 100644 (file)
@@ -1,32 +1,16 @@
 #
-# This package simply takes a string, looks it up in a
-# hash and returns the value.
+# This package impliments some of the ak1a aliases that can't
+# be done with interpolation from the file names.
 #
-# The hash is produced by reading the Alias file in both command directories
-# which contain entries for the %cmd hash. This file is in different forms in 
-# the two directories:-
+# Basically it takes the input and bashes down the list of aliases
+# for that starting letter until it either matches (in which a substitution
+# is done) or fails
 #
-# in the main cmd directory it has entries like:-
+# To roll your own Aliases, copy the /spider/cmd/Aliases file to 
+# /spider/local_cmd and alter it to your taste.
 #
-# package CmdAlias;
+# To make it active type 'load/aliases'
 #
-# %alias = (
-#   sp => 'send private',
-#   s/p => 'send private', 
-#   sb => 'send bulletin', 
-# );
-#
-# for the local cmd directory you should do it like this:-
-#
-# package CmdAlias;
-#
-# $alias{'s/p'} = 'send private';
-# $alias{'s/b'} = 'send bulletin';
-#
-# This will allow you to override as well as add to the basic set of commands 
-#
-# This system works in same way as the commands, if the modification times of
-# the two files have changed then they are re-read.
 #
 # Copyright (c) 1998 Dirk Koopman G1TLH
 #
@@ -41,34 +25,31 @@ use Carp;
 
 use strict;
 
-use vars qw(%alias $cmd_mtime $localcmd_mtime $fn $localfn);
+use vars qw(%alias $fn $localfn);
 
 %alias = ();
 
-$cmd_mtime = 1;
-$localcmd_mtime = 1;
-
 $fn = "$main::cmd/Aliases";
 $localfn = "$main::localcmd/Aliases";
 
-sub checkfiles
+sub load
 {
-  my $m = -M $fn;
-#  print "m: $m oldmtime: $cmd_mtime\n";
-  if ($m < $cmd_mtime) {
-    do $fn;
+       my $ref = shift;
+       if (-e $localfn) {
+               do $localfn;
+               return ($@) if $@ && ref $ref;
+               confess $@ if $@;
+               return ();
+       }
+       do $fn;
+       return ($@) if $@ && ref $ref;
        confess $@ if $@;
-       $cmd_mtime = $m;
-       $localcmd_mtime = 0;
-  } 
-  if (-e $localfn) {
-    $m = -M $localfn;
-       if ($m < $localcmd_mtime) {
-      do $localfn;
-         confess $@ if $@;
-         $localcmd_mtime = $m;
-    } 
-  }
+       return ();
+}
+
+sub init
+{
+       load();
 }
 
 #
@@ -82,15 +63,13 @@ sub get_cmd
 
   $let = lc $let;
   
-  checkfiles();
-  
   $ref = $alias{$let};
   return undef if !$ref;
   
   $n = @{$ref};
   for ($i = 0; $i < $n; $i += 3) {
     if ($s =~ /$ref->[$i]/i) {
-         my $ri = qq{\$ro = "$ref->[$i+1]"};
+         my $ri = qq{\$ro = "$ref->[$i+1]"};
          my $ro;
          eval $ri;
          return $ro;
@@ -110,16 +89,16 @@ sub get_hlp
 
   $let = lc $let;
   
-  checkfiles();
-  
   $ref = $alias{$let};
   return undef if !$ref;
   
   $n = @{$ref};
   for ($i = 0; $i < $n; $i += 3) {
     if ($s =~ /$ref->[$i]/i) {
-         my $ri = qq{$ref->[$i+2]};
-         return $ri;
+         my $ri = qq{\$ro = "$ref->[$i+2]"};
+         my $ro;
+         eval $ri;
+         return $ro;
        }
   }
   return undef;