Пример #1
0
        private void CalculateExec(IList<string> rawloc)
        {
            //deprecated because too many forever loop situations :(
            BatchMethod main = new BatchMethod("Main");
            BatchExec.Add(main);
            int lineno = 0;
            while (lineno != rawloc.Count)
            {
                if (rawloc[lineno].ToLower().Replace(" ", "").StartsWith("goto"))
                {
                    if (rawloc[lineno].ToLower().Replace(" ", "").Length < "goto".Length + 2)
                    {
                        throw new InvalidOperationException(@"Null error happened on batchfile line: " + lineno);
                    }
                    lineno = FindMethod(rawloc[lineno].Replace(" ", "").Replace("goto", ""), rawloc);

                    //  BatchExec.Add(new BatchMethod(rawloc[lineno].Replace(" ", "").Replace(":", "")));
                    //  BatchExec.Add(new BatchMethod(rawloc[lineno].Replace(" ", "").Replace("goto", "")));
                    lineno++;
                }
                if (rawloc[lineno].Replace(" ", "").StartsWith(":"))
                {
                    BatchExec.Add(new BatchMethod(rawloc[lineno].Replace(" ", "").Replace(":", "")));
                }
                // Console.Clear();
                lineno++;
            }
        }
Пример #2
0
        public void ConvertMethod(BatchMethod bm)
        {
            CSharpMethod csm = new CSharpMethod(bm.MethodName);
            if (csm.MethodName == "Main")
            {
                csm.code.Add("" + "Console.Clear(); //required line of code");
            }
            foreach (var loc in bm.code)
            {

                if (!echooff && !loc.StartsWith("@"))
                {

                    csm.code.Add("" + "Console.Write(Environment.NewLine);" + Environment.NewLine + "\t\t" + "Console.WriteLine(System.Environment.CurrentDirectory+\">" + loc + "\"); //echo is on so printing command");
                }
                csm.code.Add(ConvertLoc(loc));
            }
            bool hasgoto = false;
            foreach (var loc in bm.code)
            {
                if (loc.ToLower().StartsWith("goto"))
                {
                    hasgoto = true;
                    continue;
                }
            }
            if (!hasgoto)
            {
                try
                {
                    BatchMethod nextmethod = Methods[Methods.IndexOf(bm) + 1];
                    csm.code.Add("\t"+nextmethod.MethodName + "(); //proceed to next method");
                }
                catch { csm.code.Add("" + "Environment.Exit(0); //end of program"); }
            }
            CSharpMethods.Add(csm);
        }