Skip to content

Commit

Permalink
SCI: Deduplicate text-reading code in kGetFarText
Browse files Browse the repository at this point in the history
  • Loading branch information
csnover committed Dec 3, 2016
1 parent 472a436 commit 9e1bf88
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions engines/sci/engine/kstring.cpp
Expand Up @@ -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];
}

Expand Down

0 comments on commit 9e1bf88

Please sign in to comment.