From 3c4d8e869eb216ea366be23347107618033e0939 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 29 Jan 2015 11:56:25 -0500 Subject: [PATCH] Fixed improper handling of EOF --- source/onward.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/onward.c b/source/onward.c index e402023..d436317 100755 --- a/source/onward.c +++ b/source/onward.c @@ -45,11 +45,13 @@ defvar("rssz", rssz, RET_STACK_SZ, &rsb_word); /** The address of the top of the return stack */ defvar("rsp", rsp, (value_t)Return_Stack-1, &rssz_word); +/** Base of the user-defined word buffer */ defvar("hbase", hbase, (value_t)Word_Buffer, &rsp_word); /** The address where the next word or instruction will be written */ defvar("here", here, (value_t)Word_Buffer, &hbase_word); +/** Size of the user-defined word buffer */ defvar("hsize", hsize, WORD_BUF_SZ, &here_word); /** The last generated error code */ @@ -91,11 +93,11 @@ defcode("word", word, &dropline, 0u) { curr = (int)onward_aspop(); } while (char_oneof((char)curr, " \t\r\n")); /* Copy characters into the buffer */ - do { + while(((int)curr != EOF) && !char_oneof((char)curr, " \t\r\n")) { *str++ = (char)curr; key_code(); curr = (int)onward_aspop(); - } while(((int)curr != EOF) && !char_oneof((char)curr, " \t\r\n")); + } /* Terminate the string */ *str = '\0'; /* Return the internal buffer */ @@ -292,6 +294,7 @@ defcode("interp", interp, &zbr, 0u) { } /* otherwise, look it up */ } else { + char* name = (char*)onward_aspeek(0); /* Lookup the word in the dictionary */ find_code(); /* If we found a definition execute it */ @@ -310,6 +313,7 @@ defcode("interp", interp, &zbr, 0u) { } else { errcode = ERR_UNKNOWN_WORD; (void)onward_aspop(); + printf("Unknown word: %s\n", name); } } /* Otherwise, discard it */ @@ -765,6 +769,9 @@ void parse(FILE* file) { printf(":> "); Newline_Consumed = false; errcode = 0; + } else if (errcode != 0) { + fprintf(stderr, "Error (%d) while parsing file\n", (int)errcode); + errcode = 0; } } infile = old; -- 2.52.0