diff options
author | Colin Snover | 2016-11-20 19:25:12 -0600 |
---|---|---|
committer | Colin Snover | 2016-12-03 12:21:55 -0600 |
commit | 9e1bf888b8b3095a844c636e78b0bf35708878a9 (patch) | |
tree | 7021f9a2f08535a5d2efed7e55251ccb5258e009 /engines/sci/engine/kstring.cpp | |
parent | 472a43695a5be556f4b11544b4dbf7ff70d894fb (diff) | |
download | scummvm-rg350-9e1bf888b8b3095a844c636e78b0bf35708878a9.tar.gz scummvm-rg350-9e1bf888b8b3095a844c636e78b0bf35708878a9.tar.bz2 scummvm-rg350-9e1bf888b8b3095a844c636e78b0bf35708878a9.zip |
SCI: Deduplicate text-reading code in kGetFarText
Diffstat (limited to 'engines/sci/engine/kstring.cpp')
-rw-r--r-- | engines/sci/engine/kstring.cpp | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 74c1f99778..ab1f0210e7 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -438,31 +438,15 @@ reg_t kStrLen(EngineState *s, int argc, reg_t *argv) { reg_t kGetFarText(EngineState *s, int argc, reg_t *argv) { - Resource *textres = g_sci->getResMan()->findResource(ResourceId(kResourceTypeText, argv[0].toUint16()), 0); - char *seeker; - int counter = argv[1].toUint16(); - - if (!textres) { - error("text.%d does not exist", argv[0].toUint16()); - return NULL_REG; - } - - seeker = (char *)textres->data; - - // The second parameter (counter) determines the number of the string - // inside the text resource. - while (counter--) { - while (*seeker++) - ; - } + const Common::String text = g_sci->getKernel()->lookupText(make_reg(0, argv[0].toUint16()), argv[1].toUint16()); // If the third argument is NULL, allocate memory for the destination. This // occurs in SCI1 Mac games. The memory will later be freed by the game's // scripts. if (argv[2] == NULL_REG) - s->_segMan->allocDynmem(strlen(seeker) + 1, "Mac FarText", &argv[2]); + s->_segMan->allocDynmem(text.size() + 1, "Mac FarText", &argv[2]); - s->_segMan->strcpy(argv[2], seeker); // Copy the string and get return value + s->_segMan->strcpy(argv[2], text.c_str()); // Copy the string and get return value return argv[2]; } |