diff --git a/tools/src/scaninc/CMakeLists.txt b/tools/src/scaninc/CMakeLists.txt index ec335c3a..8f8bbc3e 100644 --- a/tools/src/scaninc/CMakeLists.txt +++ b/tools/src/scaninc/CMakeLists.txt @@ -2,5 +2,6 @@ file(GLOB_RECURSE sources *.cpp) add_executable(scaninc ${sources}) target_include_directories(scaninc PRIVATE .) +target_link_libraries(scaninc PRIVATE project_settings fmt::fmt) install(TARGETS scaninc RUNTIME DESTINATION bin) diff --git a/tools/src/scaninc/asm_file.cpp b/tools/src/scaninc/asm_file.cpp index 0fa0a20d..37aeb933 100644 --- a/tools/src/scaninc/asm_file.cpp +++ b/tools/src/scaninc/asm_file.cpp @@ -33,7 +33,7 @@ AsmFile::AsmFile(std::string path) { std::fseek(fp, 0, SEEK_END); - m_size = std::ftell(fp); + m_size = static_cast(std::ftell(fp)); m_buffer = new char[m_size]; @@ -60,8 +60,7 @@ IncDirectiveType AsmFile::ReadUntilIncDirective(std::string& path) { IncDirectiveType incDirectiveType = IncDirectiveType::None; - char c = PeekChar(); - if (c == '.' || c == '#') { + if (char c = static_cast(PeekChar()); c == '.' || c == '#') { m_pos++; if (MatchIncDirective("incbin", path)) @@ -95,8 +94,8 @@ IncDirectiveType AsmFile::ReadUntilIncDirective(std::string& path) { } std::string AsmFile::ReadPath() { - int length = 0; - int startPos = m_pos; + size_t length = 0; + size_t startPos = m_pos; for (;;) { int c = GetChar(); diff --git a/tools/src/scaninc/asm_file.h b/tools/src/scaninc/asm_file.h index 1f07b169..4ee0fddf 100644 --- a/tools/src/scaninc/asm_file.h +++ b/tools/src/scaninc/asm_file.h @@ -34,8 +34,8 @@ class AsmFile { private: char* m_buffer; - int m_pos; - int m_size; + size_t m_pos; + size_t m_size; int m_lineNum; std::string m_path; @@ -74,8 +74,8 @@ class AsmFile { } bool MatchIncDirective(std::string directiveName, std::string& path) { - int length = directiveName.length(); - int i; + size_t length = directiveName.length(); + size_t i; for (i = 0; i < length && m_pos + i < m_size; i++) if (directiveName[i] != m_buffer[m_pos + i]) diff --git a/tools/src/scaninc/c_file.cpp b/tools/src/scaninc/c_file.cpp index b567d646..fca672e8 100644 --- a/tools/src/scaninc/c_file.cpp +++ b/tools/src/scaninc/c_file.cpp @@ -30,7 +30,7 @@ CFile::CFile(std::string path) { std::fseek(fp, 0, SEEK_END); - m_size = std::ftell(fp); + m_size = static_cast(std::ftell(fp)); m_buffer = new char[m_size + 1]; m_buffer[m_size] = 0; @@ -144,7 +144,7 @@ void CFile::SkipWhitespace() { bool CFile::CheckIdentifier(const std::string& ident) { unsigned int i; - for (i = 0; i < ident.length() && m_pos + i < (unsigned)m_size; i++) + for (i = 0; i < ident.length() && m_pos + i < m_size; i++) if (ident[i] != m_buffer[m_pos + i]) return false; @@ -193,8 +193,8 @@ void CFile::CheckIncbin() { if (incbinType == -1) return; - long oldPos = m_pos; - long oldLineNum = m_lineNum; + auto oldPos = m_pos; + auto oldLineNum = m_lineNum; m_pos += idents[incbinType].length(); @@ -239,7 +239,7 @@ std::string CFile::ReadPath() { m_pos++; - int startPos = m_pos; + auto startPos = m_pos; while (m_buffer[m_pos] != '"') { if (m_buffer[m_pos] == 0) { diff --git a/tools/src/scaninc/c_file.h b/tools/src/scaninc/c_file.h index 2d4fc688..f09b7e3e 100644 --- a/tools/src/scaninc/c_file.h +++ b/tools/src/scaninc/c_file.h @@ -40,8 +40,8 @@ class CFile { private: char* m_buffer; - int m_pos; - int m_size; + size_t m_pos; + size_t m_size; int m_lineNum; std::string m_path; std::set m_incbins; diff --git a/tools/src/scaninc/scaninc.h b/tools/src/scaninc/scaninc.h index 92bff804..d48fb7a7 100644 --- a/tools/src/scaninc/scaninc.h +++ b/tools/src/scaninc/scaninc.h @@ -23,6 +23,7 @@ #include #include +#include #ifdef _MSC_VER @@ -40,18 +41,23 @@ #else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" + #define FATAL_INPUT_ERROR(format, ...) \ do { \ - fprintf(stderr, "%s:%d " format, m_path.c_str(), m_lineNum, ##__VA_ARGS__); \ + fmt::print(stderr, "%s:%d " format, m_path.c_str(), m_lineNum, ##__VA_ARGS__); \ exit(1); \ } while (0) #define FATAL_ERROR(format, ...) \ do { \ - fprintf(stderr, format, ##__VA_ARGS__); \ + fmt::print(stderr, format, ##__VA_ARGS__); \ exit(1); \ } while (0) +#pragma GCC diagnostic pop + #endif // _MSC_VER #define SCANINC_MAX_PATH 255