From 67f2b89bf6f6d071c61c313cc900cfc375b185d4 Mon Sep 17 00:00:00 2001 From: Charles Krinke Date: Wed, 23 Apr 2008 14:31:54 +0000 Subject: Thank you kindly, Tyre for : Commands with arguments enclosed in Double quotation marks (e.g. filenames or objects with embedded blanks) should be parsed correctly. e.g.: console command "edit-scale" don't accept prim names with embedded blanks edit-scale Prim 20x20x20 20 20 20 Region# : edit-scale "Prim 20x20x20" 20 20 20 Region# : edit-scale Prim20x20x20 20 20 20 Searching for Primitive: 'Prim20x20x20' Edited scale of Primitive: Prim20x20x20 Region# : --- OpenSim/Framework/Console/ConsoleBase.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'OpenSim/Framework/Console') diff --git a/OpenSim/Framework/Console/ConsoleBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs index 27ff340..1d92ed1 100644 --- a/OpenSim/Framework/Console/ConsoleBase.cs +++ b/OpenSim/Framework/Console/ConsoleBase.cs @@ -26,7 +26,9 @@ */ using System; +using System.Collections; using System.Collections.Generic; +using System.Text.RegularExpressions; using System.Diagnostics; using System.Net; using System.Reflection; @@ -368,23 +370,27 @@ namespace OpenSim.Framework.Console RunCommand(tempstr); } - public void RunCommand(string command) + public void RunCommand(string cmdline) { - string[] tempstrarray; - tempstrarray = command.Split(' '); - string cmd = tempstrarray[0]; - Array.Reverse(tempstrarray); - Array.Resize(ref tempstrarray, tempstrarray.Length - 1); - Array.Reverse(tempstrarray); - string[] cmdparams = (string[]) tempstrarray; - + Regex Extractor = new Regex(@"(['""][^""]+['""])\s*|([^\s]+)\s*", RegexOptions.Compiled); + char[] delims = {' ', '"'}; + MatchCollection matches = Extractor.Matches(cmdline); + // Get matches + string cmd = matches[0].Value.Trim(delims); + string[] cmdparams = new string[matches.Count - 1]; + + for (int i = 1; i < matches.Count; i++) + { + cmdparams[i-1] = matches[i].Value.Trim(delims); + } + try { RunCmd(cmd, cmdparams); } catch (Exception e) { - m_log.ErrorFormat("[Console]: Command [{0}] failed with exception {1}", command, e.ToString()); + m_log.ErrorFormat("[Console]: Command [{0}] failed with exception {1}", cmdline, e.ToString()); } } -- cgit v1.1