Skip to content
Permalink
Browse files

GLK: JACL: Graceful exit when error occurs

  • Loading branch information...
dreammaster committed Oct 7, 2019
1 parent fecf1b3 commit 1a78b67d08d206c58c841e7540eb04bdcd032b6e
@@ -363,6 +363,9 @@ int execute(const char *funcname) {
int object_1,
object_2;

if (g_vm->shouldQuit())
return 0;

/* THESE VARIABLE KEEP TRACK OF if AND endif COMMANDS TO DECIDE WHETHER
*THE CURRENT LINE OF CODE SHOULD BE EXECUTED OR NOT */
int currentLevel = 0;
@@ -389,6 +392,8 @@ int execute(const char *funcname) {

#ifdef GLK
push_stack(g_vm->glk_stream_get_position(game_stream));
if (g_vm->shouldQuit())
return FALSE;
#else
push_stack(ftell(file));
#endif
@@ -1163,6 +1168,7 @@ int execute(const char *funcname) {
}
} else if (!strcmp(word[0], "terminate")) {
terminate(0);
return 0;
} else if (!strcmp(word[0], "more")) {
if (word[1] == NULL) {
more("[MORE]");
@@ -1295,6 +1301,7 @@ int execute(const char *funcname) {
clrscrn();
} else if (!strcmp(word[0], "terminate")) {
terminate(0);
return;
} else if (!strcmp(word[0], "more")) {
if (word[1] == NULL) {
more("[MORE]");
@@ -2355,6 +2362,9 @@ int execute(const char *funcname) {
}

#ifdef GLK
if (g_vm->shouldQuit())
return 0;

before_command = g_vm->glk_stream_get_position(game_stream);
glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
#else
@@ -2716,6 +2726,7 @@ void push_stack(int32 file_pointer) {
if (stack == STACK_SIZE) {
log_error("Stack overflow.", PLUS_STDERR);
terminate(45);
return;
} else {
backup[stack].infile = infile;
infile = NULL;
@@ -2851,6 +2862,7 @@ void push_proxy() {
if (proxy_stack == STACK_SIZE) {
log_error("Stack overflow.", PLUS_STDERR);
terminate(45);
return;
} else {
proxy_backup[proxy_stack].start_of_this_command = start_of_this_command;
proxy_backup[proxy_stack].start_of_last_command = start_of_last_command;
@@ -42,7 +42,6 @@ void JACL::runGame() {
// Open up the game file as a stream, and play the game
game_stream = _streams->openStream(&_gameFile);
glk_main();
glk_stream_close(game_stream);
}

bool JACL::initialize() {
@@ -214,6 +214,7 @@ void glk_main() {
* OPEN GLK WINDOW, OUTPUT THE ERROR MESSAGE AND EXIT */
log_error(error_buffer, FALSE);
terminate(200);
return;
}

// INTIALISE THE CSV PARSER
@@ -257,6 +258,7 @@ void glk_main() {
if (object[2] == NULL) {
log_error(CANT_RUN, PLUS_STDERR);
terminate(43);
return;
}

/* DUMMY RETRIEVE OF 'HERE' FOR TESTING OF GAME STATE */
@@ -265,7 +267,7 @@ void glk_main() {
eachturn();

/* TOP OF COMMAND LOOP */
do {
while (!g_vm->shouldQuit()) {
int gotline;
event_t ev;

@@ -423,8 +425,7 @@ void glk_main() {
command_encapsulate();
preparse();
}

} while (TRUE);
}
}

void preparse() {
@@ -477,6 +478,7 @@ void word_check() {
newline();
execute("+score");
terminate(0);
return;
} else {
write_text(cstring_resolve("RETURN_GAME")->value);
}
@@ -319,6 +319,7 @@ void read_gamefile() {
if (objects == MAX_OBJECTS) {
log_error(MAXIMUM_EXCEEDED, PLUS_STDERR);
terminate(47);
return;
} else {
if ((object[objects] = (struct object_type *)
malloc(sizeof(struct object_type))) == NULL)
@@ -614,6 +615,7 @@ void read_gamefile() {
if (errors) {
totalerrs(errors);
terminate(48);
return;
}

/*************************************************************************
@@ -995,6 +997,7 @@ void read_gamefile() {
if (errors) {
totalerrs(errors);
terminate(48);
return;
}
}

@@ -74,15 +74,14 @@ int get_here() {
if (player < 1 || player > objects) {
badplrrun(player);
terminate(44);
return 0;
} else if (object[player]->PARENT < 1 || object[player]->PARENT > objects || object[player]->PARENT == player) {
badparrun();
terminate(44);
return 0;
} else {
return (object[player]->PARENT);
}

/* SHOULDN'T GET HERE, JUST TRYING TO KEEP VisualC++ HAPPY */
return 1;
}

char *strip_return(char *string) {

0 comments on commit 1a78b67

Please sign in to comment.
You can’t perform that action at this time.