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,67 +325,75 @@ void CFile::TryConvertIncbin() m_pos++; - SkipWhitespace(); + std::printf("{"); - if (m_buffer[m_pos] != '"') - RaiseError("expected double quote"); - - m_pos++; - - int startPos = m_pos; - - while (m_buffer[m_pos] != '"') + while (true) { - if (m_buffer[m_pos] == 0) + SkipWhitespace(); + + if (m_buffer[m_pos] != '"') + RaiseError("expected double quote"); + + m_pos++; + + int startPos = m_pos; + + while (m_buffer[m_pos] != '"') { - if (m_pos >= m_size) - RaiseError("unexpected EOF in path string"); - else - RaiseError("unexpected null character in path string"); + 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] == '\r' || m_buffer[m_pos] == '\n') + RaiseError("unexpected end of line 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); + + m_pos++; + + int fileSize; + std::unique_ptr buffer = ReadWholeFile(path, fileSize); + + if ((fileSize % size) != 0) + RaiseError("Size %d doesn't evenly divide file size %d.\n", size, fileSize); + + int count = fileSize / size; + int offset = 0; + + for (int i = 0; i < count; i++) + { + int data = ExtractData(buffer, offset, size); + offset += size; + + if (isSigned) + std::printf("%d,", data); + else + std::printf("%uu,", data); + } + + SkipWhitespace(); + + if (m_buffer[m_pos] != ',') + break; - if (m_buffer[m_pos] == '\\') - RaiseError("unexpected escape in path string"); - m_pos++; } - - std::string path(&m_buffer[startPos], m_pos - startPos); - - m_pos++; - - SkipWhitespace(); - + if (m_buffer[m_pos] != ')') RaiseError("expected ')'"); m_pos++; - std::printf("{"); - - int fileSize; - std::unique_ptr buffer = ReadWholeFile(path, fileSize); - - if ((fileSize % size) != 0) - RaiseError("Size %d doesn't evenly divide file size %d.\n", size, fileSize); - - int count = fileSize / size; - int offset = 0; - - for (int i = 0; i < count; i++) - { - int data = ExtractData(buffer, offset, size); - offset += size; - - if (isSigned) - std::printf("%d,", data); - else - std::printf("%uu,", data); - } - std::printf("}"); } diff --git a/tools/scaninc/c_file.cpp b/tools/scaninc/c_file.cpp index f7acc833f..d470f959d 100644 --- a/tools/scaninc/c_file.cpp +++ b/tools/scaninc/c_file.cpp @@ -244,18 +244,27 @@ void CFile::CheckIncbin() m_pos++; - SkipWhitespace(); + while (true) + { + SkipWhitespace(); - std::string path = ReadPath(); + std::string path = ReadPath(); - SkipWhitespace(); + SkipWhitespace(); + + m_incbins.emplace(path); + + if (m_buffer[m_pos] != ',') + break; + + m_pos++; + } if (m_buffer[m_pos] != ')') FATAL_INPUT_ERROR("expected ')'"); m_pos++; - m_incbins.emplace(path); } std::string CFile::ReadPath()