21#include "../../kernel.hpp"
22#include "../io/file.hpp"
49 for (
int i = 0; i < omp_get_max_threads(); i++)
64 int threadId = omp_get_thread_num();
67 throw std::out_of_range(
"Requested a random number generator for thread " + std::to_string(threadId)
68 +
", which is larger than the number of available generators (i.e. "
113int findParameter(
const string& sCmd,
const string& sParam,
const char cFollowing)
116 if (sCmd.find(
'-') == string::npos)
124 size_t nParamStart = string::npos;
125 bool isOptionValue =
false;
128 for (
size_t i = 0; i < __sCmd.length(); i++)
132 && (!i || (i && __sCmd[i - 1] !=
'\\')))
136 if (!(nQuotes % 2) && __sCmd[i] ==
'-' && nParamStart == string::npos)
143 if (nParamStart != string::npos
148 isOptionValue =
true;
151 while (i+1 < __sCmd.length() && __sCmd[i+1] ==
' ')
154 else if (nParamStart != string::npos
158 isOptionValue =
false;
162 if (nParamStart != string::npos
165 && __sCmd.substr(i, sParam.length()) ==
toLowerCase(sParam))
172 if (cFollowing ==
' ')
175 if ((__sCmd[i - 1] ==
' '
176 || __sCmd[i - 1] ==
'-')
177 && (__sCmd[i + sParam.length()] ==
' '
178 || __sCmd[i + sParam.length()] ==
'-'
179 || __sCmd[i + sParam.length()] ==
'='
180 || __sCmd[i + sParam.length()] ==
'"')
184 if (__sCmd[i - 1] ==
' ' && __sCmd[__sCmd.find_last_not_of(
' ', i - 1)] ==
'=')
185 i += sParam.length() - 1;
190 i += sParam.length() - 1;
195 if ((__sCmd[i - 1] ==
' ' || __sCmd[i - 1] ==
'-')
196 && (__sCmd[i + sParam.length()] == cFollowing))
200 if (__sCmd[i - 1] ==
' ' && __sCmd[__sCmd.find_last_not_of(
' ', i - 1)] ==
'=')
201 i += sParam.length() - 1;
205 else if ((__sCmd[i - 1] ==
' ' || __sCmd[i - 1] ==
'-')
206 && (__sCmd[i + sParam.length()] ==
' '))
210 if (__sCmd[i - 1] ==
' ' && __sCmd[__sCmd.find_last_not_of(
' ', i - 1)] ==
'=')
211 i += sParam.length() - 1;
218 while (i + sParam.length() + nSkip < __sCmd.length() && __sCmd[i + sParam.length() + nSkip] ==
' ')
220 if (__sCmd[i + sParam.length() + nSkip] == cFollowing)
221 return i + 1 + nSkip;
223 i += sParam.length() - 1;
227 i += sParam.length() - 1;
258 if (sCmd.front() !=
'=')
262 nPos = sCmd.find(
'"');
264 if (sCmd.find(
'#') != string::npos && (sCmd.find(
'#') < nPos || nPos == string::npos))
265 nPos = sCmd.find(
'#');
267 if (sCmd.find(
"to_string(") != string::npos && (sCmd.find(
"to_string(") < nPos || nPos == string::npos))
268 nPos = sCmd.find(
"to_string(");
270 if (sCmd.find(
"string(") != string::npos && (sCmd.find(
"string(") < nPos || nPos == string::npos))
271 nPos = sCmd.find(
"string(");
273 if (sCmd.find(
"substr(") != string::npos && (sCmd.find(
"substr(") < nPos || nPos == string::npos))
274 nPos = sCmd.find(
"substr(");
276 if (sCmd.find(
"strlen(") != string::npos && (sCmd.find(
"strlen(") < nPos || nPos == string::npos))
277 nPos = sCmd.find(
"strlen(");
279 if (sCmd.find(
"strfnd(") != string::npos && (sCmd.find(
"strfnd(") < nPos || nPos == string::npos))
280 nPos = sCmd.find(
"strfnd(");
282 if (sCmd.find(
"ascii(") != string::npos && (sCmd.find(
"ascii(") < nPos || nPos == string::npos))
283 nPos = sCmd.find(
"ascii(");
285 if (sCmd.find(
"to_char(") != string::npos && (sCmd.find(
"to_char(") < nPos || nPos == string::npos))
286 nPos = sCmd.find(
"to_char(");
288 if (sCmd.find(
"char(") != string::npos && (sCmd.find(
"char(") < nPos || nPos == string::npos))
289 nPos = sCmd.find(
"char(");
313 if (sCmd.front() ==
'=')
317 size_t nQuotes =
isInQuotes(sCmd, nPos,
true);
319 for (
size_t i = nPos; i < sCmd.length(); i++)
321 if (sCmd[i] ==
'"' && (!i || sCmd[i-1] !=
'\\'))
331 if (sCmd[i] ==
'(' || sCmd[i] ==
'[' || sCmd[i] ==
'{')
340 for (
size_t j = i; j < sCmd.length(); j++)
351 if (j == sCmd.length() - 1)
363 if (sCmd.find_first_not_of(
' ', i) != string::npos && sCmd[sCmd.find_first_not_of(
' ', i)] !=
'+')
373 i = sCmd.find_first_not_of(
" +", i)-1;
380 if (i >= sCmd.length() - 1 || (ispunct(sCmd[i]) && sCmd[i] !=
'.' && sCmd[i] !=
'_' && sCmd[i] !=
'+' && sCmd[i] !=
'#'))
382 if (i == string::npos)
383 nPos_2 = sCmd.length();
392 return sCmd.substr(nPos);
394 return sCmd.substr(nPos, nPos_2 - nPos + 1);
418 if (pos == string::npos)
422 char cParenthesis = sLine[pos];
423 char cClosingParenthesis = 0;
426 switch (cParenthesis)
429 cClosingParenthesis =
')';
432 cClosingParenthesis =
'}';
435 cClosingParenthesis =
']';
440 cClosingParenthesis =
')';
443 int nOpenParenthesis = 0;
448 for (
size_t i = 0; i < sLine.
length(); i++)
451 if (sLine[i] ==
'"' && (!i || sLine[i-1] !=
'\\'))
458 if (sLine[i] == cParenthesis)
462 if (sLine[i] == cClosingParenthesis)
466 if (!nOpenParenthesis && i > pos)
487 if (sExpr.find(
',') == string::npos)
491 size_t nQuotationMarks = 0;
494 for (
unsigned int i = 0; i < sExpr.length(); i++)
497 if ((sExpr[i] ==
'(' || sExpr[i] ==
'{' || sExpr[i] ==
'[') && !(nQuotationMarks % 2))
504 if (sExpr[i] ==
',' && !(nQuotationMarks % 2))
511 if (sExpr.find_first_of(
"([{") != string::npos && bIgnoreClosingParenthesis)
512 return isMultiValue(sExpr.substr(sExpr.find_first_of(
"([{")+1),
true);
529 std::map<std::string, std::string> mCodePage;
531 mCodePage[
"_pi"] =
"\\pi ";
532 mCodePage[
"_hbar"] =
"\\hbar ";
533 mCodePage[
"_k_boltz"] =
"k_B";
534 mCodePage[
"_2pi"] =
"2\\cdot \\pi ";
535 mCodePage[
"_elek_feldkonst"] =
"\\varepsilon ";
536 mCodePage[
"_elem_ladung"] =
"e";
537 mCodePage[
"_m_elektron"] =
"m_{e}";
538 mCodePage[
"_m_neutron"] =
"m_{n}";
539 mCodePage[
"_m_proton"] =
"m_{p}";
540 mCodePage[
"_m_sonne"] =
"m_{Sonne}";
541 mCodePage[
"_m_erde"] =
"m_{Erde}";
542 mCodePage[
"_m_muon"] =
"m_{\\mu}";
543 mCodePage[
"_m_tau"] =
"m_{\\tau}";
544 mCodePage[
"_magn_feldkonst"] =
"\\mu ";
545 mCodePage[
"_n_avogadro"] =
"N_A";
546 mCodePage[
"_r_erde"] =
"r_{Erde}";
547 mCodePage[
"_r_sonne"] =
"r_{Sonne}";
548 mCodePage[
"_c"] =
"c_{Licht}";
549 mCodePage[
"_e"] =
"e";
550 mCodePage[
"_g"] =
"g";
551 mCodePage[
"_h"] =
"h";
552 mCodePage[
"_R"] =
"R";
553 mCodePage[
"_alpha_fs"] =
"\\alpha_{FS}";
554 mCodePage[
"_mu_bohr"] =
"\\mu_{B}";
555 mCodePage[
"_mu_kern"] =
"\\mu_{K}";
556 mCodePage[
"_m_amu"] =
"m_u";
557 mCodePage[
"_r_bohr"] =
"a_0";
558 mCodePage[
"_G"] =
"G";
559 mCodePage[
"_theta_weinberg"] =
"\\theta_{W}";
560 mCodePage[
"_mu_e"] =
"\\mu_{e}";
561 mCodePage[
"_mu_p"] =
"\\mu_{p}";
562 mCodePage[
"_mu_n"] =
"\\mu_{n}";
563 mCodePage[
"_gamma_e"] =
"\\gamma_{e}";
564 mCodePage[
"_gamma_p"] =
"\\gamma_{p}";
565 mCodePage[
"_gamma_n"] =
"\\gamma_{n}";
566 mCodePage[
"_stefan_boltzmann"] =
"\\sigma ";
567 mCodePage[
"_rydberg"] =
"R_{\\infty}";
568 mCodePage[
"_hartree"] =
"E_{h}";
569 mCodePage[
"_wien"] =
"b_{Energie}";
570 mCodePage[
"_lande_e"] =
"g_{e}";
571 mCodePage[
"_feigenbaum_alpha"] =
"\\alpha ";
572 mCodePage[
"_feigenbaum_delta"] =
"\\delta ";
573 mCodePage[
"inf"] =
"\\infty";
574 mCodePage[
"alpha"] =
"\\alpha ";
575 mCodePage[
"Alpha"] =
"\\Alpha ";
576 mCodePage[
"beta"] =
"\\beta ";
577 mCodePage[
"Beta"] =
"\\Beta ";
578 mCodePage[
"gamma"] =
"\\gamma ";
579 mCodePage[
"Gamma"] =
"\\Gamma ";
580 mCodePage[
"delta"] =
"\\delta ";
581 mCodePage[
"Delta"] =
"\\Delta ";
582 mCodePage[
"epsilon"] =
"\\varepsilon ";
583 mCodePage[
"Epsilon"] =
"\\Epsilon ";
584 mCodePage[
"zeta"] =
"\\zeta ";
585 mCodePage[
"Zeta"] =
"\\Zeta ";
586 mCodePage[
"eta"] =
"\\eta ";
587 mCodePage[
"Eta"] =
"\\Eta ";
588 mCodePage[
"\theta"] =
"\\theta ";
589 mCodePage[
"theta"] =
"\\vartheta ";
590 mCodePage[
"Theta"] =
"\\Theta ";
591 mCodePage[
"iota"] =
"\\iota ";
592 mCodePage[
"Iota"] =
"\\Iota ";
593 mCodePage[
"kappa"] =
"\\kappa ";
594 mCodePage[
"Kappa"] =
"\\Kappa ";
595 mCodePage[
"lambda"] =
"\\lambda ";
596 mCodePage[
"Lambda"] =
"\\Lambda ";
597 mCodePage[
"mu"] =
"\\mu";
598 mCodePage[
"Mu"] =
"\\Mu ";
599 mCodePage[
"\nu"] =
"\\nu ";
600 mCodePage[
"nu"] =
"\\nu ";
601 mCodePage[
"Nu"] =
"\\Nu ";
602 mCodePage[
"xi"] =
"\\xi ";
603 mCodePage[
"Xi"] =
"\\Xi ";
604 mCodePage[
"omikron"] =
"o ";
605 mCodePage[
"Omikron"] =
"O ";
606 mCodePage[
"pi"] =
"\\pi ";
607 mCodePage[
"Pi"] =
"\\Pi ";
608 mCodePage[
"rho"] =
"\\rho ";
609 mCodePage[
"Rho"] =
"\\Rho ";
610 mCodePage[
"sigma"] =
"\\sigma ";
611 mCodePage[
"Sigma"] =
"\\Sigma ";
612 mCodePage[
"\tau"] =
"\\tau ";
613 mCodePage[
"tau"] =
"\\tau ";
614 mCodePage[
"Tau"] =
"\\Tau ";
615 mCodePage[
"ypsilon"] =
"\\upsilon ";
616 mCodePage[
"Ypsilon"] =
"\\Upsilon ";
617 mCodePage[
"phi"] =
"\\varphi ";
618 mCodePage[
"Phi"] =
"\\Phi";
619 mCodePage[
"chi"] =
"\\chi ";
620 mCodePage[
"Chi"] =
"\\Chi ";
621 mCodePage[
"psi"] =
"\\psi ";
622 mCodePage[
"Psi"] =
"\\Psi ";
623 mCodePage[
"omega"] =
"\\omega ";
624 mCodePage[
"Omega"] =
"\\Omega ";
625 mCodePage[
"heaviside"] =
"\\Theta";
626 mCodePage[
"Li2"] =
"Li_2";
627 mCodePage[
"Cl2"] =
"Cl_2";
635 std::map<std::string, std::string> mCodePage;
637 mCodePage[
"*"] =
"\\cdot ";
638 mCodePage[
"+"] =
" + ";
639 mCodePage[
"-"] =
" -- ";
640 mCodePage[
","] =
", ";
641 mCodePage[
"x"] =
"{\\i x}";
642 mCodePage[
"y"] =
"{\\i y}";
643 mCodePage[
"z"] =
"{\\i z}";
644 mCodePage[
"t"] =
"{\\i t}";
663 static std::string sDelimiter =
"+-*/, #()&|!_'";
666 for (
size_t i = 0; i < sReturn.length() - 1; i++)
669 if (sReturn[i] ==
'^' && sReturn[i + 1] !=
'{' && sReturn[i + 1] !=
'(')
672 sReturn = sReturn.substr(0, i) +
"{" + sReturn.substr(i);
674 if (sReturn[i + 1] ==
'-' || sReturn[i + 1] ==
'+')
680 for (
size_t j = i + 1; j < sReturn.length(); j++)
682 if (sDelimiter.find(sReturn[j]) != std::string::npos)
684 sReturn = sReturn.substr(0, j) +
"}" + sReturn.substr(j);
687 else if (j + 1 == sReturn.length())
694 sDelimiter[sDelimiter.length() - 1] =
'^';
697 for (
size_t i = 0; i < sReturn.length() - 1; i++)
700 if (sReturn[i] ==
'_' && sReturn[i + 1] !=
'{')
702 for (
const auto& iter : mCodePage)
704 if (iter.first.front() !=
'_')
707 if (sReturn.substr(i, iter.first.length()) == iter.first
708 && sDelimiter.find(sReturn[i + iter.first.length()]) != std::string::npos)
717 if (sReturn[i] ==
'_' && sReturn[i + 1] !=
'{')
720 sReturn = sReturn.substr(0, i) +
"{" + sReturn.substr(i);
724 for (
unsigned int j = i + 1; j < sReturn.length(); j++)
726 if (sDelimiter.find(sReturn[j]) != std::string::npos)
728 sReturn = sReturn.substr(0, j) +
"}" + sReturn.substr(j);
731 else if (j + 1 == sReturn.length())
753std::string
replaceToTeX(
const std::string& sString,
bool replaceForTeXFile)
755 std::string sReturn =
" " + sString +
" ";
758 static std::map<std::string, std::string> mCodePage =
getTeXCodePage();
762 while ((nPos = sReturn.find(
"gamma(", nPos)) != std::string::npos)
770 sReturn.replace(nPos, nPos+6,
"\\Gamma(");
775 for (
const auto& iter : mCodePage)
781 while ((nPos = sReturn.find(iter.first, nPos)) != string::npos)
784 if (sReturn[nPos - 1] ==
'\\')
787 nPos += iter.first.length();
791 if (sReturn[nPos + iter.first.length()] ==
'_')
797 nPos += iter.first.length();
801 else if (!
checkDelimiter(sReturn.substr(nPos - 1, iter.first.length() + 2)))
804 nPos += iter.first.length();
808 sReturn.replace(nPos, iter.first.length(), iter.second);
809 nPos += iter.second.length();
813 for (
const auto& iter : mSpecialSymbols)
819 while ((nPos = sReturn.find(iter.first, nPos)) != string::npos)
822 if (sReturn[nPos - 1] ==
'\\')
825 nPos += iter.first.length();
829 if (iter.first ==
"*"
830 || (!replaceForTeXFile && !isalpha(iter.first.front())))
834 if (sReturn[nPos - 1] ==
' ')
836 size_t nPos_2 = sReturn.find_last_not_of(
' ', nPos-1)+1;
837 sReturn.erase(nPos_2, nPos - nPos_2);
842 if (sReturn[nPos + 1] ==
' ')
843 sReturn.erase(nPos, sReturn.find_first_not_of(
' ', nPos+1) - nPos);
846 if (iter.first ==
"+" || iter.first ==
"-")
848 if (sReturn[nPos-1] ==
'e' || sReturn[nPos-1] ==
'E')
850 if (isdigit(sReturn[nPos-2]) && isdigit(sReturn[nPos+1]) )
859 || sReturn[nPos-1] ==
'('
860 || sReturn[nPos-1] ==
'['
861 || sReturn[nPos-1] ==
'{'
862 || sReturn[nPos-1] ==
',')
864 if (iter.first ==
"-")
866 sReturn.insert(nPos, 1,
'-');
875 else if (sReturn[nPos + iter.first.length()] ==
'_')
881 nPos += iter.first.length();
885 else if (!
checkDelimiter(sReturn.substr(nPos - 1, iter.first.length() + 2)))
888 nPos += iter.first.length();
892 sReturn.replace(nPos, iter.first.length(), iter.second);
893 nPos += iter.second.length();
903 while ((nPos = sReturn.find(
"sqrt(", nPos)) != string::npos)
906 sReturn.replace(nPos, len + 6,
"@{\\sqrt{" + sReturn.substr(nPos+5, len) +
"}}");
912 while ((nPos = sReturn.find(
"norm(", nPos)) != string::npos)
915 sReturn.replace(nPos, len + 6,
"|" + sReturn.substr(nPos+5, len) +
"|");
921 while ((nPos = sReturn.find(
"abs(", nPos)) != string::npos)
924 sReturn.replace(nPos, len + 5,
"|" + sReturn.substr(nPos+4, len) +
"|");
930 while ((nPos = sReturn.find(
"^(", nPos)) != string::npos)
933 sReturn.replace(nPos+1, len + 2,
"{" + sReturn.substr(nPos+2, len) +
"}");
954 _mMatch.
nPos = string::npos;
962 for (
unsigned int i = nStart; i < sCmd.
length(); i++)
969 if ((sCmd[i] ==
' ' || sCmd[i] ==
'\t' || sCmd[i] ==
'-' || sCmd[i] ==
'=') && _mMatch.
nPos == string::npos)
971 else if ((sCmd[i] ==
' ' || sCmd[i] ==
'-' || sCmd[i] ==
';' || sCmd[i] ==
':') && _mMatch.
nPos != string::npos)
978 _mMatch.
nPos = string::npos;
989 _mMatch.
nPos = string::npos;
995 else if ((sCmd[i] ==
'(') && _mMatch.
nPos != string::npos)
1006 && _mMatch.
sString !=
"elseif"
1007 && _mMatch.
sString !=
"switch"
1009 && _mMatch.
sString !=
"while"))
1012 _mMatch.
nPos = string::npos;
1021 if (_mMatch.
nPos == string::npos)
1027 if (_mMatch.
nPos != string::npos)
1053 _mMatch.
nPos = position;
1056 if (_mMatch.
sString.find(
' ') != string::npos)
1065 if (sCmd.
length() >= sCommand.length() + _mMatch.
nPos + _mMatch.
sString.length())
1088 _mMatch.
nPos = string::npos;
1107 _mMatch.
nPos = string::npos;
1111 if (sCmd.
subview(0,2) ==
"|>")
1115 for (
unsigned int i = nStart; i < sCmd.
length(); i++)
1122 if (sCmd[i] ==
' ' || sCmd[i] ==
'\t' || sCmd[i] ==
'(')
1126 if (sCmd.
subview(i, sCommand.length()) != sCommand)
1130 if (sCmd.
subview(i, sCommand.length()) == sCommand && i)
1133 if (i + sCommand.length() == sCmd.
length() - 1)
1153 _mMatch.
nPos = string::npos;
1162 if (sCmd[i + sCommand.length()] ==
'(' && sCmd.
find(sCommand, i + 1) != string::npos)
1164 else if (sCmd[i + sCommand.length()] ==
'(' && sCmd.
find(sCommand, i + 1) == string::npos)
1168 _mMatch.
nPos = string::npos;
1175 if (sCmd.
find(
'-', i + sCommand.length()) != string::npos)
1184 if (sCmd.
find(
' ', i + sCommand.length()) != string::npos)
1194 if (sCmd.
subview(i, sCommand.length()) == sCommand && !i)
1197 if (sCommand.length() == sCmd.
length() - 1)
1201 _mMatch.
sString =
" " + sCommand.substr(0, sCommand.length() + 1);
1216 _mMatch.
nPos = string::npos;
1226 if (sCmd[i + sCommand.length()] ==
'(' && sCmd.
find(sCommand, i + 1) != string::npos)
1228 else if (sCmd[i + sCommand.length()] ==
'(' && sCmd.
find(sCommand, i + 1) == string::npos)
1231 _mMatch.
nPos = string::npos;
1236 if (sCmd.
find(
'-', i + sCommand.length()) != string::npos)
1245 if (sCmd.
find(
' ', i + sCommand.length()) != string::npos)
1279 _mMatch.
nPos = string::npos;
1284 if (!sCommand.length())
1289 else if (sCommand.length() && (sCmd == sCommand || sCmd == sCommand +
" "))
1299 else if (sCommand.length()
1300 && sCmd.
find(sCommand) != string::npos
1301 && sCmd.
find(
' ', sCmd.
find(sCommand)) != string::npos
1327 string sCommandString =
"";
1330 if (_mMatch.
nPos == string::npos)
1337 for (
int i = _mMatch.
nPos; i >= 0; i--)
1358 if (!sCommandString.length())
1359 sCommandString = sCmd.substr(_mMatch.
nPos);
1362 return sCommandString;
1382 if (_sFile[0] !=
'"')
1383 _sFile =
"\"" + sFile +
"\"";
1390 nErrorCode = (int)ShellExecute(
nullptr,
"open", sFile.c_str(),
nullptr,
nullptr, SW_SHOWNORMAL);
1393 if (nErrorCode <= 32)
1395 if (nErrorCode == SE_ERR_NOASSOC)
1412void moveFile(
const string& sFile,
const string& sNewFileName)
1418 remove(sFile.c_str());
1431void copyFile(
const string& sFile,
const string& sTarget)
1434 ifstream File(sFile.c_str(), ios_base::binary);
1435 ofstream NewFile(sTarget.c_str(), ios_base::binary);
1440 if (!NewFile.good())
1444 NewFile << File.rdbuf();
1451 string sTemp = sTeXFile;
1454 if (sTemp.find(
'\\') != string::npos || sTemp.find(
'/') != string::npos)
1456 if (sTemp.find(
'\\') != string::npos)
1457 sTemp = sTemp.substr(sTemp.rfind(
'\\') + 1);
1458 if (sTemp.find(
'/') != string::npos)
1459 sTemp = sTemp.substr(sTemp.rfind(
'/') + 1);
1463 ofstream TexMain((sTeXFile.substr(0, sTeXFile.find(
".tex")) +
"main.tex").c_str());
1464 if (!TexMain.good())
1468 TexMain <<
"\\documentclass{scrartcl} % KOMA-SCRIPT-KLASSE (Kann durch \"article\" ersetzt werden)" << endl << endl;
1469 TexMain <<
"% Ein paar hilfreiche Packages:" << endl;
1470 TexMain <<
"\\usepackage[utf8]{inputenc} % Sonderzeichen in der Eingabe" << endl;
1471 TexMain <<
"\\usepackage[T1]{fontenc} % Sonderzeichen in der Ausgabe" << endl;
1472 TexMain <<
"\\usepackage[ngerman]{babel} % Deutsch als Dokumentsprache" << endl;
1473 TexMain <<
"\\usepackage{mathpazo} % Palatino als Schriftart (passend zum Plot)" << endl;
1474 TexMain <<
"\\usepackage{tikz} % TikZ fuer die eigentliche Graphik" << endl;
1475 TexMain <<
"% Eigentliches Dokument" << endl;
1476 TexMain <<
"\\begin{document}" << endl;
1477 TexMain <<
"\t% Hier bietet sich ein beschreibender Text an" << endl;
1478 TexMain <<
"\t\\input{";
1480 TexMain <<
"} % Einbinden des Plots" << endl;
1481 TexMain <<
"\t% Mit derselben Syntax wie der vorherigen Zeile koennen auch weitere Plots in diese TeX-Ausgabe eingebunden werden" << endl;
1482 TexMain <<
"\\end{document}" << endl;
1483 TexMain <<
"% EOF" << endl;
1490 remove(
"mglmain.tex");
1506 if (sCmd.substr(pos, 2) ==
" ")
1507 return std::string::npos;
1509 size_t nextChar = sCmd.find_first_not_of(
' ', pos+1);
1511 if (nextChar == std::string::npos || sCmd[nextChar] !=
'+')
1512 return std::string::npos;
1516 if (sCmd.length() > nextChar && sCmd[nextChar] !=
' ')
1521 if (sCmd.length() > nextChar && sCmd[nextChar] !=
' ')
1524 return std::string::npos;
1574 for (
int i = 0; i < results; i++)
1598string getArgAtPos(
const string& sCmd,
unsigned int nPos,
int extraction)
1600 string sArgument =
"";
1604 if (nPos >= sCmd.length())
1608 while (nPos < sCmd.length() && sCmd[nPos] ==
' ')
1612 if (nPos >= sCmd.length())
1617 for (
size_t i = nPos; i < sCmd.length(); i++)
1619 if (sCmd[i] ==
'"' && (!i || sCmd[i - 1] !=
'\\'))
1625 if (sCmd[i] ==
'(' || sCmd[i] ==
'[' || sCmd[i] ==
'{')
1636 sArgument = sCmd.substr(nPos, i-nPos);
1640 else if (i+1 == sCmd.length())
1641 sArgument = sCmd.substr(nPos);
1653 if (sArgument.front() ==
'"' && sArgument.back() ==
'"')
1654 sArgument = sArgument.substr(1, sArgument.length()-2);
1677 for (
size_t i = 0; i < nPos; i++)
1680 if (sExpr.
subview(i, 12) ==
"string_cast(" && i + 12 <= nPos)
1690 if (sExpr[i] ==
'"' && (!i || sExpr[i-1] !=
'\\'))
1700 if (!bIgnoreVarParser)
1703 if (sExpr.
rfind(
'#', nPos) == string::npos)
1713 for (
unsigned int i = sExpr.
rfind(
'#', nPos); i < nPos; i++)
1717 if (sExpr[i] ==
'(')
1736 if (sExpr[i] ==
' ' || sExpr[i] ==
'+' || sExpr[i] ==
',' || sExpr[i] ==
')')
1741 if (nPos < sExpr.
length() - 1 && (sExpr[nPos] ==
',' || sExpr[nPos] ==
'+' || sExpr[nPos] ==
' ' || sExpr[nPos] ==
')'))
1743 else if (nPos == sExpr.
length() - 1 && sExpr[nPos] ==
')')
1769 if (sExpr.find(
"valtostr(") == string::npos && sExpr.find(
"to_string(") == string::npos && sExpr.find(
"string_cast(") == string::npos)
1773 for (
int i = nPos; i >= 8; i--)
1779 if (i > 10 && sExpr.substr(i - 11, 12) ==
"string_cast(")
1781 else if (i > 8 && sExpr.substr(i - 9, 10) ==
"to_string(")
1783 else if (sExpr.substr(i - 8, 9) ==
"valtostr(")
1808 if (fabs(number -
rint(number)) < 1e-7)
1809 return rint(number);
1811 return static_cast<int>(number);
1824long long int intCast(
const std::complex<double>& number)
1826 return intCast(number.real());
1838bool isInt(
const std::complex<double>& number)
1840 return number.imag() == 0.0 && fabs(number.real() -
rint(number.real())) < 1e-12;
1855 return c >= 32 && c <= 125 && c != 36 && c != 39 && c != 46 && (c < 48 || c > 57) && (c < 64 || c > 90) && (c < 95 || c > 122);
1885 for (
size_t i = 0; i < args.size(); i++)
1893 if (args[i].find(
'"') != std::string::npos)
1899 size_t nPos = args[i].find(
'"') + 1;
1902 if (args[i].find(
'"', nPos) != std::string::npos)
1905 if (args[i].find(
'#', nPos) != std::string::npos)
1908 sTemp += args[i] +
"+\"\"";
1916 else if (args[i].find(
'#') != string::npos)
1921 size_t nPos = args[i].find(
'#');
1929 for (
size_t j = nPos; j < args[i].length(); j++)
1931 if (args[i][j] ==
'(')
1934 if (args[i][j] ==
' ')
1936 sTemp += args[i].insert(j,
"+\"\"");
1939 else if (j+1 == args[i].length())
1941 sTemp += args[i] +
"+\"\"";
1951 std::string sLabel = args[i];
1959 sTemp += args[i] +
" \"" + sLabel +
"\"";
1962 if (i+1 < args.size())
1985 return isDelimiter(sString.front()) && (
isDelimiter(sString.back()) || (sString.back() ==
'.' && stringdelim));
2002std::vector<std::string>
splitIntoLines(std::string sOutput,
size_t lineWidth,
bool bAllowDashBreaks,
int nFirstIndent,
int nIndent)
2005 std::vector<std::string> outputInLines;
2008 unsigned int nLastLineBreak = 0;
2014 if ((sOutput.substr(0, 4) ==
"| " || sOutput.substr(0, 4) ==
"|-> ") && nFirstIndent == 4)
2018 if (sOutput.length() < lineWidth - nFirstIndent && sOutput.find(
'$') == string::npos && sOutput.find(
"\\n") == string::npos && sOutput.find(
'\n') == string::npos)
2020 outputInLines.push_back(sOutput);
2021 return outputInLines;
2025 for (
unsigned int i = 1; i < sOutput.length(); i++)
2028 if (sOutput[i] ==
'$' && sOutput[i - 1] !=
'\\')
2031 if (sOutput[i] ==
'n' && sOutput[i - 1] ==
'\\')
2033 if ((i == 1 || sOutput[i - 2] !=
'\\')
2034 && !(sOutput.substr(i, 2) ==
"nu" &&
checkDelimiter(sOutput.substr(i - 1, 4)))
2035 && !(sOutput.substr(i, 3) ==
"neq" &&
checkDelimiter(sOutput.substr(i - 1, 5))))
2037 else if (i != 1 && sOutput[i - 2] !=
'\\')
2038 sOutput.insert(i,
"\\");
2041 if (sOutput[i] ==
'\n')
2047 if ((i == lineWidth - nFirstIndent && !nLastLineBreak) || (nLastLineBreak && i - nLastLineBreak == lineWidth - nIndent))
2050 for (
unsigned int j = i; j > nLastLineBreak; j--)
2052 if (sOutput[j] ==
' ')
2054 if (sOutput[j - 1] ==
'\\')
2056 sOutput.insert(j + 1,
"$");
2057 nLastLineBreak = j + 1;
2066 else if (sOutput[j] ==
'-' && bAllowDashBreaks && j != i)
2070 (sOutput[j - 1] ==
' '
2071 || sOutput[j - 1] ==
'('
2072 || sOutput[j + 1] ==
')'
2073 || sOutput[j - 1] ==
'['
2074 || (sOutput[j + 1] >=
'0' && sOutput[j + 1] <=
'9')
2075 || sOutput[j + 1] ==
','
2076 || (sOutput[j + 1] ==
'"' && sOutput[j - 1] ==
'"')
2079 sOutput.insert(j + 1, 1,
'\n');
2080 nLastLineBreak = j + 1;
2083 else if (sOutput[j] ==
',' && bAllowDashBreaks && sOutput[j + 1] !=
' ' && j != i)
2086 nLastLineBreak = j + 1;
2089 else if (sOutput[j] ==
'$' && sOutput[j - 1] !=
'\\')
2094 if (j - 1 == nLastLineBreak)
2096 string sDelim =
"+-*/";
2097 for (
unsigned int n = i; n > nLastLineBreak; n--)
2099 if (sDelim.find(sOutput[n]) != string::npos)
2101 sOutput = sOutput.substr(0, n) +
'$' + sOutput.substr(n);
2105 if (n - 1 == nLastLineBreak)
2107 sOutput = sOutput.substr(0, i - 1) +
'$' + sOutput.substr(i - 1);
2117 size_t lastBreak = 0;
2118 for (
unsigned int i = 0; i < sOutput.length(); i++)
2120 if (sOutput[i] ==
'$' && sOutput[i - 1] !=
'\\')
2123 outputInLines.push_back(sOutput.substr(lastBreak, i - lastBreak));
2127 else if (sOutput[i] ==
'\n')
2129 outputInLines.push_back(sOutput.substr(lastBreak, i - lastBreak));
2133 else if (sOutput[i] ==
'n' && sOutput[i - 1] ==
'\\' && sOutput[i - 2] !=
'\\')
2134 sOutput = sOutput.substr(0, i - 1) +
"\n" + sOutput.substr(i + 1);
2135 else if (sOutput[i] ==
'n' && sOutput[i - 1] ==
'\\' && sOutput[i - 2] ==
'\\')
2136 sOutput.erase(i - 1, 1);
2137 else if (sOutput[i] ==
'$' && sOutput[i - 1] ==
'\\')
2138 sOutput.erase(i - 1, 1);
2139 else if (sOutput[i] ==
'%' && bAllowDashBreaks)
2142 sOutput = sOutput.substr(0, i) +
",\n" + sOutput.substr(i + 1);
2147 outputInLines.push_back(sOutput.substr(lastBreak));
2149 return outputInLines;
2164std::string
outputString(std::vector<std::string> stringInLines,
int nFirstIndent,
int nIndent)
2166 std::string sOutput =
"";
2169 if (!stringInLines.size())
2173 if ((sOutput.substr(0, 4) ==
"| " || sOutput.substr(0, 4) ==
"|-> ") && nFirstIndent == 4)
2177 sOutput.append(stringInLines[0]);
2180 std::string sIndent =
"\n|";
2181 for (
int i = 1; i < nIndent; i++)
2185 for (
size_t i = 1; i < stringInLines.size(); i++)
2186 sOutput.append(sIndent + stringInLines[i]);
2205std::string
LineBreak(std::string sOutput,
const Settings& _option,
bool bAllowDashBreaks,
int nFirstIndent,
int nIndent)
2222double Linearize(
double x_0,
double y_0,
double x_1,
double y_1)
2225 double m = (y_1 - y_0) / (x_1 - x_0);
2248 size_t nMatching = 0;
2252 for (
size_t i = 0; i < sArgList.
length(); i++)
2254 if (sArgList[i] ==
'"' && (!i || sArgList[i-1] !=
'\\'))
2261 if ((sArgList[i] ==
'(' || sArgList[i] ==
'[' || sArgList[i] ==
'{' ) && (nMatching =
getMatchingParenthesis(sArgList.
subview(i))) != string::npos)
2265 if (sArgList[i] == cSep)
2273 if (!nPos && sArgList[0] != cSep)
2274 nPos = sArgList.
length();
2279 if (sArgList[0] == cSep)
2350 while (sArgList.
length())
2369 while (sArgList.length())
2388 while (sArgList.length())
2407 while (sArgList.length())
2446 for (
auto iter = mClusterMap.begin(); iter != mClusterMap.end(); ++iter)
2448 if (iter->second.isString())
2450 size_t pos = sLine.find(iter->first +
"{");
2452 if (pos != string::npos && (!pos ||
isDelimiter(sLine[pos-1])))
2472 if (!sLine.length())
2477 if (sLine.find_first_of(
"\"#") != string::npos
2478 || sLine.find(
"string(") != string::npos
2479 || sLine.find(
"string_cast(") != string::npos
2480 || sLine.find(
"char(") != string::npos
2481 || sLine.find(
"getlasterror(") != string::npos
2482 || sLine.find(
"getversioninfo(") != string::npos
2483 || sLine.find(
"valtostr(") != string::npos
2484 || sLine.find(
"weekday(") != string::npos
2485 || sLine.find(
"to_tex(") != std::string::npos)
2502 if (sFilename.length())
2504 string _sFile = sFilename;
2508 ifstream ifFile(_sFile.c_str());
2509 return ifFile.good();
2527void eraseToken(
string& sExpr,
const string& sToken,
bool bTokenHasValue)
2529 unsigned int nLength = sToken.length();
2539 for (
unsigned int i =
findParameter(sExpr, sToken,
'=') + nLength - 1; i < sExpr.length(); i++)
2542 if (sExpr[i] ==
'=')
2545 for (
unsigned int j = sExpr.find_first_not_of(
"= ", i); j < sExpr.length(); j++)
2548 if (!
isInQuotes(sExpr, j) && (sExpr[j] ==
'(' || sExpr[j] ==
'[' || sExpr[j] ==
'{'))
2553 if (sExpr[j] ==
' ')
2586 vector<string> vResolved;
2587 vResolved.push_back(sDirectory);
2589 unsigned int nSize = 0, nth_choose = 0;
2590 bool bResolvingPath =
false;
2593 if (sDirectory.find(
'|') != string::npos)
2596 while (vResolved[0].find(
'|') != string::npos)
2599 if (!vResolved[0].rfind(
'<'))
2603 sToken = vResolved[0].substr(vResolved[0].rfind(
'<') + 1);
2604 sToken.erase(sToken.find(
'>'));
2607 nSize = vResolved.size();
2611 while (sToken.find(
'|') != string::npos || sToken.length())
2614 if (sToken.find(
'|') != string::npos)
2617 for (
unsigned int i = 0; i < nSize; i++)
2618 vResolved.push_back(vResolved[i + nth_choose * nSize]);
2622 for (
unsigned int i = nth_choose * nSize; i < (nth_choose + 1)*nSize; i++)
2624 if (!bResolvingPath && vResolved[i].rfind(
'/') != string::npos && vResolved[i].rfind(
'/') > vResolved[i].rfind(
'>'))
2625 bResolvingPath =
true;
2626 vResolved[i].replace(vResolved[i].rfind(
'<'), vResolved[i].rfind(
'>') + 1 - vResolved[i].rfind(
'<'), sToken.substr(0, sToken.find(
'|')));
2631 && ((vResolved[nth_choose * nSize].find(
'*') != string::npos && vResolved[nth_choose * nSize].find(
'*') < vResolved[nth_choose * nSize].rfind(
'/'))
2632 || (vResolved[nth_choose * nSize].find(
'?') != string::npos && vResolved[nth_choose * nSize].find(
'?') < vResolved[nth_choose * nSize].rfind(
'/'))))
2636 vector<string> vFolderList =
getFolderList(vResolved[nth_choose * nSize].substr(0, vResolved[nth_choose * nSize].rfind(
'/')), _option, 1);
2639 for (
unsigned int j = 0; j < vFolderList.size(); j++)
2641 if ((vFolderList[j].length() >= 3 && vFolderList[j].substr(vFolderList[j].length() - 3) ==
"/..")
2642 || (vFolderList[j].length() >= 2 && vFolderList[j].substr(vFolderList[j].length() - 2) ==
"/."))
2644 vFolderList.erase(vFolderList.begin() + j);
2652 if (!vFolderList.size())
2654 bResolvingPath =
false;
2656 if (sToken.find(
'|') != string::npos)
2657 sToken.erase(0, sToken.find(
'|') + 1);
2667 for (
unsigned int j = 0; j < vFolderList.size(); j++)
2670 if (vFolderList.size() > 1 && j < vFolderList.size() - 1)
2673 if (vResolved.size() > (nth_choose + 1)*nSize)
2675 for (
unsigned int k = 0; k < nSize; k++)
2677 vResolved.push_back(vResolved[k + (nth_choose + 1)*nSize]);
2678 vResolved[k + (nth_choose + 1)*nSize] = vResolved[k + nth_choose * nSize];
2683 for (
unsigned int k = 0; k < nSize; k++)
2685 vResolved.push_back(vResolved[(nth_choose)*nSize]);
2691 for (
unsigned int k = nth_choose * nSize; k < (nth_choose + 1)*nSize; k++)
2693 vResolved[k].replace(0, vResolved[k].rfind(
'/'), vFolderList[j]);
2697 if (vFolderList.size() > 1 && j < vFolderList.size() - 1)
2703 bResolvingPath =
false;
2705 if (sToken.find(
'|') != string::npos)
2706 sToken.erase(0, sToken.find(
'|') + 1);
2717 if (vResolved[0].find(
'/') != string::npos
2718 && ((vResolved[0].find(
'*') != string::npos && vResolved[0].find(
'*') < vResolved[0].rfind(
'/'))
2719 || (vResolved[0].find(
'?') != string::npos && vResolved[0].find(
'?') < vResolved[0].rfind(
'/'))))
2722 vector<string> vFolderList =
getFolderList(vResolved[0].substr(0, vResolved[0].rfind(
'/')), _option, 1);
2725 nSize = vResolved.size();
2728 for (
unsigned int j = 0; j < vFolderList.size(); j++)
2730 if ((vFolderList[j].length() >= 3 && vFolderList[j].substr(vFolderList[j].length() - 3) ==
"/..")
2731 || (vFolderList[j].length() >= 2 && vFolderList[j].substr(vFolderList[j].length() - 2) ==
"/."))
2733 vFolderList.erase(vFolderList.begin() + j);
2741 if (!vFolderList.size())
2745 for (
unsigned int i = 0; i < vFolderList.size() - 1; i++)
2748 if (vFolderList[i].find(
'*') != string::npos || vFolderList[i].find(
'?') != string::npos || !vFolderList[i].size())
2752 for (
unsigned int k = 0; k < nSize; k++)
2754 vResolved.push_back(vResolved[k]);
2760 for (
unsigned int j = 0; j < vFolderList.size(); j++)
2763 if (vFolderList[j].find(
'*') != string::npos || vFolderList[j].find(
'?') != string::npos || !vFolderList[j].size())
2767 for (
unsigned int k = j * nSize; k < (j + 1)*nSize; k++)
2769 vResolved[k].replace(0, vResolved[k].rfind(
'/'), vFolderList[j]);
2791 HANDLE hFind = INVALID_HANDLE_VALUE;
2798 hFind = FindFirstFile((_option.
getExePath() +
"\\" + sDir).c_str(), FindFileData);
2800 sDir.erase(sDir.rfind(
'/') + 1);
2802 else if (sDir[0] ==
'<')
2805 if (sDir.substr(0, 10) ==
"<loadpath>")
2806 sPath = _option.
getLoadPath() + sDir.substr(sDir.find(
'>') + 1);
2807 else if (sDir.substr(0, 10) ==
"<savepath>")
2808 sPath = _option.
getSavePath() + sDir.substr(sDir.find(
'>') + 1);
2809 else if (sDir.substr(0, 12) ==
"<scriptpath>")
2810 sPath = _option.
getScriptPath() + sDir.substr(sDir.find(
'>') + 1);
2811 else if (sDir.substr(0, 10) ==
"<plotpath>")
2812 sPath = _option.
getPlotPath() + sDir.substr(sDir.find(
'>') + 1);
2813 else if (sDir.substr(0, 10) ==
"<procpath>")
2814 sPath = _option.
getProcPath() + sDir.substr(sDir.find(
'>') + 1);
2815 else if (sDir.substr(0, 2) ==
"<>")
2816 sPath = _option.
getExePath() + sDir.substr(sDir.find(
'>') + 1);
2817 else if (sDir.substr(0, 6) ==
"<this>")
2818 sPath = _option.
getExePath() + sDir.substr(sDir.find(
'>') + 1);
2819 else if (sDir.substr(0, 4) ==
"<wp>")
2820 sPath = _option.
getWorkPath() + sDir.substr(sDir.find(
'>') + 1);
2825 hFind = FindFirstFile(sPath.c_str(), FindFileData);
2827 sDir.erase(sDir.rfind(
'/') + 1);
2833 hFind = FindFirstFile(sDir.c_str(), FindFileData);
2834 if (sDir.find(
'/') != string::npos)
2835 sDir.erase(sDir.rfind(
'/') + 1);
2855 vector<string> vFileList;
2856 vector<string> vDirList;
2865 for (
unsigned int i = 0; i < vDirList.size(); i++)
2870 if (sDir.rfind(
'.') == string::npos && sDir.find(
'*') == string::npos && sDir.find(
'?') == string::npos)
2872 if (sDir[sDir.find_last_not_of(
' ')] !=
'/')
2876 else if ((sDir.find(
'.') == string::npos
2877 || (sDir.find(
'.') != string::npos && sDir.find(
'/', sDir.rfind(
'.')) != string::npos))
2878 && sDir.back() !=
'*')
2882 WIN32_FIND_DATA FindFileData;
2886 if (hFind == INVALID_HANDLE_VALUE)
2894 if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2899 vFileList.push_back(sDir + FindFileData.cFileName);
2901 vFileList.push_back(FindFileData.cFileName);
2903 while (FindNextFile(hFind, &FindFileData) != 0);
2927 vector<string> vFileList;
2928 vector<string> vDirList;
2937 for (
unsigned int i = 0; i < vDirList.size(); i++)
2942 if (sDir.rfind(
'.') == string::npos && sDir.find(
'*') == string::npos && sDir.find(
'?') == string::npos)
2944 if (sDir[sDir.find_last_not_of(
' ')] !=
'/')
2948 else if ((sDir.find(
'.') == string::npos
2949 || (sDir.find(
'.') != string::npos && sDir.find(
'/', sDir.rfind(
'.')) != string::npos))
2950 && sDir.back() !=
'*')
2954 WIN32_FIND_DATA FindFileData;
2958 if (hFind == INVALID_HANDLE_VALUE)
2966 if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2970 vFileList.push_back(sDir + FindFileData.cFileName);
2972 vFileList.push_back(FindFileData.cFileName);
2978 while (FindNextFile(hFind, &FindFileData) != 0);
3003 const size_t MAXLINES = 100000;
3004 const size_t MINLINES = 20000;
3007 fFile.open(sFileName.c_str(), ios_base::binary | ios_base::in);
3012 while (!fFile.eof())
3014 getline(fFile, sTemp);
3023 if (nLines >= MAXLINES)
3028 fTemp.open(
"$~tempfile.txt", ios_base::binary | ios_base::out);
3033 for (
unsigned int i = 0; i < nLines; i++)
3035 getline(fFile, sTemp);
3036 if (nLines - i > MINLINES)
3038 fTemp << sTemp << endl;
3047 fTemp.open(
"$~tempfile.txt", ios_base::binary | ios_base::in);
3048 fFile.open(sFileName.c_str(),
ios_base::trunc | ios_base::binary | ios_base::out);
3053 fFile << fTemp.rdbuf();
3058 remove(
"$~tempfile.txt");
3075 mOprtRplc[
"("] =
"[";
3076 mOprtRplc[
")"] =
"]";
3077 mOprtRplc[
":"] =
"~c~";
3078 mOprtRplc[
","] =
"_";
3079 mOprtRplc[
"."] =
"_";
3080 mOprtRplc[
"+"] =
"~p~";
3081 mOprtRplc[
"-"] =
"~m~";
3082 mOprtRplc[
"*"] =
"~ml~";
3083 mOprtRplc[
"/"] =
"~d~";
3084 mOprtRplc[
"^"] =
"~e~";
3085 mOprtRplc[
"{"] =
"~ob~";
3086 mOprtRplc[
"}"] =
"~cb~";
3087 mOprtRplc[
"&"] =
"~a~";
3088 mOprtRplc[
"|"] =
"~o~";
3089 mOprtRplc[
"%"] =
"~md~";
3090 mOprtRplc[
"!"] =
"~n~";
3091 mOprtRplc[
"="] =
"~eq~";
3092 mOprtRplc[
">"] =
"~g~";
3093 mOprtRplc[
"<"] =
"~l~";
3094 mOprtRplc[
"?"] =
"~q~";
3110 string sVectorName = sExpression;
3111 static map<string, string> mOprtRplc;
3114 if (!mOprtRplc.size())
3118 while (sVectorName.find(
' ') != string::npos)
3119 sVectorName.erase(sVectorName.find(
' '), 1);
3122 for (
auto iter = mOprtRplc.begin(); iter != mOprtRplc.end(); ++iter)
3124 while (sVectorName.find(iter->first) != string::npos)
3125 sVectorName.replace(sVectorName.find(iter->first), (iter->first).length(), iter->second);
3128 if (sVectorName.find(
'[') == string::npos)
3129 sVectorName +=
"[]";
3132 return "_~" + sVectorName;
3149 if (sExpr.substr(nPos, 3) ==
"**=")
3152 if (sExpr.find(
',', nPos) != string::npos)
3158 for (
unsigned int j = nPos; j < sExpr.length(); j++)
3162 && (sExpr[j] ==
'(' || sExpr[j] ==
'[' || sExpr[j] ==
'{'))
3166 if (sExpr[j] ==
'"')
3168 if (j && sExpr[j - 1] ==
'\\')
3178 if (sExpr[j] ==
',' || j + 1 == sExpr.length())
3181 if (j + 1 != sExpr.length())
3186 sExpr = sExpr.substr(0, nPos)
3188 + sExpr.substr(0, nPos)
3189 + sExpr.substr(nPos, nLength-1)
3191 + sExpr.substr(nPos + nLength, j - nPos - nLength)
3197 sExpr = sExpr.substr(0, nPos)
3199 + sExpr.substr(nArgSepPos + 1, nPos - nArgSepPos - 1)
3200 + sExpr.substr(nPos, nLength-1)
3202 + sExpr.substr(nPos + nLength, j - nPos - nLength)
3212 sExpr = sExpr.substr(0, nPos)
3214 + sExpr.substr(0, nPos)
3215 + sExpr.substr(nPos, nLength-1)
3217 + sExpr.substr(nPos + nLength)
3222 sExpr = sExpr.substr(0, nPos)
3224 + sExpr.substr(nArgSepPos + 1, nPos - nArgSepPos - 1)
3225 + sExpr.substr(nPos, nLength-1)
3227 + sExpr.substr(nPos + nLength)
3236 for (
unsigned int k = nPos; k < sExpr.length(); k++)
3240 && (sExpr[k] ==
'(' || sExpr[k] ==
'[' || sExpr[k] ==
'{'))
3244 if (sExpr[k] ==
'"')
3246 if (k && sExpr[k - 1] ==
'\\')
3258 if (sExpr[k] ==
',')
3276 sExpr = sExpr.substr(0, nPos)
3278 + sExpr.substr(0, nPos)
3279 + sExpr.substr(nPos, nLength-1)
3281 + sExpr.substr(nPos + nLength)
3286 sExpr = sExpr.substr(0, nPos)
3288 + sExpr.substr(nArgSepPos + 1, nPos - nArgSepPos - 1)
3289 + sExpr.substr(nPos, nLength-1)
3291 + sExpr.substr(nPos + nLength)
3318 sExpr = sExpr.substr(0, nPos)
3320 + sExpr.substr(0, nPos)
3323 + sExpr.substr(nPos + 2);
3327 sExpr = sExpr.substr(0, nPos)
3329 + sExpr.substr(nArgSepPos + 1, nPos - nArgSepPos - 1)
3332 + sExpr.substr(nPos + 2);
3349 if (sExpr.substr(0, 3) ==
"if "
3350 || sExpr.substr(0, 3) ==
"if("
3351 || sExpr.substr(0, 7) ==
"elseif "
3352 || sExpr.substr(0, 7) ==
"elseif("
3353 || sExpr.substr(0, 5) ==
"else "
3354 || sExpr.substr(0, 7) ==
"switch "
3355 || sExpr.substr(0, 7) ==
"switch("
3356 || sExpr.substr(0, 5) ==
"case "
3357 || sExpr.substr(0, 8) ==
"default:"
3358 || sExpr.substr(0, 4) ==
"for "
3359 || sExpr.substr(0, 4) ==
"for("
3360 || sExpr.substr(0, 6) ==
"while "
3361 || sExpr.substr(0, 6) ==
"while(")
3364 unsigned int nArgSepPos = 0;
3366 bool bAnswerSuppressor =
false;
3369 if (sExpr.find_last_not_of(
" \t") != string::npos && sExpr[sExpr.find_last_not_of(
" \t")] ==
';')
3371 sExpr.erase(sExpr.find_last_not_of(
" \t"));
3372 bAnswerSuppressor =
true;
3376 for (
unsigned int i = 0; i < sExpr.length(); i++)
3380 && (sExpr[i] ==
'(' || sExpr[i] ==
'{' || sExpr[i] ==
'['))
3383 if (parens != string::npos)
3388 if (sExpr[i] ==
'"')
3390 if (i && sExpr[i - 1] ==
'\\')
3401 if (sExpr[i] ==
',')
3408 if (sExpr.substr(i, 2) ==
"+="
3409 || sExpr.substr(i, 2) ==
"-="
3410 || sExpr.substr(i, 3) ==
"**="
3411 || sExpr.substr(i, 2) ==
"*="
3412 || sExpr.substr(i, 2) ==
"/="
3413 || sExpr.substr(i, 2) ==
"^=")
3421 if (sExpr.substr(i, 2) ==
"++" || sExpr.substr(i, 2) ==
"--")
3429 if (bAnswerSuppressor)
3467 sFileInfo +=
"\n" + info.
sComment.substr(0, 200) +
"...";
3478 string sNameSpace =
"";
3480 if (sCommandLine.find(
"namespace") != string::npos)
3482 sCommandLine.erase(0, sCommandLine.find(
"namespace") + 9);
3484 while (sCommandLine.back() ==
'\r' || sCommandLine.back() ==
'\n')
3485 sCommandLine.pop_back();
3489 if (sCommandLine.substr(0, 5) ==
"this~" || sCommandLine ==
"this")
3490 sCommandLine.replace(0, 4, sThisNameSpace);
3492 while (sCommandLine.back() ==
'~')
3493 sCommandLine.pop_back();
3495 if (sCommandLine !=
"main")
3496 sNameSpace = sCommandLine;
3516 int nBracketCount = 0;
3520 for (
size_t i = 0; i < sCmd.length(); i++)
3524 if (sCmd[i] ==
'"' && (!i || sCmd[i - 1] !=
'\\'))
3533 else if (sCmd[i] ==
')')
3535 else if (sCmd[i] ==
'{')
3537 else if (sCmd[i] ==
'}')
3539 else if (sCmd[i] ==
'[')
3541 else if (sCmd[i] ==
']')
3547 return !((bool)nParCount || (
bool)nVectCount || (bool)nBracketCount);
3583 while (sToAdd[pos] ==
' ')
3587 if (!
containsStrings(sToAdd.substr(pos, sToAdd.find(
' ', pos) - pos)))
3590 sToAdd = sToAdd.substr(0, pos)
3592 + sToAdd.substr(sToAdd.find(
' ', sToAdd.find(
getArgAtPos(sToAdd, pos)) +
getArgAtPos(sToAdd, pos).length()));
3609 long double dResult = 1.0L;
3616 for (
int i =
abs(nExponent); i > 0; i--)
3618 dResult *= (
long double)dNumber;
3625 return 1.0 / dResult;
3640std::complex<double>
intPower(
const std::complex<double>& dNumber,
int nExponent)
3642 if (dNumber.imag() == 0.0)
3643 return intPower(dNumber.real(), nExponent);
3645 std::complex<double> dResult = 1.0;
3652 for (
int i =
abs(nExponent); i > 0; i--)
3661 return 1.0 / dResult;
3675bool isToCmd(
const string& sCmd,
unsigned int nPos)
3678 if (nPos < 6 || nPos >= sCmd.length())
3680 if (sCmd.find(
"to_cmd(") == string::npos || sCmd.find(
"to_cmd(") > nPos)
3684 for (
int i = nPos - 6; i >= 0; i--)
3686 if (sCmd.substr(i, 7) ==
"to_cmd(" && !
isInQuotes(sCmd, i))
3710 unsigned int nCount = 0;
3713 for (
unsigned int i = 0; i < sLine.length(); i++)
3716 if (sLine.substr(i, 2) ==
"\\$")
3736 if (
isnan(*(
double*)p1) &&
isnan(*(
double*)p2))
3739 if (
isnan(*(
double*)p1))
3742 if (
isnan(*(
double*)p2))
3745 return *(
double*)p1 == *(
double*)p2
3747 : -(*(
double*)p1 < *(
double*)p2) + (*(
double*)p1 > *(
double*)p2);
3765 qsort((
void*)dArray, nlength,
sizeof(
double),
compareDouble);
3768 for (
int i = nlength - 1; i >= 0; i--)
3791static void replaceSearchMethods(
string& sLine,
size_t nPos,
size_t nFinalPos,
const string& sReplacement,
const string& sMethod,
string& sArgument)
3795 if (sArgument ==
"()")
3796 sArgument =
"(" + sReplacement +
", " + sReplacement +
")";
3797 else if (sArgument.find(
',') == string::npos)
3798 sArgument.insert(sArgument.length()-1,
", " + sReplacement +
"");
3802 sArgument.erase(0,1);
3804 sTemp +=
", " + sReplacement;
3806 if (sArgument[sArgument.find_first_not_of(
' ')] ==
')')
3807 sArgument = sTemp +
")";
3809 sArgument = sTemp +
", " + sArgument;
3813 if (sMethod ==
"fnd")
3814 sLine.replace(nPos, nFinalPos-nPos,
"strfnd" + sArgument);
3815 else if (sMethod ==
"rfnd")
3816 sLine.replace(nPos, nFinalPos-nPos,
"strrfnd" + sArgument);
3817 else if (sMethod ==
"mtch")
3818 sLine.replace(nPos, nFinalPos-nPos,
"strmatch" + sArgument);
3819 else if (sMethod ==
"rmtch")
3820 sLine.replace(nPos, nFinalPos-nPos,
"strrmatch" + sArgument);
3821 else if (sMethod ==
"nmtch")
3822 sLine.replace(nPos, nFinalPos-nPos,
"str_not_match" + sArgument);
3823 else if (sMethod ==
"nrmtch")
3824 sLine.replace(nPos, nFinalPos-nPos,
"str_not_rmatch" + sArgument);
3843static void replaceAccessMethods(
string& sLine,
size_t nPos,
size_t nFinalPos,
const string& sReplacement,
const string& sMethod,
string& sArgument)
3847 if (sArgument ==
"()")
3848 sArgument =
"(" + sReplacement +
", 1)";
3850 sArgument.insert(1, sReplacement +
", ");
3853 if (sMethod ==
"at")
3854 sLine.replace(nPos, nFinalPos-nPos,
"char" + sArgument);
3855 else if (sMethod ==
"sub")
3856 sLine.replace(nPos, nFinalPos-nPos,
"substr" + sArgument);
3857 else if (sMethod ==
"splt")
3858 sLine.replace(nPos, nFinalPos-nPos,
"split" + sArgument);
3878 if (sLine[nPos+nLength] !=
'.')
3880 sLine.replace(nPos, nLength, sReplacement);
3884 static const string sDELIMITER =
"+-*/ ={}^&|!,\\%#?:\";";
3885 string sMethod =
"";
3886 string sArgument =
"";
3887 size_t nFinalPos = 0;
3892 for (
size_t i = nPos+nLength+1; i < sLine.length(); i++)
3894 if (sLine[i] ==
'(')
3897 sMethod = sLine.substr(nPos+nLength+1, i-(nPos+nLength+1));
3902 else if (sDELIMITER.find(sLine[i]) != string::npos)
3905 sMethod = sLine.substr(nPos+nLength+1, i-(nPos+nLength+1));
3913 if (!sArgument.length())
3918 if (sMethod ==
"len")
3921 sLine.replace(nPos, nFinalPos-nPos,
"strlen(" + sReplacement +
")");
3923 else if (sMethod ==
"at"
3925 || sMethod ==
"splt")
3930 else if (sMethod ==
"fnd"
3931 || sMethod ==
"rfnd"
3932 || sMethod ==
"mtch"
3933 || sMethod ==
"rmtch"
3934 || sMethod ==
"nmtch"
3935 || sMethod ==
"nrmtch")
3955 size_t nPos = std::string::npos;
3959 while (sFileName.rfind(
'/', nPos) != string::npos)
3961 nPos = sFileName.rfind(
'/', nPos);
3963 if (nPos != 0 && nPos-1 !=
':')
3965 size_t nPos_2 = sFileName.rfind(
'/', nPos-1);
3967 if (nPos_2 != string::npos)
3969 sFileName = sFileName.substr(0,nPos_2+1) +
".." + sFileName.substr(nPos);
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
This class extends the std::vector for endlessness.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
const std::map< std::string, Cluster > & getClusterMap() const
This class resembles the binary NumeRe data file format. The data is red and written in binary mode u...
void readFileInformation()
Reads only the header of the referenced file.
virtual FileHeaderInfo getFileHeaderInformation() override
Returns the file header information structure.
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...
This class provides the interface to the core of NumeRe. It provides all functionalities,...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
MemoryManager & getMemoryManager()
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.
FunctionDefinitionManager & getDefinitions()
This class manages the setting values of the internal (kernel) settings of this application.
std::string getLoadPath() const
Returns the current loading path.
std::string getWorkPath() const
Returns the current working path (connected to the <wp> token).
std::string getSavePath() const
Returns the current saving path.
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
std::string getProcPath() const
Returns the current procedure root import path.
std::string getPlotPath() const
Returns the current plotting path (plot storing location).
std::string getExePath() const
Returns the current application root folder path.
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
std::string getScriptPath() const
Returns the current script import folder path.
size_t rfind(const std::string &findstr, size_t pos=std::string::npos) const
Wrapper member function for std::string::rfind()
void strip()
This member function shrinks the viewed section to remove all leading or trailing whitespace characte...
void trim_front(size_t len)
This member function can be used to remove characters from the front of the viewed section.
size_t find_first_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_of()
std::string to_string() const
This member function returns a copy of the viewed section of the string (via std::string::substr)....
size_t find(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find()
size_t length() const
This member function simply returns the length of the viewed section.
size_t find_first_not_of(const std::string &findstr, size_t pos=0) const
Wrapper member function for std::string::find_first_not_of()
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
StringView subview(size_t pos=0, size_t len=std::string::npos) const
This member function creates a new StringView class instance using the selected position and length a...
Common exception class for all exceptions thrown in NumeRe.
@ EXTERNAL_PROGRAM_NOT_FOUND
static size_t invalid_position
This class represents a thread safe random number generator (it is a container for multiple generator...
std::mt19937 & getGenerator()
Returns an instance of a random number generator for the current thread.
std::vector< std::mt19937 > m_randGenArray
ThreadsafeRandGen()
Create an instance of this thread safe random number generator by filling the internal array with the...
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.
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 ...
std::string fromSystemCodePage(std::string)
Transforms the system code page to the internal one.
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
std::string replacePathSeparator(const std::string &)
This function replaces the Windows style path sparators to UNIX style.
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
bool isinf(const value_type &v)
value_type rint(value_type v)
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
Structure for the findCommand function.
std::string toString(int)
Converts an integer to a string without the Settings bloat.