diff options
author | Bertrand Augereau | 2009-09-06 11:37:15 +0000 |
---|---|---|
committer | Bertrand Augereau | 2009-09-06 11:37:15 +0000 |
commit | eda081173b93f2ce5bff48d58e926253808e94ab (patch) | |
tree | d69502a564340ba18e9bcbb015e4eca3d59fc5a0 /engines | |
parent | d454c9b3793fdda9551d7833da08ab503fc10689 (diff) | |
download | scummvm-rg350-eda081173b93f2ce5bff48d58e926253808e94ab.tar.gz scummvm-rg350-eda081173b93f2ce5bff48d58e926253808e94ab.tar.bz2 scummvm-rg350-eda081173b93f2ce5bff48d58e926253808e94ab.zip |
Constness fix
svn-id: r43975
Diffstat (limited to 'engines')
-rw-r--r-- | engines/queen/journal.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/engines/queen/journal.cpp b/engines/queen/journal.cpp index 7846fa5c36..b782328f83 100644 --- a/engines/queen/journal.cpp +++ b/engines/queen/journal.cpp @@ -380,35 +380,56 @@ void Journal::handleMouseDown(int x, int y) { update(); } +static void removeLeadingAndTrailingSpaces(char *dst, size_t dstSize, const char* src) { + assert(dstSize > 0); + size_t srcLen = strlen(src); + if (0 == srcLen) { + dst[0] = '\0'; + return; + } + + size_t firstNonSpaceIndex; + for (firstNonSpaceIndex = 0; firstNonSpaceIndex < srcLen; ++firstNonSpaceIndex) { + if (src[firstNonSpaceIndex] != ' ') + break; + } + if (firstNonSpaceIndex == srcLen) { + dst[0] = '\0'; + return; + } + + size_t lastNonSpaceIndex = srcLen - 1; + while (src[lastNonSpaceIndex] == ' ') + --lastNonSpaceIndex; + + size_t newLen = lastNonSpaceIndex - firstNonSpaceIndex + 1; + assert(newLen < dstSize); + for (size_t i = 0; i < newLen; ++i) { + dst[i] = src[firstNonSpaceIndex + i]; + } + dst[newLen] = '\0'; +} + void Journal::drawPanelText(int y, const char *text) { debug(7, "Journal::drawPanelText(%d, '%s')", y, text); + char s[128]; - strncpy(s, text, 127); - s[127] = 0; - char *p; + removeLeadingAndTrailingSpaces(s, 128, text); // necessary for spanish version - // remove leading and trailing spaces (necessary for spanish version) - for (p = s + strlen(s) - 1; p >= s && *p == ' '; --p) { - *p = 0; - } - text = s; - for (p = s; *p == ' '; ++p) { - text = p + 1; - } // draw the substrings - p = (char *)strchr(text, ' '); + char *p = strchr(s, ' '); if (!p) { - int x = (128 - _vm->display()->textWidth(text)) / 2; - _vm->display()->setText(x, y, text, false); + int x = (128 - _vm->display()->textWidth(s)) / 2; + _vm->display()->setText(x, y, s, false); assert(_panelTextCount < MAX_PANEL_TEXTS); _panelTextY[_panelTextCount++] = y; } else { *p++ = '\0'; if (_vm->resource()->getLanguage() == Common::HB_ISR) { drawPanelText(y - 5, p); - drawPanelText(y + 5, text); + drawPanelText(y + 5, s); } else { - drawPanelText(y - 5, text); + drawPanelText(y - 5, s); drawPanelText(y + 5, p); } } |