NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
documentation.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 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#include <vector>
20#include <map>
21#include <fstream>
22#include "documentation.hpp"
23#include "../../kernel.hpp"
24#include "../datamanagement/database.hpp"
25#include "../ui/error.hpp"
26#include "../utils/tools.hpp"
27#include "../../syntax.hpp"
28
29
30
42static bool isValue(const std::string& sExpr, size_t nPos, size_t nLength)
43{
44 return (!nPos || !isalpha(sExpr[nPos-1])) && (nPos+nLength == sExpr.length() || !isalpha(sExpr[nPos+nLength]));
45}
46
47
59static bool isOperator(const std::string& sExpr, size_t nPos, size_t nLength)
60{
61 return true;
62}
63
64
76static bool isFunction(const std::string& sExpr, size_t nPos, size_t nLength)
77{
78 return (!nPos || !isalpha(sExpr[nPos-1])) && sExpr[nPos+nLength] == '(';
79}
80
81
92static void doc_ReplaceExprContentForHTML(std::string& sExpr, Settings& _option)
93{
94 // Get the mathstyle data base's contents
95 static NumeRe::DataBase HTMLEntitiesDB("<>/docs/mathstyle.ndb");
96 size_t nPos = 0;
97
98 // Set the starting position
99 if (sExpr.find("<exprblock>") != std::string::npos)
100 nPos = sExpr.find("<exprblock>")+11;
101
102 // Try to match the tokens to those in the
103 // data base and replace them
104 for (size_t i = nPos; i < sExpr.length(); i++)
105 {
106 // If this is the end of the current
107 // expression block, try to find a new
108 // one or abort the current loop
109 if (sExpr.substr(i, 12) == "</exprblock>")
110 {
111 if (sExpr.find("<exprblock>", i+12) != std::string::npos)
112 {
113 i = sExpr.find("<exprblock>", i+12) + 10;
114 continue;
115 }
116
117 break;
118 }
119
120 // Match the tokens of the data base
121 for (size_t n = 0; n < HTMLEntitiesDB.size(); n++)
122 {
123 if (sExpr.substr(i, HTMLEntitiesDB[n][0].length()) == HTMLEntitiesDB[n][0]
124 && ((HTMLEntitiesDB[n][2] == "OP" && isOperator(sExpr, i, HTMLEntitiesDB[n][0].length()))
125 || (HTMLEntitiesDB[n][2] == "VAL" && isValue(sExpr, i, HTMLEntitiesDB[n][0].length()))
126 || (HTMLEntitiesDB[n][2] == "FCT" && isFunction(sExpr, i, HTMLEntitiesDB[n][0].length())))
127 )
128 {
129 sExpr.replace(i, HTMLEntitiesDB[n][0].length(), HTMLEntitiesDB[n][1]);
130 i += HTMLEntitiesDB[n][1].length()-1;
131 }
132 }
133
134 // Handle supscripts
135 if (sExpr[i] == '^')
136 {
137 if (sExpr[i+1] == '(')
138 {
139 sExpr.replace(getMatchingParenthesis(sExpr.substr(i))+i, 1, "</sup>");
140 sExpr.replace(i, 2, "<sup>");
141 }
142 else
143 {
144 sExpr.insert(i+2, "</sup>");
145 sExpr.replace(i, 1, "<sup>");
146 }
147
148 i += 4;
149 continue;
150 }
151
152 // Handle subscripts
153 if (sExpr[i] == '_')
154 {
155 if (sExpr[i+1] == '(')
156 {
157 sExpr.replace(getMatchingParenthesis(sExpr.substr(i))+i, 1, "</sub >");
158 sExpr.replace(i, 2, "<sub>");
159 }
160 else
161 {
162 sExpr.insert(i+2, "</sub>");
163 sExpr.replace(i, 1, "<sub>");
164 }
165
166 i += 4;
167 continue;
168 }
169
170 // Insert whitespaces after commas
171 if (sExpr[i] == ',' && sExpr[i+1] != ' ')
172 sExpr.insert(i+1, 1, ' ');
173
174 // Special case: autodetect numerical
175 // subscripts
176 if (i < sExpr.length()-1 && isdigit(sExpr[i+1]) && isalpha(sExpr[i]))
177 {
178 if (i < sExpr.length()-2)
179 sExpr.insert(i+2, "</sub>");
180 else
181 sExpr.append("</sub>");
182
183 sExpr.insert(i+1,"<sub>");
184 i += 12;
185 }
186 }
187}
188
189
201static void doc_ReplaceTokensForHTML(std::string& sDocParagraph, bool generateFile, Settings& _option)
202{
203 for (unsigned int k = 0; k < sDocParagraph.length(); k++)
204 {
205 if (sDocParagraph.substr(k,2) == "\\$")
206 sDocParagraph.erase(k,1);
207
208 if (sDocParagraph.substr(k,3) == "\\\\n")
209 sDocParagraph.erase(k,1);
210
211 if (sDocParagraph.substr(k,2) == " ")
212 sDocParagraph.replace(k,1,"&nbsp;");
213
214 if (sDocParagraph.substr(k,4) == "<em>" && sDocParagraph.find("</em>", k+4) != std::string::npos)
215 {
216 sDocParagraph.insert(k+4, "<strong>");
217 sDocParagraph.insert(sDocParagraph.find("</em>", k+12), "</strong>");
218 }
219
220 if (sDocParagraph.substr(k,3) == "<h>" && sDocParagraph.find("</h>", k+3) != std::string::npos)
221 {
222 sDocParagraph.replace(k, 3, "<h4>");
223 sDocParagraph.replace(sDocParagraph.find("</h>",k+4), 4, "</h4>");
224 }
225
226 if (sDocParagraph.substr(k,6) == "<expr>" && sDocParagraph.find("</expr>", k+6) != std::string::npos)
227 {
228 std::string sExpr = sDocParagraph.substr(k+6, sDocParagraph.find("</expr>", k+6)-k-6);
229 doc_ReplaceExprContentForHTML(sExpr,_option);
230 sDocParagraph.replace(k,
231 sDocParagraph.find("</expr>",k+6)+7-k,
232 "<span style=\"font-style:italic; font-family: palatino linotype; font-weight: bold;\">"+sExpr+"</span>");
233 }
234
235 if (sDocParagraph.substr(k,6) == "<code>" && sDocParagraph.find("</code>", k+6) != std::string::npos)
236 {
237 sDocParagraph.insert(k+6, "<span style=\"color:#00008B;background-color:#F2F2F2;\">");
238 sDocParagraph.insert(sDocParagraph.find("</code>", k+6), "</span>");
239 std::string sCode = sDocParagraph.substr(k+6, sDocParagraph.find("</code>", k+6)-k-6);
240
241 for (unsigned int i = 0; i < sCode.length(); i++)
242 {
243 if (sCode.substr(i,2) == "\\n")
244 sCode.replace(i,2,"<br>");
245 }
246
247 k += sCode.length();
248 }
249
250 if (sDocParagraph.substr(k,5) == "<img " && sDocParagraph.find("/>", k+5) != std::string::npos)
251 {
252 std::string sImg = sDocParagraph.substr(k, sDocParagraph.find("/>", k+5)+2-k);
253
254 if (sImg.find("src") != std::string::npos)
255 {
256 std::string sImgSrc = Documentation::getArgAtPos(sImg, sImg.find('=', sImg.find("src"))+1);
257 sImgSrc = NumeReKernel::getInstance()->getFileSystem().ValidFileName(sImgSrc, ".png");
258 sImg = "<img src=\"" + sImgSrc + "\" />";
259 sImg = "<div align=\"center\">" + sImg + "</div>";
260 }
261 else
262 sImg.clear();
263
264 sDocParagraph.replace(k, sDocParagraph.find("/>", k+5)+2-k, sImg);
265 k += sImg.length();
266 }
267
268 if (sDocParagraph.substr(k, 10) == "&PLOTPATH&")
269 sDocParagraph.replace(k, 10, generateFile ? "&lt;plotpath&gt;" : replacePathSeparator(_option.getPlotPath()));
270
271 if (sDocParagraph.substr(k, 10) == "&LOADPATH&")
272 sDocParagraph.replace(k, 10, generateFile ? "&lt;loadpath&gt;" : replacePathSeparator(_option.getLoadPath()));
273
274 if (sDocParagraph.substr(k, 10) == "&SAVEPATH&")
275 sDocParagraph.replace(k, 10, generateFile ? "&lt;savepath&gt;" : replacePathSeparator(_option.getSavePath()));
276
277 if (sDocParagraph.substr(k, 10) == "&PROCPATH&")
278 sDocParagraph.replace(k, 10, generateFile ? "&lt;procpath&gt;" : replacePathSeparator(_option.getProcPath()));
279
280 if (sDocParagraph.substr(k, 12) == "&SCRIPTPATH&")
281 sDocParagraph.replace(k, 12, generateFile ? "&lt;scriptpath&gt;" : replacePathSeparator(_option.getScriptPath()));
282
283 if (sDocParagraph.substr(k, 9) == "&EXEPATH&")
284 sDocParagraph.replace(k, 9, generateFile ? "&lt;&gt;" : replacePathSeparator(_option.getExePath()));
285 }
286}
287
288
302void doc_Help(const std::string& __sTopic, Settings& _option)
303{
304 std::string sTopic = toLowerCase(__sTopic);
305
306 if (findParameter(sTopic, "html"))
307 eraseToken(sTopic, "html", false);
308
309 // --> Zunaechst einmal muessen wir anfuehrende oder abschliessende Leerzeichen entfernen <--
310 StripSpaces(sTopic);
311
312 if (!sTopic.length())
313 sTopic = "brief";
314
315 if (sTopic.front() == '-')
316 sTopic.erase(0,1);
317
318 StripSpaces(sTopic);
319
320 std::vector<std::string> vDocArticle = _option.getHelpArticle(sTopic);
321
322 if (vDocArticle[0] == "NO_ENTRY_FOUND") // Nix gefunden
323 {
324 make_hline();
325 NumeReKernel::print(LineBreak(_lang.get("DOC_HELP_NO_ENTRY_FOUND", sTopic), _option));
326 make_hline();
327 }
328 else //if (findParameter(__sTopic, "html") || _option.useExternalDocWindow()) // HTML-Export generieren
329 {
330 bool generateFile = (bool)findParameter(__sTopic, "html");
331 std::string sHTML = doc_HelpAsHTML(sTopic, generateFile, _option);
332
333 if (generateFile)
334 {
335 _option.declareFileType(".html");
336 std::string sFilename = _option.ValidizeAndPrepareName("<>/docs/htmlexport/"+_option.getHelpArticleID(sTopic) + ".html",".html");
337 std::ofstream fHTML;
338 fHTML.open(sFilename);
339
340 if (fHTML.fail())
342
343 // content schreiben
344 fHTML << sHTML;
345 NumeReKernel::print(_lang.get("DOC_HELP_HTMLEXPORT", _option.getHelpArticleTitle(_option.getHelpIdxKey(sTopic)), sFilename));
346 }
347 else
349 }
350 /*else // Hilfeartikel anzeigen
351 {
352 NumeReKernel::toggleTableStatus();
353 make_hline();
354
355 for (unsigned int i = 0; i < vDocArticle.size(); i++)
356 {
357 if (!i)
358 {
359 NumeReKernel::print(toSystemCodePage(toUpperCase(_lang.get("DOC_HELP_HEADLINE", vDocArticle[i]))));
360 make_hline();
361 continue;
362 }
363
364 if (vDocArticle[i].find("<example ") != std::string::npos) // Beispiel-Tags
365 {
366 bool bVerb = false;
367
368 if (vDocArticle[i].find("type=") && Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("type=")+5) == "verbatim")
369 bVerb = true;
370
371 doc_ReplaceTokens(vDocArticle[i], _option);
372 NumeReKernel::print(_lang.get("DOC_HELP_EXAMPLE", Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("desc=")+5)));
373 NumeReKernel::printPreFmt("|\n");
374
375 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
376 {
377 if (vDocArticle[j].find("</example>") != std::string::npos)
378 {
379 i = j;
380
381 if (i+1 < vDocArticle.size())
382 NumeReKernel::printPreFmt("|\n");
383
384 break;
385 }
386
387 if (vDocArticle[j] == "[...]")
388 {
389 NumeReKernel::printPreFmt("|[...]\n");
390 continue;
391 }
392
393 doc_ReplaceTokens(vDocArticle[j], _option);
394
395 if (!bVerb)
396 {
397 if (((i+1) % 2 && j % 2) || (!((i+1) % 2) && !(j % 2)))
398 NumeReKernel::printPreFmt("||<- " + LineBreak(vDocArticle[j], _option, false, 5) + "\n");
399 else
400 {
401 NumeReKernel::printPreFmt("||-> " + LineBreak(vDocArticle[j], _option, false, 5) + "\n");
402
403 if (vDocArticle[j+1].find("</example>") == std::string::npos)
404 NumeReKernel::printPreFmt("||\n");
405 }
406 }
407 else
408 NumeReKernel::printPreFmt("|" + toSystemCodePage(vDocArticle[j])+"\n");
409 }
410 }
411 else if (vDocArticle[i].find("<exprblock>") != std::string::npos) // EXPRBLOCK-Tags
412 {
413 if (vDocArticle[i].find("</exprblock>", vDocArticle[i].find("<exprblock>")) != std::string::npos)
414 {
415 doc_ReplaceTokens(vDocArticle[i], _option);
416
417 while (vDocArticle[i].find("</exprblock>", vDocArticle[i].find("<exprblock>")) != std::string::npos)
418 {
419 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<exprblock>")+11, vDocArticle[i].find("</exprblock>")-vDocArticle[i].find("<exprblock>")-11);
420
421 for (unsigned int k = 0; k < sExprBlock.length(); k++)
422 {
423 if (!k && sExprBlock[k] == '$')
424 sExprBlock.insert(0,"\\");
425
426 if (sExprBlock[k] == '$' && sExprBlock[k-1] != '\\')
427 sExprBlock.insert(k,"\\");
428
429 if (sExprBlock.substr(k,2) == "\\n")
430 sExprBlock.replace(k,2,"$ ");
431
432 if (sExprBlock.substr(k,2) == "\\t")
433 sExprBlock.replace(k,2," ");
434 }
435
436 vDocArticle[i].replace(vDocArticle[i].find("<exprblock>"), vDocArticle[i].find("</exprblock>")+12-vDocArticle[i].find("<exprblock>"), "$$ " + sExprBlock + "$$");
437 }
438
439 if (vDocArticle[i].substr(vDocArticle[i].length()-2) == "$$")
440 vDocArticle[i].pop_back();
441
442 NumeReKernel::print(vDocArticle[i]);
443 }
444 else
445 {
446 if (vDocArticle[i] != "<exprblock>")
447 NumeReKernel::print(vDocArticle[i].substr(0,vDocArticle[i].find("<exprblock>")));
448
449 NumeReKernel::printPreFmt("|\n");
450
451 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
452 {
453 if (vDocArticle[j].find("</exprblock>") != std::string::npos)
454 {
455 i = j;
456
457 if (i+1 < vDocArticle.size())
458 NumeReKernel::printPreFmt("|\n");
459
460 break;
461 }
462
463 doc_ReplaceTokens(vDocArticle[j], _option);
464
465 while (vDocArticle[j].find("\\t") != std::string::npos)
466 vDocArticle[j].replace(vDocArticle[j].find("\\t"), 2, " ");
467
468 NumeReKernel::printPreFmt("| " + toSystemCodePage(vDocArticle[j]) + "\n");
469 }
470 }
471 }
472 else if (vDocArticle[i].find("<codeblock>") != std::string::npos) // CODEBLOCK-Tags
473 {
474 if (vDocArticle[i].find("</codeblock>", vDocArticle[i].find("<codeblock>")) != std::string::npos)
475 {
476 doc_ReplaceTokens(vDocArticle[i], _option);
477
478 while (vDocArticle[i].find("</codeblock>", vDocArticle[i].find("<codeblock>")) != std::string::npos)
479 {
480 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<codeblock>")+11, vDocArticle[i].find("</codeblock>")-vDocArticle[i].find("<codeblock>")-11);
481
482 for (unsigned int k = 0; k < sExprBlock.length(); k++)
483 {
484 if (!k && sExprBlock[k] == '$')
485 sExprBlock.insert(0,"\\");
486
487 if (sExprBlock[k] == '$' && sExprBlock[k-1] != '\\')
488 sExprBlock.insert(k,"\\");
489
490 if (sExprBlock.substr(k,2) == "\\n")
491 sExprBlock.replace(k,2,"$ ");
492
493 if (sExprBlock.substr(k,2) == "\\t")
494 sExprBlock.replace(k,2," ");
495 }
496
497 vDocArticle[i].replace(vDocArticle[i].find("<codeblock>"), vDocArticle[i].find("</codeblock>")+12-vDocArticle[i].find("<codeblock>"), "$$ " + sExprBlock + "$$");
498 }
499
500 if (vDocArticle[i].substr(vDocArticle[i].length()-2) == "$$")
501 vDocArticle[i].pop_back();
502
503 NumeReKernel::print(vDocArticle[i]);
504 }
505 else
506 {
507 if (vDocArticle[i] != "<codeblock>")
508 NumeReKernel::print(vDocArticle[i].substr(0,vDocArticle[i].find("<codeblock>")));
509
510 NumeReKernel::printPreFmt("|\n");
511
512 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
513 {
514 if (vDocArticle[j].find("</codeblock>") != std::string::npos)
515 {
516 i = j;
517
518 if (i+1 < vDocArticle.size())
519 NumeReKernel::printPreFmt("|\n");
520
521 break;
522 }
523
524 doc_ReplaceTokens(vDocArticle[j], _option);
525
526 while (vDocArticle[j].find("\\t") != std::string::npos)
527 vDocArticle[j].replace(vDocArticle[j].find("\\t"), 2, " ");
528
529 NumeReKernel::printPreFmt("| " + toSystemCodePage(vDocArticle[j])+"\n");
530 }
531 }
532 }
533 else if (vDocArticle[i].find("<list>") != std::string::npos) // Standard-LIST-Tags
534 {
535 unsigned int nLengthMax = 0;
536
537 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
538 {
539 if (vDocArticle[j].find("</list>") != std::string::npos)
540 {
541 std::string sLine = "";
542 std::string sNode = "";
543 std::string sRemainingLine = "";
544 std::string sFinalLine = "";
545 int nIndent = 0;
546
547 for (unsigned int k = i+1; k < j; k++)
548 {
549 nIndent = 0;
550 sNode = Documentation::getArgAtPos(vDocArticle[k], vDocArticle[k].find("node=")+5);
551 sRemainingLine = vDocArticle[k].substr(vDocArticle[k].find('>', vDocArticle[k].find("node=")+5+Documentation::getArgAtPos(vDocArticle[k], vDocArticle[k].find("node=")+5).length()+2)+1, vDocArticle[k].find("</item>")-1-vDocArticle[k].find('>', vDocArticle[k].find("node=")+5+Documentation::getArgAtPos(vDocArticle[k], vDocArticle[k].find("node=")+5).length()+2));
552 sFinalLine = "";
553
554 if (vDocArticle[k].find("type=") != std::string::npos && Documentation::getArgAtPos(vDocArticle[k], vDocArticle[k].find("type=")+5) == "verbatim")
555 {
556 NumeReKernel::printPreFmt("| " + sNode);
557 nIndent = sNode.length()+6;
558 sLine.append(nLengthMax+9-nIndent, ' ');
559 sLine += "- " + sRemainingLine;
560
561 if (sLine.find('~') == std::string::npos && sLine.find('%') == std::string::npos)
562 NumeReKernel::printPreFmt(LineBreak(sLine, _option, true, nIndent, nLengthMax+11) + "\n");
563 else
564 NumeReKernel::printPreFmt(LineBreak(sLine, _option, false, nIndent, nLengthMax+11) + "\n");
565 }
566 else
567 {
568 for (unsigned int n = 0; n < sNode.length(); n++)
569 {
570 if (n && sNode[n] == '$' && sNode[n-1] != '\\')
571 {
572 sLine = "| " + sNode.substr(0,n);
573 sNode.erase(0,n+1);
574 n = -1;
575 sLine.append(nLengthMax+9-sLine.length()+countEscapeSymbols(sLine), ' ');
576
577 if (!sFinalLine.length())
578 sLine += "- " + sRemainingLine;
579 else
580 sLine += " " + sRemainingLine;
581
582 if (sLine.find('~') == std::string::npos && sLine.find('%') == std::string::npos)
583 sLine = LineBreak(sLine, _option, true, nIndent, nLengthMax+11);
584 else
585 sLine = LineBreak(sLine, _option, false, nIndent, nLengthMax+11);
586
587 sFinalLine += sLine.substr(0,sLine.find('\n'));
588
589 if (sLine.find('\n') != std::string::npos)
590 sFinalLine += '\n';
591
592 sRemainingLine.erase(0,sLine.substr(nLengthMax+11, sLine.find('\n')-nLengthMax-11).length());
593
594 if (sRemainingLine.front() == ' ')
595 sRemainingLine.erase(0,1);
596 }
597 }
598
599 sLine = "| " + sNode;
600 sLine.append(nLengthMax+9-sLine.length()+countEscapeSymbols(sLine), ' ');
601
602 if (!sFinalLine.length())
603 sLine += "- " + sRemainingLine;
604 else
605 sLine += " " + sRemainingLine;
606
607 if (sLine.find('~') == std::string::npos && sLine.find('%') == std::string::npos)
608 sFinalLine += LineBreak(sLine, _option, true, nIndent, nLengthMax+11);
609 else
610 sFinalLine += LineBreak(sLine, _option, false, nIndent, nLengthMax+11);
611
612 NumeReKernel::printPreFmt(sFinalLine + "\n");
613 }
614 }
615
616 i = j;
617 break;
618 }
619 else
620 {
621 doc_ReplaceTokens(vDocArticle[j], _option);
622
623 std::string sNode = Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5);
624
625 for (unsigned int k = 0; k < sNode.length(); k++)
626 {
627 if (sNode[k] == '$' && k && sNode[k-1] != '\\')
628 {
629 if (nLengthMax < k-countEscapeSymbols(sNode.substr(0,k)))
630 nLengthMax = k-countEscapeSymbols(sNode.substr(0,k));
631
632 sNode.erase(0,k+1);
633 k = -1;
634 }
635 }
636
637 if (nLengthMax < sNode.length()-countEscapeSymbols(sNode))
638 nLengthMax = sNode.length()-countEscapeSymbols(sNode);
639 }
640 }
641 }
642 else if (vDocArticle[i].find("<table") != std::string::npos) // TABLE-Tags
643 {
644 std::string sTable = vDocArticle[i].substr(vDocArticle[i].find("<table"));
645
646 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
647 {
648 if (vDocArticle[j].find("</table>") != std::string::npos)
649 {
650 sTable += vDocArticle[j].substr(0,vDocArticle[j].find("</table>")+8);
651 // Send the whole content to the table reader and render the obtained table on the screen.
652 std::vector<std::vector<std::string> > vTable = doc_readTokenTable(sTable, _option);
653 std::vector<size_t> vFieldSizes;
654
655 for (size_t v = 0; v < vTable.size(); v++)
656 {
657 for (size_t w = 0; w < vTable[v].size(); w++)
658 {
659 if (vFieldSizes.size() < w+1)
660 vFieldSizes.push_back(vTable[v][w].length());
661 else
662 {
663 if (vFieldSizes[w] < vTable[v][w].length())
664 vFieldSizes[w] = vTable[v][w].length();
665 }
666 }
667 }
668
669 for (size_t v = 0; v < vTable.size(); v++)
670 {
671 NumeReKernel::printPreFmt("| ");
672
673 for (size_t w = 0; w < vTable[v].size(); w++)
674 {
675 NumeReKernel::printPreFmt(strlfill(vTable[v][w], vFieldSizes[w]+2));
676 }
677
678 NumeReKernel::printPreFmt("\n");
679 }
680
681 i = j;
682 break;
683 }
684 else
685 sTable += vDocArticle[j];
686 }
687 }
688 else // Normaler Paragraph
689 {
690 doc_ReplaceTokens(vDocArticle[i], _option);
691
692 if (vDocArticle[i].find('~') == std::string::npos && vDocArticle[i].find('%') == std::string::npos)
693 NumeReKernel::print(LineBreak(vDocArticle[i], _option));
694 else
695 NumeReKernel::print(LineBreak(vDocArticle[i], _option, false));
696 }
697 }
698
699 NumeReKernel::toggleTableStatus();
700 make_hline();
701 }*/
702}
703
704
718static std::string createCssString(int style, const Settings& _option)
719{
720 std::string sSettingsString;
721
722 switch (style)
723 {
724 //case NumeReSyntax::SYNTAX_STD:
725 // sSettingsString = _option.getSetting(SETTING_S_ST_STANDARD).stringval();
726 // break;
728 sSettingsString = _option.getSetting(SETTING_S_ST_COMMAND).stringval();
729 break;
731 sSettingsString = _option.getSetting(SETTING_S_ST_OPERATOR).stringval();
732 break;
734 sSettingsString = _option.getSetting(SETTING_S_ST_SPECIALVAL).stringval();
735 break;
737 sSettingsString = _option.getSetting(SETTING_S_ST_NUMBER).stringval();
738 break;
740 sSettingsString = _option.getSetting(SETTING_S_ST_OPTION).stringval();
741 break;
743 sSettingsString = _option.getSetting(SETTING_S_ST_PROCEDURE).stringval();
744 break;
746 sSettingsString = _option.getSetting(SETTING_S_ST_STRING).stringval();
747 break;
749 sSettingsString = _option.getSetting(SETTING_S_ST_METHODS).stringval();
750 break;
752 sSettingsString = _option.getSetting(SETTING_S_ST_FUNCTION).stringval();
753 break;
755 sSettingsString = _option.getSetting(SETTING_S_ST_CONSTANT).stringval();
756 break;
758 sSettingsString = _option.getSetting(SETTING_S_ST_COMMENT).stringval();
759 break;
760 default:
761 return "";
762 }
763
764 replaceAll(sSettingsString, ":", ",");
765 std::string sCssString = "color: rgb(" + sSettingsString.substr(0, sSettingsString.find('-')) + ");";
766 std::string sBackgroundColor = sSettingsString.substr(sSettingsString.find('-')+1,
767 sSettingsString.rfind('-')-sSettingsString.find('-')-1);
768
769 sSettingsString.erase(0, sSettingsString.rfind('-')+1);
770
771 if (sSettingsString[0] == '1') // bold
772 sCssString += " font-weight: bold;";
773
774 if (sSettingsString[1] == '1') // italic
775 sCssString += " font-style: italic;";
776
777 if (sSettingsString[2] == '1') // underline
778 sCssString += " text-decoration: underline;";
779
780 if (sSettingsString[3] == '0') // custom background
781 sCssString += " background-color: rgb(" + sBackgroundColor + ");";
782
783 return sCssString;
784}
785
786
797static std::string applySyntaxHighlighting(const std::string& sCodeString, const Settings& _option)
798{
799 static NumeReSyntax _syntax(_option.getExePath() + "/", NumeReKernel::getInstance()->getPluginCommands());
800 std::string sStyleBytes;
801 std::string sStyledString;
802
803 if (sCodeString.front() != '|')
804 sStyleBytes = _syntax.highlightLine("|<- " + sCodeString + " ").substr(4);
805 else
806 sStyleBytes = _syntax.highlightLine(sCodeString + " ");
807
808 size_t nLastPos = sStyleBytes.length();
809 size_t nLastStatePosition = 0;
810
811 for (size_t i = 0; i < nLastPos; i++)
812 {
813 if (sStyleBytes[i] != sStyleBytes[nLastStatePosition] || i+1 == nLastPos)
814 {
815 int style = sStyleBytes[nLastStatePosition] - '0';
816 std::string textRange;
817
818 if (i+1 == nLastPos)
819 textRange = sCodeString.substr(nLastStatePosition, i+1-nLastStatePosition);
820 else
821 textRange = sCodeString.substr(nLastStatePosition, i-nLastStatePosition);
822
823 if (textRange.find_first_not_of(" \r\t\n") == std::string::npos)
824 {
825 sStyledString += textRange;
826 nLastStatePosition = i;
827 continue;
828 }
829
831 {
832 replaceAll(textRange, "<", "&lt;");
833 replaceAll(textRange, ">", "&gt;");
834 }
835
836 std::string sCssString = createCssString(style, _option);
837
838 if (sCssString.length())
839 sStyledString += "<span style=\"" + sCssString + "\">" + textRange + "</span>";
840 else
841 sStyledString += textRange;
842
843 nLastStatePosition = i;
844 }
845 }
846
847
848 return sStyledString;
849}
850
851
863static std::string getHighlightedCode(std::string sCode, bool verbatim, Settings& _option)
864{
865 if (!verbatim)
866 {
867 replaceAll(sCode, "\\n", " \\n ");
868 replaceAll(sCode, "\\t", "\\t ");
869 replaceAll(sCode, "&lt;", "<");
870 replaceAll(sCode, "&gt;", ">");
871 sCode = applySyntaxHighlighting(sCode, _option);
872 replaceAll(sCode, "\\t ", "&nbsp;&nbsp;&nbsp;&nbsp;");
873
874 if (sCode.substr(0, 4) == "|<- ")
875 sCode.replace(1, 1, "&lt;");
876
877 if (sCode.substr(0, 4) == "|-> ")
878 sCode.replace(2, 1, "&gt;");
879 }
880 else
881 replaceAll(sCode, "\\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
882
883 replaceAll(sCode, "\\n", "<br>\n");
884 return sCode;
885}
886
887
888#define FILE_CODEBLOCK_START "<div class=\"sites-codeblock sites-codesnippet-block\"><CODE><span style=\"color:#00008B;\">\n"
889#define FILE_CODEBLOCK_END "</span></CODE></div>\n"
890
891#define VIEWER_CODEBLOCK_START "<center><table border=\"0\" cellspacing=\"0\" bgcolor=\"#F2F2F2\" width=\"94%\">\n<tbody><tr><td>\n<CODE><span style=\"color:#00008B;\">\n"
892#define VIEWER_CODEBLOCK_END "\n</span></CODE></td></tr></tbody></table></center>\n"
893
894
907static std::string formatCodeBlock(std::string sCode, bool generateFile, bool verbatim, Settings& _option)
908{
909 sCode = getHighlightedCode(sCode, verbatim, _option);
910 doc_ReplaceTokensForHTML(sCode, generateFile, _option);
911
912 if (generateFile)
914
916}
917
932std::string doc_HelpAsHTML(const std::string& __sTopic, bool generateFile, Settings& _option)
933{
934 std::string sTopic = __sTopic;
935 StripSpaces(sTopic);
936
937 // Get the article contents
938 std::vector<std::string> vDocArticle = _option.getHelpArticle(sTopic);
939
940 if (vDocArticle[0] == "NO_ENTRY_FOUND") // Nix gefunden
941 return "";
942
943 bool isIndex = (vDocArticle[0] == "Index");
944
945 std::string sHTML;
946
947 sHTML = "<!DOCTYPE html>\n<html>\n<head>\n";
948
949 // Convert the XML-like structure of the documentation
950 // article into a valid HTML DOM, which can be returned
951 // as a single std::string
952 for (unsigned int i = 0; i < vDocArticle.size(); i++)
953 {
954 // If this is the first line, then create the header
955 // tag section of the HTML file
956 if (!i)
957 {
958 if (generateFile)
959 {
960 // Header fertigstellen
961 sHTML += "<title>" + toUpperCase(_lang.get("DOC_HELP_HEADLINE", vDocArticle[i]))
962 + "</title>\n"
963 + "</head>\n\n"
964 + "<body>\n"
965 + "<!-- START COPYING HERE -->\n";
966 sHTML += "<h4>" + _lang.get("DOC_HELP_DESC_HEADLINE") + "</h4>\n";
967 }
968 else
969 {
970 // Header fertigstellen
971 sHTML += "<title>" + vDocArticle[i] + "</title>\n</head>\n\n<body>\n<h2>"+vDocArticle[i]+"</h2>\n";
972 }
973
974 continue;
975 }
976
977 // Expand the XML tags in the documentation article
978 // into corresponding HTML tags, which will resemble
979 // the intended style
980 if (vDocArticle[i].find("<example ") != std::string::npos) // Beispiel-Tags
981 {
982 sHTML += "<h4>"+ _lang.get("DOC_HELP_EXAMPLE_HEADLINE") +"</h4>\n";
983 bool bVerb = false;
984 bool bCodeBlock = false;
985 bool bPlain = false;
986
987 if (vDocArticle[i].find("type=") && Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("type=")+5) == "verbatim")
988 bVerb = true;
989
990 if (vDocArticle[i].find("type=") && Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("type=")+5) == "codeblock")
991 bCodeBlock = true;
992
993 if (vDocArticle[i].find("type=") && Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("type=")+5) == "plain")
994 bPlain = true;
995
996 std::string sDescription = Documentation::getArgAtPos(vDocArticle[i], vDocArticle[i].find("desc=")+5);
997
998 doc_ReplaceTokensForHTML(sDescription, generateFile, _option);
999
1000 if (generateFile)
1001 sHTML += "<p>" + sDescription + "</p>\n";
1002 else
1003 sHTML += "<p>" + sDescription + "</p>\n";
1004
1005 if (bCodeBlock || bPlain)
1006 {
1007 std::string sCodeContent;
1008
1009 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1010 {
1011 if (vDocArticle[j].find("</example>") != std::string::npos)
1012 {
1013 i = j;
1014 sHTML += formatCodeBlock(sCodeContent.substr(0, sCodeContent.length()-2), generateFile, bPlain, _option) + "\n";
1015 break;
1016 }
1017
1018 sCodeContent += vDocArticle[j] + "\\n";
1019 }
1020 }
1021 else
1022 {
1023 std::string sExample;
1024
1025 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1026 {
1027 if (vDocArticle[j].find("</example>") != std::string::npos)
1028 {
1029 i = j;
1030 doc_ReplaceTokensForHTML(sExample, generateFile, _option);
1031
1032 if (generateFile)
1033 sHTML += FILE_CODEBLOCK_START + sExample.substr(0, sExample.length()-5) + FILE_CODEBLOCK_END;
1034 else
1035 sHTML += VIEWER_CODEBLOCK_START + sExample.substr(0, sExample.length()-5) + VIEWER_CODEBLOCK_END;
1036
1037 break;
1038 }
1039
1040 if (vDocArticle[j] == "[...]")
1041 {
1042 sExample += "[...]<br>\n";
1043 continue;
1044 }
1045
1046 if (!bVerb)
1047 {
1048 if (((i+1) % 2 && j % 2) || (!((i+1) % 2) && !(j % 2)))
1049 sExample += "|&lt;- " + getHighlightedCode(vDocArticle[j], false, _option) + "<br>\n";
1050 else
1051 {
1052 sExample += "|-&gt; " + vDocArticle[j] + "<br>\n";
1053
1054 if (vDocArticle[j+1].find("</example>") == std::string::npos)
1055 sExample += "|<br>\n";
1056 }
1057 }
1058 else
1059 sExample += getHighlightedCode(vDocArticle[j], false, _option) + "<br>\n";
1060 }
1061 }
1062
1063 }
1064 else if (vDocArticle[i].find("<exprblock>") != std::string::npos) // EXPRBLOCK-Tags
1065 {
1066 if (vDocArticle[i].find("</exprblock>", vDocArticle[i].find("<exprblock>")) != std::string::npos)
1067 {
1068 doc_ReplaceTokensForHTML(vDocArticle[i], generateFile, _option);
1069 doc_ReplaceExprContentForHTML(vDocArticle[i], _option);
1070
1071 while (vDocArticle[i].find("</exprblock>", vDocArticle[i].find("<exprblock>")) != std::string::npos)
1072 {
1073 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<exprblock>")+11, vDocArticle[i].find("</exprblock>")-vDocArticle[i].find("<exprblock>")-11);
1074
1075 for (unsigned int k = 0; k < sExprBlock.length(); k++)
1076 {
1077 if (sExprBlock.substr(k,2) == "\\n")
1078 sExprBlock.replace(k,2,"<br>");
1079
1080 if (sExprBlock.substr(k,2) == "\\t")
1081 sExprBlock.replace(k,2,"&nbsp;&nbsp;&nbsp;&nbsp;");
1082 }
1083
1084 if (generateFile)
1085 vDocArticle[i].replace(vDocArticle[i].find("<exprblock>"), vDocArticle[i].find("</exprblock>")+12-vDocArticle[i].find("<exprblock>"), "</p><div style=\"font-style: italic;margin-left: 40px\">" + sExprBlock + "</div><p>");
1086 else
1087 vDocArticle[i].replace(vDocArticle[i].find("<exprblock>"), vDocArticle[i].find("</exprblock>")+12-vDocArticle[i].find("<exprblock>"), "</p><blockquote><span style=\"font-style: italic; font-family: palatino linotype; font-size: 12pt; font-weight: bold;\">" + sExprBlock + "</span></blockquote><p>");
1088 }
1089
1090 sHTML += "<p>" + (vDocArticle[i]) + "</p>\n";
1091 }
1092 else
1093 {
1094 if (vDocArticle[i] != "<exprblock>")
1095 sHTML += "<p>" + (vDocArticle[i].substr(0, vDocArticle[i].find("<exprblock>"))) + "</p>\n";
1096
1097 if (generateFile)
1098 sHTML += "<div style=\"font-style: italic;margin-left: 40px\">\n";
1099 else
1100 sHTML += "<blockquote><span style=\"font-style: italic; font-family: palatino linotype; font-size: 12pt; font-weight: bold;\">\n";
1101
1102 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1103 {
1104 if (vDocArticle[j].find("</exprblock>") != std::string::npos)
1105 {
1106 i = j;
1107
1108 if (generateFile)
1109 sHTML += "</div>\n";
1110 else
1111 {
1112 sHTML.erase(sHTML.length()-5);
1113 sHTML += "\n</span></blockquote>\n";
1114 }
1115
1116 break;
1117 }
1118
1119 doc_ReplaceTokensForHTML(vDocArticle[j], generateFile, _option);
1120 doc_ReplaceExprContentForHTML(vDocArticle[j], _option);
1121
1122 while (vDocArticle[j].find("\\t") != std::string::npos)
1123 vDocArticle[j].replace(vDocArticle[j].find("\\t"), 2, "&nbsp;&nbsp;&nbsp;&nbsp;");
1124
1125 sHTML += (vDocArticle[j]) + "<br>\n";
1126 }
1127 }
1128 }
1129 else if (vDocArticle[i].find("<codeblock>") != std::string::npos) // CODEBLOCK-Tags
1130 {
1131 if (vDocArticle[i].find("</codeblock>", vDocArticle[i].find("<codeblock>")) != std::string::npos)
1132 {
1133 while (vDocArticle[i].find("</codeblock>", vDocArticle[i].find("<codeblock>")) != std::string::npos)
1134 {
1135 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<codeblock>")+11,
1136 vDocArticle[i].find("</codeblock>")-vDocArticle[i].find("<codeblock>")-11);
1137
1138 vDocArticle[i].replace(vDocArticle[i].find("<codeblock>"),
1139 vDocArticle[i].find("</codeblock>")+12-vDocArticle[i].find("<codeblock>"),
1140 "</p>" + formatCodeBlock(sExprBlock, generateFile, false, _option) + "<p>");
1141 }
1142
1143 doc_ReplaceTokensForHTML(vDocArticle[i], generateFile, _option);
1144 sHTML += "<p>" + (vDocArticle[i]) + "</p>\n";
1145 }
1146 else
1147 {
1148 if (vDocArticle[i] != "<codeblock>")
1149 sHTML += "<p>" + (vDocArticle[i].substr(0, vDocArticle[i].find("<codeblock>"))) + "</p>\n";
1150
1151 std::string sCodeContent;
1152
1153 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1154 {
1155 if (vDocArticle[j].find("</codeblock>") != std::string::npos)
1156 {
1157 i = j;
1158 sHTML += formatCodeBlock(sCodeContent.substr(0, sCodeContent.length()-2), generateFile, false, _option) + "\n";
1159 break;
1160 }
1161
1162 sCodeContent += vDocArticle[j] + "\\n";
1163 }
1164 }
1165 }
1166 else if (vDocArticle[i].find("<verbatim>") != std::string::npos) // CODEBLOCK-Tags
1167 {
1168 if (vDocArticle[i].find("</verbatim>", vDocArticle[i].find("<verbatim>")) != std::string::npos)
1169 {
1170 while (vDocArticle[i].find("</verbatim>", vDocArticle[i].find("<verbatim>")) != std::string::npos)
1171 {
1172 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<verbatim>")+10,
1173 vDocArticle[i].find("</verbatim>")-vDocArticle[i].find("<verbatim>")-10);
1174
1175 vDocArticle[i].replace(vDocArticle[i].find("<verbatim>"),
1176 vDocArticle[i].find("</verbatim>")+11-vDocArticle[i].find("<verbatim>"),
1177 "</p>" + formatCodeBlock(sExprBlock, generateFile, true, _option) + "<p>");
1178 }
1179
1180 doc_ReplaceTokensForHTML(vDocArticle[i], generateFile, _option);
1181 sHTML += "<p>" + (vDocArticle[i]) + "</p>\n";
1182 }
1183 else
1184 {
1185 if (vDocArticle[i] != "<verbatim>")
1186 sHTML += "<p>" + (vDocArticle[i].substr(0, vDocArticle[i].find("<verbatim>"))) + "</p>\n";
1187
1188 std::string sCodeContent;
1189
1190 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1191 {
1192 if (vDocArticle[j].find("</verbatim>") != std::string::npos)
1193 {
1194 i = j;
1195 sHTML += formatCodeBlock(sCodeContent.substr(0, sCodeContent.length()-2), generateFile, true, _option) + "\n";
1196 break;
1197 }
1198
1199 sCodeContent += vDocArticle[j] + "\\n";
1200 }
1201 }
1202 }
1203 else if (vDocArticle[i].find("<syntax>") != std::string::npos) // CODEBLOCK-Tags
1204 {
1205 if (vDocArticle[i].find("</syntax>", vDocArticle[i].find("<syntax>")) != std::string::npos)
1206 {
1207 while (vDocArticle[i].find("</syntax>", vDocArticle[i].find("<syntax>")) != std::string::npos)
1208 {
1209 std::string sExprBlock = vDocArticle[i].substr(vDocArticle[i].find("<syntax>")+8,
1210 vDocArticle[i].find("</syntax>")-vDocArticle[i].find("<syntax>")-8);
1211
1212 vDocArticle[i].replace(vDocArticle[i].find("<syntax>"),
1213 vDocArticle[i].find("</syntax>")+9-vDocArticle[i].find("<syntax>"),
1214 "</p><h4>Syntax</h4>" + formatCodeBlock(sExprBlock, generateFile, false, _option)
1215 + "<h4>" + _lang.get("DOC_HELP_DESC_HEADLINE") + "</h4><p>");
1216 }
1217
1218 doc_ReplaceTokensForHTML(vDocArticle[i], generateFile, _option);
1219 sHTML += "<p>" + vDocArticle[i] + "</p>\n";
1220 }
1221 else
1222 {
1223 if (vDocArticle[i] != "<syntax>")
1224 sHTML += "<p>" + (vDocArticle[i].substr(0, vDocArticle[i].find("<syntax>"))) + "</p>\n";
1225
1226 sHTML += "<h4>Syntax</h4>\n";
1227 std::string sCodeContent;
1228
1229 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1230 {
1231 if (vDocArticle[j].find("</syntax>") != std::string::npos)
1232 {
1233 i = j;
1234 sHTML += formatCodeBlock(sCodeContent.substr(0, sCodeContent.length()-2), generateFile, false, _option)
1235 + "<h4>" + _lang.get("DOC_HELP_DESC_HEADLINE") + "</h4>\n";
1236 break;
1237 }
1238
1239 sCodeContent += vDocArticle[j] + "\\n";
1240 }
1241 }
1242 }
1243 else if (vDocArticle[i].find("<list") != std::string::npos) // Alle LIST-Tags (umgewandelt zu TABLE)
1244 {
1245 if (generateFile)
1246 {
1247 sHTML += "<h4>"+ _lang.get("DOC_HELP_OPTIONS_HEADLINE") +"</h4>\n";
1248 sHTML += "<table style=\"border-collapse:collapse; border-color:rgb(136,136,136);border-width:1px\" border=\"1\" bordercolor=\"#888\" cellspacing=\"0\">\n <tbody>\n";
1249 }
1250 else
1251 {
1252 sHTML += "<table border=\"1\" bordercolor=\"#888\" cellspacing=\"0\">\n <tbody>\n";
1253 }
1254
1255 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1256 {
1257 if (vDocArticle[j].find("</list>") != std::string::npos)
1258 {
1259 sHTML += " </tbody>\n</table>\n";
1260
1261 i = j;
1262 break;
1263 }
1264 else
1265 {
1266 doc_ReplaceTokensForHTML(vDocArticle[j], generateFile, _option);
1267
1268 if (generateFile)
1269 {
1270 sHTML += " <tr>\n";
1271 sHTML += " <td style=\"width:200px;height:19px\"><code><span style=\"color:#00008B;\">"
1272 + (Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5))
1273 + "</span></code></td>\n"
1274 + " <td style=\"width:400px;height:19px\">"
1275 + (vDocArticle[j].substr(vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2)+1, vDocArticle[j].find("</item>")-1-vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2)))
1276 + "</td>\n";
1277 sHTML += " </tr>\n";
1278 }
1279 else
1280 {
1281 if (isIndex)
1282 {
1283 sHTML += " <tr>\n <td width=\"200\"><a href=\"nhlp://"+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5)+"?frame=self\"><code><span style=\"color:#00008B;\">"
1284 + Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5)
1285 + "</span></code></a></td>\n <td>"
1286 + vDocArticle[j].substr(vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2)+1, vDocArticle[j].find("</item>")-1-vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2))
1287 + "</td>\n </tr>\n";
1288 }
1289 else
1290 {
1291 sHTML += " <tr>\n <td width=\"200\"><code><span style=\"color:#00008B;\">"
1292 + Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5)
1293 + "</span></code></td>\n <td>"
1294 + vDocArticle[j].substr(vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2)+1, vDocArticle[j].find("</item>")-1-vDocArticle[j].find('>', vDocArticle[j].find("node=")+5+Documentation::getArgAtPos(vDocArticle[j], vDocArticle[j].find("node=")+5).length()+2))
1295 + "</td>\n </tr>\n";
1296 }
1297 }
1298 }
1299 }
1300 }
1301 else if (vDocArticle[i].find("<table") != std::string::npos) // Table-Tags
1302 {
1303 if (generateFile)
1304 sHTML += "<div align=\"center\"><table style=\"border-collapse:collapse; border-color:rgb(136,136,136);border-width:1px\" border=\"1\" bordercolor=\"#888\" cellspacing=\"0\">\n <tbody>\n";
1305 else
1306 sHTML += "<div align=\"center\"><table border=\"1\" bordercolor=\"#888\" cellspacing=\"0\">\n <tbody>\n";
1307
1308 for (unsigned int j = i+1; j < vDocArticle.size(); j++)
1309 {
1310 if (vDocArticle[j].find("</table>") != std::string::npos)
1311 {
1312 sHTML += " </tbody>\n</table></div>\n";
1313 i = j;
1314 break;
1315 }
1316 else
1317 {
1318 doc_ReplaceTokensForHTML(vDocArticle[j], generateFile, _option);
1319 sHTML += vDocArticle[j] + "\n";
1320 }
1321 }
1322 }
1323 else // Normaler Paragraph
1324 {
1325 doc_ReplaceTokensForHTML(vDocArticle[i], generateFile, _option);
1326 sHTML += "<p>" + vDocArticle[i] + "</p>";
1327
1328 if (generateFile)
1329 sHTML += "\n";
1330 }
1331 }
1332
1333 if (generateFile)
1334 sHTML += "<!-- END COPYING HERE -->\n</body>\n</html>\n";
1335 else
1336 sHTML += "</body>\n</html>\n";
1337
1338 return sHTML;
1339}
1340
1341
1352void doc_SearchFct(const std::string& sToLookFor, Settings& _option)
1353{
1354 static NumeRe::DataBase findDataBase;
1355 static std::vector<double> vWeighting({3.0, 2.0, 1.0});
1356
1357 // Load the database if not done already
1358 if (!findDataBase.size())
1359 {
1360 findDataBase.addData("<>/docs/find.ndb");
1361
1362 if (_option.useCustomLangFiles() && fileExists(_option.ValidFileName("<>/user/docs/find.ndb", ".ndb")))
1363 findDataBase.addData("<>/user/docs/find.ndb");
1364 }
1365
1366 // Search for matches in the database
1367 std::map<double,std::vector<size_t>> mMatches = findDataBase.findRecordsUsingRelevance(sToLookFor, vWeighting);
1368
1369 // If nothig has been found, report that to the user
1370 if (!mMatches.size())
1371 {
1373 make_hline();
1374 NumeReKernel::print(_lang.get("DOC_SEARCHFCT_NO_RESULTS", sToLookFor));
1376 make_hline();
1377 return;
1378 }
1379
1380 double dMax = mMatches.rbegin()->first;
1381 size_t nCount = 0;
1382
1383 // Format the search results accordingly
1385 make_hline();
1386 NumeReKernel::print(toSystemCodePage(toUpperCase(_lang.get("DOC_SEARCHFCT_TABLEHEAD"))));
1387 make_hline();
1388
1389 for (auto iter = mMatches.rbegin(); iter != mMatches.rend(); ++iter)
1390 {
1391 for (size_t j = 0; j < iter->second.size(); j++)
1392 {
1394
1395 if (intCast(iter->first / dMax * 100) != 100)
1397
1398 NumeReKernel::printPreFmt(toString(intCast(iter->first / dMax * 100)) + "%] ");
1399
1400 if (findDataBase.getElement(iter->second[j], 0) == "NumeRe v $$$")
1401 NumeReKernel::printPreFmt("NumeRe v " + sVersion);
1402 else
1403 NumeReKernel::printPreFmt(toSystemCodePage(findDataBase.getElement(iter->second[j], 0)));
1404
1406
1407 if (findDataBase.getElement(iter->second[j], 0) == "NumeRe v $$$")
1408 NumeReKernel::printPreFmt(findDataBase.getElement(iter->second[j], 1).substr(0, findDataBase.getElement(iter->second[j], 1).find("$$$")) + replacePathSeparator(_option.getExePath()) + "\n");
1409 else
1410 NumeReKernel::printPreFmt(findDataBase.getElement(iter->second[j], 1) + "\n");
1411
1412 nCount++;
1413 }
1414 }
1415
1417 NumeReKernel::print(toSystemCodePage(_lang.get("DOC_SEARCHFCT_RESULT", toString(nCount))));
1419 make_hline();
1420}
1421
const std::string sVersion
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
std::string getHelpArticleID(const std::string &sTopic)
This member function returns the article ID corresponding to the queried topic.
Definition: doc_helper.cpp:712
std::string getHelpIdxKey(const std::string &sTopic)
This member function returns an index key, which corresponds to the queried topic.
Definition: doc_helper.cpp:687
std::vector< std::string > getHelpArticle(const std::string &sTopic)
This member function returns the documentation article, which corresponds to the passed documentation...
Definition: doc_helper.cpp:581
std::string getHelpArticleTitle(const std::string &_sIdxKey)
This member function returns the documentation article title corresponding to the queried index key.
Definition: doc_helper.cpp:732
static std::string getArgAtPos(const std::string &sCmd, unsigned int pos)
This static member is a fallback for the XML-parsing logic-stuff.
Definition: doc_helper.cpp:382
std::string ValidizeAndPrepareName(const std::string &_sFileName, const std::string &sExtension=".dat") const
This member function validizes the passed file name and creates the needed folders on-the-fly.
Definition: filesystem.cpp:424
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 declareFileType(const std::string &sFileType)
Definition: filesystem.hpp:132
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
This class is an implementation of a database. It will handle the *.ndb data format an provides an in...
Definition: database.hpp:37
std::map< double, std::vector< size_t > > findRecordsUsingRelevance(const std::string &_sSearchString, std::vector< double > vWeighting=std::vector< double >()) const
This member function will search multiple search strings in the database and returns a map,...
Definition: database.cpp:413
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
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
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
Definition: kernel.hpp:221
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
std::vector< std::string > getPluginCommands()
This member function is used by the syntax highlighter to hightlight the plugin commands.
Definition: kernel.cpp:2329
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
FileSystem & getFileSystem()
Definition: kernel.hpp:258
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
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
Definition: kernel.cpp:3671
This class contains all needed keywords to highlight their occurences correspondingly....
Definition: syntax.hpp:55
std::string highlightLine(const std::string &sCommandLine)
This function applies the highlighting colors to the command line (only used in the terminal).
Definition: syntax.cpp:363
@ SYNTAX_OPTION
Definition: syntax.hpp:92
@ SYNTAX_FUNCTION
Definition: syntax.hpp:93
@ SYNTAX_METHODS
Definition: syntax.hpp:102
@ SYNTAX_STRING
Definition: syntax.hpp:96
@ SYNTAX_PROCEDURE
Definition: syntax.hpp:99
@ SYNTAX_COMMENT
Definition: syntax.hpp:103
@ SYNTAX_CONSTANT
Definition: syntax.hpp:94
@ SYNTAX_COMMAND
Definition: syntax.hpp:91
@ SYNTAX_SPECIALVAL
Definition: syntax.hpp:95
@ SYNTAX_OPERATOR
Definition: syntax.hpp:98
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
std::string getLoadPath() const
Returns the current loading path.
Definition: settings.hpp:1038
std::string getSavePath() const
Returns the current saving path.
Definition: settings.hpp:1029
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
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
std::string & stringval()
Returns a reference to a std::string value type setting.
Definition: settings.hpp:590
Common exception class for all exceptions thrown in NumeRe.
Definition: error.hpp:32
@ CANNOT_GENERATE_FILE
Definition: error.hpp:65
static size_t invalid_position
Definition: error.hpp:235
Language _lang
Definition: kernel.cpp:39
static bool isValue(const std::string &sExpr, size_t nPos, size_t nLength)
Static helper function for doc_ReplaceExprContentForHTML to determine literal values in expressions.
static std::string formatCodeBlock(std::string sCode, bool generateFile, bool verbatim, Settings &_option)
Returns the final HTML string containing the lexed and highlighted code and embeds that into the code...
static std::string createCssString(int style, const Settings &_option)
This static function creates the CSS string for the span element containing the lexed symbol....
static void doc_ReplaceTokensForHTML(std::string &sDocParagraph, bool generateFile, Settings &_option)
Searches for defined XML tokens in the passed string and replaces them with the plain HTML counterpar...
static bool isFunction(const std::string &sExpr, size_t nPos, size_t nLength)
Static helper function for doc_ReplaceExprContentForHTML to determine functions in expressions.
#define VIEWER_CODEBLOCK_START
static std::string applySyntaxHighlighting(const std::string &sCodeString, const Settings &_option)
This static function lexes the passed code string usign a static instance of the NumeReSyntax class.
#define FILE_CODEBLOCK_START
#define VIEWER_CODEBLOCK_END
void doc_SearchFct(const std::string &sToLookFor, Settings &_option)
This function provides the logic for searching for entries in the keywords database.
static std::string getHighlightedCode(std::string sCode, bool verbatim, Settings &_option)
Returns the final HTML string containing the already lexed and highlighted code.
static void doc_ReplaceExprContentForHTML(std::string &sExpr, Settings &_option)
This function replaces tokens in <expr>-tags to improve the readability of mathematical code.
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....
static bool isOperator(const std::string &sExpr, size_t nPos, size_t nLength)
Static helper function for doc_ReplaceExprContentForHTML to determine operators in expressions.
#define FILE_CODEBLOCK_END
void doc_Help(const std::string &__sTopic, Settings &_option)
This function shows the content of a documentation article based upon the passed topic....
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.
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
Definition: tools.cpp:2500
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
Definition: tools.cpp:414
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_ST_FUNCTION
Definition: settings.hpp:134
#define SETTING_S_ST_OPTION
Definition: settings.hpp:133
#define SETTING_S_ST_METHODS
Definition: settings.hpp:145
#define SETTING_S_ST_PROCEDURE
Definition: settings.hpp:143
#define SETTING_S_ST_SPECIALVAL
Definition: settings.hpp:138
#define SETTING_S_ST_COMMENT
Definition: settings.hpp:130
#define SETTING_S_ST_STRING
Definition: settings.hpp:139
#define SETTING_S_ST_OPERATOR
Definition: settings.hpp:142
#define SETTING_S_ST_NUMBER
Definition: settings.hpp:144
#define SETTING_S_ST_COMMAND
Definition: settings.hpp:128
#define SETTING_S_ST_CONSTANT
Definition: settings.hpp:137
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
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...
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.
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
void eraseToken(string &sExpr, const string &sToken, bool bTokenHasValue)
This function erases option tokens including their possible value from a parameter string.
Definition: tools.cpp:2527
void make_hline(int nLength=-1)
This function prints a horizontal line to the terminal using either minus or equal signs.
Definition: kernel.cpp:3720