Mercurial > projects > dil
annotate trunk/src/docgen/docgen.d @ 470:e48a011e687a
Initial plain text output support.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Wed, 31 Oct 2007 23:03:56 +0200 |
parents | db7e27b5c180 |
children | ec8dd7b8bf0c |
rev | line source |
---|---|
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
1 /** |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
2 * Author: Jari-Matti Mäkelä |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
3 * License: GPL3 |
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
4 */ |
441 | 5 module docgen.docgen; |
395
ac9cd48151b6
Added couple of docgen modules.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
diff
changeset
|
6 |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
7 import docgen.graphutils.writers; |
455
f92505ad18ab
Simple configuration reader, small modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
8 import docgen.config.configurator; |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
9 import docgen.document.latexgenerator; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
10 import docgen.document.htmlgenerator; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
11 import docgen.document.xmlgenerator; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
12 import docgen.document.plaintextgenerator; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
13 |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
14 import tango.core.Array; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
15 import tango.text.Ascii; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
16 import tango.io.Stdout; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
17 |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
18 void usage() { |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
19 Stdout( |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
20 "Usage: docgen rootpath importpath_1 ... importpath_n outputdir" |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
21 ).newline; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
22 } |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
23 |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
24 void main(char[][] args) { |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
25 Stdout(docgen_version).newline.newline; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
26 |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
27 if (args.length<3) { |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
28 usage(); |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
29 return; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
30 } |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
31 |
455
f92505ad18ab
Simple configuration reader, small modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
32 Configurator config = new DefaultConfigurator(); |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
33 |
455
f92505ad18ab
Simple configuration reader, small modifications.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
454
diff
changeset
|
34 auto options = config.getConfiguration(); |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
35 options.parser.rootPaths = [ args[1] ]; |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
36 options.parser.importPaths = args[2..$-1]; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
37 options.outputDir = args[$-1]; |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
38 |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
39 Module[] cachedModules; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
40 Edge[] cachedEdges; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
41 Vertex[char[]] cachedVertices; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
42 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
43 void parser(ref Module[] modules, ref Edge[] edges, ref Vertex[char[]] vertices) { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
44 if (cachedModules != null) { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
45 modules = cachedModules; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
46 edges = cachedEdges; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
47 vertices = cachedVertices; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
48 return; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
49 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
50 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
51 int id = 1; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
52 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
53 Parser.loadModules( |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
54 options.parser.rootPaths, |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
55 options.parser.importPaths, |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
56 options.parser.strRegexps, |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
57 options.graph.includeUnlocatableModules, |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
58 options.parser.depth, |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
59 (char[] fqn, char[] path, Module m) { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
60 if (m is null) { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
61 if (fqn in vertices) { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
62 debug Stdout.format("{} already set.\n", fqn); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
63 return; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
64 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
65 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
66 auto vertex = new Vertex(fqn, path, id++); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
67 vertex.type = VertexType.UnlocatableModule; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
68 vertices[fqn] = vertex; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
69 debug Stdout.format("Setting {} = {}.\n", fqn, path); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
70 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
71 } else { |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
72 vertices[m.moduleFQN] = new Vertex(m.moduleFQN, m.filePath, id++); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
73 debug Stdout.format("Setting {} = {}.\n", m.moduleFQN, m.filePath); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
74 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
75 }, |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
76 (Module imported, Module importer, bool isPublic) { |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
77 debug Stdout.format("Connecting {} - {}.\n", imported.moduleFQN, importer.moduleFQN); |
462
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
78 auto edge = vertices[imported.moduleFQN].addChild(vertices[importer.moduleFQN]); |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
79 edge.type = isPublic ? EdgeType.PublicDependency : EdgeType.Dependency; |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
80 edge.type = id % 2 ? EdgeType.PublicDependency : EdgeType.Dependency; // FIXME: temporary feature for demonstrating public imports |
b7503e02fbe7
Docgen code for handling public imports.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
459
diff
changeset
|
81 edges ~= edge; |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
82 }, |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
83 modules |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
84 ); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
85 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
86 modules.sort( |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
87 (Module a, Module b){ return icompare(a.moduleFQN, b.moduleFQN); } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
88 ); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
89 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
90 cachedVertices = vertices; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
91 cachedModules = modules; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
92 cachedEdges = edges; |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
93 } |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
94 |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
95 GraphCache graphcache = new DefaultGraphCache(); |
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
96 |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
97 foreach(format; options.outputFormats) { |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
98 DocGenerator generator; |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
99 |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
100 switch(format) { |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
101 case DocFormat.LaTeX: |
470
e48a011e687a
Initial plain text output support.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
102 Stdout("Generating LaTeX docs.."); |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
103 generator = new LaTeXDocGenerator(*options, &parser, graphcache); |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
104 break; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
105 case DocFormat.HTML: |
470
e48a011e687a
Initial plain text output support.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
106 Stdout("Generating HTML docs.."); |
466
db7e27b5c180
Fixed parts of HTML output, some reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
462
diff
changeset
|
107 generator = new HTMLDocGenerator(*options, &parser, graphcache); |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
108 break; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
109 case DocFormat.XML: |
470
e48a011e687a
Initial plain text output support.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
110 Stdout("Generating XML docs.."); |
459
1b5f1ce09f38
Fix to the image cache, cleaned stuff.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
457
diff
changeset
|
111 generator = new XMLDocGenerator(*options, &parser); |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
112 break; |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
113 case DocFormat.PlainText: |
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
114 Stdout("Generating plain text docs.."); |
470
e48a011e687a
Initial plain text output support.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
466
diff
changeset
|
115 generator = new PlainTextDocGenerator(*options, &parser, graphcache); |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
116 break; |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
117 default: throw new Exception("Format not supported"); |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
118 } |
457
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
119 |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
120 generator.generate(); |
33a4cb255fcc
Cached images, small fixes, reorganizing.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
456
diff
changeset
|
121 Stdout("done.").newline; |
456
de2675bc9afa
Dependency lists, minor cleanup.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
455
diff
changeset
|
122 } |
452
f658ec4a15dd
Simple docgen ui util, some fixes.
Jari-Matti M?kel? <jmjm@iki.fi>
parents:
446
diff
changeset
|
123 } |