diff options
author | Paul Gilbert | 2019-07-02 19:54:32 -0700 |
---|---|---|
committer | Paul Gilbert | 2019-07-06 15:27:09 -0700 |
commit | 6a4931106dfa426b8fc59f3ef871bd8b5e25b2db (patch) | |
tree | cea308a1b087a160c57819045bc1ccddd58e6c5b | |
parent | 5dea66231397c52afc7d2cdeae5989fd5edd0604 (diff) | |
download | scummvm-rg350-6a4931106dfa426b8fc59f3ef871bd8b5e25b2db.tar.gz scummvm-rg350-6a4931106dfa426b8fc59f3ef871bd8b5e25b2db.tar.bz2 scummvm-rg350-6a4931106dfa426b8fc59f3ef871bd8b5e25b2db.zip |
GLK: ALAN3: Wrap playererr and terminate methods in context
-rw-r--r-- | engines/glk/alan3/debug.cpp | 2 | ||||
-rw-r--r-- | engines/glk/alan3/glkstart.cpp | 66 | ||||
-rw-r--r-- | engines/glk/alan3/glkstart.h | 3 | ||||
-rw-r--r-- | engines/glk/alan3/main.cpp | 18 | ||||
-rw-r--r-- | engines/glk/alan3/syserr.cpp | 13 | ||||
-rw-r--r-- | engines/glk/alan3/syserr.h | 4 | ||||
-rw-r--r-- | engines/glk/alan3/utils.cpp | 3 | ||||
-rw-r--r-- | engines/glk/alan3/utils.h | 3 |
8 files changed, 26 insertions, 86 deletions
diff --git a/engines/glk/alan3/debug.cpp b/engines/glk/alan3/debug.cpp index 84f9e077a2..ec28d30772 100644 --- a/engines/glk/alan3/debug.cpp +++ b/engines/glk/alan3/debug.cpp @@ -1070,7 +1070,7 @@ void debug(CONTEXT, bool calledFromBreakpoint, int line, int fileNumber) { handleObjectsCommand(context); break; case QUIT_COMMAND: - terminate(0); + CALL1(terminate, 0) break; case SECTION_TRACE_COMMAND: toggleSectionTrace(); diff --git a/engines/glk/alan3/glkstart.cpp b/engines/glk/alan3/glkstart.cpp index f5f91a5de2..84a891cb4a 100644 --- a/engines/glk/alan3/glkstart.cpp +++ b/engines/glk/alan3/glkstart.cpp @@ -45,71 +45,5 @@ const glkunix_argumentlist_t glkunix_arguments[] = { { NULL, glkunix_arg_End, NULL } }; -/* Resources */ -static strid_t resourceFile; - -/*----------------------------------------------------------------------*/ -static void openGlkWindows() { - glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0); - if (glkMainWin == NULL) { - printf("FATAL ERROR: Cannot open initial window"); - g_vm->glk_exit(); - } - - glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above | - winmethod_Fixed, 1, wintype_TextGrid, 0); - g_vm->glk_set_window(glkStatusWin); - g_vm->glk_set_style(style_Preformatted); - g_vm->glk_set_window(glkMainWin); -} - -/*----------------------------------------------------------------------*/ -static void openResourceFile() { -#ifdef TODO - char *originalFileName = strdup(adventureFileName); - char *resourceFileName = originalFileName; - char *extension = strrchr(resourceFileName, '.'); - frefid_t resourceFileRef; -// giblorb_err_t ecode; - - strcpy(extension, ".a3r"); - - resourceFileRef = winglk_fileref_create_by_name(fileusage_BinaryMode, - resourceFileName, 0, FALSE); - - if (glk_fileref_does_file_exist(resourceFileRef)) { - resourceFile = glk_stream_open_file(resourceFileRef, filemode_Read, 0); - ecode = giblorb_set_resource_map(resourceFile); - (void)ecode; - } - free(originalFileName); -#endif -} - - -/*======================================================================*/ -int glkunix_startup_code(glkunix_startup_t *data) { - g_vm->glk_stylehint_set(wintype_AllTypes, style_Emphasized, stylehint_Weight, 0); - g_vm->glk_stylehint_set(wintype_AllTypes, style_Emphasized, stylehint_Oblique, 1); - g_vm->glk_stylehint_set(wintype_AllTypes, style_BlockQuote, stylehint_Indentation, 10); - - /* first, open a window for error output */ - openGlkWindows(); - - /* now process the command line arguments */ - //args(data->argc, data->argv); - - if (adventureFileName == NULL || strcmp(adventureFileName, "") == 0) { - printf("You should supply a game file to play.\n"); - usage("arun"); // TODO Find real programname from arguments - terminate(1); - } - - /* Open any possible blorb resource file */ - openResourceFile(); - - return TRUE; -} - } // End of namespace Alan3 } // End of namespace Glk diff --git a/engines/glk/alan3/glkstart.h b/engines/glk/alan3/glkstart.h index 0d91732d78..004bf9c8a5 100644 --- a/engines/glk/alan3/glkstart.h +++ b/engines/glk/alan3/glkstart.h @@ -73,9 +73,6 @@ struct glkunix_startup_t { /* The list of command-line arguments; this should be defined in your code. */ extern const glkunix_argumentlist_t glkunix_arguments[]; -/* The external function; this should be defined in your code. */ -extern int glkunix_startup_code(glkunix_startup_t *data); - } // End of namespace Alan3 } // End of namespace Glk diff --git a/engines/glk/alan3/main.cpp b/engines/glk/alan3/main.cpp index 9abba883f6..c32693ef8b 100644 --- a/engines/glk/alan3/main.cpp +++ b/engines/glk/alan3/main.cpp @@ -130,11 +130,11 @@ static int crcStart(const byte version[4]) { /*----------------------------------------------------------------------*/ -static void readTemporaryHeader(ACodeHeader *tmphdr) { +static void readTemporaryHeader(CONTEXT, ACodeHeader *tmphdr) { codfil->seek(0); if (codfil->read(&tmphdr->tag[0], sizeof(ACodeHeader)) != sizeof(ACodeHeader) || strncmp((char *)tmphdr, "ALAN", 4) != 0) - playererr("Not an Alan game file, does not start with \"ALAN\""); + playererr(context, "Not an Alan game file, does not start with \"ALAN\""); } @@ -347,12 +347,12 @@ void checkVersion(ACodeHeader *hdr) { } /*----------------------------------------------------------------------*/ -static void load(void) { +static void load(CONTEXT) { ACodeHeader tmphdr; Aword crc = 0; char err[100]; - readTemporaryHeader(&tmphdr); + CALL1(readTemporaryHeader, &tmphdr) checkVersion(&tmphdr); /* Allocate and load memory */ @@ -373,12 +373,12 @@ static void load(void) { /*----------------------------------------------------------------------*/ -static void checkDebug(void) { +static void checkDebug(CONTEXT) { /* Make sure he can't debug if not allowed! */ if (!header->debug) { if (debugOption | traceSectionOption | traceInstructionOption) { printf("<Sorry, '%s' is not compiled for debug! Exiting.>\n", adventureFileName); - terminate(0); + CALL1(terminate, 0) } para(); debugOption = FALSE; @@ -600,7 +600,7 @@ static void init(CONTEXT) { initStaticData(); initDynamicData(); initParsing(); - checkDebug(); + CALL0(checkDebug) getPageSize(); @@ -748,7 +748,9 @@ void run(void) { do { ctx.clear(); openFiles(); - load(); // Load program + load(ctx); // Load program + if (ctx._break) + break; if (theStack) deleteStack(theStack); diff --git a/engines/glk/alan3/syserr.cpp b/engines/glk/alan3/syserr.cpp index 559f104f5e..8a0dad5f39 100644 --- a/engines/glk/alan3/syserr.cpp +++ b/engines/glk/alan3/syserr.cpp @@ -26,6 +26,7 @@ #include "glk/alan3/glkio.h" #include "glk/alan3/output.h" #include "glk/alan3/utils.h" +#include "common/textconsole.h" namespace Glk { namespace Alan3 { @@ -33,7 +34,7 @@ namespace Alan3 { static void (*handler)(const char *); /*----------------------------------------------------------------------*/ -static void runtimeError(const char *errorClassification, const char *errorDescription, const char *blurb) { +static void runtimeError(CONTEXT, const char *errorClassification, const char *errorDescription, const char *blurb) { output("$n$nAs you enter the twilight zone of Adventures, you stumble \ and fall to your knees. In front of you, you can vaguely see the outlines \ of an Adventure that never was.$n$n"); @@ -49,7 +50,11 @@ of an Adventure that never was.$n$n"); newline(); output(blurb); - terminate(2); + terminate(context, 2); +} + +static void runtimeError(const char *errorClassification, const char *errorDescription, const char *blurb) { + ::error("%s %s %s", errorClassification, errorDescription, blurb); } @@ -90,10 +95,10 @@ If you *are* the author, then you have to figure this out before releasing the g } /*======================================================================*/ -void playererr(const char *description) { +void playererr(CONTEXT, const char *description) { if (handler == NULL) { const char *blurb = "<You have probably done something that is not exactly right.>"; - runtimeError("PLAYER ERROR: ", description, blurb); + runtimeError(context, "PLAYER ERROR: ", description, blurb); } else handler(description); } diff --git a/engines/glk/alan3/syserr.h b/engines/glk/alan3/syserr.h index 6112e883e4..fc80e72be6 100644 --- a/engines/glk/alan3/syserr.h +++ b/engines/glk/alan3/syserr.h @@ -25,7 +25,7 @@ /* Header file for syserr unit of ARUN Alan System interpreter */ -#include "common/textconsole.h" +#include "glk/alan3/jumps.h" namespace Glk { namespace Alan3 { @@ -33,7 +33,7 @@ namespace Alan3 { /* Functions: */ extern void syserr(const char *msg); extern void apperr(const char *msg); -extern void playererr(const char *msg); +extern void playererr(CONTEXT, const char *msg); extern void setSyserrHandler(void (*handler)(const char *)); } // End of namespace Alan3 diff --git a/engines/glk/alan3/utils.cpp b/engines/glk/alan3/utils.cpp index 402cbe6a21..38176e1924 100644 --- a/engines/glk/alan3/utils.cpp +++ b/engines/glk/alan3/utils.cpp @@ -42,7 +42,7 @@ namespace Alan3 { return buffers... */ -void terminate(int code) { +void terminate(CONTEXT, int code) { newline(); terminateStateStack(); @@ -53,6 +53,7 @@ void terminate(int code) { deallocate(memory); g_vm->glk_exit(); + LONG_JUMP } /*======================================================================*/ diff --git a/engines/glk/alan3/utils.h b/engines/glk/alan3/utils.h index f103436e86..0c56e0a239 100644 --- a/engines/glk/alan3/utils.h +++ b/engines/glk/alan3/utils.h @@ -26,12 +26,13 @@ /* Utility functions for the Alan interpreter */ #include "glk/alan3/types.h" +#include "glk/alan3/jumps.h" namespace Glk { namespace Alan3 { /* FUNCTIONS: */ -extern void terminate(int code); +extern void terminate(CONTEXT, int code); extern void usage(const char *programName); extern void printVersion(int buildNumber); extern bool match(const char *pattern, char *input); |