Skip to content

Commit

Permalink
SLUDGE: replace char* by Common::String for error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yinsimei authored and sev- committed Jul 13, 2017
1 parent 8152793 commit fe773c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 78 deletions.
3 changes: 1 addition & 2 deletions engines/sludge/builtin.cpp
Expand Up @@ -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;
}
Expand Down
89 changes: 20 additions & 69 deletions engines/sludge/newfatal.cpp
Expand Up @@ -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"

Expand All @@ -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*/;
Expand All @@ -60,61 +54,33 @@ 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);
#endif
}

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;
}

Expand All @@ -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;
}

Expand Down
12 changes: 7 additions & 5 deletions engines/sludge/newfatal.h
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions engines/sludge/variable.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit fe773c1

Please sign in to comment.