Erosion and dilasion by square successfully tested.
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / documentator / doc_autodoc.cpp
1 /************************************************************************
2 ************************************************************************
3 FAUST compiler
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
21
22
23 #include <iostream>
24 #include <string>
25 #include <set>
26 #include <map>
27 #include <cstdlib>
28
29 #include "doc_autodoc.hh"
30 #include "tlib.hh"
31 #include "boxes.hh"
32 #include "doc.hh"
33
34
35 extern SourceReader gReader;
36 extern string gDocName;
37 extern map<Tree, set<Tree> > gMetaDataSet;
38 extern map<string, string> gDocMetadatasStringMap;
39
40 map<string, string> gDocAutodocStringMap;
41 set<string> gDocAutodocKeySet;
42
43 static void initDocAutodocKeySet();
44
45
46
47
48 /*****************************************************************************
49 Public functions
50 *****************************************************************************/
51
52
53 /**
54 * @brief Declare an automatic documentation.
55 *
56 * This function simulates a default documentation :
57 * if no <mdoc> tag was found in the input faust file,
58 * and yet the '-mdoc' option was called,
59 * then print a complete 'process' doc.
60 */
61 void declareAutoDoc()
62 {
63 Tree autodoc = nil;
64 Tree process = boxIdent("process");
65
66 /** Autodoc's "head", with title, author, date, and metadatas. */
67
68 /** The latex title macro is bound to the metadata "name" if it exists,
69 (corresponding to "declare name") or else just to the file name. */
70 autodoc = cons(docTxt("\\title{"), autodoc);
71 if (gMetaDataSet.count(tree("name"))) {
72 autodoc = cons(docMtd(tree("name")), autodoc);
73 } else {
74 autodoc = cons(docTxt(gDocName.c_str()), autodoc);
75 }
76 autodoc = cons(docTxt("}\n"), autodoc);
77
78 /** The latex author macro is bound to the metadata "author" if it exists,
79 (corresponding to "declare author") or else no author item is printed. */
80 if (gMetaDataSet.count(tree("author"))) {
81 autodoc = cons(docTxt("\\author{"), autodoc);
82 autodoc = cons(docMtd(tree("author")), autodoc);
83 autodoc = cons(docTxt("}\n"), autodoc);
84 }
85
86 /** The latex date macro is bound to the metadata "date" if it exists,
87 (corresponding to "declare date") or else to the today latex macro. */
88 autodoc = cons(docTxt("\\date{"), autodoc);
89 if (gMetaDataSet.count(tree("date"))) {
90 autodoc = cons(docMtd(tree("date")), autodoc);
91 } else {
92 autodoc = cons(docTxt("\\today"), autodoc);
93 }
94 autodoc = cons(docTxt("}\n"), autodoc);
95
96 /** The latex maketitle macro. */
97 autodoc = cons(docTxt("\\maketitle\n"), autodoc);
98
99
100 /** Insert all declared metadatas in a latex tabular environment. */
101 if (! gMetaDataSet.empty()) {
102 autodoc = cons(docTxt("\\begin{tabular}{ll}\n"), autodoc);
103 autodoc = cons(docTxt("\t\\hline\n"), autodoc);
104 for (map<Tree, set<Tree> >::iterator i = gMetaDataSet.begin(); i != gMetaDataSet.end(); i++) {
105 string mtdkey = tree2str(i->first);
106 string mtdTranslatedKey = gDocMetadatasStringMap[mtdkey];
107 if (mtdTranslatedKey.empty()) {
108 mtdTranslatedKey = mtdkey;
109 }
110 autodoc = cons(docTxt("\t\\textbf{"), autodoc);
111 autodoc = cons(docTxt(mtdTranslatedKey.c_str()), autodoc);
112 autodoc = cons(docTxt("} & "), autodoc);
113 autodoc = cons(docMtd(tree(mtdkey.c_str())), autodoc);
114 autodoc = cons(docTxt(" \\\\\n"), autodoc);
115 }
116 autodoc = cons(docTxt("\t\\hline\n"), autodoc);
117 autodoc = cons(docTxt("\\end{tabular}\n"), autodoc);
118 autodoc = cons(docTxt("\\bigskip\n"), autodoc);
119 }
120
121
122 /** Autodoc's "body", with equation and diagram of process, and notice and listing. */
123
124 string autoPresentationTxt = "\n\\bigskip\n" + gDocAutodocStringMap["thisdoc"] + "\n\n";
125 autodoc = cons(docTxt(autoPresentationTxt.c_str()), autodoc);
126
127 string autoEquationTxt = "\n" + gDocAutodocStringMap["autoeqntitle"] + "\n\n";
128 autoEquationTxt += gDocAutodocStringMap["autoeqntext"] + "\n";
129 autodoc = cons(docTxt(autoEquationTxt.c_str()), autodoc);
130 autodoc = cons(docEqn(process), autodoc);
131
132 string autoDiagramTxt = "\n" + gDocAutodocStringMap["autodgmtitle"] + "\n\n";
133 autoDiagramTxt += gDocAutodocStringMap["autodgmtext"] + "\n";
134 autodoc = cons(docTxt(autoDiagramTxt.c_str()), autodoc);
135 autodoc = cons(docDgm(process), autodoc);
136
137 string autoNoticeTxt = "\n" + gDocAutodocStringMap["autontctitle"] + "\n\n";
138 // autoNoticeTxt += gDocAutodocStringMap["autontctext"] + "\n";
139 autodoc = cons(docTxt(autoNoticeTxt.c_str()), autodoc);
140 autodoc = cons(docNtc(), autodoc);
141
142 string autoListingTxt;
143 vector<string> pathnames = gReader.listSrcFiles();
144 if(pathnames.size() > 1) {
145 autoListingTxt = "\n" + gDocAutodocStringMap["autolsttitle2"] + "\n\n";
146 autoListingTxt += gDocAutodocStringMap["autolsttext2"] + "\n";
147 } else {
148 autoListingTxt = "\n" + gDocAutodocStringMap["autolsttitle1"] + "\n\n";
149 autoListingTxt += gDocAutodocStringMap["autolsttext1"] + "\n";
150 }
151 autodoc = cons(docTxt(autoListingTxt.c_str()), autodoc);
152 autodoc = cons(docLst(), autodoc);
153
154 declareDoc(autodoc);
155 }
156
157
158 /**
159 * Dispatch initialization of autodoc container.
160 */
161 void initDocAutodoc()
162 {
163 initDocAutodocKeySet();
164 }
165
166
167
168 /*****************************************************************************
169 Static functions
170 *****************************************************************************/
171
172
173 /**
174 * Initialize gDocAutodocKeySet, a set containing all the keywords.
175 */
176 static void initDocAutodocKeySet() {
177
178 gDocAutodocKeySet.insert("thisdoc");
179
180 gDocAutodocKeySet.insert("autoeqntitle");
181 gDocAutodocKeySet.insert("autoeqntext");
182
183 gDocAutodocKeySet.insert("autodgmtitle");
184 gDocAutodocKeySet.insert("autodgmtext");
185
186 gDocAutodocKeySet.insert("autontctitle");
187 gDocAutodocKeySet.insert("autontctext");
188
189 gDocAutodocKeySet.insert("autolsttitle1");
190 gDocAutodocKeySet.insert("autolsttext1");
191
192 gDocAutodocKeySet.insert("autolsttitle2");
193 gDocAutodocKeySet.insert("autolsttext2");
194 }
195
196
197 /**
198 * Simple trace function.
199 */
200 static void printDocAutodocStringMapContent() {
201 bool trace = false;
202 if(trace) {
203 cout << "gDocAutodocStringMap.size() = " << gDocAutodocStringMap.size() << endl;
204 map<string,string>::iterator it;
205 int i = 1;
206 for(it = gDocAutodocStringMap.begin(); it!=gDocAutodocStringMap.end(); ++it)
207 cout << i++ << ".\tgDocNoticeStringMap[" << it->first << "] \t= '" << it->second << "'" << endl;
208 }
209 }
210