20#include "../../../common/datastructures.h" 
   21#include "../../kernel.hpp" 
   22#include "../utils/tools.hpp" 
   23#include "../procedure/dependency.hpp" 
   24#include "../ui/winlayout.hpp" 
   42    fileSet.insert(sFile);
 
   43    vFiles.push_back(sFile);
 
   46    if (sFile.find(
".nlyt") != std::string::npos)
 
   52        for (
size_t i = 0; i < vEventProcs.size(); i++)
 
   54            if (fileSet.find(vEventProcs[i]) == fileSet.end())
 
   61    else if (sFile.find(
".nprc") == std::string::npos)
 
   74        for (
auto listiter = iter->second.begin(); listiter != iter->second.end(); ++listiter)
 
   76            if (fileSet.find(listiter->getFileName()) == fileSet.end())
 
   97    std::string sFileContents;
 
  100    std::ofstream file_out;
 
  102    bool bTextMode = 
true;
 
  105    sFileContents += 
"% Created by NumeRe from the source of " + sFileName + 
"\n\n";
 
  120                if (i - startpos > 1)
 
  124                sFileContents += 
"\\end{lstlisting}\n";
 
  139            if (i - startpos > 1)
 
  149                if (i - startpos > 1)
 
  153                sFileContents += 
"\\end{lstlisting}\n";
 
  170            if (i - startpos > 1)
 
  190                sFileContents += 
"\\begin{lstlisting}\n";
 
  195                if (i - startpos > 1)
 
  205        sFileContents += 
"\\end{lstlisting}\n";
 
  207    if (!sFileContents.length())
 
  212    file_out.open(sLaTeXFileName.c_str());
 
  214    if (!file_out.good())
 
  217    file_out << sFileContents;
 
  220    return sLaTeXFileName;
 
  247    while (sTextRange.front() == 
' ' || sTextRange.front() == 
'\r' || sTextRange.front() == 
'\n' )
 
  248        sTextRange.erase(0, 1);
 
  251    while (sTextRange.back() == 
' ' || sTextRange.back() == 
'\t' || sTextRange.back() == 
'\r' || sTextRange.back() == 
'\n')
 
  252        sTextRange.erase(sTextRange.length() - 1);
 
  255    while (sTextRange.find(
"\r\n") != std::string::npos)
 
  256        sTextRange.replace(sTextRange.find(
"\r\n"), 2, 
"\n");
 
  261    while ((nCommentSeq = sTextRange.find(
"\n##!")) != std::string::npos)
 
  262        sTextRange.erase(nCommentSeq+1, 3);
 
  269        for (
size_t i = 0; i < sTextRange.length(); i++)
 
  271            switch (sTextRange[i])
 
  274                    sTextRange.replace(i, 1, 
"Ae");
 
  277                    sTextRange.replace(i, 1, 
"ae");
 
  280                    sTextRange.replace(i, 1, 
"Oe");
 
  283                    sTextRange.replace(i, 1, 
"oe");
 
  286                    sTextRange.replace(i, 1, 
"Ue");
 
  289                    sTextRange.replace(i, 1, 
"ue");
 
  292                    sTextRange.replace(i, 1, 
"ss");
 
  298    if (sTextRange.find_first_not_of(
'\t') == std::string::npos)
 
  328    if (sTextRange.find(
"\\procedure ") != std::string::npos)
 
  331        size_t nPosStart = sTextRange.find(
"\\procedure ")+10;
 
  332        nPosStart = sTextRange.find_first_not_of(
' ', nPosStart);
 
  333        size_t nPosEnd = sTextRange.find_first_not_of(
" \r\n", nPosStart);
 
  334        nPosEnd = sTextRange.find_first_of(
" \r\n", nPosEnd);
 
  336        std::string sProcedure = sTextRange.substr(nPosStart, nPosEnd-nPosStart);
 
  338        std::string sDependencies;
 
  340        if (sMainProc.length())
 
  342            if (sMainProc != sProcedure)
 
  344                if (sMainProc.find(
'~') != std::string::npos && sMainProc.substr(sMainProc.rfind(
'~')+1) == sProcedure)
 
  345                    sProcedure = sMainProc;
 
  348                    sProcedure.insert(0, 
"thisfile~");
 
  351                    if (sMain.find(
'~') != std::string::npos)
 
  352                        sMain.erase(0, sMain.rfind(
'~')+1);
 
  355                    sMain.insert(0, 
"(): local member of \\$");
 
  361            std::map<std::string, DependencyList>::iterator iter;
 
  363            if (sProcedure.find(
"thisfile~") != std::string::npos)
 
  364                iter = mDependencies.find(
"$" + sMainProc + 
"::" + sProcedure);
 
  366                iter = mDependencies.find(
"$" + sProcedure);
 
  368            if (iter != mDependencies.end())
 
  372                for (
auto listiter = _depList.begin(); listiter != _depList.end(); ++listiter)
 
  374                    if (sDependencies.length())
 
  375                        sDependencies += 
