diff options
author | Max Horn | 2009-05-05 12:20:28 +0000 |
---|---|---|
committer | Max Horn | 2009-05-05 12:20:28 +0000 |
commit | 29809407887bbc178a49f215e08f18918e41c4e7 (patch) | |
tree | fde3a0c08fa9e33cf460ab11f27a58ce24f22a68 /engines/sci/engine | |
parent | 36f58b6378a5eea8565300096b9a9af9c26d66eb (diff) | |
download | scummvm-rg350-29809407887bbc178a49f215e08f18918e41c4e7.tar.gz scummvm-rg350-29809407887bbc178a49f215e08f18918e41c4e7.tar.bz2 scummvm-rg350-29809407887bbc178a49f215e08f18918e41c4e7.zip |
SCI: Simplified internal_stringfrag_strcmp and internal_stringfrag_strncmp
svn-id: r40323
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/stringfrag.cpp | 62 |
1 files changed, 24 insertions, 38 deletions
diff --git a/engines/sci/engine/stringfrag.cpp b/engines/sci/engine/stringfrag.cpp index e39f702526..a794d85ae0 100644 --- a/engines/sci/engine/stringfrag.cpp +++ b/engines/sci/engine/stringfrag.cpp @@ -342,28 +342,21 @@ void stringfrag_strncpy(EngineState *s, reg_t dest, reg_t src, int len) { } int internal_stringfrag_strcmp(EngineState *s, reg_t *s1, reg_t *s2) { + int c1, c2; while (1) { - if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0) + c1 = (byte)(s1->offset & 0xff00); + c2 = (byte)(s2->offset & 0xff00); + if (c1 != c2) // We found a difference + return c1 - c2; + else if (c1 == 0) // Both strings ended return 0; - if ((s1->offset & 0xff00) == 0) - return -1; - if ((s2->offset & 0xff00) == 0) - return 1; - if ((s1->offset & 0xff00) < (s2->offset & 0xff00)) - return -1; - if ((s1->offset & 0xff00) > (s2->offset & 0xff00)) - return 1; - - if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0) + + c1 = (byte)(s1->offset & 0x00ff); + c2 = (byte)(s2->offset & 0x00ff); + if (c1 != c2) // We found a difference + return c1 - c2; + else if (c1 == 0) // Both strings ended return 0; - if ((s1->offset & 0x00ff) == 0) - return -1; - if ((s2->offset & 0x00ff) == 0) - return 1; - if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff)) - return -1; - if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff)) - return 1; } return 0; @@ -377,32 +370,26 @@ void stringfrag_strcmp(EngineState *s, reg_t s1, reg_t s2) { } int internal_stringfrag_strncmp(EngineState *s, reg_t *s1, reg_t *s2, int len) { + int c1, c2; while (len) { if (len--) return 0; - if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0) + c1 = (byte)(s1->offset & 0xff00); + c2 = (byte)(s2->offset & 0xff00); + if (c1 != c2) // We found a difference + return c1 - c2; + else if (c1 == 0) // Both strings ended return 0; - if ((s1->offset & 0xff00) == 0) - return -1; - if ((s2->offset & 0xff00) == 0) - return 1; - if ((s1->offset & 0xff00) < (s2->offset & 0xff00)) - return -1; - if ((s1->offset & 0xff00) > (s2->offset & 0xff00)) - return 1; if (len--) return 0; - if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0) + + c1 = (byte)(s1->offset & 0x00ff); + c2 = (byte)(s2->offset & 0x00ff); + if (c1 != c2) // We found a difference + return c1 - c2; + else if (c1 == 0) // Both strings ended return 0; - if ((s1->offset & 0x00ff) == 0) - return -1; - if ((s2->offset & 0x00ff) == 0) - return 1; - if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff)) - return -1; - if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff)) - return 1; } return 0; @@ -416,4 +403,3 @@ void stringfrag_strncmp(EngineState *s, reg_t s1, reg_t s2, int len) { } } // end of namespace Sci - |