diff options
author | YamaArashi <shadow962@live.com> | 2016-06-05 22:00:06 -0700 |
---|---|---|
committer | YamaArashi <shadow962@live.com> | 2016-06-05 22:00:06 -0700 |
commit | 20ca34287812a451b7921be4668816b01263a2e7 (patch) | |
tree | de2381108b914c0302c14b24e6cb38ee88e8456a /tools/preproc/asm_file.cpp | |
parent | 6c47f9de06c65074d8f0d8ce847ddc7addf6126f (diff) |
add support for .braille directive to preproc
Diffstat (limited to 'tools/preproc/asm_file.cpp')
-rw-r--r-- | tools/preproc/asm_file.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index b843d640b..eba486e66 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -191,6 +191,8 @@ Directive AsmFile::GetDirective() return Directive::Include; else if (CheckForDirective(".string")) return Directive::String; + else if (CheckForDirective(".braille")) + return Directive::Braille; else return Directive::Unknown; } @@ -285,6 +287,85 @@ int AsmFile::ReadString(unsigned char* s) return length; } +int AsmFile::ReadBraille(unsigned char* s) +{ + static std::map<char, unsigned char> encoding = + { + { 'A', 0x01 }, + { 'B', 0x05 }, + { 'C', 0x03 }, + { 'D', 0x0B }, + { 'E', 0x09 }, + { 'F', 0x07 }, + { 'G', 0x0F }, + { 'H', 0x0D }, + { 'I', 0x06 }, + { 'J', 0x0E }, + { 'K', 0x11 }, + { 'L', 0x15 }, + { 'M', 0x13 }, + { 'N', 0x1B }, + { 'O', 0x19 }, + { 'P', 0x17 }, + { 'Q', 0x1F }, + { 'R', 0x1D }, + { 'S', 0x16 }, + { 'T', 0x1E }, + { 'U', 0x31 }, + { 'V', 0x35 }, + { 'W', 0x2E }, + { 'X', 0x33 }, + { 'Y', 0x3B }, + { 'Z', 0x39 }, + { ' ', 0x00 }, + { ',', 0x04 }, + { '.', 0x2C }, + { '$', 0xFF }, + }; + + SkipWhitespace(); + + int length = 0; + + if (m_buffer[m_pos] != '"') + RaiseError("expected braille string literal"); + + m_pos++; + + while (m_buffer[m_pos] != '"') + { + if (length == kMaxStringLength) + RaiseError("mapped string longer than %d bytes", kMaxStringLength); + + if (m_buffer[m_pos] == '\\' && m_buffer[m_pos + 1] == 'n') + { + s[length++] = 0xFE; + m_pos += 2; + } + else + { + char c = m_buffer[m_pos]; + + if (encoding.count(c) == 0) + { + if (IsAsciiPrintable(c)) + RaiseError("character '%c' not valid in braille string", m_buffer[m_pos]); + else + RaiseError("character '\\x%02X' not valid in braille string", m_buffer[m_pos]); + } + + s[length++] = encoding[c]; + m_pos++; + } + } + + m_pos++; // Go past the right quote. + + ExpectEmptyRestOfLine(); + + return length; +} + // If we're at a comma, consumes it. // Returns whether a comma was found. bool AsmFile::ConsumeComma() |