", ";
 
  377                    if (listiter->getProcedureName().find(
"::thisfile~") != std::string::npos)
 
  378                        sDependencies += 
"!!$" + listiter->getProcedureName().substr(listiter->getProcedureName().find(
"::")+2) + 
"()!!";
 
  380                        sDependencies += 
"!!" + listiter->getProcedureName() + 
"()!!";
 
  383                if (sDependencies.length())
 
  384                    sDependencies = 
"\n\\depends{" + sDependencies + 
"}";
 
  391        sTextRange.insert(nPosEnd, sMain + 
"}{$" + sProcedure + 
"()}" + sDependencies);
 
  392        sTextRange[nPosStart-1] = 
'{';
 
  396    if (sTextRange.find(
"\\layout ") != std::string::npos)
 
  399        size_t nPosStart = sTextRange.find(
"\\layout ")+7;
 
  400        nPosStart = sTextRange.find_first_not_of(
' ', nPosStart);
 
  401        size_t nPosEnd = sTextRange.find_first_not_of(
" \r\n", nPosStart);
 
  402        nPosEnd = sTextRange.find_first_of(
" \r\n", nPosEnd);
 
  404        std::string sLayout = sTextRange.substr(nPosStart, nPosEnd-nPosStart);
 
  408        sTextRange.replace(nPosStart-1, nPosEnd-nPosStart+1, 
"{" + sLayout + 
"}");
 
  412    if (sTextRange.find(
"- ") != std::string::npos) 
 
  414        size_t nItemizeStart = 0;
 
  417        while ((nItemizeStart = 
findListItem(sTextRange, nLength)) != std::string::npos)
 
  419            std::string sItemStart = 
"\n" + std::string(nLength-3, 
' ') + 
"- ";
 
  420            std::string sIndent = 
"\n" + std::string(nLength-1, 
' ');
 
  422            for (
size_t i = nItemizeStart; i < sTextRange.length(); i++)
 
  424                if (sTextRange.substr(i, nLength) == sItemStart)
 
  426                    sTextRange.replace(i + 1, nLength-2, 
"\t\\item");
 
  430                if ((sTextRange[i] == 
'\n' && sTextRange.substr(i, nLength) != sIndent) || i + 1 == sTextRange.length())
 
  432                    if (sTextRange[i] == 
'\n')
 
  433                        sTextRange.insert(i+1, 
"\\end{itemize}");
 
  435                        sTextRange += 
