diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2018-09-09 20:31:56 +0200 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2018-09-09 20:31:56 +0200 |
commit | cf8898071d0aa02438be2b1b1d03a6e6b33892be (patch) | |
tree | 645e643948653d0ae99a9187aab5e769c1ac3737 /tools/preproc/c_file.cpp | |
parent | 4d1df7ecbe69cf151d00976648aa34faae8cd6e9 (diff) | |
parent | e21b91cc2f48c4b6bf2cb2d8e97ea1d55c0163bb (diff) |
Merge branch 'decompile_frontier_2' of https://github.com/DizzyEggg/pokeemerald into decompile_frontier_2
Diffstat (limited to 'tools/preproc/c_file.cpp')
-rw-r--r-- | tools/preproc/c_file.cpp | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index 2f4bfea7c..229f568fa 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -325,66 +325,74 @@ void CFile::TryConvertIncbin() m_pos++; - SkipWhitespace(); + std::printf("{"); - if (m_buffer[m_pos] != '"') - RaiseError("expected double quote"); + while (true) + { + SkipWhitespace(); - m_pos++; + if (m_buffer[m_pos] != '"') + RaiseError("expected double quote"); - int startPos = m_pos; + m_pos++; - while (m_buffer[m_pos] != '"') - { - if (m_buffer[m_pos] == 0) - { - if (m_pos >= m_size) - RaiseError("unexpected EOF in path string"); - else - RaiseError("unexpected null character in path string"); - } + int startPos = m_pos; - if (m_buffer[m_pos] == '\r' || m_buffer[m_pos] == '\n') - RaiseError("unexpected end of line character in path string"); + while (m_buffer[m_pos] != '"') + { + if (m_buffer[m_pos] == 0) + { + if (m_pos >= m_size) + RaiseError("unexpected EOF in path string"); + else + RaiseError("unexpected null character in path string"); + } - if (m_buffer[m_pos] == '\\') - RaiseError("unexpected escape in path string"); - - m_pos++; - } + if (m_buffer[m_pos] == '\r' || m_buffer[m_pos] == '\n') + RaiseError("unexpected end of line character in path string"); - std::string path(&m_buffer[startPos], m_pos - startPos); + if (m_buffer[m_pos] == '\\') + RaiseError("unexpected escape in path string"); + + m_pos++; + } - m_pos++; + std::string path(&m_buffer[startPos], m_pos - startPos); - SkipWhitespace(); + m_pos++; - if (m_buffer[m_pos] != ')') - RaiseError("expected ')'"); + int fileSize; + std::unique_ptr<unsigned char[]> buffer = ReadWholeFile(path, fileSize); - m_pos++; + if ((fileSize % size) != 0) + RaiseError("Size %d doesn't evenly divide file size %d.\n", size, fileSize); - std::printf("{"); + int count = fileSize / size; + int offset = 0; - int fileSize; - std::unique_ptr<unsigned char[]> buffer = ReadWholeFile(path, fileSize); + for (int i = 0; i < count; i++) + { + int data = ExtractData(buffer, offset, size); + offset += size; - if ((fileSize % size) != 0) - RaiseError("Size %d doesn't evenly divide file size %d.\n", size, fileSize); + if (isSigned) + std::printf("%d,", data); + else + std::printf("%uu,", data); + } - int count = fileSize / size; - int offset = 0; + SkipWhitespace(); - for (int i = 0; i < count; i++) - { - int data = ExtractData(buffer, offset, size); - offset += size; + if (m_buffer[m_pos] != ',') + break; - if (isSigned) - std::printf("%d,", data); - else - std::printf("%uu,", data); + m_pos++; } + + if (m_buffer[m_pos] != ')') + RaiseError("expected ')'"); + + m_pos++; std::printf("}"); } |