main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "../../Source/DFPSR/includeFramework.h"
  2. using namespace dsr;
  3. // This program is only for maintaining the library's documentation,
  4. // so it's okay to use features specific to the Linux operating system.
  5. String ResourceFolderPath;
  6. bool string_beginsWith(const ReadableString &a, const ReadableString &b) {
  7. return string_caseInsensitiveMatch(string_before(a, string_length(b)), b);
  8. }
  9. void processContent(String &target, String content) {
  10. string_split_callback([&target](ReadableString section) {
  11. //printText(U"Processing: ", section, U"\n");
  12. if (string_length(section) == 0) {
  13. //printText(U" Break\n");+
  14. string_append(target, U"\n</P><P>\n");
  15. } else if (string_match(section, U"*")) {
  16. //printText(U" Dot\n");
  17. string_append(target, U"<IMG SRC=\"Images/SmallDot.png\">\n");
  18. } else if (string_match(section, U"---")) {
  19. //printText(U" Border\n");
  20. string_append(target, U"</P><IMG SRC=\"Images/Border.png\"><P>\n");
  21. } else if (string_beginsWith(section, U"<-")) {
  22. ReadableString arguments = string_from(section, 2);
  23. int splitIndex = string_findFirst(arguments, U'|');
  24. if (splitIndex > -1) {
  25. ReadableString link = string_removeOuterWhiteSpace(string_before(arguments, splitIndex));
  26. ReadableString text = string_removeOuterWhiteSpace(string_after(arguments, splitIndex));
  27. //printText(U" Link to ", link, U" as ", text, U"\n");
  28. string_append(target, U"<A href=\"", link, "\">", text, "</A>");
  29. } else {
  30. //printText(U" Link to ", arguments, U"\n");
  31. string_append(target, U"<A href=\"", arguments, "\">", arguments, "</A>");
  32. }
  33. } else if (string_beginsWith(section, U"Image:")) {
  34. ReadableString arguments = string_from(section, 6);
  35. int splitIndex = string_findFirst(arguments, U'|');
  36. if (splitIndex > -1) {
  37. ReadableString image = string_removeOuterWhiteSpace(string_before(arguments, splitIndex));
  38. ReadableString text = string_removeOuterWhiteSpace(string_after(arguments, splitIndex));
  39. //printText(U" Image at ", image, U" as ", text, U"\n");
  40. string_append(target, U"<IMG SRC=\"", image, "\" ALT=\"", text, "\">\n");
  41. } else {
  42. //printText(U" Image at ", arguments, U"\n");
  43. string_append(target, U"<IMG SRC=\"", arguments, "\" ALT=\"\">\n");
  44. }
  45. } else if (string_beginsWith(section, U"Title:")) {
  46. ReadableString title = string_from(section, 6);
  47. //printText(U" Title: ", title, U"\n");
  48. string_append(target, U"</P><H1>", title, U"</H1><P>");
  49. } else if (string_beginsWith(section, U"Title2:")) {
  50. ReadableString title = string_from(section, 7);
  51. //printText(U" Title2: ", title, U"\n");
  52. string_append(target, U"</P><H2>", title, U"</H2><P>");
  53. } else if (string_beginsWith(section, U"Title3:")) {
  54. ReadableString title = string_from(section, 7);
  55. //printText(U" Title3: ", title, U"\n");
  56. string_append(target, U"</P><H3>", title, U"</H3><P>");
  57. } else if (string_beginsWith(section, U"Code:")) {
  58. // TODO: Find a clean syntax for multi-line quotes in <PRE><BLOCKQUOTE>...</PRE></BLOCKQUOTE>
  59. ReadableString code = string_from(section, 5);
  60. //printText(U" Code: ", code, U"\n");
  61. string_append(target, U"<blockquote>", code, U"</blockquote>");
  62. } else {
  63. string_append(target, section, U"\n");
  64. }
  65. }, content, U'\n');
  66. }
  67. String generateHtml(String content) {
  68. String style = string_load(ResourceFolderPath + U"Default.css");
  69. String result = U"<!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>\n";
  70. string_append(result, style);
  71. string_append(result, U"</STYLE> </HEAD> <BODY>\n");
  72. string_append(result, U"<IMG SRC=\"Images/Title.png\" ALT=\"Images/Title.png\">\n");
  73. string_append(result, U"<P>\n");
  74. processContent(result, content);
  75. string_append(result, U"</P>\n");
  76. string_append(result, U"</BODY> </HTML>\n");
  77. return result;
  78. }
  79. int main(int argn, char **argv) {
  80. if (argn != 4) {
  81. printText(U"The generator needs filenames for target!\n");
  82. return 1;
  83. }
  84. String SourceFilePath = argv[1];
  85. String TargetFilePath = argv[2];
  86. ResourceFolderPath = argv[3];
  87. printText(U"Generating ", TargetFilePath, U" from ", SourceFilePath, U" using the style", ResourceFolderPath, U"\n");
  88. String content = string_load(SourceFilePath);
  89. String result = generateHtml(content);
  90. string_save(TargetFilePath, result);
  91. printText(U"Done\n");
  92. return 0;
  93. }