"\n\\end{itemize}";
 
  437                    sTextRange.insert(nItemizeStart + 1, 
"\\begin{itemize}\n");
 
  445    if (sTextRange.find(
"\\param ") != std::string::npos)
 
  447        while (sTextRange.find(
"\\param ") != std::string::npos)
 
  449            size_t nItemizeStart = sTextRange.find(
"\\param ");
 
  450            size_t nLastParam = nItemizeStart;
 
  451            std::vector<std::string> vParameters;
 
  453            for (
size_t i = nItemizeStart+1; i < sTextRange.length(); i++)
 
  455                if (sTextRange.substr(i, 7) == 
"\\param ")
 
  457                    vParameters.push_back(sTextRange.substr(nLastParam, i - nLastParam));
 
  462                if (i + 1 == sTextRange.length()
 
  463                    || (sTextRange[i] == 
'\n' && sTextRange[i+1] == 
'\n')
 
  464                    || (sTextRange[i+1] == 
'\\' && sTextRange.substr(i+1, 7) != 
"\\param "))
 
  466                    vParameters.push_back(sTextRange.substr(nLastParam, i - nLastParam+1));
 
  467                    sTextRange.replace(nItemizeStart, i+1 - nItemizeStart, 
"\\parameters\n\\noindent\n" + 
createParametersTable(vParameters));
 
  476    if (sTextRange.find(
"\\return ") != std::string::npos)
 
  478        while (sTextRange.find(
"\\return ") != std::string::npos)
 
  480            size_t nItemizeStart = sTextRange.find(
"\\return ");
 
  481            size_t nLastParam = nItemizeStart;
 
  482            std::vector<std::string> vReturns;
 
  484            for (
size_t i = nItemizeStart+1; i < sTextRange.length(); i++)
 
  486                if (sTextRange.substr(i, 8) == 
"\\return ")
 
  488                    vReturns.push_back(sTextRange.substr(nLastParam, i - nLastParam));
 
  493                if (i + 1 == sTextRange.length()
 
  494                    || (sTextRange[i] == 
'\n' && sTextRange[i+1] == 
'\n')
 
  495                    || (sTextRange[i+1] == 
'\\' && sTextRange.substr(i+1, 8) != 
"\\return "))
 
  497                    vReturns.push_back(sTextRange.substr(nLastParam, i - nLastParam+1));
 
  498                    sTextRange.replace(nItemizeStart, i+1 - nItemizeStart, 
"\\returns\n\\noindent\n" + 
createReturnsTable(vReturns));
 
  507    for (
size_t i = 0; i < sTextRange.length(); i++)
 
  509        switch (sTextRange[i])
 
  512                sTextRange.replace(i, 1, 
"\\\"A");
 
  515                sTextRange.replace(i, 1, 
"\\\"a");
 
  518                sTextRange.replace(i, 1, 
"\\\"O");
 
  521                sTextRange.replace(i, 1, 
"\\\"o");
 
  524                sTextRange.replace(i, 1, 
"\\\"U");
 
  527                sTextRange.replace(i, 1, 
"\\\"u");
 
  530                sTextRange.replace(i, 1, 
"\\ss ");
 
  536    for (
size_t i = 0; i < sTextRange.length(); i++)
 
  538        if (sTextRange.substr(i, 2) == 
"!!")
 
  540            for (
size_t j = i + 2; j < sTextRange.length(); j++)
 
  542                if (sTextRange.substr(j, 2) == 
"!!")
 
  544                    sTextRange.replace(j, 2, 
"`");
 
  545                    sTextRange.replace(i, 2, 
"\\lstinline`");
 
  568    std::string sTable = 
"\\begin{tabular}{p{0.22\\textwidth}p{0.15\\textwidth}p{0.55\\textwidth}}\n\t\\toprule\n\tParameter & Defaults to & Description\\\\\n\t\\midrule\n";
 
  569    std::string sParameter;
 
  574    for (
size_t i = 0; i < vParams.size(); i++)
 
  576        sParameter = vParams[i];
 
  579        size_t nDefaultPos = sParameter.find(
"(!!", 8);
 
  581        if (nDefaultPos != std::string::npos)
 
  582            nDescPos = sParameter.find_first_not_of(
' ', sParameter.find(
"!!)")+3);
 
  584            nDescPos = sParameter.find_first_not_of(
' ', sParameter.find(
' ', 8));
 
  586        sTable += 
