Skip to content

Commit

Permalink
GLK: ALAN3: Hook up empty lines to forfeit longjmp replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jul 6, 2019
1 parent c833d39 commit 55b93f5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
25 changes: 14 additions & 11 deletions engines/glk/alan3/main.cpp
Expand Up @@ -656,20 +656,23 @@ static void moveActor(CONTEXT, int theActor) {
StepEntry *step;
Aint previousInstance = current.instance;

if (context._break) {
// forfeit setjmp replacement destination
assert(context._label == "forfeit");
context.clear();
current.instance = previousInstance;
return;
}

current.actor = theActor;
current.instance = theActor;
current.location = where(theActor, TRANSITIVE);
if (context._break || theActor == (int)HERO) {
if (context._break) {
// Forfeit jump destination
assert(context._label == "forfeit");
context.clear();
} else {
// Ask him!
parse();
capitalize = TRUE;
fail = FALSE; // fail only aborts one actor
}

if (theActor == (int)HERO) {
// Ask him!
CALL0(parse)
capitalize = TRUE;
fail = FALSE; // fail only aborts one actor

} else if (admin[theActor].script != 0) {
for (scr = (ScriptEntry *) pointerTo(header->scriptTableAddress); !isEndOfArray(scr); scr++) {
Expand Down
7 changes: 4 additions & 3 deletions engines/glk/alan3/parse.cpp
Expand Up @@ -1437,7 +1437,7 @@ static void parseInstanceCommand(Parameter parameters[], Parameter multipleParam


/*======================================================================*/
void parse(void) {
void parse(CONTEXT) {
/* longjmp's ahead so these need to survive to not leak memory */
static Parameter *parameters = NULL;
static Parameter *multipleParameters = NULL;
Expand All @@ -1446,9 +1446,10 @@ void parse(void) {

if (endOfWords(currentWordIndex)) {
currentWordIndex = 0;
scan();
} else if (anyOutput)
CALL0(scan)
} else if (anyOutput) {
para();
}

capitalize = TRUE;

Expand Down
3 changes: 2 additions & 1 deletion engines/glk/alan3/parse.h
Expand Up @@ -27,13 +27,14 @@

#include "glk/alan3/types.h"
#include "glk/alan3/params.h"
#include "glk/alan3/jumps.h"

namespace Glk {
namespace Alan3 {

/* FUNCTIONS */

extern void parse(void);
extern void parse(CONTEXT);
extern void initParsing(void);

} // End of namespace Alan3
Expand Down
20 changes: 9 additions & 11 deletions engines/glk/alan3/scan.cpp
Expand Up @@ -134,7 +134,7 @@ static char *gettoken(char *txtBuf) {

/*----------------------------------------------------------------------*/
// TODO replace dependency to exe.c with injection of quitGame() and undo()
static void getLine(void) {
static void getLine(CONTEXT) {
para();
do {
statusline();
Expand All @@ -160,14 +160,10 @@ static void getLine(void) {
g_vm->glk_put_char_stream(logFile, '\n');
}
/* If the player input an empty command he forfeited his command */
#ifdef TODO
if (strlen(buf) == 0) {
clearWordList(playerWords);
longjmp(forfeitLabel, 0);
LONG_JUMP_LABEL("forfeit")
}
#else
syserr("TODO: empty command");
#endif

strcpy(isobuf, buf);
token = gettoken(isobuf);
Expand All @@ -190,19 +186,21 @@ static void getLine(void) {


/*======================================================================*/
void scan(void) {
void scan(CONTEXT) {
int i;
int w;

if (continued) {
/* Player used '.' to separate commands. Read next */
para();
token = gettoken(NULL); /* Or did he just finish the command with a full stop? */
if (token == NULL)
getLine();
if (token == NULL) {
CALL0(getLine)
}
continued = FALSE;
} else
getLine();
} else {
CALL0(getLine)
}

freeLiterals();
playerWords[0].code = 0; // TODO This means what?
Expand Down
3 changes: 2 additions & 1 deletion engines/glk/alan3/scan.h
Expand Up @@ -26,6 +26,7 @@
/* Player input scanner for ALAN interpreter module. */

#include "glk/alan3/types.h"
#include "glk/alan3/jumps.h"

namespace Glk {
namespace Alan3 {
Expand All @@ -37,7 +38,7 @@ extern bool continued;
/* FUNCTIONS */

extern void forceNewPlayerInput();
extern void scan();
extern void scan(CONTEXT);

} // End of namespace Alan3
} // End of namespace Glk
Expand Down

0 comments on commit 55b93f5

Please sign in to comment.