static HeaderFile ReadHeaderFile(string path) { Console.Out.WriteLine("Processing: " + path); HeaderFile headerFile = new HeaderFile(); headerFile.filePath = path; StreamReader sr = new StreamReader(path); Regex regex = new Regex("#include *\"(_*/*.*[0-9]*[A-Z]*[a-z]*)+\""); // file name can contain _/.number or char Regex regex2 = new Regex("\"(_*/*.*[0-9]*[A-Z]*[a-z]*)+\""); String curLine; while ((curLine = sr.ReadLine()) != null) { Match m = regex.Match(curLine); if (m.Success) { String includeSection = curLine.Substring(m.Index, m.Length); m = regex2.Match(includeSection); String relativeHeaderPath = includeSection.Substring(m.Index, m.Length).Substring(1, m.Length - 2); String curDir = Path.GetDirectoryName(path); String incFilePath = Path.GetFullPath(curDir + "/" + relativeHeaderPath); if (File.Exists(incFilePath)) { headerFile.incList.Add(incFilePath); } else { Console.Out.WriteLine("Error: missing " + incFilePath); return(null); } } else { lineCount++; headerFile.fileBuff += "\r\n" + curLine; } } sr.Close(); return(headerFile); }
static List <HeaderFile> SerachForHeaderFiles(string sourceDir) { string[] fileEntries = Directory.GetFiles(Path.GetFullPath(sourceDir), "*.h", SearchOption.AllDirectories); List <HeaderFile> headerFileList = new List <HeaderFile>(); foreach (string fileName in fileEntries) { HeaderFile hf = ReadHeaderFile(fileName); if (hf != null) { headerFileList.Add(hf); } else { return(null); } } return(headerFileList); }
static bool IsRequiredHeadersWritten(HeaderFile headerFile, List <HeaderFile> WrittenFiles) { bool allWritten = true; for (int i = 0; i < headerFile.incList.Count; i++) { bool curFileFound = false; for (int j = 0; j < WrittenFiles.Count; j++) { if (WrittenFiles[j].filePath.CompareTo(headerFile.incList[i]) == 0) { curFileFound = true; break; } } if (!curFileFound) { allWritten = false; break; } } return(allWritten); }