//===================================================================== private void Preprocess(SourceFile file) { System.Console.Out.WriteLine("preprocessing " + file.FullPath); StreamReader sr = new StreamReader(file.FullPath); String line; while (null != (line = sr.ReadLine())) { file.NumLines++; line = line.Trim(); if (! line.StartsWith("#include")) continue; line = line.Substring(8).Trim(); if (line == "") continue; String includeFileName; if (line[0] == '\"') { int n = line.IndexOf('\"', 1); if (n < 0) return; includeFileName = line.Substring(1, n - 1); } else if (line[0] == '<') { int n = line.IndexOf('>', 1); if (n < 0) return; includeFileName = line.Substring(1, n - 1); } else continue; SourceFile includeFile = this.FindFile(includeFileName); if (includeFile == null) throw new Exception("unknown include file: " + includeFileName); file.IncludeFiles.Add(includeFile); } sr.Close(); }
//===================================================================== /// <summary> /// Writes a file that documents a single source file. /// </summary> public void WriteFileFile(String fileName, SourceFile sf) { System.Console.Out.WriteLine("writing " + fileName); StreamWriter w = new StreamWriter(fileName); w.WriteLine("<html>\r\n<head>" + "<link rel=stylesheet type=\"text/css\" " + "href=\"../libref.css\">" + "<title>" + sf.ShortName + "</title>" // + "<script type=\"text/javascript\" " // + "src=\"../libref.js\"></script>" // + "</head><body onload=\"frmLd()\">"); + "</head><body>"); this.WriteFileTitle(w, "file", sf.ShortName, Hyperlink("../" + this.SourceFileName(sf), "source file"), null); w.WriteLine("<table class=nav><tr>"); WriteFileTOCentry(w, "Classes", "_ClassSummary_", null); if (! sf.IsHeaderFile) WriteFileTOCentry(w, "Objects", "_ObjectSummary_", null); WriteFileTOCentry(w, "Functions", "_FunctionSummary_", "_Functions_"); if (sf.IsHeaderFile) { WriteFileTOCentry(w, "Macros", "_MacroSummary_", "_Macros_"); WriteFileTOCentry(w, "Enums", "_EnumSummary_", "_Enums_"); WriteFileTOCentry(w, "Templates", "_TemplateSummary_", "_Templates_"); } w.WriteLine("</table><div class=fdesc>"); if ((sf.Description == null) || (sf.Description == "")) w.WriteLine("<i>no description available</i>"); else w.WriteLine(EncodeEntities(sf.Description)); w.WriteLine("</div>"); this.WriteMajorHeading(w, "_ClassSummary_", "Summary of Classes", ""); if (sf.Classes.Count == 0) w.WriteLine("<i>(none)</i>"); else { w.WriteLine("<code>"); foreach (ClassDef c in sf.Classes) this.WriteSummaryEntry(w, null, c.Name, "../" + this.ObjectFileName(c)); w.WriteLine("</code>"); } if (! sf.IsHeaderFile) { this.WriteMajorHeading(w, "_ObjectSummary_", "Summary of Global Objects", ""); if (sf.GlobalObjects.Count == 0) w.WriteLine("<i>(none)</i>"); else { w.WriteLine("<code>"); foreach (ObjectDef o in sf.GlobalObjects) this.WriteSummaryEntry(w, null, o.Name, "../" + this.ObjectFileName(o)); w.WriteLine("</code>"); } } this.WriteMajorHeading(w, "FunctionSummary_", "Summary of Global Functions", ""); this.WriteSymbolSummary(w, sf.GlobalFunctions, ""); if (sf.IsHeaderFile) { this.WriteMajorHeading(w, "_MacroSummary_", "Summary of Macros", ""); this.WriteSymbolSummary(w, sf.Macros, ""); this.WriteMajorHeading(w, "_EnumSummary_", "Summary of Enums", ""); this.WriteSymbolSummary(w, sf.Enums, ""); this.WriteMajorHeading(w, "_TemplateSummary_", "Summary of Templates", ""); this.WriteSymbolSummary(w, sf.Templates, ""); } this.WriteMajorHeading(w, "_Functions_", "Global Functions", ""); if (sf.GlobalFunctions.Count == 0) w.WriteLine("<i>(none)</i>"); else { foreach (FunctionDef f in sf.GlobalFunctions) this.WriteFunction(w, f); } if (sf.IsHeaderFile) { this.WriteMajorHeading(w, "_Macros_", "Macros", ""); foreach (MacroDef m in sf.Macros) this.WriteMacro(w, m); this.WriteMajorHeading(w, "_Enums_", "Enums", ""); if (sf.EnumGroups.Count == 0) w.WriteLine("<i>(none)</i>"); else { foreach (EnumGroup g in sf.EnumGroups) this.WriteEnums(w, g); } this.WriteMajorHeading(w, "_Templates_", "Templates", ""); if (sf.Templates.Count == 0) w.WriteLine("<i>(none)</i>"); else { foreach (TemplateDef t in sf.Templates) this.WriteTemplate(w, t); } } this.WriteHtmlFooter(w); w.Close(); }
//===================================================================== /// <summary> /// Writes an index of classes for a single source file. /// </summary> public void WriteClassIndex(SourceFile sf) { StreamWriter w = new StreamWriter(this.OutputDir + this.ClassIndexFileName(sf)); w.WriteLine("<html><head>" + "<link rel=stylesheet type=\"text/css\" " + "href=\"../libref.css\">" + "<title>Adv3Lite: Index of Classes in " + sf.ShortName + "</title>" + "</head><body>" + "<h2>Classes</h2>"); if (sf.Classes.Count == 0) w.WriteLine("<i>(none)</i><br>"); foreach (ClassDef c in sf.Classes) w.WriteLine(Hyperlink("../" + this.ObjectFileName(c), c.Name, "main", "<code>" + c.Name + "</code>") + "<br>"); w.WriteLine("</body></html>"); w.Close(); }
//===================================================================== /// <summary> /// Returns the name of the file documentation file for the given file, /// relative to the OutputDir. /// </summary> private String SourceFileName(SourceFile s) { return SourceDir + "/" + s.ShortName + ".html"; }
//===================================================================== /// <summary> /// Returns the name of the file documentation file for the given file, /// relative to the OutputDir. /// </summary> private String FileFileName(SourceFile sf) { return FileDir + "/" + sf.ShortName + ".html"; }
//===================================================================== /// <summary> /// Returns the name of the class index file for the given file, /// relative to the OutputDir. /// </summary> private String ClassIndexFileName(SourceFile sf) { return IndexDir + "/" + sf.ShortName + ".html"; }
//===================================================================== /// <summary> /// Adds a new SourceFile to the SymbolTable and returns it. /// </summary> /// <param name="fileName">the name of the source file</param> public SourceFile AddFile(String fileName) { SourceFile sf = new SourceFile(fileName); this.Files.Add(sf); return sf; }
//===================================================================== /// <summary> /// Parses a single input file. /// </summary> public void ParseInputFile(SourceFile file) { this.CurrentSourceFile = file; this.CurrentFileName = file.FullPath; this.LineNumber = 0; this.FirstComment = true; this.CurrentFile = new StreamReader(file.FullPath); String line; if (DocGenApp.MacroExpPath != null) { try { this.CurrentExpFile = new StreamReader( DocGenApp.MacroExpPath + "/" + file.ShortName); } catch (Exception) { CurrentExpFile = null; CurrentExpLine = null; } } while (null != (line = GetNextLine())) ProcessLine(line, CurrentExpLine); System.Console.Out.WriteLine(); CurrentFile.Close(); }