示例#1
0
        public void RunSection(string fileName, string sectionName, string labelName)
        {
            // Run the selected script
            string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

            if (RTGlobal.RefFiles.ContainsKey(FileNameWithoutExtension))
            {
                _CurrentFile = RTGlobal.RefFiles[FileNameWithoutExtension];
                if (_CurrentFile.Sections.ContainsKey(sectionName))
                {
                    _CurrentSection = _CurrentFile.Sections[sectionName];

                    if (labelName != "")
                    {
                        if (_CurrentSection.Labels.ContainsKey(labelName))
                        {
                            _CurrentLineNumber = _CurrentSection.Labels[labelName];
                        }
                        else
                        {
                            Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2Label `0" + sectionName + " `2not found in `0" + Path.GetFileName(fileName) + " `4`b**`b`2"));
                            Door.ReadKey();
                            return;
                        }
                    }

                    RunScript(_CurrentSection.Script.ToArray());
                    return;
                }
                else
                {
                    Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2Section `0" + sectionName + " `2not found in `0" + Path.GetFileName(fileName) + " `4`b**`b`2"));
                    Door.ReadKey();
                    return;
                }
            }
            else
            {
                Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2File `0" + Path.GetFileName(fileName) + " `2not found. `4`b**`b`2"));
                Door.ReadKey();
                return;
            }
        }
示例#2
0
        public void RunSection(string fileName, string sectionName, string labelName)
        {
            // Run the selected script
            string FileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            if (RTGlobal.RefFiles.ContainsKey(FileNameWithoutExtension))
            {
                _CurrentFile = RTGlobal.RefFiles[FileNameWithoutExtension];
                if (_CurrentFile.Sections.ContainsKey(sectionName))
                {
                    _CurrentSection = _CurrentFile.Sections[sectionName];

                    if (labelName != "")
                    {
                        if (_CurrentSection.Labels.ContainsKey(labelName))
                        {
                            _CurrentLineNumber = _CurrentSection.Labels[labelName];
                        }
                        else
                        {
                            Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2Label `0" + sectionName + " `2not found in `0" + Path.GetFileName(fileName) + " `4`b**`b`2"));
                            Door.ReadKey();
                            return;
                        }
                    }

                    RunScript(_CurrentSection.Script.ToArray());
                    return;
                }
                else
                {
                    Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2Section `0" + sectionName + " `2not found in `0" + Path.GetFileName(fileName) + " `4`b**`b`2"));
                    Door.ReadKey();
                    return;
                }
            }
            else
            {
                Door.WriteLn(RTVariables.TranslateVariables("`4`b**`b `%ERROR : `2File `0" + Path.GetFileName(fileName) + " `2not found. `4`b**`b`2"));
                Door.ReadKey();
                return;
            }
        }
示例#3
0
        private static void LoadRefFile(string fileName)
        {
            // A place to store all the sections found in this file
            RTRefFile NewFile = new RTRefFile(fileName);

            // Where to store the info for the section we're currently working on
            string       NewSectionName = "_HEADER";
            RTRefSection NewSection     = new RTRefSection(NewSectionName);

            // Loop through the file
            string[] Lines = FileUtils.FileReadAllLines(fileName, RMEncoding.Ansi);
            foreach (string Line in Lines)
            {
                string LineTrimmed = Line.Trim().ToUpper();

                // Check for new section
                if (LineTrimmed.StartsWith("@#"))
                {
                    // Store last section we were working on in dictionary
                    if (NewFile.Sections.ContainsKey(NewSectionName))
                    {
                        // Section already exists, so we can't add it
                        // CASTLE4 has multiple DONE sections
                        // STONEB has multiple NOTHING sections
                        // Both appear harmless, but keep that in mind if either ever seems buggy
                    }
                    else
                    {
                        NewFile.Sections.Add(NewSectionName, NewSection);
                    }

                    // Get new section name (presumes only one word headers allowed, trims @# off start) and reset script block
                    NewSectionName = Line.Trim().Split(' ')[0].Substring(2);
                    NewSection     = new RTRefSection(NewSectionName);
                }
                else if (LineTrimmed.StartsWith("@LABEL "))
                {
                    NewSection.Script.Add(Line);

                    string[] Tokens = LineTrimmed.Split(' ');
                    NewSection.Labels.Add(Tokens[1].ToUpper(), NewSection.Script.Count - 1);
                }
                else if (LineTrimmed.StartsWith("@"))
                {
                    NewSection.Script.Add(Line);

                    #region Debug crap
                    //if (Debugger.IsAttached)
                    //{
                    //    // Also record command usage
                    //    string[] Tokens = LineTrimmed.Split(' ');
                    //    if (Tokens[0] == "@DO")
                    //    {
                    //        // Get the @DO command
                    //        string Command = string.Join(" ", Tokens);
                    //        string DOName = Command;
                    //        if (RTR._DOCommands.ContainsKey(Tokens[1]))
                    //        {
                    //            Command = Tokens[1];
                    //            DOName = "@DO " + Command;
                    //        }
                    //        else if ((Tokens.Length >= 3) && (RTR._DOCommands.ContainsKey(Tokens[2])))
                    //        {
                    //            Command = Tokens[2];
                    //            DOName = "@DO . " + Command;
                    //        }

                    //        // Determine if @DO command is known
                    //        if (RTR._DOCommands.ContainsKey(Command))
                    //        {
                    //            if (RTR._DOCommands[Command].Method.Name == "LogUnimplemented")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(DOName)) _UnimplementedCommandUsage[DOName] = 0;
                    //                _UnimplementedCommandUsage[DOName] = _UnimplementedCommandUsage[DOName] + 1;
                    //            }
                    //            else if (RTR._DOCommands[Command].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(DOName)) _UnusedCommandUsage[DOName] = 0;
                    //                _UnusedCommandUsage[DOName] = _UnusedCommandUsage[DOName] + 1;
                    //            }
                    //            else if (RTR._DOCommands[Command].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(DOName)) _ImplementedCommandUsage[DOName] = 0;
                    //                _ImplementedCommandUsage[DOName] = _ImplementedCommandUsage[DOName] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(DOName)) _UnknownCommandUsage[DOName] = 0;
                    //            _UnknownCommandUsage[DOName] = _UnknownCommandUsage[DOName] + 1;
                    //        }
                    //    }
                    //    else if (Tokens[0] == "@IF")
                    //    {
                    //        // Get the @IF command
                    //        string Command = string.Join(" ", Tokens);
                    //        string IFName = Command;
                    //        if (RTR._IFCommands.ContainsKey(Tokens[1]))
                    //        {
                    //            Command = Tokens[1];
                    //            IFName = "@IF " + Command;
                    //        }
                    //        else if (RTR._IFCommands.ContainsKey(Tokens[2]))
                    //        {
                    //            Command = Tokens[2];
                    //            IFName = "@IF . " + Command;
                    //        }

                    //        // Determine if @IF command is known
                    //        if (RTR._IFCommands.ContainsKey(Command))
                    //        {
                    //            if (RTR._IFCommands[Command].Method.Name == "LogUnimplementedFunc")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(IFName)) _UnimplementedCommandUsage[IFName] = 0;
                    //                _UnimplementedCommandUsage[IFName] = _UnimplementedCommandUsage[IFName] + 1;
                    //            }
                    //            else if (RTR._IFCommands[Command].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(IFName)) _UnusedCommandUsage[IFName] = 0;
                    //                _UnusedCommandUsage[IFName] = _UnusedCommandUsage[IFName] + 1;
                    //            }
                    //            else if (RTR._IFCommands[Command].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(IFName)) _ImplementedCommandUsage[IFName] = 0;
                    //                _ImplementedCommandUsage[IFName] = _ImplementedCommandUsage[IFName] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(IFName)) _UnknownCommandUsage[IFName] = 0;
                    //            _UnknownCommandUsage[IFName] = _UnknownCommandUsage[IFName] + 1;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (RTR._Commands.ContainsKey(Tokens[0]))
                    //        {
                    //            if (RTR._Commands[Tokens[0]].Method.Name == "LogUnimplemented")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(Tokens[0])) _UnimplementedCommandUsage[Tokens[0]] = 0;
                    //                _UnimplementedCommandUsage[Tokens[0]] = _UnimplementedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else if (RTR._Commands[Tokens[0]].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(Tokens[0])) _UnusedCommandUsage[Tokens[0]] = 0;
                    //                _UnusedCommandUsage[Tokens[0]] = _UnusedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else if (RTR._Commands[Tokens[0]].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(Tokens[0])) _ImplementedCommandUsage[Tokens[0]] = 0;
                    //                _ImplementedCommandUsage[Tokens[0]] = _ImplementedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(Tokens[0])) _UnknownCommandUsage[Tokens[0]] = 0;
                    //            _UnknownCommandUsage[Tokens[0]] = _UnknownCommandUsage[Tokens[0]] + 1;
                    //        }
                    //    }
                    //}
                    #endregion
                }
                else
                {
                    NewSection.Script.Add(Line);
                }
            }

            // Store last section we were working on in dictionary
            if (NewFile.Sections.ContainsKey(NewSectionName))
            {
                // Section already exists, so we can't add it
                // CASTLE4 has multiple DONE sections
                // STONEB has multiple NOTHING sections
                // Both appear harmless, but keep that in mind if either ever seems buggy
            }
            else
            {
                NewFile.Sections.Add(NewSectionName, NewSection);
            }

            RefFiles.Add(Path.GetFileNameWithoutExtension(fileName), NewFile);
        }
示例#4
0
        private static void LoadRefFile(string fileName)
        {
            // A place to store all the sections found in this file
            RTRefFile NewFile = new RTRefFile(fileName);

            // Where to store the info for the section we're currently working on
            string NewSectionName = "_HEADER";
            RTRefSection NewSection = new RTRefSection(NewSectionName);

            // Loop through the file
            string[] Lines = FileUtils.FileReadAllLines(fileName, RMEncoding.Ansi);
            foreach (string Line in Lines)
            {
                string LineTrimmed = Line.Trim().ToUpper();

                // Check for new section
                if (LineTrimmed.StartsWith("@#"))
                {
                    // Store last section we were working on in dictionary
                    if (NewFile.Sections.ContainsKey(NewSectionName))
                    {
                        // Section already exists, so we can't add it
                        // CASTLE4 has multiple DONE sections
                        // STONEB has multiple NOTHING sections
                        // Both appear harmless, but keep that in mind if either ever seems buggy
                    }
                    else
                    {
                        NewFile.Sections.Add(NewSectionName, NewSection);
                    }

                    // Get new section name (presumes only one word headers allowed, trims @# off start) and reset script block
                    NewSectionName = Line.Trim().Split(' ')[0].Substring(2);
                    NewSection = new RTRefSection(NewSectionName);
                }
                else if (LineTrimmed.StartsWith("@LABEL "))
                {
                    NewSection.Script.Add(Line);

                    string[] Tokens = LineTrimmed.Split(' ');
                    NewSection.Labels.Add(Tokens[1].ToUpper(), NewSection.Script.Count - 1);
                }
                else if (LineTrimmed.StartsWith("@"))
                {
                    NewSection.Script.Add(Line);

                    #region Debug crap
                    //if (Debugger.IsAttached)
                    //{
                    //    // Also record command usage
                    //    string[] Tokens = LineTrimmed.Split(' ');
                    //    if (Tokens[0] == "@DO")
                    //    {
                    //        // Get the @DO command
                    //        string Command = string.Join(" ", Tokens);
                    //        string DOName = Command;
                    //        if (RTR._DOCommands.ContainsKey(Tokens[1]))
                    //        {
                    //            Command = Tokens[1];
                    //            DOName = "@DO " + Command;
                    //        }
                    //        else if ((Tokens.Length >= 3) && (RTR._DOCommands.ContainsKey(Tokens[2])))
                    //        {
                    //            Command = Tokens[2];
                    //            DOName = "@DO . " + Command;
                    //        }

                    //        // Determine if @DO command is known
                    //        if (RTR._DOCommands.ContainsKey(Command))
                    //        {
                    //            if (RTR._DOCommands[Command].Method.Name == "LogUnimplemented")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(DOName)) _UnimplementedCommandUsage[DOName] = 0;
                    //                _UnimplementedCommandUsage[DOName] = _UnimplementedCommandUsage[DOName] + 1;
                    //            }
                    //            else if (RTR._DOCommands[Command].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(DOName)) _UnusedCommandUsage[DOName] = 0;
                    //                _UnusedCommandUsage[DOName] = _UnusedCommandUsage[DOName] + 1;
                    //            }
                    //            else if (RTR._DOCommands[Command].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(DOName)) _ImplementedCommandUsage[DOName] = 0;
                    //                _ImplementedCommandUsage[DOName] = _ImplementedCommandUsage[DOName] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(DOName)) _UnknownCommandUsage[DOName] = 0;
                    //            _UnknownCommandUsage[DOName] = _UnknownCommandUsage[DOName] + 1;
                    //        }
                    //    }
                    //    else if (Tokens[0] == "@IF")
                    //    {
                    //        // Get the @IF command
                    //        string Command = string.Join(" ", Tokens);
                    //        string IFName = Command;
                    //        if (RTR._IFCommands.ContainsKey(Tokens[1]))
                    //        {
                    //            Command = Tokens[1];
                    //            IFName = "@IF " + Command;
                    //        }
                    //        else if (RTR._IFCommands.ContainsKey(Tokens[2]))
                    //        {
                    //            Command = Tokens[2];
                    //            IFName = "@IF . " + Command;
                    //        }

                    //        // Determine if @IF command is known
                    //        if (RTR._IFCommands.ContainsKey(Command))
                    //        {
                    //            if (RTR._IFCommands[Command].Method.Name == "LogUnimplementedFunc")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(IFName)) _UnimplementedCommandUsage[IFName] = 0;
                    //                _UnimplementedCommandUsage[IFName] = _UnimplementedCommandUsage[IFName] + 1;
                    //            }
                    //            else if (RTR._IFCommands[Command].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(IFName)) _UnusedCommandUsage[IFName] = 0;
                    //                _UnusedCommandUsage[IFName] = _UnusedCommandUsage[IFName] + 1;
                    //            }
                    //            else if (RTR._IFCommands[Command].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(IFName)) _ImplementedCommandUsage[IFName] = 0;
                    //                _ImplementedCommandUsage[IFName] = _ImplementedCommandUsage[IFName] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(IFName)) _UnknownCommandUsage[IFName] = 0;
                    //            _UnknownCommandUsage[IFName] = _UnknownCommandUsage[IFName] + 1;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (RTR._Commands.ContainsKey(Tokens[0]))
                    //        {
                    //            if (RTR._Commands[Tokens[0]].Method.Name == "LogUnimplemented")
                    //            {
                    //                // Known, but not yet implemented
                    //                if (!_UnimplementedCommandUsage.ContainsKey(Tokens[0])) _UnimplementedCommandUsage[Tokens[0]] = 0;
                    //                _UnimplementedCommandUsage[Tokens[0]] = _UnimplementedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else if (RTR._Commands[Tokens[0]].Method.Name == "LogUnused")
                    //            {
                    //                // Known, but not known to be used
                    //                if (!_UnusedCommandUsage.ContainsKey(Tokens[0])) _UnusedCommandUsage[Tokens[0]] = 0;
                    //                _UnusedCommandUsage[Tokens[0]] = _UnusedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else if (RTR._Commands[Tokens[0]].Method.Name.StartsWith("Command"))
                    //            {
                    //                // Known and implemented
                    //                if (!_ImplementedCommandUsage.ContainsKey(Tokens[0])) _ImplementedCommandUsage[Tokens[0]] = 0;
                    //                _ImplementedCommandUsage[Tokens[0]] = _ImplementedCommandUsage[Tokens[0]] + 1;
                    //            }
                    //            else
                    //            {
                    //                // Should never happen
                    //                Crt.WriteLn("What's up with this? " + string.Join(" ", Tokens));
                    //                Crt.ReadKey();
                    //            }
                    //        }
                    //        else
                    //        {
                    //            // Unknown
                    //            if (!_UnknownCommandUsage.ContainsKey(Tokens[0])) _UnknownCommandUsage[Tokens[0]] = 0;
                    //            _UnknownCommandUsage[Tokens[0]] = _UnknownCommandUsage[Tokens[0]] + 1;
                    //        }
                    //    }
                    //}
                    #endregion
                }
                else
                {
                    NewSection.Script.Add(Line);
                }
            }

            // Store last section we were working on in dictionary
            if (NewFile.Sections.ContainsKey(NewSectionName))
            {
                // Section already exists, so we can't add it
                // CASTLE4 has multiple DONE sections
                // STONEB has multiple NOTHING sections
                // Both appear harmless, but keep that in mind if either ever seems buggy
            }
            else
            {
                NewFile.Sections.Add(NewSectionName, NewSection);
            }

            RefFiles.Add(Path.GetFileNameWithoutExtension(fileName), NewFile);
        }