diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aif2pcm/Makefile | 10 | ||||
-rw-r--r-- | tools/bin2c/Makefile | 10 | ||||
-rw-r--r-- | tools/gbafix/Makefile | 10 | ||||
-rw-r--r-- | tools/gbagfx/Makefile | 12 | ||||
-rwxr-xr-x | tools/jsonproc/Makefile | 10 | ||||
-rw-r--r-- | tools/mapjson/Makefile | 10 | ||||
-rw-r--r-- | tools/mapjson/mapjson.cpp | 2 | ||||
-rw-r--r-- | tools/mid2agb/Makefile | 10 | ||||
-rw-r--r-- | tools/preproc/Makefile | 10 | ||||
-rw-r--r-- | tools/preproc/c_file.cpp | 55 | ||||
-rw-r--r-- | tools/preproc/c_file.h | 5 | ||||
-rw-r--r-- | tools/preproc/preproc.cpp | 22 | ||||
-rw-r--r-- | tools/ramscrgen/Makefile | 10 | ||||
-rw-r--r-- | tools/rsfont/Makefile | 10 | ||||
-rw-r--r-- | tools/scaninc/Makefile | 10 |
15 files changed, 151 insertions, 45 deletions
diff --git a/tools/aif2pcm/Makefile b/tools/aif2pcm/Makefile index 77df29152..dd48a8759 100644 --- a/tools/aif2pcm/Makefile +++ b/tools/aif2pcm/Makefile @@ -6,12 +6,18 @@ LIBS = -lm SRCS = main.c extended.c +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: aif2pcm +all: aif2pcm$(EXE) @: -aif2pcm: $(SRCS) +aif2pcm$(EXE): $(SRCS) $(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) $(LIBS) clean: diff --git a/tools/bin2c/Makefile b/tools/bin2c/Makefile index 52806e39c..4dbfab94f 100644 --- a/tools/bin2c/Makefile +++ b/tools/bin2c/Makefile @@ -6,10 +6,16 @@ CFLAGS = -Wall -Wextra -Werror -std=c11 -O2 SRCS = bin2c.c -all: bin2c +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + +all: bin2c$(EXE) @: -bin2c: $(SRCS) +bin2c$(EXE): $(SRCS) $(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/gbafix/Makefile b/tools/gbafix/Makefile index 91a60a9e4..efb016c97 100644 --- a/tools/gbafix/Makefile +++ b/tools/gbafix/Makefile @@ -3,10 +3,16 @@ CC ?= gcc SRCS = gbafix.c -all: gbafix +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + +all: gbafix$(EXE) @: -gbafix: $(SRCS) +gbafix$(EXE): $(SRCS) $(CC) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/gbagfx/Makefile b/tools/gbagfx/Makefile index f0638414d..b4244aa8d 100644 --- a/tools/gbagfx/Makefile +++ b/tools/gbagfx/Makefile @@ -6,15 +6,21 @@ LIBS = -lpng -lz SRCS = main.c convert_png.c gfx.c jasc_pal.c lz.c rl.c util.c font.c huff.c +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: gbagfx +all: gbagfx$(EXE) @: -gbagfx-debug: $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h rl.h util.h font.h +gbagfx-debug$(EXE): $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h rl.h util.h font.h $(CC) $(CFLAGS) -DDEBUG $(SRCS) -o $@ $(LDFLAGS) $(LIBS) -gbagfx: $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h rl.h util.h font.h +gbagfx$(EXE): $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h rl.h util.h font.h $(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) $(LIBS) clean: diff --git a/tools/jsonproc/Makefile b/tools/jsonproc/Makefile index 47198b171..eec73eb7b 100755 --- a/tools/jsonproc/Makefile +++ b/tools/jsonproc/Makefile @@ -8,12 +8,18 @@ SRCS := jsonproc.cpp HEADERS := jsonproc.h inja.hpp nlohmann/json.hpp +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: jsonproc +all: jsonproc$(EXE) @: -jsonproc: $(SRCS) $(HEADERS) +jsonproc$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(INCLUDES) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/mapjson/Makefile b/tools/mapjson/Makefile index c1f703f9f..100e809c6 100644 --- a/tools/mapjson/Makefile +++ b/tools/mapjson/Makefile @@ -6,12 +6,18 @@ SRCS := json11.cpp mapjson.cpp HEADERS := mapjson.h +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: mapjson +all: mapjson$(EXE) @: -mapjson: $(SRCS) $(HEADERS) +mapjson$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 5e246ff24..d767b469e 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -395,7 +395,7 @@ string generate_map_constants_text(string groups_filepath, Json groups_data) { int group_num = 0; for (auto &group : groups_data["group_order"].array_items()) { - text << "// Map Group " << group_num << "\n"; + text << "// " << group.string_value() << "\n"; vector<Json> map_ids; size_t max_length = 0; diff --git a/tools/mid2agb/Makefile b/tools/mid2agb/Makefile index 451d4b39f..553b7859e 100644 --- a/tools/mid2agb/Makefile +++ b/tools/mid2agb/Makefile @@ -6,12 +6,18 @@ SRCS := agb.cpp error.cpp main.cpp midi.cpp tables.cpp HEADERS := agb.h error.h main.h midi.h tables.h +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: mid2agb +all: mid2agb$(EXE) @: -mid2agb: $(SRCS) $(HEADERS) +mid2agb$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/preproc/Makefile b/tools/preproc/Makefile index 8c48afea2..1507c973f 100644 --- a/tools/preproc/Makefile +++ b/tools/preproc/Makefile @@ -8,12 +8,18 @@ SRCS := asm_file.cpp c_file.cpp charmap.cpp preproc.cpp string_parser.cpp \ HEADERS := asm_file.h c_file.h char_util.h charmap.h preproc.h string_parser.h \ utf8.h +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + .PHONY: all clean -all: preproc +all: preproc$(EXE) @: -preproc: $(SRCS) $(HEADERS) +preproc$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index b996a048c..17a08cc9f 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -23,32 +23,59 @@ #include <stdexcept> #include <string> #include <memory> +#include <cstring> +#include <cerrno> #include "preproc.h" #include "c_file.h" #include "char_util.h" #include "utf8.h" #include "string_parser.h" -CFile::CFile(std::string filename) : m_filename(filename) +CFile::CFile(const char * filenameCStr, bool isStdin) { - FILE *fp = std::fopen(filename.c_str(), "rb"); + FILE *fp; + + if (isStdin) { + fp = stdin; + m_filename = std::string{"<stdin>/"}.append(filenameCStr); + } else { + fp = std::fopen(filenameCStr, "rb"); + m_filename = std::string(filenameCStr); + } + + std::string& filename = m_filename; 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); + m_size = 0; + m_buffer = (char *)malloc(CHUNK_SIZE + 1); + if (m_buffer == NULL) { + FATAL_ERROR("Failed to allocate memory to process file \"%s\"!", filename.c_str()); + } - if (m_size < 0) - FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); + std::size_t numAllocatedBytes = CHUNK_SIZE + 1; + std::size_t bufferOffset = 0; + std::size_t count; - m_buffer = new char[m_size + 1]; + while ((count = std::fread(m_buffer + bufferOffset, 1, CHUNK_SIZE, fp)) != 0) { + if (!std::ferror(fp)) { + m_size += count; - std::rewind(fp); + if (std::feof(fp)) { + break; + } - if (std::fread(m_buffer, m_size, 1, fp) != 1) - FATAL_ERROR("Failed to read \"%s\".\n", filename.c_str()); + numAllocatedBytes += CHUNK_SIZE; + bufferOffset += CHUNK_SIZE; + m_buffer = (char *)realloc(m_buffer, numAllocatedBytes); + if (m_buffer == NULL) { + FATAL_ERROR("Failed to allocate memory to process file \"%s\"!", filename.c_str()); + } + } else { + FATAL_ERROR("Failed to read \"%s\". (error: %s)", filename.c_str(), std::strerror(errno)); + } + } m_buffer[m_size] = 0; @@ -56,6 +83,7 @@ CFile::CFile(std::string filename) : m_filename(filename) m_pos = 0; m_lineNum = 1; + m_isStdin = isStdin; } CFile::CFile(CFile&& other) : m_filename(std::move(other.m_filename)) @@ -64,13 +92,14 @@ CFile::CFile(CFile&& other) : m_filename(std::move(other.m_filename)) m_pos = other.m_pos; m_size = other.m_size; m_lineNum = other.m_lineNum; + m_isStdin = other.m_isStdin; - other.m_buffer = nullptr; + other.m_buffer = NULL; } CFile::~CFile() { - delete[] m_buffer; + free(m_buffer); } void CFile::Preproc() diff --git a/tools/preproc/c_file.h b/tools/preproc/c_file.h index 7369aba85..49e633a18 100644 --- a/tools/preproc/c_file.h +++ b/tools/preproc/c_file.h @@ -30,7 +30,7 @@ class CFile { public: - CFile(std::string filename); + CFile(const char * filenameCStr, bool isStdin); CFile(CFile&& other); CFile(const CFile&) = delete; ~CFile(); @@ -42,6 +42,7 @@ private: long m_size; long m_lineNum; std::string m_filename; + bool m_isStdin; bool ConsumeHorizontalWhitespace(); bool ConsumeNewline(); @@ -55,4 +56,6 @@ private: void RaiseWarning(const char* format, ...); }; +#define CHUNK_SIZE 4096 + #endif // C_FILE_H diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index c9c6042df..eb2d4c8a2 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -103,9 +103,9 @@ void PreprocAsmFile(std::string filename) } } -void PreprocCFile(std::string filename) +void PreprocCFile(const char * filename, bool isStdin) { - CFile cFile(filename); + CFile cFile(filename, isStdin); cFile.Preproc(); } @@ -132,9 +132,9 @@ char* GetFileExtension(char* filename) int main(int argc, char **argv) { - if (argc != 3) + if (argc < 3 || argc > 4) { - std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE", argv[0]); + std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE [-i]\nwhere -i denotes if input is from stdin\n", argv[0]); return 1; } @@ -147,9 +147,17 @@ int main(int argc, char **argv) if ((extension[0] == 's') && extension[1] == 0) PreprocAsmFile(argv[1]); - else if ((extension[0] == 'c' || extension[0] == 'i') && extension[1] == 0) - PreprocCFile(argv[1]); - else + else if ((extension[0] == 'c' || extension[0] == 'i') && extension[1] == 0) { + if (argc == 4) { + if (argv[3][0] == '-' && argv[3][1] == 'i' && argv[3][2] == '\0') { + PreprocCFile(argv[1], true); + } else { + FATAL_ERROR("unknown argument flag \"%s\".\n", argv[3]); + } + } else { + PreprocCFile(argv[1], false); + } + } else FATAL_ERROR("\"%s\" has an unknown file extension of \"%s\".\n", argv[1], extension); return 0; diff --git a/tools/ramscrgen/Makefile b/tools/ramscrgen/Makefile index 4e901a29c..a9375c87a 100644 --- a/tools/ramscrgen/Makefile +++ b/tools/ramscrgen/Makefile @@ -8,10 +8,16 @@ HEADERS := ramscrgen.h sym_file.h elf.h char_util.h .PHONY: all clean -all: ramscrgen +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + +all: ramscrgen$(EXE) @: -ramscrgen: $(SRCS) $(HEADERS) +ramscrgen$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: diff --git a/tools/rsfont/Makefile b/tools/rsfont/Makefile index 930a92b36..0bc88a42b 100644 --- a/tools/rsfont/Makefile +++ b/tools/rsfont/Makefile @@ -8,10 +8,16 @@ SRCS = main.c convert_png.c util.c font.c .PHONY: all clean -all: rsfont +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + +all: rsfont$(EXE) @: -rsfont: $(SRCS) convert_png.h gfx.h global.h util.h font.h +rsfont$(EXE): $(SRCS) convert_png.h gfx.h global.h util.h font.h $(CC) $(CFLAGS) $(SRCS) -o $@ $(LDFLAGS) $(LIBS) clean: diff --git a/tools/scaninc/Makefile b/tools/scaninc/Makefile index 52e663d8d..96d92f706 100644 --- a/tools/scaninc/Makefile +++ b/tools/scaninc/Makefile @@ -8,10 +8,16 @@ HEADERS := scaninc.h asm_file.h c_file.h source_file.h .PHONY: all clean -all: scaninc +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif + +all: scaninc$(EXE) @: -scaninc: $(SRCS) $(HEADERS) +scaninc$(EXE): $(SRCS) $(HEADERS) $(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS) clean: |