diff options
author | yinsimei | 2017-07-06 18:49:50 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-07-13 18:27:45 +0200 |
commit | fe773c1bebf353bdba2a4a279b19a85ea4d7be5a (patch) | |
tree | de69dd61289945426cd991642ee2314913817e43 /engines | |
parent | 8152793d09a8a776213a31f457fed897e62cc4b0 (diff) | |
download | scummvm-rg350-fe773c1bebf353bdba2a4a279b19a85ea4d7be5a.tar.gz scummvm-rg350-fe773c1bebf353bdba2a4a279b19a85ea4d7be5a.tar.bz2 scummvm-rg350-fe773c1bebf353bdba2a4a279b19a85ea4d7be5a.zip |
SLUDGE: replace char* by Common::String for error messages
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sludge/builtin.cpp | 3 | ||||
-rw-r--r-- | engines/sludge/newfatal.cpp | 89 | ||||
-rw-r--r-- | engines/sludge/newfatal.h | 12 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 6 |
4 files changed, 32 insertions, 78 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 21818b9cb5..1f19fc3b14 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -2569,8 +2569,7 @@ builtIn(setThumbnailSize) { return BR_ERROR; trimStack(fun->stack); if (thumbWidth < 0 || thumbHeight < 0 || thumbWidth > winWidth || thumbHeight > winHeight) { - char buff[50]; - sprintf(buff, "%d x %d", thumbWidth, thumbHeight); + Common::String buff = thumbWidth + " x " + thumbHeight; fatal("Invalid thumbnail size", buff); return BR_ERROR; } diff --git a/engines/sludge/newfatal.cpp b/engines/sludge/newfatal.cpp index 8bafd1fcf2..bbb0f8c79b 100644 --- a/engines/sludge/newfatal.cpp +++ b/engines/sludge/newfatal.cpp @@ -19,12 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ -#if 0 -#include <SDL/SDL.h> - -#include <string.h> -#include <stdlib.h> -#endif #include "common/debug.h" @@ -41,8 +35,8 @@ namespace Sludge { const char emergencyMemoryMessage[] = "Out of memory displaying error message!"; -static char *fatalMessage = NULL; -static char *fatalInfo = joinStrings("Initialisation error! Something went wrong before we even got started!", ""); +static Common::String fatalMessage; +static Common::String fatalInfo = "Initialisation error! Something went wrong before we even got started!"; extern int numResourceNames /* = 0*/; extern char * *allResourceNames /*= NULL*/; @@ -60,20 +54,20 @@ const char *resourceNameFromNum(int i) { } bool hasFatal() { - if (fatalMessage) + if (!fatalMessage.empty()) return true; return false; } void displayFatal() { - if (fatalMessage) { + if (!fatalMessage.empty()) { #if 0 msgBox("SLUDGE v" TEXT_VERSION " fatal error!", fatalMessage); #endif } } -void warning(const char *l) { +void warning(const Common::String &l) { #if 0 setGraphicsWindow(false); msgBox("SLUDGE v" TEXT_VERSION " non-fatal indigestion report", l); @@ -81,40 +75,12 @@ void warning(const char *l) { } void registerWindowForFatal() { - delete[] fatalInfo; - fatalInfo = - joinStrings("There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured.", ""); + fatalInfo = "There's an error with this SLUDGE game! If you're designing this game, please turn on verbose error messages in the project manager and recompile. If not, please contact the author saying where and how this problem occured."; } -#if 0 -extern SDL_Event quit_event; -#endif - -int inFatal(const char *str) { - error(str); - delete []str; -#if 0 - FILE *fatFile = fopen("fatal.txt", "wt"); - if (fatFile) { - fprintf(fatFile, "FATAL:\n%s\n", str); - fclose(fatFile); - } - - fatalMessage = copyString(str); - if (fatalMessage == NULL) - fatalMessage = copyString("Out of memory"); - +int inFatal(const Common::String &str) { killSoundStuff(); - -#if defined(HAVE_GLES2) - EGL_Close(); -#endif - - SDL_Quit(); - - atexit(displayFatal); - exit(1); -#endif + error(str.c_str()); return true; } @@ -126,45 +92,30 @@ int checkNew(const void *mem) { return 1; } -void setFatalInfo(const char *userFunc, const char *BIF) { - delete[] fatalInfo; - fatalInfo = new char[strlen(userFunc) + strlen(BIF) + 38]; - if (fatalInfo) - sprintf(fatalInfo, "Currently in this sub: %s\nCalling: %s", userFunc, BIF); - debug(kSludgeDebugFatal, "%s", fatalInfo); +void setFatalInfo(const Common::String &userFunc, const Common::String &BIF) { + fatalInfo = "Currently in this sub: " + userFunc + "\nCalling: " + BIF; + debug(kSludgeDebugFatal, "%s", fatalInfo.c_str()); } void setResourceForFatal(int n) { resourceForFatal = n; } -int fatal(const char *str1) { +int fatal(const Common::String &str1) { if (numResourceNames && resourceForFatal != -1) { - const char *r = resourceNameFromNum(resourceForFatal); - char *newStr = new char[strlen(str1) + strlen(r) + strlen(fatalInfo) + 14]; - if (checkNew(newStr)) { - sprintf(newStr, "%s\nResource: %s\n\n%s", fatalInfo, r, str1); - inFatal(newStr); - } else - fatal(emergencyMemoryMessage); + Common::String r = resourceNameFromNum(resourceForFatal); + Common::String newStr = fatalInfo + "\nResource: " + r + "\n\n" + str1; + inFatal(newStr); } else { - char *newStr = new char[strlen(str1) + strlen(fatalInfo) + 3]; - if (checkNew(newStr)) { - sprintf(newStr, "%s\n\n%s", fatalInfo, str1); - inFatal(newStr); - } else - fatal(emergencyMemoryMessage); + Common::String newStr = fatalInfo + "\n\n" + str1; + inFatal(newStr); } return 0; } -int fatal(const char *str1, const char *str2) { - char *newStr = new char[strlen(str1) + strlen(str2) + 2]; - if (checkNew(newStr)) { - sprintf(newStr, "%s %s", str1, str2); - fatal(newStr); - } else - fatal(emergencyMemoryMessage); +int fatal(const Common::String &str1, const Common::String &str2) { + Common::String newStr = str1 + " " + str2; + fatal(newStr); return 0; } diff --git a/engines/sludge/newfatal.h b/engines/sludge/newfatal.h index 089b053f9a..bb22227f82 100644 --- a/engines/sludge/newfatal.h +++ b/engines/sludge/newfatal.h @@ -22,21 +22,23 @@ #ifndef SLUDGE_NEWFATAL_H #define SLUDGE_NEWFATAL_H +#include "common/str.h" + #include "sludge/errors.h" namespace Sludge { bool hasFatal(); -int fatal(const char *str); -int fatal(const char *str1, const char *str2); +int fatal(const Common::String &str); +int fatal(const Common::String &str1, const Common::String &str2); int checkNew(const void *mem); void displayFatal(); void registerWindowForFatal(); -void setFatalInfo(const char *userFunc, const char *BIF); -void warning(const char *l); +void setFatalInfo(const Common::String &userFunc, const Common::String &BIF); +void warning(const Common::String &l); void setResourceForFatal(int n); -char *resourceNameFromNum(int i); +const char *resourceNameFromNum(int i); } // End of namespace Sludge diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 13f6608727..a9f91d581f 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -591,8 +591,10 @@ variableStack *stackFindLast(variableStack *hunt) { bool getValueType(int &toHere, variableType vT, const variable &v) { //if (! v) return false; if (v.varType != vT) { - char *e1 = joinStrings("Can only perform specified operation on a value which is of type ", typeName[vT]); - char *e2 = joinStrings("... value supplied was of type ", typeName[v.varType]); + Common::String e1 = "Can only perform specified operation on a value which is of type "; + e1 += typeName[vT]; + Common::String e2 = "... value supplied was of type "; + e2 += typeName[v.varType]; fatal(e1, e2); return false; |