Exemple #1
0
 /*
  * Converts argument to integer or return default value
  */
 public static int Int(this Argumenter a, int i, int d = 0)
 {
     try
     {
         return(int.Parse(a.Get(i)));
     } catch (Exception) { }
     return(d);
 }
Exemple #2
0
        /*
         * Get everything that comes after the command
         */
        public static string RawString(this Argumenter a, bool lower = false)
        {
            if (a.FormatStr.Count < a.Offset + 1)
            {
                return("");
            }
            string s = a.Cmd;

            for (int i = 0; i < a.Offset + 1; i++)
            {
                try
                {
                    s = s.Substring(a.FormatStr[i][1].Length + 1).Trim();
                } catch (Exception) { }
            }
            if (lower)
            {
                return(s.ToLower());
            }
            return(s);
        }
Exemple #3
0
        public bool RunCommand(string interp, bool ExpectsOutput = false, bool pretty = false)
        {
            if (pretty)
            {
                t.ColorWrite("$f> {0}", interp);
            }
            if (Hide)
            {
                t.hide = true;
            }
            else
            {
                t.hide = false;
            }
            Return = null;
            Command cmd = null;
            Thread  ct  = new Thread(() =>
            {
                Argumenter a      = new Argumenter(interp, true);
                CurrentArgumenter = a;
                a.SetM(this);
                if (a.GetRaw(0).Trim().Length == 0)
                {
                    return;
                }
                a.SetM(this);
                Command c = null;
                Action <Command> PickThis = (c_) =>
                {
                    a.Switches = c.Switches;
                    a.Params   = c.Parameters;
                    a.AllSP    = c.AllSP;
                    cmd        = c;
                };
                try
                {
                    c = Cmds[a.GetRaw(0).ToLower()];
                    PickThis(c);
                }
                catch (Exception)
                {
                    try
                    {
                        if (c == null)
                        {
                            CommandGroup g = Groups[a.GetRaw(0).ToLower()];
                            c = g.C[a.GetRaw(1).ToLower()];
                            PickThis(c);
                            if (c != null)
                            {
                                a.AddOffset();
                            }
                        }
                    } catch (Exception) { }
                }
                if (c == null)
                {
                    t.ColorWrite("$cInvalid command.");
                    return;
                }
                if (!Equals(c, null))
                {
                    if (a.Parse(c.ParseSW, c.ParsePR))
                    {
                        t.SetForeColor('f');

                        if (a.OutType != Argumenter.OutputType.None)
                        {
                            t.StartBuffer(true);
                        }
                        a.ExpectsOutput = ExpectsOutput;
#if (DEBUG)
                        Return = c.Run(t, a);
#else
                        try
                        {
                            Return = c.Run(t, a);
                        } catch (Exception e)
                        {
                            Trace(e);
                        }
#endif
                        if (!Equals(cmd.Exit, null))
                        {
                            cmd.Exit.Invoke();
                        }
                        if (Return == null)
                        {
                            Ret = new UserVar(new Null());
                        }
                        else
                        {
                            Ret = new UserVar(Return);
                        }

                        if (a.OutType != Argumenter.OutputType.None)
                        {
                            Stream s = t.EndStreamBuffer();
                            a.WriteOutput(s, Ret);
                            t.KillBuffer();
                        }
                    }
                }
            });

            ct.SetApartmentState(ApartmentState.STA);
            ct.Start();
            while (ct.IsAlive)
            {
                Thread.Sleep(100);
                if (killthread)
                {
                    ct.Abort();
                    ct.Interrupt();
                    if (!Equals(cmd.Exit, null))
                    {
                        cmd.Exit.Invoke();
                    }
                }
            }
            return(false);
        }
Exemple #4
0
 public object Run(TerminalController Console, Argumenter Arg)
 {
     return(Main.Invoke(Arg));
 }