"\t!!" + sParameter.substr(7, sParameter.find(
' ', 8) - 7) + 
"!! & ";
 
  588        if (nDefaultPos != std::string::npos)
 
  591            if (sParameter[nDefaultPos+3] == 
'=')
 
  592                sTable += 
"!!" + sParameter.substr(nDefaultPos+4, sParameter.find(
"!!)")-nDefaultPos -2) + 
" & ";
 
  594                sTable += sParameter.substr(nDefaultPos+1, sParameter.find(
"!!)")+1-nDefaultPos) + 
" & ";
 
  599        sTable += sParameter.substr(nDescPos) + 
"\\\\\n";
 
  603    return sTable + 
"\t\\bottomrule\n\\end{tabular}\n";
 
  619    std::string sTable = 
"\\begin{tabular}{p{0.22\\textwidth}p{0.725\\textwidth}}\n\t\\toprule\n\tReturn type & Description\\\\\n\t\\midrule\n";
 
  620    std::string sReturnValue;
 
  625    for (
size_t i = 0; i < vReturns.size(); i++)
 
  627        sReturnValue = vReturns[i];
 
  630        nDescPos = sReturnValue.find_first_not_of(
' ', sReturnValue.find(
' ', 9));
 
  632        sTable += 
"\t!!" + sReturnValue.substr(8, sReturnValue.find(
' ', 9) - 8) + 
"!! & ";
 
  633        sTable += sReturnValue.substr(nDescPos) + 
"\\\\\n";
 
  637    return sTable + 
"\t\\bottomrule\n\\end{tabular}\n";
 
  653    size_t nItemCandidate = sTextRange.find(
"- ");
 
  655    if (nItemCandidate == std::string::npos)
 
  656        return nItemCandidate;
 
  658    size_t nItemStart = sTextRange.find_last_not_of(
"- ", nItemCandidate);
 
  660    if (nItemStart == std::string::npos || sTextRange[nItemStart] != 
'\n')
 
  661        return std::string::npos;
 
  663    nLength = nItemCandidate - nItemStart + 2;
 
  682    if (sFileName.find(
".nprc") == std::string::npos)
 
  685    sFileName.erase(sFileName.rfind(
'.'));
 
  690        sFileName.erase(0, vPaths[
PROCPATH].length());
 
  692        if (sFileName.front() == 
'/')
 
  693            sFileName.erase(0, 1);
 
  699        sFileName.erase(0, sFileName.rfind(
'/')+1);
 
  700        sFileName.insert(0, 
"this~");
 
  725        sFileName.erase(0, vPaths[
PROCPATH].length());
 
  726        sFileName = 
getPath() + 
"/procedures" + sFileName;
 
  731        sFileName.erase(0, vPaths[
SCRIPTPATH].length());
 
  732        sFileName = 
getPath() + 
"/scripts" + sFileName;
 
  734    else if (sFileName.substr(0, vPaths[
EXEPATH].length()) == vPaths[
EXEPATH])
 
  737        sFileName.erase(0, vPaths[
EXEPATH].length());
 
  738        sFileName = 
getPath() + sFileName;
 
  743        sFileName.erase(0, sFileName.rfind(
'/'));
 
  744        sFileName = 
getPath() + 
"/externals" + sFileName;
 
  748    sFileName[sFileName.rfind(
'.')] = 
'_';
 
  771        if (sFileName.substr(0, vPaths[i].length()) == vPaths[i])
 
  773            sFileName.erase(0, vPaths[i].length());
 
  775            if (sFileName.front() == 
'/')
 
  776                sFileName.erase(0, 1);
 
  783    for (
size_t i = 0; i < sFileName.length(); i++)
 
  785        if (sFileName[i] == 
'_' && (!i || sFileName[i-1] != 
'\\'))
 
  787            sFileName.insert(i, 1, 
'\\');
 
  807    for (
size_t i = 0; i < sKeyWordList.length(); i++)
 
  809        if (sKeyWordList[i] == 
' ')
 
  810            sKeyWordList[i] = 
