NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
commandfunctions.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef COMMANDFUNCTIONS_HPP
20#define COMMANDFUNCTIONS_HPP
21
22#include <string>
23#include <vector>
24#include <map>
25#include "built-in.hpp"
28#include "plotting/plotting.hpp"
29#include "../kernel.hpp"
30#include "ui/winlayout.hpp"
31#include "io/logger.hpp"
32#include "utils/tools.hpp"
33#include "utils/archive.hpp"
34
35#include "commandlineparser.hpp"
36
37using namespace std;
38using namespace mu;
39
41{
48};
49
50
51typedef CommandReturnValues (*CommandFunc)(string&);
52
53extern mglGraph _fontData;
54
55string removeQuotationMarks(const string& sString);
56static size_t findSettingOption(const std::string& sCmd, const std::string& sOption);
57
67static bool confirmOperation(const std::string& sMessage)
68{
69 NumeReKernel::print(sMessage);
70 std::string sArgument;
71
72 do
73 {
75 NumeReKernel::getline(sArgument);
76 StripSpaces(sArgument);
77 }
78 while (!sArgument.length());
79
80 if (sArgument.substr(0, 1) != _lang.YES())
81 {
82 NumeReKernel::print(_lang.get("COMMON_CANCEL"));
83 return false;
84 }
85
86 return true;
87}
88
89
102static string getVarList(const string& sCmd, Parser& _parser, MemoryManager& _data, Settings& _option)
103{
104 mu::varmap_type mNumVars = _parser.GetVar();
105 map<string, string> mStringVars = NumeReKernel::getInstance()->getStringParser().getStringVars();
106 map<string, int> mVars;
107
108 string sSep = ", ";
109 string sReturn = "";
110
111 // Fill the vars map with the names and the
112 // types of the variables
113 for (auto iter = mNumVars.begin(); iter != mNumVars.end(); ++iter)
114 mVars[iter->first] = 0;
115
116 for (auto iter = mStringVars.begin(); iter != mStringVars.end(); ++iter)
117 mVars[iter->first] = 1;
118
119 // Change the separation characters, if the user
120 // wants the return value to be a string
121 if (findParameter(sCmd, "asstr"))
122 {
123 sSep = "\", \"";
124 sReturn = "\"";
125 }
126
127 // Return all variables, when "vars" was passed
128 if (findCommand(sCmd).sString == "vars")
129 {
130 for (auto iter = mVars.begin(); iter != mVars.end(); ++iter)
131 {
132 sReturn += iter->first + " = ";
133
134 if (iter->second)
135 {
136 if (findParameter(sCmd, "asstr"))
137 sReturn += "\\\"" + mStringVars[iter->first] + "\\\"";
138 else
139 sReturn += "\"" + mStringVars[iter->first] + "\"";
140 }
141 else
142 sReturn += toString(*mNumVars[iter->first], _option.getPrecision());
143
144 sReturn += sSep;
145 }
146 }
147
148 // Return only string variables, if "strings" was
149 // passed
150 if (findCommand(sCmd).sString == "strings")
151 {
152 for (auto iter = mStringVars.begin(); iter != mStringVars.end(); ++iter)
153 {
154 sReturn += iter->first + " = ";
155
156 if (findParameter(sCmd, "asstr"))
157 sReturn += "\\\"" + iter->second + "\\\"";
158 else
159 sReturn += "\"" + iter->second + "\"";
160
161 sReturn += sSep;
162 }
163
164 if (sReturn == "\"")
165 return "\"\"";
166 }
167
168 // Return only numerical variables, if "nums"
169 // was passed
170 if (findCommand(sCmd).sString == "nums")
171 {
172 for (auto iter = mNumVars.begin(); iter != mNumVars.end(); ++iter)
173 {
174 sReturn += iter->first + " = ";
175 sReturn += toString(*iter->second, _option.getPrecision());
176 sReturn += sSep;
177 }
178 }
179
180 // Remove the trailing separation character
181 if (findParameter(sCmd, "asstr") && sReturn.length() > 2)
182 sReturn.erase(sReturn.length() - 3);
183 else if (!findParameter(sCmd, "asstr") && sReturn.length() > 1)
184 sReturn.erase(sReturn.length() - 2);
185
186 return sReturn;
187}
188
189
201static bool undefineFunctions(string sFunctionList, FunctionDefinitionManager& _functions, const Settings& _option)
202{
203 string sSuccessFulRemoved;
204
205 // As long as the list of passed functions has a length,
206 // undefine the current first argument of the list
207 while (sFunctionList.length())
208 {
209 string sFunction = getNextArgument(sFunctionList, true);
210
211 // Try to undefine the functions
212 if (!_functions.undefineFunc(sFunction))
213 NumeReKernel::issueWarning(_lang.get("BUILTIN_CHECKKEYWORD_UNDEF_FAIL", sFunction));
214 else
215 sSuccessFulRemoved += sFunction + ", ";
216 }
217
218 // Inform the user that (some) of the functions were undefined
219 if (_option.systemPrints() && sSuccessFulRemoved.length())
220 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_UNDEF_SUCCESS", sSuccessFulRemoved.substr(0, sSuccessFulRemoved.length()-2)));
221
222 return true;
223}
224
225
235static bool prepareTemplate(const std::string& sTemplateID, const std::string& sFileName)
236{
237 std::vector<std::string> vTokens;
239
240 vTokens.push_back(sFileName.substr(sFileName.rfind('/') + 1, sFileName.rfind('.') - sFileName.rfind('/') - 1));
241 vTokens.push_back(getTimeStamp(false));
242
243 if (fileExists(_option.ValidFileName("<>/user/lang/" + sTemplateID + ".nlng", ".nlng")))
244 return generateTemplate(sFileName, "<>/user/lang/" + sTemplateID + ".nlng", vTokens, _option);
245
246 return generateTemplate(sFileName, "<>/lang/" + sTemplateID + ".nlng", vTokens, _option);
247}
248
249
261static bool newObject(string& sCmd, Parser& _parser, MemoryManager& _data, Settings& _option)
262{
264 std::string sFileName;
265 FileSystem _fSys;
266 _fSys.initializeFromKernel();
267
268 if (cmdParser.hasParam("dir"))
269 {
270 sFileName = replacePathSeparator(cmdParser.getParameterValueAsString("dir", "", true, true));
271 int nReturn = _fSys.setPath(sFileName, true, _option.getExePath());
272
273 if (nReturn == 1 && _option.systemPrints())
274 NumeReKernel::print(_lang.get("BUILTIN_NEW_FOLDERCREATED", sFileName));
275
276 return true;
277 }
278 else if (cmdParser.hasParam("script"))
279 {
280 sFileName = replacePathSeparator(cmdParser.getParameterValueAsString("script", "", true, true));
281
282 if (!sFileName.length())
283 return false;
284
285 if (sFileName.find(':') == std::string::npos && sFileName.front() != '<')
286 sFileName = "<scriptpath>/" + sFileName;
287
288 sFileName = _fSys.ValidizeAndPrepareName(sFileName, ".nscr");
289
290 if (!prepareTemplate("tmpl_script", sFileName))
291 throw SyntaxError(SyntaxError::CANNOT_GENERATE_SCRIPT, sCmd, sFileName, sFileName);
292
293 if (_option.systemPrints())
294 NumeReKernel::print(_lang.get("BUILTIN_NEW_SCRIPTCREATED", sFileName));
295
296 return true;
297 }
298 else if (cmdParser.hasParam("proc"))
299 {
300 sFileName = replacePathSeparator(cmdParser.getParameterValueAsString("proc", "", true, true));
301
302 if (!sFileName.length())
303 return false;
304
305 replaceAll(sFileName, "~", "/");
306 replaceAll(sFileName, "$", "");
307 replaceAll(sFileName, "main/", "");
308
309 if (sFileName.find(':') == std::string::npos && sFileName.front() != '<')
310 sFileName = "<procpath>/" + sFileName;
311
312 sFileName = _fSys.ValidizeAndPrepareName(sFileName, ".nprc");
313
314 if (!prepareTemplate("tmpl_procedure", sFileName))
315 throw SyntaxError(SyntaxError::CANNOT_GENERATE_PROCEDURE, sCmd, sFileName, sFileName);
316
317 if (_option.systemPrints())
318 NumeReKernel::print(_lang.get("BUILTIN_NEW_PROCCREATED", sFileName));
319
320 return true;
321 }
322 else if (cmdParser.hasParam("file"))
323 {
324 sFileName = replacePathSeparator(cmdParser.getParameterValueAsString("file", "", true, true));
325
326 if (!sFileName.length())
327 return false;
328
329 if (sFileName.find(':') == std::string::npos && sFileName.front() != '<')
330 sFileName = "<>/" + sFileName;
331
332 sFileName = _fSys.ValidizeAndPrepareName(sFileName, ".txt");
333
334 if (sFileName.substr(sFileName.rfind('.')) == ".nprc"
335 || sFileName.substr(sFileName.rfind('.')) == ".nscr"
336 || sFileName.substr(sFileName.rfind('.')) == ".nlyt"
337 || sFileName.substr(sFileName.rfind('.')) == ".ndat")
338 sFileName.replace(sFileName.rfind('.'), 5, ".txt");
339
340 if (!prepareTemplate("tmpl_file", sFileName))
341 throw SyntaxError(SyntaxError::CANNOT_GENERATE_FILE, sCmd, sFileName, sFileName);
342
343 if (_option.systemPrints())
344 NumeReKernel::print(_lang.get("BUILTIN_NEW_FILECREATED", sFileName));
345
346 return true;
347 }
348 else if (cmdParser.hasParam("plugin"))
349 {
350 sFileName = replacePathSeparator(cmdParser.getParameterValueAsString("plugin", "", true, true));
351
352 if (!sFileName.length())
353 return false;
354
355 if (sFileName.find(':') == std::string::npos && sFileName.front() != '<')
356 sFileName = "<scriptpath>/" + sFileName;
357
358 sFileName = _fSys.ValidizeAndPrepareName(sFileName, ".nscr");
359
360 if (!prepareTemplate("tmpl_plugin", sFileName))
361 throw SyntaxError(SyntaxError::CANNOT_GENERATE_SCRIPT, sCmd, sFileName, sFileName);
362
363 if (_option.systemPrints())
364 NumeReKernel::print(_lang.get("BUILTIN_NEW_PLUGINCREATED", sFileName));
365
366 return true;
367 }
368 else
369 {
370 if (cmdParser.getExpr().front() == '$')
371 {
372 sFileName = cmdParser.getExpr();
373
374 if (!sFileName.length())
375 return false;
376
377 replaceAll(sFileName, "~", "/");
378 replaceAll(sFileName, "$", "");
379 replaceAll(sFileName, "main/", "");
380
381 if (sFileName.find(':') == std::string::npos && sFileName.front() != '<')
382 sFileName = "<procpath>/" + sFileName;
383
384 sFileName = _fSys.ValidizeAndPrepareName(sFileName, ".nprc");
385
386 if (!prepareTemplate("tmpl_procedure", sFileName))
387 throw SyntaxError(SyntaxError::CANNOT_GENERATE_PROCEDURE, sCmd, sFileName, sFileName);
388
389 if (_option.systemPrints())
390 NumeReKernel::print(_lang.get("BUILTIN_NEW_PROCCREATED", sFileName));
391
392 return true;
393 }
394 else if (cmdParser.getExpr().find("()") != std::string::npos)
395 {
396 // Create new tables
397 std::string sReturnVal = "";
398 std::string sObject = cmdParser.parseExprAsString();
399
400 if (!sObject.length())
401 return false;
402
403 // Create the tables
404 while (sObject.length())
405 {
406 std::string sTableName = getNextArgument(sObject, true);
407
408 // Does the table already exist?
409 if (_data.isTable(sTableName))
410 {
411 if (cmdParser.hasParam("free"))
412 {
413 std::string sName = sTableName.substr(0, sTableName.find('('));
414 _data.deleteBulk(sName, 0, _data.getLines(sName) - 1, 0, _data.getCols(sName) - 1);
415
416 if (sReturnVal.length())
417 sReturnVal += ", ";
418
419 sReturnVal += "\"" + sTableName + "\"";
420 }
421
422 continue;
423 }
424
425 // Create a new table
426 if (_data.addTable(sTableName, _option))
427 {
428 if (sReturnVal.length())
429 sReturnVal += ", ";
430
431 sReturnVal += "\"" + sTableName + "\"";
432 continue;
433 }
434 else
435 return false;
436 }
437
438 if (sReturnVal.length() && _option.systemPrints())
439 {
440 if (cmdParser.hasParam("free"))
441 NumeReKernel::print(_lang.get("BUILTIN_NEW_FREE_CACHES", sReturnVal));
442 else
443 NumeReKernel::print(_lang.get("BUILTIN_NEW_CACHES", sReturnVal));
444 }
445
446 return true;
447 }
448 }
449
450 return false;
451}
452
453
465static bool editObject(string& sCmd, Parser& _parser, MemoryManager& _data, Settings& _option)
466{
467 int nType = 0;
468 int nFileOpenFlag = 0;
469
470 if (findParameter(sCmd, "norefresh"))
471 nFileOpenFlag = 1;
472
473 if (findParameter(sCmd, "refresh"))
474 nFileOpenFlag = 2 | 4;
475
476 string sObject;
477
478 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCmd))
480 else
481 {
482 sObject = sCmd.substr(findCommand(sCmd).sString.length());
483
484 // remove flags from object
485 if (nFileOpenFlag)
486 sObject.erase(sObject.rfind('-'));
487 }
488
489 StripSpaces(sObject);
490 FileSystem _fSys;
491 _fSys.setTokens(_option.getTokenPaths());
492
493 if (sObject.find('.') != string::npos)
494 _fSys.declareFileType(sObject.substr(sObject.rfind('.')));
495
496 if (!sObject.length())
498
499 if (sObject[0] == '$' && sObject[1] != '\'')
500 sObject = "<procpath>/" + sObject.substr(1);
501 else if (sObject[0] == '$')
502 sObject.erase(0, 1);
503
504 while (sObject.find('~') != string::npos)
505 sObject[sObject.find('~')] = '/';
506
507 while (sObject.find('$') != string::npos)
508 sObject.erase(sObject.find('$'), 1);
509
510 if (sObject[0] == '\'' && sObject[sObject.length() - 1] == '\'')
511 sObject = sObject.substr(1, sObject.length() - 2);
512
513 // Resolve the paths
514 if (sObject.find("<loadpath>") != string::npos || sObject.find(_option.getLoadPath()) != string::npos)
515 {
516 _fSys.setPath(_option.getLoadPath(), false, _option.getExePath());
517 sObject = _fSys.ValidFileName(sObject, ".dat");
518 }
519 else if (sObject.find("<savepath>") != string::npos || sObject.find(_option.getSavePath()) != string::npos)
520 {
521 _fSys.setPath(_option.getSavePath(), false, _option.getExePath());
522 sObject = _fSys.ValidFileName(sObject, ".dat");
523 }
524 else if (sObject.find("<scriptpath>") != string::npos || sObject.find(_option.getScriptPath()) != string::npos)
525 {
526 _fSys.setPath(_option.getScriptPath(), false, _option.getExePath());
527 sObject = _fSys.ValidFileName(sObject, ".nscr");
528 }
529 else if (sObject.find("<plotpath>") != string::npos || sObject.find(_option.getPlotPath()) != string::npos)
530 {
531 _fSys.setPath(_option.getPlotPath(), false, _option.getExePath());
532 sObject = _fSys.ValidFileName(sObject, ".png");
533 }
534 else if (sObject.find("<procpath>") != string::npos || sObject.find(_option.getProcPath()) != string::npos)
535 {
536 _fSys.setPath(_option.getProcPath(), false, _option.getExePath());
537 sObject = _fSys.ValidFileName(sObject, ".nprc");
538 }
539 else if (sObject.find("<wp>") != string::npos || sObject.find(_option.getWorkPath()) != string::npos)
540 {
541 _fSys.setPath(_option.getWorkPath(), false, _option.getExePath());
542 sObject = _fSys.ValidFileName(sObject, ".nprc");
543 }
544 else if (sObject.find("<>") != string::npos || sObject.find("<this>") != string::npos || sObject.find(_option.getExePath()) != string::npos)
545 {
546 _fSys.setPath(_option.getExePath(), false, _option.getExePath());
547 sObject = _fSys.ValidFileName(sObject, ".dat");
548 }
549 else if (!_data.containsTablesOrClusters(sObject))
550 {
551 // Is probably a folder path to be edited in the Windows Explorer
552 if (sObject.find('.') == string::npos && (sObject.find('/') != string::npos || sObject.find('\\') != string::npos))
553 {
554 ShellExecute(NULL, NULL, sObject.c_str(), NULL, NULL, SW_SHOWNORMAL);
555 return true;
556 }
557
558 // Append a wildcard at the end of the path if necessary
559 if (sObject[sObject.length() - 1] != '*' && sObject.find('.') == string::npos)
560 sObject += "*";
561
562 // Try to determine the path based upon the file extension, where we might find the
563 // file, if the user did not supply the path to the file
564 if (sObject.find('.') != string::npos)
565 {
566 if (sObject.substr(sObject.rfind('.')) == ".dat" || sObject.substr(sObject.rfind('.')) == ".txt")
567 {
568 _fSys.setPath(_option.getLoadPath(), false, _option.getExePath());
569 string sTemporaryObjectName = _fSys.ValidFileName(sObject, ".dat");
570
571 if (!fileExists(sTemporaryObjectName))
572 _fSys.setPath(_option.getSavePath(), false, _option.getExePath());
573 }
574 else if (sObject.substr(sObject.rfind('.')) == ".nscr")
575 _fSys.setPath(_option.getScriptPath(), false, _option.getExePath());
576 else if (sObject.substr(sObject.rfind('.')) == ".nprc")
577 _fSys.setPath(_option.getProcPath(), false, _option.getExePath());
578 else if (sObject.substr(sObject.rfind('.')) == ".png"
579 || sObject.substr(sObject.rfind('.')) == ".gif"
580 || sObject.substr(sObject.rfind('.')) == ".svg"
581 || sObject.substr(sObject.rfind('.')) == ".eps")
582 _fSys.setPath(_option.getPlotPath(), false, _option.getExePath());
583 else if (sObject.substr(sObject.rfind('.')) == ".tex")
584 {
585 _fSys.setPath(_option.getPlotPath(), false, _option.getExePath());
586 string sTemporaryObjectName = _fSys.ValidFileName(sObject, ".tex");
587
588 if (!fileExists(sTemporaryObjectName))
589 _fSys.setPath(_option.getSavePath(), false, _option.getExePath());
590 }
591 else if (sObject.substr(sObject.rfind('.')) == ".nhlp")
592 _fSys.setPath(_option.getExePath() + "/docs", false, _option.getExePath());
593 else
594 _fSys.setPath(_option.getExePath(), false, _option.getExePath());
595 }
596 else
597 _fSys.setPath(_option.getExePath(), false, _option.getExePath());
598
599 sObject = _fSys.ValidFileName(sObject, ".dat");
600 }
601
602 // Is probably a folder path
603 if (!_data.containsTablesOrClusters(sObject) && sObject.find('.') == string::npos && (sObject.find('/') != string::npos || sObject.find('\\') != string::npos))
604 {
605 ShellExecute(NULL, NULL, sObject.c_str(), NULL, NULL, SW_SHOWNORMAL);
606 return true;
607 }
608
609 // Open the table for editing
610 if (_data.containsTables(sObject))
611 {
612 StripSpaces(sObject);
613 string sTableName = sObject.substr(0, sObject.find('('));
614
615 NumeReKernel::showTable(_data.extractTable(sTableName), sTableName, true);
616 NumeReKernel::printPreFmt("|-> " + _lang.get("BUILTIN_WAITINGFOREDIT") + " ... ");
617
619 NumeReKernel::printPreFmt(_lang.get("COMMON_DONE") + ".\n");
620
621 if (_table.isEmpty())
622 return true;
623
624 _data.importTable(_table, sTableName);
625 return true;
626 }
627
628 // Could be a folder -> open it in the Windows Explorer
629 if (!fileExists(sObject) || sObject.find('.') == string::npos)
630 {
631 sObject.erase(sObject.rfind('.'));
632
633 if (sObject.find('*') != string::npos)
634 sObject.erase(sObject.rfind('*'));
635
636 if ((int)ShellExecute(NULL, NULL, sObject.c_str(), NULL, NULL, SW_SHOWNORMAL) > 32)
637 return true;
638
640 }
641
642 // Determine the file type of the file to be edited
643 if (sObject.substr(sObject.rfind('.')) == ".dat"
644 || sObject.substr(sObject.rfind('.')) == ".txt"
645 || sObject.substr(sObject.rfind('.')) == ".tex"
646 || sObject.substr(sObject.rfind('.')) == ".xml"
647 || sObject.substr(sObject.rfind('.')) == ".yaml"
648 || sObject.substr(sObject.rfind('.')) == ".yml"
649 || sObject.substr(sObject.rfind('.')) == ".json"
650 || sObject.substr(sObject.rfind('.')) == ".csv"
651 || sObject.substr(sObject.rfind('.')) == ".labx"
652 || sObject.substr(sObject.rfind('.')) == ".jdx"
653 || sObject.substr(sObject.rfind('.')) == ".jcm"
654 || sObject.substr(sObject.rfind('.')) == ".dx"
655 || sObject.substr(sObject.rfind('.')) == ".nscr"
656 || sObject.substr(sObject.rfind('.')) == ".nprc"
657 || sObject.substr(sObject.rfind('.')) == ".nhlp"
658 || sObject.substr(sObject.rfind('.')) == ".nlyt"
659 || sObject.substr(sObject.rfind('.')) == ".png"
660 || sObject.substr(sObject.rfind('.')) == ".gif"
661 || sObject.substr(sObject.rfind('.')) == ".m"
662 || sObject.substr(sObject.rfind('.')) == ".cpp"
663 || sObject.substr(sObject.rfind('.')) == ".cxx"
664 || sObject.substr(sObject.rfind('.')) == ".c"
665 || sObject.substr(sObject.rfind('.')) == ".hpp"
666 || sObject.substr(sObject.rfind('.')) == ".hxx"
667 || sObject.substr(sObject.rfind('.')) == ".h"
668 || sObject.substr(sObject.rfind('.')) == ".log")
669 nType = 1;
670 else if (sObject.substr(sObject.rfind('.')) == ".svg"
671 || sObject.substr(sObject.rfind('.')) == ".eps")
672 nType = 2;
673
674 if (!nType)
676
677 if (nType == 1)
678 {
679 NumeReKernel::nOpenFileFlag = nFileOpenFlag;
680 NumeReKernel::gotoLine(sObject);
681 }
682 else if (nType == 2)
683 openExternally(sObject);
684
685 return true;
686}
687
688
699static bool listDirectory(const string& sDir, const string& sParams, const Settings& _option)
700{
701 WIN32_FIND_DATA FindFileData;
702 HANDLE hFind = INVALID_HANDLE_VALUE;
703 LARGE_INTEGER Filesize;
704 double dFilesize = 0.0;
705 double dFilesizeTotal = 0.0;
706 string sConnect;
707 string sPattern = "*";
708 string sFilesize = " Bytes";
709 string sFileName;
710 string sDirectory = "";
711 int nLength = 0;
712 int nCount[2] = {0, 0};
713 unsigned int nFirstColLength = _option.getWindow() / 2 - 6;
714 bool bOnlyDir = false;
715
716 if (findSettingOption(sParams, "dir"))
717 bOnlyDir = true;
718
719 if (findSettingOption(sParams, "pattern") || findSettingOption(sParams, "p"))
720 {
721 int nPos = 0;
722
723 if (findSettingOption(sParams, "pattern"))
724 nPos = findSettingOption(sParams, "pattern");
725 else
726 nPos = findSettingOption(sParams, "p");
727
728 sPattern = getArgAtPos(sParams, nPos);
729 StripSpaces(sPattern);
730
731 if (!sPattern.length())
732 sPattern = "*";
733 }
734
735 for (int n = 0; n < 2; n++)
736 {
737 if (bOnlyDir && n)
738 break;
739
740 if (sDir == "LOADPATH")
741 {
742 hFind = FindFirstFile((_option.getLoadPath() + "\\" + sPattern).c_str(), &FindFileData);
743 sDirectory = _option.getLoadPath();
744 }
745 else if (sDir == "SAVEPATH")
746 {
747 hFind = FindFirstFile((_option.getSavePath() + "\\" + sPattern).c_str(), &FindFileData);
748 sDirectory = _option.getSavePath();
749 }
750 else if (sDir == "PLOTPATH")
751 {
752 hFind = FindFirstFile((_option.getPlotPath() + "\\" + sPattern).c_str(), &FindFileData);
753 sDirectory = _option.getPlotPath();
754 }
755 else if (sDir == "SCRIPTPATH")
756 {
757 hFind = FindFirstFile((_option.getScriptPath() + "\\" + sPattern).c_str(), &FindFileData);
758 sDirectory = _option.getScriptPath();
759 }
760 else if (sDir == "PROCPATH")
761 {
762 hFind = FindFirstFile((_option.getProcPath() + "\\" + sPattern).c_str(), &FindFileData);
763 sDirectory = _option.getProcPath();
764 }
765 else if (sDir == "WORKPATH")
766 {
767 hFind = FindFirstFile((_option.getWorkPath() + "\\" + sPattern).c_str(), &FindFileData);
768 sDirectory = _option.getWorkPath();
769 }
770 else
771 {
772 if (sDir[0] == '.')
773 {
774 hFind = FindFirstFile((_option.getExePath() + "\\" + sDir + "\\" + sPattern).c_str(), &FindFileData);
775 sDirectory = _option.getExePath() + "/" + sDir;
776 }
777 else if (sDir[0] == '<')
778 {
779 if (sDir.substr(0, 10) == "<loadpath>")
780 {
781 hFind = FindFirstFile((_option.getLoadPath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
782 sDirectory = _option.getLoadPath() + sDir.substr(10);
783 }
784 else if (sDir.substr(0, 10) == "<savepath>")
785 {
786 hFind = FindFirstFile((_option.getSavePath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
787 sDirectory = _option.getSavePath() + sDir.substr(10);
788 }
789 else if (sDir.substr(0, 12) == "<scriptpath>")
790 {
791 hFind = FindFirstFile((_option.getScriptPath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
792 sDirectory = _option.getScriptPath() + sDir.substr(12);
793 }
794 else if (sDir.substr(0, 10) == "<plotpath>")
795 {
796 hFind = FindFirstFile((_option.getPlotPath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
797 sDirectory = _option.getPlotPath() + sDir.substr(10);
798 }
799 else if (sDir.substr(0, 10) == "<procpath>")
800 {
801 hFind = FindFirstFile((_option.getProcPath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
802 sDirectory = _option.getProcPath() + sDir.substr(10);
803 }
804 else if (sDir.substr(0, 4) == "<wp>")
805 {
806 hFind = FindFirstFile((_option.getWorkPath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
807 sDirectory = _option.getWorkPath() + sDir.substr(10);
808 }
809 else if (sDir.substr(0, 2) == "<>" || sDir.substr(0, 6) == "<this>")
810 {
811 hFind = FindFirstFile((_option.getExePath() + "\\" + sDir.substr(sDir.find('>') + 1) + "\\" + sPattern).c_str(), &FindFileData);
812 sDirectory = _option.getExePath() + sDir.substr(sDir.find('>') + 1);
813 }
814 }
815 else
816 {
817 hFind = FindFirstFile((sDir + "\\" + sPattern).c_str(), &FindFileData);
818 sDirectory = sDir;
819 }
820 }
821
822 if (hFind == INVALID_HANDLE_VALUE)
823 return false;
824
825 do
826 {
827 sFilesize = " Bytes";
828 sConnect = "| ";
829 sConnect += FindFileData.cFileName;
830 sFileName = sDirectory + "/" + FindFileData.cFileName;
831
832 if (sConnect.length() + 3 > nFirstColLength) //31
833 sConnect = sConnect.substr(0, nFirstColLength - 14) + "..." + sConnect.substr(sConnect.length() - 8); //20
834
835 nLength = sConnect.length();
836
837 if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
838 {
839 if (n)
840 continue;
841
842 // Ignore parent and current directory placeholders
843 if (sConnect.substr(sConnect.length() - 2) == ".." || sConnect.substr(sConnect.length() - 1) == ".")
844 continue;
845
846 nCount[1]++;
847 sConnect += " (...)";
848 sConnect.append(nFirstColLength - 1 - nLength, ' ');
849 sConnect += "<" + _lang.get("BUILTIN_LISTFILES_CUSTOMPATH") + ">";
850 }
851 else if (!bOnlyDir && n)
852 {
853 nCount[0]++;
854 Filesize.LowPart = FindFileData.nFileSizeLow;
855 Filesize.HighPart = FindFileData.nFileSizeHigh;
856 string sExt = "";
857
858 if (sConnect.find('.') != string::npos)
859 sExt = toLowerCase(sConnect.substr(sConnect.rfind('.'), sConnect.find(' ', sConnect.rfind('.')) - sConnect.rfind('.')));
860
861 sConnect.append(nFirstColLength + 7 - nLength, '.');
862
863 // Get the language string for the current file type
864 if (!sExt.length())
865 sConnect += _lang.get("COMMON_FILETYPE_NOEXT");
866 else if (sExt == ".dx" || sExt == ".jcm")
867 sConnect += _lang.get("COMMON_FILETYPE_JDX");
868 else if (sExt == ".wave")
869 sConnect += _lang.get("COMMON_FILETYPE_WAV");
870 else
871 {
872 sExt = _lang.get("COMMON_FILETYPE_" + toUpperCase(sExt.substr(1)));
873
874 if (sExt.find("COMMON_FILETYPE_") != string::npos)
875 sConnect += sExt.substr(sExt.rfind('_')+1) + "-" + _lang.get("COMMON_FILETYPE_NOEXT");
876 else
877 sConnect += sExt;
878 }
879
880 // Create the file size string
881 dFilesize = (double)Filesize.QuadPart;
882 dFilesizeTotal += dFilesize;
883
884 if (dFilesize / 1000.0 >= 1)
885 {
886 dFilesize /= 1024.0;
887 sFilesize = "KBytes";
888
889 if (dFilesize / 1000.0 >= 1)
890 {
891 dFilesize /= 1024.0;
892 sFilesize = "MBytes";
893
894 if (dFilesize / 1000.0 >= 1)
895 {
896 dFilesize /= 1024.0;
897 sFilesize = "GBytes";
898 }
899 }
900 }
901
902 sFilesize = toString(dFilesize, 3) + " " + sFilesize;
903 sConnect.append(_option.getWindow() - sConnect.length() - sFilesize.length(), '.');
904 sConnect += sFilesize;
905
906 if (sExt == _lang.get("COMMON_FILETYPE_NDAT") && _option.showExtendedFileInfo())
907 {
908 sConnect += "\n| : ";
909 std::string sFileInfo = getFileInfo(sFileName);
910 replaceAll(sFileInfo, "\n", "\n| : ");
911 sConnect += sFileInfo;
912 }
913 }
914 else
915 continue;
916
917 NumeReKernel::printPreFmt(sConnect + "\n");
918 }
919 while (FindNextFile(hFind, &FindFileData) != 0);
920 }
921
922 FindClose(hFind);
923
924 // Create the byte sum string for the whole list
925 if (nCount[0])
926 {
927 sFilesize = " Bytes";
928
929 if (dFilesizeTotal / 1000.0 >= 1)
930 {
931 dFilesizeTotal /= 1024.0;
932 sFilesize = "KBytes";
933
934 if (dFilesizeTotal / 1000.0 >= 1)
935 {
936 dFilesizeTotal /= 1024.0;
937 sFilesize = "MBytes";
938
939 if (dFilesizeTotal / 1000.0 >= 1)
940 {
941 dFilesizeTotal /= 1024.0;
942 sFilesize = "GBytes";
943 }
944 }
945 }
946
947 sFilesize = "Total: " + toString(dFilesizeTotal, 3) + " " + sFilesize;
948 }
949 else
950 sFilesize = "";
951
952 string sSummary = "-- " + _lang.get("BUILTIN_LISTFILES_SUMMARY", toString(nCount[0]), toString(nCount[1])) + " --";
953 sSummary.append(_option.getWindow() - sSummary.length() - 4 - sFilesize.length(), ' ');
954 sSummary += sFilesize;
955
956 if (bOnlyDir)
957 {
958 if (nCount[1])
959 NumeReKernel::printPreFmt("| -- " + _lang.get("BUILTIN_LISTFILES_DIR_SUMMARY", toString(nCount[1])) + " --\n");
960 else
961 NumeReKernel::printPreFmt("| -- " + _lang.get("BUILTIN_LISTFILES_NODIRS") + " --\n");
962 }
963 else
964 NumeReKernel::printPreFmt("| " + sSummary + "\n");
965
966 return true;
967}
968
969
980static string createListDirectoryHeader(const string& sPathName, const string& sLangString, size_t nWindowLength)
981{
982 size_t nFirstColLength = nWindowLength / 2 - 6;
983 string sHeader = sPathName + " ";
984
985 if (sHeader.length() > nFirstColLength)
986 {
987 sHeader += "$";
988 sHeader.append(nFirstColLength, '-');
989 }
990 else
991 sHeader.append(nFirstColLength - sHeader.length(), '-');
992
993 sHeader += " <" + toUpperCase(sLangString) + "> ";
994
995 if (sHeader.find('$') != string::npos)
996 sHeader.append(nWindowLength - 4 - sHeader.length() + sHeader.rfind('$'), '-');
997 else
998 sHeader.append(nWindowLength - 4 - sHeader.length(), '-');
999
1000 return sHeader;
1001}
1002
1003
1014static bool listFiles(const string& sCmd, const Settings& _option)
1015{
1016 string sConnect = "";
1017 string sSpecified = "";
1018 string __sCmd = sCmd + " ";
1019 string sPattern = "";
1020 unsigned int nFirstColLength = _option.getWindow() / 2 - 6;
1021 bool bFreePath = false;
1022
1023 // Extract a search pattern
1024 if (findSettingOption(__sCmd, "pattern") || findSettingOption(__sCmd, "p"))
1025 {
1026 int nPos = 0;
1027
1028 if (findSettingOption(__sCmd, "pattern"))
1029 nPos = findSettingOption(__sCmd, "pattern");
1030 else
1031 nPos = findSettingOption(__sCmd, "p");
1032
1033 sPattern = getArgAtPos(__sCmd, nPos);
1034 StripSpaces(sPattern);
1035
1036 if (sPattern.length())
1037 sPattern = _lang.get("BUILTIN_LISTFILES_FILTEREDFOR", sPattern);
1038 }
1039
1041
1042 // Write the headline
1043 make_hline();
1044 sConnect = "NUMERE: " + toUpperCase(_lang.get("BUILTIN_LISTFILES_EXPLORER"));
1045
1046 if (sConnect.length() > nFirstColLength + 6)
1047 sConnect += " ";
1048 else
1049 sConnect.append(nFirstColLength + 6 - sConnect.length(), ' ');
1050
1051 NumeReKernel::print(LineBreak(sConnect + sPattern, _option, true, 0, sConnect.length()) );
1052 make_hline();
1053
1054 // Find the specified folder
1055 size_t nPos = findSettingOption(__sCmd, "files");
1056
1057 if (nPos && sCmd[nPos-1] == '=')
1058 {
1059 sSpecified = getArgAtPos(__sCmd, nPos);
1060 StripSpaces(sSpecified);
1061
1062 if (sSpecified[0] == '<' && sSpecified[sSpecified.length() - 1] == '>' && sSpecified != "<>" && sSpecified != "<this>")
1063 {
1064 sSpecified = sSpecified.substr(1, sSpecified.length() - 2);
1065 sSpecified = toLowerCase(sSpecified);
1066
1067 if (sSpecified != "loadpath" && sSpecified != "savepath" && sSpecified != "plotpath" && sSpecified != "scriptpath" && sSpecified != "procpath" && sSpecified != "wp")
1068 sSpecified = "";
1069 }
1070 else
1071 bFreePath = true;
1072 }
1073
1074 // Write the headers and list the directories
1075 if (!bFreePath)
1076 {
1077 if (!sSpecified.length() || sSpecified == "loadpath")
1078 {
1079 NumeReKernel::print(createListDirectoryHeader(_option.getLoadPath(), _lang.get("BUILTIN_LISTFILES_LOADPATH"), _option.getWindow()));
1080
1081 if (!listDirectory("LOADPATH", __sCmd, _option))
1082 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1083 }
1084
1085 if (!sSpecified.length() || sSpecified == "savepath")
1086 {
1087 if (!sSpecified.length())
1089
1090 NumeReKernel::print(createListDirectoryHeader(_option.getSavePath(), _lang.get("BUILTIN_LISTFILES_SAVEPATH"), _option.getWindow()));
1091
1092 if (!listDirectory("SAVEPATH", __sCmd, _option))
1093 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1094 }
1095
1096 if (!sSpecified.length() || sSpecified == "scriptpath")
1097 {
1098 if (!sSpecified.length())
1100
1101 NumeReKernel::print(createListDirectoryHeader(_option.getScriptPath(), _lang.get("BUILTIN_LISTFILES_SCRIPTPATH"), _option.getWindow()));
1102
1103 if (!listDirectory("SCRIPTPATH", __sCmd, _option))
1104 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1105 }
1106
1107 if (!sSpecified.length() || sSpecified == "procpath")
1108 {
1109 if (!sSpecified.length())
1111
1112 NumeReKernel::print(createListDirectoryHeader(_option.getProcPath(), _lang.get("BUILTIN_LISTFILES_PROCPATH"), _option.getWindow()));
1113
1114 if (!listDirectory("PROCPATH", __sCmd, _option))
1115 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1116 }
1117
1118 if (!sSpecified.length() || sSpecified == "plotpath")
1119 {
1120 if (!sSpecified.length())
1122
1123 NumeReKernel::print(createListDirectoryHeader(_option.getPlotPath(), _lang.get("BUILTIN_LISTFILES_PLOTPATH"), _option.getWindow()));
1124
1125 if (!listDirectory("PLOTPATH", __sCmd, _option))
1126 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1127 }
1128
1129 if (sSpecified == "wp")
1130 {
1131 NumeReKernel::print(createListDirectoryHeader(_option.getWorkPath(), _lang.get("BUILTIN_LISTFILES_WORKPATH"), _option.getWindow()));
1132
1133 if (!listDirectory("WORKPATH", __sCmd, _option))
1134 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1135 }
1136 }
1137 else
1138 {
1139 sSpecified = fromSystemCodePage(sSpecified);
1140
1141 if (sSpecified == "<>" || sSpecified == "<this>")
1142 NumeReKernel::print(createListDirectoryHeader(_option.getExePath(), _lang.get("BUILTIN_LISTFILES_ROOTPATH"), _option.getWindow()));
1143 else
1144 NumeReKernel::print(createListDirectoryHeader(sSpecified, _lang.get("BUILTIN_LISTFILES_CUSTOMPATH"), _option.getWindow()));
1145
1146 if (!listDirectory(sSpecified, __sCmd, _option))
1147 NumeReKernel::printPreFmt(LineBreak("| -- " + _lang.get("BUILTIN_LISTFILES_NOFILES") + " --", _option) + "\n");
1148 }
1149
1150 make_hline();
1151
1153 return true;
1154}
1155
1156
1168static void listFunctions(const Settings& _option, const string& sType) //PRSRFUNC_LISTFUNC_[TYPES]_*
1169{
1171 make_hline();
1172 NumeReKernel::printPreFmt("|-> NUMERE: " + toUpperCase(_lang.get("PARSERFUNCS_LISTFUNC_HEADLINE")));
1173 if (sType != "all")
1174 {
1175 NumeReKernel::printPreFmt(" [" + toUpperCase(_lang.get("PARSERFUNCS_LISTFUNC_TYPE_" + toUpperCase(sType))) + "]");
1176 }
1178 make_hline();
1179 NumeReKernel::printPreFmt(LineBreak("| " + _lang.get("PARSERFUNCS_LISTFUNC_TABLEHEAD"), _option, false, 0, 28) + "\n|\n");
1180 vector<string> vFuncs;
1181
1182 // Get the list of functions from the language file
1183 // depending on the selected type
1184 if (sType == "all")
1185 vFuncs = _lang.getList("PARSERFUNCS_LISTFUNC_FUNC_*");
1186 else
1187 vFuncs = _lang.getList("PARSERFUNCS_LISTFUNC_FUNC_*_[" + toUpperCase(sType) + "]");
1188
1189 // Print the obtained function list on the terminal
1190 for (unsigned int i = 0; i < vFuncs.size(); i++)
1191 {
1192 NumeReKernel::printPreFmt(LineBreak("| " + vFuncs[i], _option, false, 0, 60) + "\n");
1193 }
1195 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTFUNC_FOOTNOTE1"), _option));
1196 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTFUNC_FOOTNOTE2"), _option));
1198 make_hline();
1199 return;
1200}
1201
1202
1215static void listDefinitions(const FunctionDefinitionManager& _functions, const Settings& _option)
1216{
1218 make_hline();
1219 NumeReKernel::print("NUMERE: " + toUpperCase(_lang.get("PARSERFUNCS_LISTDEFINE_HEADLINE")));
1220 make_hline();
1221 if (!_functions.getDefinedFunctions())
1222 {
1223 NumeReKernel::print(toSystemCodePage(_lang.get("PARSERFUNCS_LISTDEFINE_EMPTY")));
1224 }
1225 else
1226 {
1227 // Print all custom defined functions on the terminal
1228 for (unsigned int i = 0; i < _functions.getDefinedFunctions(); i++)
1229 {
1230 // Print first the name of the function
1231 NumeReKernel::printPreFmt(sectionHeadline(_functions.getFunctionSignature(i).substr(0, _functions.getFunctionSignature(i).rfind('('))));
1232
1233 // Print the comment, if it is available
1234 if (_functions.getComment(i).length())
1235 {
1236 NumeReKernel::printPreFmt(LineBreak("| " + _lang.get("PARSERFUNCS_LISTDEFINE_DESCRIPTION", _functions.getComment(i)), _option, true, 0, 25) + "\n"); //10
1237 }
1238
1239 // Print the actual implementation of the function
1240 NumeReKernel::printPreFmt(LineBreak("| " + _lang.get("PARSERFUNCS_LISTDEFINE_DEFINITION", _functions.getFunctionSignature(i), _functions.getImplementation(i)), _option, false, 0, 29) + "\n"); //14
1241 }
1242 NumeReKernel::printPreFmt("| -- " + toString(_functions.getDefinedFunctions()) + " " + toSystemCodePage(_lang.get("PARSERFUNCS_LISTDEFINE_FUNCTIONS")) + " --\n");
1243 }
1245 make_hline();
1246 return;
1247}
1248
1249
1258static void listLogicalOperators(const Settings& _option)
1259{
1261 make_hline();
1262 NumeReKernel::print(toSystemCodePage("NUMERE: " + toUpperCase(_lang.get("PARSERFUNCS_LISTLOGICAL_HEADLINE"))));
1263 make_hline();
1264 NumeReKernel::printPreFmt(toSystemCodePage("| " + _lang.get("PARSERFUNCS_LISTLOGICAL_TABLEHEAD")) + "\n|\n");
1265
1266 // Get the list of all logical expressions
1267 vector<string> vLogicals = _lang.getList("PARSERFUNCS_LISTLOGICAL_ITEM*");
1268
1269 // Print the list on the terminal
1270 for (unsigned int i = 0; i < vLogicals.size(); i++)
1271 NumeReKernel::printPreFmt(toSystemCodePage("| " + vLogicals[i]) + "\n");
1272
1274 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTLOGICAL_FOOTNOTE1"), _option));
1275 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTLOGICAL_FOOTNOTE2"), _option));
1277 make_hline();
1278 return;
1279}
1280
1281
1297static void listDeclaredVariables(Parser& _parser, const Settings& _option, const MemoryManager& _data)
1298{
1299 int nDataSetNum = 1;
1300 map<string, int> VarMap;
1301 int nBytesSum = 0;
1302
1303 // Query the used variables
1304 //
1305 // Get the numerical variables
1306 mu::varmap_type variables = _parser.GetVar();
1307
1308 // Get the string variables
1309 map<string, string> StringMap = NumeReKernel::getInstance()->getStringParser().getStringVars();
1310
1311 // Get the current defined data tables
1312 map<string, std::pair<size_t,size_t>> CacheMap = _data.getTableMap();
1313
1314 const map<string, NumeRe::Cluster>& mClusterMap = _data.getClusterMap();
1315
1316 // Combine string and numerical variables to have
1317 // them sorted after their name
1318 for (auto iter = variables.begin(); iter != variables.end(); ++iter)
1319 {
1320 VarMap[iter->first] = 0;
1321 }
1322 for (auto iter = StringMap.begin(); iter != StringMap.end(); ++iter)
1323 {
1324 VarMap[iter->first] = 1;
1325 }
1326
1327 // Get data table and string table sizes
1328 string sStringSize = toString(_data.getStringElements()) + " x " + toString(_data.getStringCols());
1329
1331 make_hline();
1332 NumeReKernel::print("NUMERE: " + toUpperCase(toSystemCodePage(_lang.get("PARSERFUNCS_LISTVAR_HEADLINE"))));
1333 make_hline();
1334
1335 // Print all defined caches first
1336 for (auto iter = CacheMap.begin(); iter != CacheMap.end(); ++iter)
1337 {
1338 string sCacheSize = toString(_data.getLines(iter->first, false)) + " x " + toString(_data.getCols(iter->first, false));
1339 NumeReKernel::printPreFmt("| " + iter->first + "()" + strfill("Dim:", (_option.getWindow(0) - 32) / 2 - (iter->first).length() + _option.getWindow(0) % 2) + strfill(sCacheSize, (_option.getWindow(0) - 50) / 2) + strfill("[table]", 19));
1340
1341 if (_data.getSize(iter->second.second) >= 1024 * 1024)
1342 NumeReKernel::printPreFmt(strfill(toString(_data.getSize(iter->second.second) / (1024.0 * 1024.0), 4), 9) + " MBytes\n");
1343 else if (_data.getSize(iter->second.second) >= 1024)
1344 NumeReKernel::printPreFmt(strfill(toString(_data.getSize(iter->second.second) / (1024.0), 4), 9) + " KBytes\n");
1345 else
1346 NumeReKernel::printPreFmt(strfill(toString(_data.getSize(iter->second.second)), 9) + " Bytes\n");
1347
1348 nBytesSum += _data.getSize(iter->second.second);
1349 }
1350
1351 NumeReKernel::printPreFmt("| " + strfill("-", _option.getWindow(0) - 4, '-') + "\n");
1352
1353 // Print all defined cluster
1354 for (auto iter = mClusterMap.begin(); iter != mClusterMap.end(); ++iter)
1355 {
1356 string sClusterSize = toString(iter->second.size()) + " x 1";
1357 NumeReKernel::printPreFmt("| " + iter->first + "{}" + strfill("Dim:", (_option.getWindow(0) - 32) / 2 - (iter->first).length() + _option.getWindow(0) % 2) + strfill(sClusterSize, (_option.getWindow(0) - 50) / 2) + strfill("[cluster]", 19));
1358
1359 if (iter->second.getBytes() >= 1024 * 1024)
1360 NumeReKernel::printPreFmt(strfill(toString(iter->second.getBytes() / (1024.0 * 1024.0), 4), 9) + " MBytes\n");
1361 else if (iter->second.getBytes() >= 1024)
1362 NumeReKernel::printPreFmt(strfill(toString(iter->second.getBytes() / (1024.0), 4), 9) + " KBytes\n");
1363 else
1364 NumeReKernel::printPreFmt(strfill(toString(iter->second.getBytes()), 9) + " Bytes\n");
1365
1366 nBytesSum += iter->second.getBytes();
1367 }
1368
1369 if (mClusterMap.size())
1370 NumeReKernel::printPreFmt("| " + strfill("-", _option.getWindow(0) - 4, '-') + "\n");
1371
1372
1373 // Print now the dimension of the string table
1374 if (_data.getStringElements())
1375 {
1376 NumeReKernel::printPreFmt("| string()" + strfill("Dim:", (_option.getWindow(0) - 32) / 2 - 6 + _option.getWindow(0) % 2) + strfill(sStringSize, (_option.getWindow(0) - 50) / 2) + strfill("[string x string]", 19));
1377 if (_data.getStringSize() >= 1024 * 1024)
1378 NumeReKernel::printPreFmt(strfill(toString(_data.getStringSize() / (1024.0 * 1024.0), 4), 9) + " MBytes\n");
1379 else if (_data.getStringSize() >= 1024)
1380 NumeReKernel::printPreFmt(strfill(toString(_data.getStringSize() / (1024.0), 4), 9) + " KBytes\n");
1381 else
1382 NumeReKernel::printPreFmt(strfill(toString(_data.getStringSize()), 9) + " Bytes\n");
1383 nBytesSum += _data.getStringSize();
1384
1385 NumeReKernel::printPreFmt("| " + strfill("-", _option.getWindow(0) - 4, '-') + "\n");
1386 }
1387
1388 // Print now the set of variables
1389 for (auto item = VarMap.begin(); item != VarMap.end(); ++item)
1390 {
1391 // The second member indicates, whether a
1392 // variable is a string or a numerical variable
1393 if (item->second)
1394 {
1395 // This is a string
1396 NumeReKernel::printPreFmt("| " + item->first + strfill(" = ", (_option.getWindow(0) - 20) / 2 + 1 - _option.getPrecision() - (item->first).length() + _option.getWindow(0) % 2));
1397 if (StringMap[item->first].length() > _option.getPrecision() + (_option.getWindow(0) - 60) / 2 - 4)
1398 NumeReKernel::printPreFmt(strfill("\"" + StringMap[item->first].substr(0, _option.getPrecision() + (_option.getWindow(0) - 60) / 2 - 7) + "...\"", (_option.getWindow(0) - 60) / 2 + _option.getPrecision()));
1399 else
1400 NumeReKernel::printPreFmt(strfill("\"" + StringMap[item->first] + "\"", (_option.getWindow(0) - 60) / 2 + _option.getPrecision()));
1401 NumeReKernel::printPreFmt(strfill("[string]", 19) + strfill(toString(StringMap[item->first].size()), 9) + " Bytes\n");
1402 nBytesSum += StringMap[item->first].size();
1403 }
1404 else
1405 {
1406 // This is a numerical variable
1407 NumeReKernel::printPreFmt("| " + item->first + strfill(" = ", (_option.getWindow(0) - 20) / 2 + 1 - _option.getPrecision() - (item->first).length() + _option.getWindow(0) % 2) + strfill(toString(*variables[item->first], _option.getPrecision()), (_option.getWindow(0) - 60) / 2 + _option.getPrecision()) + (variables[item->first]->imag() ? strfill("[complex]", 19) + strfill("16", 9) + " Bytes\n" : strfill("[double]", 19) + strfill("8", 9) + " Bytes\n"));
1408 nBytesSum += variables[item->first]->imag() ? sizeof(std::complex<double>) : sizeof(double);
1409 }
1410 }
1411
1412 // Create now the footer of the list:
1413 // Combine the number of variables and data
1414 // tables first
1415 NumeReKernel::printPreFmt("| -- " + toString(VarMap.size()) + " " + toSystemCodePage(_lang.get("PARSERFUNCS_LISTVAR_VARS_AND")) + " ");
1416 if (_data.isValid() || _data.getStringElements())
1417 {
1418 if (_data.isValid() && _data.getStringElements())
1419 {
1420 NumeReKernel::printPreFmt(toString(1 + CacheMap.size()));
1421 nDataSetNum = CacheMap.size() + 1;
1422 }
1423 else if (_data.isValid())
1424 {
1425 NumeReKernel::printPreFmt(toString(CacheMap.size()));
1426 nDataSetNum = CacheMap.size();
1427 }
1428 else
1430 }
1431 else
1433 NumeReKernel::printPreFmt(" " + toSystemCodePage(_lang.get("PARSERFUNCS_LISTVAR_DATATABLES")) + " --");
1434
1435 // Calculate now the needed memory for the stored values and print it at the
1436 // end of the footer line
1437 if (VarMap.size() > 9 && nDataSetNum > 9)
1438 NumeReKernel::printPreFmt(strfill("Total: ", (_option.getWindow(0) - 32 - _lang.get("PARSERFUNCS_LISTVAR_VARS_AND").length() - _lang.get("PARSERFUNCS_LISTVAR_DATATABLES").length())));
1439 else if (VarMap.size() > 9 || nDataSetNum > 9)
1440 NumeReKernel::printPreFmt(strfill("Total: ", (_option.getWindow(0) - 31 - _lang.get("PARSERFUNCS_LISTVAR_VARS_AND").length() - _lang.get("PARSERFUNCS_LISTVAR_DATATABLES").length())));
1441 else
1442 NumeReKernel::printPreFmt(strfill("Total: ", (_option.getWindow(0) - 30 - _lang.get("PARSERFUNCS_LISTVAR_VARS_AND").length() - _lang.get("PARSERFUNCS_LISTVAR_DATATABLES").length())));
1443 if (nBytesSum >= 1024 * 1024)
1444 NumeReKernel::printPreFmt(strfill(toString(nBytesSum / (1024.0 * 1024.0), 4), 8) + " MBytes\n");
1445 else if (nBytesSum >= 1024)
1446 NumeReKernel::printPreFmt(strfill(toString(nBytesSum / (1024.0), 4), 8) + " KBytes\n");
1447 else
1448 NumeReKernel::printPreFmt(strfill(toString(nBytesSum), 8) + " Bytes\n");
1450 make_hline();
1451 return;
1452}
1453
1454
1465static void listConstants(const Parser& _parser, const Settings& _option)
1466{
1467 const int nUnits = 20;
1468 // Define a set of units including a simple
1469 // heuristic, which defines, which constant
1470 // needs which unit
1471 static string sUnits[nUnits] =
1472 {
1473 "_G[m^3/(kg s^2)]",
1474 "_R[J/(mol K)]",
1475 "_coul_norm[V m/(A s)]",
1476 "_c[m/s]",
1477 "_elek[A s/(V m)]",
1478 "_elem[A s]",
1479 "_gamma[1/(T s)]",
1480 "_g[m/s^2]",
1481 "_hartree[J]",
1482 "_h[J s]",
1483 "_k[J/K]",
1484 "_m_[kg]",
1485 "_magn[V s/(A m)]",
1486 "_mu_[J/T]",
1487 "_n[1/mol]",
1488 "_rydberg[1/m]",
1489 "_r[m]",
1490 "_stefan[J/(m^2 s K^4)]",
1491 "_wien[m K]",
1492 "_[---]"
1493 };
1495 make_hline();
1496 NumeReKernel::print("NUMERE: " + toSystemCodePage(toUpperCase(_lang.get("PARSERFUNCS_LISTCONST_HEADLINE"))));
1497 make_hline();
1498
1499 // Get the map of all defined constants from the parser
1500 mu::valmap_type cmap = _parser.GetConst();
1501 valmap_type::const_iterator item = cmap.begin();
1502
1503 // Print all constants, their values and their unit on
1504 // the terminal
1505 for (; item != cmap.end(); ++item)
1506 {
1507 if (item->first[0] != '_')
1508 continue;
1509 NumeReKernel::printPreFmt("| " + item->first + strfill(" = ", (_option.getWindow() - 10) / 2 + 2 - _option.getPrecision() - (item->first).length() + _option.getWindow() % 2) + strfill(toString(item->second, _option.getPrecision()), _option.getPrecision() + (_option.getWindow() - 50) / 2));
1510 for (int i = 0; i < nUnits; i++)
1511 {
1512 if (sUnits[i].substr(0, sUnits[i].find('[')) == (item->first).substr(0, sUnits[i].find('[')))
1513 {
1514 NumeReKernel::printPreFmt(strfill(sUnits[i].substr(sUnits[i].find('[')), 24) + "\n");
1515 break;
1516 }
1517 }
1518 }
1520 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTCONST_FOOTNOTE1"), _option));
1521 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTCONST_FOOTNOTE2"), _option));
1523 make_hline();
1524 return;
1525}
1526
1527
1538static void listCommands(const Settings& _option)
1539{
1541 make_hline();
1542 NumeReKernel::print("NUMERE: " + toSystemCodePage(toUpperCase(_lang.get("PARSERFUNCS_LISTCMD_HEADLINE")))); //PRSRFUNC_LISTCMD_*
1543 make_hline();
1544 NumeReKernel::printPreFmt(LineBreak("| " + _lang.get("PARSERFUNCS_LISTCMD_TABLEHEAD"), _option, 0) + "\n|\n");
1545
1546 // Get the list of all defined commands
1547 // from the language files
1548 vector<string> vCMDList = _lang.getList("PARSERFUNCS_LISTCMD_CMD_*");
1549
1550 // Print the complete list on the terminal
1551 for (unsigned int i = 0; i < vCMDList.size(); i++)
1552 {
1553 NumeReKernel::printPreFmt(LineBreak("| " + vCMDList[i], _option, false, 0, 42) + "\n");
1554 }
1555
1557 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTCMD_FOOTNOTE1"), _option));
1558 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTCMD_FOOTNOTE2"), _option));
1560 make_hline();
1561}
1562
1563
1577static void printUnits(const string& sUnit, const string& sDesc, const string& sDim, const string& sValues, unsigned int nWindowsize)
1578{
1579 NumeReKernel::printPreFmt("| " + strlfill(sUnit, 11) + strlfill(sDesc, (nWindowsize - 17) / 3 + (nWindowsize + 1) % 3) + strlfill(sDim, (nWindowsize - 35) / 3) + "=" + strfill(sValues, (nWindowsize - 2) / 3) + "\n");
1580 return;
1581}
1582
1583
1594static void listUnitConversions(const Settings& _option) //PRSRFUNC_LISTUNITS_*
1595{
1597 make_hline();
1598 NumeReKernel::print("NUMERE: " + toSystemCodePage(toUpperCase(_lang.get("PARSERFUNCS_LISTUNITS_HEADLINE")))); //(_option.getWindow()-x)/3
1599 make_hline(); // 11 21 x=17 15 x=35 1 x=2 26
1600 printUnits(_lang.get("PARSERFUNCS_LISTUNITS_SYMBOL"), _lang.get("PARSERFUNCS_LISTUNITS_DESCRIPTION"), _lang.get("PARSERFUNCS_LISTUNITS_DIMENSION"), _lang.get("PARSERFUNCS_LISTUNITS_UNIT"), _option.getWindow());
1602 printUnits("1'A", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_ANGSTROEM"), "L", "1e-10 [m]", _option.getWindow());
1603 printUnits("1'AU", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_ASTRO_UNIT"), "L", "1.4959787e11 [m]", _option.getWindow());
1604 printUnits("1'b", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_BARN"), "L^2", "1e-28 [m^2]", _option.getWindow());
1605 printUnits("1'cal", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_CALORY"), "M L^2 / T^2", "4.1868 [J]", _option.getWindow());
1606 printUnits("1'Ci", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_CURIE"), "1 / T", "3.7e10 [Bq]", _option.getWindow());
1607 printUnits("1'eV", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_ELECTRONVOLT"), "M L^2 / T^2", "1.60217657e-19 [J]", _option.getWindow());
1608 printUnits("1'fm", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_FERMI"), "L", "1e-15 [m]", _option.getWindow());
1609 printUnits("1'ft", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_FOOT"), "L", "0.3048 [m]", _option.getWindow());
1610 printUnits("1'Gs", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_GAUSS"), "M / (T^2 I)", "1e-4 [T]", _option.getWindow());
1611 printUnits("1'in", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_INCH"), "L", "0.0254 [m]", _option.getWindow());
1612 printUnits("1'kmh", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_VELOCITY"), "L / T", "0.2777777... [m/s]", _option.getWindow());
1613 printUnits("1'kn", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_KNOTS"), "L / T", "0.5144444... [m/s]", _option.getWindow());
1614 printUnits("1'l", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_LITERS"), "L^3", "1e-3 [m^3]", _option.getWindow());
1615 printUnits("1'ly", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_LIGHTYEAR"), "L", "9.4607305e15 [m]", _option.getWindow());
1616 printUnits("1'mile", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_MILE"), "L", "1609.344 [m]", _option.getWindow());
1617 printUnits("1'mol", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_MOL"), "N", "6.022140857e23 ---", _option.getWindow());
1618 printUnits("1'mph", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_VELOCITY"), "L / T", "0.44703722 [m/s]", _option.getWindow());
1619 printUnits("1'Ps", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_POISE"), "M / (L T)", "0.1 [Pa s]", _option.getWindow());
1620 printUnits("1'pc", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_PARSEC"), "L", "3.0856776e16 [m]", _option.getWindow());
1621 printUnits("1'psi", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_PSI"), "M / (L T^2)", "6894.7573 [Pa]", _option.getWindow());
1622 printUnits("1'TC", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_CELSIUS"), "Theta", "274.15 [K]", _option.getWindow());
1623 printUnits("1'TF", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_FAHRENHEIT"), "Theta", "255.92778 [K]", _option.getWindow());
1624 printUnits("1'Torr", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_TORR"), "M / (L T^2)", "133.322 [Pa]", _option.getWindow());
1625 printUnits("1'yd", _lang.get("PARSERFUNCS_LISTUNITS_UNIT_YARD"), "L", "0.9144 [m]", _option.getWindow());
1627 printUnits("1'G", "(giga)", "---", "1e9 ---", _option.getWindow());
1628 printUnits("1'M", "(mega)", "---", "1e6 ---", _option.getWindow());
1629 printUnits("1'k", "(kilo)", "---", "1e3 ---", _option.getWindow());
1630 printUnits("1'm", "(milli)", "---", "1e-3 ---", _option.getWindow());
1631 printUnits("1'mu", "(micro)", "---", "1e-6 ---", _option.getWindow());
1632 printUnits("1'n", "(nano)", "---", "1e-9 ---", _option.getWindow());
1633
1635 NumeReKernel::print(LineBreak(_lang.get("PARSERFUNCS_LISTUNITS_FOOTNOTE"), _option));
1637 make_hline();
1638
1639 return;
1640}
1641
1642
1657std::vector<size_t> calcTableWidth(size_t maxWidth, std::vector<size_t> minDesiredColWidth)
1658{
1659 std::vector<size_t> colWidth;
1660
1661 // Get the average column width
1662 size_t avgWidth = maxWidth / minDesiredColWidth.size();
1663
1664 // Find the column width, depending on wether this column should be maxed or not
1665 for (size_t i = 0; i < minDesiredColWidth.size(); i++)
1666 {
1667 if (minDesiredColWidth[i] > 0)
1668 colWidth.push_back(std::min(avgWidth, minDesiredColWidth[i]));
1669 else
1670 colWidth.push_back(0);
1671 }
1672
1673 // Find the number of columns to be maximized
1674 size_t numOfMarkedColumns = std::count(colWidth.begin(), colWidth.end(), 0);
1675
1676 // Get the current sum of chars
1677 size_t sumOfChars = 0;
1678 for (auto& n : colWidth)
1679 sumOfChars += n;
1680
1681 // Expand the marked columns
1682 for (size_t i = 0; i < colWidth.size(); i++)
1683 {
1684 if (colWidth[i] == 0)
1685 colWidth[i] = (maxWidth - sumOfChars) / numOfMarkedColumns;
1686 }
1687
1688 return colWidth;
1689}
1690
1691
1703void plotTableBySize(std::vector<std::string> lineEntries, std::vector<size_t> lineColSizes)
1704{
1705 // Format the string
1706 string sDummy = "";
1707 for (auto& thisEntry: lineEntries)
1708 {
1709 thisEntry = '"' + thisEntry + "\" -nq";
1710 NumeReKernel::getInstance()->getStringParser().evalAndFormat(thisEntry, sDummy, true);
1711 }
1712
1713 // Split all columns into multiple lines if necessary
1714 std::vector<std::vector<std::string>> splittedLineEntries;
1715 for (size_t i = 0; i < lineEntries.size(); i++)
1716 {
1717 splittedLineEntries.push_back(splitIntoLines(lineEntries[i], lineColSizes[i], true, 2, 2));
1718 }
1719
1720 // Print lines as long as strings are not all empty
1721 while (true)
1722 {
1723 std::string sLine = "| ";
1724
1725 // Join the various columns into one line
1726 for (size_t i = 0; i < splittedLineEntries.size(); i++)
1727 {
1728 if (splittedLineEntries[i].size())
1729 {
1730 sLine += strlfill(splittedLineEntries[i].front(), lineColSizes[i], ' ');
1731 splittedLineEntries[i].erase(splittedLineEntries[i].begin());
1732 }
1733 else
1734 sLine += strlfill("", lineColSizes[i], ' ');
1735 }
1736
1737 // Check if all strings have been plotted completely
1738 size_t totalStringElements = 0;
1739 for (std::vector<std::string> thisColumn: splittedLineEntries)
1740 totalStringElements += thisColumn.size();
1741
1742 // Plot depending on last line or not
1743 if (totalStringElements <= 0)
1744 {
1745 NumeReKernel::printPreFmt(sLine + "\n|\n");
1746 break;
1747 }
1748 else
1749 {
1750 NumeReKernel::printPreFmt(sLine + "\n");
1751 }
1752 }
1753}
1754
1755
1769static void listInstalledPlugins(Parser& _parser, MemoryManager& _data, const Settings& _option)
1770{
1771
1773 make_hline();
1774 NumeReKernel::print(toSystemCodePage("NUMERE: " + toUpperCase(_lang.get("PARSERFUNCS_LISTPLUGINS_HEADLINE"))));
1775 make_hline();
1777
1778 // Probably there's no plugin defined
1779 if (!_procedure.getPackageCount())
1780 NumeReKernel::print(toSystemCodePage(_lang.get("PARSERFUNCS_LISTPLUGINS_EMPTY")));
1781 else
1782 {
1783 size_t largewindowoffset = _option.getWindow() > 230 ? 10 : 0;
1784 // The info to be printed is: Package Name, Version, Command, Description, Author, License
1785 // The minimal desired column width is
1786 std::vector<size_t> minDesiredColWidth{20 + largewindowoffset,
1787 10,
1788 25 + largewindowoffset,
1789 0,
1790 20 + largewindowoffset,
1791 15 + largewindowoffset};
1792
1793 //Get the terminal window width minus the 4 digit indent
1794 size_t maxWidth = _option.getWindow(0) - 4;
1795
1796 // Set the column withs depending on number of columns and window width
1797 std::vector<size_t> colWidth = calcTableWidth(maxWidth, minDesiredColWidth);
1798
1799 // Print the table head and an empty line
1800 std::vector<std::string> headerEntries;
1801 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_PACKAGENAME"));
1802 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_VERSION"));
1803 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_COMMAND"));
1804 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_DESCRIPTION"));
1805 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_AUTHOR"));
1806 headerEntries.push_back(_lang.get("PARSERFUNCS_LISTPLUGINS_LICENSE"));
1807 plotTableBySize(headerEntries, colWidth);
1808
1809 // Print all plugins (name, command and description) on the terminal
1810 for (unsigned int i = 0; i < _procedure.getPackageCount(); i++)
1811 {
1812 // Tabellenfunktion unter utils/tools.cpp oder util/stringtools.cpp
1813 std::vector<std::string> lineEntries;
1814
1815 // Print package name
1816 lineEntries.push_back(_procedure.getPackageName(i));
1817 // Print package version
1818 lineEntries.push_back("v" + _procedure.getPackageVersion(i));
1819 // Print command info
1820 lineEntries.push_back(_procedure.getPluginCommand(i).length() ? _procedure.getPluginCommandSignature(i) : "---");
1821 // Print the description
1822 lineEntries.push_back(_procedure.getPackageDescription(i));
1823 // Print package author
1824 lineEntries.push_back(_procedure.getPackageAuthor(i));
1825 // Print package license
1826 lineEntries.push_back(_procedure.getPackageLicense(i));
1827 // Plot this line
1828 plotTableBySize(lineEntries, colWidth);
1829 }
1830 }
1831
1833 make_hline();
1834 return;
1835}
1836
1837
1856static bool executeCommand(string& sCmd, Parser& _parser, MemoryManager& _data, FunctionDefinitionManager& _functions, const Settings& _option)
1857{
1858 if (!_option.executeEnabled())
1859 throw SyntaxError(SyntaxError::EXECUTE_COMMAND_DISABLED, sCmd, "execute");
1860
1861 CommandLineParser cmdParser(sCmd, "execute", CommandLineParser::CMD_EXPR_set_PAR);
1862
1863 FileSystem _fSys;
1864 _fSys.setTokens(_option.getTokenPaths());
1865 _fSys.setPath(_option.getExePath(), false, _option.getExePath());
1866 _fSys.declareFileType(".exe");
1867 string sParams = cmdParser.getParameterValueAsString("params", "");
1868 string sWorkpath = cmdParser.getParameterValueAsString("wp", "");
1869 string sObject = cmdParser.parseExprAsString();
1870 int nRetVal = 0;
1871 bool bWaitForTermination = cmdParser.hasParam("wait");
1872
1873 // Resolve path placeholders
1874 if (sObject.find('<') != string::npos && sObject.find('>', sObject.find('<') + 1) != string::npos)
1875 sObject = _fSys.ValidFileName(sObject, ".exe");
1876
1877 if (sParams.find('<') != string::npos && sParams.find('>', sParams.find('<') + 1) != string::npos)
1878 {
1879 if (sParams.front() == '"')
1880 sParams = "\"" + _fSys.ValidFileName(sParams.substr(1));
1881 else
1882 sParams = _fSys.ValidFileName(sParams);
1883 }
1884
1885 if (sWorkpath.find('<') != string::npos && sWorkpath.find('>', sWorkpath.find('<') + 1) != string::npos)
1886 {
1887 if (sWorkpath.front() == '"')
1888 sWorkpath = "\"" + _fSys.ValidFileName(sWorkpath.substr(1));
1889 else
1890 sWorkpath = _fSys.ValidFileName(sWorkpath);
1891
1892 if (sWorkpath.rfind(".dat") != string::npos)
1893 sWorkpath.erase(sWorkpath.rfind(".dat"), 4);
1894 }
1895
1896 StripSpaces(sObject);
1897
1898 // Prepare the shell execution information
1899 // structure
1900 SHELLEXECUTEINFO ShExecInfo = {0};
1901 ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
1902 ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
1903 ShExecInfo.hwnd = NULL;
1904 ShExecInfo.lpVerb = NULL;
1905 ShExecInfo.lpFile = sObject.c_str();
1906 ShExecInfo.lpParameters = sParams.c_str();
1907 ShExecInfo.lpDirectory = sWorkpath.c_str();
1908 ShExecInfo.nShow = SW_SHOW;
1909 ShExecInfo.hInstApp = NULL;
1910
1911 nRetVal = ShellExecuteEx(&ShExecInfo);
1912
1913 if (!nRetVal)
1915
1916 // Do we have to wait for termination?
1917 if (bWaitForTermination)
1918 {
1919 if (_option.systemPrints())
1920 NumeReKernel::printPreFmt("|-> " + _lang.get("COMMON_EVALUATING") + " ... ");
1921
1922 while (true)
1923 {
1924 // wait 1sec and check, whether the user pressed the ESC key
1925 if (WaitForSingleObject(ShExecInfo.hProcess, 1000) == WAIT_OBJECT_0)
1926 break;
1927
1929 {
1930 if (_option.systemPrints())
1931 NumeReKernel::printPreFmt(_lang.get("COMMON_CANCEL") + "\n");
1932
1934 }
1935 }
1936
1937 if (_option.systemPrints())
1938 NumeReKernel::printPreFmt(_lang.get("COMMON_DONE") + ".\n");
1939 }
1940
1941 return true;
1942}
1943
1944
1955static void autoSave(MemoryManager& _data, Output& _out, Settings& _option)
1956{
1957 // Only do something, if there's unsaved and valid data
1958 if (_data.isValid() && !_data.getSaveStatus())
1959 {
1960 // Inform the user
1961 if (_option.systemPrints())
1962 NumeReKernel::printPreFmt(toSystemCodePage( _lang.get("BUILTIN_AUTOSAVE") + " ... "));
1963
1964 // Try to save the cache
1965 if (_data.saveToCacheFile())
1966 {
1967 if (_option.systemPrints())
1968 NumeReKernel::printPreFmt(toSystemCodePage(_lang.get("COMMON_SUCCESS") + ".") );
1969 }
1970 else
1971 {
1972 if (_option.systemPrints())
1975 }
1976 }
1977 return;
1978}
1979
1980
1991static string getPathForSetting(string& sCmd, size_t pos)
1992{
1993 string sPath;
1994
1995 addArgumentQuotes(sCmd, pos);
1996
1997 while (sCmd.find('\\') != string::npos)
1998 sCmd[sCmd.find('\\')] = '/';
1999
2000 if (!extractFirstParameterStringValue(sCmd, sPath))
2001 {
2002 NumeReKernel::print(toSystemCodePage( _lang.get("BUILTIN_CHECKKEYWORD_SET_GIVEPATH") + ":") );
2003
2004 do
2005 {
2006 NumeReKernel::printPreFmt("|\n|<- ");
2007 NumeReKernel::getline(sPath);
2008 }
2009 while (!sPath.length());
2010 }
2011
2012 return sPath;
2013}
2014
2015
2029static void copyDataToTemporaryTable(const string& sCmd, DataAccessParser& _accessParser, MemoryManager& _data, MemoryManager& _cache)
2030{
2031 // Validize the obtained index sets
2032 if (!isValidIndexSet(_accessParser.getIndices()))
2033 throw SyntaxError(SyntaxError::TABLE_DOESNT_EXIST, sCmd, _accessParser.getDataObject() + "(", _accessParser.getDataObject() + "()");
2034
2035 // Copy the target data to a new table
2036 _accessParser.evalIndices();
2037 Memory* mem = _data.getTable(_accessParser.getDataObject())->extractRange(_accessParser.getIndices().row,
2038 _accessParser.getIndices().col);
2039 _cache.melt(mem, "table", true);
2040}
2041
2042
2053static size_t findSettingOption(const std::string& sCmd, const std::string& sOption)
2054{
2055 size_t pos = findParameter(sCmd, sOption, '=');
2056
2057 if (pos)
2058 return pos+sOption.length();
2059
2060 pos = findParameter(sCmd, sOption);
2061
2062 if (pos)
2063 return pos-1 + sOption.length();
2064
2065 pos = sCmd.find(sOption);
2066
2067 if (pos != std::string::npos
2068 && (!pos || sCmd[pos-1] == ' '))
2069 {
2070 if (pos+sOption.length() == sCmd.length() || sCmd[pos+sOption.length()] == ' ')
2071 return pos + sOption.length();
2072
2073 if (sCmd[pos+sOption.length()] == '=')
2074 return pos + sOption.length()+1;
2075 }
2076
2077 return 0u;
2078}
2079
2080
2092static CommandReturnValues swapTables(string& sCmd, MemoryManager& _data, Settings& _option)
2093{
2094 string sArgument;
2095
2096 // If the current command line contains strings
2097 // handle them here
2098 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCmd))
2099 sCmd = evaluateParameterValues(sCmd);
2100
2101 // Handle legacy and new syntax in these two cases
2102 if (_data.matchTableAsParameter(sCmd, '=').length())
2103 {
2104 // Legacy syntax: swap -cache1=cache2
2105 //
2106 // Get the option value of the parameter "cache1"
2107 sArgument = getArgAtPos(sCmd, findParameter(sCmd, _data.matchTableAsParameter(sCmd, '='), '=') + _data.matchTableAsParameter(sCmd, '=').length());
2108
2109 // Swap the caches
2110 _data.swapTables(_data.matchTableAsParameter(sCmd, '='), sArgument);
2111
2112 if (_option.systemPrints())
2113 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_SWAP_CACHE", _data.matchTableAsParameter(sCmd, '='), sArgument), _option) );
2114 }
2115 else if (sCmd.find("()") != string::npos && sCmd.find(',') != string::npos)
2116 {
2117 // New syntax: swap cache1(), cache2()
2118 //
2119 // Extract the first of the two arguments
2120 // (length of command = 4)
2121 sCmd.erase(0, 4);
2122 sArgument = getNextArgument(sCmd, true);
2123
2124 if (!sCmd.length())
2125 return COMMAND_PROCESSED;
2126
2127 // Remove parentheses, if available
2128 if (sArgument.find('(') != string::npos)
2129 sArgument.erase(sArgument.find('('));
2130
2131 if (sCmd.find('(') != string::npos)
2132 sCmd.erase(sCmd.find('('));
2133
2134 // Remove not necessary white spaces
2135 StripSpaces(sCmd);
2136 StripSpaces(sArgument);
2137
2138 // Swap the caches
2139 _data.swapTables(sCmd, sArgument);
2140
2141 if (_option.systemPrints())
2142 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_SWAP_CACHE", sCmd, sArgument), _option) );
2143 }
2144
2145 return COMMAND_PROCESSED;
2146}
2147
2148
2160{
2161 // Get references to the main objects
2164
2166
2167 size_t nPrecision = _option.getPrecision();
2168
2169 // Update the precision, if the user selected any
2170 auto vParVal = cmdParser.getParameterValueAsNumericalValue("precision");
2171
2172 if (vParVal.size())
2173 nPrecision = std::min(14LL, intCast(vParVal.front()));
2174
2175 // Copy the selected data into another datafile instance and
2176 // save the copied data
2177 DataAccessParser _access = cmdParser.getExprAsDataObject();
2178
2179 if (_access.getDataObject().length())
2180 {
2181 // Create the new instance
2182 MemoryManager _cache;
2183
2184 // Update the necessary parameters
2185 _cache.setTokens(_option.getTokenPaths());
2186 _cache.setPath(_option.getSavePath(), false, _option.getExePath());
2187
2188 copyDataToTemporaryTable(sCmd, _access, _data, _cache);
2189
2190 // Update the name of the cache table (force it)
2191 if (_access.getDataObject() != "table")
2192 _cache.renameTable("table", _access.getDataObject(), true);
2193
2194 // If the command line contains string variables
2195 // get those values here
2196 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
2198
2199 std::string sFileName;
2200
2201 if (cmdParser.getCommand() == "export")
2202 sFileName = cmdParser.getFileParameterValue(".dat", "<savepath>", "");
2203 else
2204 sFileName = cmdParser.getFileParameterValue(".ndat", "<savepath>", "");
2205
2206 if (!sFileName.length())
2207 {
2208 _cache.setPrefix(_access.getDataObject());
2209
2210 if (cmdParser.getCommand() == "export")
2211 sFileName = _cache.generateFileName(".dat");
2212 else
2213 sFileName = _cache.generateFileName(".ndat");
2214 }
2215
2216 if (_cache.saveFile(_access.getDataObject(), sFileName, nPrecision))
2217 {
2218 if (_option.systemPrints())
2219 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_SAVEDATA_SUCCESS", _cache.getOutputFileName()));
2220 }
2221 else
2222 throw SyntaxError(SyntaxError::CANNOT_SAVE_FILE, sCmd, sFileName, sFileName);
2223
2224 return COMMAND_PROCESSED;
2225 }
2226 else
2228
2229 return NO_COMMAND;
2230}
2231
2232
2241static CommandReturnValues cmd_find(string& sCmd)
2242{
2245
2246 if (cmdParser.getExpr().length())
2247 doc_SearchFct(cmdParser.getExpr(), _option);
2248 else if (cmdParser.getParameterList().length())
2249 doc_SearchFct(cmdParser.getParameterList(), _option);
2250 else
2251 {
2252 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_CHECKKEYWORD_FIND_CANNOT_READ"), _option));
2253 doc_Help("find", _option);
2254 }
2255
2256 return COMMAND_PROCESSED;
2257}
2258
2259
2269{
2270 CommandLineParser cmdParser(sCmd, "integrate", CommandLineParser::CMD_EXPR_set_PAR);
2271
2272 if (cmdParser.getCommand().substr(0, 10) == "integrate2"
2273 || cmdParser.parseIntervals().size() == 2)
2274 {
2275 integrate2d(cmdParser);
2276 sCmd = cmdParser.getReturnValueStatement();
2278 }
2279 else
2280 {
2281 integrate(cmdParser);
2282 sCmd = cmdParser.getReturnValueStatement();
2284 }
2285}
2286
2287
2296static CommandReturnValues cmd_diff(string& sCmd)
2297{
2299
2300 if (cmdParser.getExpr().length())
2301 {
2302 differentiate(cmdParser);
2303 sCmd = cmdParser.getReturnValueStatement();
2305 }
2306 else
2307 doc_Help("diff", NumeReKernel::getInstance()->getSettings());
2308
2309 return COMMAND_PROCESSED;
2310}
2311
2312
2322{
2323 CommandLineParser cmdParser(sCmd, "extrema", CommandLineParser::CMD_EXPR_set_PAR);
2325
2326 if (cmdParser.getExpr().length())
2327 {
2328 if (findExtrema(cmdParser))
2329 {
2330 sCmd = cmdParser.getReturnValueStatement();
2332 }
2333 else
2334 doc_Help("extrema", _option);
2335
2336 return COMMAND_PROCESSED;
2337 }
2338 else
2339 doc_Help("extrema", _option);
2340
2341 return COMMAND_PROCESSED;
2342}
2343
2344
2353static CommandReturnValues cmd_pulse(string& sCmd)
2354{
2355 CommandLineParser cmdParser(sCmd, "pulse", CommandLineParser::CMD_DAT_PAR);
2356
2357 if (!analyzePulse(cmdParser))
2358 {
2359 doc_Help("pulse", NumeReKernel::getInstance()->getSettings());
2360 return COMMAND_PROCESSED;
2361 }
2362
2363 sCmd = cmdParser.getReturnValueStatement();
2364
2366}
2367
2368
2377static CommandReturnValues cmd_eval(string& sCmd)
2378{
2380
2381 if (evalPoints(cmdParser))
2382 {
2383 sCmd = cmdParser.getReturnValueStatement();
2385 }
2386 else
2387 doc_Help("eval", NumeReKernel::getInstance()->getSettings());
2388
2389 return COMMAND_PROCESSED;
2390}
2391
2392
2402{
2403 CommandLineParser cmdParser(sCmd, "zeroes", CommandLineParser::CMD_EXPR_set_PAR);
2405
2406 if (cmdParser.getExpr().length())
2407 {
2408 if (findZeroes(cmdParser))
2409 {
2410 sCmd = cmdParser.getReturnValueStatement();
2412 }
2413 else
2414 doc_Help("zeroes", _option);
2415 }
2416 else
2417 doc_Help("zeroes", _option);
2418
2419 return COMMAND_PROCESSED;
2420}
2421
2422
2431static CommandReturnValues cmd_sort(string& sCmd)
2432{
2434
2435 sortData(cmdParser);
2436
2437 if (cmdParser.getReturnValueStatement().length())
2438 {
2439 sCmd = cmdParser.getReturnValueStatement();
2441 }
2442
2443 return COMMAND_PROCESSED;
2444}
2445
2446
2459{
2460 CommandLineParser cmdParser(sCmd, "dialog", CommandLineParser::CMD_EXPR_set_PAR);
2461 dialogCommand(cmdParser);
2462 sCmd = cmdParser.getReturnValueStatement();
2463
2465}
2466
2467
2476static CommandReturnValues cmd_pso(string& sCmd)
2477{
2479
2480 // Call the optimizer
2481 particleSwarmOptimizer(cmdParser);
2482
2483 sCmd = cmdParser.getReturnValueStatement();
2484
2486}
2487
2488
2498{
2504
2505 string sCommand = findCommand(sCmd).sString;
2506
2507 if (sCmd.length() > sCommand.length() + 1)
2508 {
2509 if (sCommand == "graph")
2510 sCmd.replace(findCommand(sCmd).nPos, 5, "plot");
2511
2512 if (sCommand == "graph3d")
2513 sCmd.replace(findCommand(sCmd).nPos, 7, "plot3d");
2514
2515 if (sCmd.find("--") != string::npos || sCmd.find("-set") != string::npos)
2516 {
2517 string sCmdSubstr;
2518
2519 if (sCmd.find("--") != string::npos)
2520 sCmdSubstr = sCmd.substr(4, sCmd.find("--") - 4);
2521 else
2522 sCmdSubstr = sCmd.substr(4, sCmd.find("-set") - 4);
2523
2524 if (!isNotEmptyExpression(sCmdSubstr))
2525 {
2526 if (sCmd.find("--") != string::npos)
2527 _pData.setParams(sCmd.substr(sCmd.find("--")));
2528 else
2529 _pData.setParams(sCmd.substr(sCmd.find("-set")));
2530
2531 if (_option.systemPrints())
2532 NumeReKernel::print(toSystemCodePage( _lang.get("BUILTIN_CHECKKEYWORD_PLOTPARAMS")));
2533
2534 }
2535 else
2536 createPlot(sCmd, _data, _parser, _option, _functions, _pData);
2537 }
2538 else
2539 createPlot(sCmd, _data, _parser, _option, _functions, _pData);
2540
2541 }
2542 else
2543 doc_Help(sCommand, _option);
2544
2545 return COMMAND_PROCESSED;
2546}
2547
2548
2557static CommandReturnValues cmd_fit(string& sCmd)
2558{
2563
2564 if (_data.isValid())
2565 fitDataSet(sCmd, _parser, _data, _functions, _option);
2566 else
2567 doc_Help("fit", _option);
2568
2569 return COMMAND_PROCESSED;
2570}
2571
2572
2581static CommandReturnValues cmd_fft(string& sCmd)
2582{
2583 CommandLineParser cmdParser(sCmd, "fft", CommandLineParser::CMD_DAT_PAR);
2584
2585 fastFourierTransform(cmdParser);
2586 return COMMAND_PROCESSED;
2587}
2588
2589
2598static CommandReturnValues cmd_fwt(string& sCmd)
2599{
2600 CommandLineParser cmdParser(sCmd, "fwt", CommandLineParser::CMD_DAT_PAR);
2601
2602 fastWaveletTransform(cmdParser);
2603 return COMMAND_PROCESSED;
2604}
2605
2606
2615static CommandReturnValues cmd_get(string& sCmd)
2616{
2621
2622 const std::map<std::string, SettingsValue>& mSettings = _option.getSettings();
2623
2624 size_t nPos = findCommand(sCmd, "get").nPos;
2625 string sCommand = extractCommandString(sCmd, findCommand(sCmd, "get"));
2626
2627 bool asVal = findParameter(sCmd, "asval");
2628 bool asStr = findParameter(sCmd, "asstr");
2629
2630 for (auto iter = mSettings.begin(); iter != mSettings.end(); ++iter)
2631 {
2632 if (findSettingOption(sCmd, iter->first.substr(iter->first.find('.')+1)) && !iter->second.isHidden())
2633 {
2634 std::string convertedValue;
2635
2636 switch (iter->second.getType())
2637 {
2639 convertedValue = toString(iter->second.active());
2640 break;
2642 convertedValue = toString(iter->second.value());
2643 break;
2645 convertedValue = iter->second.stringval();
2646 break;
2647 }
2648
2649 switch (iter->second.getType())
2650 {
2653 if (asVal)
2654 {
2655 if (!nPos)
2656 sCmd = convertedValue;
2657 else
2658 sCmd.replace(nPos, sCommand.length(), convertedValue);
2659
2660 break;
2661 }
2662 // Fallthrough intended
2664 if (asStr || asVal)
2665 {
2666 if (!nPos)
2667 sCmd = "\"" + convertedValue + "\"";
2668 else
2669 sCmd.replace(nPos, sCommand.length(), "\"" + convertedValue + "\"");
2670 }
2671 else
2672 NumeReKernel::print(toUpperCase(iter->first.substr(iter->first.find('.')+1)) + ": " + convertedValue);
2673
2674 break;
2675 }
2676
2677 if (asStr || asVal)
2679 else
2680 return COMMAND_PROCESSED;
2681 }
2682 }
2683
2684 if (findSettingOption(sCmd, "windowsize"))
2685 {
2686 std::string convertedValue = "x = " + toString(mSettings.at(SETTING_V_WINDOW_X).value() + 1) + ", y = " + toString(mSettings.at(SETTING_V_WINDOW_Y).value() + 1);
2687 if (asVal)
2688 {
2689 if (!nPos)
2690 sCmd = convertedValue;
2691 else
2692 sCmd.replace(nPos, sCommand.length(), "{" + toString(mSettings.at(SETTING_V_WINDOW_X).value() + 1) + ", " + toString(mSettings.at(SETTING_V_WINDOW_Y).value() + 1) + "}");
2693
2695 }
2696
2697 if (asStr)
2698 {
2699 if (!nPos)
2700 sCmd = "\"" + convertedValue + "\"";
2701 else
2702 sCmd.replace(nPos, sCommand.length(), "\"" + convertedValue + "\"");
2703
2705 }
2706
2707 NumeReKernel::print("WINDOWSIZE: " + convertedValue);
2708 return COMMAND_PROCESSED;
2709 }
2710 else if (findSettingOption(sCmd, "varlist"))
2711 {
2712 if (asStr)
2713 {
2714 if (!nPos)
2715 sCmd = getVarList("vars -asstr", _parser, _data, _option);
2716 else
2717 sCmd.replace(nPos, sCommand.length(), getVarList("vars -asstr", _parser, _data, _option));
2718
2720 }
2721
2722 NumeReKernel::print(LineBreak("VARLIST: " + getVarList("vars", _parser, _data, _option), _option, false));
2723 return COMMAND_PROCESSED;
2724 }
2725 else if (findSettingOption(sCmd, "stringlist"))
2726 {
2727 if (asStr)
2728 {
2729 if (!nPos)
2730 sCmd = getVarList("strings -asstr", _parser, _data, _option);
2731 else
2732 sCmd.replace(nPos, sCommand.length(), getVarList("strings -asstr", _parser, _data, _option));
2733
2735 }
2736
2737 NumeReKernel::print(LineBreak("STRINGLIST: " + getVarList("strings", _parser, _data, _option), _option, false));
2738 return COMMAND_PROCESSED;
2739 }
2740 else if (findSettingOption(sCmd, "numlist"))
2741 {
2742 if (asStr)
2743 {
2744 if (!nPos)
2745 sCmd = getVarList("nums -asstr", _parser, _data, _option);
2746 else
2747 sCmd.replace(nPos, sCommand.length(), getVarList("nums -asstr", _parser, _data, _option));
2748
2750 }
2751
2752 NumeReKernel::print(LineBreak("NUMLIST: " + getVarList("nums", _parser, _data, _option), _option, false));
2753 return COMMAND_PROCESSED;
2754 }
2755 else if (findSettingOption(sCmd, "plotparams"))
2756 {
2757 if (asStr)
2758 {
2759 if (!nPos)
2760 sCmd = _pData.getParams(true);
2761 else
2762 sCmd.replace(nPos, sCommand.length(), _pData.getParams(true));
2763
2765 }
2766
2767 NumeReKernel::print(LineBreak("PLOTPARAMS: " + _pData.getParams(), _option, false));
2768 return COMMAND_PROCESSED;
2769 }
2770 else
2771 {
2772 doc_Help("get", _option);
2773 return COMMAND_PROCESSED;
2774 }
2775}
2776
2777
2787{
2790 size_t nPos = findCommand(sCmd).nPos;
2791
2792 if (sCmd.length() > 7)
2793 undefineFunctions(sCmd.substr(sCmd.find(' ', nPos) + 1), _functions, _option);
2794 else
2795 doc_Help("define", _option);
2796
2797 return COMMAND_PROCESSED;
2798}
2799
2800
2810{
2811 CommandLineParser cmdParser(sCmd, "readline", CommandLineParser::CMD_PAR);
2813
2814 std::string sDefault = cmdParser.getParameterValueAsString("dflt", "");
2815 std::string sMessage = cmdParser.getParameterValueAsString("msg", "");
2816 std::string sArgument;
2817
2818
2819 while (!sArgument.length())
2820 {
2821 string sLastLine = "";
2823
2824 if (sMessage.length())
2825 {
2826 sLastLine = LineBreak(sMessage, _option, false, 4);
2827 NumeReKernel::printPreFmt(sLastLine);
2828
2829 if (sLastLine.find('\n') != string::npos)
2830 sLastLine.erase(0, sLastLine.rfind('\n'));
2831
2832 if (sLastLine.substr(0, 4) == "| " || sLastLine.substr(0, 4) == "|<- " || sLastLine.substr(0, 4) == "|-> ")
2833 sLastLine.erase(0, 4);
2834
2835 StripSpaces(sLastLine);
2836 }
2837
2838 NumeReKernel::getline(sArgument);
2839
2840 if (sLastLine.length() && sArgument.find(sLastLine) != string::npos)
2841 sArgument.erase(0, sArgument.find(sLastLine) + sLastLine.length());
2842
2843 StripSpaces(sArgument);
2844
2845 if (!sArgument.length() && sDefault.length())
2846 sArgument = sDefault;
2847 }
2848
2849 if (cmdParser.hasParam("asstr") && sArgument[0] != '"' && sArgument[sArgument.length() - 1] != '"')
2850 cmdParser.setReturnValue("\"" + sArgument + "\"");
2851 else
2852 cmdParser.setReturnValue(sArgument);
2853
2854 sCmd = cmdParser.getReturnValueStatement();
2855
2856 GetAsyncKeyState(VK_ESCAPE);
2858}
2859
2860
2869static CommandReturnValues cmd_read(string& sCmd)
2870{
2871 CommandLineParser cmdParser(sCmd, "read", CommandLineParser::CMD_DAT_PAR);
2873
2874 if (cmdParser.getExpr().length())
2875 {
2876 readFromFile(cmdParser);
2877 sCmd = cmdParser.getReturnValueStatement();
2879 }
2880 else
2881 doc_Help("read", _option);
2882
2883 return COMMAND_PROCESSED;
2884}
2885
2886
2896{
2897 CommandLineParser cmdParser(sCmd, "window", CommandLineParser::CMD_DAT_PAR);
2898
2899 if (cmdParser.getExpr().length() || cmdParser.getParameterList().length())
2900 {
2901 windowCommand(cmdParser);
2902 sCmd = cmdParser.getReturnValueStatement();
2904 }
2905 else
2906 doc_Help("window", NumeReKernel::getInstance()->getSettings());
2907
2908 return COMMAND_PROCESSED;
2909}
2910
2911
2920static CommandReturnValues cmd_new(string& sCmd)
2921{
2926
2927 if (findParameter(sCmd, "dir", '=')
2928 || findParameter(sCmd, "script", '=')
2929 || findParameter(sCmd, "proc", '=')
2930 || findParameter(sCmd, "file", '=')
2931 || findParameter(sCmd, "plugin", '=')
2932 || findParameter(sCmd, "cache", '=')
2933 || sCmd.find("()", findCommand(sCmd).nPos + 3) != string::npos
2934 || sCmd.find('$', findCommand(sCmd).nPos + 3) != string::npos)
2935 {
2937
2938 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCmd))
2939 sCmd = evaluateParameterValues(sCmd);
2940
2941 if (!newObject(sCmd, _parser, _data, _option))
2942 doc_Help("new", _option);
2943 }
2944 else
2945 doc_Help("new", _option);
2946
2947 return COMMAND_PROCESSED;
2948}
2949
2950
2959static CommandReturnValues cmd_edit(string& sCmd)
2960{
2964
2965 if (sCmd.length() > 5)
2966 {
2967 string sArgument;
2968 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCmd))
2969 {
2970 extractFirstParameterStringValue(sCmd, sArgument);
2971 sArgument = "edit " + sArgument;
2972 editObject(sArgument, _parser, _data, _option);
2973 }
2974 else
2975 editObject(sCmd, _parser, _data, _option);
2976 }
2977 else
2978 doc_Help("edit", _option);
2979
2980 return COMMAND_PROCESSED;
2981}
2982
2983
2993{
2994 CommandLineParser cmdParser(sCmd, "taylor", CommandLineParser::CMD_EXPR_set_PAR);
2995
2996 if (cmdParser.getExpr().length())
2997 {
2998 taylor(cmdParser);
2999 sCmd = cmdParser.getReturnValueStatement();
3001 }
3002 else
3003 doc_Help("taylor", NumeReKernel::getInstance()->getSettings());
3004
3005 return COMMAND_PROCESSED;
3006}
3007
3008
3017static CommandReturnValues cmd_quit(string& sCmd)
3018{
3022
3023 if (findParameter(sCmd, "as"))
3024 autoSave(_data, _out, _option);
3025
3026 if (findParameter(sCmd, "i"))
3027 _data.setSaveStatus(true);
3028
3029 return NUMERE_QUIT;
3030}
3031
3032
3042{
3047
3048 if (sCmd.length() > 9)
3049 {
3050 Odesolver _solver(&_parser, &_data, &_functions, &_option);
3051 _solver.solve(sCmd);
3052 }
3053 else
3054 doc_Help("odesolver", _option);
3055
3056 return COMMAND_PROCESSED;
3057}
3058
3059
3069{
3073
3074 string sArgument;
3075 int nArgument;
3076
3077 DataAccessParser accessParser = cmdParser.getExprAsDataObject();
3078
3079 if (_data.containsTablesOrClusters(cmdParser.getExpr()))
3080 {
3081 if (!cmdParser.hasParam("ignore") && !cmdParser.hasParam("i"))
3082 {
3083 if (!confirmOperation(_lang.get("BUILTIN_CHECKKEYWORD_DELETE_CONFIRM")))
3084 return COMMAND_PROCESSED;
3085 }
3086
3087 if (deleteCacheEntry(cmdParser))
3088 {
3089 if (_option.systemPrints())
3090 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_DELETE_SUCCESS"));
3091 }
3092 else
3094 }
3095 else if (accessParser.getDataObject() == "string")
3096 {
3097 nArgument = accessParser.getIndices().row.front();
3098
3099 if (_data.removeStringElements(nArgument))
3100 {
3101 if (_option.systemPrints())
3102 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_DELETESTRINGS_SUCCESS", toString(nArgument + 1)));
3103 }
3104
3105 return COMMAND_PROCESSED;
3106 }
3107
3108 return COMMAND_PROCESSED;
3109}
3110
3111
3122static CommandReturnValues cmd_clear(string& sCmd)
3123{
3124 CommandLineParser cmdParser(sCmd, "clear", CommandLineParser::CMD_DAT_PAR);
3127
3128 Match _mMatch = findCommand(sCmd);
3129
3130 if (_data.containsTables(cmdParser.getExpr()))
3131 {
3132 string sCommand = "delete " + cmdParser.getExpr();
3133
3134 if (cmdParser.hasParam("ignore") || cmdParser.hasParam("i"))
3135 sCommand += " -ignore";
3136
3137 return cmd_delete(sCommand);
3138 }
3139 else if (cmdParser.hasParam("memory"))
3140 {
3141 // Clear all tables
3142 if (cmdParser.hasParam("ignore") || cmdParser.hasParam("i"))
3143 clear_cache(_data, _option, true);
3144 else
3145 clear_cache(_data, _option);
3146
3147 // Clear also the string table
3148 _data.clearStringElements();
3149
3150 // Clear also the clusters
3151 _data.clearAllClusters();
3152 NumeRe::Cluster& ans = _data.newCluster("ans");
3153 ans.setDouble(0, NAN);
3155 }
3156 else if (cmdParser.getExpr() == "string()")
3157 {
3158 if (_data.clearStringElements())
3159 {
3160 if (_option.systemPrints())
3161 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_CLEARSTRINGS_SUCCESS"));
3162 }
3163
3164 return COMMAND_PROCESSED;
3165 }
3166
3167 return COMMAND_PROCESSED;
3168}
3169
3170
3179static CommandReturnValues cmd_close(string& sCmd)
3180{
3182
3183 if (findParameter(sCmd, "all"))
3184 instance->closeWindows(WT_ALL);
3185 else if (findParameter(sCmd, "graphs"))
3186 instance->closeWindows(WT_GRAPH);
3187 else if (findParameter(sCmd, "tables"))
3188 instance->closeWindows(WT_TABLEVIEWER);
3189 else if (findParameter(sCmd, "images"))
3190 instance->closeWindows(WT_IMAGEVIEWER);
3191 else if (findParameter(sCmd, "docs"))
3192 instance->closeWindows(WT_DOCVIEWER);
3193
3194 return COMMAND_PROCESSED;
3195}
3196
3197
3207{
3210
3211 if (sCmd.find(' ') != string::npos)
3212 {
3213 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
3215
3216 if (findParameter(sCmd, "comment", '='))
3217 addArgumentQuotes(sCmd, "comment");
3218
3219 string sArgument = sCmd.substr(sCmd.find(' '));
3220 StripSpaces(sArgument);
3221
3222 if (!_functions.isDefined(sArgument.substr(0, sArgument.find(":="))))
3223 {
3224 if (_functions.defineFunc(sArgument))
3225 NumeReKernel::print(_lang.get("DEFINE_SUCCESS"), _option.systemPrints());
3226 else
3227 NumeReKernel::issueWarning(_lang.get("DEFINE_FAILURE"));
3228 }
3229 }
3230 else
3231 doc_Help("ifndef", _option);
3232
3233 return COMMAND_PROCESSED;
3234}
3235
3236
3246{
3248
3249 string sArgument;
3250
3251 if (!_script.isOpen())
3252 {
3253 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
3255
3256 _script.setInstallProcedures();
3257
3258 if (containsStrings(sCmd))
3259 extractFirstParameterStringValue(sCmd, sArgument);
3260 else
3261 sArgument = sCmd.substr(findCommand(sCmd).nPos + 8);
3262
3263 StripSpaces(sArgument);
3264 _script.openScript(sArgument);
3265 }
3266
3267 return COMMAND_PROCESSED;
3268}
3269
3270
3279static CommandReturnValues cmd_copy(string& sCmd)
3280{
3281 CommandLineParser cmdParser(sCmd, "copy", CommandLineParser::CMD_DAT_PAR);
3283
3284 if (cmdParser.exprContainsDataObjects())
3285 {
3286 if (CopyData(cmdParser))
3287 {
3288 if (_option.systemPrints())
3289 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_COPYDATA_SUCCESS"));
3290 }
3291 else
3293 }
3294 else if ((cmdParser.hasParam("target") || cmdParser.hasParam("t")) && cmdParser.getExpr().length())
3295 {
3296 if (moveOrCopyFiles(cmdParser))
3297 {
3298 if (_option.systemPrints())
3299 {
3300 if (cmdParser.hasParam("all") || cmdParser.hasParam("a"))
3301 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_COPYFILE_ALL_SUCCESS", cmdParser.getReturnValueStatement()));
3302 else
3303 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_COPYFILE_SUCCESS", cmdParser.getReturnValueStatement()));
3304 }
3305 }
3306 else
3307 {
3309 }
3310 }
3311
3312 return COMMAND_PROCESSED;
3313}
3314
3315
3325{
3327 make_hline();
3331 make_hline();
3332 NumeReKernel::printPreFmt("|-> Version: " + sVersion);
3333 NumeReKernel::printPreFmt(" | " + _lang.get("BUILTIN_CREDITS_BUILD") + ": " + AutoVersion::YEAR + "-" + AutoVersion::MONTH + "-" + AutoVersion::DATE + "\n");
3334 NumeReKernel::print("Copyright (c) 2013-" + (AutoVersion::YEAR + toSystemCodePage(", Erik HÄNEL et al.")) );
3335 NumeReKernel::printPreFmt("| <numere.developer@gmail.com>\n" );
3336 NumeReKernel::print(_lang.get("BUILTIN_CREDITS_VERSIONINFO"));
3337 make_hline(-80);
3338 NumeReKernel::print(_lang.get("BUILTIN_CREDITS_LICENCE_1"));
3339 NumeReKernel::print(_lang.get("BUILTIN_CREDITS_LICENCE_2"));
3340 NumeReKernel::print(_lang.get("BUILTIN_CREDITS_LICENCE_3"));
3342 make_hline();
3343
3344 return COMMAND_PROCESSED;
3345}
3346
3347
3357{
3358 CommandLineParser cmdParser(sCmd, "append", CommandLineParser::CMD_DAT_PAR);
3359
3361
3362 if (cmdParser.getExpr().length())
3363 {
3365
3366 double j1 = _data.getCols("data") + 1;
3367 append_data(cmdParser);
3368 cmdParser.setReturnValue(std::vector<mu::value_type>({1, _data.getColElements(VectorIndex(j1, VectorIndex::OPEN_END), "data"), j1, _data.getCols("data")}));
3369
3370 sCmd = cmdParser.getReturnValueStatement();
3372 }
3373
3374 return COMMAND_PROCESSED;
3375}
3376
3377
3386static CommandReturnValues cmd_audio(string& sCmd)
3387{
3389
3390 if (!writeAudioFile(cmdParser))
3392 else if (NumeReKernel::getInstance()->getSettings().systemPrints())
3393 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_AUDIO_SUCCESS"));
3394
3395 return COMMAND_PROCESSED;
3396}
3397
3398
3407static CommandReturnValues cmd_clc(string& sCmd)
3408{
3410
3411 return COMMAND_PROCESSED;
3412}
3413
3414
3424{
3425 CommandLineParser cmdParser(sCmd, "audioread", CommandLineParser::CMD_EXPR_set_PAR);
3426
3427 if (!readAudioFile(cmdParser))
3429 else if (NumeReKernel::getInstance()->getSettings().systemPrints())
3430 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_AUDIOREAD_SUCCESS"));
3431
3432 sCmd = cmdParser.getReturnValueStatement();
3434}
3435
3436
3445static CommandReturnValues cmd_seek(string& sCmd)
3446{
3448
3449 if (!seekInAudioFile(cmdParser))
3451 else if (NumeReKernel::getInstance()->getSettings().systemPrints())
3452 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_SEEK_SUCCESS"));
3453
3454 sCmd = cmdParser.getReturnValueStatement();
3456}
3457
3458
3468{
3469 CommandLineParser cmdParser(sCmd, "imread", CommandLineParser::CMD_DAT_PAR);
3470
3471 readImage(cmdParser);
3472
3473 sCmd = cmdParser.getReturnValueStatement();
3475}
3476
3477
3486static CommandReturnValues cmd_write(string& sCmd)
3487{
3489
3490 if (cmdParser.getExpr().length() && cmdParser.hasParam("file"))
3491 writeToFile(cmdParser);
3492 else
3493 doc_Help("write", NumeReKernel::getInstance()->getSettings());
3494
3495 return COMMAND_PROCESSED;
3496}
3497
3498
3508{
3509 CommandLineParser cmdParser(sCmd, "workpath", CommandLineParser::CMD_EXPR_set_PAR);
3511
3512 if (!cmdParser.getExpr().length())
3513 return NO_COMMAND;
3514
3515 _option.getSetting(SETTING_S_WORKPATH).stringval() = cmdParser.getExprAsFileName("");
3516
3517 if (_option.systemPrints())
3518 NumeReKernel::print(toSystemCodePage(_lang.get("BUILTIN_CHECKKEYWORD_SET_PATH")));
3519
3520 return COMMAND_PROCESSED;
3521}
3522
3523
3532static CommandReturnValues cmd_warn(string& sCmd)
3533{
3536
3537 std::string sMessage = cmdParser.getExpr();
3538
3539 if (sMessage.length())
3540 {
3541 if (!NumeReKernel::getInstance()->getStringParser().isStringExpression(sMessage))
3542 {
3543 auto vVals = cmdParser.parseExprAsNumericalValues();
3544
3545 if (vVals.size() > 1)
3546 {
3547 sMessage = "{";
3548
3549 for (size_t i = 0; i < vVals.size(); i++)
3550 sMessage += " " + toString(vVals[i], _option.getPrecision()) + ",";
3551
3552 sMessage.back() = '}';
3553 }
3554 else
3555 sMessage = toString(vVals.front(), _option.getPrecision());
3556 }
3557 else
3558 sMessage = cmdParser.parseExprAsString();
3559
3561 }
3562 else
3563 doc_Help("warn", _option);
3564
3565 return COMMAND_PROCESSED;
3566}
3567
3568
3577static CommandReturnValues cmd_stats(string& sCmd)
3578{
3580 Match _match = findCommand(sCmd, "stats");
3581 string sExpr = sCmd;
3582
3583 sExpr.replace(_match.nPos, string::npos, "_~load[~_~]");
3584 sCmd.erase(0, _match.nPos);
3585
3586 string sArgument = evaluateParameterValues(sCmd);
3587
3588 DataAccessParser _accessParser(sCmd);
3589
3590 if (_accessParser.getDataObject().length())
3591 {
3592 MemoryManager _cache;
3593
3594 copyDataToTemporaryTable(sCmd, _accessParser, _data, _cache);
3595
3596 if (_accessParser.getDataObject() != "table")
3597 _cache.renameTable("table", _accessParser.getDataObject(), true);
3598
3599 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
3601
3602 if (findParameter(sCmd, "export", '='))
3603 addArgumentQuotes(sCmd, "export");
3604
3605 sArgument = "stats -" + _accessParser.getDataObject() + " " + sCmd.substr(getMatchingParenthesis(sCmd.substr(sCmd.find('('))) + 1 + sCmd.find('('));
3606 sArgument = evaluateParameterValues(sArgument);
3607 std::string sRet = plugin_statistics(sArgument, _cache);
3608
3609 if (sRet.length())
3610 {
3611 sExpr.replace(_match.nPos, string::npos, sRet);
3612 sCmd = sExpr;
3614 }
3615 }
3616 else
3618
3619 return COMMAND_PROCESSED;
3620}
3621
3622
3631static CommandReturnValues cmd_stfa(string& sCmd)
3632{
3633 CommandLineParser cmdParser(sCmd, "stfa", CommandLineParser::CMD_DAT_PAR);
3634
3635 if (!shortTimeFourierAnalysis(cmdParser))
3636 doc_Help("stfa", NumeReKernel::getInstance()->getSettings());
3637 else if (NumeReKernel::getInstance()->getSettings().systemPrints())
3638 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYOWRD_STFA_SUCCESS", cmdParser.getReturnValueStatement()));
3639
3640 return COMMAND_PROCESSED;
3641}
3642
3643
3653{
3654 CommandLineParser cmdParser(sCmd, "spline", CommandLineParser::CMD_DAT_PAR);
3655
3657
3658 if (!calculateSplines(cmdParser))
3659 doc_Help("spline", _option);
3660
3661 return COMMAND_PROCESSED;
3662}
3663
3664
3673static CommandReturnValues cmd_save(string& sCmd)
3674{
3677
3678 if (findParameter(sCmd, "define"))
3679 {
3680 _functions.save(_option);
3681 return COMMAND_PROCESSED;
3682 }
3683 else if (findParameter(sCmd, "settings"))
3684 {
3685 _option.save(_option.getExePath());
3686 return COMMAND_PROCESSED;
3687 }
3688 else
3689 return saveDataObject(sCmd);
3690}
3691
3692
3701static CommandReturnValues cmd_set(string& sCmd)
3702{
3710
3711 std::map<std::string, SettingsValue>& mSettings = _option.getSettings();
3712
3713 size_t nArgument;
3714 size_t pos;
3715 string sArgument;
3716
3717 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
3719
3720 for (auto iter = mSettings.begin(); iter != mSettings.end(); ++iter)
3721 {
3722 if (iter->second.isMutable() && (pos = findSettingOption(sCmd, iter->first.substr(iter->first.find('.')+1))))
3723 {
3724 switch (iter->second.getType())
3725 {
3727 if (!parseCmdArg(sCmd, pos, _parser, nArgument) || (nArgument != 0 && nArgument != 1))
3728 nArgument = !iter->second.active();
3729
3730 iter->second.active() = (bool)nArgument;
3731
3732 _data.setbLoadEmptyCols(mSettings[SETTING_B_LOADEMPTYCOLS].active());
3733
3734 if (iter->first == SETTING_B_DEFCONTROL && mSettings[SETTING_B_DEFCONTROL].active()
3735 && !_functions.getDefinedFunctions()
3736 && fileExists(_option.getExePath() + "\\functions.def"))
3737 _functions.load(_option);
3738 else if (iter->first == SETTING_B_DEBUGGER)
3740
3741 if (iter->second.isUiModifying())
3743
3744 if (_option.systemPrints())
3745 NumeReKernel::print(toUpperCase(iter->first.substr(iter->first.find('.')+1)) + ": " + toString((bool)nArgument));
3746
3747 break;
3749 if (parseCmdArg(sCmd, pos, _parser, nArgument)
3750 && nArgument >= iter->second.min()
3751 && nArgument <= iter->second.max())
3752 {
3753 iter->second.value() = nArgument;
3754
3755 if (iter->second.isUiModifying())
3757
3758 if (_option.systemPrints())
3759 NumeReKernel::print(toUpperCase(iter->first.substr(iter->first.find('.')+1)) + ": " + toString(nArgument));
3760 }
3761
3762 break;
3764 if (iter->second.isPath())
3765 {
3766 sArgument = getPathForSetting(sCmd, pos);
3767
3768 FileSystem _fSys;
3769 _fSys.setTokens(_option.getTokenPaths());
3770 _fSys.setPath(sArgument, true, _data.getProgramPath());
3771
3772 iter->second.stringval() = _fSys.getPath();
3773
3774 _out.setPath(mSettings[SETTING_S_SAVEPATH].stringval(), false, mSettings[SETTING_S_EXEPATH].stringval());
3775 _data.setSavePath(mSettings[SETTING_S_SAVEPATH].stringval());
3776 _data.setPath(mSettings[SETTING_S_LOADPATH].stringval(), false, mSettings[SETTING_S_EXEPATH].stringval());
3777 _script.setPath(mSettings[SETTING_S_SCRIPTPATH].stringval(), false, mSettings[SETTING_S_EXEPATH].stringval());
3778 _pData.setPath(mSettings[SETTING_S_PLOTPATH].stringval(), false, mSettings[SETTING_S_EXEPATH].stringval());
3779
3780 if (iter->second.isUiModifying())
3782
3783 if (_option.systemPrints())
3784 NumeReKernel::print(toUpperCase(iter->first.substr(iter->first.find('.')+1)) + ": " + iter->second.stringval());
3785 }
3786 else
3787 {
3788 if (sCmd[pos] == '=')
3789 addArgumentQuotes(sCmd, pos);
3790
3791 if (extractFirstParameterStringValue(sCmd, sArgument))
3792 {
3793 if (sArgument.front() == '"')
3794 sArgument.erase(0, 1);
3795
3796 if (sArgument.back() == '"')
3797 sArgument.erase(sArgument.length() - 1);
3798
3799 if (iter->first == SETTING_S_PLOTFONT)
3800 {
3801 _option.setDefaultPlotFont(sArgument);
3802 _fontData.LoadFont(mSettings[SETTING_S_PLOTFONT].stringval().c_str(), mSettings[SETTING_S_EXEPATH].stringval().c_str());
3803 _pData.setFont(mSettings[SETTING_S_PLOTFONT].stringval());
3804 }
3805 else
3806 iter->second.stringval() = sArgument;
3807
3808 if (iter->second.isUiModifying())
3810
3811 if (_option.systemPrints())
3812 NumeReKernel::print(toUpperCase(iter->first.substr(iter->first.find('.')+1)) + ": " + sArgument);
3813 }
3814 }
3815
3816 }
3817
3818 return COMMAND_PROCESSED;
3819 }
3820 }
3821
3822 if ((pos = findSettingOption(sCmd, "mode")))
3823 {
3824 sArgument = getArgAtPos(sCmd, pos, ARGEXTRACT_STRIPPED);
3825
3826 if (sArgument.length() && sArgument == "debug")
3827 {
3828 if (_option.useDebugger())
3829 {
3830 mSettings[SETTING_B_DEBUGGER].active() = false;
3832 }
3833 else
3834 {
3835 mSettings[SETTING_B_DEBUGGER].active() = true;
3837 }
3838
3839 if (_option.systemPrints())
3840 NumeReKernel::print("DEBUGGER: " + toString(_option.useDebugger()));
3841 }
3842 else if (sArgument.length() && sArgument == "developer")
3843 {
3844 if (_option.isDeveloperMode())
3845 {
3846 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_SET_DEVMODE_INACTIVE"), _option) );
3847 mSettings[SETTING_B_DEVELOPERMODE].active() = false;
3848 _parser.EnableDebugDump(false, false);
3850 }
3851 else
3852 {
3853 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_SET_DEVMODE_ACTIVE"), _option) );
3854 sArgument = "";
3855
3856 do
3857 {
3858 NumeReKernel::printPreFmt("|\n|<- ");
3859 NumeReKernel::getline(sArgument);
3860 }
3861 while (!sArgument.length());
3862
3863 if (sArgument == AutoVersion::STATUS)
3864 {
3865 mSettings[SETTING_B_DEVELOPERMODE].active() = true;
3866 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_SET_DEVMODE_SUCCESS"), _option) );
3867 _parser.EnableDebugDump(true, true);
3869 }
3870 else
3871 NumeReKernel::print(toSystemCodePage( _lang.get("COMMON_CANCEL")) );
3872 }
3873 }
3874 }
3875 else if (findSettingOption(sCmd, "save"))
3876 _option.save(_option.getExePath());
3877 else
3878 doc_Help("set", _option);
3879
3880 return COMMAND_PROCESSED;
3881}
3882
3883
3892static CommandReturnValues cmd_start(string& sCmd)
3893{
3894 CommandLineParser cmdParser(sCmd, "start", CommandLineParser::CMD_DAT_PAR);
3896
3897 if (_script.isOpen())
3899
3900 std::string sFileName = cmdParser.getExprAsFileName(".nscr", "<scriptpath>");
3901
3902 if (!sFileName.length())
3903 throw SyntaxError(SyntaxError::SCRIPT_NOT_EXIST, sCmd, sFileName, "[" + _lang.get("BUILTIN_CHECKKEYWORD_START_ERRORTOKEN") + "]");
3904
3905 _script.openScript(sFileName);
3906
3907 return COMMAND_PROCESSED;
3908}
3909
3910
3920static CommandReturnValues cmd_show(string& sCmd)
3921{
3922 // Get references to the main objects
3926
3928
3929 // Handle the compact mode (probably not needed any more)
3930 if (cmdParser.getCommand().substr(0, 5) == "showf")
3931 _out.setCompact(false);
3932 else
3933 _out.setCompact(_option.createCompactTables());
3934
3935 DataAccessParser _accessParser = cmdParser.getExprAsDataObject();
3936 _accessParser.evalIndices();
3937
3938 if (_accessParser.getDataObject().length())
3939 {
3940 if (_accessParser.isCluster())
3941 {
3942 NumeRe::Cluster& cluster = _data.getCluster(_accessParser.getDataObject());
3943
3944 // Create the target container
3945 NumeRe::Container<string> _stringTable(_accessParser.getIndices().row.size(), 1);
3946
3947 // Copy the data to the new container
3948 for (size_t i = 0; i < _accessParser.getIndices().row.size(); i++)
3949 {
3951 _stringTable.set(i, 0, cluster.getString(_accessParser.getIndices().row[i]));
3952 else
3953 _stringTable.set(i, 0, mu::isnan(cluster.getDouble(_accessParser.getIndices().row[i])) ? "---" : toString(cluster.getDouble(_accessParser.getIndices().row[i]), 5));
3954 }
3955
3956 // Redirect control
3957 NumeReKernel::showStringTable(_stringTable, _accessParser.getDataObject() + "{}");
3958
3959 return COMMAND_PROCESSED;
3960 }
3961 else if (_accessParser.getDataObject() == "string")
3962 {
3963 // Create the target container
3964 NumeRe::Container<string> _stringTable(_accessParser.getIndices().row.size(), _accessParser.getIndices().col.size());
3965
3966 // Copy the data to the new container and add surrounding
3967 // quotation marks
3968 for (size_t j = 0; j < _accessParser.getIndices().col.size(); j++)
3969 {
3970 for (size_t i = 0; i < _accessParser.getIndices().row.size(); i++)
3971 {
3972 if ((int)_data.getStringElements(_accessParser.getIndices().col[j]) <= _accessParser.getIndices().row[i])
3973 break;
3974
3975 _stringTable.set(i, j, "\"" + _data.readString(_accessParser.getIndices().row[i], _accessParser.getIndices().col[j]) + "\"");
3976 }
3977 }
3978
3979 // Redirect control
3980 NumeReKernel::showStringTable(_stringTable, "string()");
3981 }
3982 else
3983 {
3984 MemoryManager _cache;
3985
3986 // Validize the obtained index sets
3987 if (!isValidIndexSet(_accessParser.getIndices()))
3988 throw SyntaxError(SyntaxError::TABLE_DOESNT_EXIST, sCmd, _accessParser.getDataObject() + "(", _accessParser.getDataObject() + "()");
3989
3990 // Copy the target data to a new table
3991 copyDataToTemporaryTable(sCmd, _accessParser, _data, _cache);
3992 _cache.renameTable("table", "*" + _accessParser.getDataObject(), true);
3993
3994 // Redirect the control
3995 show_data(_cache, _out, _option, "*" + _accessParser.getDataObject(), _option.getPrecision());
3996 return COMMAND_PROCESSED;
3997 }
3998 }
3999 else
4000 {
4002 }
4003
4004 return COMMAND_PROCESSED;
4005}
4006
4007
4017{
4020
4021 CommandLineParser cmdParser(sCmd, "smooth", CommandLineParser::CMD_DAT_PAR);
4022
4023 string sArgument;
4024 int nWindowSize = 1;
4025 double dAlpha = NAN;
4028
4029 // Find the window size
4030 auto vParVal = cmdParser.getParameterValueAsNumericalValue("order");
4031
4032 if (vParVal.size())
4033 nWindowSize = intCast(vParVal.front());
4034
4035 // Ensure that the windowsize is odd (we don't need even window sizes)
4036 nWindowSize = 2 * nWindowSize + 1;
4037
4038 // Find the window shape (used for type=gaussian)
4039 vParVal = cmdParser.getParameterValueAsNumericalValue("alpha");
4040
4041 if (vParVal.size())
4042 dAlpha = vParVal.front().real();
4043
4044 // Find the smoothing filter type
4045 std::string sFilterType = cmdParser.getParameterValue("type");
4046
4047 if (!sFilterType.length())
4048 sFilterType = cmdParser.getParameterValue("method");
4049
4050 if (sFilterType.length())
4051 {
4052 if (sFilterType == "weightedlinear")
4054 else if (sFilterType == "gaussian")
4056 else if (sFilterType == "savitzkygolay")
4058 }
4059
4060 // Find the app dir
4061 if (cmdParser.hasParam("grid"))
4062 dir = MemoryManager::GRID;
4063 else if (cmdParser.hasParam("lines"))
4065 else if (cmdParser.hasParam("cols"))
4066 dir = MemoryManager::COLS;
4067
4068 if (!cmdParser.exprContainsDataObjects())
4069 return COMMAND_PROCESSED;
4070
4071 DataAccessParser _access = cmdParser.getExprAsDataObject();
4072
4073 if (_access.getDataObject().length())
4074 {
4075 if (!isValidIndexSet(_access.getIndices()))
4076 throw SyntaxError(SyntaxError::INVALID_INDEX, sCmd, _access.getDataObject(), _access.getIndexString());
4077
4078 _access.evalIndices();
4079
4080 bool success = false;
4081
4082 // Apply the smoothing filter
4083 switch (dir)
4084 {
4086 case MemoryManager::ALL:
4087 success = _data.smooth(_access.getDataObject(), _access.getIndices().row, _access.getIndices().col, NumeRe::FilterSettings(_type, nWindowSize, nWindowSize, dAlpha), dir);
4088 break;
4091 success = _data.smooth(_access.getDataObject(), _access.getIndices().row, _access.getIndices().col, NumeRe::FilterSettings(_type, nWindowSize, 1u, dAlpha), dir);
4092 break;
4093 }
4094
4095 if (success)
4096 {
4097 if (_option.systemPrints())
4098 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_SMOOTH", "\"" + _access.getDataObject() + "\""));
4099 }
4100 else
4102 }
4103 else
4105
4106 return COMMAND_PROCESSED;
4107}
4108
4109
4118static CommandReturnValues cmd_swap(string& sCmd)
4119{
4120 return swapTables(sCmd, NumeReKernel::getInstance()->getMemoryManager(), NumeReKernel::getInstance()->getSettings());
4121}
4122
4123
4132static CommandReturnValues cmd_hist(string& sCmd)
4133{
4134 string sArgument = evaluateParameterValues(sCmd);
4135
4136 plugin_histogram(sArgument);
4137
4138 return COMMAND_PROCESSED;
4139}
4140
4141
4150static CommandReturnValues cmd_help(string& sCmd)
4151{
4153
4154 if (findCommand(sCmd).nPos + findCommand(sCmd).sString.length() < sCmd.length())
4155 doc_Help(sCmd.substr(findCommand(sCmd).nPos + findCommand(sCmd).sString.length()), _option);
4156 else
4157 doc_Help("brief", _option);
4158
4159 return COMMAND_PROCESSED;
4160}
4161
4162
4171static CommandReturnValues cmd_move(string& sCmd)
4172{
4173 CommandLineParser cmdParser(sCmd, "move", CommandLineParser::CMD_DAT_PAR);
4175
4176 if (cmdParser.getExpr().length())
4177 {
4178 if (cmdParser.exprContainsDataObjects())
4179 {
4180 if (moveData(cmdParser))
4181 {
4182 if (_option.systemPrints())
4183 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_MOVEDATA_SUCCESS"), _option) );
4184 }
4185 else
4187 }
4188 else
4189 {
4190 if (moveOrCopyFiles(cmdParser))
4191 {
4192 if (_option.systemPrints())
4193 {
4194 if (cmdParser.hasParam("all") || cmdParser.hasParam("a"))
4195 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_MOVEFILE_ALL_SUCCESS", cmdParser.getReturnValueStatement()));
4196 else
4197 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_MOVEFILE_SUCCESS", cmdParser.getReturnValueStatement()));
4198 }
4199 }
4200 else
4202 }
4203 }
4204
4205 return COMMAND_PROCESSED;
4206}
4207
4208
4217static CommandReturnValues cmd_pack(string& sCmd)
4218{
4221
4222 if (cmdParser.getExpr().length() && cmdParser.hasParam("file"))
4223 {
4224 std::string sTargetPathName = cmdParser.getFileParameterValueForSaving("", "<savepath>", "");
4225 std::string sExpression = cmdParser.getExpr();
4227
4228 if (cmdParser.hasParam("type"))
4229 {
4230 std::string sType = cmdParser.getParameterValue("type");
4231
4232 if (sType == "ziparchive")
4233 type = Archive::ARCHIVE_ZIP;
4234 else if (sType == "gzarchive")
4235 type = Archive::ARCHIVE_GZ;
4236 else if (sType == "tarchive")
4237 type = Archive::ARCHIVE_TAR;
4238 }
4239
4240 if (instance->getStringParser().isStringExpression(sExpression)
4241 || instance->getMemoryManager().containsClusters(sExpression))
4242 {
4243 sExpression += " -komq";
4244 std::string sDummy = "";
4245 instance->getStringParser().evalAndFormat(sExpression, sDummy, true);
4246 }
4247
4248 std::vector<std::string> vFileNames;
4249
4250 while (sExpression.length())
4251 {
4252 vFileNames.push_back(instance->getFileSystem().ValidFileName(removeQuotationMarks(getNextArgument(sExpression)), "", false, false));
4253 }
4254
4255
4256 Archive::pack(vFileNames, sTargetPathName, type);
4257 }
4258
4259 return COMMAND_PROCESSED;
4260}
4261
4262
4272{
4273 CommandLineParser cmdParser(sCmd, "unpack", CommandLineParser::CMD_EXPR_set_PAR);
4274
4275 if (cmdParser.getExpr().length())
4276 {
4277 std::string sArchiveFileName = cmdParser.getExprAsFileName(".zip", "<loadpath>");
4278 std::string sTargetPathName = replacePathSeparator(cmdParser.getParameterValueAsString("target", ""));
4279
4280 if (sTargetPathName.length())
4281 sTargetPathName = NumeReKernel::getInstance()->getFileSystem().ValidFolderName(sTargetPathName, true, false);
4282
4283 std::vector<std::string> vFiles = Archive::unpack(sArchiveFileName, sTargetPathName);
4284
4285 if (vFiles.size())
4286 {
4287 for (auto& file : vFiles)
4288 {
4289 file.insert(0, 1, '"');
4290 file += '"';
4291 }
4292
4293 cmdParser.setReturnValue(vFiles);
4294
4295 sCmd = cmdParser.getReturnValueStatement();
4297 }
4298 }
4299
4300 return COMMAND_PROCESSED;
4301}
4302
4303
4312static CommandReturnValues cmd_hline(string& sCmd)
4313{
4314 if (findParameter(sCmd, "single"))
4315 make_hline(-2);
4316 else
4317 make_hline();
4318
4319 return COMMAND_PROCESSED;
4320}
4321
4322
4331static CommandReturnValues cmd_matop(string& sCmd)
4332{
4337
4338 performMatrixOperation(sCmd, _parser, _data, _functions, _option);
4339 return COMMAND_PROCESSED;
4340}
4341
4342
4352{
4353 plugin_random(sCmd);
4354
4355 return COMMAND_PROCESSED;
4356}
4357
4358
4368{
4371
4372 if (sCmd.length() > findCommand(sCmd).sString.length() + 1)
4373 {
4374 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
4376
4377 if (findParameter(sCmd, "comment", '='))
4378 addArgumentQuotes(sCmd, "comment");
4379
4380 if (_functions.defineFunc(sCmd.substr(sCmd.find(' ') + 1), true))
4381 NumeReKernel::print(_lang.get("DEFINE_SUCCESS"), _option.systemPrints());
4382 else
4383 NumeReKernel::issueWarning(_lang.get("DEFINE_FAILURE"));
4384 }
4385 else
4386 doc_Help("define", _option);
4387
4388 return COMMAND_PROCESSED;
4389}
4390
4391
4401{
4402 CommandLineParser cmdParser(sCmd, "resample", CommandLineParser::CMD_DAT_PAR);
4405
4406 if (!cmdParser.exprContainsDataObjects())
4407 return COMMAND_PROCESSED;
4408
4409 DataAccessParser _access = cmdParser.getExprAsDataObject();
4410
4411 if (_access.getDataObject().length())
4412 {
4413 auto vParVal = cmdParser.getParameterValueAsNumericalValue("samples");
4414
4415 std::pair<size_t, size_t> samples;
4416
4417 if (vParVal.size() > 1)
4418 {
4419 samples.first = intCast(vParVal[0]);
4420 samples.second = intCast(vParVal[1]);
4421 }
4422 else if (vParVal.size() == 1)
4423 {
4424 samples.first = intCast(vParVal.front());
4425 samples.second = intCast(vParVal.front());
4426 }
4427 else
4428 {
4429 samples.first = _data.getLines(_access.getDataObject(), false);
4430 samples.second = _data.getCols(_access.getDataObject(), false);
4431 }
4432
4433 if (!isValidIndexSet(_access.getIndices()))
4434 throw SyntaxError(SyntaxError::INVALID_INDEX, sCmd, _access.getDataObject(), _access.getIndexString());
4435
4436 _access.evalIndices();
4437
4439
4440 if (cmdParser.hasParam("grid"))
4441 dir = MemoryManager::GRID;
4442 else if (cmdParser.hasParam("cols"))
4443 dir = MemoryManager::COLS;
4444 else if (cmdParser.hasParam("lines"))
4446
4447 std::string sFilter = "lanczos3";
4448
4449 if (cmdParser.hasParam("method"))
4450 sFilter = cmdParser.getParameterValue("method");
4451
4452 if (_data.resample(_access.getDataObject(), _access.getIndices().row, _access.getIndices().col, samples, dir, sFilter))
4453 {
4454 if (_option.systemPrints())
4455 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_RESAMPLE", _lang.get("COMMON_LINES")), _option) );
4456 }
4457 else
4459 }
4460 else
4462
4463 return COMMAND_PROCESSED;
4464}
4465
4466
4476{
4479
4480 CommandLineParser cmdParser(sCmd, "remove", CommandLineParser::CMD_DAT_PAR);
4481
4482 std::string sReturnStatement;
4483
4484 if (cmdParser.exprContainsDataObjects())
4485 {
4486 std::string sTableList = cmdParser.getExpr();
4487
4488 while (_data.containsTables(sTableList) && sTableList.length())
4489 {
4490 std::string sTable = getNextArgument(sTableList, true);
4491
4492 for (auto iter = _data.getTableMap().begin(); iter != _data.getTableMap().end(); ++iter)
4493 {
4494 size_t nPos = sTable.find(iter->first + "()");
4495
4496 if (nPos != string::npos && (!nPos || isDelimiter(sTable[nPos-1])) && iter->first != "table")
4497 {
4498 sTable = iter->first;
4499
4500 if (_data.deleteTable(iter->first))
4501 {
4502 if (sReturnStatement.length())
4503 sReturnStatement += ", ";
4504
4505 sReturnStatement += "\"" + sTable + "()\"";
4506 break;
4507 }
4508 }
4509 }
4510 }
4511
4512 if (sReturnStatement.length() && _option.systemPrints())
4513 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_REMOVECACHE", sReturnStatement));
4514 }
4515 else if (cmdParser.getExpr().length())
4516 {
4517 if (!removeFile(cmdParser))
4519 else if (_option.systemPrints())
4520 {
4521 if (cmdParser.hasParam("all") || cmdParser.hasParam("a"))
4522 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_REMOVE_ALL_FILE"));
4523 else
4524 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_REMOVE_FILE"));
4525 }
4526 }
4527 else
4529
4530 return COMMAND_PROCESSED;
4531}
4532
4533
4543{
4546
4547 string sArgument;
4548
4549 // If the current command line contains strings
4550 // handle them here
4551 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sCmd))
4552 sCmd = evaluateParameterValues(sCmd);
4553
4554 // Handle legacy and new syntax in these two cases
4555 if (_data.matchTableAsParameter(sCmd, '=').length())
4556 {
4557 // Legacy syntax: rename -cache1=cache2
4558 //
4559 // Get the option value of the parameter "cache1"
4560 sArgument = getArgAtPos(sCmd, findParameter(sCmd, _data.matchTableAsParameter(sCmd, '='), '=') + _data.matchTableAsParameter(sCmd, '=').length());
4561
4562 // Rename the cache
4563 _data.renameTable(_data.matchTableAsParameter(sCmd, '='), sArgument);
4564
4565 if (_option.systemPrints())
4566 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_RENAME_CACHE", sArgument), _option) );
4567 }
4568 else if (sCmd.find("()") != string::npos && sCmd.find(',') != string::npos)
4569 {
4570 // New syntax: rename cache1(), cache2()
4571 //
4572 // Extract the first of the two arguments
4573 // (length of command = 6)
4574 sCmd.erase(0, 6);
4575 sArgument = getNextArgument(sCmd, true);
4576
4577 if (!sCmd.length())
4578 return COMMAND_PROCESSED;
4579
4580 // Remove parentheses, if available
4581 if (sArgument.find('(') != string::npos)
4582 sArgument.erase(sArgument.find('('));
4583
4584 if (sCmd.find('(') != string::npos)
4585 sCmd.erase(sCmd.find('('));
4586
4587 // Remove not necessary white spaces
4588 StripSpaces(sArgument);
4589 StripSpaces(sCmd);
4590
4591 // Rename the cache
4592 _data.renameTable(sArgument, sCmd);
4593
4594 if (_option.systemPrints())
4595 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_RENAME_CACHE", sCmd), _option) );
4596 }
4597
4598 return COMMAND_PROCESSED;
4599}
4600
4601
4611{
4614
4615 if (!_data.containsTablesOrClusters(sCmd))
4616 return COMMAND_PROCESSED;
4617
4618 // DEPRECATED: Declared at v1.1.2rc1
4619 if (findCommand(sCmd).sString == "retoque")
4620 NumeReKernel::issueWarning(_lang.get("COMMON_COMMAND_DEPRECATED", sCmd));
4621
4622 DataAccessParser _access(sCmd);
4623
4624 if (_access.getDataObject().length())
4625 {
4626 if (!isValidIndexSet(_access.getIndices()))
4627 throw SyntaxError(SyntaxError::INVALID_INDEX, sCmd, _access.getDataObject(), _access.getIndexString());
4628
4629 if (_access.getIndices().row.isOpenEnd())
4630 _access.getIndices().row.setRange(0, _data.getLines(_access.getDataObject(), false)-1);
4631
4632 if (_access.getIndices().col.isOpenEnd())
4633 _access.getIndices().col.setRange(0, _data.getCols(_access.getDataObject())-1);
4634
4636
4637 if (findParameter(sCmd, "grid"))
4638 dir = MemoryManager::GRID;
4639 else if (findParameter(sCmd, "lines"))
4641 else if (findParameter(sCmd, "cols"))
4642 dir = MemoryManager::COLS;
4643
4644 if (_data.retouch(_access.getDataObject(), _access.getIndices().row, _access.getIndices().col, dir))
4645 {
4646 if (_option.systemPrints())
4647 NumeReKernel::print(LineBreak( _lang.get("BUILTIN_CHECKKEYWORD_RETOQUE", _lang.get("COMMON_COLS")), _option) );
4648 }
4649 else
4651 }
4652 else
4654
4655 return COMMAND_PROCESSED;
4656}
4657
4658
4668{
4670 CommandLineParser cmdParser(sCmd, "regularize", CommandLineParser::CMD_DAT_PAR);
4671
4672 if (!regularizeDataSet(cmdParser))
4674 else if (_option.systemPrints())
4675 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_REGULARIZE"));
4676
4677 return COMMAND_PROCESSED;
4678}
4679
4680
4690{
4694
4695 if (sCmd.length() > 8)
4696 {
4697 _functions.setTableList(_data.getTableNames());
4698
4699 if (NumeReKernel::getInstance()->getStringParser().containsStringVars(sCmd))
4701
4702 if (findParameter(sCmd, "comment", '='))
4703 addArgumentQuotes(sCmd, "comment");
4704
4705 if (findParameter(sCmd, "save"))
4706 {
4707 _functions.save(_option);
4708 return COMMAND_PROCESSED;
4709 }
4710 else if (findParameter(sCmd, "load"))
4711 {
4712 if (fileExists(_option.getExePath() + "\\functions.def"))
4713 _functions.load(_option);
4714 else
4715 NumeReKernel::print(toSystemCodePage( _lang.get("BUILTIN_CHECKKEYWORD_DEF_EMPTY")) );
4716
4717 return COMMAND_PROCESSED;
4718 }
4719 else
4720 {
4721 if (_functions.defineFunc(sCmd.substr(7)))
4722 NumeReKernel::print(_lang.get("DEFINE_SUCCESS"), _option.systemPrints());
4723 else
4724 NumeReKernel::issueWarning(_lang.get("DEFINE_FAILURE"));
4725 }
4726 }
4727 else
4728 doc_Help("define", _option);
4729
4730 return COMMAND_PROCESSED;
4731}
4732
4733
4743{
4744 CommandLineParser cmdParser(sCmd, "datagrid", CommandLineParser::CMD_EXPR_set_PAR);
4746
4747 if (!createDatagrid(cmdParser))
4748 doc_Help("datagrid", _option);
4749 else if (_option.systemPrints())
4750 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYWORD_DATAGRID_SUCCESS", cmdParser.getReturnValueStatement()));
4751
4752 return COMMAND_PROCESSED;
4753}
4754
4755
4765{
4766 CommandLineParser cmdParser(sCmd, "detect", CommandLineParser::CMD_EXPR_set_PAR);
4767 boneDetection(cmdParser);
4768
4769 return COMMAND_PROCESSED;
4770}
4771
4772
4781static CommandReturnValues cmd_list(string& sCmd)
4782{
4787
4788 string sArgument;
4789
4790 if (findSettingOption(sCmd, "files"))
4791 listFiles(sCmd, _option);
4792 else if (findSettingOption(sCmd, "var"))
4793 listDeclaredVariables(_parser, _option, _data);
4794 else if (findSettingOption(sCmd, "const"))
4795 listConstants(_parser, _option);
4796 else if (findSettingOption(sCmd, "func"))
4797 {
4798 sArgument = getArgAtPos(sCmd, findSettingOption(sCmd, "func"));
4799
4800 if (sArgument == "num" || sArgument == "numerical")
4801 listFunctions(_option, "num");
4802 else if (sArgument == "mat" || sArgument == "matrix" || sArgument == "vec" || sArgument == "vector")
4803 listFunctions(_option, "mat");
4804 else if (sArgument == "string")
4805 listFunctions(_option, "string");
4806 else if (sArgument == "trigonometric")
4807 listFunctions(_option, "trigonometric");
4808 else if (sArgument == "hyperbolic")
4809 listFunctions(_option, "hyperbolic");
4810 else if (sArgument == "logarithmic")
4811 listFunctions(_option, "logarithmic");
4812 else if (sArgument == "polynomial")
4813 listFunctions(_option, "polynomial");
4814 else if (sArgument == "stats" || sArgument == "statistical")
4815 listFunctions(_option, "stats");
4816 else if (sArgument == "angular")
4817 listFunctions(_option, "angular");
4818 else if (sArgument == "physics" || sArgument == "physical")
4819 listFunctions(_option, "physics");
4820 else if (sArgument == "logic" || sArgument == "logical")
4821 listFunctions(_option, "logic");
4822 else if (sArgument == "time")
4823 listFunctions(_option, "time");
4824 else if (sArgument == "distrib")
4825 listFunctions(_option, "distrib");
4826 else if (sArgument == "random")
4827 listFunctions(_option, "random");
4828 else if (sArgument == "coords")
4829 listFunctions(_option, "coords");
4830 else if (sArgument == "draw")
4831 listFunctions(_option, "draw");
4832 else
4833 listFunctions(_option, "all");
4834
4835 }
4836 else if (findSettingOption(sCmd, "logic"))
4837 listLogicalOperators(_option);
4838 else if (findSettingOption(sCmd, "cmd"))
4839 listCommands(_option);
4840 else if (findSettingOption(sCmd, "define"))
4841 listDefinitions(_functions, _option);
4842 else if (findSettingOption(sCmd, "units"))
4843 listUnitConversions(_option);
4844 else if (findSettingOption(sCmd, "plugins") || findSettingOption(sCmd, "packages"))
4845 listInstalledPlugins(_parser, _data, _option);
4846
4847 return COMMAND_PROCESSED;
4848}
4849
4850
4858static std::string getTargetTable(const std::string& sCmd)
4859{
4860 std::string sTargetTable;
4861
4862 if (findParameter(sCmd, "totable", '='))
4863 sTargetTable = getArgAtPos(sCmd, findParameter(sCmd, "totable", '=')+7);
4864 else if (findParameter(sCmd, "tocache", '='))
4865 sTargetTable = getArgAtPos(sCmd, findParameter(sCmd, "tocache", '=')+7);
4866 else if (findParameter(sCmd, "target", '='))
4867 sTargetTable = getArgAtPos(sCmd, findParameter(sCmd, "target", '=')+6);
4868
4869 if (sTargetTable.find('(') != std::string::npos)
4870 return sTargetTable.substr(0, sTargetTable.find('('));
4871
4872 return sTargetTable;
4873}
4874
4875
4884static CommandReturnValues cmd_load(string& sCmd)
4885{
4890
4891 CommandLineParser cmdParser(sCmd, "load", CommandLineParser::CMD_DAT_PAR);
4892
4893 int nArgument;
4894
4895 if (findParameter(sCmd, "define"))
4896 {
4897 if (fileExists("functions.def"))
4898 _functions.load(_option);
4899 else
4900 NumeReKernel::print( _lang.get("BUILTIN_CHECKKEYWORD_DEF_EMPTY") );
4901 }
4902 else if (cmdParser.getExpr().length())
4903 {
4904 if (cmdParser.hasParam("app"))
4905 {
4906 double j1 = _data.getCols("data") + 1;
4907 append_data(cmdParser);
4908 cmdParser.setReturnValue(std::vector<mu::value_type>({1, _data.getLines("data"), j1, _data.getCols("data")}));
4909 sCmd = cmdParser.getReturnValueStatement();
4910
4912 }
4913
4914 std::string sFileName = cmdParser.parseExprAsString();
4915
4916 if (sFileName.length())
4917 {
4918 std::string sSlicingParam = cmdParser.getParameterValue("slice");
4919
4920 if (sSlicingParam == "xz")
4921 nArgument = -1;
4922 else if (sSlicingParam == "yz")
4923 nArgument = -2;
4924 else
4925 nArgument = 0;
4926
4927 _data.setbLoadEmptyColsInNextFile(cmdParser.hasParam("keepdim") || cmdParser.hasParam("complete"));
4928
4929 if ((cmdParser.hasParam("tocache") || cmdParser.hasParam("totable") || cmdParser.hasParam("target")) && !cmdParser.hasParam("all"))
4930 {
4931 // Single file directly to cache
4932 std::string sTargetTable = getTargetTable(cmdParser.getParameterList());
4933
4934 NumeRe::FileHeaderInfo info = _data.openFile(sFileName, true, cmdParser.hasParam("ignore") || cmdParser.hasParam("i"), nArgument, sTargetTable);
4935
4936 if (!_data.isEmpty(info.sTableName))
4937 {
4938 if (_option.systemPrints())
4939 NumeReKernel::print(_lang.get("BUILTIN_LOADDATA_SUCCESS", info.sTableName + "()", toString(_data.getLines(info.sTableName, false)), toString(_data.getCols(info.sTableName, false))));
4940
4941 cmdParser.setReturnValue(std::vector<mu::value_type>({1, info.nRows, _data.getCols(info.sTableName)-info.nCols+1, _data.getCols(info.sTableName)}));
4942 sCmd = cmdParser.getReturnValueStatement();
4943
4945 }
4946
4947 return COMMAND_PROCESSED;
4948 }
4949 else if ((cmdParser.hasParam("tocache") || cmdParser.hasParam("totable") || cmdParser.hasParam("target")) && cmdParser.hasParam("all") && (sFileName.find('*') != string::npos || sFileName.find('?') != string::npos))
4950 {
4951 // multiple files directly to cache
4952 if (sFileName.find('/') == string::npos)
4953 sFileName = "<loadpath>/" + sFileName;
4954
4955 vector<string> vFilelist = getFileList(sFileName, _option, 1);
4956
4957 if (!vFilelist.size())
4958 throw SyntaxError(SyntaxError::FILE_NOT_EXIST, sCmd, sFileName, sFileName);
4959
4960 for (size_t i = 0; i < vFilelist.size(); i++)
4961 vFilelist[i] = _data.openFile(vFilelist[i], true, cmdParser.hasParam("ignore") || cmdParser.hasParam("i"), nArgument, getTargetTable(cmdParser.getParameterList())).sTableName;
4962
4963 if (!_data.isEmpty(vFilelist.front()) && _option.systemPrints())
4964 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYOWRD_LOAD_ALL_CACHES_SUCCESS", toString(vFilelist.size()), sFileName));
4965
4966 // Returning of indices not possible due to multiple
4967 // table targets
4968
4969 return COMMAND_PROCESSED;
4970 }
4971
4972 if (cmdParser.hasParam("i") || cmdParser.hasParam("ignore") || _data.isEmpty("data"))
4973 {
4974 if (!_data.isEmpty("data"))
4975 _data.removeData();
4976
4977 // multiple files
4978 if (cmdParser.hasParam("all") && (sFileName.find('*') != string::npos || sFileName.find('?') != string::npos))
4979 {
4980 if (sFileName.find('/') == string::npos)
4981 sFileName = "<loadpath>/" + sFileName;
4982
4983 vector<string> vFilelist = getFileList(sFileName, _option, 1);
4984
4985 if (!vFilelist.size())
4986 throw SyntaxError(SyntaxError::FILE_NOT_EXIST, sCmd, sFileName, sFileName);
4987
4988 for (size_t i = 0; i < vFilelist.size(); i++)
4989 {
4990 // Melting is done automatically
4991 _data.openFile(vFilelist[i], false, false, nArgument);
4992 }
4993
4994 if (!_data.isEmpty("data") && _option.systemPrints())
4995 NumeReKernel::print(_lang.get("BUILTIN_CHECKKEYOWRD_LOAD_ALL_SUCCESS", toString(vFilelist.size()), sFileName, toString(_data.getLines("data", false)), toString(_data.getCols("data", false))));
4996
4997 cmdParser.setReturnValue(std::vector<mu::value_type>({1, _data.getLines("data", false), 1, _data.getCols("data", false)}));
4998 sCmd = cmdParser.getReturnValueStatement();
4999
5001 }
5002
5004
5005 // Provide headline
5006 auto vParList = cmdParser.getParameterValueAsNumericalValue("head");
5007
5008 if (vParList.size())
5009 nArgument = intCast(vParList.front());
5010 else
5011 {
5012 vParList = cmdParser.getParameterValueAsNumericalValue("h");
5013
5014 if (vParList.size())
5015 nArgument = intCast(vParList.front());
5016 }
5017
5018 info = _data.openFile(sFileName, false, false, nArgument);
5019
5020 if (!_data.isEmpty("data"))
5021 {
5022 if (_option.systemPrints())
5023 NumeReKernel::print(_lang.get("BUILTIN_LOADDATA_SUCCESS", info.sFileName, toString(info.nRows), toString(info.nCols)));
5024
5025 cmdParser.setReturnValue(std::vector<mu::value_type>({1, _data.getLines("data", false), 1, _data.getCols("data", false)}));
5026 sCmd = cmdParser.getReturnValueStatement();
5027
5029 }
5030 }
5031 else
5032 load_data(_data, _option, _parser, sFileName);
5033 }
5034 else
5035 load_data(_data, _option, _parser);
5036 }
5037 else
5038 doc_Help("load", _option);
5039
5040 return COMMAND_PROCESSED;
5041}
5042
5043
5053{
5056
5057 string sArgument;
5058 auto _filenames = getAllSemiColonSeparatedTokens(_data.getDataFileName("data"));
5059 Match _mMatch = findCommand(sCmd, "reload");
5060
5061 if (!_filenames.size())
5062 return COMMAND_PROCESSED;
5063
5064 _data.removeData();
5065
5066 for (size_t i = 0; i < _filenames.size(); i++)
5067 {
5068 if (sCmd.find_first_not_of(' ', _mMatch.nPos+6) != string::npos)
5069 {
5070 // Seems not to contain any valid file name
5071 if (sCmd[sCmd.find_first_not_of(' ', _mMatch.nPos+6)] == '-')
5072 sArgument = "load " + _filenames[i] + " " + sCmd.substr(sCmd.find_first_not_of(' ', _mMatch.nPos+6)) + " -app";
5073 else
5074 sArgument = sCmd.substr(_mMatch.nPos+2) + " -app";
5075 }
5076 else
5077 sArgument = "load " + _filenames[i] + " -app";
5078
5079 cmd_load(sArgument);
5080 }
5081
5082 _parser.SetVectorVar("_~load[~_~]", {1, _data.getLines("data", false), 1, _data.getCols("data", false)});
5083 sCmd.replace(_mMatch.nPos, string::npos, "_~load[~_~]");
5084
5086}
5087
5088
5098{
5103
5104 executeCommand(sCmd, _parser, _data, _functions, _option);
5105 return COMMAND_PROCESSED;
5106}
5107
5108
5118{
5119 CommandLineParser cmdParser(sCmd, "progress", CommandLineParser::CMD_EXPR_set_PAR);
5120
5121 if (!cmdParser.getExpr().length())
5122 return COMMAND_PROCESSED;
5123
5124 string sArgument;
5125 int frst = 1, lst = 100;
5126
5127 auto vParVal = cmdParser.getParameterValueAsNumericalValue("first");
5128
5129 if (vParVal.size())
5130 frst = intCast(vParVal.front());
5131
5132 vParVal = cmdParser.getParameterValueAsNumericalValue("last");
5133
5134 if (vParVal.size())
5135 lst = intCast(vParVal.front());
5136
5137 sArgument = cmdParser.getParameterValue("type");
5138
5139 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sArgument))
5140 sArgument = cmdParser.getParameterValueAsString("type", "std");
5141
5142 auto vVal = cmdParser.parseExprAsNumericalValues();
5143
5144 if (vVal.size())
5145 make_progressBar(intCast(vVal.front()), frst, lst, sArgument);
5146
5147 return COMMAND_PROCESSED;
5148}
5149
5150
5159static CommandReturnValues cmd_print(string& sCmd)
5160{
5161 string sArgument = sCmd.substr(findCommand(sCmd).nPos + 6);
5162 string sDummy;
5163
5164 if (!NumeReKernel::getInstance()->getDefinitions().call(sArgument))
5165 throw SyntaxError(SyntaxError::FUNCTION_ERROR, sCmd, sArgument);
5166
5167 if (sArgument.find("??") != string::npos)
5168 sArgument = promptForUserInput(sArgument);
5169
5170 sArgument += " -print";
5171
5172 NumeReKernel::getInstance()->getStringParser().evalAndFormat(sArgument, sDummy, false);
5173
5174 return COMMAND_PROCESSED;
5175}
5176
5177
5187{
5189 rotateTable(cmdParser);
5190
5191 return COMMAND_PROCESSED;
5192}
5193
5194
5203static CommandReturnValues cmd_url(string& sCmd)
5204{
5205 CommandLineParser cmdParser(sCmd, "url", CommandLineParser::CMD_DAT_PAR);
5206 urlExecute(cmdParser);
5207 sCmd = cmdParser.getReturnValueStatement();
5208
5210}
5211
5212
5222{
5223 // Command is not usable in this context
5224 throw SyntaxError(SyntaxError::INVALID_COMMAND, sCmd, "include", "include");
5225}
5226
5227
5236static std::map<std::string,CommandFunc> getCommandFunctions()
5237{
5238 std::map<std::string, CommandFunc> mCommandFuncMap;
5239
5240 mCommandFuncMap["about"] = cmd_credits;
5241 mCommandFuncMap["audio"] = cmd_audio;
5242 mCommandFuncMap["clc"] = cmd_clc;
5243 mCommandFuncMap["clear"] = cmd_clear;
5244 mCommandFuncMap["close"] = cmd_close;
5245 mCommandFuncMap["cont"] = cmd_plotting;
5246 mCommandFuncMap["cont3d"] = cmd_plotting;
5247 mCommandFuncMap["contour"] = cmd_plotting;
5248 mCommandFuncMap["contour3d"] = cmd_plotting;
5249 mCommandFuncMap["copy"] = cmd_copy;
5250 mCommandFuncMap["credits"] = cmd_credits;
5251 mCommandFuncMap["datagrid"] = cmd_datagrid;
5252 mCommandFuncMap["del"] = cmd_delete;
5253 mCommandFuncMap["delete"] = cmd_delete;
5254 mCommandFuncMap["dens"] = cmd_plotting;
5255 mCommandFuncMap["dens3d"] = cmd_plotting;
5256 mCommandFuncMap["density"] = cmd_plotting;
5257 mCommandFuncMap["density3d"] = cmd_plotting;
5258 mCommandFuncMap["draw"] = cmd_plotting;
5259 mCommandFuncMap["draw3d"] = cmd_plotting;
5260 mCommandFuncMap["define"] = cmd_define;
5261 mCommandFuncMap["detect"] = cmd_detect;
5262 mCommandFuncMap["edit"] = cmd_edit;
5263 mCommandFuncMap["execute"] = cmd_execute;
5264 mCommandFuncMap["export"] = saveDataObject;
5265 mCommandFuncMap["fit"] = cmd_fit;
5266 mCommandFuncMap["fitw"] = cmd_fit;
5267 mCommandFuncMap["fft"] = cmd_fft;
5268 mCommandFuncMap["fft2d"] = cmd_fft;
5269 mCommandFuncMap["fwt"] = cmd_fwt;
5270 mCommandFuncMap["grad"] = cmd_plotting;
5271 mCommandFuncMap["grad3d"] = cmd_plotting;
5272 mCommandFuncMap["gradient"] = cmd_plotting;
5273 mCommandFuncMap["gradient3d"] = cmd_plotting;
5274 mCommandFuncMap["graph"] = cmd_plotting;
5275 mCommandFuncMap["graph3d"] = cmd_plotting;
5276 mCommandFuncMap["hist"] = cmd_hist;
5277 mCommandFuncMap["hist2d"] = cmd_hist;
5278 mCommandFuncMap["hline"] = cmd_hline;
5279 mCommandFuncMap["ifndef"] = cmd_ifndefined;
5280 mCommandFuncMap["ifndefined"] = cmd_ifndefined;
5281 mCommandFuncMap["implot"] = cmd_plotting;
5282 mCommandFuncMap["include"] = cmd_include;
5283 mCommandFuncMap["info"] = cmd_credits;
5284 mCommandFuncMap["install"] = cmd_install;
5285 mCommandFuncMap["list"] = cmd_list;
5286 mCommandFuncMap["matop"] = cmd_matop;
5287 mCommandFuncMap["mesh"] = cmd_plotting;
5288 mCommandFuncMap["mesh3d"] = cmd_plotting;
5289 mCommandFuncMap["meshgrid"] = cmd_plotting;
5290 mCommandFuncMap["meshgrid3d"] = cmd_plotting;
5291 mCommandFuncMap["move"] = cmd_move;
5292 mCommandFuncMap["mtrxop"] = cmd_matop;
5293 mCommandFuncMap["new"] = cmd_new;
5294 mCommandFuncMap["odesolve"] = cmd_odesolve;
5295 mCommandFuncMap["open"] = cmd_edit;
5296 mCommandFuncMap["pack"] = cmd_pack;
5297 mCommandFuncMap["plot"] = cmd_plotting;
5298 mCommandFuncMap["plot3d"] = cmd_plotting;
5299 mCommandFuncMap["plotcompose"] = cmd_plotting;
5300 mCommandFuncMap["print"] = cmd_print;
5301 mCommandFuncMap["progress"] = cmd_progress;
5302 mCommandFuncMap["quit"] = cmd_quit;
5303 mCommandFuncMap["random"] = cmd_random;
5304 mCommandFuncMap["redef"] = cmd_redefine;
5305 mCommandFuncMap["redefine"] = cmd_redefine;
5306 mCommandFuncMap["regularize"] = cmd_regularize;
5307 mCommandFuncMap["remove"] = cmd_remove;
5308 mCommandFuncMap["rename"] = cmd_rename;
5309 mCommandFuncMap["resample"] = cmd_resample;
5310 mCommandFuncMap["retoque"] = cmd_retouch;
5311 mCommandFuncMap["retouch"] = cmd_retouch;
5312 mCommandFuncMap["save"] = cmd_save;
5313 mCommandFuncMap["set"] = cmd_set;
5314 mCommandFuncMap["show"] = cmd_show;
5315 mCommandFuncMap["showf"] = cmd_show;
5316 mCommandFuncMap["smooth"] = cmd_smooth;
5317 mCommandFuncMap["spline"] = cmd_spline;
5318 mCommandFuncMap["start"] = cmd_start;
5319 mCommandFuncMap["stfa"] = cmd_stfa;
5320 mCommandFuncMap["surf"] = cmd_plotting;
5321 mCommandFuncMap["surf3d"] = cmd_plotting;
5322 mCommandFuncMap["surface"] = cmd_plotting;
5323 mCommandFuncMap["surface3d"] = cmd_plotting;
5324 mCommandFuncMap["swap"] = cmd_swap;
5325 mCommandFuncMap["tabrot"] = cmd_rotate;
5326 mCommandFuncMap["imrot"] = cmd_rotate;
5327 mCommandFuncMap["gridrot"] = cmd_rotate;
5328 mCommandFuncMap["undef"] = cmd_undefine;
5329 mCommandFuncMap["undefine"] = cmd_undefine;
5330 mCommandFuncMap["vect"] = cmd_plotting;
5331 mCommandFuncMap["vect3d"] = cmd_plotting;
5332 mCommandFuncMap["vector"] = cmd_plotting;
5333 mCommandFuncMap["vector3d"] = cmd_plotting;
5334 mCommandFuncMap["view"] = cmd_edit;
5335 mCommandFuncMap["warn"] = cmd_warn;
5336 mCommandFuncMap["workpath"] = cmd_workpath;
5337 mCommandFuncMap["write"] = cmd_write;
5338
5339 return mCommandFuncMap;
5340}
5341
5342
5351static std::map<std::string,CommandFunc> getCommandFunctionsWithReturnValues()
5352{
5353 std::map<std::string, CommandFunc> mCommandFuncMap;
5354
5355 mCommandFuncMap["append"] = cmd_append;
5356 mCommandFuncMap["audioread"] = cmd_audioread;
5357 mCommandFuncMap["dialog"] = cmd_dialog;
5358 mCommandFuncMap["diff"] = cmd_diff;
5359 mCommandFuncMap["eval"] = cmd_eval;
5360 mCommandFuncMap["extrema"] = cmd_extrema;
5361 mCommandFuncMap["imread"] = cmd_imread;
5362 mCommandFuncMap["integrate"] = cmd_integrate;
5363 mCommandFuncMap["integrate2d"] = cmd_integrate;
5364 mCommandFuncMap["load"] = cmd_load;
5365 mCommandFuncMap["pso"] = cmd_pso;
5366 mCommandFuncMap["pulse"] = cmd_pulse;
5367 mCommandFuncMap["read"] = cmd_read;
5368 mCommandFuncMap["readline"] = cmd_readline;
5369 mCommandFuncMap["reload"] = cmd_reload;
5370 mCommandFuncMap["seek"] = cmd_seek;
5371 mCommandFuncMap["sort"] = cmd_sort;
5372 mCommandFuncMap["stats"] = cmd_stats;
5373 mCommandFuncMap["taylor"] = cmd_taylor;
5374 mCommandFuncMap["unpack"] = cmd_unpack;
5375 mCommandFuncMap["url"] = cmd_url;
5376 mCommandFuncMap["window"] = cmd_window;
5377 mCommandFuncMap["zeroes"] = cmd_zeroes;
5378
5379 return mCommandFuncMap;
5380}
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391#endif // COMMANDFUNCTIONS_HPP
5392
const std::string sVersion
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
bool extractFirstParameterStringValue(const string &sCmd, string &sArgument)
This function returns the string argument for a single parameter in the command line.
Definition: built-in.cpp:98
bool parseCmdArg(const string &sCmd, size_t nPos, Parser &_parser, size_t &nArgument)
This function finds the numerical argument to the selected command line parameter and evaluates it.
Definition: built-in.cpp:422
string evaluateParameterValues(const string &sCmd)
This function evaluates a passed parameter string, so that the values of the parameters are only valu...
Definition: built-in.cpp:221
CommandReturnValues
Definition: built-in.hpp:50
@ COMMAND_PROCESSED
Definition: built-in.hpp:53
@ COMMAND_HAS_RETURNVALUE
Definition: built-in.hpp:54
@ NUMERE_QUIT
Definition: built-in.hpp:51
@ NO_COMMAND
Definition: built-in.hpp:52
This class provides the functionality to extract the different components of a command line into the ...
std::vector< mu::value_type > parseExprAsNumericalValues() const
Parses the expression into numerical values, returned as a vector of doubles.
DataAccessParser getExprAsDataObject() const
Parses the expression to a DataAccessParser, which will extract the needed information for the curren...
const std::string & getReturnValueStatement() const
Returns the return value statement for commands with return values.
std::string getFileParameterValue(std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const
Parses the value of the common "file" command line parameter and returns a valid filename.
std::vector< mu::value_type > getParameterValueAsNumericalValue(const std::string &sParameter) const
Parses the selected parameter as (one or more) numerical value(s) and returns them as a vector of dou...
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.
const std::string & getParameterList() const
Returns the parameter list.
std::string getFileParameterValueForSaving(std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const
Parses the value of the common "file" command line parameter and returns a valid filename....
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to 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...
std::string getParameterValue(const std::string &sParameter) const
Simply returns the parameter value or an empty string. Does not do any parsing steps.
@ CMD_PAR
Command-parameter sequence.
@ CMD_DAT_PAR
Command-dataobject-parameter sequence (e.g. fit)
@ CMD_EXPR_set_PAR
Command-expression-set-parameter sequence.
std::string getExprAsFileName(std::string sFileExt, const std::string &sBasePath="") const
Converts the expression to a file name and removes the surrounding quotation marks,...
bool exprContainsDataObjects() const
Simply returns, whether the expression contains any data objects.
IntervalSet parseIntervals(bool bErase=false)
Parses intervals in the parameter list and returns them as a vector. The interval may be deleted,...
bool hasParam(const std::string &sParameter) const
Simple wrapper around findParameter(), if used as a boolean flag.
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Definition: dataaccess.hpp:38
Indices & getIndices()
Returns a reference to the stored indices.
Definition: dataaccess.cpp:196
void evalIndices()
Evaluates open end indices using the identified data object size.
Definition: dataaccess.cpp:141
bool isCluster() const
Determines, whether the data access references a cluster.
Definition: dataaccess.cpp:209
std::string & getDataObject()
Returns a reference to the data object identifier.
Definition: dataaccess.cpp:170
std::string getIndexString()
This member function returns the index definitions as a human-readable string.
Definition: dataaccess.cpp:183
void setLoggingLevel(Logger::LogLevel lvl)
Change the logging level or completely disable the logger.
Definition: logger.cpp:261
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
std::string getProgramPath() const
Definition: filesystem.hpp:127
std::string ValidFolderName(std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
This member function evaluates, whether the passed foldername is a valid foldername.
Definition: filesystem.cpp:369
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.
Definition: filesystem.cpp:424
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
Definition: filesystem.cpp:750
std::string getPath() const
Returns the default path of this FileSystem instance.
Definition: filesystem.cpp:547
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...
Definition: filesystem.cpp:280
void setTokens(std::string _sTokens)
This member function may be used to update the path placeholders of the current FileSystem instance.
Definition: filesystem.cpp:694
void declareFileType(const std::string &sFileType)
Definition: filesystem.hpp:132
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.
Definition: filesystem.cpp:443
This class implements the function definition managing instance.
Definition: define.hpp:74
std::string getFunctionSignature(size_t _i) const
Returns the function signature of the ith defined custom function.
Definition: define.cpp:983
void setTableList(const std::string &sTableList)
Sets the internal table list. This list is used to avoid redefinition of an already existing table as...
Definition: define.hpp:148
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.
Definition: define.cpp:655
bool undefineFunc(const std::string &sFunc)
This function removes a previously defined function from the internal memory.
Definition: define.cpp:772
std::string getComment(size_t _i) const
Returns the comment of the ith defined function.
Definition: define.cpp:1021
bool isDefined(const std::string &sFunc)
This method checks, whether the passed function is already defined.
Definition: define.cpp:625
bool load(const Settings &_option, bool bAutoLoad=false)
This function loads previously saved function definitions to memory.
Definition: define.cpp:1104
bool save(const Settings &_option)
This function saves the function definitions to the definition file.
Definition: define.cpp:1056
std::string getNamesOfDefinedFunctions() const
Returns a list of the names of the custom defined functions.
Definition: define.hpp:127
std::string getImplementation(size_t _i) const
Returns the implementation of the ith defined custom function.
Definition: define.cpp:1002
size_t getDefinedFunctions() const
Returns the number of defined functions.
Definition: define.cpp:950
std::string YES() const
Definition: language.hpp:197
std::vector< std::string > getList(const std::string &sMessageScheme) const
This member function returns a vector of language strings matching to the passed identifier containin...
Definition: language.cpp:349
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 ...
Definition: language.cpp:292
@ LVL_INFO
Definition: logger.hpp:54
@ LVL_DEBUG
Definition: logger.hpp:53
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
Definition: memory.hpp:68
Memory * extractRange(const VectorIndex &_vLine, const VectorIndex &_vCol) const
This member function extracts a range of this table and returns it as a new Memory instance.
Definition: memory.cpp:723
This class represents the central memory managing instance. It will handle all tables and clusters,...
std::string matchTableAsParameter(const std::string &sExpression, char cFollowing=' ')
void removeData(bool bAutoSave=false)
Removes the "data()" table, if it is available.
bool smooth(const std::string &_sCache, const VectorIndex &_vLine, const VectorIndex &_vCol, const NumeRe::FilterSettings &_settings, AppDir Direction=ALL)
bool saveToCacheFile()
This member function saves the contents of this class to the cache file so that they may be restored ...
bool getSaveStatus() const
Returns, whether there's at least a single table in memory, which has not been saved yet.
virtual void melt(Memory *_mem, const std::string &sTable, bool overrideTarget=false) override
This member function either combines the contents of the passed Memory instance with an existing one ...
void deleteBulk(const std::string &_sCache, int i1, int i2, int j1=0, int j2=0)
int getLines(StringView sTable, bool _bFull=false) const
const std::map< std::string, std::pair< size_t, size_t > > & getTableMap() const
bool isEmpty(const std::string &sTable) const
bool isTable(const std::string &sTable) const
This member function returns, whether the passed table name corresponds to a known table.
void setUserdefinedFuncs(const std::string &sUserFuncs)
void swapTables(std::string sTable1, std::string sTable2)
bool deleteTable(const std::string &sCache)
This member function removes the selected table.
NumeRe::Table extractTable(const std::string &_sTable, const VectorIndex &lines=VectorIndex(0, VectorIndex::OPEN_END), const VectorIndex &cols=VectorIndex(0, VectorIndex::OPEN_END))
bool retouch(const std::string &_sCache, const VectorIndex &_vLine, const VectorIndex &_vCol, AppDir Direction=ALL)
bool resample(const std::string &_sCache, const VectorIndex &_vLine, const VectorIndex &_vCol, std::pair< size_t, size_t > samples, AppDir Direction=ALL, std::string sFilter="lanczos3")
void importTable(NumeRe::Table _table, const std::string &_sTable, const VectorIndex &lines=VectorIndex(0, VectorIndex::OPEN_END), const VectorIndex &cols=VectorIndex(0, VectorIndex::OPEN_END))
bool containsTables(const std::string &sExpression)
This member function detects, whether a table is used in the current expression.
bool isValid() const
Evaluates, whether there's at least a single non-empty table.
void setSaveStatus(bool _bIsSaved)
Changes the save status of all tables in memory.
bool addTable(const std::string &sCache, const Settings &_option)
This member function creates a new table. It is checked, whether its name is valid and not already us...
void renameTable(const std::string &sCache, const std::string &sNewName, bool bForceRenaming=false)
Memory * getTable(const std::string &sTable)
This member function returns a pointer to an existing Memory instance representing the selected table...
std::string getTableNames() const
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
int getSize(int _nLayer) const
int getCols(StringView sTable, bool _bFull=false) const
int getColElements(const VectorIndex &cols, const std::string &_sTable) const
Returns the maximal number of elements in the selected column range.
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
Definition: cluster.hpp:325
std::string getString(size_t i) const
This member function returns the data of the i-th cluster item in memory as a string.
Definition: cluster.cpp:745
void setDouble(size_t i, const mu::value_type &value)
This member function assigns a value as data for the i-th cluster item in memory. The type of the i-t...
Definition: cluster.cpp:561
mu::value_type getDouble(size_t i) const
This member function returns the data of the i-th cluster item in memory as a value.
Definition: cluster.cpp:541
unsigned short getType(size_t i) const
This member function returns the type of the i-th cluster item in the internal memory buffer.
Definition: cluster.cpp:524
bool containsClusters(const std::string &sCmdLine) const
This member function detects, whether any cluster is used in the current expression.
Definition: cluster.cpp:1989
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Definition: cluster.cpp:2077
Cluster & newCluster(const std::string &sCluster)
This member function creates a new cluster from the passed cluster identifier and returns a reference...
Definition: cluster.cpp:2139
const std::map< std::string, Cluster > & getClusterMap() const
Definition: cluster.hpp:475
void clearAllClusters()
Clear all clusters currently in memory.
Definition: cluster.cpp:2229
void set(size_t row, size_t col, T val)
Definition: container.hpp:197
std::string getDataFileName(const std::string &sTable) const
This member function will return the file name of the selected table. Will default to the table name.
std::string getOutputFileName() const
This member function will return the output file name, which was used for saving the last table.
void setbLoadEmptyColsInNextFile(bool _bLoadEmptyCols)
Set, whether empty columns shall be loaded in the next file.
FileHeaderInfo openFile(std::string _sFile, bool loadToCache=false, bool overrideTarget=false, int _nHeadline=0, const std::string &sTargetTable="")
This member function loads the contents of the selected file to a new Memory class instance....
bool saveFile(const std::string &sTable, std::string _sFileName, unsigned short nPrecision=7)
This member function wraps the saving functionality of the Memory class. The passed filename is evalu...
void setSavePath(const std::string &_sPath)
This function may be used to update the target saving path of this class.
void setbLoadEmptyCols(bool _bLoadEmptyCols)
Set, whether empty columns shall be loaded.
void setPrefix(const std::string &_sPrefix)
This function is used to set a file prefix for the saving file name.
std::string generateFileName(const std::string &sExtension=".ndat")
This member function creates a file name from the file prefix and the time stamp.
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
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...
void getStringValues(std::string &sLine)
This public member function resolves all string variable occurences and replaces them with their valu...
const std::map< std::string, std::string > & getStringVars() const
This data container is a copy- efficient table to interchange data between Kernel and GUI.
Definition: table.hpp:87
bool isEmpty() const
Return, whether the table is empty.
Definition: table.cpp:668
void setActive(bool active)
Definition: debugger.hpp:105
This class provides the interface to the core of NumeRe. It provides all functionalities,...
Definition: kernel.hpp:97
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
void setAns(NumeRe::Cluster *ans)
Definition: kernel.hpp:276
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
Definition: kernel.cpp:3621
Script & getScript()
Definition: kernel.hpp:311
void closeWindows(int type)
This member function informs the GUI to close all windows of the selected type. Use 0 or WT_ALL to cl...
Definition: kernel.cpp:3590
static NumeRe::Table getTable()
This member function is used by the kernel to be notified when the user finished the table edit proce...
Definition: kernel.cpp:3299
PlotData & getPlottingData()
Definition: kernel.hpp:301
Output & getOutput()
Definition: kernel.hpp:306
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...
Definition: kernel.cpp:2683
mu::Parser & getParser()
Definition: kernel.hpp:281
NumeReDebugger & getDebugger()
Definition: kernel.hpp:326
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
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...
Definition: kernel.cpp:2636
static void clcTerminal()
Clear the terminal.
Definition: kernel.cpp:3543
static void showTable(NumeRe::Table _table, std::string __name, bool openeditable=false)
This member function passes a table to the GUI to be displayed in the table viewer....
Definition: kernel.cpp:3191
void displaySplash()
This function displays the intro text.
Definition: kernel.cpp:2265
FileSystem & getFileSystem()
Definition: kernel.hpp:258
static void showStringTable(NumeRe::Container< std::string > _stringtable, std::string __name, bool openeditable=false)
This member function passes a string table to the GUI to be displayed in the table viewer.
Definition: kernel.cpp:3230
FunctionDefinitionManager & getDefinitions()
Definition: kernel.hpp:291
Procedure & getProcedureInterpreter()
Definition: kernel.hpp:316
static void gotoLine(const std::string &sFile, unsigned int nLine=0)
This member function handles opening files and jumping to lines as requested by the kernel.
Definition: kernel.cpp:3098
static int nOpenFileFlag
Definition: kernel.hpp:194
static void issueWarning(std::string sWarningMessage)
This static function may be used to issue a warning to the user. The warning will be printed by the t...
Definition: kernel.cpp:2833
static bool GetAsyncCancelState()
This function is used by the kernel to get informed, when the user pressed ESC or used other means of...
Definition: kernel.cpp:3703
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
Definition: kernel.cpp:3671
Settings & getSettings()
Definition: kernel.hpp:296
static bool modifiedSettings
Definition: kernel.hpp:197
bool solve(const std::string &sCmd)
Definition: odesolver.cpp:94
void setCompact(bool _bCompact)
Definition: output.cpp:141
std::string getPackageName(unsigned int i=0) const
Returns the plugin name of the ith plugin.
Definition: plugin.hpp:241
std::string getPackageDescription(unsigned int i=0) const
Returns the description of the ith plugin.
Definition: plugin.hpp:288
std::string getPluginCommandSignature(unsigned int i=0) const
Returns the plugin command signature of the ith plugin.
Definition: plugin.hpp:225
std::string getPackageLicense(unsigned int i=0) const
Returns the license information of the ith plugin.
Definition: plugin.hpp:304
std::string getPackageVersion(unsigned int i=0) const
Returns the version number string of the ith plugin.
Definition: plugin.hpp:257
unsigned int getPackageCount() const
Returns the number of installed plugins.
Definition: plugin.hpp:146
std::string getPackageAuthor(unsigned int i=0) const
Returns the author of the ith plugin.
Definition: plugin.hpp:272
std::string getPluginCommand(unsigned int i=0) const
Returns the plugin command of the ith plugin.
Definition: plugin.hpp:209
This class contains all the plot settings usable by the plotting algorithm.
Definition: plotdata.hpp:42
void setFont(const std::string &Font)
Definition: plotdata.hpp:254
void setParams(const std::string &__sCmd, int nType=ALL)
Identifies parameters and values in the passed parameter string and updates the selected type of the ...
Definition: plotdata.cpp:233
std::string getParams(bool asstr=false) const
Return the internal plotting parameters as a human-readable string. Can be converted to an internal s...
Definition: plotdata.cpp:2084
This class implements the logic to evaluate complex procedures, which may be called recursively.
Definition: procedure.hpp:56
bool isOpen() const
Definition: script.hpp:101
void openScript(std::string &_sScriptFileName)
This member function opens the script with the passed file name.
Definition: script.cpp:67
void setInstallProcedures(bool _bInstall=true)
Definition: script.hpp:96
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
bool createCompactTables() const
Returns, whether tables shall be displayed in a more compact way (does nothing in the external table ...
Definition: settings.hpp:913
std::map< std::string, SettingsValue > & getSettings()
Returns a reference to the internal map of setting values.
Definition: settings.hpp:748
std::string getLoadPath() const
Returns the current loading path.
Definition: settings.hpp:1038
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
Definition: settings.hpp:1140
bool executeEnabled() const
Returns, whether the user enabled the execute command.
Definition: settings.hpp:1181
std::string getWorkPath() const
Returns the current working path (connected to the <wp> token).
Definition: settings.hpp:1020
bool isDeveloperMode() const
Returns, whether the developer mode is currently enabled.
Definition: settings.hpp:892
std::string getSavePath() const
Returns the current saving path.
Definition: settings.hpp:1029
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
Definition: settings.hpp:1000
std::string getTokenPaths() const
Returns a semicolon-separated list of the current defined path placeholders and their values.
Definition: settings.hpp:1122
std::string getProcPath() const
Returns the current procedure root import path.
Definition: settings.hpp:1068
std::string getPlotPath() const
Returns the current plotting path (plot storing location).
Definition: settings.hpp:1048
bool showExtendedFileInfo() const
Returns, whether the file tree or the terminal file explorer shall display extended file information ...
Definition: settings.hpp:966
std::string getExePath() const
Returns the current application root folder path.
Definition: settings.hpp:1010
SettingsValue & getSetting(const std::string &value)
Returns a reference to the setting value, which corresponds to the passed string. Throws an exception...
Definition: settings.hpp:711
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
Definition: settings.hpp:1101
void setDefaultPlotFont(const std::string &plotFont)
Update the default plotting font. This member function evaluates first, whether the selected font act...
Definition: settings.hpp:843
std::string getScriptPath() const
Returns the current script import folder path.
Definition: settings.hpp:1058
bool useDebugger() const
Returns, whether the debugger is currently active.
Definition: settings.hpp:1150
void save(const std::string &_sWhere, bool bMkBackUp=false)
Saves the setting values to the corresponding config file. Does only save the setting values,...
Definition: settings.cpp:187
std::string & stringval()
Returns a reference to a std::string value type setting.
Definition: settings.hpp:590
int getStringSize(unsigned int nCol=std::string::npos) const
unsigned int getStringCols() const
unsigned int getStringElements(unsigned int nCol=std::string::npos) const
std::string readString(unsigned int _nthString=std::string::npos, unsigned int nCol=0)
bool clearStringElements()
bool removeStringElements(unsigned int nCol=0)
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ CANNOT_RETOQUE_CACHE
Definition: error.hpp:80
@ EXECUTE_COMMAND_UNSUCCESSFUL
Definition: error.hpp:102
@ CANNOT_SAVE_CACHE
Definition: error.hpp:81
@ CANNOT_GENERATE_SCRIPT
Definition: error.hpp:67
@ CANNOT_SMOOTH_CACHE
Definition: error.hpp:83
@ CANNOT_DELETE_ELEMENTS
Definition: error.hpp:56
@ CANNOT_GENERATE_FILE
Definition: error.hpp:65
@ TABLE_DOESNT_EXIST
INSERT HERE.
Definition: error.hpp:211
@ CANNOT_COPY_FILE
Definition: error.hpp:55
@ CANNOT_EDIT_FILE_TYPE
Definition: error.hpp:57
@ INVALID_COMMAND
Definition: error.hpp:145
@ CANNOT_READ_FILE
Definition: error.hpp:75
@ CANNOT_SAVE_FILE
Definition: error.hpp:82
@ FILE_NOT_EXIST
Definition: error.hpp:105
@ FUNCTION_ERROR
Definition: error.hpp:110
@ EXECUTE_COMMAND_DISABLED
Definition: error.hpp:101
@ SCRIPT_NOT_EXIST
Definition: error.hpp:204
@ CANNOT_COPY_DATA
Definition: error.hpp:54
@ CANNOT_REGULARIZE_CACHE
Definition: error.hpp:76
@ CANNOT_MOVE_DATA
Definition: error.hpp:68
@ CANNOT_GENERATE_PROCEDURE
Definition: error.hpp:66
@ CANNOT_MOVE_FILE
Definition: error.hpp:69
@ CANNOT_RESAMPLE_CACHE
Definition: error.hpp:79
@ CANNOT_REMOVE_FILE
Definition: error.hpp:78
@ INVALID_INDEX
Definition: error.hpp:129
@ CANNOT_CALL_SCRIPT_RECURSIVELY
Definition: error.hpp:52
@ NO_FILENAME
Definition: error.hpp:169
@ PROCESS_ABORTED_BY_USER
Definition: error.hpp:202
static size_t invalid_position
Definition: error.hpp:235
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
Definition: structures.hpp:614
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
Definition: structures.hpp:712
int & front()
This member function returns a reference to the first index value stored internally.
Definition: structures.hpp:640
const varmap_type & GetVar() const
Return a map containing the used variables only.
const valmap_type & GetConst() const
Return a map containing all parser constants.
static void EnableDebugDump(bool bDumpCmd, bool bDumpStack)
Enable the dumping of bytecode amd stack content on the console.
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
Mathematical expressions parser.
Definition: muParser.h:51
bool findZeroes(CommandLineParser &cmdParser)
This function is a wrapper to the actual zeros localisation function localizeZero() further below.
void urlExecute(CommandLineParser &cmdParser)
This function implements the url command providing an interface to http(s) and (s)ftp URLs.
bool writeAudioFile(CommandLineParser &cmdParser)
This function creates a WAVE file from the selected data set.
bool shortTimeFourierAnalysis(CommandLineParser &cmdParser)
This function performs the short-time fourier analysis on the passed data set.
bool integrate2d(CommandLineParser &cmdParser)
Calculate the integral of a function in two dimensions.
void rotateTable(CommandLineParser &cmdParser)
This function rotates a table, an image or a datagrid around a specified angle.
bool analyzePulse(CommandLineParser &cmdParser)
This function performs a pulse analysis on the selected data set.
bool createDatagrid(CommandLineParser &cmdParser)
This function calculates a datagrid from passed functions or (x-y-z) data values.
bool readAudioFile(CommandLineParser &cmdParser)
Reads either the audio file meta information or the whole audio file to memory.
bool fastWaveletTransform(CommandLineParser &cmdParser)
This function calculates the fast wavelet transform of the passed data set.
void boneDetection(CommandLineParser &cmdParser)
This function is the implementation of the detect command.
bool differentiate(CommandLineParser &cmdParser)
Calculate the numerical differential of the passed expression or data set.
bool findExtrema(CommandLineParser &cmdParser)
This function is a wrapper to the actual extrema localisation function localizeExtremum() further bel...
bool seekInAudioFile(CommandLineParser &cmdParser)
Seek a position in an audiofile and extract a length of samples from it.
void taylor(CommandLineParser &cmdParser)
This function approximates the passed expression using Taylor's method.
bool calculateSplines(CommandLineParser &cmdParser)
This function approximates the passed data set using cubic splines.
bool regularizeDataSet(CommandLineParser &cmdParser)
This function regularizes the samples of a defined x-y-data array such that DeltaX is equal for every...
bool integrate(CommandLineParser &cmdParser)
Calculate the integral of a function or a data set in a single dimension.
void particleSwarmOptimizer(CommandLineParser &cmdParser)
This function implements a particle swarm optimizer in up to four dimensions (depending on the number...
bool evalPoints(CommandLineParser &cmdParser)
This function samples a defined expression in an array of discrete values.
bool fastFourierTransform(CommandLineParser &cmdParser)
This function calculates the fast fourier transform of the passed data set.
bool fitDataSet(std::string &sCmd, mu::Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
Definition: fitting.cpp:73
static CommandReturnValues cmd_save(string &sCmd)
This static function implements the "save" command.
static CommandReturnValues cmd_redefine(string &sCmd)
This static function implements the "redefine" command.
static CommandReturnValues cmd_imread(string &sCmd)
This static function implements the "imread" command.
static CommandReturnValues cmd_include(string &sCmd)
This static function implements the "include" command.
static CommandReturnValues cmd_copy(string &sCmd)
This static function implements the "copy" command.
static CommandReturnValues cmd_print(string &sCmd)
This static function implements the "print" command.
static CommandReturnValues cmd_detect(string &sCmd)
This static function implements the "detect" command.
static void copyDataToTemporaryTable(const string &sCmd, DataAccessParser &_accessParser, MemoryManager &_data, MemoryManager &_cache)
This static function copies the contents of the selected table to the provided temporary Datafile obj...
static CommandReturnValues cmd_integrate(string &sCmd)
This static function implements the "integrate" command.
static CommandReturnValues cmd_stfa(string &sCmd)
This static function implements the "stfa" command.
static string getVarList(const string &sCmd, Parser &_parser, MemoryManager &_data, Settings &_option)
This function returns a list of the current defined variables either as strings or as plain text.
static void listConstants(const Parser &_parser, const Settings &_option)
This function lists all known constants.
CommandReturnValues(* CommandFunc)(string &)
static CommandReturnValues cmd_readline(string &sCmd)
This static function implements the "readline" command.
static CommandReturnValues cmd_clc(string &sCmd)
This static function implements the "clc" command.
static CommandReturnValues cmd_spline(string &sCmd)
This static function implements the "spline" command.
static CommandReturnValues cmd_ifndefined(string &sCmd)
This static function implements the "ifndefined" command.
static CommandReturnValues cmd_rename(string &sCmd)
This static function implements the "rename" command.
static CommandReturnValues cmd_append(string &sCmd)
This static function implements the "append" command.
static std::map< std::string, CommandFunc > getCommandFunctionsWithReturnValues()
This static function returns a map of commands with return values linked to their function implementa...
static bool prepareTemplate(const std::string &sTemplateID, const std::string &sFileName)
Perpares a template based upon the selected template id. The file has to exist.
static CommandReturnValues cmd_odesolve(string &sCmd)
This static function implements the "odesolve" command.
static void listInstalledPlugins(Parser &_parser, MemoryManager &_data, const Settings &_option)
This function lists all declared plugins including their name, their command and their description.
static CommandReturnValues cmd_audioread(string &sCmd)
This static function implements the "audioread" command.
static CommandReturnValues cmd_workpath(string &sCmd)
This static function implements the "workpath" command.
static CommandReturnValues cmd_reload(string &sCmd)
This static function implements the "reload" command.
@ WT_CUSTOM
@ WT_IMAGEVIEWER
@ WT_DOCVIEWER
@ WT_GRAPH
@ WT_TABLEVIEWER
@ WT_ALL
static CommandReturnValues cmd_hist(string &sCmd)
This static function implements the "hist" command.
static CommandReturnValues cmd_write(string &sCmd)
This static function implements the "write" command.
static CommandReturnValues cmd_taylor(string &sCmd)
This static function implements the "taylor" command.
static CommandReturnValues cmd_seek(string &sCmd)
This static function implements the "seek" command.
static CommandReturnValues cmd_find(string &sCmd)
This static function implements the "find" command.
static CommandReturnValues cmd_random(string &sCmd)
This static function implements the "random" command.
static CommandReturnValues cmd_fwt(string &sCmd)
This static function implements the "fwt" command.
static CommandReturnValues cmd_zeroes(string &sCmd)
This static function implements the "zeroes" command.
static CommandReturnValues cmd_swap(string &sCmd)
This static function implements the "swap" command.
mglGraph _fontData
Definition: kernel.cpp:40
static CommandReturnValues cmd_plotting(string &sCmd)
This static function implements all plotting commands.
static CommandReturnValues cmd_execute(string &sCmd)
This static function implements the "execute" command.
static bool listFiles(const string &sCmd, const Settings &_option)
This function handles the display of the contents of the selected folders directly in the terminal.
static CommandReturnValues cmd_audio(string &sCmd)
This static function implements the "audio" command.
static CommandReturnValues cmd_pack(string &sCmd)
This static function implements the "pack" command.
static CommandReturnValues saveDataObject(string &sCmd)
This static function handles the saving and exporting of data into files (internally,...
static CommandReturnValues cmd_help(string &sCmd)
This static function implements the "help" command.
static CommandReturnValues cmd_list(string &sCmd)
This static function implements the "list" command.
static CommandReturnValues cmd_stats(string &sCmd)
This static function implements the "stats" command.
static size_t findSettingOption(const std::string &sCmd, const std::string &sOption)
This static function is used to detect a setting option independent on a leading dash character in fr...
static std::map< std::string, CommandFunc > getCommandFunctions()
This static function returns a map of commands linked to their function implementation.
static CommandReturnValues cmd_unpack(string &sCmd)
This static function implements the "unpack" command.
static void listDefinitions(const FunctionDefinitionManager &_functions, const Settings &_option)
This function lists all custom defined functions.
static CommandReturnValues cmd_regularize(string &sCmd)
This static function implements the "regularize" command.
static CommandReturnValues cmd_load(string &sCmd)
This static function implements the "load" command.
static CommandReturnValues cmd_diff(string &sCmd)
This static function implements the "diff" command.
static CommandReturnValues cmd_progress(string &sCmd)
This static function implements the "progress" command.
static CommandReturnValues cmd_hline(string &sCmd)
This static function implements the "hline" command.
static bool newObject(string &sCmd, Parser &_parser, MemoryManager &_data, Settings &_option)
This function creates new objects: files, directories, procedures and tables.
static CommandReturnValues cmd_fit(string &sCmd)
This static function implements the "fit" and "fitw" commands.
static CommandReturnValues cmd_new(string &sCmd)
This static function implements the "new" command.
static CommandReturnValues cmd_rotate(string &sCmd)
This static function implements all "*rot" commands.
static bool confirmOperation(const std::string &sMessage)
Performs the operation confirmation loop, if the user did not supply the ignore command line option.
static CommandReturnValues cmd_resample(string &sCmd)
This static function implements the "resample" command.
static void listCommands(const Settings &_option)
This function lists all defined commands.
static CommandReturnValues cmd_matop(string &sCmd)
This static function implements the "matop" command.
static bool executeCommand(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This static function implements the possibility to call the Windows shell directly from the code.
static CommandReturnValues cmd_define(string &sCmd)
This static function implements the "define" command.
static CommandReturnValues cmd_datagrid(string &sCmd)
This static function implements the "datagrid" command.
static CommandReturnValues cmd_install(string &sCmd)
This static function implements the "install" command.
static CommandReturnValues cmd_smooth(string &sCmd)
This static function implements the "smooth" command.
static CommandReturnValues cmd_edit(string &sCmd)
This static function implements the "edit" command.
static CommandReturnValues cmd_credits(string &sCmd)
This static function implements the "credits" command.
static CommandReturnValues cmd_read(string &sCmd)
This static function implements the "read" command.
static CommandReturnValues cmd_sort(string &sCmd)
This static function implements the "sort" command.
static bool undefineFunctions(string sFunctionList, FunctionDefinitionManager &_functions, const Settings &_option)
This static function handles the undefinition process of custom defined functions.
static bool editObject(string &sCmd, Parser &_parser, MemoryManager &_data, Settings &_option)
This function opens the object in the editor to edit its contents.
static CommandReturnValues cmd_remove(string &sCmd)
This static function implements the "remove" command.
static void printUnits(const string &sUnit, const string &sDesc, const string &sDim, const string &sValues, unsigned int nWindowsize)
This static function prints the selected unit, its description, its dimension and its value conversio...
static CommandReturnValues cmd_quit(string &sCmd)
This static function implements the "quit" command.
static CommandReturnValues cmd_set(string &sCmd)
This static function implements the "set" command.
static CommandReturnValues swapTables(string &sCmd, MemoryManager &_data, Settings &_option)
This static function handles the swapping of the data of the values of two tables.
string removeQuotationMarks(const string &sString)
This function simply removes the surrounding quotation marks.
void plotTableBySize(std::vector< std::string > lineEntries, std::vector< size_t > lineColSizes)
This function actually plots the table with the desired colun widths. For this all the content to plo...
static CommandReturnValues cmd_delete(string &sCmd)
This static function implements the "delete" command.
static string createListDirectoryHeader(const string &sPathName, const string &sLangString, size_t nWindowLength)
This static function draws the headers for the listed directories.
static CommandReturnValues cmd_warn(string &sCmd)
This static function implements the "warn" command.
static string getPathForSetting(string &sCmd, size_t pos)
This static function extracts the path from the selected parameter. It is only used by cmd_set().
static CommandReturnValues cmd_move(string &sCmd)
This static function implements the "move" command.
static CommandReturnValues cmd_pso(string &sCmd)
This static function implements the interface to the particle swarm optimizer.
static bool listDirectory(const string &sDir, const string &sParams, const Settings &_option)
This function displays the contents of a single directory directly in the terminal.
static void listFunctions(const Settings &_option, const string &sType)
This function lists all known functions in the terminal.
static CommandReturnValues cmd_get(string &sCmd)
This static function implements the "get" command.
std::vector< size_t > calcTableWidth(size_t maxWidth, std::vector< size_t > minDesiredColWidth)
This function returns a vector with column widths for a table, depending on the overall table size an...
static CommandReturnValues cmd_eval(string &sCmd)
This static function implements the "eval" command.
static CommandReturnValues cmd_show(string &sCmd)
This static function implements the "show" command. Editing of tables is not supplied by this functio...
static CommandReturnValues cmd_dialog(string &sCmd)
This static function handles the displaying of user interaction dialogs.
static CommandReturnValues cmd_fft(string &sCmd)
This static function implements the "fft" command.
static CommandReturnValues cmd_undefine(string &sCmd)
This static function implements the "undefine" command.
static std::string getTargetTable(const std::string &sCmd)
Simple handler function for cmd_load.
static void autoSave(MemoryManager &_data, Output &_out, Settings &_option)
This function performs the autosave at the application termination.
static CommandReturnValues cmd_url(string &sCmd)
This static function implements the "url" command.
static CommandReturnValues cmd_extrema(string &sCmd)
This static function implements the "extrema" command.
static void listUnitConversions(const Settings &_option)
This function lists all unit conversions and their result, if applied on 1.
static CommandReturnValues cmd_close(string &sCmd)
This static function implements the "close" command.
static CommandReturnValues cmd_clear(string &sCmd)
This static function implements the "clear" command.
static CommandReturnValues cmd_start(string &sCmd)
This static function implements the "start" command.
static void listLogicalOperators(const Settings &_option)
This function lists all logical expressions.
static CommandReturnValues cmd_window(string &sCmd)
This static function implements the "window" command.
static CommandReturnValues cmd_pulse(string &sCmd)
This static function implements the "pulse" command.
static CommandReturnValues cmd_retouch(string &sCmd)
This static function implements the "retouch" command.
static void listDeclaredVariables(Parser &_parser, const Settings &_option, const MemoryManager &_data)
This function lists all declared variables, which are known by the numerical and the string parser as...
bool isNotEmptyExpression(const string &sExpr)
This function checks, whether the passed expression is non-empty (i.e. it contains more than white sp...
bool isValidIndexSet(const Indices &_idx)
Definition: dataaccess.hpp:81
bool sortData(CommandLineParser &cmdParser)
This function is a wrapper for the corresponding member function of the Datafile object.
Definition: dataops.cpp:933
bool readImage(CommandLineParser &cmdParser)
This function reads image data from an image file and stores it as a cache table.
Definition: dataops.cpp:1234
bool moveData(CommandLineParser &cmdParser)
This function will move the selected part of a data table to a new location.
Definition: dataops.cpp:655
bool CopyData(CommandLineParser &cmdParser)
This function copies whole chunks of data between tables.
Definition: dataops.cpp:620
void load_data(MemoryManager &_data, Settings &_option, Parser &_parser, string sFileName)
This function is a wrapper for the Datafile object. It will simply do the whole UI stuff and let the ...
Definition: dataops.cpp:53
bool deleteCacheEntry(CommandLineParser &cmdParser)
This function removes one or multiple entries in the selected table or cluster.
Definition: dataops.cpp:579
bool readFromFile(CommandLineParser &cmdParser)
This function reads the content of a file as strings and copies them to a temporary string vector var...
Definition: dataops.cpp:1145
Language _lang
Definition: kernel.cpp:39
void clear_cache(MemoryManager &_data, Settings &_option, bool bIgnore)
This function removes all allocated tables and frees the assigned memory.
Definition: dataops.cpp:428
void append_data(CommandLineParser &cmdParser)
This function handles appending data sets to already existing data.
Definition: dataops.cpp:346
bool writeToFile(CommandLineParser &cmdParser)
This function writes the string contents in the command to a file.
Definition: dataops.cpp:998
void show_data(MemoryManager &_data, Output &_out, Settings &_option, const string &_sCache, size_t nPrecision)
This function presents the passed data to the user in a visual way.
Definition: dataops.cpp:281
WindowType
This enumeration defines all terminal- closable window types.
void doc_SearchFct(const std::string &sToLookFor, Settings &_option)
This function provides the logic for searching for entries in the keywords database.
void doc_Help(const std::string &__sTopic, Settings &_option)
This function shows the content of a documentation article based upon the passed topic....
bool generateTemplate(const std::string &sFile, const std::string &sTempl, const std::vector< std::string > &vTokens, Settings &_option)
Definition: fileops.cpp:263
bool removeFile(CommandLineParser &cmdParser)
Removes one or more files from the disk.
Definition: fileops.cpp:37
bool moveOrCopyFiles(CommandLineParser &cmdParser)
Moves or copies files from one location to another. Supports also wildcards and file lists.
Definition: fileops.cpp:98
std::string fromSystemCodePage(std::string)
Transforms the system code page to the internal one.
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
std::string sectionHeadline(const std::string &sString, char cHeadLineSep='-')
This function provides a headline for the "windows" in the console.
Definition: kernel.hpp:458
std::string strfill(const std::string &sString, unsigned int nWidth, char cFill=' ', bool limit=false)
This function fills the passed string up to the width nWidth with the characters cFill....
Definition: kernel.hpp:408
std::string strlfill(const std::string &sString, unsigned int nWidth, char cFill=' ')
This function fills the passed string up to the width nWidth with the characters cFill....
Definition: kernel.hpp:438
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
Definition: tools.cpp:2500
DetachedLogger g_logger
Definition: logger.cpp:23
if(nReturnType==EIGENVALUES)
Definition: matfuncs.hpp:390
bool performMatrixOperation(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
This function is the main interface to the matrix operations.
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
Definition: tools.cpp:414
std::vector< std::string > unpack(const std::string &sArchiveName, const std::string &sTargetPath)
Unpacks an archive file format into its folder structure at the specified location....
Definition: archive.cpp:307
void pack(const std::vector< std::string > &vFileList, const std::string &sTargetFile, Type type)
Pack a set of files or folders into an archive file type with the specified file name....
Definition: archive.cpp:168
@ ARCHIVE_GZ
Definition: archive.hpp:31
@ ARCHIVE_TAR
Definition: archive.hpp:30
@ ARCHIVE_AUTO
Definition: archive.hpp:29
@ ARCHIVE_ZIP
Definition: archive.hpp:33
static const char DATE[]
Definition: version.h:7
static const char MONTH[]
Definition: version.h:8
static const char YEAR[]
Definition: version.h:9
static const char STATUS[]
Definition: version.h:13
Namespace for mathematical applications.
Definition: muParser.cpp:53
bool isnan(const value_type &v)
Definition: muParserDef.h:379
std::map< string_type, value_type > valmap_type
Type used for storing constants.
Definition: muParserDef.h:276
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:273
string promptForUserInput(const string &__sCommand)
This function is invoked, if a prompt operator ("??") was found in a string.
void createPlot(std::string &sCmd, MemoryManager &_data, mu::Parser &_parser, Settings &_option, FunctionDefinitionManager &_functions, PlotData &_pData)
Wrapper function for creating plots. Will create an instance of the Plot class, which will handle the...
Definition: plotting.cpp:113
void plugin_histogram(std::string &sCmd)
This function is the interface to both the 1D and the 2D histogram generation.
void plugin_random(std::string &sCmd)
This function is the implementation of the random command.
std::string plugin_statistics(std::string &sCmd, MemoryManager &_data)
This is the implementation of the stats command.
#define min(a, b)
Definition: resampler.cpp:34
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,...
Definition: tools.cpp:113
#define SETTING_S_PLOTFONT
Definition: settings.hpp:65
#define SETTING_B_LOADEMPTYCOLS
Definition: settings.hpp:38
#define SETTING_S_EXEPATH
Definition: settings.hpp:58
#define SETTING_V_WINDOW_X
Definition: settings.hpp:52
#define SETTING_B_DEVELOPERMODE
Definition: settings.hpp:33
#define SETTING_S_LOADPATH
Definition: settings.hpp:60
#define SETTING_V_WINDOW_Y
Definition: settings.hpp:53
#define SETTING_S_SAVEPATH
Definition: settings.hpp:59
#define SETTING_B_DEFCONTROL
Definition: settings.hpp:44
#define SETTING_S_WORKPATH
Definition: settings.hpp:64
#define SETTING_B_DEBUGGER
Definition: settings.hpp:34
#define SETTING_S_PLOTPATH
Definition: settings.hpp:61
#define SETTING_S_SCRIPTPATH
Definition: settings.hpp:62
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
std::string getNextArgument(std::string &sArgList, bool bCut)
Definition: tools.cpp:2294
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
std::string getTimeStamp(bool bGetStamp)
This function simple returns the current time as a default timestamp.
VectorIndex col
VectorIndex row
size_t size() const
Return the number of intervals.
Definition: interval.cpp:643
Structure for the findCommand function.
unsigned int nPos
std::string sString
This structure wraps all necessary meta information of a single file.
Definition: file.hpp:41
long long int nCols
Definition: file.hpp:47
std::string sTableName
Definition: file.hpp:44
std::string sFileName
Definition: file.hpp:43
long long int nRows
Definition: file.hpp:46
This structure contains the necessary information to create an instance of one of the following filte...
Definition: filtering.hpp:40
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
void addArgumentQuotes(string &sToAdd, const string &sParam)
This function adds quotation marks around the value of the specified parameter.
Definition: tools.cpp:3560
void openExternally(const string &sFile)
Opens a file with the program, which is associated by default within the Windows shell.
Definition: tools.cpp:1375
std::vector< std::string > splitIntoLines(std::string sOutput, size_t lineWidth, bool bAllowDashBreaks, int nFirstIndent, int nIndent)
This function splits a string into multiple lines if the line is longer than the desired line width.
Definition: tools.cpp:2002
Match findCommand(StringView sCmd, const std::string &sCommand)
This function is very important for the command handler.
Definition: tools.cpp:1275
bool containsStrings(const string &sLine)
This function checks, whether the passed expression contains strings or valtostring parser.
Definition: tools.cpp:2470
vector< string > getFileList(const string &sDirectory, const Settings &_option, int nFlags)
This function returns a list of files (including their paths, if nFlags & 1).
Definition: tools.cpp:2853
string getFileInfo(const string &sFileName)
This function opens a NumeRe-Datafile file, reads its header and converts it to a human-readable stri...
Definition: tools.cpp:3446
string getArgAtPos(const string &sCmd, unsigned int nPos, int extraction)
Extracts a options value at the selected position and applies automatic parsing, if necessary.
Definition: tools.cpp:1598
EndlessVector< string > getAllSemiColonSeparatedTokens(string sArgList)
Splits up the complete index list and returns them as an EndlessVector.
Definition: tools.cpp:2403
string extractCommandString(const string &sCmd, const Match &_mMatch)
Extracts the whole command string from a command line (which might contain more than one).
Definition: tools.cpp:1325
std::string LineBreak(std::string sOutput, const Settings &_option, bool bAllowDashBreaks, int nFirstIndent, int nIndent)
This function takes a string, splits it into multiple lines if it is too long and returns the result.
Definition: tools.cpp:2205
bool isDelimiter(char c)
This function determines, if the passed character is a delimiter character.
Definition: tools.cpp:1852
void make_progressBar(int nStep, int nFirstStep, int nFinalStep, const string &sType)
Wrapper for the static member function of the kernel.
Definition: tools.cpp:2425
void make_hline(int nLength=-1)
This function prints a horizontal line to the terminal using either minus or equal signs.
Definition: kernel.cpp:3720
@ ARGEXTRACT_STRIPPED
Definition: tools.hpp:56
void dialogCommand(CommandLineParser &cmdParser)
This function is the actual implementation of the dialog command.
Definition: winlayout.cpp:770
void windowCommand(CommandLineParser &cmdParser)
This function is the actual implementation of the window command.
Definition: winlayout.cpp:572