summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2017-01-22 21:55:01 -0800
committerYamaArashi <shadow962@live.com>2017-01-22 22:08:38 -0800
commit535ed69d33072543b543829b86409758cc7f6318 (patch)
treee7be4a872994d59fcba07a944f0bd1ace185941f
parenta14cd89b9ca175af2fba4faadd8989e24d1275ce (diff)
change preproc syntax for C strings
-rw-r--r--src/field_player_avatar.c2
-rw-r--r--src/link.c20
-rw-r--r--src/pokemon_size_record.c2
-rw-r--r--src/sprite.c10
-rw-r--r--src/string_util.c6
-rw-r--r--tools/preproc/c_file.cpp183
-rw-r--r--tools/preproc/c_file.h4
-rw-r--r--tools/preproc/char_util.h4
8 files changed, 145 insertions, 86 deletions
diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c
index 0a506bbac..08d9c13d6 100644
--- a/src/field_player_avatar.c
+++ b/src/field_player_avatar.c
@@ -1562,7 +1562,7 @@ u8 Fishing4(struct Task *task)
u8 Fishing5(struct Task *task)
{
- const u8 dot[] = _"·";
+ const u8 dot[] = _("·");
sub_805A954();
task->data[1]++;
diff --git a/src/link.c b/src/link.c
index 2b463f6b4..5c33fe986 100644
--- a/src/link.c
+++ b/src/link.c
@@ -160,16 +160,16 @@ EWRAM_DATA bool8 gLinkOpen = {0};
static const u8 sDebugMessages[7][12] =
{
- _"せつぞく ちゅうです",
- _"せつぞく できません",
- _"かくにん ちゅうです",
- _"かくにん できました",
- _"かくにん できません",
- _"かくにん を かくにん",
- _"かくにん は しっぱい",
+ _("せつぞく ちゅうです"),
+ _("せつぞく できません"),
+ _("かくにん ちゅうです"),
+ _("かくにん できました"),
+ _("かくにん できません"),
+ _("かくにん を かくにん"),
+ _("かくにん は しっぱい"),
};
-static const u8 sColorCodes[] = _"{HIGHLIGHT TRANSPARENT}{COLOR WHITE2}";
+static const u8 sColorCodes[] = _("{HIGHLIGHT TRANSPARENT}{COLOR WHITE2}");
static const u32 sBlockRequestLookupTable[5 * 2] =
{
@@ -180,11 +180,11 @@ static const u32 sBlockRequestLookupTable[5 * 2] =
(u32)gBlockSendBuffer, 40,
};
-static const u8 sTestString[] = _"テストな";
+static const u8 sTestString[] = _("テストな");
ALIGNED(4) static const u8 sMagic[] = "GameFreak inc.";
-ALIGNED(4) static const u8 sEmptyString[] = _"";
+ALIGNED(4) static const u8 sEmptyString[] = _("");
void Task_DestroySelf(u8 taskId)
{
diff --git a/src/pokemon_size_record.c b/src/pokemon_size_record.c
index 92743b729..6540858c1 100644
--- a/src/pokemon_size_record.c
+++ b/src/pokemon_size_record.c
@@ -88,7 +88,7 @@ static u32 GetMonSize(u16 species, u16 b)
static void FormatMonSizeRecord(u8 *string, u32 size)
{
- u8 decimalPoint[] = _".";
+ u8 decimalPoint[] = _(".");
//Convert size from centimeters to inches
size = (double)(size * 10) / (CM_PER_INCH * 10);
diff --git a/src/sprite.c b/src/sprite.c
index f20ea2927..0f5b0caf1 100644
--- a/src/sprite.c
+++ b/src/sprite.c
@@ -129,10 +129,12 @@ const struct SpriteTemplate gDummySpriteTemplate;
// Unreferenced error message.
// It means "The DMA transfer request table has exceeded its limit."
static const u8 sDmaOverErrorMsg[] =
- _"DMA OVER\n"
- "DMAてんそう\n"
- "リクエストテーブルが\n"
- "オーバーしました";
+ _(
+ "DMA OVER\n"
+ "DMAてんそう\n"
+ "リクエストテーブルが\n"
+ "オーバーしました"
+ );
// Unreferenced data.
static const u8 sUnknownData[24] =
diff --git a/src/string_util.c b/src/string_util.c
index 258077c9f..e537cff3a 100644
--- a/src/string_util.c
+++ b/src/string_util.c
@@ -4,10 +4,10 @@
u8 gUnknownStringVar[16];
-const u8 gEmptyString_81E72B0[] = _"";
-const u8 gRightPointingTriangleString[] = _"▶";
+const u8 gEmptyString_81E72B0[] = _("");
+const u8 gRightPointingTriangleString[] = _("▶");
-static const u8 sDigits[] = @"0123456789ABCDEF";
+static const u8 sDigits[] = __("0123456789ABCDEF");
static const s32 sPowersOfTen[] =
{
diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp
index aed53d44b..4e6035214 100644
--- a/tools/preproc/c_file.cpp
+++ b/tools/preproc/c_file.cpp
@@ -72,8 +72,6 @@ CFile::~CFile()
void CFile::Preproc()
{
- bool inConcatMode = false;
- bool noTerminator = false;
char stringChar = 0;
while (m_pos < m_size)
@@ -94,85 +92,140 @@ void CFile::Preproc()
}
else
{
+ if (m_buffer[m_pos] == '\n')
+ m_lineNum++;
std::putchar(m_buffer[m_pos]);
m_pos++;
}
}
else
{
- if (inConcatMode ? m_buffer[m_pos] == '"'
- : (m_buffer[m_pos] == '_' || m_buffer[m_pos] == '@') && m_buffer[m_pos + 1] == '"')
- {
- if (!inConcatMode)
- {
- noTerminator = (m_buffer[m_pos] == '@');
- m_pos++; // skip past underscore or at-sign
- }
-
- 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());
- }
-
- if (!inConcatMode)
- {
- std::printf("{ ");
- }
-
- inConcatMode = true;
-
- for (int i = 0; i < length; i++)
- printf("0x%02X, ", s[i]);
- }
- else
- {
- char c = m_buffer[m_pos++];
+ TryConvertString();
- if (c == '\r')
- {
- if (m_buffer[m_pos] == '\n')
- {
- m_pos++;
- }
+ char c = m_buffer[m_pos++];
- c = '\n';
- }
+ std::putchar(c);
- if ((c != ' ' && c != '\t' && c != '\n') && inConcatMode)
- {
- if (noTerminator)
- std::printf(" }");
- else
- std::printf("0xFF }");
+ if (c == '\n')
+ m_lineNum++;
+ else if (c == '"')
+ stringChar = '"';
+ else if (m_buffer[m_pos] == '\'')
+ stringChar = '\'';
+ }
+ }
+}
- inConcatMode = false;
- }
+bool CFile::ConsumeHorizontalWhitespace()
+{
+ if (m_buffer[m_pos] == '\t' || m_buffer[m_pos] == ' ')
+ {
+ m_pos++;
+ return true;
+ }
- std::putchar(c);
+ return false;
+}
- if (c == '\n')
- m_lineNum++;
- else if (c == '"')
- stringChar = '"';
- else if (m_buffer[m_pos] == '\'')
- stringChar = '\'';
- }
- }
+bool CFile::ConsumeNewline()
+{
+ if (m_buffer[m_pos] == '\r' && m_buffer[m_pos + 1] == '\n')
+ {
+ m_pos += 2;
+ m_lineNum++;
+ return true;
}
- if (inConcatMode)
+ if (m_buffer[m_pos] == '\n')
{
- printf("0xFF }");
- RaiseWarning("string at end of file");
+ m_pos++;
+ m_lineNum++;
+ return true;
}
+
+ return false;
+}
+
+void CFile::SkipWhitespace()
+{
+ while (ConsumeHorizontalWhitespace() || ConsumeNewline())
+ ;
+}
+
+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 }");
}
// Reports a diagnostic message.
diff --git a/tools/preproc/c_file.h b/tools/preproc/c_file.h
index b6041cc00..1a2573839 100644
--- a/tools/preproc/c_file.h
+++ b/tools/preproc/c_file.h
@@ -42,6 +42,10 @@ private:
long m_lineNum;
std::string m_filename;
+ bool ConsumeHorizontalWhitespace();
+ bool ConsumeNewline();
+ void SkipWhitespace();
+ void TryConvertString();
void ReportDiagnostic(const char* type, const char* format, std::va_list args);
void RaiseError(const char* format, ...);
void RaiseWarning(const char* format, ...);
diff --git a/tools/preproc/char_util.h b/tools/preproc/char_util.h
index ab20dbc53..02a6e1ceb 100644
--- a/tools/preproc/char_util.h
+++ b/tools/preproc/char_util.h
@@ -56,13 +56,13 @@ inline bool IsAsciiPrintable(unsigned char c)
return (c >= ' ' && c <= '~');
}
-// Returns whether the character can start the identifier of a "{FOO}" constant in strings.
+// Returns whether the character can start a C identifier or the identifier of a "{FOO}" constant in strings.
inline bool IsIdentifierStartingChar(unsigned char c)
{
return IsAsciiAlpha(c) || c == '_';
}
-// Returns whether the character can be used in the identifier of a "{FOO}" constant in strings.
+// Returns whether the character can be used in a C identifier or the identifier of a "{FOO}" constant in strings.
inline bool IsIdentifierChar(unsigned char c)
{
return IsAsciiAlphanum(c) || c == '_';