diff options
Diffstat (limited to 'tools/preproc')
| -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("}");  } | 
