Commit 1cfae6da authored by Nigel Kukard's avatar Nigel Kukard

Optimized commandline parsing to be more efficient

parent 784dbbb8
...@@ -329,8 +329,13 @@ sub processCommand ...@@ -329,8 +329,13 @@ sub processCommand
# If whitespace only or comment # If whitespace only or comment
return 0 if ($cmdline =~ /^\s*$/ || $cmdline =~ /^\s*#/); return 0 if ($cmdline =~ /^\s*$/ || $cmdline =~ /^\s*#/);
# Optimize by removing spaces from beginning and end of line
$cmdline =~ s/^\s+//;
chomp($cmdline);
# Check for special: .. # Check for special: ..
if ($cmdline =~ /^\s*\.\.$/) { if ($cmdline eq "..") {
# If we have history, shift it in # If we have history, shift it in
if (@cmdHistory > 0) { if (@cmdHistory > 0) {
$cmdMap = pop(@cmdHistory); $cmdMap = pop(@cmdHistory);
...@@ -343,7 +348,7 @@ sub processCommand ...@@ -343,7 +348,7 @@ sub processCommand
# Check for special: help # Check for special: help
} elsif ($cmdline =~ /^\s*help\s*$/i) { } elsif ($cmdline eq "help") {
print($OUT "Valid commands...\n"); print($OUT "Valid commands...\n");
# Loop commands # Loop commands
...@@ -368,7 +373,7 @@ sub processCommand ...@@ -368,7 +373,7 @@ sub processCommand
return 0; return 0;
# Check for special: help <command> # Check for special: help <command>
} elsif (my ($cmd) = ($cmdline =~ /^\s*help\s*(\S+)\s*$/i)) { } elsif (my ($cmd) = ($cmdline =~ /^help\s*(\S+)$/i)) {
my $res = 0; my $res = 0;
# Loop with commands # Loop with commands
foreach my $i (@{$cmdMap->{'Children'}}) { foreach my $i (@{$cmdMap->{'Children'}}) {
...@@ -423,7 +428,7 @@ sub processCommand ...@@ -423,7 +428,7 @@ sub processCommand
my $substitution = $i->{'Substitute'} ? defined($i->{'Substitute'}) : ""; my $substitution = $i->{'Substitute'} ? defined($i->{'Substitute'}) : "";
(my $fcmd = $cmdline) =~ s/^\s*$i->{'Regex'}\s*/$substitution/i; (my $fcmd = $cmdline) =~ s/^\s*$i->{'Regex'}\s*/$substitution/i;
print($OUT "Found '".$i->{'Regex'}."', dest '".$fcmd."'\n"); # print($OUT "Found '".$i->{'Regex'}."', dest '".$fcmd."'\n");
# Pull args # Pull args
my @args = shellwords($fcmd); my @args = shellwords($fcmd);
...@@ -441,13 +446,14 @@ sub processCommand ...@@ -441,13 +446,14 @@ sub processCommand
} }
} }
# If no command, give error # If no command, give error
if (!defined($res)) { if (!defined($res)) {
return 0; return 0;
} elsif ($res == 0) { } elsif ($res == 0) {
print($OUT " => Ok!\n"); # print($OUT " => Ok!\n");
} elsif ($res > 0) { } elsif ($res > 0) {
print($OUT " => Ok! (res: $res)\n"); # print($OUT " => Ok! (res: $res)\n");
} elsif ($res == -103) { } elsif ($res == -103) {
print($OUT " => ERROR - Not authorized to access this function\n"); print($OUT " => ERROR - Not authorized to access this function\n");
} elsif ($res == -200) { } elsif ($res == -200) {
...@@ -458,6 +464,7 @@ sub processCommand ...@@ -458,6 +464,7 @@ sub processCommand
print($OUT "Usage Error...\n"); print($OUT "Usage Error...\n");
print($OUT " ".$matchedCmd->{'Help'}."\n"); print($OUT " ".$matchedCmd->{'Help'}."\n");
} else { } else {
print($OUT " => ERROR - Processing line: $cmdline\n");
print($OUT " => ERROR - Unknown result: $res\n"); print($OUT " => ERROR - Unknown result: $res\n");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment