use RISCOS::Filespec;
use RISCOS::Module 'modules_only';
$command = $ARGV[0];

die "$0 <command>\n" unless $command;

($alias_command = $command) =~ s/\.$/\*/ ;
# Abbreviated commands match the first Alias$ variable

   
$alias = $ENV{"Alias\$$alias_command"};
if ($command !~ s/^\%// and $alias)
{
    ($command, $tail) = $alias =~ /\s*(\S+)\s+(.*)/;
}

($mod_command = $command) =~ s/\.$/.*/;
# Convert trailing '.' to '.*' for perl wildcard match
foreach $modname (modules_only) {
    $module = grab RISCOS::Module $modname;

    if ($table = $module->CommandTable) {
	foreach $com (@$table) {
	    $com = $com->Name;
	    if ($com =~ /^$mod_command$/io) {
		print "$com $tail [in module '$modname']\n";
		exit
	    }
	}
    }
}
    
$command = glob ("Run:$command");

print  "$command $tail\n" if $command;

# or perl -e 'print scalar glob ("Run:$ARGV[0]") . "\n"' for a simple version!