start work on scaninc

This commit is contained in:
Henny022p 2021-11-30 05:24:07 +01:00
parent 029ce60b3d
commit b6314d9269
6 changed files with 24 additions and 18 deletions

View File

@ -2,5 +2,6 @@ file(GLOB_RECURSE sources *.cpp)
add_executable(scaninc ${sources}) add_executable(scaninc ${sources})
target_include_directories(scaninc PRIVATE .) target_include_directories(scaninc PRIVATE .)
target_link_libraries(scaninc PRIVATE project_settings fmt::fmt)
install(TARGETS scaninc RUNTIME DESTINATION bin) install(TARGETS scaninc RUNTIME DESTINATION bin)

View File

@ -33,7 +33,7 @@ AsmFile::AsmFile(std::string path) {
std::fseek(fp, 0, SEEK_END); std::fseek(fp, 0, SEEK_END);
m_size = std::ftell(fp); m_size = static_cast<size_t>(std::ftell(fp));
m_buffer = new char[m_size]; m_buffer = new char[m_size];
@ -60,8 +60,7 @@ IncDirectiveType AsmFile::ReadUntilIncDirective(std::string& path) {
IncDirectiveType incDirectiveType = IncDirectiveType::None; IncDirectiveType incDirectiveType = IncDirectiveType::None;
char c = PeekChar(); if (char c = static_cast<char>(PeekChar()); c == '.' || c == '#') {
if (c == '.' || c == '#') {
m_pos++; m_pos++;
if (MatchIncDirective("incbin", path)) if (MatchIncDirective("incbin", path))
@ -95,8 +94,8 @@ IncDirectiveType AsmFile::ReadUntilIncDirective(std::string& path) {
} }
std::string AsmFile::ReadPath() { std::string AsmFile::ReadPath() {
int length = 0; size_t length = 0;
int startPos = m_pos; size_t startPos = m_pos;
for (;;) { for (;;) {
int c = GetChar(); int c = GetChar();

View File

@ -34,8 +34,8 @@ class AsmFile {
private: private:
char* m_buffer; char* m_buffer;
int m_pos; size_t m_pos;
int m_size; size_t m_size;
int m_lineNum; int m_lineNum;
std::string m_path; std::string m_path;
@ -74,8 +74,8 @@ class AsmFile {
} }
bool MatchIncDirective(std::string directiveName, std::string& path) { bool MatchIncDirective(std::string directiveName, std::string& path) {
int length = directiveName.length(); size_t length = directiveName.length();
int i; size_t i;
for (i = 0; i < length && m_pos + i < m_size; i++) for (i = 0; i < length && m_pos + i < m_size; i++)
if (directiveName[i] != m_buffer[m_pos + i]) if (directiveName[i] != m_buffer[m_pos + i])

View File

@ -30,7 +30,7 @@ CFile::CFile(std::string path) {
std::fseek(fp, 0, SEEK_END); std::fseek(fp, 0, SEEK_END);
m_size = std::ftell(fp); m_size = static_cast<size_t>(std::ftell(fp));
m_buffer = new char[m_size + 1]; m_buffer = new char[m_size + 1];
m_buffer[m_size] = 0; m_buffer[m_size] = 0;
@ -144,7 +144,7 @@ void CFile::SkipWhitespace() {
bool CFile::CheckIdentifier(const std::string& ident) { bool CFile::CheckIdentifier(const std::string& ident) {
unsigned int i; 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]) if (ident[i] != m_buffer[m_pos + i])
return false; return false;
@ -193,8 +193,8 @@ void CFile::CheckIncbin() {
if (incbinType == -1) if (incbinType == -1)
return; return;
long oldPos = m_pos; auto oldPos = m_pos;
long oldLineNum = m_lineNum; auto oldLineNum = m_lineNum;
m_pos += idents[incbinType].length(); m_pos += idents[incbinType].length();
@ -239,7 +239,7 @@ std::string CFile::ReadPath() {
m_pos++; m_pos++;
int startPos = m_pos; auto startPos = m_pos;
while (m_buffer[m_pos] != '"') { while (m_buffer[m_pos] != '"') {
if (m_buffer[m_pos] == 0) { if (m_buffer[m_pos] == 0) {

View File

@ -40,8 +40,8 @@ class CFile {
private: private:
char* m_buffer; char* m_buffer;
int m_pos; size_t m_pos;
int m_size; size_t m_size;
int m_lineNum; int m_lineNum;
std::string m_path; std::string m_path;
std::set<std::string> m_incbins; std::set<std::string> m_incbins;

View File

@ -23,6 +23,7 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <fmt/format.h>
#ifdef _MSC_VER #ifdef _MSC_VER
@ -40,18 +41,23 @@
#else #else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#define FATAL_INPUT_ERROR(format, ...) \ #define FATAL_INPUT_ERROR(format, ...) \
do { \ 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); \ exit(1); \
} while (0) } while (0)
#define FATAL_ERROR(format, ...) \ #define FATAL_ERROR(format, ...) \
do { \ do { \
fprintf(stderr, format, ##__VA_ARGS__); \ fmt::print(stderr, format, ##__VA_ARGS__); \
exit(1); \ exit(1); \
} while (0) } while (0)
#pragma GCC diagnostic pop
#endif // _MSC_VER #endif // _MSC_VER
#define SCANINC_MAX_PATH 255 #define SCANINC_MAX_PATH 255