コード例 #1
0
        static void Main(string[] args)
        {
            var opts = new Options(args);

            // Get a list of filenames from options
            var fileArray = opts.GetFiles();

            // Extract YML header values for output
            StringBuilder sb = new StringBuilder();
            var           cb = new CommandBuilder(opts.GetOutput(), opts.Tag);

            // Parse each file in the list
            foreach (var filename in fileArray)
            {
                cb.ParseFile(filename);
            }

            // Write results to the output file or stdout
            cb.WriteFile(opts.Use_output);

#if DEBUG
            var    mydocs      = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string fileName    = "MUT-log-" + DateTime.Now.ToFileTime() + ".txt";
            string LogFileName = System.IO.Path.Combine(mydocs, fileName);
            YMLMeister.PrintLog(LogFileName);
#endif

            Console.WriteLine("Output was successfully written to {0}.", cb.OutputFile);

            // debug trap so you can see it at work; remove from production
            Console.WriteLine("Press any key to continue... ... ...");
            Console.ReadLine();
        }
コード例 #2
0
        public void ParseFile(string filename)
        {
            string filedata = File.ReadAllText(filename);

            // Get YML

            var beg = filedata.IndexOf("---") + 3;
            var end = filedata.IndexOf("---", beg); // We assume "---" never appears inside a tag

            if ((beg == -1) || (end == -1))
            {
                // only warn if lack of tag might mean something
                if (!filename.Contains("TOC.md"))
                {
                    Console.WriteLine("CommandBuilder: could not find metadata section in {0}", filename);
                }
                return;
            }

            // Parse YML into a list of Tag objects
            YMLMeister.CurrentFile = filename;
            var tagList = YMLMeister.ParseYML2(filedata, this.Tag);

            // Append each tag's data to the output string
            foreach (var tag in tagList)
            {
                sb.Append(filename);
                sb.Append("\t");
                sb.Append("IGNORE");
                sb.Append("\t");
                sb.Append(tag.TagName);
                sb.Append("\t");
                sb.Append(tag.TagValuesBracketedOrSingle());
                sb.Append("\t");
                sb.Append(tag.TagFormatString);
                sb.Append(Environment.NewLine);
            }

            return;
        }