summaryrefslogtreecommitdiff
path: root/src/factories/IncludeFactory.cpp
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2024-03-24 21:27:07 -0600
committerGitHub <noreply@github.com>2024-03-24 21:27:07 -0600
commit81f4371c2083c5f31c8abc07592d25c9f69741a6 (patch)
tree362abce06cee12f726d175df261c44a12108a279 /src/factories/IncludeFactory.cpp
parentcd7dd6f59a9b0ffb867fcd7b80a6c05def701088 (diff)
Add Include Factory (#51)
* Add Include Factory * Fix * Fixes * Update --------- Co-authored-by: = <=>
Diffstat (limited to 'src/factories/IncludeFactory.cpp')
-rw-r--r--src/factories/IncludeFactory.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/factories/IncludeFactory.cpp b/src/factories/IncludeFactory.cpp
new file mode 100644
index 0000000..bf3d268
--- /dev/null
+++ b/src/factories/IncludeFactory.cpp
@@ -0,0 +1,48 @@
+#include "IncludeFactory.h"
+#include "spdlog/spdlog.h"
+
+#include "Companion.h"
+#include "utils/Decompressor.h"
+
+#define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x
+#define COL(c) std::dec << std::setfill(' ') << std::setw(3) << c
+
+ExportResult IncludeHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
+ const auto symbol = GetSafeNode(node, "symbol", entryName);
+ auto ctype = GetSafeNode<std::string>(node, "ctype");
+
+ if(Companion::Instance->IsOTRMode()){
+ write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
+ return std::nullopt;
+ }
+
+ write << "extern " << ctype << " " << symbol << "[];\n";
+ return std::nullopt;
+}
+
+ExportResult IncludeCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ const auto symbol = GetSafeNode(node, "symbol", entryName);
+ const auto file = GetSafeNode<std::string>(node, "file_path");
+ const auto ctype = GetSafeNode<std::string>(node, "ctype");
+ SPDLOG_INFO("writing INC");
+ write << ctype << " " << symbol << "[] = {\n";
+
+ write << fourSpaceTab << "#include '" << file << "'\n";
+
+ write << "};\n\n";
+
+ return std::nullopt;
+}
+
+ExportResult IncludeBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ throw std::runtime_error("Include factory should not be used for otr/o2r mode.");
+ return std::nullopt;
+}
+
+std::optional<std::shared_ptr<IParsedData>> IncludeFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
+
+ SPDLOG_INFO("parsing INC");
+ const uint32_t blank = 1;
+
+ return std::make_shared<IncludeData>(blank);
+} \ No newline at end of file