CommandConsole.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Xml;
  29. using System.Collections.Generic;
  30. using System.Diagnostics;
  31. using System.Linq;
  32. using System.Reflection;
  33. using System.Text;
  34. using System.Text.RegularExpressions;
  35. using System.Threading;
  36. using log4net;
  37. using OpenSim.Framework;
  38. namespace OpenSim.Framework.Console
  39. {
  40. public class Commands : ICommands
  41. {
  42. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. /// <summary>
  44. /// Encapsulates a command that can be invoked from the console
  45. /// </summary>
  46. private class CommandInfo
  47. {
  48. /// <value>
  49. /// The module from which this command comes
  50. /// </value>
  51. public string module;
  52. /// <value>
  53. /// Whether the module is shared
  54. /// </value>
  55. public bool shared;
  56. /// <value>
  57. /// Very short BNF description
  58. /// </value>
  59. public string help_text;
  60. /// <value>
  61. /// Longer one line help text
  62. /// </value>
  63. public string long_help;
  64. /// <value>
  65. /// Full descriptive help for this command
  66. /// </value>
  67. public string descriptive_help;
  68. /// <value>
  69. /// The method to invoke for this command
  70. /// </value>
  71. public List<CommandDelegate> fn;
  72. }
  73. public const string GeneralHelpText
  74. = "To enter an argument that contains spaces, surround the argument with double quotes.\nFor example, show object name \"My long object name\"\n";
  75. public const string ItemHelpText
  76. = "For more information, type 'help <item>' where <item> is one of the following:";
  77. /// <value>
  78. /// Commands organized by keyword in a tree
  79. /// </value>
  80. private Dictionary<string, object> tree =
  81. new Dictionary<string, object>();
  82. /// <summary>
  83. /// Commands organized by module
  84. /// </summary>
  85. private Dictionary<string, List<CommandInfo>> m_modulesCommands = new Dictionary<string, List<CommandInfo>>();
  86. /// <summary>
  87. /// Get help for the given help string
  88. /// </summary>
  89. /// <param name="helpParts">Parsed parts of the help string. If empty then general help is returned.</param>
  90. /// <returns></returns>
  91. public List<string> GetHelp(string[] cmd)
  92. {
  93. List<string> help = new List<string>();
  94. List<string> helpParts = new List<string>(cmd);
  95. // Remove initial help keyword
  96. helpParts.RemoveAt(0);
  97. // General help
  98. if (helpParts.Count == 0)
  99. {
  100. help.Add(""); // Will become a newline.
  101. help.Add(GeneralHelpText);
  102. help.Add(ItemHelpText);
  103. help.AddRange(CollectModulesHelp(tree));
  104. }
  105. else
  106. {
  107. help.AddRange(CollectHelp(helpParts));
  108. }
  109. return help;
  110. }
  111. /// <summary>
  112. /// See if we can find the requested command in order to display longer help
  113. /// </summary>
  114. /// <param name="helpParts"></param>
  115. /// <returns></returns>
  116. private List<string> CollectHelp(List<string> helpParts)
  117. {
  118. string originalHelpRequest = string.Join(" ", helpParts.ToArray());
  119. List<string> help = new List<string>();
  120. // Check modules first to see if we just need to display a list of those commands
  121. if (TryCollectModuleHelp(originalHelpRequest, help))
  122. {
  123. help.Insert(0, ItemHelpText);
  124. return help;
  125. }
  126. Dictionary<string, object> dict = tree;
  127. while (helpParts.Count > 0)
  128. {
  129. string helpPart = helpParts[0];
  130. if (!dict.ContainsKey(helpPart))
  131. break;
  132. //m_log.Debug("Found {0}", helpParts[0]);
  133. if (dict[helpPart] is Dictionary<string, Object>)
  134. dict = (Dictionary<string, object>)dict[helpPart];
  135. helpParts.RemoveAt(0);
  136. }
  137. // There was a command for the given help string
  138. if (dict.ContainsKey(String.Empty))
  139. {
  140. CommandInfo commandInfo = (CommandInfo)dict[String.Empty];
  141. help.Add(commandInfo.help_text);
  142. help.Add(commandInfo.long_help);
  143. string descriptiveHelp = commandInfo.descriptive_help;
  144. // If we do have some descriptive help then insert a spacing line before and after for readability.
  145. if (descriptiveHelp != string.Empty)
  146. help.Add(string.Empty);
  147. help.Add(commandInfo.descriptive_help);
  148. if (descriptiveHelp != string.Empty)
  149. help.Add(string.Empty);
  150. }
  151. else
  152. {
  153. help.Add(string.Format("No help is available for {0}", originalHelpRequest));
  154. }
  155. return help;
  156. }
  157. /// <summary>
  158. /// Try to collect help for the given module if that module exists.
  159. /// </summary>
  160. /// <param name="moduleName"></param>
  161. /// <param name="helpText">/param>
  162. /// <returns>true if there was the module existed, false otherwise.</returns>
  163. private bool TryCollectModuleHelp(string moduleName, List<string> helpText)
  164. {
  165. lock (m_modulesCommands)
  166. {
  167. foreach (string key in m_modulesCommands.Keys)
  168. {
  169. // Allow topic help requests to succeed whether they are upper or lowercase.
  170. if (moduleName.ToLower() == key.ToLower())
  171. {
  172. List<CommandInfo> commands = m_modulesCommands[key];
  173. var ourHelpText = commands.ConvertAll(c => string.Format("{0} - {1}", c.help_text, c.long_help));
  174. ourHelpText.Sort();
  175. helpText.AddRange(ourHelpText);
  176. return true;
  177. }
  178. }
  179. return false;
  180. }
  181. }
  182. private List<string> CollectModulesHelp(Dictionary<string, object> dict)
  183. {
  184. lock (m_modulesCommands)
  185. {
  186. List<string> helpText = new List<string>(m_modulesCommands.Keys);
  187. helpText.Sort();
  188. return helpText;
  189. }
  190. }
  191. // private List<string> CollectHelp(Dictionary<string, object> dict)
  192. // {
  193. // List<string> result = new List<string>();
  194. //
  195. // foreach (KeyValuePair<string, object> kvp in dict)
  196. // {
  197. // if (kvp.Value is Dictionary<string, Object>)
  198. // {
  199. // result.AddRange(CollectHelp((Dictionary<string, Object>)kvp.Value));
  200. // }
  201. // else
  202. // {
  203. // if (((CommandInfo)kvp.Value).long_help != String.Empty)
  204. // result.Add(((CommandInfo)kvp.Value).help_text+" - "+
  205. // ((CommandInfo)kvp.Value).long_help);
  206. // }
  207. // }
  208. // return result;
  209. // }
  210. /// <summary>
  211. /// Add a command to those which can be invoked from the console.
  212. /// </summary>
  213. /// <param name="module"></param>
  214. /// <param name="command"></param>
  215. /// <param name="help"></param>
  216. /// <param name="longhelp"></param>
  217. /// <param name="fn"></param>
  218. public void AddCommand(string module, bool shared, string command,
  219. string help, string longhelp, CommandDelegate fn)
  220. {
  221. AddCommand(module, shared, command, help, longhelp, String.Empty, fn);
  222. }
  223. /// <summary>
  224. /// Add a command to those which can be invoked from the console.
  225. /// </summary>
  226. /// <param name="module"></param>
  227. /// <param name="command"></param>
  228. /// <param name="help"></param>
  229. /// <param name="longhelp"></param>
  230. /// <param name="descriptivehelp"></param>
  231. /// <param name="fn"></param>
  232. public void AddCommand(string module, bool shared, string command,
  233. string help, string longhelp, string descriptivehelp,
  234. CommandDelegate fn)
  235. {
  236. string[] parts = Parser.Parse(command);
  237. Dictionary<string, Object> current = tree;
  238. foreach (string part in parts)
  239. {
  240. if (current.ContainsKey(part))
  241. {
  242. if (current[part] is Dictionary<string, Object>)
  243. current = (Dictionary<string, Object>)current[part];
  244. else
  245. return;
  246. }
  247. else
  248. {
  249. current[part] = new Dictionary<string, Object>();
  250. current = (Dictionary<string, Object>)current[part];
  251. }
  252. }
  253. CommandInfo info;
  254. if (current.ContainsKey(String.Empty))
  255. {
  256. info = (CommandInfo)current[String.Empty];
  257. if (!info.shared && !info.fn.Contains(fn))
  258. info.fn.Add(fn);
  259. return;
  260. }
  261. info = new CommandInfo();
  262. info.module = module;
  263. info.shared = shared;
  264. info.help_text = help;
  265. info.long_help = longhelp;
  266. info.descriptive_help = descriptivehelp;
  267. info.fn = new List<CommandDelegate>();
  268. info.fn.Add(fn);
  269. current[String.Empty] = info;
  270. // Now add command to modules dictionary
  271. lock (m_modulesCommands)
  272. {
  273. List<CommandInfo> commands;
  274. if (m_modulesCommands.ContainsKey(module))
  275. {
  276. commands = m_modulesCommands[module];
  277. }
  278. else
  279. {
  280. commands = new List<CommandInfo>();
  281. m_modulesCommands[module] = commands;
  282. }
  283. // m_log.DebugFormat("[COMMAND CONSOLE]: Adding to category {0} command {1}", module, command);
  284. commands.Add(info);
  285. }
  286. }
  287. public string[] FindNextOption(string[] cmd, bool term)
  288. {
  289. Dictionary<string, object> current = tree;
  290. int remaining = cmd.Length;
  291. foreach (string s in cmd)
  292. {
  293. remaining--;
  294. List<string> found = new List<string>();
  295. foreach (string opt in current.Keys)
  296. {
  297. if (remaining > 0 && opt == s)
  298. {
  299. found.Clear();
  300. found.Add(opt);
  301. break;
  302. }
  303. if (opt.StartsWith(s))
  304. {
  305. found.Add(opt);
  306. }
  307. }
  308. if (found.Count == 1 && (remaining != 0 || term))
  309. {
  310. current = (Dictionary<string, object>)current[found[0]];
  311. }
  312. else if (found.Count > 0)
  313. {
  314. return found.ToArray();
  315. }
  316. else
  317. {
  318. break;
  319. // return new string[] {"<cr>"};
  320. }
  321. }
  322. if (current.Count > 1)
  323. {
  324. List<string> choices = new List<string>();
  325. bool addcr = false;
  326. foreach (string s in current.Keys)
  327. {
  328. if (s == String.Empty)
  329. {
  330. CommandInfo ci = (CommandInfo)current[String.Empty];
  331. if (ci.fn.Count != 0)
  332. addcr = true;
  333. }
  334. else
  335. choices.Add(s);
  336. }
  337. if (addcr)
  338. choices.Add("<cr>");
  339. return choices.ToArray();
  340. }
  341. if (current.ContainsKey(String.Empty))
  342. return new string[] { "Command help: "+((CommandInfo)current[String.Empty]).help_text};
  343. return new string[] { new List<string>(current.Keys)[0] };
  344. }
  345. public string[] Resolve(string[] cmd)
  346. {
  347. string[] result = cmd;
  348. int index = -1;
  349. Dictionary<string, object> current = tree;
  350. foreach (string s in cmd)
  351. {
  352. index++;
  353. List<string> found = new List<string>();
  354. foreach (string opt in current.Keys)
  355. {
  356. if (opt == s)
  357. {
  358. found.Clear();
  359. found.Add(opt);
  360. break;
  361. }
  362. if (opt.StartsWith(s))
  363. {
  364. found.Add(opt);
  365. }
  366. }
  367. if (found.Count == 1)
  368. {
  369. result[index] = found[0];
  370. current = (Dictionary<string, object>)current[found[0]];
  371. }
  372. else if (found.Count > 0)
  373. {
  374. return new string[0];
  375. }
  376. else
  377. {
  378. break;
  379. }
  380. }
  381. if (current.ContainsKey(String.Empty))
  382. {
  383. CommandInfo ci = (CommandInfo)current[String.Empty];
  384. if (ci.fn.Count == 0)
  385. return new string[0];
  386. foreach (CommandDelegate fn in ci.fn)
  387. {
  388. if (fn != null)
  389. fn(ci.module, result);
  390. else
  391. return new string[0];
  392. }
  393. return result;
  394. }
  395. return new string[0];
  396. }
  397. public XmlElement GetXml(XmlDocument doc)
  398. {
  399. CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
  400. ((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
  401. if (((Dictionary<string, object>)tree["help"]).Count == 0)
  402. tree.Remove("help");
  403. CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
  404. ((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
  405. if (((Dictionary<string, object>)tree["quit"]).Count == 0)
  406. tree.Remove("quit");
  407. XmlElement root = doc.CreateElement("", "HelpTree", "");
  408. ProcessTreeLevel(tree, root, doc);
  409. if (!tree.ContainsKey("help"))
  410. tree["help"] = (object) new Dictionary<string, object>();
  411. ((Dictionary<string, object>)tree["help"])[String.Empty] = help;
  412. if (!tree.ContainsKey("quit"))
  413. tree["quit"] = (object) new Dictionary<string, object>();
  414. ((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
  415. return root;
  416. }
  417. private void ProcessTreeLevel(Dictionary<string, object> level, XmlElement xml, XmlDocument doc)
  418. {
  419. foreach (KeyValuePair<string, object> kvp in level)
  420. {
  421. if (kvp.Value is Dictionary<string, Object>)
  422. {
  423. XmlElement next = doc.CreateElement("", "Level", "");
  424. next.SetAttribute("Name", kvp.Key);
  425. xml.AppendChild(next);
  426. ProcessTreeLevel((Dictionary<string, object>)kvp.Value, next, doc);
  427. }
  428. else
  429. {
  430. CommandInfo c = (CommandInfo)kvp.Value;
  431. XmlElement cmd = doc.CreateElement("", "Command", "");
  432. XmlElement e;
  433. e = doc.CreateElement("", "Module", "");
  434. cmd.AppendChild(e);
  435. e.AppendChild(doc.CreateTextNode(c.module));
  436. e = doc.CreateElement("", "Shared", "");
  437. cmd.AppendChild(e);
  438. e.AppendChild(doc.CreateTextNode(c.shared.ToString()));
  439. e = doc.CreateElement("", "HelpText", "");
  440. cmd.AppendChild(e);
  441. e.AppendChild(doc.CreateTextNode(c.help_text));
  442. e = doc.CreateElement("", "LongHelp", "");
  443. cmd.AppendChild(e);
  444. e.AppendChild(doc.CreateTextNode(c.long_help));
  445. e = doc.CreateElement("", "Description", "");
  446. cmd.AppendChild(e);
  447. e.AppendChild(doc.CreateTextNode(c.descriptive_help));
  448. xml.AppendChild(cmd);
  449. }
  450. }
  451. }
  452. public void FromXml(XmlElement root, CommandDelegate fn)
  453. {
  454. CommandInfo help = (CommandInfo)((Dictionary<string, object>)tree["help"])[String.Empty];
  455. ((Dictionary<string, object>)tree["help"]).Remove(string.Empty);
  456. if (((Dictionary<string, object>)tree["help"]).Count == 0)
  457. tree.Remove("help");
  458. CommandInfo quit = (CommandInfo)((Dictionary<string, object>)tree["quit"])[String.Empty];
  459. ((Dictionary<string, object>)tree["quit"]).Remove(string.Empty);
  460. if (((Dictionary<string, object>)tree["quit"]).Count == 0)
  461. tree.Remove("quit");
  462. tree.Clear();
  463. ReadTreeLevel(tree, root, fn);
  464. if (!tree.ContainsKey("help"))
  465. tree["help"] = (object) new Dictionary<string, object>();
  466. ((Dictionary<string, object>)tree["help"])[String.Empty] = help;
  467. if (!tree.ContainsKey("quit"))
  468. tree["quit"] = (object) new Dictionary<string, object>();
  469. ((Dictionary<string, object>)tree["quit"])[String.Empty] = quit;
  470. }
  471. private void ReadTreeLevel(Dictionary<string, object> level, XmlNode node, CommandDelegate fn)
  472. {
  473. Dictionary<string, object> next;
  474. string name;
  475. XmlNodeList nodeL = node.ChildNodes;
  476. XmlNodeList cmdL;
  477. CommandInfo c;
  478. foreach (XmlNode part in nodeL)
  479. {
  480. switch (part.Name)
  481. {
  482. case "Level":
  483. name = ((XmlElement)part).GetAttribute("Name");
  484. next = new Dictionary<string, object>();
  485. level[name] = next;
  486. ReadTreeLevel(next, part, fn);
  487. break;
  488. case "Command":
  489. cmdL = part.ChildNodes;
  490. c = new CommandInfo();
  491. foreach (XmlNode cmdPart in cmdL)
  492. {
  493. switch (cmdPart.Name)
  494. {
  495. case "Module":
  496. c.module = cmdPart.InnerText;
  497. break;
  498. case "Shared":
  499. c.shared = Convert.ToBoolean(cmdPart.InnerText);
  500. break;
  501. case "HelpText":
  502. c.help_text = cmdPart.InnerText;
  503. break;
  504. case "LongHelp":
  505. c.long_help = cmdPart.InnerText;
  506. break;
  507. case "Description":
  508. c.descriptive_help = cmdPart.InnerText;
  509. break;
  510. }
  511. }
  512. c.fn = new List<CommandDelegate>();
  513. c.fn.Add(fn);
  514. level[String.Empty] = c;
  515. break;
  516. }
  517. }
  518. }
  519. }
  520. public class Parser
  521. {
  522. // If an unquoted portion ends with an element matching this regex
  523. // and the next element contains a space, then we have stripped
  524. // embedded quotes that should not have been stripped
  525. private static Regex optionRegex = new Regex("^--[a-zA-Z0-9-]+=$");
  526. public static string[] Parse(string text)
  527. {
  528. List<string> result = new List<string>();
  529. int index;
  530. string[] unquoted = text.Split(new char[] {'"'});
  531. for (index = 0 ; index < unquoted.Length ; index++)
  532. {
  533. if (index % 2 == 0)
  534. {
  535. string[] words = unquoted[index].Split(new char[] {' '});
  536. bool option = false;
  537. foreach (string w in words)
  538. {
  539. if (w != String.Empty)
  540. {
  541. if (optionRegex.Match(w) == Match.Empty)
  542. option = false;
  543. else
  544. option = true;
  545. result.Add(w);
  546. }
  547. }
  548. // The last item matched the regex, put the quotes back
  549. if (option)
  550. {
  551. // If the line ended with it, don't do anything
  552. if (index < (unquoted.Length - 1))
  553. {
  554. // Get and remove the option name
  555. string optionText = result[result.Count - 1];
  556. result.RemoveAt(result.Count - 1);
  557. // Add the quoted value back
  558. optionText += "\"" + unquoted[index + 1] + "\"";
  559. // Push the result into our return array
  560. result.Add(optionText);
  561. // Skip the already used value
  562. index++;
  563. }
  564. }
  565. }
  566. else
  567. {
  568. result.Add(unquoted[index]);
  569. }
  570. }
  571. return result.ToArray();
  572. }
  573. }
  574. /// <summary>
  575. /// A console that processes commands internally
  576. /// </summary>
  577. public class CommandConsole : ConsoleBase, ICommandConsole
  578. {
  579. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  580. public event OnOutputDelegate OnOutput;
  581. public ICommands Commands { get; private set; }
  582. public CommandConsole(string defaultPrompt) : base(defaultPrompt)
  583. {
  584. Commands = new Commands();
  585. Commands.AddCommand(
  586. "Help", false, "help", "help [<item>]",
  587. "Display help on a particular command or on a list of commands in a category", Help);
  588. }
  589. private void Help(string module, string[] cmd)
  590. {
  591. List<string> help = Commands.GetHelp(cmd);
  592. foreach (string s in help)
  593. Output(s);
  594. }
  595. protected void FireOnOutput(string text)
  596. {
  597. OnOutputDelegate onOutput = OnOutput;
  598. if (onOutput != null)
  599. onOutput(text);
  600. }
  601. /// <summary>
  602. /// Display a command prompt on the console and wait for user input
  603. /// </summary>
  604. public void Prompt()
  605. {
  606. string line = ReadLine(m_defaultPrompt + "# ", true, true);
  607. if (line != String.Empty)
  608. Output("Invalid command");
  609. }
  610. public void RunCommand(string cmd)
  611. {
  612. string[] parts = Parser.Parse(cmd);
  613. Commands.Resolve(parts);
  614. }
  615. public override string ReadLine(string p, bool isCommand, bool e)
  616. {
  617. System.Console.Write("{0}", p);
  618. string cmdinput = System.Console.ReadLine();
  619. if (isCommand)
  620. {
  621. string[] cmd = Commands.Resolve(Parser.Parse(cmdinput));
  622. if (cmd.Length != 0)
  623. {
  624. int i;
  625. for (i=0 ; i < cmd.Length ; i++)
  626. {
  627. if (cmd[i].Contains(" "))
  628. cmd[i] = "\"" + cmd[i] + "\"";
  629. }
  630. return String.Empty;
  631. }
  632. }
  633. return cmdinput;
  634. }
  635. }
  636. }