20#include "../utils/tools.hpp"
21#include "../maths/parser_functions.hpp"
22#include "../../kernel.hpp"
23#include "../ui/language.hpp"
39 if (!cmdParser.
getExpr().length())
44 std::string _sCmd =
"";
58 for (
const std::string& sFile : vFiles)
60 if (sFile.substr(sFile.rfind(
'.')) ==
".exe"
61 || sFile.substr(sFile.rfind(
'.')) ==
".dll"
62 || sFile.substr(sFile.rfind(
'.')) ==
".sys"
63 || sFile.substr(sFile.rfind(
'.')) ==
".vfm")
78 remove(sFile.c_str());
100 if (!cmdParser.
getExpr().length())
103 std::string sSource = cmdParser.
getExpr();
104 std::string sTarget =
"";
105 std::string _sTarget =
"";
106 std::string sDummy =
"";
107 std::string sFile =
"";
108 std::vector<std::string> vFileList;
110 unsigned int nthFile = 1;
112 bool bSuccess =
false;
150 if (!vFileList.size())
154 for (
unsigned int nFile = 0; nFile < vFileList.size(); nFile++)
157 sFile = vFileList[nFile];
159 if (sFile.find(
'.') != std::string::npos)
161 std::string sExt = sFile.substr(sFile.rfind(
'.'));
163 if (sExt !=
".exe" && sExt !=
".sys" && sExt !=
".dll")
170 if (_sTarget[_sTarget.length()-1] ==
'*' && _sTarget[_sTarget.length()-2] ==
'/')
171 _sTarget = _sTarget.substr(0, _sTarget.length()-2) + sFile.substr(sFile.rfind(
'/'));
172 else if (_sTarget[_sTarget.length()-1] ==
'/')
173 _sTarget = _sTarget.substr(0, _sTarget.length()-1) + sFile.substr(sFile.rfind(
'/'));
176 if (_sTarget.find(
'<') != std::string::npos && _sTarget.find(
'>', _sTarget.find(
'<')) != std::string::npos)
178 std::string sToken =
"";
180 for (
unsigned int i = 0; i < _sTarget.length(); i++)
182 if (_sTarget[i] ==
'<')
184 if (_sTarget.find(
'>', i) == std::string::npos)
187 sToken = _sTarget.substr(i, _sTarget.find(
'>', i)+1-i);
189 if (sToken.find(
'#') != std::string::npos)
191 unsigned int nLength = 1;
193 if (sToken.find(
'~') != std::string::npos)
194 nLength = sToken.rfind(
'~')-sToken.find(
'#')+1;
198 if (nLength >
toString((
int)nthFile).length())
199 sToken.append(nLength-
toString((
int)(nthFile)).length(),
'0');
202 _sTarget.replace(i,_sTarget.find(
'>',i)+1-i,sToken);
203 i += sToken.length();
205 else if (sToken ==
"<fname>")
207 sToken = sDummy.substr(sDummy.rfind(
'/')+1, sDummy.rfind(
'.')-1-sDummy.rfind(
'/'));
208 _sTarget.replace(i,_sTarget.find(
'>',i)+1-i,sToken);
209 i += sToken.length();
213 if (_sTarget.find(
'<',i) == std::string::npos)
224 if (_sTarget.substr(_sTarget.length()-2) ==
"/*")
225 _sTarget.erase(_sTarget.length()-1);
230 if (_sTarget.substr(_sTarget.rfind(
'.')-1) ==
"*.dat")
231 _sTarget = _sTarget.substr(0,_sTarget.rfind(
'/')) + sFile.substr(sFile.rfind(
'/'));
232 else if (_sTarget.substr(_sTarget.rfind(
'.')-1) ==
"/.dat")
233 _sTarget = _sTarget.substr(0, _sTarget.rfind(
'/')) + sFile.substr(sFile.rfind(
'/'));
235 if (_sTarget.substr(_sTarget.rfind(
'.')) != sFile.substr(sFile.rfind(
'.')))
236 _sTarget = _sTarget.substr(0, _sTarget.rfind(
'.')) + sFile.substr(sFile.rfind(
'.'));
251 || (cmdParser.
getCommandLine().find_first_of(
"?*") == std::string::npos)
252 || (sTarget.find(
'*') == std::string::npos && (sTarget[sTarget.length()-1] !=
'/' && sTarget.substr(sTarget.length()-2) !=
"/\"") && sTarget.find(
"<#") == std::string::npos && sTarget.find(
"<fname>") == std::string::npos))
263bool generateTemplate(
const std::string& sFile,
const std::string& sTempl,
const std::vector<std::string>& vTokens,
Settings& _option)
265 std::ifstream iTempl_in;
266 std::ofstream oFile_out;
270 iTempl_in.open(_option.
ValidFileName(sTempl,
".nlng").c_str());
271 oFile_out.open(_option.
ValidFileName(sFile, sFile.substr(sFile.rfind(
'.'))).c_str());
273 if (iTempl_in.fail() || oFile_out.fail())
280 while (!iTempl_in.eof())
282 std::getline(iTempl_in, sLine);
283 for (
unsigned int i = 0; i < vTokens.size(); i++)
286 while (sLine.find(sToken) != std::string::npos)
288 sLine.replace(sLine.find(sToken), sToken.length(), vTokens[i]);
291 oFile_out << sLine << std::endl;
This class provides the functionality to extract the different components of a command line into the ...
const std::string & getCommandLine() const
Returns the command line used for constructing this instance (e.g. for errors).
std::string getParameterValueAsString(const std::string &sParameter, const std::string &sDefaultValue, bool stripAlways=false, bool onlyStringEvaluation=false) const
Parses the selected parameter value as a string and returns it. If the parameter is not found,...
const std::string & getExpr() const
Returns the expression as plain value.
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to the return value statement.
void clearReturnValue()
Removes the return value statement.
const std::string & getCommand() const
Returns the command.
std::string parseExprAsString() const
Prepares the expression by handling all string operations and removing the surrounding quotation mark...
bool hasParam(const std::string &sParameter) const
Simple wrapper around findParameter(), if used as a boolean flag.
This class implements the basic input/ output file system and provides functionalities to work with f...
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
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...
void declareFileType(const std::string &sFileType)
This class handles the internal language system and returns the language strings of the selected lang...
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 ...
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
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 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...
This class manages the setting values of the internal (kernel) settings of this application.
Common exception class for all exceptions thrown in NumeRe.
static size_t invalid_position
bool generateTemplate(const std::string &sFile, const std::string &sTempl, const std::vector< std::string > &vTokens, Settings &_option)
bool removeFile(CommandLineParser &cmdParser)
Removes one or more files from the disk.
std::string removeQuotationMarks(const std::string &)
This function simply removes the surrounding quotation marks.
bool moveOrCopyFiles(CommandLineParser &cmdParser)
Moves or copies files from one location to another. Supports also wildcards and file lists.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
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.
std::string toString(int)
Converts an integer to a string without the Settings bloat.