X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=522200da3b8249cb74f3bc492a92fa1862d17331;hb=d7cd2f1d32971efd542a9e4bf0d1df92a4d054de;hp=024ccb0e491ece4cac8962e9cdb0efbfd241f36c;hpb=57b5e464bc44ae8eee23ab94c1f499f527595dc9;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 024ccb0e..522200da 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -17,15 +17,18 @@ use DXUser; use DXVars; use DXDebug; use DXM; +use CmdAlias; use FileHandle; use Carp; use strict; -use vars qw(%Cache %cmd_cache $errstr); +use vars qw(%Cache %cmd_cache $errstr %aliases); %Cache = (); # cache of dynamically loaded routine's mod times %cmd_cache = (); # cache of short names $errstr = (); # error string from eval +%aliases = (); # aliases for (parts of) commands + # # obtain a new connection this is derived from dxchannel # @@ -109,13 +112,19 @@ sub normal if ($cmd) { my ($path, $fcmd); + + # alias it if possible + my $acmd = CmdAlias::get_cmd($cmd); + if ($acmd) { + ($cmd, $args) = "$acmd $args" =~ /^([\w\/]+)\s*(.*)/o; + } # first expand out the entry to a command ($path, $fcmd) = search($main::localcmd, $cmd, "pl"); ($path, $fcmd) = search($main::cmd, $cmd, "pl") if !$path || !$fcmd; my $package = find_cmd_name($path, $fcmd); - @ans = (0, "Syserr: compile err on $package\n$@$errstr") if !$package ; + @ans = (0) if !$package ; if ($package) { my $c = qq{ \@ans = $package(\$self, \$args) }; @@ -128,15 +137,13 @@ sub normal } } -# my @ans = $self->eval_file($path, $fcmd, $args) if $path && $fcmd; -# @ans = $self->eval_file($main::cmd, $cmd, $args) if !$ans[0]; if ($ans[0]) { shift @ans; $self->send(@ans) if @ans > 0; } else { shift @ans; if (@ans > 0) { - $self->send($self->msg('e2', @ans)); + $self->send($self->msg('e2'), @ans); } else { $self->send($self->msg('e1')); } @@ -385,10 +392,10 @@ sub find_cmd_name { my $fh = new FileHandle; if (!open $fh, $filename) { $errstr = "Syserr: can't open '$filename' $!"; + return undef; }; - my $old = $fh->input_record_separator(undef); + local $/ = undef; my $sub = <$fh>; - $fh->input_record_separator($old); close $fh; #wrap the code into a subroutine inside our unique package @@ -416,7 +423,6 @@ sub find_cmd_name { print "\$\@ = $@"; $errstr = $@; delete_package($package); - $package = undef; } else { #cache it unless we're cleaning out each time $Cache{$package}{mtime} = $mtime; @@ -425,6 +431,7 @@ sub find_cmd_name { #print Devel::Symdump->rnew($package)->as_string, $/; $package = "DXCommandmode::$package" if $package; + $package = undef if $errstr; return $package; }