home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / Perl / Non-RPC / !Perl / scripts / which < prev    next >
Text File  |  1998-07-14  |  890b  |  37 lines

  1. use RISCOS::Filespec;
  2. use RISCOS::Module 'modules_only';
  3. $command = $ARGV[0];
  4.  
  5. die "$0 <command>\n" unless $command;
  6.  
  7. ($alias_command = $command) =~ s/\.$/\*/ ;
  8. # Abbreviated commands match the first Alias$ variable
  9.  
  10.    
  11. $alias = $ENV{"Alias\$$alias_command"};
  12. if ($command !~ s/^\%// and $alias)
  13. {
  14.     ($command, $tail) = $alias =~ /\s*(\S+)\s+(.*)/;
  15. }
  16.  
  17. ($mod_command = $command) =~ s/\.$/.*/;
  18. # Convert trailing '.' to '.*' for perl wildcard match
  19. foreach $modname (modules_only) {
  20.     $module = grab RISCOS::Module $modname;
  21.  
  22.     if ($table = $module->CommandTable) {
  23.     foreach $com (@$table) {
  24.         $com = $com->Name;
  25.         if ($com =~ /^$mod_command$/io) {
  26.         print "$com $tail [in module '$modname']\n";
  27.         exit
  28.         }
  29.     }
  30.     }
  31. }
  32.     
  33. $command = glob ("Run:$command");
  34.  
  35. print  "$command $tail\n" if $command;
  36.  
  37. # or perl -e 'print scalar glob ("Run:$ARGV[0]") . "\n"' for a simple version!