aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-10-20 12:23:21 +0000
committerMax Horn2009-10-20 12:23:21 +0000
commit95c572c8b90ba5cafa55ae9df5d91683f0d6d7b3 (patch)
tree686309d3ab27074448f17e22fac0d60192ab22d3
parent66fae7bc8a2557e876ed7fbcc2738adad175ad88 (diff)
downloadscummvm-rg350-95c572c8b90ba5cafa55ae9df5d91683f0d6d7b3.tar.gz
scummvm-rg350-95c572c8b90ba5cafa55ae9df5d91683f0d6d7b3.tar.bz2
scummvm-rg350-95c572c8b90ba5cafa55ae9df5d91683f0d6d7b3.zip
AGI: Cleanup AgiEngine::agiSprintf
svn-id: r45267
-rw-r--r--engines/agi/agi.h1
-rw-r--r--engines/agi/text.cpp37
2 files changed, 15 insertions, 23 deletions
diff --git a/engines/agi/agi.h b/engines/agi/agi.h
index 71789a6322..994edcc11b 100644
--- a/engines/agi/agi.h
+++ b/engines/agi/agi.h
@@ -1000,7 +1000,6 @@ private:
void printText2(int l, const char *msg, int foff, int xoff, int yoff, int len, int fg, int bg, bool checkerboard = false);
void blitTextbox(const char *p, int y, int x, int len);
void eraseTextbox();
- char *safeStrcat(char *s, const char *t);
void loadDict(void);
bool matchWord(void);
diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp
index 6b1466642b..32c12e9e78 100644
--- a/engines/agi/text.cpp
+++ b/engines/agi/text.cpp
@@ -516,11 +516,9 @@ void AgiEngine::printStatus(const char *message, ...) {
printText(x, 0, 0, _game.lineStatus, 40, STATUS_FG, STATUS_BG);
}
-char *AgiEngine::safeStrcat(char *s, const char *t) {
+static void safeStrcat(Common::String p, const char *t) {
if (t != NULL)
- strcat(s, t);
-
- return s;
+ p += t;
}
/**
@@ -530,20 +528,15 @@ char *AgiEngine::safeStrcat(char *s, const char *t) {
* @param s string containing the format specifier
* @param n logic number
*/
-#define MAX_LEN 768
char *AgiEngine::agiSprintf(const char *s) {
- static char y[MAX_LEN];
- char x[MAX_LEN];
- char z[16], *p;
+ static char agiSprintf_buf[768];
+ Common::String p;
+ char z[16];
debugC(3, kDebugLevelText, "logic %d, '%s'", _game.lognum, s);
- p = x;
- for (*p = 0; *s;) {
+ while (*s) {
switch (*s) {
- case '\\':
- s++;
- goto literal;
case '%':
s++;
switch (*s++) {
@@ -591,27 +584,27 @@ char *AgiEngine::agiSprintf(const char *s) {
case 'm':
i = strtoul(s, NULL, 10) - 1;
if (_game.logics[_game.lognum].numTexts > i)
- safeStrcat(p, agiSprintf(_game. logics[_game.lognum].texts[i]));
+ safeStrcat(p, agiSprintf(_game.logics[_game.lognum].texts[i]));
break;
}
while (*s >= '0' && *s <= '9')
s++;
- while (*p)
- p++;
break;
+ case '\\':
+ s++;
+ // FALL THROUGH
+
default:
-literal:
- assert(p < x + MAX_LEN);
- *p++ = *s++;
- *p = 0;
+ p += *s++;
break;
}
}
- strcpy(y, x);
- return y;
+ assert(sizeof(agiSprintf_buf) < p.size());
+ strcpy(agiSprintf_buf, p.c_str());
+ return agiSprintf_buf;
}
/**