- my $self = shift;
- my $user = $self->{user};
- my $call = $self->{call};
- my $cmd = shift;
-
- # read in the list of valid commands, note that the commands themselves are cached elsewhere
- scan_cmd_dirs if (!defined %cmd);
-
- # strip out any nasty characters like $@%&|. and double // etc.
- $cmd =~ s/[%\@\$&\\.`~]//og;
- $cmd =~ s|//|/|og;
-
- # split the command up into parts
- my @part = split /[\/\b]+/, $cmd;
-
- # the bye command - temporary probably
- if ($part[0] =~ /^b/io) {
- $self->user_finish();
- $self->state('bye');
- return;
- }
-
- # first expand out the entry to a command, note that I will accept
- # anything in any case with any (reasonable) seperator
- $self->prompt();
+ my $self = shift;
+ my $user = $self->{user};
+ my $call = $self->{call};
+ my $cmdline = shift;
+ my @ans;
+
+ if ($self->{func}) {
+ my $c = qq{ \@ans = $self->{func}(\$self, \$cmdline) };
+ dbg('eval', "stored func cmd = $c\n");
+ eval $c;
+ if ($@) {
+ return ("Syserr: Eval err $errstr on stored func $self->{func}", $@);
+ }
+ } else {
+
+ return () if length $cmdline == 0;
+
+ # strip out //
+ $cmdline =~ s|//|/|og;
+
+ # split the command line up into parts, the first part is the command
+ my ($cmd, $args) = split /\s+/, $cmdline, 2;
+ $args = "" unless $args;
+
+ if ($cmd) {
+
+ my ($path, $fcmd);
+
+ dbg('command', "cmd: $cmd");
+
+ # alias it if possible
+ my $acmd = CmdAlias::get_cmd($cmd);
+ if ($acmd) {
+ ($cmd, $args) = split /\s+/, "$acmd $args", 2;
+ $args = "" unless $args;
+ dbg('command', "aliased cmd: $cmd $args");
+ }
+
+ # 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;
+
+ if ($path && $cmd) {
+ dbg('command', "path: $cmd cmd: $fcmd");
+
+ my $package = find_cmd_name($path, $fcmd);
+ @ans = (0) if !$package ;
+
+ if ($package) {
+ dbg('command', "package: $package");
+ my $c;
+ unless (exists $Cache{$package}->{sub}) {
+ $c = eval $Cache{$package}->{eval};
+ if ($@) {
+ return ("Syserr: Syntax error in $package", $@);
+ }
+ $Cache{$package}->{sub} = $c;
+ }
+ $c = $Cache{$package}->{sub};
+ eval {
+ @ans = &{$c}($self, $args);
+ };
+
+ return ($@) if $@;
+ }
+ } else {
+ dbg('command', "cmd: $cmd not found");
+ return ($self->msg('e1'));
+ }
+ }
+ }
+
+ shift @ans;
+ return (@ans);