#include "MyString.h" #include "List.h" #include "Logger.h" #include "replacer.h" #include #include #include struct InnerCategory { bool isLabel = false; String label; String path; void toCode(StringBuilder& sb) { if (isLabel) { sb.format("\t\t\t\t\t
  • \n", label.getValue()); } else { sb.format("\t\t\t\t\t
  • %s
  • \n", path.getValue(), path.getValue(), label.getValue()); } } void free() { label.free(); path.free(); } }; struct OuterCategory { String outerName; String outerSymbol; List items; void toCode(StringBuilder& sb) { sb.addStr("\t\t\t
  • \n"); sb.format("\t\t\t\t%s%s\n", outerSymbol.getValue(), outerName.getValue()); sb.addStr("\t\t\t\t
      \n"); FOREACH(items) { value->toCode(sb); } sb.addStr("\t\t\t\t
    \n"); sb.addStr("\t\t\t
  • \n"); } void reset() { outerName.free(); outerSymbol.free(); items.clear(); } void free() { outerName.free(); outerSymbol.free(); FOREACH(items) { value->free(); } items.deallocate(); } }; int main() { logger_info("Running transpiler"); FILE* pagesFile = fopen("tools/transpiler/pages.txt", "r+"); char * cLine = NULL; size_t len = 0; ssize_t read; StringBuilder sb; StringBuilder otherSb; sb.addStr("\t\t\n"); oc.reset(); fclose(pagesFile); String navbarRetval = sb.toString(); sb.clear(); logger_info("Creating served files"); // Create the header FOREACH(servedFiles) { otherSb.clear(); otherSb.format("%s.content", value->getValue()); String contentFileName = otherSb.toString(); FILE* contentFile = fopen(contentFileName.getValue(), "r+"); if (contentFile == NULL) { logger_warning("Could not output file, most likely unimplemented: %s", contentFileName.getValue()); continue; } logger_info("Outputting file: %s", contentFileName.getValue()); // Header sb.addStr("\n" "\n" "\t\n" "\t\t\n" "\t\t\n" "\t\tPhysics for Games\n" "\t\t\n" "\t\t\n" "\t\t\n" "\t\n" "\t\n" "\t\t
    \n" "\t\t\t

    Physics for Games

    \n" "\t\t
    \n" "\t\t
    \n"); // Write navigation bar sb.addStr(navbarRetval.getValue()); // Read body fseek(contentFile, 0, SEEK_END); long fsize = ftell(contentFile); fseek(contentFile, 0, SEEK_SET); char* bodyContent = new char[fsize + 1]; fread(bodyContent, 1, fsize, contentFile); bodyContent[fsize] = '\0'; auto processedBody = insertCodeSnippets(contentFileName.getValue(), bodyContent); sb.addStr(processedBody.c_str()); delete [] bodyContent; contentFileName.free(); fclose(contentFile); // Footer sb.addStr("\t\t
    \n" "\t\n" "\n"); FILE* outFile = fopen(value->getValue(), "w+"); String outStr = sb.toString(); fwrite(outStr.getValue(), 1, outStr.length, outFile); outStr.free(); fclose(outFile); sb.clear(); } logger_info("Outputting files to their proper directories..."); sb.free(); navbarRetval.free(); otherSb.free(); FOREACH(servedFiles) { value->free(); } servedFiles.deallocate(); return 0; }