Example #1
0
        private static void InterpreterLoop(ReplInterpreter interpreter, ShellContext shellContext)
        {
            Console.Write(interpreter.ClassicPrompt + " ");

            string s = Console.ReadLine();

            if (!interpreter.HasPendingCommand && s.StartsWith("!"))
            {
                ExecuteCommand(shellContext, s.Substring(1));
                return;
            }

            try
            {
                DynValue result = interpreter.Evaluate(s);

                if (result != null && result.Type != DataType.Void)
                {
                    Console.WriteLine("{0}", result);
                }
            }
            catch (InterpreterException ex)
            {
                Console.WriteLine("{0}", ex.DecoratedMessage ?? ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex.Message);
            }
        }
Example #2
0
		private static void InterpreterLoop(ReplInterpreter interpreter, ShellContext shellContext)
		{
			Console.Write(interpreter.ClassicPrompt + " ");

			string s = Console.ReadLine();

			if (!interpreter.HasPendingCommand && s.StartsWith("!"))
			{
				ExecuteCommand(shellContext, s.Substring(1));
				return;
			}

			try
			{
				DynValue result = interpreter.Evaluate(s);

				if (result != null && result.Type != DataType.Void)
					Console.WriteLine("{0}", result);
			}
			catch (InterpreterException ex)
			{
				Console.WriteLine("{0}", ex.DecoratedMessage ?? ex.Message);
			}
			catch (Exception ex)
			{
				Console.WriteLine("{0}", ex.Message);
			}
		}
Example #3
0
        private static void ExecuteCommand(ShellContext shellContext, string cmdline)
        {
            StringBuilder cmd  = new StringBuilder();
            StringBuilder args = new StringBuilder();
            StringBuilder dest = cmd;

            for (int i = 0; i < cmdline.Length; i++)
            {
                if (dest == cmd && cmdline[i] == ' ')
                {
                    dest = args;
                    continue;
                }

                dest.Append(cmdline[i]);
            }

            string scmd  = cmd.ToString().Trim();
            string sargs = args.ToString().Trim();

            ICommand C = CommandManager.Find(scmd);

            if (C == null)
            {
                Console.WriteLine("Invalid command '{0}'.", scmd);
            }
            else
            {
                C.Execute(shellContext, sargs);
            }
        }
Example #4
0
        private static bool CheckArgs(string[] args, ShellContext shellContext)
        {
            if (args.Length == 0)
            {
                return(false);
            }

            if (args.Length == 1 && args[0].Length > 0 && args[0][0] != '-')
            {
                Script script = new Script();
                script.DoFile(args[0]);
            }

            if (args[0] == "-H" || args[0] == "--help" || args[0] == "/?" || args[0] == "-?")
            {
                ShowCmdLineHelpBig();
            }

            return(true);
        }
Example #5
0
        private static void InterpreterLoop(ReplInterpreter interpreter, ShellContext shellContext)
        {
            Console.Write(interpreter.ClassicPrompt + " ");

            string s = Console.ReadLine();

            try
            {
                DynValue result = interpreter.Evaluate(s);

                if (result != null && result.Type != DataType.Void)
                {
                    Console.WriteLine("{0}", result);
                }
            }
            catch (InterpreterException ex)
            {
                Console.WriteLine("{0}", ex.DecoratedMessage ?? ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex.Message);
            }
        }
