/
GenerateDoc.mos
194 lines (182 loc) · 7.1 KB
/
GenerateDoc.mos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linköping University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* Generates Modelica documentation automatically in about 30 minutes
* Includes Modelica standard libraries
* Most Modelica builtin operators
* Some non-Modelica-but-used-in-MSL operators
* OpenModelica scripting
*
* $Id$
*/
if true then
loadModel(Modelica,{"3.2"});
loadModel(ModelicaReference);
loadModel(ObsoleteModelica3);
loadModel(ModelicaTest);
loadModel(Modelica_LinearSystems2);
end if;
/*
deleteClass(ModelicaServices);
deleteClass(Complex);
deleteClass(ObsoleteModelica3);
deleteClass(Modelica_LinearSystems2);
deleteClass(ModelicaTest);
deleteClass(Modelica);
// deleteClass(ModelicaReference);
*/
getErrorString();
a:=0;
b:=getClassNames(builtin=true,recursive=true,sort=true);
/* If we want to test on fewer classes */
// b := {$TypeName(Modelica),$TypeName(Modelica.Math.Matrices.LAPACK.dgglse_vec)};
// b := {$TypeName(Modelica),$TypeName(Modelica.Electrical.Analog.Basic),$TypeName(Modelica.Electrical.Analog.Basic.VariableInductor)};
// b := {$TypeName(Modelica.UsersGuide.Overview)};
version := "<hr />Generated by <a href=\"http://openmodelica.org\">OpenModelica</a>" + getVersion() + " using <a href=\"GenerateDoc.mos\">GenerateDoc.mos</a>";
"classNames";
classNames := getClassNames(builtin=true,sort=true);
loadString("
function filename
input String str;
output String ostr :=
// OpenModelica.Scripting.stringReplace(
// OpenModelica.Scripting.stringReplace(
OpenModelica.Scripting.stringReplace(
OpenModelica.Scripting.stringReplace(
OpenModelica.Scripting.stringReplace(str,\"'\",\"\"),
\"/\",\"Division\"),
\"*\",\"Multiplication\")
// \"(\",\"\"),
//\")\",\"\")
;
end filename;
");
searchPaths := "";
filetmp := "index.html";
writeFile(filetmp, "<html><head><title>Modelica Documentation</title></head><body><h1>Modelica Documentation</h1>\n");
writeFile(filetmp, "<p>This is a listing of builtin Modelica functions, libraries shipped with OpenModelica and the documentation for OpenModelica-specific scripting.</p>\n", append = true);
writeFile(filetmp, "<h2>Contents</h2>\n", append = true);
writeFile(filetmp, "<table><tr><th>Name</th><th>Description</th><th>Version</th></tr>", append = true);
for cl in classNames loop
file := getSourceFile(cl);
base := basename(file);
if base == "package.mo" then
searchPaths := searchPaths + " \"" + dirname(file) + "\"";
end if;
contentStr := typeNameString(cl);
contentStrToks := strtok(contentStr,".");
comment := getClassComment(cl);
fileName := filename(contentStr);
modelVersion := getVersion(cl);
writeFile(filetmp, "<tr><td><a href=\"" + fileName + ".html\">" + contentStrToks[end] + "</a></td><td>" + comment + "</td><td>" + modelVersion + "</td></tr>", append = true);
end for;
writeFile(filetmp, "</table>\n", append = true);
writeFile(filetmp, version + " (<a href=\"ModelicaDocumentation.tar.xz\">Offline version</a>)", append = true);
writeFile(filetmp, "</body>\n</html>", append = true);
i := 0;
sz := size(b,1);
for c in b loop
contents := getClassNames(c,qualified=true,sort=true);
cl := typeNameString(c);
cls := typeNameStrings(c);
compound := "";
clsEnd := cls[end];
clsNotEnd := cls[1:end-1];
file := filename(cl) + ".html";
filetmp := file + ".tmp";
writeFile(filetmp, "<title>"+cl+"</title>\n<h1><a href = \"index.html\">.</a>");
for ident in clsNotEnd loop
compound := if compound == "" then ident else compound+"."+ident;
file := compound+".html";
writeFile(filetmp, "<a href = \""+file+"\">"+ident+"</a>.", append = true);
end for;
writeFile(filetmp, clsEnd + "</h1>", append = true);
arr := getDocumentationAnnotation(c);
docInfo := if arr[1] == "" then "<pre>" + OpenModelica.Scripting.getClassComment(c) + "</pre>" else arr[1];
revisions := arr[2];
if regexBool(docInfo,"^.*<[Hh][Tt][Mm][Ll]>.*$") then
writeFile(filetmp, "\n" + docInfo, append = true);
else
writeFile(filetmp, "\n<pre>" + docInfo + "</pre>", append = true);
end if;
if size(contents,1)>0 then
writeFile(filetmp, "<h2>Contents</h2>\n", append = true);
writeFile(filetmp, "<table><tr><th>Name</th><th>Description</th></tr>", append = true);
for content in contents loop
contentStr := typeNameString(content);
contentStrToks := strtok(contentStr,".");
comment := getClassComment(content);
fileName := filename(contentStr);
writeFile(filetmp, "<tr><td><a href=\"" + fileName + ".html\">" + contentStrToks[end] + "</a></td><td>" + comment + "</td></tr>", append = true);
end for;
writeFile(filetmp, "</table>", append = true);
end if;
if revisions <> "" then
writeFile(filetmp, "<h2>Revisions:</h2>" + revisions, append = true);
end if;
writeFile(filetmp, version, append = true);
i := i + 1;
print(cl + " (" + String(i) + "/" + String(sz) + ")" + "\n");
end for;
writeFile("Tidy.sh","#!/bin/bash
rm -f tidy.log
for f in *.html.tmp ; do
F=`echo $f | sed s/\\.tmp\\$//`
echo Checking file $F >> tidy.log
cp \"$f\" \"$F\"
# Image sources (filenames)
sed -i 's/src=\"modelica:\\/\\/[A-Za-z0-9/'\\''()._-]*\\/\\([A-Za-z0-9'\\''()._-]*\\.png\"\\)/src=\"\\1/g' \"$F\"
# Links to classnames
sed -i 's/href=\"modelica:\\/\\/\\([A-Za-z0-9'\\''()._]*\\)/href=\"\\1.html/g' \"$F\"
# Make quoted identifiers pretty
sed -i 's/\\(href=\"[^\"'\\'']*\\)'\\''\\([^\"'\\'']*\\)'\\''/\\1\\2/g' \"$F\"
tidy -modify -quiet \"$F\" 2>> tidy.log
done
mkdir -p old-html-tmp
mv *.html.tmp old-html-tmp
");
writeFile("FindFiles.sh","#!/bin/bash
egrep -o \"[A-Za-z_0-9.-]*\\.(png|jpg)\" *.html | cut -d: -f2- | sort -u | tr -d \\\" > tmp
for f in `cat tmp`; do
if test -f \"$f\"; then
true
else
find " + searchPaths + " -name \"$f\" -exec cp '{}' '.' ';'
test -f \"$f\" && echo Found: $f || echo Not found: $f
fi
done
");
system("bash Tidy.sh");
system("bash FindFiles.sh");
system("rm -f ModelicaDocumentation.tar.xz");
system("rm -f *.html.tmp");
system("tar cJf ModelicaDocumentation.tar.xz --dereference *.html *.png GenerateDoc.mos");
getErrorString();