Update scaninc and preproc with multi-file incbins

This commit is contained in:
Diegoisawesome 2018-09-06 03:45:50 -05:00
parent f8f7a8e300
commit e0a83e3d72
2 changed files with 69 additions and 52 deletions

View File

@ -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<unsigned char[]> 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<unsigned char[]> 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("}");
}

View File

@ -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()