// Reads include path. std::string SymFile::ReadPath() { SkipWhitespace(); if (m_buffer[m_pos] != '"') RaiseError("expected file path"); m_pos++; int length = 0; long startPos = m_pos; while (m_buffer[m_pos] != '"') { unsigned char c = m_buffer[m_pos++]; if (c == 0) { if (m_pos >= m_size) RaiseError("unexpected EOF in include string"); else RaiseError("unexpected null character in include string"); } if (!IsAsciiPrintable(c)) RaiseError("unexpected character '\\x%02X' in include string", c); // Don't bother allowing any escape sequences. if (c == '\\') { c = m_buffer[m_pos]; RaiseError("unexpected escape '\\%c' in include string", c); } length++; if (length > kMaxPath) RaiseError("path is too long"); } m_pos++; // Go past the right quote. return std::string(&m_buffer[startPos], length); }
void CFile::TryConvertString() { long oldPos = m_pos; long oldLineNum = m_lineNum; bool noTerminator = false; if (m_buffer[m_pos] != '_' || (m_pos > 0 && IsIdentifierChar(m_buffer[m_pos - 1]))) return; m_pos++; if (m_buffer[m_pos] == '_') { noTerminator = true; m_pos++; } SkipWhitespace(); if (m_buffer[m_pos] != '(') { m_pos = oldPos; m_lineNum = oldLineNum; return; } m_pos++; SkipWhitespace(); std::printf("{ "); while (1) { SkipWhitespace(); if (m_buffer[m_pos] == '"') { unsigned char s[kMaxStringLength]; int length; StringParser stringParser(m_buffer, m_size); try { m_pos += stringParser.ParseString(m_pos, s, length); } catch (std::runtime_error& e) { RaiseError(e.what()); } for (int i = 0; i < length; i++) printf("0x%02X, ", s[i]); } else if (m_buffer[m_pos] == ')') { m_pos++; break; } else { if (m_pos >= m_size) RaiseError("unexpected EOF"); if (IsAsciiPrintable(m_buffer[m_pos])) RaiseError("unexpected character '%c'", m_buffer[m_pos]); else RaiseError("unexpected character '\\x%02X'", m_buffer[m_pos]); } } if (noTerminator) std::printf(" }"); else std::printf("0xFF }"); }