',';
 
  813    if (sKeyWordList.back() == 
',')
 
  814        sKeyWordList.erase(sKeyWordList.length()-1);
 
  833    std::ifstream fHeaderTemplate;
 
  839    if (!fHeaderTemplate.good())
 
  843    std::string sTemplate;
 
  848    while (!fHeaderTemplate.eof())
 
  850        std::getline(fHeaderTemplate, sLine);
 
  851        sTemplate += sLine + 
"\n";
 
  858    if ((pos = sTemplate.find(
"NSCRCOMMANDS")) != std::string::npos)
 
  861    if ((pos = sTemplate.find(
"NSCRFUNCTIONS")) != std::string::npos)
 
  864    if ((pos = sTemplate.find(
"NSCRCONSTANTS")) != std::string::npos)
 
  867    if ((pos = sTemplate.find(
"NSCROPTIONS")) != std::string::npos)
 
  870    if ((pos = sTemplate.find(
"NSCRMETHODS")) != std::string::npos)
 
  873    if ((pos = sTemplate.find(
"NSCRSPECIALVALS")) != std::string::npos)
 
  877    std::ofstream fHeader;
 
  878    fHeader.open((
getPath() + 
"/numereheader.tex").c_str());
 
  885    fHeader << sTemplate;
 
  905    fMain.open(sLaTeXMainFile.c_str());
 
  911    fMain << 
"\\documentclass[DIV=17]{scrartcl}" << std::endl;
 
  912    fMain << 
"% Main file for the documentation file " << sFileName << std::endl << std::endl;
 
  913    fMain << 
"\\input{" << 
getPath() << 
"/numereheader}" << std::endl << std::endl;
 
  915    fMain << 
"\\ihead{Documentation}" << std::endl;
 
  916    fMain << 
"\\ifoot{NumeRe: Free numerical software}" << std::endl;
 
  917    fMain << 
"\\ofoot{Get it at: www.numere.org}" << std::endl;
 
  918    fMain << 
"\\pagestyle{scrheadings}" << std::endl;
 
  919    fMain << 
"\\subject{Documentation}" << std::endl;
 
  922    if (vFiles.size() > 1)
 
  923        fMain << 
"\\subtitle{And all called procedures}" << std::endl;
 
  925    fMain << 
"\\begin{document}" << std::endl;
 
  926    fMain << 
"    \\maketitle" << std::endl;
 
  929    if (vFiles.size() > 1)
 
  931        fMain << 
"    \\addsec{Files included in this documentation}\n    \\begin{itemize}" << std::endl;
 
  933        for (
size_t i = 0; i < vFiles.size(); i++)
 
  936        fMain << 
"    \\end{itemize}" << std::endl;
 
  940    for (
size_t i = 0; i < vIncludesList.size(); i++)
 
  941        fMain << 
"    \\input{" << vIncludesList[i] << 
"}" << std::endl;
 
  943    fMain << 
"\\end{document}" << std::endl;
 
  945    return sLaTeXMainFile;
 
  975    if (sFileName.find(
".nscr") == std::string::npos
 
  976        && sFileName.find(
".nlyt") == std::string::npos
 
  977        && sFileName.find(
".nprc") == std::string::npos)
 
  996    if (sFileName.find(
".nscr") == std::string::npos
 
  997        && sFileName.find(
".nlyt") == std::string::npos
 
  998        && sFileName.find(
".nprc") == std::string::npos)
 
 1001    std::set<std::string> fileSet;
 
 1002    std::vector<std::string> vIncludesList;
 
 1003    std::vector<std::string> vFiles;
 
 1009    for (
size_t i = 0; i < vFiles.size(); i++)
 
