NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
kernel.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 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
20
21#include "wx/wx.h"
22#include "../gui/terminal/terminal.hpp"
24#include "core/io/logger.hpp"
25
26#define KERNEL_PRINT_SLEEP 2
27#define TERMINAL_FORMAT_FIELD_LENOFFSET 16
28#define DEFAULT_NUM_PRECISION 7
29#define DEFAULT_MINMAX_PRECISION 5
30
31extern const std::string sVersion;
32/* --> STATUS: Versionsname des Programms; Aktuell "Ampere", danach "Angstroem". Ab 1.0 Namen mit "B",
33 * z.B.: Biot(1774), Boltzmann(1844), Becquerel(1852), Bragg(1862), Bohr(1885), Brillouin(1889),
34 * de Broglie(1892, Bose(1894), Bloch(1905), Bethe(1906)) <--
35 * --> de Coulomb(1736), Carnot(1796), P.Curie(1859), M.Curie(1867), A.Compton(1892), Cherenkov(1904),
36 * Casimir(1909), Chandrasekhar(1910), Chamberlain(1920), Cabibbo(1935) <--
37 */
38
40mglGraph _fontData;
41extern value_type vAns;
43__time64_t tTimeZero = _time64(0);
44
45// Initialization of the static member variables
49std::queue<NumeReTask> NumeReKernel::taskQueue;
54unsigned int NumeReKernel::nLastLineLength = 0;
62
63
67NumeReKernel::NumeReKernel() : _option(), _memoryManager(), _parser(), _stringParser(_parser, _memoryManager, _option), _functions(false)
68{
69 sCommandLine.clear();
70 sAnswer.clear();
71 sPlotCompose.clear();
72 kernelInstance = this;
73 _ans = nullptr;
74}
75
76
81{
83 kernelInstance = nullptr;
84}
85
86
95{
96 return _option;
97}
98
99
108{
109 _option.copySettings(_settings);
110 _debugger.setActive(_settings.useDebugger());
111}
112
113
122{
124 {
125 g_logger.info("Autosaving tables.");
127 }
128}
129
130
144void NumeReKernel::StartUp(NumeReTerminal* _parent, const std::string& __sPath, const std::string& sPredefinedFunctions)
145{
146 if (_parent && m_parent == nullptr)
147 m_parent = _parent;
148 //Do some start-up stuff here
149
150 std::string sTime = getTimeStamp(false);
151 std::string sLogFile = "numere.log";
152 std::string sPath = __sPath;
153
154 // Set the functions provided by the syntax object in the parent class
155 _functions.setPredefinedFuncs(sPredefinedFunctions);
157 _script.setPredefinedFuncs(sPredefinedFunctions);
158 _procedure.setPredefinedFuncs(sPredefinedFunctions);
159
160 // Make the path UNIX style
161 while (sPath.find('\\') != std::string::npos)
162 sPath[sPath.find('\\')] = '/';
163
164 // Set the path in the settings object and load the settings
165 // from the config file
167 _option.load(sPath); // Lade Informationen aus einem ini-File
168
169 // Initialize the log file
170 if (_option.useLogFile())
171 {
172 reduceLogFilesize((sPath + "/" + sLogFile).c_str());
173 g_logger.open(sPath + "/" + sLogFile);
174 }
175 else
177
178 g_logger.info("Verifying file system.");
179 // Set the path tokens for all relevant objects
189
190 // Set the current line length
192 refreshTree = false;
193
194 // Set the default paths for all objects
195 _out.setPath(_option.getSavePath(), true, sPath);
197
200 _memoryManager.newCluster("ans").setDouble(0, NAN);
201
204
205 _pData.setPath(_option.getPlotPath(), true, sPath);
207
208 _script.setPath(_option.getScriptPath(), true, sPath);
209 _script.setPath(_option.getScriptPath() + "/packages", true, sPath);
210 _script.setPath(_option.getScriptPath(), false, sPath);
212
213 _procedure.setPath(_option.getProcPath(), true, sPath);
215
216 // Create the default paths, if they are not present
217 _option.setPath(_option.getExePath() + "/docs/plugins", true, sPath);
218 _option.setPath(_option.getExePath() + "/docs", true, sPath);
219 _option.setPath(_option.getExePath() + "/user/lang", true, sPath);
220 _option.setPath(_option.getExePath() + "/user/docs", true, sPath);
221 _option.setPath(_option.getSavePath() + "/docs", true, sPath);
222 _functions.setPath(_option.getExePath(), false, sPath);
223 _fSys.setPath(_option.getExePath(), false, sPath);
224 g_logger.info("File system was verified.");
225
226 // Load the documentation index file
227 g_logger.info("Loading documentation index.");
229
230 // Load the language strings
231 g_logger.info("Loading kernel language files.");
233
234 std::string sCacheFile = _option.getExePath() + "/numere.cache";
235
236 // Load the plugin informations
238 {
239 g_logger.info("Loading plugins.");
243 }
244
245 // Load the function definitions
246 if (_option.controlDefinitions() && fileExists(_option.getExePath() + "\\functions.def"))
247 {
248 g_logger.info("Loading custom function definitions.");
249 _functions.load(_option, true);
250 }
251
252 // Load the binary plot font
253 g_logger.info("Loading plotting font.");
254 _fontData.LoadFont(_option.getDefaultPlotFont().c_str(), (_option.getExePath() + "\\fonts").c_str());
255
256 // Load the autosave file
257 if (fileExists(sCacheFile))
258 {
259 g_logger.info("Loading tables from last session.");
261 }
262
263 // Declare the default variables
264 _parser.DefineVar("ans", &vAns); // Deklariere die spezielle Variable "ans", die stets, das letzte Ergebnis speichert und die vier Standardvariablen
269
270 // Declare the table dimension variables
275
276 // --> VAR-FACTORY Deklarieren (Irgendwo muessen die ganzen Variablen-Werte ja auch gespeichert werden) <--
277 g_logger.debug("Creating variable factory.");
279
280 // Define the operators
281 g_logger.debug("Defining operators.");
283
284 // Define the constants
285 g_logger.debug("Defining constants.");
286 defineConst();
287
288 // Define the functions
289 g_logger.debug("Defining functions.");
291
292 g_logger.info("Kernel ready.");
293}
294
295
304{
305 // --> Syntax fuer die Umrechnungsfunktionen definieren und die zugehoerigen Funktionen deklarieren <--
312
313 // --> Einheitenumrechnungen: Werden aufgerufen durch WERT'EINHEIT <--
341
342 // --> Logisches NICHT <--
345
346 // --> Operatoren <--
351}
352
353
362{
363 // --> Eigene Konstanten <--
364 _parser.DefineConst("_g", 9.80665);
365 _parser.DefineConst("_c", 299792458);
366 _parser.DefineConst("_elek_feldkonst", 8.854187817e-12);
367 _parser.DefineConst("_n_avogadro", 6.02214129e23);
368 _parser.DefineConst("_k_boltz", 1.3806488e-23);
369 _parser.DefineConst("_elem_ladung", 1.602176565e-19);
370 _parser.DefineConst("_h", 6.62606957e-34);
371 _parser.DefineConst("_hbar", 1.054571726e-34);
372 _parser.DefineConst("_m_elektron", 9.10938291e-31);
373 _parser.DefineConst("_m_proton", 1.672621777e-27);
374 _parser.DefineConst("_m_neutron", 1.674927351e-27);
375 _parser.DefineConst("_m_muon", 1.883531475e-28);
376 _parser.DefineConst("_m_tau", 3.16747e-27);
377 _parser.DefineConst("_magn_feldkonst", 1.25663706144e-6);
378 _parser.DefineConst("_m_erde", 5.9726e24);
379 _parser.DefineConst("_m_sonne", 1.9885e30);
380 _parser.DefineConst("_r_erde", 6.378137e6);
381 _parser.DefineConst("_r_sonne", 6.9551e8);
382 _parser.DefineConst("true", 1);
383 _parser.DefineConst("_theta_weinberg", 0.49097621387892);
384 _parser.DefineConst("false", 0);
385 _parser.DefineConst("_2pi", 6.283185307179586476925286766559);
386 _parser.DefineConst("_R", 8.3144622);
387 _parser.DefineConst("_alpha_fs", 7.2973525698E-3);
388 _parser.DefineConst("_mu_bohr", 9.27400968E-24);
389 _parser.DefineConst("_mu_kern", 5.05078353E-27);
390 _parser.DefineConst("_mu_e", -9.284764620e-24);
391 _parser.DefineConst("_mu_n", -9.662365e-27);
392 _parser.DefineConst("_mu_p", 1.4106067873e8);
393 _parser.DefineConst("_m_amu", 1.660538921E-27);
394 _parser.DefineConst("_r_bohr", 5.2917721092E-11);
395 _parser.DefineConst("_G", 6.67384E-11);
396 _parser.DefineConst("_coul_norm", 8987551787.99791145324707);
397 _parser.DefineConst("_stefan_boltzmann", 5.670367e-8);
398 _parser.DefineConst("_wien", 2.8977729e-3);
399 _parser.DefineConst("_rydberg", 1.0973731568508e7);
400 _parser.DefineConst("_hartree", 4.35974465e-18);
401 _parser.DefineConst("_lande_e", -2.00231930436182);
402 _parser.DefineConst("_gamma_e", 1.760859644e11);
403 _parser.DefineConst("_gamma_n", 1.83247172e8);
404 _parser.DefineConst("_gamma_p", 2.6752219e8);
405 _parser.DefineConst("_feigenbaum_delta", 4.66920160910299067185);
406 _parser.DefineConst("_feigenbaum_alpha", 2.50290787509589282228);
407 _parser.DefineConst("nan", NAN);
408 _parser.DefineConst("inf", INFINITY);
409 _parser.DefineConst("void", NAN);
410 _parser.DefineConst("I", mu::value_type(0.0, 1.0));
415}
416
417
426{
427
429 // NOTE:
430 // If multi-argument functions are declared, think of whether
431 // they can be use a column of data sets as their argument list.
432 // If not, then they have to be excluded in the multi-argument
433 // function search in the parser.
435
436 _parser.DefineFun("faculty", parser_Faculty); // faculty(n)
437 _parser.DefineFun("factorial", parser_Faculty); // factorial(n)
438 _parser.DefineFun("dblfacul", parser_doubleFaculty); // dblfacul(n)
439 _parser.DefineFun("dblfact", parser_doubleFaculty); // dblfact(n)
440 _parser.DefineFun("binom", parser_Binom); // binom(Wert1,Wert2)
441 _parser.DefineFun("num", parser_Num); // num(a,b,c,...)
442 _parser.DefineFun("cnt", parser_Cnt); // num(a,b,c,...)
443 _parser.DefineFun("std", parser_Std); // std(a,b,c,...)
444 _parser.DefineFun("prd", parser_product); // prd(a,b,c,...)
445 _parser.DefineFun("round", parser_round); // round(x,n)
446 _parser.DefineFun("radian", parser_toRadian); // radian(alpha)
447 _parser.DefineFun("degree", parser_toDegree); // degree(x)
448 _parser.DefineFun("Y", parser_SphericalHarmonics); // Y(l,m,theta,phi)
449 _parser.DefineFun("imY", parser_imSphericalHarmonics); // imY(l,m,theta,phi)
450 _parser.DefineFun("Z", parser_Zernike); // Z(n,m,rho,phi)
451 _parser.DefineFun("sinc", parser_SinusCardinalis); // sinc(x)
452 _parser.DefineFun("sbessel", parser_SphericalBessel); // sbessel(n,x)
453 _parser.DefineFun("sneumann", parser_SphericalNeumann); // sneumann(n,x)
454 _parser.DefineFun("bessel", parser_RegularCylBessel); // bessel(n,x)
455 _parser.DefineFun("neumann", parser_IrregularCylBessel); // neumann(n,x)
456 _parser.DefineFun("legendre", parser_LegendrePolynomial); // legendre(n,x)
457 _parser.DefineFun("legendre_a", parser_AssociatedLegendrePolynomial); // legendre_a(l,m,x)
458 _parser.DefineFun("laguerre", parser_LaguerrePolynomial); // laguerre(n,x)
459 _parser.DefineFun("laguerre_a", parser_AssociatedLaguerrePolynomial); // laguerre_a(n,k,x)
460 _parser.DefineFun("hermite", parser_HermitePolynomial); // hermite(n,x)
461 _parser.DefineFun("betheweizsaecker", parser_BetheWeizsaecker); // betheweizsaecker(N,Z)
462 _parser.DefineFun("heaviside", parser_Heaviside); // heaviside(x)
463 _parser.DefineFun("phi", parser_phi); // phi(x,y)
464 _parser.DefineFun("theta", parser_theta); // theta(x,y,z)
465 _parser.DefineFun("norm", parser_Norm); // norm(x,y,z,...)
466 _parser.DefineFun("med", parser_Med); // med(x,y,z,...)
467 _parser.DefineFun("pct", parser_Pct); // pct(x,y,z,...)
468 _parser.DefineFun("and", parser_and); // and(x,y,z,...)
469 _parser.DefineFun("or", parser_or); // or(x,y,z,...)
470 _parser.DefineFun("xor", parser_xor); // xor(x,y,z,...)
471 _parser.DefineFun("minpos", parser_MinPos); // minpos(x,y,z,...)
472 _parser.DefineFun("maxpos", parser_MaxPos); // maxpos(x,y,z,...)
473 _parser.DefineFun("polynomial", parser_polynomial); // polynomial(x,a0,a1,a2,a3,...)
474 _parser.DefineFun("perlin", parser_perlin); // perlin(x,y,z,seed,freq,oct,pers)
475 _parser.DefineFun("rand", parser_Random, false); // rand(left,right)
476 _parser.DefineFun("gauss", parser_gRandom, false); // gauss(mean,std)
477 _parser.DefineFun("erf", parser_erf); // erf(x)
478 _parser.DefineFun("erfc", parser_erfc); // erfc(x)
479 _parser.DefineFun("gamma", parser_gamma); // gamma(x)
480 _parser.DefineFun("cmp", parser_compare); // cmp(crit,a,b,c,...,type)
481 _parser.DefineFun("is_string", parser_is_string); // is_string(EXPR)
482 _parser.DefineFun("to_value", parser_Ignore); // to_value(STRING)
483 _parser.DefineFun("time", parser_time, false); // time()
484 _parser.DefineFun("clock", parser_clock, false); // clock()
485 _parser.DefineFun("sleep", parser_sleep, false); // sleep(millisecnds)
486 _parser.DefineFun("version", parser_numereversion); // version()
487 _parser.DefineFun("date", parser_date); // date(TIME,TYPE)
488 _parser.DefineFun("weeknum", parser_weeknum); // date(TIME,TYPE)
489 _parser.DefineFun("is_nan", parser_isnan); // is_nan(x)
490 _parser.DefineFun("range", parser_interval); // range(x,left,right)
491 _parser.DefineFun("Ai", parser_AiryA); // Ai(x)
492 _parser.DefineFun("Bi", parser_AiryB); // Bi(x)
493 _parser.DefineFun("ellipticF", parser_EllipticF); // ellipticF(x,k)
494 _parser.DefineFun("ellipticE", parser_EllipticE); // ellipticE(x,k)
495 _parser.DefineFun("ellipticPi", parser_EllipticP); // ellipticPi(x,n,k)
496 _parser.DefineFun("ellipticD", parser_EllipticD); // ellipticD(x,n,k)
497 _parser.DefineFun("cot", parser_cot); // cot(x)
498 _parser.DefineFun("floor", parser_floor); // floor(x)
499 _parser.DefineFun("roof", parser_roof); // roof(x)
500 _parser.DefineFun("rect", parser_rect); // rect(x,x0,x1)
501 _parser.DefineFun("ivl", parser_ivl); // ivl(x,x0,x1,lb,rb)
502 _parser.DefineFun("student_t", parser_studentFactor); // student_t(number,confidence)
503 _parser.DefineFun("gcd", parser_gcd); // gcd(x,y)
504 _parser.DefineFun("lcm", parser_lcm); // lcm(x,y)
505 _parser.DefineFun("beta", parser_beta); // beta(x,y)
506 _parser.DefineFun("zeta", parser_zeta); // zeta(n)
507 _parser.DefineFun("Cl2", parser_clausen); // Cl2(x)
508 _parser.DefineFun("psi", parser_digamma); // psi(x)
509 _parser.DefineFun("psi_n", parser_polygamma); // psi_n(n,x)
510 _parser.DefineFun("Li2", parser_dilogarithm); // Li2(x)
511 _parser.DefineFun("log_b", parser_log_b); // log_b(b,x)
512 _parser.DefineFun("real", parser_real); // real(x)
513 _parser.DefineFun("imag", parser_imag); // imag(x)
514 _parser.DefineFun("to_rect", parser_polar2rect); // to_rect(x)
515 _parser.DefineFun("to_polar", parser_rect2polar); // to_polar(x)
516 _parser.DefineFun("conj", parser_conj); // conj(x)
517 _parser.DefineFun("complex", parser_complex); // complex(re,im)
518 _parser.DefineFun("sec", parser_sec); // sec(x)
519 _parser.DefineFun("csc", parser_csc); // csc(x)
520 _parser.DefineFun("asec", parser_asec); // asec(x)
521 _parser.DefineFun("acsc", parser_acsc); // acsc(x)
522 _parser.DefineFun("sech", parser_sech); // sech(x)
523 _parser.DefineFun("csch", parser_csch); // csch(x)
524 _parser.DefineFun("asech", parser_asech); // asech(x)
525 _parser.DefineFun("acsch", parser_acsch); // acsch(x)
526
528 // NOTE:
529 // If multi-argument functions are declared, think of whether
530 // they can be use a column of data sets as their argument list.
531 // If not, then they have to be excluded in the multi-argument
532 // function search in the parser.
533 // Multi-args with a limited number of args (like perlin) have to be
534 // excluded always.
536}
537
538
547{
548 // measure the current stack position
549 int stackMeasureVar;
550 baseStackPosition = &stackMeasureVar;
551 g_logger.debug("Base stack address = " + toHexString((int)baseStackPosition));
552}
553
554
564{
565 bWritingTable = true;
566 make_hline(80);
567 printPreFmt("| ");
569 printPreFmt(" |\n");
570 printPreFmt("| Version: " + sVersion + strfill("Build: ", 79 - 22 - sVersion.length()) + AutoVersion::YEAR + "-" + AutoVersion::MONTH + "-" + AutoVersion::DATE + " |\n");
571 printPreFmt("| Copyright (c) 2013-" + std::string(AutoVersion::YEAR) + toSystemCodePage(", Erik A. Hänel et al.") + strfill(toSystemCodePage(_lang.get("MAIN_ABOUT_NBR")), 79 - 48) + " |\n");
572 make_hline(80);
573
574 printPreFmt("|\n");
575
576 if (_option.showGreeting() && fileExists(_option.getExePath() + "\\numere.ini"))
578
579 print(LineBreak(_lang.get("PARSER_INTRO", wxGetUserName().ToStdString()), _option));
580 flush();
581 bWritingTable = false;
582
583}
584
585
601{
602 if (!m_parent)
603 return NUMERE_ERROR;
604
605 std::string sLine_Temp = ""; // Temporaerer String fuer die Eingabe
606 std::string sCache; // Zwischenspeicher fuer die Cache-Koordinaten
607 std::string sKeep = ""; // Zwei '\' am Ende einer Zeile ermoeglichen es, dass die Eingabe auf mehrere Zeilen verteilt wird.
608 std::string sLine = ""; // The actual line
609 std::string sCurrentCommand = "";// The current command
610 std::queue<std::string> emptyQueue;
611 commandQueue.swap(emptyQueue);
612 mu::value_type* v = 0; // Ergebnisarray
613 int& nDebuggerCode = _procedure.getDebuggerCode();
614 int nNum = 0; // Zahl der Ergebnisse in value_type* v
615 nLastStatusVal = -1;
616 nLastLineLength = 0;
617 refreshTree = false;
618
619 // Needed for some handler functions
620 KernelStatus nReturnVal = NUMERE_ERROR;
621
622 // add the passed command to the internal command line (append it, if it's non-empty)
623 sCommandLine += sCommand;
624 if (!sCommandLine.length())
625 return NUMERE_PENDING;
626
627 // clear whitespaces
628 while (sCommandLine.front() == ' ')
629 sCommandLine.erase(0, 1);
630 if (!sCommandLine.length())
631 return NUMERE_PENDING;
632
633 // clear whitespaces
634 while (sCommandLine.back() == ' ')
635 sCommandLine.pop_back();
636
637 // check for the double backslash at the end of the line
638 if (sCommandLine.length() > 2 && sCommandLine.substr(sCommandLine.length() - 2, 2) == "\\\\")
639 {
640 sCommandLine.erase(sCommandLine.length() - 2);
641 return NUMERE_PENDING;
642 }
643
644 // Check for comments
645 size_t nQuotes = 0;
646
647 for (size_t i = 0; i < sCommandLine.length(); i++)
648 {
649 if (sCommandLine[i] == '"' && (!i || sCommandLine[i-1] != '\\'))
650 nQuotes++;
651
652 if (nQuotes % 2)
653 continue;
654
655 if (sCommandLine.substr(i, 2) == "##")
656 {
657 sCommandLine.erase(i);
658 break;
659 }
660
661 if (sCommandLine.substr(i, 2) == "#*")
662 {
663 for (size_t j = i+2; j < sCommandLine.length(); j++)
664 {
665 if (sCommandLine.substr(j, 2) == "*#")
666 {
667 sCommandLine.erase(i, j+2-i);
668 break;
669 }
670
671 if (j+1 == sCommandLine.length())
672 return NUMERE_PENDING;
673 }
674 }
675 }
676
677 // Pass the combined command line to the internal variable and clear the contents of the class
678 // member variable (we don't want to repeat the tasks entered last time)
679 sLine = sCommandLine;
680 sCommandLine.clear();
682 // Remove all temporary clusters defined for
683 // inlined procedures
686 bSupressAnswer = false;
687
688 // set the procedure main path to the desired one. --> check, whether this is necessary here
690 {
693 }
694
695 // Evaluate the passed commands or the contents of the script
696 // This is the actual loop. It will evaluate at least once.
697 do
698 {
699 bSupressAnswer = false;
700 sCache.clear();
702
703 // Reset the parser variable map pointer
706
707 // Try-catch block to handle all the internal exceptions
708 try
709 {
710 // Handle command line sources and validate the input
711 if (!handleCommandLineSource(sLine, sKeep))
712 continue;
713
714 // Search for the "assert" command decoration
715 if (findCommand(sLine, "assert").sString == "assert" && !_procedure.getCurrentBlockDepth())
716 {
718 sLine.erase(findCommand(sLine, "assert").nPos, 6);
719 StripSpaces(sLine);
720 }
721
722 // Get the current command
723 sCurrentCommand = findCommand(sLine).sString;
724
725 // Get the tasks from the command cache or add
726 // the current line to the command cache
727 if (!getLineFromCommandCache(sLine, sCurrentCommand))
728 continue;
729
730 // Eval debugger breakpoints from scripts
731 if ((sLine.substr(0, 2) == "|>" || nDebuggerCode == DEBUGGER_STEP)
732 && _script.isValid()
735 {
736 if (sLine.substr(0, 2) == "|>")
737 sLine.erase(0, 2);
738
739 if (_option.useDebugger() && nDebuggerCode != DEBUGGER_LEAVE)
740 {
741 nDebuggerCode = evalDebuggerBreakPoint(sLine);
742 }
743 }
744
745 // Log the current line
746 g_logger.cmdline(sLine);
747
748 // Handle, whether the pressed the ESC key
750 {
753 }
754 // Done explicitly twice to clear the key cache
755 GetAsyncKeyState(VK_ESCAPE);
756
757 // Get the current command
758 sCurrentCommand = findCommand(sLine).sString;
759
760 // Handle the compose block
761 nReturnVal = NUMERE_ERROR;
762 if (!handleComposeBlock(sLine, sCurrentCommand, nReturnVal))
763 {
764 // returns false either when the loop shall return
765 // or it shall continue
766 if (nReturnVal)
767 return nReturnVal;
768 continue;
769 }
770
771 // Get the current command
772 sCurrentCommand = findCommand(sLine).sString;
773
774 // uninstall the plugin, if desired
775 if (uninstallPlugin(sLine, sCurrentCommand))
776 return NUMERE_DONE_KEYWORD;
777
778 // Handle the writing of procedures
779 nReturnVal = NUMERE_ERROR;
780 if (!handleProcedureWrite(sLine, sCurrentCommand, nReturnVal))
781 {
782 // returns false either when the loop shall return
783 // or it shall continue
784 if (nReturnVal)
785 return nReturnVal;
786 continue;
787 }
788
789 // Handle the "to_cmd()" function
790 handleToCmd(sLine, sCache, sCurrentCommand);
791
792 // Handle procedure calls at this location
793 // Will return false, if the command line was cleared completely
794 if (!evaluateProcedureCalls(sLine))
795 continue;
796
797 // --> Gibt es "??"? Dann rufe die Prompt-Funktion auf <--
798 if (!_procedure.getCurrentBlockDepth() && sLine.find("??") != std::string::npos && sCurrentCommand != "help")
799 sLine = promptForUserInput(sLine);
800
801 // Handle plugin commands
802 // Will return false, if the command line was cleared completely
803 if (!executePlugins(sLine))
804 continue;
805
806 // remove the "explicit" command, which may be used to suppress plugins
807 if (findCommand(sLine, "explicit").sString == "explicit")
808 {
809 sLine.erase(findCommand(sLine, "explicit").nPos, 8);
810 StripSpaces(sLine);
811 }
812
813 /* --> Die Keyword-Suche soll nur funktionieren, wenn keine Schleife eingegeben wird, oder wenn eine
814 * eine Schleife eingegeben wird, dann nur in den wenigen Spezialfaellen, die zum Nachschlagen
815 * eines Keywords noetig sind ("list", "help", "find", etc.) <--
816 */
818 || sCurrentCommand == "help"
819 || sCurrentCommand == "man"
820 || sCurrentCommand == "quit"
821 || sCurrentCommand == "list"
822 || sCurrentCommand == "find"
823 || sCurrentCommand == "search")
824 {
825 //print("Debug: Keywords");
826 switch (commandHandler(sLine))
827 {
828 case NO_COMMAND:
830 break; // Kein Keyword: Mit dem Parser auswerten
831 case COMMAND_PROCESSED: // Keyword: Naechster Schleifendurchlauf!
832 if (!commandQueue.size() && !(_script.isValid() && _script.isOpen()))
833 {
835 {
836 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
838
840 }
841
842 sCommandLine.clear();
843 bCancelSignal = false;
844 return NUMERE_DONE_KEYWORD;
845 }
846 else
847 continue;
848 case NUMERE_QUIT:
849 // --> Sind ungesicherte Daten im Cache? Dann moechte der Nutzer diese vielleicht speichern <--
850 if (!_memoryManager.getSaveStatus()) // MAIN_UNSAVED_CACHE
851 {
852 std::string c = "";
853 print(LineBreak(_lang.get("MAIN_UNSAVED_CACHE"), _option));
854 printPreFmt("|\n|<- ");
856 if (c == _lang.YES())
857 {
858 _memoryManager.saveToCacheFile(); // MAIN_CACHE_SAVED
859 print(LineBreak(_lang.get("MAIN_CACHE_SAVED"), _option));
860 Sleep(500);
861 }
862 else
863 {
865 }
866 }
867 return NUMERE_QUIT; // Keyword "quit"
868 //case 2: return 1; // Keyword "mode"
869 }
870 }
871
872 // Evaluate function calls (only outside the flow control blocks)
874 {
875 if (!_functions.call(sLine))
877 }
878
879 // Handle procedure calls at this location
880 // Will return false, if the command line was cleared completely
881 if (!evaluateProcedureCalls(sLine))
882 continue;
883
884 // --> Nochmals ueberzaehlige Leerzeichen entfernen <--
885 StripSpaces(sLine);
887 {
888 // this is obviously a time consuming task => to be investigated
890 }
891
892 // Handle the flow controls like "if", "while", "for"
893 nReturnVal = NUMERE_ERROR;
894 if (!handleFlowControls(sLine, sCurrentCommand, nReturnVal))
895 {
896 // returns false either when the loop shall return
897 // or it shall continue
898 if (nReturnVal)
899 return nReturnVal;
900 continue;
901 }
902
903 // --> Gibt es "??" ggf. nochmal? Dann rufe die Prompt-Funktion auf <--
904 if (sLine.find("??") != std::string::npos)
905 sLine = promptForUserInput(sLine);
906
907 bool bWriteToCache = false;
908 bool bWriteToCluster = false;
909
910 // Get data elements for the current command line or determine,
911 // if the target value of the current command line is a candidate
912 // for a cluster
914 {
916
917 if (sCache.length() && sCache.find('#') == std::string::npos)
918 bWriteToCache = true;
919 }
920 else if (isClusterCandidate(sLine, sCache))
921 bWriteToCache = true;
922
923 // Remove the definition operator
924 while (sLine.find(":=") != std::string::npos)
925 {
926 sLine.erase(sLine.find(":="), 1);
927 }
928
929 // evaluate strings
930 nReturnVal = NUMERE_ERROR;
931
932 if (!evaluateStrings(sLine, sCache, bWriteToCache, nReturnVal))
933 {
934 // returns false either when the loop shall return
935 // or it shall continue
936 if (nReturnVal)
937 return nReturnVal;
938
939 continue;
940 }
941
942 // --> Wenn die Ergebnisse in den Cache geschrieben werden sollen, bestimme hier die entsprechenden Koordinaten <--
943 Indices _idx;
944
945 if (bWriteToCache)
946 {
947 // Get the indices from the corresponding function
948 getIndices(sCache, _idx, _parser, _memoryManager, _option);
949
950 if (sCache[sCache.find_first_of("({")] == '{')
951 {
952 bWriteToCluster = true;
953 }
954
955 if (!isValidIndexSet(_idx))
956 throw SyntaxError(SyntaxError::INVALID_INDEX, sCache, "", _idx.row.to_string() + "," + _idx.col.to_string());
957
958 if (!bWriteToCluster && _idx.row.isOpenEnd() && _idx.col.isOpenEnd())
959 throw SyntaxError(SyntaxError::NO_MATRIX, sCache, "");
960
961 sCache.erase(sCache.find_first_of("({"));
962 StripSpaces(sCache);
963 }
964
965 // --> Ausdruck an den Parser uebergeben und einmal auswerten <--
966 if (!_parser.IsAlreadyParsed(sLine))
967 _parser.SetExpr(sLine);
968
969 // --> Jetzt weiss der Parser, wie viele Ergebnisse er berechnen muss <--
970 v = _parser.Eval(nNum);
972
973 // Create the answer of the calculation and print it
974 // to the command line, if not suppressed
976
977 if (bWriteToCache)
978 {
979 // Is it a cluster?
980 if (bWriteToCluster)
981 {
982 NumeRe::Cluster& cluster = _memoryManager.getCluster(sCache);
983 cluster.assignResults(_idx, nNum, v);
984 }
985 else
986 _memoryManager.writeToTable(_idx, sCache, v, nNum);
987 }
988 }
989 // This section starts the error handling
991 {
993 // --> Vernuenftig formatierte Fehlermeldungen <--
994 unsigned int nErrorPos = e.GetPos();
996 make_hline();
997 print(toUpperCase(_lang.get("ERR_MUP_HEAD")));
998 make_hline();
999
1000 // --> Eigentliche Fehlermeldung <--
1002 print(LineBreak(_lang.get("ERR_EXPRESSION", maskProcedureSigns(e.GetExpr())), _option, true, 4, 15));
1003
1004 /* --> Ausdruecke, die laenger als 63 Zeichen sind, passen nicht in die Zeile. Wir stellen nur die ersten
1005 * 60 Zeichen gefolgt von "..." dar <--
1006 */
1007 // --> Fehlerhaftes/Unerwartetes Objekt <--
1008 if (e.GetToken().length())
1009 print(toSystemCodePage(_lang.get("ERR_OBJECT", e.GetToken())));
1010
1011 /* --> Position des Fehlers im Ausdruck: Wir stellen um den Fehler nur einen Ausschnitt
1012 * des Ausdrucks in der Laenge von etwa 63 Zeichen dar und markieren die Fehlerposition
1013 * durch ein darunter angezeigten Zirkumflex "^" <--
1014 */
1015 if (nErrorPos < e.GetExpr().length())
1016 {
1017 if (e.GetExpr().length() > 63 && nErrorPos > 31 && nErrorPos < e.GetExpr().length() - 32)
1018 {
1019 printPreFmt("| Position: '..." + e.GetExpr().substr(nErrorPos - 29, 57) + "...'\n");
1021 }
1022 else if (nErrorPos < 32)
1023 {
1024 std::string sErrorExpr = "| Position: '";
1025 if (e.GetExpr().length() > 63)
1026 sErrorExpr += e.GetExpr().substr(0, 60) + "...'";
1027 else
1028 sErrorExpr += e.GetExpr() + "'";
1029 printPreFmt(sErrorExpr + "\n");
1030 printPreFmt(pointToError(nErrorPos + 1));
1031 }
1032 else if (nErrorPos > e.GetExpr().length() - 32)
1033 {
1034 std::string sErrorExpr = "| Position: '";
1035 if (e.GetExpr().length() > 63)
1036 {
1037 printPreFmt(sErrorExpr + "..." + e.GetExpr().substr(e.GetExpr().length() - 60) + "'\n");
1038 printPreFmt(pointToError(65 - (e.GetExpr().length() - nErrorPos) - 2));
1039 }
1040 else
1041 {
1042 printPreFmt(sErrorExpr + e.GetExpr() + "'\n");
1043 printPreFmt(pointToError(nErrorPos));
1044 }
1045 }
1046 }
1047
1049
1050 make_hline();
1051 g_logger.error(toUpperCase(_lang.get("ERR_ERROR")) + ": " + e.GetMsg());
1052
1053
1055 return NUMERE_ERROR;
1056 }
1057 catch (const std::bad_alloc& e)
1058 {
1060 /* --> Das ist die schlimmste aller Exceptions: Fehler bei der Speicherallozierung.
1061 * Leider gibt es bis dato keine Moeglichkeit, diesen wieder zu beheben, also bleibt
1062 * vorerst nichts anderes uebrig, als NumeRe mit terminate() abzuschiessen <--
1063 */
1065 make_hline();
1066 print(toUpperCase(_lang.get("ERR_STD_BA_HEAD")));
1067 make_hline();
1068 print(LineBreak(_lang.get("ERR_STD_BADALLOC", sVersion), _option));
1070
1071 make_hline();
1072 g_logger.error("ERROR: BAD ALLOC");
1074
1075 return NUMERE_ERROR;
1076 }
1077 catch (const std::exception& e)
1078 {
1080 // --> Alle anderen Standard-Exceptions <--
1082 make_hline();
1083 print(toUpperCase(_lang.get("ERR_STD_INTERNAL_HEAD")));
1084 make_hline();
1085 print(LineBreak(std::string(e.what()), _option));
1086 print(LineBreak(_lang.get("ERR_STD_INTERNAL"), _option));
1087
1089
1090 g_logger.error(toUpperCase(_lang.get("ERR_ERROR")) + ": " + e.what());
1091 make_hline();
1093
1094 return NUMERE_ERROR;
1095 }
1096 catch (SyntaxError& e)
1097 {
1100 make_hline();
1101 if (e.errorcode == SyntaxError::PROCESS_ABORTED_BY_USER)
1102 {
1103 print(toUpperCase(_lang.get("ERR_PROCESS_CANCELLED_HEAD")));
1104 make_hline();
1105 print(LineBreak(_lang.get("ERR_NR_3200_0_PROCESS_ABORTED_BY_USER"), _option, false));
1106 //cerr << LineBreak("|-> Siehe auch \"help procedure\"", _option) << endl;
1107
1108 g_logger.warning("Process was cancelled by user");
1109 // --> Wenn ein Script ausgefuehrt wird, lesen wir den Index der letzten eingelesenen Zeile und geben diesen hier aus <--
1110 if (_script.isValid() && _script.isOpen())
1111 {
1112 print(LineBreak(_lang.get("ERR_SCRIPTABORT", toString((int)_script.getCurrentLine())), _option));
1113 // --> Script beenden! Mit einem Fehler ist es unsinnig weiterzurechnen <--
1114 _script.close();
1115 }
1116 }
1117 else
1118 {
1119 print(toUpperCase(_lang.get("ERR_NR_HEAD")));
1120 make_hline();
1121
1122 if (e.getToken().length() && (e.errorcode == SyntaxError::PROCEDURE_THROW || e.errorcode == SyntaxError::LOOP_THROW))
1123 {
1124 print(LineBreak(e.getToken(), _option));
1125 g_logger.error(toUpperCase(_lang.get("ERR_ERROR")) + ": " + e.getToken());
1126 }
1127 else
1128 {
1129 std::string sErrLine_0 = _lang.get("ERR_NR_" + toString((int)e.errorcode) + "_0_*", e.getToken(), toString(e.getIndices()[0]), toString(e.getIndices()[1]), toString(e.getIndices()[2]), toString(e.getIndices()[3]));
1130 std::string sErrLine_1 = _lang.get("ERR_NR_" + toString((int)e.errorcode) + "_1_*", e.getToken(), toString(e.getIndices()[0]), toString(e.getIndices()[1]), toString(e.getIndices()[2]), toString(e.getIndices()[3]));
1131 std::string sErrIDString = _lang.getKey("ERR_NR_" + toString((int)e.errorcode) + "_0_*");
1132
1133 if (sErrLine_0.substr(0, 7) == "ERR_NR_")
1134 {
1135 sErrLine_0 = _lang.get("ERR_GENERIC_0", toString((int)e.errorcode));
1136 sErrLine_1 = _lang.get("ERR_GENERIC_1");
1137 sErrIDString = "ERR_GENERIC";
1138 }
1139 print(LineBreak(sErrLine_0, _option));
1140 print(LineBreak(sErrLine_1, _option));
1141 if (e.getExpr().length())
1142 {
1143 print(LineBreak(_lang.get("ERR_EXPRESSION", maskProcedureSigns(e.getExpr())), _option, true, 4, 15));
1144 if (e.getPosition() != SyntaxError::invalid_position)
1145 {
1146 /* --> Position des Fehlers im Ausdruck: Wir stellen um den Fehler nur einen Ausschnitt
1147 * des Ausdrucks in der Laenge von etwa 63 Zeichen dar und markieren die Fehlerposition
1148 * durch ein darunter angezeigten Zirkumflex "^" <--
1149 */
1150 if (e.getExpr().length() > 63 && e.getPosition() > 31 && e.getPosition() < e.getExpr().length() - 32)
1151 {
1152 printPreFmt("| Position: '..." + e.getExpr().substr(e.getPosition() - 29, 57) + "...'\n");
1154 }
1155 else if (e.getPosition() < 32)
1156 {
1157 std::string sErrorExpr = "| Position: '";
1158 if (e.getExpr().length() > 63)
1159 sErrorExpr += e.getExpr().substr(0, 60) + "...'";
1160 else
1161 sErrorExpr += e.getExpr() + "'";
1162 printPreFmt(sErrorExpr + "\n");
1163 printPreFmt(pointToError(e.getPosition() + 1));
1164 }
1165 else if (e.getPosition() > e.getExpr().length() - 32)
1166 {
1167 std::string sErrorExpr = "| Position: '";
1168 if (e.getExpr().length() > 63)
1169 {
1170 printPreFmt(sErrorExpr + "..." + e.getExpr().substr(e.getExpr().length() - 60) + "'\n");
1171 printPreFmt(pointToError(65 - (e.getExpr().length() - e.getPosition()) - 2));
1172 }
1173 else
1174 {
1175 printPreFmt(sErrorExpr + e.getExpr() + "'\n");
1176 printPreFmt(pointToError(e.getPosition()));
1177 }
1178 }
1179 }
1180 }
1181
1182 g_logger.error(toUpperCase(_lang.get("ERR_ERROR")) + ": " + sErrIDString);
1183 }
1184 }
1186
1187 make_hline();
1189
1190 return NUMERE_ERROR;
1191 }
1192 catch (...)
1193 {
1194 /* --> Allgemeine Exception abfangen, die nicht durch mu::exception_type oder std::exception
1195 * abgedeckt wird <--
1196 */
1199 make_hline();
1200 print(toUpperCase(_lang.get("ERR_CATCHALL_HEAD")));
1201 make_hline();
1202 print(LineBreak(_lang.get("ERR_CATCHALL"), _option));
1203
1205 make_hline();
1206
1207 g_logger.error("ERROR: UNKNOWN EXCEPTION");
1209
1210 return NUMERE_ERROR;
1211 }
1212
1214
1215 if (_script.wasLastCommand())
1216 {
1217 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
1219
1221
1222 if (!commandQueue.size())
1223 {
1224 bCancelSignal = false;
1225 return NUMERE_DONE_KEYWORD;
1226 }
1227 }
1228 }
1229 while ((_script.isValid() && _script.isOpen()) || commandQueue.size());
1230
1231 bCancelSignal = false;
1232 nDebuggerCode = 0;
1233
1234 if (_script.wasLastCommand())
1235 {
1236 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
1238
1240
1241 return NUMERE_DONE_KEYWORD;
1242 }
1243
1244 if (bSupressAnswer || !sLine.length())
1245 return NUMERE_DONE_KEYWORD;
1246 return NUMERE_DONE;
1247
1248}
1249
1250
1261bool NumeReKernel::handleCommandLineSource(std::string& sLine, std::string& sKeep)
1262{
1263 if (!commandQueue.size())
1264 {
1265 // --> Wenn gerade ein Script aktiv ist, lese dessen naechste Zeile, sonst nehme eine Zeile von std::cin <--
1266 if (_script.isValid() && _script.isOpen())
1267 {
1268 sLine = _script.getNextScriptCommand();
1269 }
1270
1271 // --> Leerzeichen und Tabulatoren entfernen <--
1272 StripSpaces(sLine);
1273 for (unsigned int i = 0; i < sLine.length(); i++)
1274 {
1275 if (sLine[i] == '\t')
1276 sLine[i] = ' ';
1277 }
1278
1279 // --> Keine Laenge? Ignorieren! <--
1280 if (!sLine.length() || sLine[0] == '@')
1281 return false;
1282
1283 // --> Kommando "global" entfernen <--
1284 if (findCommand(sLine).sString == "global")
1285 {
1286 sLine = sLine.substr(findCommand(sLine).nPos + 6);
1287 StripSpaces(sLine);
1288 }
1289
1290 // --> Wenn die Laenge groesser als 2 ist, koennen '\' am Ende sein <--
1291 if (sLine.length() > 2)
1292 {
1293 if (sLine.substr(sLine.length() - 2, 2) == "\\\\")
1294 {
1295 // --> Ergaenze die Eingabe zu sKeep und beginne einen neuen Schleifendurchlauf <--
1296 sKeep += sLine.substr(0, sLine.length() - 2);
1297 return false;
1298 }
1299 }
1300
1301 /* --> Steht etwas in sKeep? Ergaenze die aktuelle Eingabe, weise dies
1302 * wiederum an sLine zu und loesche den Inhalt von sKeep <--
1303 */
1304 if (sKeep.length())
1305 {
1306 sKeep += sLine;
1307 sLine = sKeep;
1308 sKeep = "";
1309 }
1310
1311 // Ensure that the number of parentheses is matching
1312 if (findCommand(sLine).sString != "help"
1313 && findCommand(sLine).sString != "find"
1314 && findCommand(sLine).sString != "search"
1315 && (sLine.find('(') != std::string::npos || sLine.find('{') != std::string::npos))
1316 {
1317 if (!validateParenthesisNumber(sLine))
1318 throw SyntaxError(SyntaxError::UNMATCHED_PARENTHESIS, sLine, sLine.find('('));
1319 }
1320 }
1321 return true;
1322}
1323
1324
1336bool NumeReKernel::getLineFromCommandCache(std::string& sLine, const std::string& sCurrentCommand)
1337{
1338 // Only do something if the command cache is not empty or the current line contains a semicolon
1339 if ((commandQueue.size() || sLine.find(';') != std::string::npos)
1340 && !_procedure.is_writing() && sCurrentCommand != "procedure")
1341 {
1342 if (commandQueue.size())
1343 {
1344 // The command cache is not empty
1345 // Get the next task from the command cache
1346 sLine = commandQueue.front();
1347
1348 if (sLine.back() == ';')
1349 {
1350 sLine.pop_back();
1351 bSupressAnswer = true;
1352 }
1353
1354 commandQueue.pop();
1355 }
1356 else if (sLine.find(';') == sLine.length() - 1)
1357 {
1358 // Only remove the trailing semicolon -> used to suppress the output of the current line
1359 bSupressAnswer = true;
1360 sLine.pop_back();
1361 }
1362 else
1363 {
1364 // Use only the first task from the command line and cache the remaining
1365 // part in the command cache
1367
1368 for (const auto& expr : expressions)
1369 {
1370 commandQueue.push(expr + ";");
1371 }
1372
1373 if (sLine.back() != ';')
1374 commandQueue.back().pop_back();
1375
1376 sLine = commandQueue.front();
1377
1378 if (sLine.back() == ';')
1379 {
1380 sLine.pop_back();
1381 bSupressAnswer = true;
1382 }
1383
1384 commandQueue.pop();
1385 }
1386 }
1387
1388 return sLine.length() != 0;
1389}
1390
1391
1404bool NumeReKernel::handleComposeBlock(std::string& sLine, const std::string& sCurrentCommand, KernelStatus& nReturnVal)
1405{
1406 // Only do something, if the current command contains
1407 // a compose block syntax element
1408 if ((sCurrentCommand == "compose"
1409 || sCurrentCommand == "endcompose"
1410 || sPlotCompose.length())
1412 && sCurrentCommand != "quit"
1413 && sCurrentCommand != "help")
1414 {
1415 if (!sPlotCompose.length() && findCommand(sLine).sString == "compose")
1416 {
1417 // Create a new compose block
1418 sPlotCompose = "plotcompose ";
1419
1420 // Add the multiplot layout, if needed
1421 if (findParameter(sLine, "multiplot", '='))
1422 {
1423 sPlotCompose += "-multiplot=" + getArgAtPos(sLine, findParameter(sLine, "multiplot", '=') + 9) + " <<COMPOSE>> ";
1424 }
1425
1426 // If the block wasn't started from a script, then ask the user
1427 // to complete it
1428 if (!(_script.isValid() && _script.isOpen()) && !commandQueue.size())
1429 {
1431 {
1432 // --> Wenn in "_procedure" geschrieben wird und dabei kein Script ausgefuehrt wird, hebe dies entsprechend hervor <--
1434 if (_procedure.getCurrentBlock() == "IF")
1435 {
1437 printPreFmt("---");
1438 else
1439 printPreFmt("-");
1440 }
1441 else if (_procedure.getCurrentBlock() == "ELSE" && _procedure.getCurrentBlockDepth() > 1)
1442 printPreFmt("-");
1443 else
1444 {
1446 printPreFmt("--");
1447 }
1449 }
1450 else if (_procedure.is_writing())
1451 {
1452 printPreFmt("|PROC> ");
1453 }
1454 else if (!_procedure.is_writing() && sPlotCompose.length())
1455 {
1456 printPreFmt("|COMP> ");
1457 }
1458
1459 // Waiting for input
1460 nReturnVal = NUMERE_PENDING_SPECIAL;
1461 return false;
1462 }
1463 return false;
1464 }
1465 else if (findCommand(sLine).sString == "abort")
1466 {
1467 // Abort the compose block
1468 sPlotCompose = "";
1469 print(LineBreak(_lang.get("PARSER_ABORTED"), _option));
1470 return false;
1471 }
1472 else if (findCommand(sLine).sString != "endcompose")
1473 {
1474 // add a new plotting command
1475 std::string sCommand = findCommand(sLine).sString;
1476 if (sCommand.substr(0, 4) == "plot"
1477 || sCommand.substr(0, 7) == "subplot"
1478 || sCommand.substr(0, 4) == "grad"
1479 || sCommand.substr(0, 4) == "dens"
1480 || sCommand.substr(0, 4) == "draw"
1481 || sCommand.substr(0, 4) == "vect"
1482 || sCommand.substr(0, 4) == "cont"
1483 || sCommand.substr(0, 4) == "surf"
1484 || sCommand.substr(0, 4) == "mesh")
1485 {
1486 sPlotCompose += sLine + " <<COMPOSE>> ";
1487 // If the block wasn't started from a script, then ask the user
1488 // to complete it
1489 if (!(_script.isValid() && _script.isOpen()) && !commandQueue.size())
1490 {
1492 {
1493 // --> Wenn in "_procedure" geschrieben wird und dabei kein Script ausgefuehrt wird, hebe dies entsprechend hervor <--
1495 if (_procedure.getCurrentBlock() == "IF")
1496 {
1498 printPreFmt("---");
1499 else
1500 printPreFmt("-");
1501 }
1502 else if (_procedure.getCurrentBlock() == "ELSE" && _procedure.getCurrentBlockDepth() > 1)
1503 printPreFmt("-");
1504 else
1505 {
1507 printPreFmt("--");
1508 }
1510 }
1511 else if (_procedure.is_writing())
1512 {
1513 printPreFmt("|PROC> ");
1514 }
1515 else if (!_procedure.is_writing() && sPlotCompose.length())
1516 {
1517 printPreFmt("|COMP> ");
1518 }
1519
1520 // Waiting for input
1521 nReturnVal = NUMERE_PENDING_SPECIAL;
1522 return false;
1523 }
1524 }
1525 return false;
1526 }
1527 else
1528 {
1529 // End the current compose block and clear the cache
1530 // "endcompose" is not needed here
1531 sLine = sPlotCompose;
1532 sPlotCompose = "";
1533 }
1534 }
1535 return true;
1536}
1537
1538
1550bool NumeReKernel::handleProcedureWrite(const std::string& sLine, const std::string& sCurrentCommand, KernelStatus& nReturnVal)
1551{
1552 if (_procedure.is_writing() || sCurrentCommand == "procedure")
1553 {
1554 if (!_procedure.writeProcedure(sLine))
1555 print(LineBreak(_lang.get("PARSER_CANNOTCREATEPROC"), _option));
1556
1557 if (!(_script.isValid() && _script.isOpen()) && !commandQueue.size())
1558 {
1560 {
1561 // --> Wenn in "_procedure" geschrieben wird und dabei kein Script ausgefuehrt wird, hebe dies entsprechend hervor <--
1563 if (_procedure.getCurrentBlock() == "IF")
1564 {
1566 printPreFmt("---");
1567 else
1568 printPreFmt("-");
1569 }
1570 else if (_procedure.getCurrentBlock() == "ELSE" && _procedure.getCurrentBlockDepth() > 1)
1571 printPreFmt("-");
1572 else
1573 {
1575 printPreFmt("--");
1576 }
1577
1579 }
1580 else if (_procedure.is_writing())
1581 {
1582 printPreFmt("|PROC> ");
1583 }
1584 else if (!_procedure.is_writing() && sPlotCompose.length())
1585 {
1586 printPreFmt("|COMP> ");
1587 }
1588
1589 nReturnVal = NUMERE_PENDING_SPECIAL;
1590 return false;
1591 }
1592
1593 return false;
1594 }
1595
1596 return true;
1597}
1598
1599
1609bool NumeReKernel::uninstallPlugin(const std::string& sLine, const std::string& sCurrentCommand)
1610{
1611 if (sCurrentCommand == "uninstall")
1612 {
1613 // Ge the plugin name
1614 std::string sPlugin = fromSystemCodePage(getArgAtPos(sLine, findCommand(sLine).nPos + 9));
1615
1616 // Remove the plugin and get the help index ID
1617 sPlugin = _procedure.deletePackage(sPlugin);
1618
1619 if (sPlugin.length())
1620 {
1621 if (sPlugin != "<<NO_HLP_ENTRY>>")
1622 {
1623 while (sPlugin.find(';') != std::string::npos)
1624 sPlugin[sPlugin.find(';')] = ',';
1625
1626 while (sPlugin.length())
1627 {
1628 // Remove the reference from the help index
1630 }
1631 }
1632
1633 print(LineBreak(_lang.get("PARSER_PLUGINDELETED"), _option));
1635 }
1636 else
1637 print(LineBreak(_lang.get("PARSER_PLUGINNOTFOUND"), _option));
1638
1639 return true;
1640 }
1641
1642 return false;
1643}
1644
1645
1657void NumeReKernel::handleToCmd(std::string& sLine, std::string& sCache, std::string& sCurrentCommand)
1658{
1659 // Do only something, if "to_cmd()" is located
1660 if (sLine.find("to_cmd(") != std::string::npos && !_procedure.getCurrentBlockDepth())
1661 {
1662 unsigned int nPos = 0;
1663
1664 // Find all "to_cmd()"'s
1665 while (sLine.find("to_cmd(", nPos) != std::string::npos)
1666 {
1667 nPos = sLine.find("to_cmd(", nPos) + 6;
1668 if (isInQuotes(sLine, nPos))
1669 continue;
1670 unsigned int nParPos = getMatchingParenthesis(sLine.substr(nPos));
1671 if (nParPos == std::string::npos)
1673 std::string sCmdString = sLine.substr(nPos + 1, nParPos - 1);
1674 StripSpaces(sCmdString);
1675
1676 // Evaluate the string part
1677 if (_stringParser.isStringExpression(sCmdString))
1678 {
1679 sCmdString += " -nq";
1680 NumeReKernel::getInstance()->getStringParser().evalAndFormat(sCmdString, sCache, true);
1681 sCache = "";
1682 }
1683 sLine = sLine.substr(0, nPos - 6) + sCmdString + sLine.substr(nPos + nParPos + 1);
1684 nPos -= 5;
1685 }
1686
1687 // Get the current command
1688 sCurrentCommand = findCommand(sLine).sString;
1689 }
1690}
1691
1692
1703{
1704 // Only if there's a candidate for a procedure
1705 if (sLine.find('$') != std::string::npos && sLine.find('(', sLine.find('$')) != std::string::npos && !_procedure.getCurrentBlockDepth())
1706 {
1707 unsigned int nPos = 0;
1708 int nProc = 0;
1709
1710 // Find all procedures
1711 while (sLine.find('$', nPos) != std::string::npos && sLine.find('(', sLine.find('$', nPos)) != std::string::npos)
1712 {
1713 unsigned int nParPos = 0;
1714 nPos = sLine.find('$', nPos) + 1;
1715
1716 // Get procedure name and argument list
1717 std::string __sName = sLine.substr(nPos, sLine.find('(', nPos) - nPos);
1718 std::string __sVarList = "";
1719
1720 if (sLine[nPos] == '\'')
1721 {
1722 // This is an explicit file name
1723 __sName = sLine.substr(nPos + 1, sLine.find('\'', nPos + 1) - nPos - 1);
1724 nParPos = sLine.find('(', nPos + 1 + __sName.length());
1725 }
1726 else
1727 nParPos = sLine.find('(', nPos);
1728
1729 __sVarList = sLine.substr(nParPos);
1730 nParPos += getMatchingParenthesis(sLine.substr(nParPos));
1731 __sVarList = __sVarList.substr(1, getMatchingParenthesis(__sVarList) - 1);
1732
1733 // Ensure that the procedure is not part of quotation marks
1734 if (!isInQuotes(sLine, nPos, true))
1735 {
1736 // Execute the current procedure
1739 sLine = sLine.substr(0, nPos - 1) + sLine.substr(nParPos + 1);
1740 else
1741 {
1742 _procedure.replaceReturnVal(sLine, _parser, _rTemp, nPos - 1, nParPos + 1,
1743 "_~PROC~[" + _procedure.mangleName(__sName) + "~ROOT_" + toString(nProc) + "]");
1744 nProc++;
1745 }
1746 }
1747
1748 nPos += __sName.length() + __sVarList.length() + 1;
1749 }
1750
1751 StripSpaces(sLine);
1752
1753 if (!sLine.length())
1754 return false;
1755 }
1756 else if (sLine.find('$') != std::string::npos && sLine.find('(', sLine.find('$')) == std::string::npos)
1757 {
1758 // If there's a dollar sign without an opening parenthesis
1759 // ensure that it is enclosed with quotation marks
1760 size_t i = sLine.find('$');
1761
1762 if (findCommand(sLine).sString == "new")
1763 return true;
1764
1765 bool isnotinquotes = true;
1766
1767 // Examine each occurence of a dollar sign
1768 while (isInQuotes(sLine, i))
1769 {
1770 if (sLine.find('$', i + 1) != std::string::npos)
1771 i = sLine.find('$', i + 1);
1772 else
1773 {
1774 isnotinquotes = false;
1775 break;
1776 }
1777 }
1778
1779 // If there's one, which is not in quotation marks
1780 // clear the line and return false
1781 if (isnotinquotes)
1782 {
1783 sLine = "";
1784 return false;
1785 }
1786 }
1787
1788 return true;
1789}
1790
1791
1800bool NumeReKernel::executePlugins(std::string& sLine)
1801{
1802 // If there's a plugin command
1804 {
1805 // Evaluate the command and store procedure name and argument list internally
1806 if (_procedure.evalPluginCmd(sLine))
1807 {
1809
1810 // Call the relevant procedure
1812
1813 // Handle the return values
1814 if (_rTemp.isString() && sLine.find("<<RETURNVAL>>") != std::string::npos)
1815 {
1816 std::string sReturn = "{";
1817 for (unsigned int v = 0; v < _rTemp.vStringVal.size(); v++)
1818 sReturn += _rTemp.vStringVal[v] + ",";
1819 sReturn.back() = '}';
1820 sLine.replace(sLine.find("<<RETURNVAL>>"), 13, sReturn);
1821 }
1822 else if (_rTemp.sReturnedTable.length())
1823 {
1824 std::string sTargetTable = sLine.substr(0, sLine.find("<<RETURNVAL>>"));
1825
1826 if (sTargetTable.find('=') != std::string::npos)
1827 sTargetTable.erase(sTargetTable.find_last_not_of(" ="));
1828
1829 StripSpaces(sTargetTable);
1830
1831 if (sTargetTable.find('(') != std::string::npos
1832 && sTargetTable.substr(sTargetTable.find('(')) == "()"
1833 && sLine.substr(sLine.find("<<RETURNVAL>>")+13).find_first_not_of(" ;") == std::string::npos)
1834 {
1835 sTargetTable.erase(sTargetTable.find('('));
1836
1837 // Copy efficient move operations
1838 if (_rTemp.delayDelete)
1839 {
1840 if (!_memoryManager.isTable(sTargetTable))
1841 _memoryManager.renameTable(_rTemp.sReturnedTable, sTargetTable, true);
1842 else
1843 {
1844 _memoryManager.swapTables(sTargetTable, _rTemp.sReturnedTable);
1846 }
1847 }
1848 else
1849 _memoryManager.copyTable(_rTemp.sReturnedTable, sTargetTable);
1850
1851 sLine = _parser.CreateTempVectorVar(std::vector<mu::value_type>({_memoryManager.getLines(sTargetTable),
1852 _memoryManager.getCols(sTargetTable)}))
1853 + sLine.substr(sLine.find("<<RETURNVAL>>")+13);
1854 }
1855 else
1856 {
1857 sLine.replace(sLine.find("<<RETURNVAL>>"), 13, _memoryManager.isEmpty(_rTemp.sReturnedTable) ? "false" : "true");
1858
1859 if (_rTemp.delayDelete)
1861 }
1862 }
1863 else if (_rTemp.isNumeric() && sLine.find("<<RETURNVAL>>") != std::string::npos)
1864 {
1865 sLine.replace(sLine.find("<<RETURNVAL>>"), 13, "_~PLUGIN[" + _procedure.getPluginProcName() + "~ROOT]");
1866 _parser.SetVectorVar("_~PLUGIN[" + _procedure.getPluginProcName() + "~ROOT]", _rTemp.vNumVal);
1867 }
1869 if (!sLine.length())
1870 return false;
1871 }
1872 else
1873 {
1874 return false;
1875 }
1876 }
1877 return true;
1878}
1879
1880
1891bool NumeReKernel::handleFlowControls(std::string& sLine, const std::string& sCurrentCommand, KernelStatus& nReturnVal)
1892{
1894 {
1895 if (bSupressAnswer)
1896 sLine += ";";
1897 // --> Die Zeile in den Ausdrucksspeicher schreiben, damit sie spaeter wiederholt aufgerufen werden kann <--
1899 /* --> So lange wir im Loop sind und nicht endfor aufgerufen wurde, braucht die Zeile nicht an den Parser
1900 * weitergegeben werden. Wir ignorieren daher den Rest dieser for(;;)-Schleife <--
1901 */
1902 if (!(_script.isValid() && _script.isOpen()) && !commandQueue.size())
1903 {
1905 {
1907 // --> Wenn in "_procedure" geschrieben wird und dabei kein Script ausgefuehrt wird, hebe dies entsprechend hervor <--
1909
1910 if (_procedure.getCurrentBlock() == "IF")
1911 {
1913 printPreFmt("---");
1914 else
1915 printPreFmt("-");
1916 }
1917 else if (_procedure.getCurrentBlock() == "ELSE" && _procedure.getCurrentBlockDepth() > 1)
1918 printPreFmt("-");
1919 else
1920 {
1922 printPreFmt("--");
1923 }
1924
1927 }
1928 else if (_procedure.is_writing())
1929 printPreFmt("|PROC> ");
1930 else if (!_procedure.is_writing() && sPlotCompose.length() )
1931 printPreFmt("|COMP> ");
1932 else
1933 {
1934 if (_script.wasLastCommand())
1935 {
1936 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
1938
1940 }
1941
1942 bCancelSignal = false;
1943 nReturnVal = NUMERE_DONE_KEYWORD;
1944 return false;
1945 }
1946
1947 nReturnVal = NUMERE_PENDING_SPECIAL;
1948 return false;
1949 }
1950 else
1951 {
1952 // A return command occured in an evaluated flow
1953 // control block. If the block was created by a
1954 // script, close the script now.
1956 {
1958 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
1959
1961
1962 nReturnVal = NUMERE_DONE_KEYWORD;
1963 }
1964 }
1965
1966 return false;
1967 }
1968 else if (sCurrentCommand == "return")
1969 {
1970 // The current command is return. If the command
1971 // has been read from a script, close that script
1972 // now
1973 if (_script.isOpen())
1974 {
1976
1977 // Only signal finishing if the script was not
1978 // already re-opened due to chained installations.
1979 if (!_script.isOpen())
1980 {
1981 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
1983 }
1984 else
1985 return true;
1986 }
1987
1988 nReturnVal = NUMERE_DONE_KEYWORD;
1989 return false;
1990 }
1991
1992 return true;
1993}
1994
1995
2007bool NumeReKernel::evaluateStrings(std::string& sLine, std::string& sCache, bool& bWriteToCache, KernelStatus& nReturnVal)
2008{
2010 {
2011 auto retVal = _stringParser.evalAndFormat(sLine, sCache, false, true);
2012
2014 {
2015 if (!commandQueue.size() && !(_script.isValid() && _script.isOpen()))
2016 {
2017 if (_script.wasLastCommand())
2018 {
2019 print(LineBreak(_lang.get("PARSER_SCRIPT_FINISHED", _script.getScriptFileName()), _option, true, 4));
2022 }
2023
2024 sCommandLine.clear();
2025 bCancelSignal = false;
2026 nReturnVal = NUMERE_DONE_KEYWORD;
2027 return false;
2028 }
2029 else
2030 return false;
2031 }
2032
2033#warning NOTE (erik.haenel#3#): This is changed due to double writes in combination with c{nlen+1} = VAL
2034 //if (sCache.length() && _memoryManager.containsTablesOrClusters(sCache) && !bWriteToCache)
2035 // bWriteToCache = true;
2036
2037 if (sCache.length())
2038 {
2039 bWriteToCache = false;
2040 sCache.clear();
2041 }
2042 }
2043
2044 return true;
2045}
2046
2047
2059{
2060 vAns = v[0];
2061 getAns().setDoubleArray(nNum, v);
2062
2063 if (!bSupressAnswer)
2065}
2066
2067
2077{
2078 _pData.setFileName("");
2079
2080 if (commandQueue.size())
2081 {
2082 std::queue<std::string> emptyQueue;
2083 commandQueue.swap(emptyQueue);
2084 }
2086 sCommandLine.clear();
2087 bCancelSignal = false;
2088
2089 // If script is still open, close it
2090 if (_script.isOpen() && _script.isValid())
2091 {
2092 print(LineBreak(_lang.get("ERR_SCRIPTCATCH", toString((int)_script.getCurrentLine())), _option));
2093 _script.close();
2094 }
2095
2096 // Reset the debugger, if not already done
2098 _procedure.reset();
2100}
2101
2102
2111{
2112 NumeRe::DataBase greetingsDB("<>/docs/greetings.ndb");
2113
2114 // Get the greetings from the database file
2115 if (_option.useCustomLangFiles() && fileExists(_option.ValidFileName("<>/user/docs/greetings.ndb", ".ndb")))
2116 greetingsDB.addData("<>/user/docs/greetings.ndb");
2117
2118 if (!greetingsDB.size())
2119 return "|-> ERROR: GREETINGS FILE IS EMPTY.\n";
2120
2121 // return a random greeting
2122 return "|-> \"" + greetingsDB.getElement(greetingsDB.randomRecord(), 0) + "\"\n";
2123}
2124
2125
2134{
2135 if (refreshTree)
2136 {
2137 refreshTree = false;
2139
2140 if (!m_parent)
2141 return;
2142 else
2143 {
2144 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2145
2146 // create the task
2147 NumeReTask task;
2149
2150 taskQueue.push(task);
2151
2153 }
2154
2155 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2156 }
2157}
2158
2159
2170{
2171 if (nLength > 0)
2172 {
2173 g_logger.debug("Changing line length.");
2174 nLINE_LENGTH = nLength;
2176 }
2177}
2178
2179
2188{
2190 {
2191 g_logger.info("Saving latest table changes.");
2193 print(LineBreak(_lang.get("MAIN_CACHE_SAVED"), _option));
2194 Sleep(500);
2195 }
2196
2197}
2198
2199
2211{
2212 // Does not to be carried out twice
2213 if (!m_parent)
2214 return;
2215
2216 saveData();
2218
2219 // --> Konfiguration aus den Objekten zusammenfassen und anschliessend speichern <--
2224
2225 // Save the function definitions
2227 {
2228 g_logger.info("Saving function definitions.");
2230 Sleep(100);
2231 }
2232
2233 g_logger.info("Saving options.");
2234 _option.save(_option.getExePath()); // MAIN_QUIT
2235
2236 // Do some clean-up stuff here
2237 sCommandLine.clear();
2238 sAnswer.clear();
2239 m_parent = nullptr;
2240}
2241
2242
2252{
2253 std::string sAns = sAnswer;
2254 sAnswer.clear();
2255 return sAns;
2256}
2257
2258
2266{
2267 printPreFmt("NUMERE: FRAMEWORK FÜR NUMERISCHE RECHNUNGEN");
2268 return;
2269}
2270
2271
2281std::map<std::string, std::string> NumeReKernel::getPluginLanguageStrings()
2282{
2283 std::map<std::string, std::string> mPluginLangStrings;
2284 for (size_t i = 0; i < _procedure.getPackageCount(); i++)
2285 {
2286 if (!_procedure.getPluginCommand(i).length())
2287 continue;
2288
2289 std::string sDesc = _procedure.getPluginCommandSignature(i) + " - " + _procedure.getPackageDescription(i);
2290 replaceAll(sDesc, "\\\"", "\"");
2291 mPluginLangStrings["PARSERFUNCS_LISTCMD_CMD_" + toUpperCase(_procedure.getPluginCommand(i)) + "_[PLUGINS]"] = sDesc;
2292 }
2293 return mPluginLangStrings;
2294}
2295
2296
2306std::map<std::string, std::string> NumeReKernel::getFunctionLanguageStrings()
2307{
2308 std::map<std::string, std::string> mFunctionLangStrings;
2309 for (size_t i = 0; i < _functions.getDefinedFunctions(); i++)
2310 {
2311 std::string sDesc = _functions.getFunctionSignature(i) + " ARG - " + _functions.getComment(i);
2312 while (sDesc.find("\\\"") != std::string::npos)
2313 sDesc.erase(sDesc.find("\\\""), 1);
2314
2315 mFunctionLangStrings["PARSERFUNCS_LISTFUNC_FUNC_" + toUpperCase(_functions.getFunctionSignature(i).substr(0, _functions.getFunctionSignature(i).rfind('('))) + "_[DEFINE]"] = sDesc;
2316 }
2317 return mFunctionLangStrings;
2318}
2319
2320
2329std::vector<std::string> NumeReKernel::getPluginCommands()
2330{
2331 std::vector<std::string> vPluginCommands;
2332
2333 for (size_t i = 0; i < _procedure.getPackageCount(); i++)
2334 {
2335 if (_procedure.getPluginCommand(i).length())
2336 vPluginCommands.push_back(_procedure.getPluginCommand(i));
2337 }
2338
2339 return vPluginCommands;
2340}
2341
2342
2352{
2353 int nFlag = nOpenFileFlag;
2354 nOpenFileFlag = 0;
2355 return nFlag;
2356}
2357
2358
2368std::string NumeReKernel::getDocumentation(const std::string& sCommand)
2369{
2370 return doc_HelpAsHTML(sCommand, false, _option);
2371}
2372
2373
2383std::vector<std::string> NumeReKernel::getDocIndex()
2384{
2385 return _option.getDocIndex();
2386}
2387
2388
2397static std::string formatByteSize(double bytes)
2398{
2399 if (bytes > 1024.0)
2400 {
2401 bytes /= 1024.0;
2402
2403 if (bytes > 1024.0)
2404 return toString(bytes / 1024.0, 5) + " MBytes";
2405
2406 return toString(bytes, 5) + " KBytes";
2407 }
2408
2409 return toString(bytes, 5) + " Bytes";
2410}
2411
2412
2422{
2423 NumeReVariables vars;
2424 constexpr size_t MAXSTRINGLENGTH = 1024;
2425
2426 mu::varmap_type varmap = _parser.GetVar();
2427 const std::map<std::string, std::string>& stringmap = _stringParser.getStringVars();
2428 std::map<std::string, std::pair<size_t, size_t>> tablemap = _memoryManager.getTableMap();
2429 const std::map<std::string, NumeRe::Cluster>& clustermap = _memoryManager.getClusterMap();
2430 std::string sCurrentLine;
2431
2433 tablemap["string"] = std::pair<size_t,size_t>(-1, -1);
2434
2435 // Gather all (global) numerical variables
2436 for (auto iter = varmap.begin(); iter != varmap.end(); ++iter)
2437 {
2438 if ((iter->first).substr(0, 2) == "_~")
2439 continue;
2440
2441 if ((*iter->second).imag() && !(isnan((*iter->second).real()) && isnan((*iter->second).imag())))
2442 sCurrentLine = iter->first + "\t1 x 1\tcomplex\t" + toString(*iter->second, DEFAULT_NUM_PRECISION*2) + "\t" + iter->first + "\t" + formatByteSize(16);
2443 else
2444 sCurrentLine = iter->first + "\t1 x 1\tdouble\t" + toString(*iter->second, DEFAULT_NUM_PRECISION) + "\t" + iter->first + "\t" + formatByteSize(8);
2445
2446 vars.vVariables.push_back(sCurrentLine);
2447 }
2448
2449 vars.nNumerics = vars.vVariables.size();
2450
2451 // Gather all (global) string variables
2452 for (auto iter = stringmap.begin(); iter != stringmap.end(); ++iter)
2453 {
2454 if ((iter->first).substr(0, 2) == "_~")
2455 continue;
2456
2457 sCurrentLine = iter->first
2458 + "\t1 x 1\tstring\t"
2460 + iter->first + "\t" + formatByteSize(iter->second.length());
2461 vars.vVariables.push_back(sCurrentLine);
2462 }
2463
2464 vars.nStrings = vars.vVariables.size() - vars.nNumerics;
2465
2466 // Gather all (global) tables
2467 for (auto iter = tablemap.begin(); iter != tablemap.end(); ++iter)
2468 {
2469 if ((iter->first).substr(0, 2) == "_~")
2470 continue;
2471
2472 if (iter->first == "string")
2473 {
2474 sCurrentLine = iter->first + "()\t" + toString(_memoryManager.getStringElements()) + " x " + toString(_memoryManager.getStringCols());
2475 sCurrentLine += "\tstring\t{\"" + replaceControlCharacters(_memoryManager.minString()) + "\", ..., \"" + replaceControlCharacters(_memoryManager.maxString()) + "\"}\tstring()\t" + formatByteSize(_memoryManager.getStringSize());
2476 }
2477 else
2478 {
2479 sCurrentLine = iter->first + "()\t" + toString(_memoryManager.getLines(iter->first, false)) + " x " + toString(_memoryManager.getCols(iter->first, false));
2480 sCurrentLine += "\ttable\t{" + toString(_memoryManager.min(iter->first, "")[0], DEFAULT_MINMAX_PRECISION) + ", ..., " + toString(_memoryManager.max(iter->first, "")[0], DEFAULT_MINMAX_PRECISION) + "}\t" + iter->first + "()\t" + formatByteSize(_memoryManager.getBytes(iter->first));
2481 }
2482
2483 vars.vVariables.push_back(sCurrentLine);
2484 }
2485
2486 vars.nTables = vars.vVariables.size() - vars.nNumerics - vars.nStrings;
2487
2488 // Gather all (global) clusters
2489 for (auto iter = clustermap.begin(); iter != clustermap.end(); ++iter)
2490 {
2491 if ((iter->first).substr(0, 2) == "_~")
2492 continue;
2493
2494 sCurrentLine = iter->first + "{}\t" + toString(iter->second.size()) + " x 1";
2495 sCurrentLine += "\tcluster\t" + replaceControlCharacters(iter->second.getShortVectorRepresentation(MAXSTRINGLENGTH))
2496 + "\t" + iter->first + "{}\t" + formatByteSize(iter->second.getBytes());
2497
2498 vars.vVariables.push_back(sCurrentLine);
2499 }
2500
2501 vars.nClusters = vars.vVariables.size() - vars.nNumerics - vars.nStrings - vars.nTables;
2502
2503 return vars;
2504}
2505
2506
2516{
2517 bool modified = modifiedSettings;
2518 modifiedSettings = false;
2519 return modified;
2520}
2521
2522
2531std::vector<std::string> NumeReKernel::getPathSettings() const
2532{
2533 std::vector<std::string> vPaths;
2534 vPaths.push_back(_option.getExePath()); //0
2535 vPaths.push_back(_option.getWorkPath()); //1
2536 vPaths.push_back(_option.getLoadPath()); //2
2537 vPaths.push_back(_option.getSavePath()); //3
2538 vPaths.push_back(_option.getScriptPath()); //4
2539 vPaths.push_back(_option.getProcPath()); //5
2540 vPaths.push_back(_option.getPlotPath()); //6
2541
2542 return vPaths;
2543}
2544
2545
2553const std::vector<Package>& NumeReKernel::getInstalledPackages() const
2554{
2555 return _procedure.getPackages();
2556}
2557
2558
2566std::map<std::string, std::string> NumeReKernel::getMenuMap() const
2567{
2568 return _procedure.getMenuMap();
2569}
2570
2571
2582void NumeReKernel::printResult(const std::string& sLine, bool bScriptRunning)
2583{
2584 if (!m_parent)
2585 return;
2586
2587 if (bSupressAnswer)
2588 return;
2589
2590 {
2591 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2592 m_parent->m_sAnswer += "|-> " + sLine + "\n";
2593
2596 }
2597
2598 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2599 Sleep(5);
2600}
2601
2602
2613std::string NumeReKernel::maskProcedureSigns(std::string sLine)
2614{
2615 for (size_t i = 0; i < sLine.length(); i++)
2616 {
2617 if (sLine[i] == '$' && (!i || sLine[i - 1] != '\\'))
2618 sLine.insert(i, 1, '\\');
2619 }
2620
2621 return sLine;
2622}
2623
2624
2636void NumeReKernel::print(const std::string& __sLine, bool printingEnabled)
2637{
2638 if (!m_parent || !printingEnabled)
2639 return;
2640 else
2641 {
2642 std::string sLine = __sLine;
2643
2645 {
2646 if (sLine.front() == '\r')
2647 sLine.insert(1, 1, (char)15);
2648 else
2649 sLine.insert(0, 1, (char)15);
2650
2651 for (size_t i = 0; i < sLine.length(); i++)
2652 {
2653 if (i < sLine.length() - 2 && sLine[i] == '\n')
2654 sLine.insert(i + 1, 1, (char)15);
2655 }
2656 }
2657
2658 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2659 m_parent->m_sAnswer += "|-> " + sLine + "\n";
2660
2663 }
2664
2665 if (bWritingTable)
2666 return;
2667
2668 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2669 Sleep(KERNEL_PRINT_SLEEP);
2670}
2671
2672
2683void NumeReKernel::printPreFmt(const std::string& __sLine, bool printingEnabled)
2684{
2685 if (!m_parent || !printingEnabled)
2686 return;
2687 else
2688 {
2689 std::string sLine = __sLine;
2690
2692 {
2693 if (sLine.front() == '\r')
2694 sLine.insert(1, 1, (char)15);
2695 else
2696 sLine.insert(0, 1, (char)15);
2697
2698 for (size_t i = 0; i < sLine.length(); i++)
2699 {
2700 if (i < sLine.length() - 2 && sLine[i] == '\n')
2701 sLine.insert(i + 1, 1, (char)15);
2702 }
2703 }
2704
2705 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2706 m_parent->m_sAnswer += sLine;
2707
2710 }
2711
2712 if (bWritingTable)
2713 return;
2714
2715 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2716 Sleep(KERNEL_PRINT_SLEEP);
2717}
2718
2719
2731{
2733
2734 if (nNum > 1)
2735 {
2736 // More than one result
2737 //
2738 // How many fit into one line?
2739 int nLineBreak = numberOfNumbersPerLine();
2740 std::string sAns = "ans = {";
2741
2742 // compose the result
2743 for (int i = 0; i < nNum; ++i)
2744 {
2746
2747 if (i < nNum - 1)
2748 sAns += ", ";
2749
2750 if (nNum + 1 > nLineBreak && !((i + 1) % nLineBreak) && i < nNum - 1)
2751 sAns += "...\n| ";
2752 }
2753
2754 sAns += "}";
2755
2756 // return the composed result
2757 return sAns;
2758 }
2759 else
2760 {
2761 // Only one result
2762 // return the answer
2763 return "ans = " + toString(v[0], _option.getPrecision());
2764 }
2765
2766 // fallback
2767 return "";
2768}
2769
2770
2781std::string NumeReKernel::formatResultOutput(const std::vector<std::string>& vStringResults)
2782{
2784
2785 if (vStringResults.size() > 1)
2786 {
2787 // More than one result
2788 //
2789 // How many fit into one line?
2790 size_t nLineBreak = numberOfNumbersPerLine();
2791 std::string sAns = "ans = {";
2792 size_t nNum = vStringResults.size();
2793
2794 // compose the result
2795 for (size_t i = 0; i < nNum; ++i)
2796 {
2798
2799 if (i < nNum - 1)
2800 sAns += ", ";
2801
2802 if (nNum + 1 > nLineBreak && !((i + 1) % nLineBreak) && i < nNum - 1)
2803 sAns += "...\n| ";
2804 }
2805
2806 sAns += "}";
2807
2808 // return the composed result
2809 return sAns;
2810 }
2811 else
2812 {
2813 // Only one result
2814 // return the answer
2815 return "ans = " + vStringResults.front();
2816 }
2817
2818 // fallback
2819 return "";
2820}
2821
2822
2833void NumeReKernel::issueWarning(std::string sWarningMessage)
2834{
2835 if (!m_parent)
2836 return;
2837 else
2838 {
2839 g_logger.warning(sWarningMessage);
2840 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2841
2842 // Insert warning symbols, if linebreaks are contained in this message
2843 replaceAll(sWarningMessage, "\n", "\n|!> ");
2844
2845 m_parent->m_sAnswer += "\r|!> " + _lang.get("COMMON_WARNING") + ": " + sWarningMessage + "\n";
2846
2849
2850 }
2851
2852 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2853 Sleep(10*KERNEL_PRINT_SLEEP);
2854}
2855
2856
2865void NumeReKernel::failMessage(std::string sFailMessage)
2866{
2867 if (!m_parent)
2868 return;
2869 else
2870 {
2871 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
2872
2873 // Insert warning symbols, if linebreaks are contained in this message
2874 replaceAll(sFailMessage, "\n", "\n|!> ");
2875 replaceAll(sFailMessage, "$", " ");
2876
2877 m_parent->m_sAnswer += "\r|!> " + sFailMessage + "\n";
2878
2881
2882 }
2883
2884 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
2885 Sleep(10*KERNEL_PRINT_SLEEP);
2886}
2887
2888
2898{
2899 /* --> Wir berechnen die Anzahl an Zahlen, die in eine Zeile passen, automatisch <--
2900 * Links: 11 Zeichen bis [; rechts: vier Zeichen mit EOL;
2901 * Fuer jede Zahl: 1 Vorzeichen, 1 Dezimalpunkt, 5 Exponentenstellen, Praezision Ziffern, 1 Komma und 1 Leerstelle
2902 */
2904}
2905
2906
2917{
2919}
2920
2921
2933static std::string drawBar(int nValue, size_t nLength, const std::string& sProgressChar, const std::string& sWhitespaceChar)
2934{
2935 return "[" + strfill(sProgressChar, nValue, sProgressChar[0]) + strfill(sWhitespaceChar, nLength - nValue, sWhitespaceChar[0]) + "]";
2936}
2937
2938
2950void NumeReKernel::progressBar(int nStep, int nFirstStep, int nFinalStep, const std::string& sType)
2951{
2952 int nStatusVal = 0;
2953 const int BARLENGTH = 40;
2954 const double BARDIVISOR = 2.5;
2955 int nDistance = std::abs(nFinalStep - nFirstStep);
2956 double dRatio = std::abs(nStep - nFirstStep) / (double)nDistance; // 0-1
2957
2958 // Calculate the current status val in percent depending
2959 // on the number of elements
2960 if (nDistance < 9999
2961 && dRatio * BARLENGTH > std::abs((nStep - 1 - nFirstStep) / (double)nDistance * BARLENGTH))
2962 nStatusVal = intCast(dRatio * BARLENGTH) * BARDIVISOR;
2963 else if (nDistance >= 9999
2964 && dRatio * 100 > std::abs((nStep - 1 - nFirstStep) / (double)nDistance * 100))
2965 nStatusVal = intCast(dRatio * 100);
2966
2967 // Do not update unless explicit necessary
2968 if (nLastStatusVal >= 0 && nLastStatusVal == nStatusVal && (sType != "cancel" && sType != "bcancel"))
2969 return;
2970
2972
2973 // Show the progress depending on the selected type
2974 if (sType == "std")
2975 {
2976 // Only value
2977 printPreFmt("\r|-> " + _lang.get("COMMON_EVALUATING") + " ... " + toString(nStatusVal) + " %");
2978 nLastLineLength = 14 + _lang.get("COMMON_EVALUATING").length();
2979 }
2980 else if (sType == "cancel")
2981 {
2982 // Cancelation of only value
2983 printPreFmt("\r|-> " + _lang.get("COMMON_EVALUATING") + " ... " + _lang.get("COMMON_CANCEL"));
2984 nStep = nFinalStep;
2985 }
2986 else if (sType == "bar")
2987 {
2988 // Bar with value
2989 printPreFmt("\r|-> " + drawBar(intCast(100*dRatio/BARDIVISOR), BARLENGTH, "#", " ") + " (" + toString(nStatusVal) + " %)");
2990 nLastLineLength = 14 + BARLENGTH;
2991 }
2992 else if (sType == "bcancel")
2993 {
2994 // Cancelation of bar with value
2995 printPreFmt("\r|-> " + drawBar(intCast(nLastStatusVal/BARDIVISOR), BARLENGTH, "#", " ") + " (--- %)");
2996 nFinalStep = nStep;
2997 }
2998 else
2999 {
3000 nLastLineLength = 1;
3001
3002 // Create a buffer
3003 std::string sLine = "\r|";
3004
3005 // This is the custom part, where special tokens define
3006 // values or bars in different shapes and the remaining
3007 // string is printed directly
3008 for (unsigned int i = 0; i < sType.length(); i++)
3009 {
3010 // Standard bar
3011 if (sType.substr(i, 5) == "<bar>")
3012 {
3013 sLine += drawBar(intCast(100*dRatio/BARDIVISOR), BARLENGTH, "#", " ");
3014 i += 4;
3015 nLastLineLength += 2 + BARLENGTH;
3016 continue;
3017 }
3018
3019 // Bar with minus sign as filler
3020 if (sType.substr(i, 5) == "<Bar>")
3021 {
3022 sLine += drawBar(intCast(100*dRatio/BARDIVISOR), BARLENGTH, "#", "-");
3023 i += 4;
3024 nLastLineLength += 2 + BARLENGTH;
3025 continue;
3026 }
3027
3028 // Bar with an equal sign as filler
3029 if (sType.substr(i, 5) == "<BAR>")
3030 {
3031 sLine += drawBar(intCast(100*dRatio/BARDIVISOR), BARLENGTH, "#", "=");
3032 i += 4;
3033 nLastLineLength += 2 + BARLENGTH;
3034 continue;
3035 }
3036
3037 // Only value
3038 if (sType.substr(i, 5) == "<val>")
3039 {
3040 sLine += toString(nStatusVal);
3041 i += 4;
3042 nLastLineLength += 3;
3043 continue;
3044 }
3045
3046 // Value with whitespace as filler
3047 if (sType.substr(i, 5) == "<Val>")
3048 {
3049 sLine += strfill(toString(nStatusVal), 3);
3050 i += 4;
3051 nLastLineLength += 3;
3052 continue;
3053 }
3054
3055 // Value with zeroes as filler
3056 if (sType.substr(i, 5) == "<VAL>")
3057 {
3058 sLine += strfill(toString(nStatusVal), 3, '0');
3059 i += 4;
3060 nLastLineLength += 3;
3061 continue;
3062 }
3063
3064 // Append the remaining part
3065 sLine += sType[i];
3067 }
3068
3069 // Print the line buffer
3070 printPreFmt(sLine);
3071 }
3072
3073 if (nLastStatusVal == 0 || nLastStatusVal != nStatusVal)
3074 nLastStatusVal = nStatusVal;
3075
3076 if (nFinalStep == nStep)
3077 {
3078 printPreFmt("\n");
3079 nLastStatusVal = 0;
3080 nLastLineLength = 0;
3081 }
3082
3083 flush();
3085}
3086
3087
3098void NumeReKernel::gotoLine(const std::string& sFile, unsigned int nLine)
3099{
3100 if (!m_parent)
3101 return;
3102 else
3103 {
3104 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3105
3106 // Create the task
3107 NumeReTask task;
3108 task.sString = sFile;
3109 task.nLine = nLine;
3111
3112 taskQueue.push(task);
3113
3115 }
3116 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3117 Sleep(10);
3118}
3119
3120
3130void NumeReKernel::setDocumentation(const std::string& _sDocumentation)
3131{
3132 if (!m_parent)
3133 return;
3134 else
3135 {
3136 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3137
3138 // Create the task
3139 NumeReTask task;
3140 task.sString = _sDocumentation;
3142
3143 taskQueue.push(task);
3144
3146 }
3147 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3148 Sleep(10);
3149}
3150
3151
3160{
3161 if (!m_parent)
3162 return;
3163 else
3164 {
3165 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3166
3167 // Create the task
3168 NumeReTask task;
3170
3171 taskQueue.push(task);
3172
3174 }
3175 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3176 Sleep(10);
3177}
3178
3179
3191void NumeReKernel::showTable(NumeRe::Table _table, std::string __name, bool openeditable)
3192{
3193 if (!m_parent)
3194 return;
3195 else
3196 {
3197 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3198
3199 // Create the task
3200 NumeReTask task;
3201 task.sString = __name + "()";
3202 task.table = _table;
3203
3204 // Use the corresponding task type
3205 if (openeditable)
3207 else
3209
3210 taskQueue.push(task);
3211
3213 }
3214 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3215 Sleep(10);
3216}
3217
3218
3230void NumeReKernel::showStringTable(NumeRe::Container<std::string> _stringtable, std::string __name, bool openeditable)
3231{
3232 if (!m_parent)
3233 return;
3234 else
3235 {
3236 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3237
3238 // Create the task
3239 NumeReTask task;
3240 task.sString = __name;
3241 task.stringTable = _stringtable;
3242
3243 // Use the corresponding task type
3244 if (openeditable)
3246 else
3248
3249 taskQueue.push(task);
3250
3252 }
3253 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3254 Sleep(10);
3255}
3256
3257
3268{
3269 if (!m_parent)
3270 return;
3271 else
3272 {
3273 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3274
3275 // create the task
3276 NumeReTask task;
3277 task.window = window;
3279
3280 taskQueue.push(task);
3281
3283 }
3284
3285 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3286 Sleep(10);
3287}
3288
3289
3300{
3301 if (!m_parent)
3302 return NumeRe::Table();
3303
3304 bool bHasTable = false;
3305 bool bWasCanceled = false;
3306
3307 do
3308 {
3309 Sleep(100);
3310 {
3311 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3312 bHasTable = m_parent->m_bTableEditAvailable;
3313 bWasCanceled = m_parent->m_bTableEditCanceled;
3316 }
3317 }
3318 while (!bHasTable && !bWasCanceled);
3319
3320 if (bWasCanceled)
3321 return NumeRe::Table();
3322
3323 return table;
3324}
3325
3326
3335NumeRe::Table NumeReKernel::getTable(const std::string& sTableName)
3336{
3337 std::string sSelectedTable = sTableName;
3338
3339 if (sSelectedTable.find("()") != std::string::npos)
3340 sSelectedTable.erase(sSelectedTable.find("()"));
3341
3342 if (!_memoryManager.isTable(sSelectedTable) || !_memoryManager.getCols(sSelectedTable))
3343 return NumeRe::Table();
3344
3345 return _memoryManager.extractTable(sSelectedTable);
3346}
3347
3348
3358{
3359 if (sStringTableName == "string()")
3360 {
3361 // Create the container for the string table
3363
3364 for (size_t j = 0; j < _memoryManager.getStringCols(); j++)
3365 {
3366 for (size_t i = 0; i < _memoryManager.getStringElements(j); i++)
3367 {
3368 stringTable.set(i, j, "\"" + _memoryManager.readString(i, j) + "\"");
3369 }
3370 }
3371
3372 return stringTable;
3373 }
3374 else if (_memoryManager.isCluster(sStringTableName))
3375 {
3376 // Create the container for the selected cluster
3377 NumeRe::Cluster& clust = _memoryManager.getCluster(sStringTableName.substr(0, sStringTableName.find("{}")));
3378 NumeRe::Container<std::string> stringTable(clust.size(), 1);
3379
3380 for (size_t i = 0; i < clust.size(); i++)
3381 {
3383 stringTable.set(i, 0, clust.getString(i));
3384 else
3385 stringTable.set(i, 0, mu::isnan(clust.getDouble(i)) ? "---" : toString(clust.getDouble(i), 5));
3386 }
3387
3388 return stringTable;
3389 }
3390
3392}
3393
3394
3405void NumeReKernel::showDebugEvent(const std::string& sTitle, const std::vector<std::string>& vStacktrace)
3406{
3407 if (!m_parent)
3408 return;
3409 else
3410 {
3411 g_logger.debug("Debugger event.");
3412 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3413
3414 NumeReTask task;
3416
3417 // note the size of the fields
3418 task.vDebugEvent.push_back(sTitle);
3419 task.vDebugEvent.insert(task.vDebugEvent.end(), vStacktrace.begin(), vStacktrace.end());
3420
3421 taskQueue.push(task);
3422
3425 }
3426 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3427 Sleep(10);
3428}
3429
3430
3441{
3442 if (!m_parent)
3443 return DEBUGGER_CONTINUE;
3444
3445 int nDebuggerCode = 0;
3446 g_logger.debug("Waiting for continue.");
3447
3448 // Periodically check for an updated debugger code
3449 do
3450 {
3451 Sleep(100);
3452 {
3453 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3454 nDebuggerCode = m_parent->m_nDebuggerCode;
3456 }
3457 }
3458 while (!nDebuggerCode);
3459
3460 // Return the obtained debugger code
3461 return nDebuggerCode;
3462}
3463
3464
3475int NumeReKernel::evalDebuggerBreakPoint(const std::string& sCurrentCommand)
3476{
3477 if (!getInstance())
3478 return DEBUGGER_CONTINUE;
3479
3480 std::map<std::string, std::pair<std::string, mu::value_type*>> mLocalVars;
3481 std::map<std::string, std::pair<std::string, std::string>> mLocalStrings;
3482 std::map<std::string, std::string> mLocalTables;
3483 std::map<std::string, std::string> mLocalClusters;
3484 std::map<std::string, std::string> mArguments;
3485
3486 // Obtain references to the debugger and the parser
3488 const Parser& _parser = getInstance()->getParser();
3489
3490 // Get the numerical variable map
3491 const mu::varmap_type& varmap = _parser.GetVar();
3492
3493 for (auto iter : varmap)
3494 {
3495 if (iter.first.substr(0, 2) != "_~")
3496 mLocalVars[iter.first] = std::make_pair(iter.first, iter.second);
3497 }
3498
3499 // Get the string variable map
3500 const std::map<std::string, std::string>& sStringMap = getInstance()->getStringParser().getStringVars();
3501
3502 for (const auto& iter : sStringMap)
3503 {
3504 if (iter.first.substr(0, 2) != "_~")
3505 mLocalStrings[iter.first] = std::make_pair(iter.first, iter.second);
3506 }
3507
3508 // Get the table variable map
3509 std::map<std::string, std::pair<size_t,size_t>> tableMap = getInstance()->getMemoryManager().getTableMap();
3510
3511 if (getInstance()->getMemoryManager().getStringElements())
3512 tableMap["string"] = std::pair<size_t, size_t>(-1, -1);
3513
3514 for (const auto& iter : tableMap)
3515 mLocalTables[iter.first] = iter.first;
3516
3517 // Get the cluster mao
3518 const std::map<std::string, NumeRe::Cluster>& clusterMap = getInstance()->getMemoryManager().getClusterMap();
3519
3520 for (const auto& iter : clusterMap)
3521 {
3522 if (iter.first.substr(0, 2) != "_~")
3523 mLocalClusters[iter.first] = iter.first;
3524 }
3525
3526
3527 // Pass the created information to the debugger
3528 _debugger.gatherInformations(mLocalVars, mLocalStrings, mLocalTables, mLocalClusters, mArguments,
3529 sCurrentCommand, getInstance()->getScript().getScriptFileName(), getInstance()->getScript().getCurrentLine()-1);
3530
3531 // Show the breakpoint and wait for the
3532 // user interaction
3533 return _debugger.showBreakPoint();
3534}
3535
3536
3544{
3545 if (!m_parent)
3546 return;
3547 else
3548 {
3549 g_logger.debug("Clearing terminal.");
3550 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3551
3552 // create the task
3553 NumeReTask task;
3555
3556 taskQueue.push(task);
3557
3559 }
3560
3561 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3562 Sleep(10*KERNEL_PRINT_SLEEP);
3563}
3564
3574{
3575 g_logger.debug("Refreshing function tree.");
3576 getInstance()->refreshTree = true;
3577}
3578
3579
3591{
3592 if (!m_parent)
3593 return;
3594 else
3595 {
3596 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3597
3598 // create the task
3599 NumeReTask task;
3601 task.nLine = type;
3602
3603 taskQueue.push(task);
3604
3606 }
3607
3608 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3609 Sleep(KERNEL_PRINT_SLEEP);
3610}
3611
3612
3621void NumeReKernel::getline(std::string& sLine)
3622{
3623 if (!m_parent)
3624 return;
3625
3626 // Inform the terminal that we'd like to get
3627 // a textual input from the user through the
3628 // terminal and that this is not to be noted
3629 // in the history.
3630 {
3631 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3632 bGettingLine = true;
3633 }
3634
3635 bool bgotline = false;
3636
3637 // Check regularily, if the user provided
3638 // some input
3639 do
3640 {
3641 Sleep(100);
3642 {
3643 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3644 bgotline = m_parent->m_bCommandAvailable;
3645 sLine = m_parent->m_sCommandLine;
3647 m_parent->m_sCommandLine.clear();
3648 }
3649 }
3650 while (!bgotline);
3651
3652 // Inform the terminal that we're finished with
3653 // getline()
3654 {
3655 wxCriticalSectionLocker lock(m_parent->m_kernelCS);
3656 bGettingLine = false;
3657 }
3658
3659 StripSpaces(sLine);
3660}
3661
3662
3672{
3674}
3675
3676
3685{
3686 if (!m_parent)
3687 return;
3688
3689 wxQueueEvent(m_parent->GetEventHandler(), new wxThreadEvent());
3690 Sleep(1);
3691}
3692
3693
3704{
3705 bool b = bCancelSignal;
3706 bCancelSignal = false;
3707 return b;
3708}
3709
3710
3720void make_hline(int nLength)
3721{
3722 if (nLength == -1)
3723 NumeReKernel::printPreFmt("\r" + strfill(std::string(1, '='), NumeReKernel::nLINE_LENGTH - 1, '=') + "\n");
3724 else if (nLength < -1)
3725 NumeReKernel::printPreFmt("\r" + strfill(std::string(1, '-'), NumeReKernel::nLINE_LENGTH - 1, '-') + "\n");
3726 else
3727 NumeReKernel::printPreFmt("\r" + strfill(std::string(1, '='), nLength, '=') + "\n");
3728
3729 return;
3730}
3731
3732
CommandReturnValues commandHandler(string &sCmd)
This function is the main command handling function.
Definition: built-in.cpp:42
@ COMMAND_PROCESSED
Definition: built-in.hpp:53
@ COMMAND_HAS_RETURNVALUE
Definition: built-in.hpp:54
@ NO_COMMAND
Definition: built-in.hpp:52
void enable(const std::string &sExpr)
Enables the assertion handler using the passed expression.
Definition: error.cpp:228
void reset()
Resets the assertion handler.
Definition: error.cpp:196
void resetStats()
Resets the internal statistic variables for accumulating the total number of executed and the number ...
Definition: error.cpp:214
void checkAssertion(mu::value_type *v, int nNum)
Checks the return value of a muParser evaluated result.
Definition: error.cpp:244
bool open(const std::string &sLogFile)
Open the log file and push the buffered messages directly to this file.
Definition: logger.cpp:237
void info(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:106
void warning(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:130
void debug(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:94
void error(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:142
void setLoggingLevel(Logger::LogLevel lvl)
Change the logging level or completely disable the logger.
Definition: logger.cpp:261
void cmdline(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:118
void removeFromDocIndex(const std::string &_sID)
This member function removes the index entry passed to the function from the documentation index.
Definition: doc_helper.cpp:531
void createDocumentationIndex(bool bLoadUserLangFiles=true)
This member function loads the index files to memory.
Definition: doc_helper.cpp:456
std::vector< std::string > getDocIndex() const
This member function returns the key list for the documentation index prepared for the corresponding ...
Definition: doc_helper.cpp:646
This class extends the std::vector for endlessness.
Definition: structures.hpp:838
std::string getProgramPath() const
Definition: filesystem.hpp:127
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 createRevisionsFolder()
This member function creates the hidden revisions folders for the version control system.
Definition: filesystem.cpp:532
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
int getCurrentBlockDepth() const
Returns the current block depth while reading a flow control statement to memory.
Definition: flowctrl.cpp:119
bool getReturnSignal() const
Definition: flowctrl.hpp:186
static bool isFlowCtrlStatement(const std::string &sCmd)
This static member function returns whether the passed command is a flow control statement.
Definition: flowctrl.cpp:4726
void setCommand(std::string &__sCmd, int nCurrentLine)
This member function is used to set a command line from the outside into the flow control statement c...
Definition: flowctrl.cpp:1948
std::string getCurrentBlock() const
Definition: flowctrl.hpp:175
void reset()
This function clears the memory of this FlowCtrl object and sets everything back to its original stat...
Definition: flowctrl.cpp:2534
std::string getFunctionSignature(size_t _i) const
Returns the function signature of the ith defined custom function.
Definition: define.cpp:983
void setPredefinedFuncs(const std::string &sPredefined)
This member function updates the internal list of predefined functions. If the list is whitespace-sep...
Definition: define.cpp:1158
std::string getPredefinedFuncs() const
Return a list of the internal defined default functions.
Definition: define.hpp:162
std::string getComment(size_t _i) const
Returns the comment of the ith defined function.
Definition: define.cpp:1021
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
Definition: define.cpp:801
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
size_t getDefinedFunctions() const
Returns the number of defined functions.
Definition: define.cpp:950
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
void addToLanguage(const std::map< std::string, std::string > &_langstrings)
This member function adds the contents of the passed language file into the internal map.
Definition: language.cpp:238
std::string YES() const
Definition: language.hpp:197
void loadStrings(bool bloadUserFiles=true)
This member function loads the language files to the internal map and replaces the named tokens with ...
Definition: language.cpp:164
std::string getKey(const std::string &sMessage) const
This member function searches the internal language map for an identifier, which starts similar with ...
Definition: language.cpp:257
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_DISABLED
Definition: logger.hpp:58
bool saveToCacheFile()
This member function saves the contents of this class to the cache file so that they may be restored ...
mu::value_type tableLinesCount
bool getSaveStatus() const
Returns, whether there's at least a single table in memory, which has not been saved yet.
mu::value_type tableColumnsCount
std::vector< mu::value_type > min(const std::string &sTable, std::string sDir) const
void removeTablesFromMemory()
Removes all tables in memory and re- initializes the MemoryManager with the default table.
void copyTable(const std::string &source, const std::string &target)
Copy one table to another one (and create the missing table automatically, if needed).
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 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))
void setPredefinedFuncs(const std::string &sFuncs)
std::vector< mu::value_type > max(const std::string &sTable, std::string sDir) const
void renameTable(const std::string &sCache, const std::string &sNewName, bool bForceRenaming=false)
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
bool loadFromCacheFile()
This member function wraps the loading of the tables from the cache file. It will automatically detec...
int getBytes(const std::string &sTable) const
int getCols(StringView sTable, bool _bFull=false) const
void setPluginCommands(const std::string &sPluginCmds)
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
Definition: cluster.hpp:325
size_t size() const
This member function returns the size of the internal memory buffer as items.
Definition: cluster.cpp:356
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
void assignResults(Indices _idx, int nNum, mu::value_type *data)
This member function assigns calculation results as data for the cluster items in memory,...
Definition: cluster.cpp:720
void setDoubleArray(const std::vector< mu::value_type > &vVals)
This member function assigns values as data for the all cluster items in memory. The type of the clus...
Definition: cluster.cpp:648
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
void removeTemporaryClusters()
This member function returns all temporary clusters from the internal map. Temporary clusters are ind...
Definition: cluster.cpp:2209
mu::value_type dClusterElementsCount
Definition: cluster.hpp:459
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
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
Definition: cluster.cpp:2041
const std::map< std::string, Cluster > & getClusterMap() const
Definition: cluster.hpp:475
void set(size_t row, size_t col, T val)
Definition: container.hpp:197
This class is an implementation of a database. It will handle the *.ndb data format an provides an in...
Definition: database.hpp:37
std::string getElement(size_t i, size_t j) const
This member function will return the contents of the selected database field, or an empty string,...
Definition: database.cpp:245
size_t size() const
Definition: database.hpp:54
size_t randomRecord() const
This member function can be used to select and random record.
Definition: database.cpp:320
void addData(const std::string &sDataBaseFile)
This member function will use the passed database file name to update its internal contents (i....
Definition: database.cpp:212
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.
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 removeTempStringVectorVars()
This member function removes all temporary string vector variables.
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
This class represents an abstract window handled by the window manager.
void finalize()
Definition: debugger.hpp:71
void gatherInformations(ProcedureVarFactory *_varFactory, const std::string &_sErraticCommand, const std::string &_sErraticModule, unsigned int _nLineNumber)
This member function gathers all information from the current workspace and stores them internally to...
Definition: debugger.cpp:516
int showBreakPoint()
This member function shows the debugger for the current breakpoint and returns the debugger code (i....
Definition: debugger.cpp:158
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
static ProcedureLibrary ProcLibrary
Definition: kernel.hpp:202
static int evalDebuggerBreakPoint(const std::string &sCurrentCommand="")
This member function handles the creation of the debugger information for a script debugger breakpoin...
Definition: kernel.cpp:3475
std::string maskProcedureSigns(std::string sLine)
This member function masks the dollar signs in the strings to avoid that the line breaking functions ...
Definition: kernel.cpp:2613
FunctionDefinitionManager _functions
Definition: kernel.hpp:153
std::map< std::string, std::string > getPluginLanguageStrings()
This member function returns a map of language strings for the installed plugins, which will be used ...
Definition: kernel.cpp:2281
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
NumeReDebugger _debugger
Definition: kernel.hpp:157
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
Definition: kernel.cpp:3621
NumeRe::Cluster * _ans
Definition: kernel.hpp:159
Settings getKernelSettings()
Get the settings available in the Settings class.
Definition: kernel.cpp:94
static bool bSupressAnswer
Definition: kernel.hpp:199
bool handleCommandLineSource(std::string &sLine, std::string &sKeep)
This private member function will handle the command line input source and validate it,...
Definition: kernel.cpp:1261
std::string ReadAnswer()
This member function is a simple wrapper to read the kernel answer and reset it automatically.
Definition: kernel.cpp:2251
bool handleProcedureWrite(const std::string &sLine, const std::string &sCurrentCommand, KernelStatus &nReturnVal)
This private member function will handle the writing of procedure lines to the corresponding file.
Definition: kernel.cpp:1550
static NumeReKernel * kernelInstance
Definition: kernel.hpp:144
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
bool evaluateStrings(std::string &sLine, std::string &sCache, bool &bWriteToCache, KernelStatus &nReturnVal)
This private member function redirects the processing of strings to the string parser.
Definition: kernel.cpp:2007
std::vector< std::string > getDocIndex()
This member function returns the documentation index as a string vector, which can be used to fill th...
Definition: kernel.cpp:2383
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
static bool bGettingLine
Definition: kernel.hpp:200
FileSystem _fSys
Definition: kernel.hpp:147
void defineConst()
This member function declares all numerical constants.
Definition: kernel.cpp:361
PlotData _pData
Definition: kernel.hpp:154
bool uninstallPlugin(const std::string &sLine, const std::string &sCurrentCommand)
This private member function uninstalls a previously installed plugin.
Definition: kernel.cpp:1609
void updateLineLenght(int nLength)
This member function is used to update the internal terminal line length information after the termin...
Definition: kernel.cpp:2169
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
bool SettingsModified()
Returns true, if the user changed any internal settings using the set command.
Definition: kernel.cpp:2515
static std::queue< NumeReTask > taskQueue
Definition: kernel.hpp:190
static int nLastStatusVal
Definition: kernel.hpp:195
std::vector< std::string > getPluginCommands()
This member function is used by the syntax highlighter to hightlight the plugin commands.
Definition: kernel.cpp:2329
static bool bCancelSignal
Definition: kernel.hpp:193
mu::Parser & getParser()
Definition: kernel.hpp:281
void createCalculationAnswer(int nNum, mu::value_type *v)
This private member function will create the answer line for the parser which is then passed to NumeR...
Definition: kernel.cpp:2058
std::string sCommandLine
Definition: kernel.hpp:138
NumeReDebugger & getDebugger()
Definition: kernel.hpp:326
static void failMessage(std::string sFailMessage)
This static function may be used to print a test failure message in the terminal.
Definition: kernel.cpp:2865
void defineFunctions()
This member function declares all mathematical functions.
Definition: kernel.cpp:425
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
bool evaluateProcedureCalls(std::string &sLine)
This private member function will evaluate any calls to procedurs and replace their results in the cu...
Definition: kernel.cpp:1702
static void installationDone()
Notify the GUI that the installation was processed.
Definition: kernel.cpp:3159
bool handleComposeBlock(std::string &sLine, const std::string &sCurrentCommand, KernelStatus &nReturnVal)
This private member function will handle the compose block (i.e. store the different commands and ret...
Definition: kernel.cpp:1404
std::string getGreeting()
Returns a random greeting string, which may be printed to the terminal later.
Definition: kernel.cpp:2110
static int numberOfNumbersPerLine()
This member function returns the count of numbers fitting into a single terminal line depending on it...
Definition: kernel.cpp:2897
static void showDebugEvent(const std::string &sTitle, const std::vector< std::string > &vStacktrace)
This member function passes the debugging information to the GUI to be displayed in the debugger wind...
Definition: kernel.cpp:3405
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
~NumeReKernel()
Destructor of the kernel.
Definition: kernel.cpp:80
@ DEBUGGER_LEAVE
Definition: kernel.hpp:134
@ DEBUGGER_CONTINUE
Definition: kernel.hpp:131
NumeRe::Cluster & getAns()
Definition: kernel.hpp:268
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
std::map< std::string, std::string > getMenuMap() const
Returns the menu map used to construct the package menu.
Definition: kernel.cpp:2566
KernelStatus MainLoop(const std::string &sCommand)
This is the main loop for the core of NumeRe.
Definition: kernel.cpp:600
void checkInternalStates()
Evaluates the internal states, performs necessary actions and resets them.
Definition: kernel.cpp:2133
static void progressBar(int nStep, int nFirstStep, int nFinalStep, const std::string &sType)
This function displays a progress bar constructed from characters in the terminal.
Definition: kernel.cpp:2950
Script _script
Definition: kernel.hpp:155
static bool bErrorNotification
Definition: kernel.hpp:201
std::queue< std::string > commandQueue
Definition: kernel.hpp:141
void StartUp(NumeReTerminal *_parent, const std::string &__sPath, const std::string &sPredefinedFunctions)
This is the kernel "booting" function.
Definition: kernel.cpp:144
MemoryManager _memoryManager
Definition: kernel.hpp:150
void displaySplash()
This function displays the intro text.
Definition: kernel.cpp:2265
std::string sPlotCompose
Definition: kernel.hpp:140
std::string getDocumentation(const std::string &sCommand)
This member function returns the documentation for the passed command string as HTML string prepared ...
Definition: kernel.cpp:2368
Settings _option
Definition: kernel.hpp:148
std::string sAnswer
Definition: kernel.hpp:139
static int nLINE_LENGTH
Definition: kernel.hpp:191
void handleToCmd(std::string &sLine, std::string &sCache, std::string &sCurrentCommand)
This private member function handles the "to_cmd()" function, if it is part of the current command li...
Definition: kernel.cpp:1657
@ NUMERE_CLC_TERMINAL
Definition: kernel.hpp:126
@ NUMERE_EDIT_FILE
Definition: kernel.hpp:115
@ NUMERE_INSTALLATION_DONE
Definition: kernel.hpp:125
@ NUMERE_PENDING_SPECIAL
Definition: kernel.hpp:111
@ NUMERE_QUEUED_COMMAND
Definition: kernel.hpp:114
@ NUMERE_EDIT_TABLE
Definition: kernel.hpp:118
@ NUMERE_PRINTLINE_PREFMT
Definition: kernel.hpp:108
@ NUMERE_PRINTLINE
Definition: kernel.hpp:107
@ NUMERE_STATUSBAR_UPDATE
Definition: kernel.hpp:113
@ NUMERE_ANSWER_READ
Definition: kernel.hpp:121
@ NUMERE_ISSUE_WARNING
Definition: kernel.hpp:109
@ NUMERE_SHOW_WINDOW
Definition: kernel.hpp:122
@ NUMERE_OPEN_DOC
Definition: kernel.hpp:116
@ NUMERE_PENDING
Definition: kernel.hpp:110
@ NUMERE_DEBUG_EVENT
Definition: kernel.hpp:120
@ NUMERE_CLOSE_WINDOWS
Definition: kernel.hpp:124
@ NUMERE_CALC_UPDATE
Definition: kernel.hpp:112
@ NUMERE_SHOW_TABLE
Definition: kernel.hpp:117
@ NUMERE_DONE_KEYWORD
Definition: kernel.hpp:106
@ NUMERE_REFRESH_FUNCTIONTREE
Definition: kernel.hpp:123
@ NUMERE_SHOW_STRING_TABLE
Definition: kernel.hpp:119
void saveData()
This member function performs the autosaving of tables at application shutdown.
Definition: kernel.cpp:2187
static NumeRe::Table table
Definition: kernel.hpp:198
void refreshFunctionTree()
This member function informs the GUI to reload the contents of the function tree as soon as possible.
Definition: kernel.cpp:3573
std::map< std::string, std::string > getFunctionLanguageStrings()
This member function returns a map of language strings for the declared functions,...
Definition: kernel.cpp:2306
void sendErrorNotification()
This member function is used to toggle the error notification status. The error notification is used ...
Definition: kernel.cpp:2916
static void flush()
Inform the terminal to write the current output buffer as soon as possible.
Definition: kernel.cpp:3684
void CloseSession()
This member function shuts the kernel down and terminates the kernel instance. Every call to NumeReKe...
Definition: kernel.cpp:2210
void printResult(const std::string &sLine, bool bScriptRunning)
This member function appends the formatted string to the buffer and informs the terminal that we have...
Definition: kernel.cpp:2582
void resetAfterError()
This private member function will reset the kernel variables after an error had been handled.
Definition: kernel.cpp:2076
static NumeReTerminal * m_parent
Definition: kernel.hpp:189
mu::Parser _parser
Definition: kernel.hpp:151
NumeRe::Container< std::string > getStringTable(const std::string &sStringTableName)
This member function creates the table container for the string table or the clusters.
Definition: kernel.cpp:3357
const std::vector< Package > & getInstalledPackages() const
Returns a vector containing the names and the version info of each installed plugin.
Definition: kernel.cpp:2553
bool handleFlowControls(std::string &sLine, const std::string &sCurrentCommand, KernelStatus &nReturnVal)
This private member function will handle used flow controls.
Definition: kernel.cpp:1891
void printVersionInfo()
This member function prints the version headline and the version information to the console.
Definition: kernel.cpp:563
NumeReKernel()
Constructor of the kernel.
Definition: kernel.cpp:67
NumeReVariables getVariableList()
This member function returns a structure containing all currently declared variables,...
Definition: kernel.cpp:2421
int ReadOpenFileFlag()
This member function returns the mode, how a file shall be opened in the editor, when called by the k...
Definition: kernel.cpp:2351
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
NumeRe::StringParser _stringParser
Definition: kernel.hpp:152
void setKernelSettings(const Settings &_settings)
Update the internal settings.
Definition: kernel.cpp:107
static unsigned int nLastLineLength
Definition: kernel.hpp:196
static bool bWritingTable
Definition: kernel.hpp:192
bool getLineFromCommandCache(std::string &sLine, const std::string &sCurrentCommand)
This private member function returns the current command line from the command cache (i....
Definition: kernel.cpp:1336
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
void initializeStackTracker()
Starts the stack tracker, which will prevent stack overflows.
Definition: kernel.cpp:546
void defineOperators()
This member function declares all numerical operators.
Definition: kernel.cpp:303
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 setDocumentation(const std::string &_sDocumentation)
This member function handles the display of a documentation window as requested by the kernel.
Definition: kernel.cpp:3130
bool refreshTree
Definition: kernel.hpp:142
std::vector< std::string > getPathSettings() const
This member function returns a vector containing all currently declared paths in a distinct order.
Definition: kernel.cpp:2531
static std::string formatResultOutput(int nNum, mu::value_type *v)
This static function is used to format the result output in the terminal for numerical-only results.
Definition: kernel.cpp:2730
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
Definition: kernel.cpp:3671
void Autosave()
Saves the allocated memories by the tables automatically.
Definition: kernel.cpp:121
Settings & getSettings()
Definition: kernel.hpp:296
static int * baseStackPosition
Definition: kernel.hpp:188
static bool modifiedSettings
Definition: kernel.hpp:197
static int waitForContinue()
This static function waits until the user sends a continuation command via the debugger and returns t...
Definition: kernel.cpp:3440
Procedure _procedure
Definition: kernel.hpp:156
void showWindow(const NumeRe::Window &window)
This member function passes a window object to the user interface, which will then converted into a r...
Definition: kernel.cpp:3267
bool executePlugins(std::string &sLine)
This private member function will execute any call to a plugin.
Definition: kernel.cpp:1800
Output _out
Definition: kernel.hpp:149
The terminal class for the GUI. It's a specialisation of the GenericTerminal.
Definition: terminal.hpp:46
NumeReKernel::KernelStatus m_KernelStatus
Definition: terminal.hpp:168
bool m_bTableEditAvailable
Definition: terminal.hpp:170
std::string m_sCommandLine
Definition: terminal.hpp:174
bool m_bTableEditCanceled
Definition: terminal.hpp:171
bool m_bCommandAvailable
Definition: terminal.hpp:169
wxCriticalSection m_kernelCS
Definition: terminal.hpp:167
std::string m_sAnswer
Definition: terminal.hpp:175
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 getPluginProcName() const
Returns the current plugin's procedure name.
Definition: plugin.hpp:188
std::string deletePackage(const std::string &sPackage)
This member function deletes the plugin with the passed name from the internal set of definitions and...
Definition: plugin.cpp:857
std::string getPluginInfoPath()
This member function simply returns the plugin definition file path.
Definition: plugin.cpp:913
bool loadPlugins()
This member function will read the plugin definitions from the definitions file and create the intern...
Definition: plugin.cpp:501
std::string getPluginVarList() const
Returns the current plugin's procedure argument list.
Definition: plugin.hpp:198
const std::vector< Package > & getPackages() const
Returns a const reference to the currently installed packages.
Definition: plugin.hpp:159
bool isPluginCmd(const std::string &sCmd) const
This member function determines, whether the passed command line contains a plugin command.
Definition: plugin.cpp:829
bool evalPluginCmd(std::string &sCmd)
This member function converts the call to a plugin in the passed command line into a call to the corr...
Definition: plugin.cpp:544
std::string getPluginNames() const
Returns the names of the installed plugins.
Definition: plugin.hpp:171
unsigned int getPackageCount() const
Returns the number of installed plugins.
Definition: plugin.hpp:146
std::map< std::string, std::string > getMenuMap() const
Returns the menu map connecting menu entry names with their corresponding procedure,...
Definition: plugin.cpp:892
std::string getPluginCommand(unsigned int i=0) const
Returns the plugin command of the ith plugin.
Definition: plugin.hpp:209
void setFileName(std::string _sFileName)
Change the output file name.
Definition: plotdata.cpp:2411
Returnvalue execute(std::string sProc, std::string sVarList, mu::Parser &_parser, FunctionDefinitionManager &_functions, MemoryManager &_data, Settings &_option, Output &_out, PlotData &_pData, Script &_script, unsigned int nth_procedure=0)
This member function is central in the execution of the currently selected procedure as it handles al...
Definition: procedure.cpp:614
bool is_writing() const
Definition: procedure.hpp:118
size_t replaceReturnVal(std::string &sLine, mu::Parser &_parser, const Returnvalue &_return, unsigned int nPos, unsigned int nPos2, const std::string &sReplaceName)
This member function replaces the procedure occurence between the both passed positions using akronym...
Definition: procedure.cpp:2591
void setPredefinedFuncs(const std::string &sPredefined)
Definition: procedure.hpp:109
int getReturnType() const
Definition: procedure.hpp:116
bool writeProcedure(std::string sProcedureLine)
This member function handles the procedure installation process by governing the file stream and pass...
Definition: procedure.cpp:1547
static std::string mangleName(std::string sProcedureName)
Mangles a procedure name to be used as a usual variable.
Definition: procedure.cpp:2414
int & getDebuggerCode()
Definition: procedure.hpp:122
This class manages all already read and possibly pre-parsed procedure files for easier and faster acc...
bool isOpen() const
Definition: script.hpp:101
bool wasLastCommand()
Definition: script.hpp:105
void close()
This member function closes an opened script.
Definition: script.cpp:107
std::string getScriptFileName() const
Definition: script.hpp:85
std::string getNextScriptCommand()
This member function is the main interface to the internal managed script. It will always return the ...
Definition: script.cpp:1055
unsigned int getCurrentLine() const
Definition: script.hpp:91
void returnCommand()
This member function closes the script, if the code reached a "return" statement.
Definition: script.cpp:176
void setPredefinedFuncs(const std::string &sPredefined)
Definition: script.hpp:87
bool isValid() const
Definition: script.hpp:103
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
std::string getDefaultPlotFont() const
Returns the current plotting font name.
Definition: settings.hpp:1111
std::string getLoadPath() const
Returns the current loading path.
Definition: settings.hpp:1038
bool showGreeting() const
Returns, whether NumeRe shall greet the user with a funny message at application start-up.
Definition: settings.hpp:924
bool useLogFile() const
Returns, whether the terminal inputs shall be protocoled in a dedicated logfile. This setting does no...
Definition: settings.hpp:978
std::string getWorkPath() const
Returns the current working path (connected to the <wp> token).
Definition: settings.hpp:1020
bool controlDefinitions() const
Returns, whether NumeRe shall load and save custom functions automatically.
Definition: settings.hpp:955
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
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
void enableSystemPrints(bool _bSystemPrints=true)
Enables or disables the system printing functionality. This is a convenience wrapper for the direct m...
Definition: settings.hpp:829
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
Definition: settings.hpp:1101
void copySettings(const Settings &_settings)
This member function is an alias for the assignment operator overload.
Definition: settings.cpp:740
bool useCustomLangFiles() const
Returns, whether user language files shall be used to override internal language strings.
Definition: settings.hpp:1161
std::string getScriptPath() const
Returns the current script import folder path.
Definition: settings.hpp:1058
bool loadEmptyCols() const
Returns, whether NumeRe shall keep empty columns when loading a file to memory.
Definition: settings.hpp:988
bool useDebugger() const
Returns, whether the debugger is currently active.
Definition: settings.hpp:1150
void load(const std::string &_sWhere)
Opens the configuration file, identifies its version and imports the setting values.
Definition: settings.cpp:607
bool useEscInScripts() const
Returns, whether ESC key presses shall be handled, when scripts are being executed.
Definition: settings.hpp:945
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
size_t & value()
Returns a reference to an unsigned int value type setting.
Definition: settings.hpp:573
std::string & stringval()
Returns a reference to a std::string value type setting.
Definition: settings.hpp:590
std::string maxString(unsigned int i1=0, unsigned int i2=std::string::npos, unsigned int nCol=0)
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)
std::string minString(unsigned int i1=0, unsigned int i2=std::string::npos, unsigned int nCol=0)
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ LOOP_THROW
Definition: error.hpp:152
@ FUNCTION_ERROR
Definition: error.hpp:110
@ UNMATCHED_PARENTHESIS
Definition: error.hpp:224
@ PROCEDURE_THROW
Definition: error.hpp:199
@ INVALID_INDEX
Definition: error.hpp:129
@ PROCESS_ABORTED_BY_USER
Definition: error.hpp:202
static size_t invalid_position
Definition: error.hpp:235
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
Definition: structures.hpp:614
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
Definition: structures.hpp:770
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const varmap_type & GetVar() const
Return a map containing the used variables only.
void DeactivateLoopMode()
Deactivates the loop mode and resets the internal arrays.
void ClearVectorVars(bool bIgnoreProcedureVects=false)
This member function cleares the internal vector storage.
void SetVarFactory(facfun_type a_pFactory, void *pUserData=NULL)
Set a function that can create variable pointer for unknown expression variables.
void DefineVar(const string_type &a_sName, value_type *a_fVar)
Add a user defined variable.
void DefineConst(const string_type &a_sName, value_type a_fVal)
Add a user defined constant.
void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool optimizeAway=true)
Add a user defined operator.
bool IsAlreadyParsed(StringView sNewEquation)
This member function checks, whether the passed expression is already parsed, so that the parsing ste...
void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool optimizeAway=true)
Add a user defined operator.
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
std::map< std::string, std::string > * mVarMapPntr
Definition: muParserBase.h:98
void DefineFun(const string_type &a_strName, T a_pFun, bool optimizeAway=true)
Define a parser function without arguments.
Definition: muParserBase.h:156
std::list< mu::value_type * > m_lDataStorage
Definition: muParserBase.h:99
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...
void DefineOprt(const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool optimizeAway=true)
Define a binary operator.
Error class of the parser.
std::size_t GetPos() const
Return the formula position related to the error.
const string_type & GetMsg() const
Returns the message string for this error.
const string_type & GetExpr() const
gets the expression related tp this error.
const string_type & GetToken() const
Return string related with this token (if available).
Mathematical expressions parser.
Definition: muParser.h:51
value_type parser_Random(const value_type &vRandMin, const value_type &vRandMax)
This function returns a uniformly distributed random number between both boundaries.
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
Definition: dataaccess.cpp:276
bool isClusterCandidate(string &sLine, string &sCluster, bool doCut)
This function checks, whether the passed command line contains the syntax for a cluster candidate,...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
Definition: indices.cpp:49
bool isValidIndexSet(const Indices &_idx)
Definition: dataaccess.hpp:81
#define MAXSTRINGLENGTH
Definition: debugger.cpp:28
std::string doc_HelpAsHTML(const std::string &__sTopic, bool generateFile, Settings &_option)
This function returns the documentation article for the selected topic as an HTML std::string....
std::string errorTypeToString(ErrorType e)
Return the error type converted to a human readable string.
Definition: error.cpp:148
Assertion _assertionHandler
Definition: error.cpp:27
@ TYPE_ASSERTIONERROR
Definition: error.hpp:474
@ TYPE_SYNTAXERROR
Definition: error.hpp:473
@ TYPE_MATHERROR
Definition: error.hpp:472
@ TYPE_CUSTOMERROR
Definition: error.hpp:475
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.
value_type parser_Binom(const value_type &v1, const value_type &v2)
Function representing the binomial coefficient.
value_type parser_Faculty(const value_type &v)
Function representing the faculty of any natural number.
value_type parser_Parsec(const value_type &v)
Conversion function for 1pc.
value_type parser_gcd(const value_type &n, const value_type &k)
This function returns the greatest common divisor of both argments.
value_type parser_Norm(const value_type *vElements, int nElements)
This function calculates the vector norm of the elements in the passed array.
value_type parser_Pct(const value_type *vElements, int nElements)
This function calculates the selected percentile of the passed array.
value_type parser_is_string(const value_type &v)
This function is a numerical version of the string is_string() function. Used as a fallback.
value_type parser_studentFactor(const value_type &vFreedoms, const value_type &vAlpha)
This function returns the Student factor s_t for the selected degrees of freedom and a confidence int...
value_type parser_and(const value_type *vElements, int nElements)
This function calculates the logical AND operation between all elements in the passed array.
value_type parser_interval(const value_type &v, const value_type &vLeft, const value_type &vRight)
This function numerically defines a valid value range (the value is set to NaN, if outside of this ra...
value_type parser_Poise(const value_type &v)
Conversion function for 1Ps.
value_type parser_clock()
This function returns the current CPU clock count.
value_type parser_asec(const value_type &x)
This function returns the inverse secant of the passed value.
value_type parser_SphericalNeumann(const value_type &vn, const value_type &vc)
This function calculates the spherical von Neumann function.
value_type parser_theta(const value_type &x, const value_type &y, const value_type &z)
This function calculates the angle of a vector and the z axis in any z-r plane (the polar angle theta...
value_type parser_Lightyear(const value_type &v)
Conversion function for 1ly.
value_type * parser_AddVariable(const char_type *a_szName, void *a_pUserData)
This function represents the numerical variable factory. New memory is allocated in this function and...
value_type parser_SinusCardinalis(const value_type &v)
This function calculates the cardinal sine of x.
value_type parser_Barn(const value_type &v)
Conversion function for 1bn.
value_type parser_Yard(const value_type &v)
Conversion function for 1yd.
value_type parser_mol(const value_type &v)
Conversion function for 1mol.
value_type parser_csch(const value_type &x)
This function returns the hyperbolic cosecant of the passed value.
value_type parser_EllipticD(const value_type &phi, const value_type &n, const value_type &k)
This function returns the value of the elliptic intergal D(phi,n,k).
value_type parser_AiryA(const value_type &x)
This function calculates the Airy function Ai(x).
value_type parser_Nano(const value_type &a_fVal)
Conversion function for 1n.
value_type parser_roof(const value_type &x)
This is the roof (ceil) function.
value_type parser_Zernike(const value_type &vn, const value_type &vm, const value_type &rho, const value_type &phi)
This function calculates the selected Zernike polynomials.
value_type parser_AssociatedLegendrePolynomial(const value_type &vl, const value_type &vm, const value_type &v)
This function calculates the associated Legendre polynomials of the selected order.
value_type parser_EllipticF(const value_type &phic, const value_type &kc)
This function returns the value of the elliptic intergal F(phi,k).
value_type parser_Micro(const value_type &a_fVal)
Conversion function for 1mu.
value_type parser_AssociatedLaguerrePolynomial(const value_type &vn, const value_type &vk, const value_type &v)
This function calculates the associated Laguerre polynomials of the selected order.
value_type parser_Ignore(const value_type &v)
Identity function. Used for ignoring functions and parameters in special cases.
value_type parser_Mile(const value_type &v)
Conversion function for 1mi.
value_type parser_real(const value_type &v)
Extracts the real part of a complex number.
value_type parser_acsc(const value_type &x)
This function returns the inverse cosecant of the passed value.
value_type parser_beta(const value_type &a, const value_type &b)
This function returns the value of the Beta function.
value_type parser_complex(const value_type &re, const value_type &im)
Construct a complex number from two real numbers.
value_type parser_isnan(const value_type &v)
Returns, whether the selected value is NaN.
value_type parser_erf(const value_type &x)
This function calculates the gaussian error function.
value_type parser_date(const value_type &vTime, const value_type &vType)
This function converts UNIX time values into a selected part of a time stamp.
value_type parser_polar2rect(const value_type &v)
Converts a polar representation into a rectangular representation and returns it as a new complex num...
value_type parser_AstroUnit(const value_type &v)
Conversion function for 1AU.
value_type parser_LaguerrePolynomial(const value_type &vn, const value_type &v)
This function calculates the Laguerre polynomials of the selected order.
value_type parser_imSphericalHarmonics(const value_type &vl, const value_type &vm, const value_type &theta, const value_type &phi)
This function calculates the imaginary part of the selected spherical harmonics.
value_type parser_RegularCylBessel(const value_type &n, const value_type &x)
This function calculates the regulary bessel function.
value_type parser_time()
This function returns the current UNIX time.
value_type parser_rect(const value_type &x, const value_type &x0, const value_type &x1)
This is the rect function.
value_type parser_Not(const value_type &v)
Function representing the logical NOT operator.
value_type parser_Cnt(const value_type *vElements, int nElements)
This functioon simply returns the number of elements in its array (even the invalid ones).
value_type parser_PSI(const value_type &v)
Conversion function for 1psi.
value_type parser_sec(const value_type &x)
This function returns the secant of the passed value.
value_type parser_Milli(const value_type &a_fVal)
Conversion function for 1m.
value_type parser_Mega(const value_type &a_fVal)
Conversion function for 1M.
value_type parser_Num(const value_type *vElements, int nElements)
This function returns the number of valid elements in its array.
value_type parser_EllipticP(const value_type &phi, const value_type &n, const value_type &k)
This function returns the value of the elliptic intergal Pi(phi,n,k).
value_type parser_kmh(const value_type &v)
Conversion function for 1kmh.
value_type parser_zeta(const value_type &s)
This function returns the value of the Zeta function.
value_type parser_Giga(const value_type &a_fVal)
Conversion function for 1G.
value_type parser_SphericalBessel(const value_type &vn, const value_type &vc)
This function calculates the spherical bessel function.
value_type parser_gamma(const value_type &x)
This function calculates the riemannian Gamma function.
value_type parser_EllipticE(const value_type &phic, const value_type &kc)
This function returns the value of the elliptic intergal E(phi,k).
value_type parser_BetheWeizsaecker(const value_type &vN, const value_type &vZ)
This function calculates the nucleic core binding energy according the Bethe Weizsäcker formula.
value_type parser_Calorie(const value_type &v)
Conversion function for 1cal.
value_type parser_toDegree(const value_type &v)
This function converts radian to degree.
value_type parser_MaxPos(const value_type *vElements, int nElements)
This function returns the index of the (first) maximal value in the array.
value_type parser_sech(const value_type &x)
This function returns the hyperbolic secant of the passed value.
value_type parser_Torr(const value_type &v)
Conversion function for 1Torr/1mmhg.
value_type parser_Curie(const value_type &v)
Conversion function for 1C.
value_type parser_perlin(const value_type *vElements, int nElements)
This function implements the perlin noise function.
value_type parser_lcm(const value_type &n, const value_type &k)
This function returns the least common multiple of both arguments.
value_type parser_weeknum(const value_type &vTime)
This function returns the calendar week associated with the passed time value.
value_type parser_liter(const value_type &v)
Conversion function for 1l.
value_type parser_BinAND(const value_type &v1, const value_type &v2)
This function represents the binary AND operator.
value_type parser_round(const value_type &vToRound, const value_type &vDecimals)
This function rounds the passed value to the selected number of decimals.
value_type parser_log_b(const value_type &b, const value_type &x)
Calculates the logarithm of x using the base b.
value_type parser_SphericalHarmonics(const value_type &vl, const value_type &vm, const value_type &theta, const value_type &phi)
This function calculates the real part of the selected spherical harmonics.
value_type parser_Std(const value_type *vElements, int nElements)
This function calculates the standard deviation of the elements in the passed array.
value_type parser_Med(const value_type *vElements, int nElements)
This function calculates the median of the elements in the passed array.
value_type parser_digamma(const value_type &x)
This function returns the value of the Digamma function.
value_type parser_HermitePolynomial(const value_type &vn, const value_type &v)
This function calculates the Hermite polynomials of the selected order.
value_type parser_toRadian(const value_type &v)
This function converts degree to radian.
value_type parser_compare(const value_type *vElements, int nElements)
This function searches for elements of a specified type in the passed array.
value_type parser_ivl(const value_type &x, const value_type &x0, const value_type &x1, const value_type &lborder, const value_type &rborder)
This function describes an interval with borders of a selected type (including, excluding,...
value_type parser_Mod(const value_type &v1, const value_type &v2)
This function represents the Modulo operator.
value_type parser_Angstroem(const value_type &v)
Conversion function for 1A.
value_type parser_dilogarithm(const value_type &x)
This function returns the value of the Dilogarithm Li2(x).
value_type parser_MinPos(const value_type *vElements, int nElements)
This function returns the index of the (first) minimal value in the array.
value_type parser_Kilo(const value_type &a_fVal)
Conversion function for 1k.
value_type parser_LegendrePolynomial(const value_type &vn, const value_type &v)
This function calculates the Legendre polynomials of the selected order.
value_type parser_gRandom(const value_type &vRandAvg, const value_type &vRandstd)
This function returns a gaussian distributed random number using the passed values as mean and standa...
value_type parser_Gauss(const value_type &v)
Conversion function for 1Gs.
value_type parser_polynomial(const value_type *vElements, int nElements)
This function implements an abstract polynomial of an arbitrary order.
value_type parser_imag(const value_type &v)
Extracts the imaginary part of a complex number.
value_type parser_xor(const value_type *vElements, int nElements)
This function calculates the logical XOR operation between all elements in the passed array.
value_type parser_acsch(const value_type &x)
This function returns the inverse hyperbolic cosecant of the passed value.
value_type parser_Fahrenheit(const value_type &v)
Conversion function for 1°F.
value_type parser_BinOR(const value_type &v1, const value_type &v2)
This function represents the binary OR operator.
value_type parser_Fermi(const value_type &v)
Conversion function for 1fm.
value_type parser_imaginaryUnit(const value_type &v)
Multiplies a number with the imaginary unit.
value_type parser_ElectronVolt(const value_type &v)
Conversion function for 1eV.
value_type parser_Inch(const value_type &v)
Conversion function for 1in.
value_type parser_cot(const value_type &x)
This function returns the cotangent of the passed value.
value_type parser_erfc(const value_type &x)
This function calculates the complementary gaussian error function.
value_type parser_Foot(const value_type &v)
Conversion function for 1ft.
value_type parser_or(const value_type *vElements, int nElements)
This function calculates the logical OR operation between all elements in the passed array.
value_type parser_numereversion()
Returns the version number of NumeRe as a natural number.
value_type parser_doubleFaculty(const value_type &v)
Function representing the double faculty of any natural number.
value_type parser_Knoten(const value_type &v)
Conversion function for 1kn.
value_type parser_floor(const value_type &x)
This is the floor function.
value_type parser_sleep(const value_type &milliseconds)
Sleeps for the passed amount of milliseconds and returns this number.
value_type parser_csc(const value_type &x)
This function returns the cosecant of the passed value.
value_type parser_clausen(const value_type &x)
This function returns the value of the Clausen function.
value_type parser_phi(const value_type &x, const value_type &y)
This function calculates the angle of a vector and the x axis in the x-y plane (the azimuthal angle p...
value_type parser_asech(const value_type &x)
This function returns the inverse hyperbolic secant of the passed value.
value_type parser_Heaviside(const value_type &v)
This function represents the Heaviside (theta) function.
value_type parser_IrregularCylBessel(const value_type &n, const value_type &x)
This function calculates the irregulary bessel (von Neumann) function.
value_type parser_polygamma(const value_type &n, const value_type &x)
This function returns the value if the Polygamma function.
value_type parser_conj(const value_type &v)
Calculates the complex conjugate number of the passed complex number.
value_type parser_product(const value_type *vElements, int nElements)
This function calculates the product of all elements in the passed array.
value_type parser_mph(const value_type &v)
Conversion function for 1mph.
value_type parser_rect2polar(const value_type &v)
Converts a rectangular representation into polar representation and returns it as a new complex numbe...
value_type parser_XOR(const value_type &v1, const value_type &v2)
This function represent the XOR operator.
value_type parser_AiryB(const value_type &x)
This function calculates the Airy function Bi(x).
value_type parser_Celsius(const value_type &v)
Conversion function for 1°C.
__time64_t tTimeZero
Definition: kernel.cpp:43
void make_hline(int nLength)
This function prints a horizontal line to the terminal using either minus or equal signs.
Definition: kernel.cpp:3720
#define KERNEL_PRINT_SLEEP
Definition: kernel.cpp:26
mglGraph _fontData
Definition: kernel.cpp:40
DefaultVariables _defVars
Language _lang
Definition: kernel.cpp:39
#define TERMINAL_FORMAT_FIELD_LENOFFSET
Definition: kernel.cpp:27
#define DEFAULT_NUM_PRECISION
Definition: kernel.cpp:28
value_type vAns
#define DEFAULT_MINMAX_PRECISION
Definition: kernel.cpp:29
const std::string sVersion
static std::string drawBar(int nValue, size_t nLength, const std::string &sProgressChar, const std::string &sWhitespaceChar)
Simple static helper function to render the actual progress bar.
Definition: kernel.cpp:2933
static std::string formatByteSize(double bytes)
Formats the byte size using KB or MB as units.
Definition: kernel.cpp:2397
std::string pointToError(unsigned int nPos)
This function points to the error indicated by nPos. It draws three circumflexes below the error loca...
Definition: kernel.hpp:482
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
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
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
Definition: tools.cpp:414
static const char DATE[]
Definition: version.h:7
static const char MONTH[]
Definition: version.h:8
static const char YEAR[]
Definition: version.h:9
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: date.h:1317
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:273
@ prLOGIC
logic operators
Definition: muParserDef.h:233
@ prMUL_DIV
multiplication/division
Definition: muParserDef.h:236
@ oaLEFT
Definition: muParserDef.h:221
string promptForUserInput(const string &__sCommand)
This function is invoked, if a prompt operator ("??") was found in a string.
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_PROCPATH
Definition: settings.hpp:63
#define SETTING_S_EXEPATH
Definition: settings.hpp:58
#define SETTING_V_WINDOW_X
Definition: settings.hpp:52
#define SETTING_S_LOADPATH
Definition: settings.hpp:60
#define SETTING_S_SAVEPATH
Definition: settings.hpp:59
#define SETTING_S_PLOTPATH
Definition: settings.hpp:61
#define SETTING_S_SCRIPTPATH
Definition: settings.hpp:62
std::string toHexString(int nNumber)
Converts an integer to a hexadecimal number printed as string.
std::string truncString(const std::string &sText, size_t nMaxChars)
This function truncates the string to the passed max length (including a trailing ellipsis) or return...
std::string replaceControlCharacters(std::string sToModify)
This function is a simple wrapper for replaceAll() and specialized to remove control characters from ...
std::string toExternalString(std::string sStr)
Converts an internal string to the external representation in the terminal.
std::string ellipsize(const std::string &sLongString, size_t nMaxStringLength)
Shortens the passed string by introducing a ellipsis in the middle of the string, if the string is lo...
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.
Structure for the four standard variables.
std::string sName[4]
mu::value_type vValue[4][4]
This structure is central for managing the indices of a table or cluster read or write data access....
VectorIndex col
VectorIndex row
std::string sString
This structure abstracts the necessary information for a task to be done by the graphical user interf...
Definition: kernel.hpp:380
NumeRe::Table table
Definition: kernel.hpp:384
NumeRe::Container< std::string > stringTable
Definition: kernel.hpp:386
std::vector< std::string > vDebugEvent
Definition: kernel.hpp:383
NumeRe::Window window
Definition: kernel.hpp:385
int taskType
Definition: kernel.hpp:387
size_t nLine
Definition: kernel.hpp:382
std::string sString
Definition: kernel.hpp:381
This structure combines a vector of declared variables including their values and respective sizes wi...
Definition: kernel.hpp:80
size_t nNumerics
Definition: kernel.hpp:82
size_t nStrings
Definition: kernel.hpp:83
size_t nTables
Definition: kernel.hpp:84
size_t nClusters
Definition: kernel.hpp:85
std::vector< std::string > vVariables
Definition: kernel.hpp:81
Structure as wrapper for the return value of procedures (which may be numerical or string values or a...
std::vector< std::string > vStringVal
bool isString() const
bool isNumeric() const
std::string sReturnedTable
std::vector< mu::value_type > vNumVal
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.
Match findCommand(StringView sCmd, const std::string &sCommand)
This function is very important for the command handler.
Definition: tools.cpp:1275
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
void evalRecursiveExpressions(string &sExpr)
This function converts the recursive assignments like VAR += VAL into VAR = VAR + (VAL)
Definition: tools.cpp:3346
bool isInQuotes(StringView sExpr, unsigned int nPos, bool bIgnoreVarParser)
Checks, whether the position in the passed expression is part of a string literal.
Definition: tools.cpp:1672
void reduceLogFilesize(const string &sFileName)
This function is used to reduce the log file size from >= 100.000 to 20.000 lines to reduce the neede...
Definition: tools.cpp:2998
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 validateParenthesisNumber(const string &sCmd)
This function is used to validate the number of parentheses, i.e. whether there's a closing parenthes...
Definition: tools.cpp:3512
static NumeRe::WindowInformation getWindow(const std::string &sExpr)
This static function returns the window information describing the window with the selected ID.
Definition: winlayout.cpp:427