main.cpp 4.3 KB

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