From b6a0890d97ec5c8eae151c376a9bdc0c6daff726 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 16 Oct 2016 20:24:32 +0100 Subject: [PATCH] Add string format debugging assistance --- src/localisation/localisation.c | 33 ++++++++++++++++++++++++++++++++- src/localisation/localisation.h | 1 + 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 94894859e3..ba577051f9 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -34,6 +34,12 @@ char gCommonStringFormatBuffer[256]; uint8 gCommonFormatArgs[80]; uint8 gMapTooltipFormatArgs[40]; +#ifdef DEBUG + // Set to true before a string format call to see details of the formatting. + // Set to false after the call. + bool gDebugStringFormatting = false; +#endif + const rct_string_id SpeedNames[] = { STR_SPEED_NORMAL, STR_SPEED_QUICK, @@ -1050,6 +1056,12 @@ static void format_string_code(unsigned int format_code, char **dest, size_t *si if ((*size) == 0) return; +#ifdef DEBUG + if (gDebugStringFormatting) { + printf("format_string_code(\"%s\")\n", format_get_token(format_code)); + } +#endif + switch (format_code) { case FORMAT_COMMA32: // Pop argument @@ -1188,6 +1200,12 @@ static void format_string_code(unsigned int format_code, char **dest, size_t *si static void format_string_part_from_raw(utf8 **dest, size_t *size, const utf8 *src, char **args) { +#ifdef DEBUG + if (gDebugStringFormatting) { + printf("format_string_part_from_raw(\"%s\")\n", src); + } +#endif + unsigned int code; while (*size > 1) { code = utf8_get_next(src, &src); @@ -1232,7 +1250,8 @@ static void format_string_part(utf8 **dest, size_t *size, rct_string_id format, *(*dest) = '\0'; } else if (format < 0x8000) { // Language string - format_string_part_from_raw(dest, size, language_get_string(format), args); + const utf8 * rawString = language_get_string(format); + format_string_part_from_raw(dest, size, rawString, args); } else if (format < 0x9000) { // Custom string format -= 0x8000; @@ -1271,6 +1290,12 @@ static void format_string_part(utf8 **dest, size_t *size, rct_string_id format, */ void format_string(utf8 *dest, size_t size, rct_string_id format, void *args) { +#ifdef DEBUG + if (gDebugStringFormatting) { + printf("format_string(%hu)\n", format); + } +#endif + utf8 *end = dest; size_t left = size; format_string_part(&end, &left, format, (char**)&args); @@ -1280,6 +1305,12 @@ void format_string(utf8 *dest, size_t size, rct_string_id format, void *args) void format_string_raw(utf8 *dest, size_t size, utf8 *src, void *args) { +#ifdef DEBUG + if (gDebugStringFormatting) { + printf("format_string_raw(\"%s\")\n", src); + } +#endif + utf8 *end = dest; size_t left = size; format_string_part_from_raw(&end, &left, src, (char**)&args); diff --git a/src/localisation/localisation.h b/src/localisation/localisation.h index b701026923..b573e5a145 100644 --- a/src/localisation/localisation.h +++ b/src/localisation/localisation.h @@ -65,6 +65,7 @@ extern utf8 gUserStrings[MAX_USER_STRINGS * USER_STRING_MAX_LENGTH]; extern char gCommonStringFormatBuffer[256]; extern uint8 gCommonFormatArgs[80]; extern uint8 gMapTooltipFormatArgs[40]; +extern bool gDebugStringFormatting; extern const rct_string_id SpeedNames[5]; extern const rct_string_id ObjectiveNames[12];