diff options
author | yenatch <yenatch@gmail.com> | 2017-07-22 18:49:38 -0400 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2017-07-22 18:49:38 -0400 |
commit | 0faa6c9c93804c4ce0e6fc8e5a6d5cfbc85f01da (patch) | |
tree | 7e42c1ad480d5d0c49e8fd45f2f8766bb0280922 /tools/scaninc/c_file.cpp | |
parent | 5e80a12ec9fcf2201c070712d8e2dcefe2a0e364 (diff) |
scaninc: read c includes
Now editing .h files triggers a rebuild.
Also allow .h and .inc files to be passed as a main argument.
src/ and include/ are temporarily hardcoded.
Diffstat (limited to 'tools/scaninc/c_file.cpp')
-rw-r--r-- | tools/scaninc/c_file.cpp | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/tools/scaninc/c_file.cpp b/tools/scaninc/c_file.cpp index b82276dd6..2dd400967 100644 --- a/tools/scaninc/c_file.cpp +++ b/tools/scaninc/c_file.cpp @@ -145,6 +145,7 @@ void CFile::FindIncbins() } else { + CheckInclude(); CheckIncbin(); if (m_pos >= m_size) @@ -211,6 +212,29 @@ bool CFile::CheckIdentifier(const std::string& ident) return (i == ident.length()); } +void CFile::CheckInclude() +{ + if (m_buffer[m_pos] != '#') + return; + + std::string ident = "#include"; + + if (!CheckIdentifier(ident)) + { + return; + } + + m_pos += ident.length(); + + ConsumeHorizontalWhitespace(); + + std::string path = ReadPath(); + + if (!path.empty()) { + m_includes.emplace(path); + } +} + void CFile::CheckIncbin() { std::string idents[6] = { "INCBIN_S8", "INCBIN_U8", "INCBIN_S16", "INCBIN_U16", "INCBIN_S32", "INCBIN_U32" }; @@ -246,8 +270,28 @@ void CFile::CheckIncbin() SkipWhitespace(); + std::string path = ReadPath(); + + SkipWhitespace(); + + if (m_buffer[m_pos] != ')') + FATAL_INPUT_ERROR("expected ')'"); + + m_pos++; + + m_incbins.emplace(path); +} + +std::string CFile::ReadPath() +{ if (m_buffer[m_pos] != '"') - FATAL_INPUT_ERROR("expected double quote"); + { + if (m_buffer[m_pos] == '<') + { + return std::string(); + } + FATAL_INPUT_ERROR("expected '\"' or '<'"); + } m_pos++; @@ -272,16 +316,7 @@ void CFile::CheckIncbin() m_pos++; } - std::string path(&m_buffer[startPos], m_pos - startPos); - m_pos++; - SkipWhitespace(); - - if (m_buffer[m_pos] != ')') - FATAL_INPUT_ERROR("expected ')'"); - - m_pos++; - - m_incbins.emplace(path); + return std::string(m_buffer, startPos, m_pos - 1 - startPos); } |