[Scummvm-cvs-logs] SF.net SVN: scummvm:[41169] scummvm/trunk/engines/sci/engine
waltervn at users.sourceforge.net
waltervn at users.sourceforge.net
Thu Jun 4 16:29:20 CEST 2009
Revision: 41169
http://scummvm.svn.sourceforge.net/scummvm/?rev=41169&view=rev
Author: waltervn
Date: 2009-06-04 14:29:20 +0000 (Thu, 04 Jun 2009)
Log Message:
-----------
SCI: Message: Added support for escape sequences.
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/kstring.cpp
scummvm/trunk/engines/sci/engine/message.cpp
scummvm/trunk/engines/sci/engine/message.h
Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp 2009-06-04 12:47:11 UTC (rev 41168)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp 2009-06-04 14:29:20 UTC (rev 41169)
@@ -713,7 +713,7 @@
case K_MESSAGE_NEXT: {
reg_t bufferReg;
char *buffer = NULL;
- const char *str;
+ Common::String str;
reg_t retval;
if (func == K_MESSAGE_GET) {
@@ -735,18 +735,18 @@
else
retval = make_reg(0, s->_msgState.getTalker());
} else {
- str = DUMMY_MESSAGE;
+ str = Common::String(DUMMY_MESSAGE);
retval = NULL_REG;
}
if (!bufferReg.isNull()) {
- int len = strlen(str) + 1;
+ int len = str.size() + 1;
buffer = kernel_dereference_char_pointer(s, bufferReg, len);
if (buffer) {
- strcpy(buffer, str);
+ strcpy(buffer, str.c_str());
} else {
- warning("Message: buffer %04x:%04x invalid or too small to hold the following text of %i bytes: '%s'", PRINT_REG(bufferReg), len, str);
+ warning("Message: buffer %04x:%04x invalid or too small to hold the following text of %i bytes: '%s'", PRINT_REG(bufferReg), len, str.c_str());
// Set buffer to empty string if possible
buffer = kernel_dereference_char_pointer(s, bufferReg, 1);
@@ -763,7 +763,7 @@
MessageState tempState;
if (tempState.loadRes(s->resmgr, UKPV(1), false) && tempState.findTuple(tuple) && tempState.getMessage())
- return make_reg(0, strlen(tempState.getText()) + 1);
+ return make_reg(0, tempState.getText().size() + 1);
else
return NULL_REG;
}
Modified: scummvm/trunk/engines/sci/engine/message.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/message.cpp 2009-06-04 12:47:11 UTC (rev 41168)
+++ scummvm/trunk/engines/sci/engine/message.cpp 2009-06-04 14:29:20 UTC (rev 41169)
@@ -153,9 +153,59 @@
return _lastReturnedModule;
}
-char *MessageState::getText() {
- int offset = READ_LE_UINT16(_engineCursor.index_record + ((_version == 2101) ? 2 : 5));
- return (char *)_currentResource->data + offset;
+Common::String MessageState::getText() {
+ char *str = (char *)_currentResource->data + READ_LE_UINT16(_engineCursor.index_record + ((_version == 2101) ? 2 : 5));
+
+ Common::String strippedStr;
+ Common::String skippedSubstr;
+ bool skipping = false;
+
+ for (uint i = 0; i < strlen(str); i++) {
+ if (skipping) {
+ // Skip stage direction
+ skippedSubstr += str[i];
+
+ // Hopefully these locale-dependant functions are good enough
+ if (islower(str[i]) || isdigit(str[i])) {
+ // Lowercase or digit found, this is not a stage direction
+ strippedStr += skippedSubstr;
+ skipping = false;
+ } else if (str[i] == ')') {
+ // End of stage direction, skip trailing white space
+ while ((i + 1 < strlen(str)) && isspace(str[i + 1]))
+ i++;
+ skipping = false;
+ }
+ } else {
+ if (str[i] == '(') {
+ // Start skipping stage direction
+ skippedSubstr = str[i];
+ skipping = true;
+ } else if (str[i] == '\\') {
+ // Escape sequence
+ if ((i + 2 < strlen(str)) && isdigit(str[i + 1]) && isdigit(str[i + 2])) {
+ // Hex escape sequence
+ char hexStr[3];
+
+ hexStr[0] = str[++i];
+ hexStr[1] = str[++i];
+ hexStr[2] = 0;
+
+ char *endptr;
+ int hexNr = strtol(hexStr, &endptr, 16);
+ if (*endptr == 0)
+ strippedStr += hexNr;
+ } else if (i + 1 < strlen(str)) {
+ // Literal escape sequence
+ strippedStr += str[++i];
+ }
+ } else {
+ strippedStr += str[i];
+ }
+ }
+ }
+
+ return strippedStr;
}
void MessageState::gotoNext() {
Modified: scummvm/trunk/engines/sci/engine/message.h
===================================================================
--- scummvm/trunk/engines/sci/engine/message.h 2009-06-04 12:47:11 UTC (rev 41168)
+++ scummvm/trunk/engines/sci/engine/message.h 2009-06-04 14:29:20 UTC (rev 41169)
@@ -54,7 +54,7 @@
MessageTuple getRefTuple();
int getMessage();
void gotoNext();
- char *getText();
+ Common::String getText();
int getTalker();
int getLength();
MessageTuple &getLastTuple();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list