Exemple #1
0
        static void SetupDefaultIncludePaths(SearchPaths searchPaths)
        {
            searchPaths.AddSearchPath(Environment.CurrentDirectory);

            string[] includePaths = (Environment.GetEnvironmentVariable("INCLUDE") ?? string.Empty).Split(';');
            foreach (string includePath in includePaths)
            {
                if (!searchPaths.AddSearchPath(includePath))
                {
                    Console.WriteLine($"Couldn't find '{includePath}' specified in %INCLUDE%");
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            SearchPaths searchPaths = new SearchPaths();

            SetupDefaultIncludePaths(searchPaths);

            CommandLineOptions options = new CommandLineOptions();

            Utilities.CommandLineSwitchParser commandLineParser = new Utilities.CommandLineSwitchParser();

            // todo: catch exceptions
            commandLineParser.Parse(args, options);

            // Parse command line arguments
            foreach (var path in options.I)
            {
                if (!string.IsNullOrEmpty(path) && !searchPaths.AddSearchPath(path))
                {
                    Console.WriteLine($"Couldn't add include directory '{path}'");
                }
            }

            // Find all cpp and header files
            Console.WriteLine("Finding source files...");
            IEnumerable <string> cppFilesToSearch = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.cpp", SearchOption.AllDirectories);
            IEnumerable <string> hFilesToSearch   = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.h", SearchOption.AllDirectories);

            List <string> allFiles = new List <string>();

            allFiles.AddRange(cppFilesToSearch);
            allFiles.AddRange(hFilesToSearch);

            Console.WriteLine($"{allFiles.Count} files found.");

            Regex includeRegex = new Regex(@"^\s*#include\s+[""<]([^""<>]+?)["">]", RegexOptions.Singleline | RegexOptions.Compiled);

            UniqueNodeList uniqueNodes = new UniqueNodeList(searchPaths, includeRegex);

            // Read each file
            HashSet <string> visited = new HashSet <string>();

            foreach (var file in allFiles)
            {
                Node node = uniqueNodes.GetNodeForPath(file);
                uniqueNodes.BuildHierarchy(node);

                Console.WriteLine(Tabulate(node.FilePath, 0));
                PrintNode(node, 1, visited);
            }
        }