aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/archetype
diff options
context:
space:
mode:
authorPaul Gilbert2019-11-09 08:21:42 -0800
committerPaul Gilbert2019-11-11 18:20:30 -0800
commit86e7717e62b11e1f35145d14d55e012379a40e50 (patch)
treee7fa78824614beb2671d543c79ad1b05d65be304 /engines/glk/archetype
parent5d8b8752e82abb91746c01dd61865d0ad6944e3d (diff)
downloadscummvm-rg350-86e7717e62b11e1f35145d14d55e012379a40e50.tar.gz
scummvm-rg350-86e7717e62b11e1f35145d14d55e012379a40e50.tar.bz2
scummvm-rg350-86e7717e62b11e1f35145d14d55e012379a40e50.zip
GLK: ARCHETYPE: Cleanup and fixes for text display
Diffstat (limited to 'engines/glk/archetype')
-rw-r--r--engines/glk/archetype/archetype.cpp52
-rw-r--r--engines/glk/archetype/archetype.h10
-rw-r--r--engines/glk/archetype/interpreter.cpp5
-rw-r--r--engines/glk/archetype/sys_object.cpp3
-rw-r--r--engines/glk/archetype/wrap.cpp147
-rw-r--r--engines/glk/archetype/wrap.h65
6 files changed, 45 insertions, 237 deletions
diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp
index 38eb83fc83..4ea197ea5c 100644
--- a/engines/glk/archetype/archetype.cpp
+++ b/engines/glk/archetype/archetype.cpp
@@ -30,7 +30,6 @@
#include "glk/archetype/saveload.h"
#include "glk/archetype/sys_object.h"
#include "glk/archetype/timestamp.h"
-#include "glk/archetype/wrap.h"
namespace Glk {
namespace Archetype {
@@ -142,7 +141,7 @@ void Archetype::writeln(const String fmt, ...) {
glk_put_buffer(s.c_str(), s.size());
}
-void Archetype::readln(String &s) {
+String Archetype::readLine() {
event_t ev;
char buffer[MAX_INPUT_LINE + 1];
@@ -152,19 +151,30 @@ void Archetype::readln(String &s) {
glk_select(&ev);
if (ev.type == evtype_Quit) {
glk_cancel_line_event(_mainWindow, &ev);
- return;
+ return "";
} else if (ev.type == evtype_LineInput)
break;
} while (ev.type != evtype_Quit);
buffer[ev.val1] = 0;
- s = String(buffer);
+ return String(buffer);
}
-char Archetype::ReadKey() {
- // TODO
- return '\0';
+char Archetype::readKey() {
+ glk_request_char_event(_mainWindow);
+
+ event_t ev;
+ while (ev.type != evtype_CharInput) {
+ glk_select(&ev);
+
+ if (ev.type == evtype_Quit) {
+ glk_cancel_char_event(_mainWindow);
+ return '\0';
+ }
+ }
+
+ return (char)ev.val1;
}
void Archetype::lookup(int the_obj, int the_attr, ResultType &result, ContextType &context,
@@ -355,7 +365,7 @@ bool Archetype::send_message(int transport, int message_sent, int recipient,
} else if (index_xarray(Type_List, op->inherited_from, p)) {
op = (ObjectPtr)p;
} else {
- wraperr("Internal error: invalid inheritance");
+ error("Internal error: invalid inheritance");
return false;
}
}
@@ -398,12 +408,12 @@ void Archetype::eval_expr(ExprTree the_expr, ResultType &result, ContextType &co
case RW_KEY:
result._kind = STR_PTR;
if (the_expr->_data._reserved.keyword == RW_READ)
- result._data._str.acl_str = ReadLine(true); // read full line
- else
- result._data._str.acl_str = ReadLine(false); // read single key
-
- Rows = 0;
- cursor_reset(); // user will have had to hit <RETURN>
+ result._data._str.acl_str = MakeNewDynStr(readLine()); // read full line
+ else {
+ String s;
+ s += readKey();
+ result._data._str.acl_str = MakeNewDynStr(s); // read single key
+ }
break;
case RW_MESSAGE:
@@ -753,6 +763,9 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
exec_stmt((StatementPtr)np->data, result, context);
b = (result._kind == RESERVED) && (result._data._reserved.keyword == RW_BREAK);
+
+ if (shouldQuit())
+ return;
}
break;
@@ -765,7 +778,7 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
if (index_xarray(Literals, the_stmt->_data._expr.expression->_data._msgTextQuote.index, p)) {
result._kind = TEXT_LIT;
result._data._msgTextQuote.index = the_stmt->_data._expr.expression->_data._msgTextQuote.index;
- wrapout(*((StringPtr)p), true);
+ writeln(*((StringPtr)p));
}
break;
@@ -817,7 +830,7 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
}
if (the_stmt->_kind == ST_WRITE) {
- wrapout("", true);
+ g_vm->writeln();
} else if (the_stmt->_kind == ST_STOP) {
g_vm->writeln();
g_vm->writeln();
@@ -900,6 +913,9 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
exec_stmt(the_stmt->_data._loop.action, result, context);
b = (result._kind == RESERVED) && (result._data._reserved.keyword == RW_BREAK);
cleanup(result);
+
+ if (shouldQuit())
+ return;
}
break;
@@ -955,14 +971,14 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType
if (result._data._ident.ident_int == (int)Object_List.size())
shrink_xarray(Object_List);
} else {
- wraperr("Can only destroy previously created objects");
+ error("Can only destroy previously created objects");
}
cleanup(result);
break;
default:
- wraperr("Internal error: statement not supported yet");
+ error("Internal error: statement not supported yet");
break;
}
diff --git a/engines/glk/archetype/archetype.h b/engines/glk/archetype/archetype.h
index 8df78e58aa..a54fa172de 100644
--- a/engines/glk/archetype/archetype.h
+++ b/engines/glk/archetype/archetype.h
@@ -173,9 +173,15 @@ public:
void writeln(const String fmt, ...);
void writeln() { writeln(""); }
- void readln(String &s);
+ /**
+ * Read an input line typed by the player
+ */
+ String readLine();
- char ReadKey();
+ /**
+ * Read in a single key
+ */
+ char readKey();
};
extern Archetype *g_vm;
diff --git a/engines/glk/archetype/interpreter.cpp b/engines/glk/archetype/interpreter.cpp
index a9ee1bbb51..15328a1dab 100644
--- a/engines/glk/archetype/interpreter.cpp
+++ b/engines/glk/archetype/interpreter.cpp
@@ -25,7 +25,6 @@
#include "glk/archetype/misc.h"
#include "glk/archetype/saveload.h"
#include "glk/archetype/timestamp.h"
-#include "glk/archetype/wrap.h"
namespace Glk {
namespace Archetype {
@@ -325,7 +324,7 @@ bool assignment(ResultType &target, ResultType &value) {
ExprPtr e;
if (target._kind != ATTR_PTR) {
- wraperr("Warning: attempted assignment to a non-attribute");
+ error("Warning: attempted assignment to a non-attribute");
return false;
} else {
e = (ExprPtr)target._data._attr.acl_attr->data;
@@ -377,7 +376,7 @@ void display_result(ResultType &result) {
break;
case QUOTE_LIT:
enclose = " ";
- wrapout(">>", false);
+ debugN(">>");
break;
case MESSAGE:
enclose = "\'";
diff --git a/engines/glk/archetype/sys_object.cpp b/engines/glk/archetype/sys_object.cpp
index 955067196d..233fde1709 100644
--- a/engines/glk/archetype/sys_object.cpp
+++ b/engines/glk/archetype/sys_object.cpp
@@ -25,7 +25,6 @@
#include "glk/archetype/game_stat.h"
#include "glk/archetype/heap_sort.h"
#include "glk/archetype/parser.h"
-#include "glk/archetype/wrap.h"
#include "common/algorithm.h"
#include "common/debug-channels.h"
#include "common/savefile.h"
@@ -128,7 +127,7 @@ void send_to_system(int transport, String &strmsg, ResultType &result, ContextTy
if (convert_to(NUMERIC, result)) {
g_vm->Abbreviate = result._data._numeric.acl_int;
} else {
- wraperr("Warning: non-numeric abbreviation message sent to system");
+ error("Warning: non-numeric abbreviation message sent to system");
cleanup(result);
}
sys_state = IDLING;
diff --git a/engines/glk/archetype/wrap.cpp b/engines/glk/archetype/wrap.cpp
deleted file mode 100644
index ddc3850043..0000000000
--- a/engines/glk/archetype/wrap.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "glk/archetype/wrap.h"
-#include "glk/archetype/archetype.h"
-
-namespace Glk {
-namespace Archetype {
-
-const int
- MAXCOLS = 75, // leave room for punctuation
- SAFETY_MARGIN = 3,
- MAXROWS = 24,
-
- REVERSE_VID = 3,
- BOLDFACE = 8;
-
-int Rows;
-int cursor;
-
-void wrap_init() {
- cursor_reset();
- Rows = 0;
-}
-
-static void wrap_wait() {
-#ifdef UNUSED
- char ch;
-
- TextColor(BOLDFACE); TextBackground(REVERSE_VID);
- write('Hit any key to continue...');
- ch := ReadKey;
- write(chr(13));
- NormVideo;
- ClrScr; // or ClrEol if you don't want the whole screen
- Rows : = 0
-#endif
-}
-
-void wrapint(int i, bool terminate) {
- String s = String::format("%d", i);
- wrapout(s, terminate);
-}
-
-void wrapout(const String &str, bool terminate) {
- int thisline, maxchars, startnext;
- String s = str;
-
- // 'thisline' starts out as the maximum number of characters that can be
- // written before a newline; it gets trimmed back to being the number of
- // characters from the string that are actually written on this line
- maxchars = MAXCOLS - cursor;
-
- const char CHARS[7] = { '.', ',', ':', ';', ')', '-', '"' };
- for (int i = 0; i < 7; ++i) {
- if (!s.empty() && s[0] == CHARS[i]) {
- maxchars += SAFETY_MARGIN;
- break;
- }
- }
-
- thisline = maxchars;
- while (thisline < (int)s.size()) {
- while (thisline >= 0 && s[thisline] != ' ')
- --thisline;
- }
-
- // If we were unable to find a wrapping point then it means one of two
- // things : a) the string is too long to fit on one line, andmust be
- // split unnaturally; or b) we are near the end of a line andmust wrap
- // the entire string; i.e.print nothing, finish the line andgo on
- if (thisline == 0 && s.size() > MAXCOLS)
- thisline = maxchars + 1;
-
- g_vm->writeln(s.substring(0, thisline - 1));
- ++Rows;
- if (Rows >= MAXROWS)
- wrap_wait();
-
- startnext = thisline;
- while (startnext < (int)s.size() && s[startnext] == ' ') {
- ++startnext;
-
- s = s.substring(startnext, s.size());
- cursor = 1;
- thisline = MAXCOLS - cursor;
- }
-
- g_vm->write(s);
- cursor += s.size();
-
- if (terminate) {
- g_vm->writeln();
- ++Rows;
- if (Rows >= MAXROWS)
- wrap_wait();
- cursor = 1;
- }
-}
-
-void wraperr(const String &s) {
- if (cursor > 1)
- g_vm->writeln();
- g_vm->writeln(s);
-
- String tmp;
- for (int i = 1; i < cursor; ++i)
- tmp += ' ';
- g_vm->write(tmp);
-}
-
-StringPtr ReadLine(bool full_line) {
- String s;
-
- if (full_line)
- g_vm->readln(s);
- else
- s = g_vm->ReadKey();
-
- return NewDynStr(s);
-}
-
-void cursor_reset() {
- cursor = 1;
-}
-
-} // End of namespace Archetype
-} // End of namespace Glk
diff --git a/engines/glk/archetype/wrap.h b/engines/glk/archetype/wrap.h
deleted file mode 100644
index 7195303b9f..0000000000
--- a/engines/glk/archetype/wrap.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ARCHETYPE_WRAP
-#define ARCHETYPE_WRAP
-
-#include "glk/archetype/misc.h"
-
-namespace Glk {
-namespace Archetype {
-
-extern int Rows;
-
-/**
- * When we want to wrap a number
- */
-extern void wrapint(int i, bool terminate);
-
-/**
- * Given a string, writes it out to screen, making sure that if it exceeds the screen columns,
- * it is broken at natural word boundaries (i.e. white space)
- */
-extern void wrapout(const String &s, bool terminate);
-
-/**
- * Used for printing run-time errors. It will print the error message on
- * a line by itself and pick up the next line at the exact same cursor position.
- */
-extern void wraperr(const String &s);
-
-/**
- * Hides the extra stack space necessary for performing a readln() so that
- * it won't affect eval_expr
- */
-extern StringPtr ReadLine(bool full_line);
-
-/**
- * Used for directly resetting the cursor position by means other than
- * physically wrapping it around
- */
-extern void cursor_reset();
-
-} // End of namespace Archetype
-} // End of namespace Glk
-
-#endif