24#include "../kernel.hpp"
76 if (_sScriptFileName.length())
81 if (
m_script->getLastPosition() == -1)
182 m_logger.
push(
"--- INSTALLATION TERMINATED SUCCESSFULLY ---\n\n\n");
215 sScriptCommand = sScriptCommand.substr(9);
218 if (!sScriptCommand.length())
222 if (sScriptCommand.find(
"<info>") == string::npos)
250 unsigned int nRequiredVersion = nNumereVersion;
255 if (sScriptCommand.find(
"<endinfo>") == string::npos)
260 while (nLine < m_script->getLinesCount())
266 if (sTemp.find(
"<endinfo>") == string::npos)
267 sScriptCommand +=
" " + sTemp;
270 sScriptCommand +=
" " + sTemp.substr(0, sTemp.find(
"<endinfo>") + 9);
277 if (sScriptCommand.find(
"<endinfo>") == string::npos)
283 std::string sInstallInfoString = sScriptCommand.substr(sScriptCommand.find(
"<info>")+6, sScriptCommand.find(
"<endinfo>")-sScriptCommand.find(
"<info>")-6);
284 sScriptCommand = sScriptCommand.substr(sScriptCommand.find(
"<endinfo>")+9);
288 if (sInstallInfoString.find(
"-version=") != std::string::npos)
290 size_t nPackageVersion =
versionToInt(
getArgAtPos(sInstallInfoString, sInstallInfoString.find(
"-version=")+9));
296 for (
const auto& package : vInstalledPackages)
312 if (sInstallInfoString.find(
"requirepackages=") != string::npos)
315 string sInstallPackages =
getArgAtPos(sInstallInfoString, sInstallInfoString.find(
"requirepackages=")+16);
318 while (sInstallPackages.length())
330 if (!sPackage.length())
345 if (sInstallInfoString.find(
"requireversion=") != string::npos)
346 nRequiredVersion =
versionToInt(
getArgAtPos(sInstallInfoString, sInstallInfoString.find(
"requireversion=")+15));
349 if (nRequiredVersion > nNumereVersion)
353 if (sInstallInfoString.find(
"license=") != std::string::npos)
355 std::string sLicense =
getArgAtPos(sInstallInfoString, sInstallInfoString.find(
"license=")+8);
362 if (sAnswer.substr(0, 1) !=
_lang.
YES())
372 if (sInstallInfoString.length())
375 if (!sScriptCommand.length())
392 std::vector<std::string> vDocFileContents;
396 if (sScriptCommand.find(
"</helpfile>") != std::string::npos)
398 sScriptCommand.erase(sScriptCommand.find(
"</helpfile>")+11);
399 sScriptCommand.erase(0, 10);
401 vDocFileContents.push_back(sScriptCommand);
405 vDocFileContents.push_back(sScriptCommand.substr(10));
409 while (nLine < m_script->getLinesCount())
416 if (sTemp.find(
"</helpfile>") == std::string::npos)
417 vDocFileContents.push_back(sTemp);
421 vDocFileContents.push_back(sTemp.substr(0,sTemp.find(
"</helpfile>")));
428 std::vector<DocumentationArticle>& vArticles = docFile.
getArticles();
430 for (
size_t i = 0; i < vArticles.size(); i++)
432 if (!
sHelpID.length() && vArticles[i].m_docEntry.sArticleId.length())
434 sHelpID = vArticles[i].m_docEntry.sArticleId;
437 if (
sHelpID.substr(0, 5) !=
"plgn_" &&
sHelpID.substr(0, 4) !=
"pkg_")
441 std::string sId = vArticles[i].m_docEntry.sArticleId;
443 if (sId.substr(0, 5) !=
"plgn_" && sId.substr(0, 4) !=
"pkg_")
445 std::string sNewId =
"pkg_" + sId;
446 vArticles[i].m_docEntry.sArticleId = sId;
449 if (!vArticles[i].m_keywords.size())
450 vArticles[i].m_keywords.push_back(
sInstallID);
453 std::string sHelpfileName =
"<>/docs/plugins/" +
sHelpID +
".nhlp";
456 docFile.
print(sHelpfileName);
460 sScriptCommand.clear();
475 std::string sLayoutFileName =
getArgAtPos(sScriptCommand, sScriptCommand.find_first_not_of(
' ', 6));
477 ofstream fLayoutFile(sLayoutFileName);
484 for (
size_t i = sScriptCommand.find_first_not_of(
' ', 6); i < sScriptCommand.length(); i++)
486 if (sScriptCommand[i] ==
'"' && sScriptCommand[i-1] !=
'\\')
489 if (!(nQuotes % 2) && sScriptCommand[i] ==
' ')
491 sScriptCommand =
"layout " + sScriptCommand.substr(i);
494 else if (i+1 == sScriptCommand.length())
495 sScriptCommand =
"layout";
500 if (sScriptCommand.find(
"endlayout") != string::npos)
502 sScriptCommand.erase(sScriptCommand.find(
"endlayout")+9);
505 if (!fLayoutFile.fail())
510 fLayoutFile << sScriptCommand << endl;
523 if (!fLayoutFile.fail())
528 fLayoutFile << sScriptCommand << endl;
534 while (nLine < m_script->getLinesCount())
543 if (sTemp.substr(0, 8) ==
"endgroup" || sTemp.substr(0, 9) ==
"endlayout")
546 sTemp.insert(0, nIndent,
'\t');
549 if (sTemp.find(
"endlayout") == string::npos)
552 fLayoutFile << sTemp << endl;
557 fLayoutFile << sTemp.substr(0, sTemp.find(
"endlayout")+9) << endl;
561 if (sTemp.substr(nIndent, 5) ==
"group")
574 sScriptCommand.clear();
587 std::string sDocumentation;
603 std::string sLine =
m_script->getLine(line);
605 sDocumentation += sLine +
"\n";
615 m_logger.
push_line(
">> Installing: \"" + sLine.substr(sLine.find(
'$'), sLine.find(
'(', sLine.find(
'$'))-sLine.find(
'$')) +
"\" ...");
627 while (nLine < m_script->getLinesCount())
655 size_t pos = sStartLine.find(
"<file ");
657 if (pos == std::string::npos || sStartLine.find(
"name=", pos) == std::string::npos)
662 std::vector<std::string> vFileContents;
663 size_t nIndent = UINT_MAX;
667 while (nLine < m_script->getLinesCount())
675 size_t nFirstChar = vFileContents.back().find_first_not_of(
' ');
679 if (nFirstChar < nIndent)
680 nIndent = nFirstChar;
687 if (
m_script->getStrippedLine(
nLine).find(
"<endfile>") != std::string::npos)
693 std::ofstream wholeFile(sFileName);
697 for (
size_t i = 0; i < vFileContents.size(); i++)
699 wholeFile << vFileContents[i].substr(nIndent) +
"\n";
719 if (sInstallInfoString.length())
726 if (sParam.find(
"ENABLE_FULL_LOGGING") != string::npos)
729 if (sParam.find(
"DISABLE_SCREEN_OUTPUT") != string::npos)
739 if (sInstallInfoString.length())
753 std::string sScriptCommand;
757 while (
m_script && nLine < m_script->getLinesCount() && !sScriptCommand.length())
768 if (sScriptCommand.length() > 2 && sScriptCommand.substr(sScriptCommand.length()-2) ==
"\\\\")
769 sScriptCommand.erase(sScriptCommand.length()-2);
771 sScriptCommand += sCurrentLine;
775 sScriptCommand.insert(0,
"|> ");
777 while (nLine < m_script->getLinesCount() && sScriptCommand.length() > 2 && sScriptCommand.substr(sScriptCommand.length()-2) ==
"\\\\");
780 if (!sScriptCommand.length())
785 if (sScriptCommand.substr(0,9) ==
"<install>" && !
isInstallMode)
788 while (nLine < m_script->getLinesCount())
794 if (sScriptCommand.substr(0,12) ==
"<endinstall>")
798 sScriptCommand.clear();
801 else if (sScriptCommand.substr(0,9) ==
"<install>")
809 bool shallReturn =
false;
812 while (nLine < m_script->getLinesCount())
818 if (sScriptCommand.substr(0,12) ==
"<endinstall>")
821 if (
findCommand(sScriptCommand).sString ==
"return")
823 else if (sScriptCommand.length())
829 m_logger.
push(
"--- NOT INSTALLED: NEWER OR SAME VERSION ALREADY AVAILABLE ---\n\n\n");
840 sScriptCommand.clear();
855 bool shallReturn =
false;
858 while (nLine < m_script->getLinesCount())
864 if (sScriptCommand.substr(0,12) ==
"<endinstall>")
867 if (
findCommand(sScriptCommand).sString ==
"return")
869 else if (sScriptCommand.length())
875 m_logger.
push(
"--- NOT INSTALLED: NEWER OR SAME VERSION ALREADY AVAILABLE ---\n\n\n");
886 sScriptCommand.clear();
898 sScriptCommand.clear();
921 sScriptCommand.clear();
930 m_logger.
push(
"--- INSTALLATION TERMINATED SUCCESSFULLY ---\n\n\n");
940 sScriptCommand = sScriptCommand.substr(12);
942 if (!sScriptCommand.length())
956 return sScriptCommand;
992 std::string sFileName =
m_script->getFileName();
993 m_include.reset(
new Includer(sScriptCommand, sFileName.substr(0, sFileName.rfind(
'/'))));
1005 return sScriptCommand;
1024 if (sCommand ==
"lclfunc")
1027 sScriptCommand.clear();
1033 sScriptCommand.clear();
1057 std::string sScriptCommand =
"";
1081 while (sScriptCommand.find(
"<this>") != string::npos)
1090 && sScriptCommand.find(
"procedure") != string::npos
1091 && sScriptCommand.find(
'$', sScriptCommand.find(
"procedure")) != string::npos)
1102 return sScriptCommand;
This class represents a whole documentation file with its contained documentation articles.
void print(const std::string &sFileName)
Print the documentation file to the specified file.
std::vector< DocumentationArticle > & getArticles()
Get all articles present in the current documentation file.
void addFileToDocumentationIndex(const std::string &sFileName)
This member function is used to add documentation index entries to the index during a plugin or packa...
static std::string getArgAtPos(const std::string &sCmd, unsigned int pos)
This static member is a fallback for the XML-parsing logic-stuff.
This class implements the basic input/ output file system and provides functionalities to work with f...
std::string ValidizeAndPrepareName(const std::string &_sFileName, const std::string &sExtension=".dat") const
This member function validizes the passed file name and creates the needed folders on-the-fly.
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
std::string sTokens[7][2]
bool reset()
This member function resets the FunctionDefinitionManager object to a state before any function was d...
bool defineFunc(const std::string &sExpr, bool bRedefine=false, bool bFallback=false)
This function defines a custom function, by passing it to a new FunctionDefinition class instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
This class represents a file, which can be included into other files using the @ syntax.
static bool is_including_syntax(const std::string &sLine)
Static member function which determines, whether the passed line is actually a including syntax.
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
void push(const std::string &sMessage)
Push a message to the logger stream. Will automatically re-open a file, if the stream had been closed...
bool is_open() const
Check, whether the logger stream is currently open.
void push_line(const std::string &sMessage)
Push a line to the logger stream. The stream will automatically append the line termination character...
bool open(const std::string &sLogFile)
Open the target logging file for writing.
void close()
Close the logger stream.
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
static void installationDone()
Notify the GUI that the installation was processed.
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
const std::vector< Package > & getInstalledPackages() const
Returns a vector containing the names and the version info of each installed plugin.
Procedure & getProcedureInterpreter()
void addHelpIndex(const std::string &_sPluginName, std::string _sHelpId)
This member function adds the passed documentation index ID to the plugin definition.
bool declareNewPackage(const std::string &sInstallInfoString)
This member function declares a new plugin from the passed install information string.
This class implements the logic to evaluate complex procedures, which may be called recursively.
bool writeProcedure(std::string sProcedureLine)
This member function handles the procedure installation process by governing the file stream and pass...
std::unique_ptr< Includer > m_include
FunctionDefinitionManager _localDef
bool handleInstallInformation(std::string &sScriptCommand)
This member function handles the install information tags of the current installation section.
Script()
Default constructor.
void openScript(std::string &_sScriptFileName)
This member function opens the script with the passed file name.
bool writeWholeFile()
Writes the contents of a whole file to the target file, which has been specified by the XML-like tags...
void writeDocumentationArticle(std::string &sScriptCommand)
This member function writes the appended documentation article to the target file.
void writeProcedure()
Writes a procedure including the comments to a procedure file.
void evaluateInstallInformation(std::string &sInstallInfoString)
This member function evaluates the flags from the installation information string and also removes un...
unsigned int nCurrentPackage
std::string getNextScriptCommandFromInclude()
This member function returns the next valid line from the included script.
std::vector< std::string > vInstallPackages
void writeLayout(std::string &sScriptCommand)
This member function writes the embedded window layout to the target file.
void close()
This member function closes an opened script.
std::unique_ptr< StyledTextFile > m_script
std::string sScriptFileName
std::string getNextScriptCommandFromScript()
This member function returns the next valid line from the currently opened script.
std::string getNextScriptCommand()
This member function is the main interface to the internal managed script. It will always return the ...
bool startInstallation(std::string &sScriptCommand)
This member function starts the current installation section.
void returnCommand()
This member function closes the script, if the code reached a "return" statement.
bool handleLocalDefinitions(std::string &sScriptCommand)
This private member function handles the definition and replacement of local functions.
std::string handleIncludeSyntax(std::string &sScriptCommand)
This member function handles the script include syntax ("@SCRIPT") and prepares the included file str...
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded...
void resolveSymbols(std::string &sCommandLine) const
Resolve all file-static constant declarations in the current line.
void clear()
Remove all file-static constant declarations.
void createSymbol(const std::string &sCommandLine)
Create one or more new file-static constant declarations for the current file.
Common exception class for all exceptions thrown in NumeRe.
@ PROCEDURE_WITHOUT_INSTALL_FOUND
@ INSUFFICIENT_NUMERE_VERSION
static size_t invalid_position
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
std::string toString(int)
Converts an integer to a string without the Settings bloat.