diff options
| author | Tal Hayon <talhayon1@gmail.com> | 2022-05-13 18:44:14 +0300 |
|---|---|---|
| committer | Tal Hayon <talhayon1@gmail.com> | 2022-05-13 21:46:39 +0300 |
| commit | 2062499f0c17e7564e30b4a9c7ae96a32491c5c1 (patch) | |
| tree | 31962be30046c40c67b27ef14afed943466ff5fa /tools/src | |
| parent | b675bce0d1d75cf2c703fb26e5e864e3ee789b8e (diff) | |
Initial version of enum extractor script
Diffstat (limited to 'tools/src')
| -rw-r--r-- | tools/src/preproc/asm_file.cpp | 11 | ||||
| -rw-r--r-- | tools/src/preproc/preproc.cpp | 16 | ||||
| -rw-r--r-- | tools/src/preproc/preproc.h | 1 |
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 |
