X-Git-Url: http://www.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCommandmode.pm;h=aa4cb1a37a4fb287f9245612ec0b9d88e1c8c346;hb=cef696652d16bbeec53aca45234ea0b64f3496d3;hp=024ccb0e491ece4cac8962e9cdb0efbfd241f36c;hpb=57b5e464bc44ae8eee23ab94c1f499f527595dc9;p=spider.git diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 024ccb0e..aa4cb1a3 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -17,15 +17,19 @@ use DXUser; use DXVars; use DXDebug; use DXM; +use DXLog; +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 # @@ -71,6 +75,7 @@ sub start my $nchan = DXChannel->get($main::mycall); my @pc16 = DXProt::pc16($nchan, $cuser); DXProt::broadcast_ak1a(@pc16); + Log('DXCommand', "$call connected"); } # @@ -109,13 +114,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 +139,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')); } @@ -185,7 +194,8 @@ sub finish my $nchan = DXChannel->get($main::mycall); my $pc17 = $nchan->pc17($self); DXProt::broadcast_ak1a($pc17); - + + Log('DXCommand', "$call disconnected"); $ref->del() if $ref; } @@ -385,10 +395,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 +426,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 +434,7 @@ sub find_cmd_name { #print Devel::Symdump->rnew($package)->as_string, $/; $package = "DXCommandmode::$package" if $package; + $package = undef if $errstr; return $package; }