diff options
-rw-r--r-- | gob/game.cpp | 11 | ||||
-rw-r--r-- | gob/inter_v1.cpp | 5 | ||||
-rw-r--r-- | gob/util.cpp | 40 | ||||
-rw-r--r-- | gob/util.h | 15 |
4 files changed, 24 insertions, 47 deletions
diff --git a/gob/game.cpp b/gob/game.cpp index 05c13b8429..babb44b820 100644 --- a/gob/game.cpp +++ b/gob/game.cpp @@ -1122,7 +1122,6 @@ void Game::collisionsBlock(void) { int16 descIndex; int16 timeVal; char *str; - int16 pos; int16 savedCollStackSize; int16 i; int16 counter; @@ -1546,12 +1545,12 @@ void Game::collisionsBlock(void) { continue; if ((_collisionAreas[i].flags & 0x0f) > 8) { + char *ptr; strcpy(_tempStr, _vm->_global->_inter_variables + _collisionAreas[i].key); - while ((pos = - _vm->_util->strstr(" ", _tempStr)) != 0) { - _vm->_util->cutFromStr(_tempStr, pos - 1, 1); - pos = _vm->_util->strstr(" ", _tempStr); + while ((ptr = strchr(_tempStr, ' ')) != 0) { + _vm->_util->cutFromStr(_tempStr, (ptr - _tempStr), 1); + ptr = strchr(_tempStr, ' '); } strcpy(_vm->_global->_inter_variables + _collisionAreas[i].key, _tempStr); } @@ -1565,7 +1564,7 @@ void Game::collisionsBlock(void) { if ((_collisionAreas[i].flags & 0x0f) < 7) _vm->_util->prepareStr(_tempStr); - pos = 0; + int16 pos = 0; do { strcpy(_collStr, str); pos += strlen(str) + 1; diff --git a/gob/inter_v1.cpp b/gob/inter_v1.cpp index 5c23bc2cb8..9e5c0aa876 100644 --- a/gob/inter_v1.cpp +++ b/gob/inter_v1.cpp @@ -1032,8 +1032,9 @@ bool Inter_v1::o1_strstr(char &cmdCount, int16 &counter, int16 &retFlag) { evalExpr(0); resVar = _vm->_parse->parseVarIndex(); - pos = _vm->_util->strstr(_vm->_global->_inter_resStr, _vm->_global->_inter_variables + strVar); - WRITE_VAR_OFFSET(resVar, pos - 1); + char *res = strstr(_vm->_global->_inter_variables + strVar, _vm->_global->_inter_resStr); + pos = res ? (res - (_vm->_global->_inter_variables + strVar)) : 0; + WRITE_VAR_OFFSET(resVar, pos); return false; } diff --git a/gob/util.cpp b/gob/util.cpp index 139cd24688..266a3907e6 100644 --- a/gob/util.cpp +++ b/gob/util.cpp @@ -368,25 +368,6 @@ void Util::cutFromStr(char *str, int16 from, int16 cutlen) { //log_write("res = %s\n", str); } -int16 Util::strstr(const char *str1, char *str2) { - char c; - uint16 len1; - uint16 i; - - //log_write("strstr: str1 = %s, str2 = %s\n", str1, str2); - - for (i = 0, len1 = strlen(str1); strlen(str2 + i) >= len1; i++) { - c = str2[i + len1]; - str2[i + len1] = 0; - if (strcmp(str2 + i, str1) == 0) { - str2[i + len1] = c; - return i + 1; - } - str2[i + len1] = c; - } - return 0; -} - void Util::listInsertFront(List * list, void *data) { ListNode *node; @@ -454,7 +435,7 @@ const char Util::trStr3[] = " "; void Util::prepareStr(char *str) { uint16 i; - int16 j; + char *start, *end; char buf[300]; strcpy(buf, trStr1); @@ -470,22 +451,19 @@ void Util::prepareStr(char *str) { while (strlen(str) > 0 && str[strlen(str) - 1] == ' ') cutFromStr(str, strlen(str) - 1, 1); - i = strstr(" ", str); - - while (1) { - if (i == 0) - return; + start = strchr(str, ' '); - if (str[i] == ' ') { - cutFromStr(str, i - 1, 1); + while (start != 0) { + if (*(start+1) == ' ') { + cutFromStr(str, start - str, 1); continue; } - j = strstr(" ", str + i); - if (j != 0) - i += j; + end = strchr(start + 1, ' '); + if (end != 0) + start = end + 1; else - i = 0; + start = 0; } } diff --git a/gob/util.h b/gob/util.h index 4b859b0c9c..6fd0857d07 100644 --- a/gob/util.h +++ b/gob/util.h @@ -70,17 +70,16 @@ public: Video::FontDesc *loadFont(const char *path); void freeFont(Video::FontDesc * fontDesc); - void insertStr(const char *str1, char *str2, int16 pos); - void cutFromStr(char *str, int16 from, int16 cutlen); - int16 strstr(const char *str1, char *str2); + static void insertStr(const char *str1, char *str2, int16 pos); + static void cutFromStr(char *str, int16 from, int16 cutlen); void waitEndFrame(); void setFrameRate(int16 rate); - void listInsertBack(List * list, void *data); - void listInsertFront(List * list, void *data); - void listDropFront(List * list); - void deleteList(List * list); - void prepareStr(char *str); + static void listInsertBack(List * list, void *data); + static void listInsertFront(List * list, void *data); + static void listDropFront(List * list); + static void deleteList(List * list); + static void prepareStr(char *str); void waitMouseRelease(char drawMouse); static const char trStr1[]; |