Example #6
0
        private static bool CheckArgs(string[] args, ShellContext shellContext)
        {
            if (args.Length == 0)
            {
                return(false);
            }

            if (args.Length == 1 && args[0].Length > 0 && args[0][0] != '-')
            {
                Script script = new Script();
                script.DoFile(args[0]);
            }

            if (args[0] == "-H" || args[0] == "--help" || args[0] == "/?" || args[0] == "-?")
            {
                ShowCmdLineHelpBig();
            }
            else if (args[0] == "-X")
            {
                if (args.Length == 2)
                {
                    ExecuteCommand(shellContext, args[1]);
                }
                else
                {
                    Console.WriteLine("Wrong syntax.");
                    ShowCmdLineHelp();
                }
            }
            else if (args[0] == "-W")
            {
                bool   internals     = false;
                string dumpfile      = null;
                string destfile      = null;
                string classname     = null;
                string namespacename = null;
                bool   useVb         = false;
                bool   fail          = true;

                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i] == "--internals")
                    {
                        internals = true;
                    }
                    else if (args[i] == "--vb")
                    {
                        useVb = true;
                    }
                    else if (args[i].StartsWith("--class:"))
                    {
                        classname = args[i].Substring("--class:".Length);
                    }
                    else if (args[i].StartsWith("--namespace:"))
                    {
                        namespacename = args[i].Substring("--namespace:".Length);
                    }
                    else if (dumpfile == null)
                    {
                        dumpfile = args[i];
                    }
                    else if (destfile == null)
                    {
                        destfile = args[i];
                        fail     = false;
                    }
                    else
                    {
                        fail = true;
                    }
                }

                if (fail)
                {
                    Console.WriteLine("Wrong syntax.");
                    ShowCmdLineHelp();
                }
                else
                {
                    HardWireCommand.Generate(useVb ? "vb" : "cs", dumpfile, destfile, internals, classname, namespacename);
                }
            }

            return(true);
        }
Example #7
0
		private static void ExecuteCommand(ShellContext shellContext, string cmdline)
		{
			StringBuilder cmd = new StringBuilder();
			StringBuilder args = new StringBuilder();
			StringBuilder dest = cmd;

			for (int i = 0; i < cmdline.Length; i++)
			{
				if (dest == cmd && cmdline[i] == ' ')
				{
					dest = args;
					continue;
				}

				dest.Append(cmdline[i]);
			}

			string scmd = cmd.ToString().Trim();
			string sargs = args.ToString().Trim();

			ICommand C = CommandManager.Find(scmd);

			if (C == null)
				Console.WriteLine("Invalid command '{0}'.", scmd);
			else
				C.Execute(shellContext, sargs);
		}
Example #8
0
		private static bool CheckArgs(string[] args, ShellContext shellContext)
		{
			if (args.Length == 0)
				return false;

			if (args.Length == 1 && args[0].Length > 0 && args[0][0] != '-')
			{
				Script script = new Script();
				script.DoFile(args[0]);
			}

			if (args[0] == "-H" || args[0] == "--help" || args[0] == "/?" || args[0] == "-?")
			{
				ShowCmdLineHelpBig();
			}
			else if (args[0] == "-X")
			{
				if (args.Length == 2)
				{
					ExecuteCommand(shellContext, args[1]);
				}
				else
				{
					Console.WriteLine("Wrong syntax.");
					ShowCmdLineHelp();
				}
			}
			else if (args[0] == "-W")
			{
				bool internals = false;
				string dumpfile = null;
				string destfile = null;
				string classname = null;
				string namespacename = null;
				bool useVb = false;
				bool fail = true;

				for (int i = 1; i < args.Length; i++)
				{
					if (args[i] == "--internals")
						internals = true;
					else if (args[i] == "--vb")
						useVb = true;
					else if (args[i].StartsWith("--class:"))
						classname = args[i].Substring("--class:".Length);
					else if (args[i].StartsWith("--namespace:"))
						namespacename = args[i].Substring("--namespace:".Length);
					else if (dumpfile == null)
						dumpfile = args[i];
					else if (destfile == null)
					{
						destfile = args[i];
						fail = false;
					}
					else fail = true;
				}

				if (fail)
				{
					Console.WriteLine("Wrong syntax.");
					ShowCmdLineHelp();
				}
				else
				{
					HardWireCommand.Generate(useVb ? "vb" : "cs", dumpfile, destfile, internals, classname, namespacename);
				}
			}

			return true;
		}