121 static void printlatexheader(istream& latexheader,
const string& faustversion, ostream& docout);
125 static void printdoccontent(
const char* svgTopDir,
const vector<Tree>& docVector,
const string& faustversion, ostream& docout);
128 static void printDocDgm(
const Tree expr,
const char* svgTopDir, ostream& docout,
int i);
132 static void prepareDocEqns(
const vector<Tree>& docBoxes, vector<Lateq*>& docCompiledEqnsVector );
133 static void collectDocEqns(
const vector<Tree>& docBoxes, vector<Tree>& eqBoxes );
134 static void mapEvalDocEqn(
const vector<Tree>& eqBoxes,
const Tree& env, vector<Tree>& evalEqBoxes );
135 static void mapGetEqName(
const vector<Tree>& evalEqBoxes, vector<string>& eqNames );
136 static void calcEqnsNicknames(
const vector<string>& eqNames, vector<string>& eqNicknames );
137 static void mapPrepareEqSig(
const vector<Tree>& evalEqBoxes, vector<int>& eqInputs, vector<int>& eqOutputs, vector<Tree>& eqSigs );
138 static void mapSetSigNickname(
const vector<string>& eqNicknames,
const vector<int>& eqInputs,
const vector<Tree>& eqSigs );
142 static void mapCompileDocEqnSigs(
const vector<Tree>& eqSigs,
const vector<int>& eqInputs,
const vector<int>& eqOutputs,
DocCompiler* DC, vector<Lateq*>& docCompiledEqnsVector );
157 static void copyFaustSources(
const char* projname,
const vector<string>& pathnames);
158 vector<string>&
docCodeSlicer(
const string& faustfile, vector<string>& codeSlices);
224 void printDoc(
const char* projname,
const char* docdev,
const char* faustversion)
236 string svgTopDir =
subst(
"$0/svg", projname);
239 string cppdir =
subst(
"$0/cpp", projname);
242 string pdfdir =
subst(
"$0/pdf", projname);
249 string texdir =
subst(
"$0/tex", projname);
283 static void printlatexheader(istream& latexheader,
const string& faustversion, ostream& docout)
286 while(getline(latexheader, s)) docout << s << endl;
289 docout <<
"\\newcommand{\\faustfilename}{" <<
gMasterDocument <<
"}" << endl;
290 docout <<
"\\newcommand{\\faustdocdir}{" <<
gMasterName <<
"-mdoc}" << endl;
291 docout <<
"\\newcommand{\\faustprogname}{" <<
gMasterName <<
"}" << endl;
292 docout <<
"\\newcommand{\\faustversion}{" << faustversion <<
"}" << endl;
295 docout <<
"\\newcommand{\\faustdocdate}{" << datebuf <<
"}" << endl;
297 docout << endl <<
"\\begin{document}" << endl;
317 for (set<Tree>::iterator j = mset.begin(); j != mset.end(); j++) {
335 for (
unsigned int i=0; i< pathnames.size(); i++) {
357 src.open(faustfile.c_str(), ifstream::in);
359 docout << endl <<
"\\bigskip\\bigskip" << endl;
360 docout <<
"\\begin{lstlisting}[caption=\\texttt{" <<
filebasename(faustfile.c_str()) <<
"}]" << endl;
362 bool isInsideDoc =
false;
364 if (faustfile !=
"" && src.good()) {
365 while(getline(src, s)) {
366 size_t foundopendoc = s.find(
"<mdoc>");
367 if (foundopendoc != string::npos &&
gStripDocSwitch) isInsideDoc =
true;
369 if (isInsideDoc ==
false)
372 size_t foundclosedoc = s.find(
"</mdoc>");
373 if (foundclosedoc != string::npos &&
gStripDocSwitch) isInsideDoc =
false;
376 cerr <<
"ERROR : can't open faust source file " << faustfile << endl;
380 docout <<
"\\end{lstlisting}" << endl << endl;
391 docout << endl <<
"\\end{document}" << endl << endl;
409 docout <<
"%% This documentation was generated with Faust version " << faustversion << endl;
410 docout <<
"%% " << datebuf << endl;
411 docout <<
"%% http://faust.grame.fr" << endl << endl;
436 static void printdoccontent(
const char* svgTopDir,
const vector<Tree>& docVector,
const string& faustversion, ostream& docout)
441 vector<Lateq*> docCompiledEqnsVector;
443 vector<Lateq*>::iterator eqn_it = docCompiledEqnsVector.begin();
447 vector<string> docMasterCodeMap;
450 vector<Tree>::const_iterator
doc;
451 vector<string>::const_iterator code;
452 code = docMasterCodeMap.begin();
460 for (doc=docVector.begin(); doc<docVector.end(); doc++, code++) {
487 cerr <<
"ERROR : " << *
hd(L) <<
" is not a valid documentation type." << endl;
515 static void prepareDocEqns(
const vector<Tree>& docBoxes, vector<Lateq*>& docCompiledEqnsVector)
519 if(! eqBoxes.empty() ) {
521 vector<string> eqNames;
mapGetEqName( evalEqBoxes, eqNames );
524 vector<int> eqInputs;
525 vector<int> eqOutputs;
526 vector<Tree> eqSigs;
mapPrepareEqSig( evalEqBoxes, eqInputs, eqOutputs, eqSigs );
548 for (vector<Tree>::const_iterator
doc=docBoxes.begin();
doc<docBoxes.end();
doc++) {
553 eqBoxes.push_back(expr);
570 static void mapEvalDocEqn(
const vector<Tree>& eqBoxes,
const Tree& env, vector<Tree>& evalEqBoxes)
574 for ( vector<Tree>::const_iterator eq=eqBoxes.begin(); eq < eqBoxes.end(); eq++)
588 static void mapGetEqName(
const vector<Tree>& evalEqBoxes, vector<string>& eqNames)
593 for( vector<Tree>::const_iterator eq = evalEqBoxes.begin(); eq < evalEqBoxes.end(); eq++, i++ ) {
603 eqNames.push_back( s ) ;
624 for( vector<string>::const_iterator eq = eqNames.begin(); eq < eqNames.end(); eq++ ) {
633 eqNicknames.push_back(init);
658 static void mapPrepareEqSig(
const vector<Tree>& evalEqBoxes, vector<int>& eqInputs, vector<int>& eqOutputs, vector<Tree>& eqSigs)
662 for( vector<Tree>::const_iterator eq = evalEqBoxes.begin(); eq < evalEqBoxes.end(); eq++ ) {
664 int numInputs, numOutputs;
667 eqInputs.push_back(numInputs);
668 eqOutputs.push_back(numOutputs);
679 eqSigs.push_back(lsig4);
692 static void mapSetSigNickname(
const vector<string>& eqNicknames,
const vector<int>& eqInputs,
const vector<Tree>& eqSigs)
717 for( vector<Tree>::const_iterator it = eqSigs.begin(); it < eqSigs.end(); ++it ) {
718 superEqList =
cons( *it, superEqList );
755 static void mapCompileDocEqnSigs(
const vector<Tree>& eqSigs,
const vector<int>& eqInputs,
const vector<int>& eqOutputs,
DocCompiler* DC, vector<Lateq*>& docCompiledEqnsVector)
759 for(
unsigned int i=0; i < eqSigs.size(); i++ ) {
762 docCompiledEqnsVector.push_back( DC->
compileLateq(eqSigs[i],
new Lateq(eqInputs[i], eqOutputs[i])) );
788 else if (s.substr(0,6) ==
"doceqn")
805 if (!
getBoxType(t, &numInputs, &numOutputs)) {
806 cerr <<
"ERROR during the evaluation of t : " <<
boxpp(t) << endl;
842 static void printDocDgm(
const Tree expr,
const char* svgTopDir, ostream& docout,
int i)
847 cerr <<
"Total of " <<
gErrorCount <<
" errors during evaluation of : diagram docdgm = " <<
boxpp(docdgm) <<
";\n";
856 sprintf(dgmid,
"%02d", i);
857 string thisdgmdir =
subst(
"$0/svg-$1", svgTopDir, dgmid);
860 drawSchema( docdgm, thisdgmdir.c_str(),
"svg" );
864 const string dgmfilename =
legalFileName(docdgm, 1024, temp);
866 docout <<
"\\begin{figure}[ht!]" << endl;
867 docout <<
"\t\\centering" << endl;
868 docout <<
"\t\\includegraphics[width=\\textwidth]{" <<
subst(
"../svg/svg-$0/", dgmid) << dgmfilename <<
"}" << endl;
869 docout <<
"\t\\caption{" <<
gDocMathStringMap[
"dgmcaption"] <<
" \\texttt{" << dgmfilename <<
"}}" << endl;
870 docout <<
"\t\\label{figure" << i <<
"}" << endl;
871 docout <<
"\\end{figure}" << endl << endl;
891 vector<string>&
docCodeSlicer(
const string& faustfile, vector<string>& codeSlices)
895 src.open(faustfile.c_str(), ifstream::in);
898 bool isInsideDoc =
false;
900 if (faustfile !=
"" && src.good()) {
901 while(getline(src, s)) {
902 size_t foundopendoc = s.find(
"<mdoc>");
904 if (foundopendoc != string::npos) {
905 if (isInsideDoc ==
false) {
906 if (! tmp.empty() ) {
907 codeSlices.push_back(tmp); }
913 if (isInsideDoc ==
false) {
917 size_t foundclosedoc = s.find(
"</mdoc>");
918 if (foundclosedoc != string::npos) isInsideDoc =
false;
921 cerr <<
"ERROR : can't open faust source file " << faustfile << endl;
936 if ( ! code.empty() ) {
937 docout << endl <<
"\\begin{lstlisting}[numbers=none, frame=none, basicstyle=\\small\\ttfamily, backgroundcolor=\\color{yobg}]" << endl;
938 docout << code << endl;
939 docout <<
"\\end{lstlisting}" << endl << endl;
953 src.open(faustfile.c_str(), ifstream::in);
955 if (faustfile !=
"" && src.good()) {
957 size_t foundopendoc = s.find(
"<mdoc>");
958 if(
int(foundopendoc)==0) {
964 cerr <<
"ERROR : can't open faust source file " << faustfile << endl;
985 cerr <<
"ERROR : can't open architecture file " << filename << endl;
1005 for (i=0; isalnum(src[i]) && i<16; i++) {
1010 if (strcmp(dst,
"process") != 0) {
1012 snprintf(&dst[i], n-i,
"-%p", t);
1024 sprintf(nb,
"%03d", i);
1025 return subst(
"$0$1", base, nb);
1034 size_t i = s.find_first_not_of(
"\"");
1035 size_t j = s.find_last_not_of(
"\"");
1037 if ( (i != string::npos) & (j != string::npos) ) {
1038 return s.substr(i, 1+j-i);
1053 string srcdir =
subst(
"$0/src", projname);
1057 for (
unsigned int i=0; i< pathnames.size(); i++) {
1060 string faustfile = pathnames[i];
1064 src.open(faustfile.c_str(), ifstream::in);
1065 dst.open(copy.c_str(), ofstream::out);
1067 while ( getline(src,s) ) dst << s << endl;
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
static char * legalFileName(const Tree t, int n, char *dst)
Transform the definition name property of tree into a legal file name.
static void printlatexheader(istream &latexheader, const string &faustversion, ostream &docout)
Print a static LaTeX header.
static string calcDocEqnInitial(const string s)
Calculate an appropriate nickname for equations, from previous names.
static int cholddir()
Switch back to the previously stored current directory.
int mkchdir(string dirname)
Create a new directory in the current one to store the diagrams.
static void prepareDocEqns(const vector< Tree > &docBoxes, vector< Lateq * > &docCompiledEqnsVector)
Caller function.
static string calcNumberedName(const char *base, int i)
Simply concat a string with a number in a "%03d" format.
Class Node = (type x (int + double + Sym + void*))
#define MAXIDCHARS
max numbers (characters) to represent ids (e.g. for directories).
static void annotateSuperList(DocCompiler *DC, Tree superEqList)
step 8. Annotate superlist.
static void mapCompileDocEqnSigs(const vector< Tree > &eqSigs, const vector< int > &eqInputs, const vector< int > &eqOutputs, DocCompiler *DC, vector< Lateq * > &docCompiledEqnsVector)
step 10. Compile equations.
void drawSchema(Tree bd, const char *projname, const char *dev)
The entry point to generate from a block diagram as a set of svg files stored in the directory "
static void mapSetSigNickname(const vector< string > &eqNicknames, const vector< int > &eqInputs, const vector< Tree > &eqSigs)
step 6. Set signals nicknames.
Tree deBruijn2Sym(Tree t)
Tree cons(Tree a, Tree b)
static void collectDocEqns(const vector< Tree > &docBoxes, vector< Tree > &eqBoxes)
step 0. Feed a vector.
Tree evaldocexpr(Tree docexpr, Tree eqlist)
map< string, bool > gDocNoticeFlagMap
gDocNoticeFlagMap is public to let others turn to "true" flags that one want to print.
static void printdoccontent(const char *svgTopDir, const vector< Tree > &docVector, const string &faustversion, ostream &docout)
Main documentator loop.
static struct tm * getCompilationDate()
bool gLstDistributedSwitch
mdoc listing management.
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
bool gLstMdocTagsSwitch
mdoc listing management.
ifstream * open_arch_stream(const char *filename)
Try to open an architecture file searching in various directories.
static void copyFaustSources(const char *projname, const vector< string > &pathnames)
Copy all Faust source files into an 'src' subdirectory.
string gFaustSuperSuperDirectory
Tree docTableConvertion(Tree sig)
const Node & node() const
return the content of the tree
bool isDocDgm(Tree t, Tree &x)
Tree docTxt(const char *name)
static istream * openArchFile(const string &filename)
Open architecture file.
Lateq * compileLateq(Tree L, Lateq *compiledEqn)
map< string, string > gDocMathStringMap
static void printDocEqn(Lateq *ltq, ostream &docout)
Print doc equations, following the Lateq::println method.
Interface of the block diagram evaluator.
int makedir(string dirname)
string gDocName
Contains the filename for out documentation.
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
vector< string > listSrcFiles()
Return a vector of pathnames representing the list of all the source files that have been required to...
static void initCompilationDate()
string subst(const string &model, const vector< string > &args)
Text substitution.
vector< Tree > gDocVector
Contains parsed trees: DOCTXT, DOCEQN, DOCDGM.
const char * filebasename(const char *name)
returns a pointer on the basename part of name
static void mapPrepareEqSig(const vector< Tree > &evalEqBoxes, vector< int > &eqInputs, vector< int > &eqOutputs, vector< Tree > &eqSigs)
step 4&5. Propagate and prepare signals.
static void getCurrentDir()
Get current directory and store it in gCurrentDir.
map< Tree, set< Tree > > gMetaDataSet
bool isSym(const Node &n)
static void getBoxInputsAndOutputs(const Tree t, int &numInputs, int &numOutputs)
Just get the number of inputs and the number of outputs of a box.
static void printlatexfooter(ostream &docout)
Print the static LaTeX footer.
void println(ostream &docout)
Top-level method to print a whole set of compiled LaTeX formulas.
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
static void collectEqSigs(const vector< Tree > &eqSigs, Tree &superEqList)
step 7. Collect all signals in a superlist.
const char * name(Symbol *sym)
Returns the name of a symbol.
static const string gLatexheaderfilename
bool isDocMtd(Tree t, Tree &x)
static void printfaustlistings(ostream &docout)
Print listings of each Faust code ".dsp" files, calling the 'printfaustlisting' function.
vector< string > & docCodeSlicer(const string &faustfile, vector< string > &codeSlices)
Slice faust code between "mdoc" sections.
void loadTranslationFile(const string &lang)
Compile a list of FAUST signals into a list of LaTeX formulas.
string gFaustSuperDirectory
bool isDocEqn(Tree t, Tree &x)
static void calcEqnsNicknames(const vector< string > &eqNames, vector< string > &eqNicknames)
step 3. Calculate nicknames.
static void mapGetEqName(const vector< Tree > &evalEqBoxes, vector< string > &eqNames)
step 2. Get boxes name.
Symbols are unique objects with a name stored in a hash table.
bool isTree(const Tree &t, const Node &n)
static string rmExternalDoubleQuotes(const string &s)
Remove the leading and trailing double quotes of a string (but not those in the middle of the string)...
static void printdocCodeSlices(const string &code, ostream &docout)
Print faust code inside a listing environment.
static const char * gDocDevSuffix
".tex" (or .??? - used to choose output device).
map< string, string > gDocMetadatasStringMap
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
static void printfaustlisting(string &path, ostream &docout)
Print a listing of the Faust code, in a LaTeX "listing" environment.
static void printDocMetadata(const Tree expr, ostream &docout)
Print a metadata set.
Interface for names management.
void printDocNotice(const string &faustversion, ostream &docout)
Print the content of the notice (a string map), as LaTeX items inside an itemize environment.
static struct tm gCompilationDate
static void mapEvalDocEqn(const vector< Tree > &eqBoxes, const Tree &env, vector< Tree > &evalEqBoxes)
step 1. Evaluate boxes.
static void printDocDgm(const Tree expr, const char *svgTopDir, ostream &docout, int i)
Doc diagrams handling.
static void printfaustdocstamp(const string &faustversion, ostream &docout)
Print a "doc stamp" in the LaTeX document :
static bool doesFileBeginWithCode(const string &faustfile)
Test whether a file does begin with some faust code or not.
void printDoc(const char *projname, const char *docdev, const char *faustversion)
The entry point to generate faust doc files.
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Tree branch(int i) const
return the ith branch (subtree) of a tree
void declareAutoDoc()
Declare an automatic documentation.
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
bool gLstDependenciesSwitch
mdoc listing management.