This class handles the dependencies of the current procedure file (passed as pointer to a ProcedureEl...
std::map< std::string, DependencyList > & getDependencyMap()
This class is a child of the std::list, where the function unique() has been overridden (i....
std::string createReturnsTable(const std::vector< std::string > &vParams) const
This member function creates a table out of the declared return values in the documentation comments.
std::string convertToLaTeX(const std::string &sFileName) const
Writes the content of the current code file to a LaTeX file.
size_t findListItem(const std::string &sTextRange, size_t &nLength) const
This helper function finds the next list item in the passed documentation string.
std::string createMainFile(const std::string &sFileName, const std::vector< std::string > &vIncludesList, const std::vector< std::string > &vFiles) const
This member function creates a main LaTeX file including the perviously created LaTeX documentation f...
std::string constructKeyWords(std::string sKeyWordList) const
This member function replaces the passed whitespace-separated keyword list with a comma-separated lis...
std::string createDocumentation(const std::string &sFileName) const
This member function creates a LaTeX documentation from a single file and stores it....
std::string getStrippedRange(const StyledTextFile &file, int pos1, int pos2, bool encode=true) const
Gets the contents of the selected range.
std::string createLaTeXFileName(std::string sFileName) const
This method will create a target filename for the TeX files and create the needed folder structure on...
std::string createParametersTable(const std::vector< std::string > &vParams) const
This member function creates a table out of the declared parameters in the documentation comments.
DocumentationGenerator(NumeReSyntax *_syntax, const std::string &sRootPath)
DocumentationGenerator constructor.
std::string createMainProcedure(std::string sFileName) const
This method converts the passed filename into a main procedure for the current file.
std::string parseDocumentation(const StyledTextFile &file, const std::string &sMainProc, int pos1, int pos2) const
Converts the documentation into LaTeX code.
void createStyleFile() const
This member function writes the LaTeX header file used to highlight the code snippets,...
void followBranch(const std::string &sFile, std::set< std::string > &fileSet, std::vector< std::string > &vFiles) const
This member function finds all dependent procedure files. If the current file is not a procedure,...
std::string createFullDocumentation(const std::string &sFileName) const
This member function creates a LaTeX documentation from the passed file and all dependent files....
std::string prepareFileNameForLaTeX(std::string sFileName) const
This member function removes the path parts of the default paths and masks underscores,...
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string getPath() const
Returns the default path of this FileSystem instance.
int createFolders(const std::string &_sPath) const
This member function creates all missing directories in the passed path.
int setPath(std::string _sPath, bool bMkDir, std::string _sExePath)
This member function may be used to set the preferred file path of the current FileSystem instance.
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
ProcedureLibrary & getProcedureLibrary()
std::vector< std::string > getPathSettings() const
This member function returns a vector containing all currently declared paths in a distinct order.
This class contains all needed keywords to highlight their occurences correspondingly....
std::string getNPRCCommands() const
std::string getConstants() const
std::string getMethods() const
std::string getCommands() const
std::string getSpecial() const
std::string getFunctions() const
std::string getOptions() const
Dependencies * getDependencies()
This member function returns the first-level dependencies of the current procedure file....
This class manages all already read and possibly pre-parsed procedure files for easier and faster acc...
ProcedureElement * getProcedureContents(const std::string &sProcedureFileName)
Returns the ProcedureElement pointer to the desired procedure file. It also creates the element,...
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded...
int getLastPosition() const
Returns the last printable character position in the currently loaded file.
int LineFromPosition(size_t pos) const
Returns the line number containing the selected character position.
std::string getTextRange(int pos1, int pos2) const
This method returns the text between the passed two positions (including possible line termination ch...
int getLineEndPosition(size_t line) const
Returns the position of the last printable character in the selected line (before any line terminatio...
int PositionFromLine(size_t line) const
Returns the position of the first character in the selected line.
Style getStyleAt(size_t pos) const
Returns the style at the current selected character position.
std::string getFileName() const
Returns the filename of the respresented file in memory.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
std::vector< std::string > getEventProcedures(const std::string &sLayoutFile)
Examines a window layout file and searches for all event handler procedures. Returns their correspond...