예제 #1
0
파일: Cmd.cs 프로젝트: attackgithub/escript
        public static object MethodCleanup(string MethodName)
        {
            List <EVariable> removeList = new List <EVariable>();

            for (int idx = 0; idx < Variables.VarList.Count; idx++)
            {
                EVariable var = Variables.VarList[idx];

                for (int optionIdx = 0; optionIdx < var.Options.Count; optionIdx++)
                {
                    string option = var.Options[optionIdx];
                    if (GlobalVars.RemoveDirtFromString(option) == "Method=" + GlobalVars.RemoveDirtFromString(MethodName))
                    {
                        removeList.Add(var);
                    }
                }
            }

            foreach (var var in removeList)
            {
                Program.Debug("Removing " + var.Name + " because of " + MethodName + " cleanup");
                Variables.Remove(var);
            }

            return(1);
        }
예제 #2
0
        private void CleanCode()
        {
            for (int m = 0; m < ScriptContent.Length; m++)
            {
                ScriptContent[m] = GlobalVars.RemoveDirtFromString(ScriptContent[m]);

                if (ScriptContent[m].StartsWith("//"))
                {
                    GlobalVars.RemoveEntry(ScriptContent, ScriptContent[m]);
                }
            }
        }
예제 #3
0
 public static void CommandLine()
 {
     ScriptColor = ConsoleColor.White;
     Cmd.Process("ShowConsole");
     new Thread(CheckUpdates).Start();
     Variables.Set("showResult", "1");
     GlobalVars.StopProgram   = false;
     EConsole.ForegroundColor = ConsoleColor.White;
     EConsole.WriteLine("Need help? Type: help");
     if (!GlobalVars.IsCompiledScript && !System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("\\ESCRIPT\\escript.exe"))
     {
         EConsole.WriteLine("To install this copy of ESCRIPT type: install");
     }
     while (true)
     {
         EConsole.ForegroundColor = ConsoleColor.Green;
         EConsole.Write(Variables.GetValue("invitation"));
         EConsole.ForegroundColor = ConsoleColor.White;
         string line = EConsole.ReadLine();
         EConsole.ForegroundColor = ScriptColor;
         SetResult(Cmd.Process(GlobalVars.RemoveDirtFromString(line)));
         if (Variables.GetValue("showResult") == "1")
         {
             PrintResult(Variables.GetValue("result"));
         }
         if (Variables.GetValue("forceGC") == "1")
         {
             GC.Collect();
             GC.WaitForPendingFinalizers();
         }
         if (GlobalVars.StopProgram)
         {
             break;
         }
     }
 }
예제 #4
0
        private void GenerateMethods()
        {
            for (int m = 0; m < ScriptContent.Length; m++)//methods & labels & dirtycode
            {
                if (ScriptContent[m].Length <= 1)
                {
                    continue;
                }
                if (ScriptContent[m].StartsWith("//"))
                {
                    continue;
                }
                if (ScriptContent[m].StartsWith("func "))
                {
                    int methodStartIdx = 0;
                    if (ScriptContent[m + 1].StartsWith("{"))
                    {
                        methodStartIdx = m + 2;
                    }
                    EMethod thisMethod = new EMethod();
                    thisMethod.Name = ScriptContent[m].Remove(0, "func ".Length).Split(' ')[0];
                    try
                    {
                        var argList1         = ScriptContent[m].Remove(0, "func ".Length + thisMethod.Name.Length + 1);
                        var mth              = Cmd.GetMethodsInsideOfString(argList1);
                        var argListNoDefault = argList1;

                        foreach (var argStr in mth)
                        {
                            string fstr = "=" + argStr.text.ToString();
                            argListNoDefault = argListNoDefault.Replace(fstr, "");
                        }

                        var argList = argListNoDefault.Split(' ').ToList();

                        foreach (var arg in argList)
                        {
                            if (arg.StartsWith("(") && arg.EndsWith(")"))
                            {
                                thisMethod.Options.Add(arg.Remove(0, 1).Remove(arg.Length - 2, 1));
                                continue;
                            }
                            EMethodArgument argObj = new EMethodArgument();
                            argObj.Name = arg;
                            foreach (var argStr in mth)
                            {
                                string fstr = arg + "=" + argStr.text.ToString();
                                if (argList1.Contains(fstr))
                                {
                                    argObj.DefaultValue = argStr.text.ToString().Remove(0, 1).Remove(argStr.text.ToString().Length - 2, 1);
                                }
                                else
                                {
                                }
                            }
                            thisMethod.Arguments.Add(argObj);
                        }
                    }
                    catch
                    {
                        //EConsole.WriteLine($"ERROR PROCESSING {thisMethod.Name}!{Environment.NewLine}{ex.ToString()}", true, ConsoleColor.Red);
                    }

                    int end = 0;
                    for (int c = methodStartIdx; c < ScriptContent.Length; c++)
                    {
                        if (!ScriptContent[c].StartsWith("}") && !ScriptContent[m].StartsWith("//"))
                        {
                            ScriptContent[c] = GlobalVars.RemoveDirtFromString(ScriptContent[c]);

                            if (ScriptContent[c].Length <= 0)
                            {
                                continue;
                            }
                            if (ScriptContent[c].StartsWith("//"))
                            {
                                continue;
                            }

                            thisMethod.Code.Add(ScriptContent[c]);
                        }
                        else
                        {
                            end = c;
                            break;
                        }
                    }
                    m = end;

                    for (int x = 0; x < GlobalVars.Methods.Count; x++)
                    {
                        if (GlobalVars.Methods[x].Name == thisMethod.Name)
                        {
                            Program.Debug($"Overwriting exiting method ({thisMethod.Name})");
                            GlobalVars.Methods.Remove(GlobalVars.Methods[x]);
                        }
                    }

                    GlobalVars.Methods.Add(thisMethod);

                    Program.Debug("Added method: " + thisMethod.Name + ", line: " + m + 1, ConsoleColor.DarkGreen);


                    if (thisMethod.Arguments.Count >= 1)
                    {
                        Program.Debug("Arguments:");
                        foreach (var argument in thisMethod.Arguments)
                        {
                            Program.Debug($"\t{argument.Name} = {argument.DefaultValue}");
                        }
                    }

                    if (thisMethod.Options.Count >= 1)
                    {
                        Program.Debug("Options:");
                        foreach (var option in thisMethod.Options)
                        {
                            Program.Debug($"\t{option}");
                        }
                    }
                }
            }
        }