summaryrefslogtreecommitdiff
path: root/tools/src
diff options
context:
space:
mode:
authornotyourav <65437533+notyourav@users.noreply.github.com>2022-05-17 14:35:16 -0700
committerGitHub <noreply@github.com>2022-05-17 14:35:16 -0700
commit3afbd0e9012be95e687ccb36eb62f6df08cded19 (patch)
tree00b83f84cdefeaa6d4e334d3154278589bdb76b5 /tools/src
parent393db92f245c93927fd402738db8a04f61e0d56d (diff)
parentaceb014a82c89fd1783dc13e7eb3cffc26ac4ca4 (diff)
Merge pull request #516 from hatal175/enumasm
Initial version of enum extractor script
Diffstat (limited to 'tools/src')
-rw-r--r--tools/src/preproc/asm_file.cpp11
-rw-r--r--tools/src/preproc/preproc.cpp16
-rw-r--r--tools/src/preproc/preproc.h1
3 files changed, 19 insertions, 9 deletions
diff --git a/tools/src/preproc/asm_file.cpp b/tools/src/preproc/asm_file.cpp
index 30d6758f..283fed68 100644
--- a/tools/src/preproc/asm_file.cpp
+++ b/tools/src/preproc/asm_file.cpp
@@ -30,14 +30,13 @@
AsmFile::AsmFile(std::string filename) : m_filename(filename) {
FILE* fp = std::fopen(filename.c_str(), "rb");
- if (fp == NULL) {
- // The include might be an asset.
- fp = std::fopen(("build/" + g_buildName + "/assets/" + filename).c_str(), "rb");
-
- if (fp == NULL)
- FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str());
+ for (int i = 0; fp == NULL && i < g_incPaths.size(); i++) {
+ fp = std::fopen((g_incPaths[i] + "/" + filename).c_str(), "rb");
}
+ if (fp == NULL)
+ FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str());
+
std::fseek(fp, 0, SEEK_END);
m_size = std::ftell(fp);
diff --git a/tools/src/preproc/preproc.cpp b/tools/src/preproc/preproc.cpp
index 2aada83d..40bc66e2 100644
--- a/tools/src/preproc/preproc.cpp
+++ b/tools/src/preproc/preproc.cpp
@@ -19,7 +19,9 @@
// THE SOFTWARE.
#include <string>
+#include <cstring>
#include <stack>
+#include <vector>
#include "preproc.h"
#include "asm_file.h"
#include "c_file.h"
@@ -27,6 +29,7 @@
Charmap* g_charmap;
std::string g_buildName;
+std::vector<std::string> g_incPaths;
void PrintAsmBytes(unsigned char* s, int length) {
if (length > 0) {
@@ -117,13 +120,20 @@ char* GetFileExtension(char* filename) {
}
int main(int argc, char** argv) {
- if (argc != 4 && argc != 3) {
- std::fprintf(stderr, "Usage: %s BUILD_NAME SRC_FILE CHARMAP_FILE", argv[0]);
+ if (argc < 3) {
+ std::fprintf(stderr, "Usage: %s BUILD_NAME SRC_FILE [CHARMAP_FILE] -- [ASM INC PATH] ...", argv[0]);
return 1;
}
+ int pathStart = 0;
+ while (pathStart < argc && strcmp(argv[pathStart], "--") != 0) pathStart++;
+
+ for (int i = pathStart + 1; i < argc; i++) {
+ g_incPaths.push_back(argv[i]);
+ }
+
g_buildName = std::string(argv[1]);
- g_charmap = new Charmap(argc == 4 ? argv[3] : "");
+ g_charmap = new Charmap(argc > 3 && pathStart > 3 ? argv[3] : "");
char* extension = GetFileExtension(argv[2]);
diff --git a/tools/src/preproc/preproc.h b/tools/src/preproc/preproc.h
index f896b6ae..f194dcda 100644
--- a/tools/src/preproc/preproc.h
+++ b/tools/src/preproc/preproc.h
@@ -49,5 +49,6 @@ const unsigned long kMaxCharmapSequenceLength = 16;
extern Charmap* g_charmap;
extern std::string g_buildName;
+extern std::vector<std::string> g_incPaths;
#endif // PREPROC_H