comparison src/docgen/docgen.d @ 806:bcb74c9b895c

Moved out files in the trunk folder to the root.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 09 Mar 2008 00:12:19 +0100
parents trunk/src/docgen/docgen.d@2eee29aaa357
children
comparison
equal deleted inserted replaced
805:a3fab8b74a7d 806:bcb74c9b895c
1 /**
2 * Author: Jari-Matti Mäkelä
3 * License: GPL3
4 */
5 module docgen.docgen;
6
7 import docgen.graphutils.writers;
8 import docgen.config.configurator;
9 import docgen.document.latexgenerator;
10 import docgen.document.htmlgenerator;
11 import docgen.document.xmlgenerator;
12 import docgen.document.plaintextgenerator;
13
14 //import dil.Settings;
15 import dil.SettingsLoader;
16
17 import tango.core.Array;
18 import tango.text.Text;
19 import tango.io.Stdout;
20
21 void usage() {
22 Stdout(
23 "Usage: docgen rootpath importpath_1 ... importpath_n outputdir"
24 ).newline;
25 }
26
27 void main(char[][] args) {
28 dil.SettingsLoader.loadSettings();
29
30 Stdout(docgen_version).newline.newline;
31
32 if (args.length<3) {
33 usage();
34 return;
35 }
36
37 Configurator config = new DefaultConfigurator();
38
39 auto options = config.getConfiguration();
40 options.parser.rootPaths = [ args[1] ];
41 options.parser.importPaths = args[2..$-1];
42 options.outputDir = args[$-1];
43
44 alias DepGraph.Vertex Vertex;
45 alias DepGraph.Edge Edge;
46
47 Module[] cachedModules;
48 DepGraph cachedGraph;
49
50 void parser(ref Module[] modules, ref DepGraph depGraph) {
51 Edge[] edges;
52 Vertex[char[]] vertices;
53
54 if (cachedGraph !is null) {
55 modules = cachedModules;
56 depGraph = cachedGraph;
57 return;
58 }
59
60 int id = 1;
61
62 Parser.loadModules(
63 options.parser.rootPaths,
64 options.parser.importPaths,
65 options.parser.strRegexps,
66 options.graph.includeUnlocatableModules,
67 options.parser.depth,
68 (char[] fqn, char[] path, Module m) {
69 if (m is null) {
70 if (fqn in vertices) {
71 debug Stdout.format("{} already set.\n", fqn);
72 return;
73 }
74 auto vertex = new Vertex(fqn, path, id++);
75 vertices[fqn] = vertex;
76 debug Stdout.format("Setting {} = {}.\n", fqn, path);
77 } else {
78 vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++);
79 debug Stdout.format("Setting {} = {}.\n", m.moduleFQN, m.filePath);
80 }
81 },
82 (Module imported, Module importer, bool isPublic, bool isStatic) {
83 debug Stdout.format("Connecting {} - {}.\n", imported.moduleFQN, importer.moduleFQN);
84 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]);
85 edge.isPublic = isPublic;
86 edge.isStatic = isStatic;
87 edges ~= edge;
88 },
89 modules
90 );
91
92 modules.sort(
93 (Module a, Module b) { return ((new Text!(char)(a.moduleFQN)).compare(b.moduleFQN)) < 0; }
94 );
95
96 depGraph.edges = edges;
97 depGraph.vertices = vertices.values;
98
99 cachedGraph = depGraph;
100 cachedModules = modules;
101 }
102
103 GraphCache graphcache = new DefaultGraphCache();
104
105 foreach(format; options.outputFormats) {
106 DocGenerator generator;
107
108 switch(format) {
109 case DocFormat.LaTeX:
110 Stdout("Generating LaTeX docs..");
111 generator = new LaTeXDocGenerator(*options, &parser, graphcache);
112 break;
113 case DocFormat.HTML:
114 Stdout("Generating HTML docs..");
115 generator = new HTMLDocGenerator(*options, &parser, graphcache);
116 break;
117 case DocFormat.XML:
118 Stdout("Generating XML docs..");
119 generator = new XMLDocGenerator(*options, &parser);
120 break;
121 case DocFormat.PlainText:
122 Stdout("Generating plain text docs..");
123 generator = new PlainTextDocGenerator(*options, &parser, graphcache);
124 break;
125 default: throw new Exception("Format not supported");
126 }
127
128 generator.generate();
129 Stdout("done.").newline;
130 }
131 }