コード例 #1
0
 private void parsefile(string file)
 {
     if (File.Exists(file))
     {
         StreamReader      reader   = new StreamReader(file);
         string            content  = reader.ReadToEnd();
         string[]          elements = content.Split(' ');
         CommandLineparser p        = new CommandLineparser();
         p.Init();
         p.parseOptions(elements);
         updateModel(p);
     }
 }
コード例 #2
0
        public ProjectModel Fac_getProjectModel(string[] args)
        {
            model = new ProjectModel();
            CommandLineparser parser = new CommandLineparser();

            parser.Init();
            parser.parseOptions(args);
            if (args.Length == 0)
            {
                return(null);
            }
            else if (args.Length > 0)
            {
                if (parser.CommandLineOptions["-file"].Count > 0)
                {
                    foreach (string f in parser.CommandLineOptions["-file"])
                    {
                        parsefile(f);
                    }
                }
                else
                {
                    updateModel(parser);
                }

                foreach (string path in model.IncludePaths)
                {
                    path.Replace('/', '\\');
                }
                foreach (string path in model.CommonHeaders)
                {
                    path.Replace('/', '\\');
                }
                foreach (string path in model.LibraryPaths)
                {
                    path.Replace('/', '\\');
                }

                model.IncludePaths  = model.IncludePaths.Distinct <string>().ToList();
                model.CommonHeaders = model.CommonHeaders.Distinct <string>().ToList();
                foreach (string path in model.IncludePaths)
                {
                    if (Directory.Exists(path))
                    {
                        model.HeaderFiles.AddRange(Directory.GetFiles(path, "*.h", SearchOption.TopDirectoryOnly));
                    }
                }
                foreach (string path in model.SourcePaths)
                {
                    if (File.Exists(path))
                    {
                        model.SourceFiles.Add(path);
                    }
                }
                model.SourceFiles = model.SourceFiles.Distinct().ToList();
                if (model.IncludePaths.Count == 0)
                {
                    model.HeaderFiles.AddRange(Directory.GetFiles(model.RootDir.Trim(), "*.h", SearchOption.AllDirectories));
                    foreach (string file in model.HeaderFiles)
                    {
                        DirectoryInfo di = new DirectoryInfo(file);
                        while (di.FullName != model.RootDir)
                        {
                            di = di.Parent;
                            model.IncludePaths.Add(di.FullName);
                        }
                    }
                    model.IncludePaths = model.IncludePaths.Distinct().ToList();
                }

                if (model.SourcePaths.Count == 0)
                {
                    model.SourceFiles.AddRange(Directory.GetFiles(model.RootDir.Trim(), "*.c", SearchOption.AllDirectories));
                    foreach (string file in model.SourceFiles)
                    {
                        DirectoryInfo di = new DirectoryInfo(file);

                        while (di.FullName != model.RootDir)
                        {
                            di = di.Parent;
                            model.IncludePaths.Add(di.FullName);
                        }
                    }
                    model.IncludePaths = model.IncludePaths.Distinct().ToList();
                }
                model.HeaderFiles = model.HeaderFiles.Distinct().ToList();
                model.SourceFiles = model.SourceFiles.Distinct().ToList();
            }
            Updateclangoptions();
            updateSwcConfig();

            return(model);
        }
コード例 #3
0
 private void updateModel(CommandLineparser parser)
 {
     if (parser.CommandLineOptions["-root"].Count > 0)
     {
         model.RootDir = parser.CommandLineOptions["-root"][parser.CommandLineOptions["-root"].Count - 1];
     }
     if (parser.CommandLineOptions["-include"].Count > 0)
     {
         model.CommonHeaders.AddRange(parser.CommandLineOptions["-include"]);
     }
     if (parser.CommandLineOptions["-I"].Count > 0)
     {
         model.IncludePaths.AddRange(parser.CommandLineOptions["-I"]);
     }
     if (parser.CommandLineOptions["-S"].Count > 0)
     {
         model.SourcePaths.AddRange(parser.CommandLineOptions["-S"]);
     }
     if (parser.CommandLineOptions["-l"].Count > 0)
     {
         model.LibraryPaths.AddRange(parser.CommandLineOptions["-l"]);
     }
     if (parser.CommandLineOptions["-L"].Count > 0)
     {
         model.Libraries.AddRange(parser.CommandLineOptions["-L"]);
     }
     if (parser.CommandLineOptions["-D"].Count > 0)
     {
         model.MacroDefines.AddRange(parser.CommandLineOptions["-D"]);
     }
     if (parser.CommandLineOptions["-O"].Count > 0)
     {
         model.CodeXmlModel = parser.CommandLineOptions["-O"][parser.CommandLineOptions["-O"].Count - 1];
     }
     if (parser.CommandLineOptions["-SWCConfig"].Count > 0)
     {
         model.SWCConfig = parser.CommandLineOptions["-SWCConfig"][parser.CommandLineOptions["-SWCConfig"].Count - 1];
     }
     if (parser.CommandLineOptions["-g"].Count > 0)
     {
         model.UmlModel = parser.CommandLineOptions["-g"][parser.CommandLineOptions["-g"].Count - 1];
     }
     if (parser.CommandLineOptions["-F"].Count > 0)
     {
         model.SrcListFile = parser.CommandLineOptions["-F"][parser.CommandLineOptions["-F"].Count - 1];
         if (File.Exists(model.SrcListFile))
         {
             model.SourcePaths.Clear();
             string line = "";
             using (StreamReader reader = new StreamReader(model.SrcListFile))
             {
                 while ((line = reader.ReadLine()) != null)
                 {
                     if (File.Exists(line))
                     {
                         model.SourcePaths.Add(line);
                     }
                 }
             }
         }
     }
 }