[Scummvm-git-logs] scummvm master -> bad3ecd643132a09422117b63a687bf758139c01
dreammaster
paulfgilbert at gmail.com
Sat Jun 22 23:43:52 CEST 2019
This automated email contains information about 21 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
004df0ef90 GLK: ALAN2: Add detection entries
84dfa6d3b8 GLK: ALAN2: Remove previously added code fragments
08bc570308 GLK: ALAN2: Initial import of full set of interpreter files
ed21388e11 GLK: ALAN2: Added missing main code file, hooked up to Alan2 engine skeleton
0bbd9e2638 GLK: ALAN2: Fixes to game header loading and validation
2fba84bf0a GLK: ALAN2: Add Glk window initialization
35cfe001c2 GLK: ALAN2: Add structure packing to types
51a142aaf8 GLK: ALAN2: Loading fixes
b4ae2ec437 GLK: ALAN2: Open text data file on startup
df74652321 GLK: ALAN2: Added shouldQuit checks to break out of game loops
ad1cecaeac GLK: ALAN2: Added savegame code
8f75589971 GLK: ALAN2: Remove all prototype ifdef blocks
dd4108e7c7 GLK: ALAN2: Removing all the existing system specific ifdef blocks
a3fa9d12a9 GLK: ALAN2: Fix gcc errors for references to packed struct fields
2450df501c GLK: ALAN2: astyle formatting
2cf0320569 GLK: ALAN2: Fixing gcc warnings
1249c33539 GLK: ALAN2: Change all EOF to EOD that is case to uint
8b509bbfee GLK: ALAN2: Warning fixes
d4075b188d GLK: ALAN2: Further gcc warning fixes
62eb0be065 GLK: ALAN2: Further gcc warning fixes
bad3ecd643 GLK: ALAN2: Create jump context system to replace original setjmp
Commit: 004df0ef90f8a4b6367b529f66aeffe65e824977
https://github.com/scummvm/scummvm/commit/004df0ef90f8a4b6367b529f66aeffe65e824977
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:22-07:00
Commit Message:
GLK: ALAN2: Add detection entries
Changed paths:
engines/glk/alan2/detection.cpp
engines/glk/alan2/detection_tables.h
diff --git a/engines/glk/alan2/detection.cpp b/engines/glk/alan2/detection.cpp
index fab5117..0b146ad 100644
--- a/engines/glk/alan2/detection.cpp
+++ b/engines/glk/alan2/detection.cpp
@@ -46,24 +46,22 @@ GameDescriptor Alan2MetaEngine::findGame(const char *gameId) {
}
bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
- const char *const EXTENSIONS[] = { ".acd", ".dat", nullptr };
-
// Loop through the files of the folder
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
// Check for a recognised filename
if (file->isDirectory())
continue;
Common::String filename = file->getName();
- bool hasExt = false;
- for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
- hasExt = filename.hasSuffixIgnoreCase(*ext);
+ bool hasExt = filename.hasSuffix(".acd");
if (!hasExt)
continue;
// Open up the file and calculate the md5
Common::File gameFile;
- if (!gameFile.open(*file))
+ if (!gameFile.open(*file) || gameFile.readUint32BE() != MKTAG(2, 8, 1, 0))
continue;
+
+ gameFile.seek(0);
Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000);
size_t filesize = gameFile.size();
gameFile.close();
@@ -75,15 +73,9 @@ bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
DetectedGame gd;
if (!p->_gameId) {
- if (filename.hasSuffixIgnoreCase(".dat"))
- continue;
-
if (gDebugLevel > 0) {
// Print an entry suitable for putting into the detection_tables.h, using the
// name of the parent folder the game is in as the presumed game Id
- Common::String folderName = file->getParent().getName();
- if (folderName.hasSuffix("\\"))
- folderName.deleteLastChar();
Common::String fname = filename;
const char *dot = strchr(fname.c_str(), '.');
if (dot)
@@ -95,8 +87,7 @@ bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown);
} else {
PlainGameDescriptor gameDesc = findGame(p->_gameId);
- gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra);
- gd.setGUIOptions(GUIO4(GUIO_NOSPEECH, GUIO_NOSFX, GUIO_NOMUSIC, GUIO_NOSUBTITLES));
+ gd = DetectedGame(p->_gameId, gameDesc.description, Common::EN_ANY, Common::kPlatformUnknown);
}
gd.addExtraEntry("filename", filename);
diff --git a/engines/glk/alan2/detection_tables.h b/engines/glk/alan2/detection_tables.h
index c642652..277a473 100644
--- a/engines/glk/alan2/detection_tables.h
+++ b/engines/glk/alan2/detection_tables.h
@@ -41,6 +41,20 @@ struct Alan2GameDescription {
const PlainGameDescriptor ALAN2_GAME_LIST[] = {
{ "alan2", "Alan2 Game" },
+ { "bugged", "Bugged" },
+ { "chasing", "The Chasing" },
+ { "closet", "Closet" },
+ { "dinnertime", "Dinnertime" },
+ { "hebgb", "The HeBGB Horror!" },
+ { "lostinnewyork", "Lost In New York" },
+ { "mazemapper", "Mazemapper" },
+ { "meanstory", "The Mean Story" },
+ { "outofthestudy", "Out Of The Study" },
+ { "plsghints", "Painless Little Stupid Games Hints" },
+ { "sardoria", "Sardoria" },
+ { "tgttos", "To Get To The Other Side" },
+ { "afteryou", "They're After You" },
+
{ nullptr, nullptr }
};
@@ -48,7 +62,20 @@ const PlainGameDescriptor ALAN2_GAME_LIST[] = {
#define TABLE_END_MARKER { nullptr, nullptr, nullptr, 0, Common::EN_ANY }
const Alan2GameDescription ALAN2_GAMES[] = {
- //ENTRY0("cragne", "082f518c0120d2323ce340bef8a2d5a9", 8869096),
+ ENTRY0("bugged", "f4eed3db3771a456143744a0e36653db", 112640),
+ ENTRY0("chasing", "718ffcc9dfe85cfd8c6f50f541a3926e", 147456),
+ ENTRY0("closet", "5d724469e6240cde0c16c959f50ebc93", 37888),
+ ENTRY0("dinnertime", "1c0bad19156e8bdefe9e19d99f96f7d8", 9216),
+ ENTRY0("hebgb", "87f9516bc4217afb5c329cb1ae01d861", 173056),
+ ENTRY0("lostinnewyork", "483a8c7c84f3bb5af61150fd770806e5", 30720),
+ ENTRY0("mazemapper", "8e7409758c3535201aeb901923b20064", 30720),
+ ENTRY0("meanstory", "e4ae6873d6f2ab74fb2ec35b27752397", 13312),
+ ENTRY0("outofthestudy", "cc4ab3f1b406a8ce04adcfb641c3b250", 110592),
+ ENTRY0("plsghints", "fb9df41138691a77ea3489986fe8856c", 10240),
+ ENTRY0("sardoria", "b48ba08ae33b5cb224bcb4ce0eea36bc", 150528),
+ ENTRY0("tgttos", "0fed94b37b8add48938d8288ca5e7e4f", 29696),
+ ENTRY0("afteryou", "998ca167b0e9ffb671203b2057d06bef", 17408),
+
TABLE_END_MARKER
};
Commit: 84dfa6d3b83e080f099ad606dc7fbeb40ebe4b97
https://github.com/scummvm/scummvm/commit/84dfa6d3b83e080f099ad606dc7fbeb40ebe4b97
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:22-07:00
Commit Message:
GLK: ALAN2: Remove previously added code fragments
Changed paths:
R engines/glk/alan2/acode.h
R engines/glk/alan2/decode.cpp
R engines/glk/alan2/decode.h
R engines/glk/alan2/execute.cpp
R engines/glk/alan2/execute.h
R engines/glk/alan2/interpreter.cpp
R engines/glk/alan2/interpreter.h
R engines/glk/alan2/parse.cpp
R engines/glk/alan2/parse.h
R engines/glk/alan2/rules.cpp
R engines/glk/alan2/rules.h
R engines/glk/alan2/saveload.cpp
R engines/glk/alan2/saveload.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/alan2.h
engines/glk/module.mk
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
deleted file mode 100644
index 5b5a5be..0000000
--- a/engines/glk/alan2/acode.h
+++ /dev/null
@@ -1,289 +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 GLK_ALAN2_ACODE
-#define GLK_ALAN2_ACODE
-
-#include "common/scummsys.h"
-
-namespace Glk {
-namespace Alan2 {
-
-typedef size_t Aptr; // Type for an ACODE memory address
-typedef uint32 Aword; // Type for an ACODE word
-typedef uint32 Aaddr; // Type for an ACODE address
-typedef uint32 Abool; // Type for an ACODE Boolean value
-typedef int32 Aint; // Type for an ACODE Integer value
-typedef int CodeValue; // Definition for the packing process
-
-// Constants for the Acode file, words/block & bytes/block
-#define BLOCKLEN 256L
-#define BLOCKSIZE (BLOCKLEN*sizeof(Aword))
-
-
-// Definitions for the packing process
-#define VALUEBITS 16
-
-#define EOFChar 256
-#define TOPVALUE (((CodeValue)1<<VALUEBITS) - 1) // Highest value possible
-
-// Half and quarter points in the code value range
-#define ONEQUARTER (TOPVALUE / 4 + 1) // Point after first quarter
-#define HALF (2 * ONEQUARTER) // Point after first half
-#define THREEQUARTER (3 * ONEQUARTER) // Point after third quarter
-
-
-// AMACHINE Word Classes
-typedef int WrdKind;
-#define WRD_SYN 0 // 1 - Synonym
-#define WRD_ADJ 1 // 2 - Adjective
-#define WRD_ALL 2 // 4 - All
-#define WRD_BUT 3 // 8 - But
-#define WRD_CONJ 4 // 16 - Conjunction
-#define WRD_PREP 5 // 32 - Preposition
-#define WRD_DIR 6 // 64 - Direction
-#define WRD_IT 7 // 128 - It
-#define WRD_NOISE 8 // 256 - Noise word
-#define WRD_NOUN 9 // 512 - Noun
-#define WRD_ACT 10 // 1024 - Actor
-#define WRD_THEM 11 // 2048 - Them
-#define WRD_VRB 12 // 4096 - Verb
-#define WRD_CLASSES 13
-
-
-
-// Syntax element classifications
-#define EOS (-2) // End Of Syntax
-
-// Syntax element flag bits
-#define MULTIPLEBIT 0x1
-#define OMNIBIT 0x2
-
-
-// Parameter Classes
-enum ClaKind { // NOTE! These must have the same order as
- CLA_OBJ = 1 << 0, // the name classes in NAM.H
- CLA_CNT = 1 << 1,
- CLA_ACT = 1 << 2,
- CLA_NUM = 1 << 3,
- CLA_STR = 1 << 4,
- CLA_COBJ = 1 << 5,
- CLA_CACT = 1 << 6
-};
-
-
-// Verb Qualifiers
-enum QualClass {
- Q_DEFAULT,
- Q_AFTER,
- Q_BEFORE,
- Q_ONLY
-};
-
-
-// The AMACHINE Operations
-enum OpClass {
- C_CONST,
- C_STMOP,
- C_CURVAR
-};
-
-enum InstClass {
- I_PRINT, // Print a string from the text file
- I_QUIT,
- I_LOOK,
- I_SAVE,
- I_RESTORE,
- I_LIST, // List contents of a container
- I_EMPTY,
- I_SCORE,
- I_VISITS,
- I_SCHEDULE,
- I_CANCEL,
- I_LOCATE,
- I_MAKE,
- I_SET, // Set a numeric attribute to the
- // value on top of stack
- I_STRSET, // Set a string valued attribute to a
- // copy of the string on top of stack,
- // deallocate current contents first
- I_GETSTR, // Get a string contents from text
- // file, create a copy and push it
- // on top of stack
- I_INCR, // Increment an attribute
- I_DECR, // Decrement a numeric attribute
- I_USE,
- I_IN,
- I_DESCRIBE,
- I_SAY,
- I_SAYINT,
- I_SAYSTR,
- I_IF,
- I_ELSE,
- I_ENDIF,
- I_ATTRIBUTE,
- I_STRATTR, // Push a copy of a string attribute
- I_HERE,
- I_NEAR,
- I_WHERE,
- I_AND,
- I_OR,
- I_NE,
- I_EQ,
- I_STREQ, // String compare
- I_STREXACT,
- I_LE,
- I_GE,
- I_LT,
- I_GT,
- I_PLUS,
- I_MINUS,
- I_MULT,
- I_DIV,
- I_NOT,
- I_UMINUS,
- I_RND,
- I_SUM, // SUM-aggregate
- I_MAX, // MAX-aggregate
- I_COUNT, // COUNT-aggregate
- I_RETURN,
- I_SYSTEM,
- I_RESTART, // INTRODUCED: v2.7
- I_BTW, // INTRODUCED: v2.8
- I_CONTAINS, // -""-
- I_DEPSTART, // -""-
- I_DEPCASE, // -""-
- I_DEPEXEC, // -""-
- I_DEPELSE, // -""-
- I_DEPEND // -""-
-};
-
-
-enum VarClass {
- V_PARAM,
- V_CURLOC,
- V_CURACT,
- V_CURVRB,
- V_SCORE
-};
-
-
-#define I_CLASS(x) ((x)>>28)
-#define I_OP(x) ((x&0x8000000)?(x)|0x0f0000000:(x)&0x0fffffff)
-
-
-struct AcdHdr {
-// Important info
- char vers[4]; // 01 - Version of compiler
- Aword size; // 02 - Size of ACD-file in Awords
-// Options
- Abool pack; // 03 - Is the text packed ?
- Aword paglen; // 04 - Length of a page
- Aword pagwidth; // 05 - and width
- Aword debug; // 06 - Option debug
-// Data structures
- Aaddr dict; // 07 - Dictionary
- Aaddr oatrs; // 08 - Object default attributes
- Aaddr latrs; // 09 - Location default attributes
- Aaddr aatrs; // 0a - Actor default attributes
- Aaddr acts; // 0b - Actor table
- Aaddr objs; // 0c - Object table
- Aaddr locs; // 0d - Location table
- Aaddr stxs; // 0e - Syntax table
- Aaddr vrbs; // 0f - Verb table
- Aaddr evts; // 10 - Event table
- Aaddr cnts; // 11 - Container table
- Aaddr ruls; // 12 - Rule table
- Aaddr init; // 13 - String init table
- Aaddr start; // 14 - Start code
- Aword msgs; // 15 - Messages table
-// Miscellaneous
- Aword objmin, objmax; // 16 - Interval for object codes
- Aword actmin, actmax; // 18 - Interval for actor codes
- Aword cntmin, cntmax; // 1a - Interval for container codes
- Aword locmin, locmax; // 1c - Interval for location codes
- Aword dirmin, dirmax; // 1e - Interval for direction codes
- Aword evtmin, evtmax; // 20 - Interval for event codes
- Aword rulmin, rulmax; // 22 - Interval for rule codes
- Aword maxscore; // 24 - Maximum score
- Aaddr scores; // 25 - Score table
- Aaddr freq; // 26 - Address to Char freq's for coding
- Aword acdcrc; // 27 - Checksum for acd code (excl. hdr)
- Aword txtcrc; // 28 - Checksum for text data file
-};
-
-// Error message numbers
-enum MsgKind {
- M_HUH, // Obsolete
- M_WHAT,
- M_WHAT_ALL,
- M_WHAT_IT,
- M_WHAT_THEM,
- M_MULTIPLE,
- M_WANT,
- M_NOUN,
- M_AFTER_BUT,
- M_BUT_ALL,
- M_NOT_MUCH,
- M_WHICH_ONE,
- M_NO_SUCH,
- M_NO_WAY,
- M_CANT0,
- M_CANT,
- M_NOTHING, // Obsolete
- M_SEEOBJ1,
- M_SEEOBJ2,
- M_SEEOBJ3,
- M_SEEOBJ4,
- M_SEEACT,
- M_CONTAINS1,
- M_CONTAINS2,
- M_CONTAINS3,
- M_CONTAINS4,
- M_CONTAINS5,
- M_EMPTY1,
- M_EMPTY2,
- M_SCORE1,
- M_SCORE2,
- M_UNKNOWN_WORD,
- M_MORE,
- M_AGAIN,
- M_SAVEWHERE,
- M_SAVEOVERWRITE,
- M_SAVEFAILED,
- M_SAVEMISSING,
- M_SAVEVERS,
- M_SAVENAME,
- M_RESTOREFROM,
- M_REALLY, // CHANGED: v2.7 from M_RESTART
- M_QUITACTION, // INTRODUCED: v2.7, so M_ARTICLE moved
- M_ARTICLE, // INTRODUCED: v2.6 but replaced the M_NOMSG
- MSGMAX
-};
-
-#define M_ARTICLE26 M_QUITACTION
-#define M_MSGMAX26 M_ARTICLE
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 492d425..1889c69 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -21,10 +21,6 @@
*/
#include "glk/alan2/alan2.h"
-#include "glk/alan2/decode.h"
-#include "glk/alan2/execute.h"
-#include "glk/alan2/interpreter.h"
-#include "glk/alan2/saveload.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
@@ -36,25 +32,16 @@
namespace Glk {
namespace Alan2 {
-Alan2 *_vm = nullptr;
+Alan2 *g_vm = nullptr;
Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
vm_exited_cleanly(false) {
- _vm = this;
- looking = false;
- dscrstkp = 0;
+ g_vm = this;
}
void Alan2::runGame() {
Common::String gameFileName = _gameFile.getName();
- // TODO: Initialize these properly
- int tmp = 0;
- _decode = new Decode(nullptr, nullptr);
- _execute = new Execute();
- _saveLoad = new SaveLoad(gameFileName, nullptr, nullptr, nullptr, nullptr, &tmp);
- _interpreter = new Interpreter(_execute, _saveLoad, _stack);
-
if (!is_gamefile_valid())
return;
@@ -85,27 +72,5 @@ bool Alan2::is_gamefile_valid() {
return true;
}
-void Alan2::output(const Common::String str) {
- // TODO
-}
-
-void Alan2::printMessage(MsgKind msg) {
- // TODO
-}
-
-void Alan2::printError(MsgKind msg) {
- // TODO
-}
-
-void Alan2::paragraph() {
- if (col != 1)
- newLine();
- newLine();
-}
-
-void Alan2::newLine() {
- // TODO
-}
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h
index a8e500a..3b5c778 100644
--- a/engines/glk/alan2/alan2.h
+++ b/engines/glk/alan2/alan2.h
@@ -26,20 +26,10 @@
#include "common/scummsys.h"
#include "common/stack.h"
#include "glk/glk_api.h"
-#include "glk/alan2/acode.h"
-#include "glk/alan2/types.h"
namespace Glk {
namespace Alan2 {
-typedef Common::FixedStack<Aptr, 100> Alan2Stack;
-class Decode;
-class Execute;
-class Interpreter;
-class SaveLoad;
-
-#define N_EVTS 100
-
/**
* Alan2 game interpreter
*/
@@ -78,63 +68,9 @@ public:
*/
virtual Common::Error writeGameData(Common::WriteStream *ws) override;
- /**
- * Output a string to the screen
- */
- void output(const Common::String str);
-
- /**
- * Print a message from the message table
- */
- void printMessage(MsgKind msg);
-
- /**
- * Print an error from the message table, force new player input and abort
- */
- void printError(MsgKind msg);
-
- /**
- * Make a new paragraph, i.e one empty line (one or two newlines)
- */
- void paragraph();
-
- /**
- * Print the the status line on the top of the screen
- */
- void statusLine();
-
- /**
- * Make a newline, but check for screen full
- */
- void newLine();
-
- // Engine variables
- Alan2Stack *_stack;
- int pc;
- ParamElem *params;
- Aword *memory; // The Amachine memory
- int memTop; // Top of memory
- CurVars cur; // Amachine variables
- int col;
- bool fail;
- int scores[100]; // FIXME: type + size
- AcdHdr *header;
- bool _needSpace; // originally "needsp"
-
- EvtElem *evts; // Event table pointer
- bool looking; // LOOKING? flag
- int dscrstkp; // Describe-stack pointer
- Common::File *_txtFile;
- bool _anyOutput;
- winid_t _bottomWindow;
-
- Decode *_decode;
- Execute *_execute;
- Interpreter *_interpreter;
- SaveLoad *_saveLoad;
};
-extern Alan2 *_vm;
+extern Alan2 *g_vm;
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
deleted file mode 100644
index 58e814f..0000000
--- a/engines/glk/alan2/decode.cpp
+++ /dev/null
@@ -1,120 +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/alan2/decode.h"
-
-namespace Glk {
-namespace Alan2 {
-
-int Decode::inputBit() {
- int bit;
-
- if (!_bitsToGo) { // More bits available ?
- _decodeBuffer = _txtFile->readByte(); // No, so get more
- if (_txtFile->eos()) {
- _garbageBits++;
-
- if (_garbageBits > VALUEBITS - 2)
- error("Error in encoded data file.");
- } else
- _bitsToGo = 8; // Another Char, 8 new bits
- }
-
- bit = _decodeBuffer & 1; // Get next bit
- _decodeBuffer = _decodeBuffer >> 1; // and remove it
- _bitsToGo--;
-
- return bit;
-}
-
-void Decode::startDecoding() {
- _bitsToGo = 0;
- _garbageBits = 0;
-
- _value = 0;
- for (int i = 0; i < VALUEBITS; i++)
- _value = 2 * _value + inputBit();
-
- _low = 0;
- _high = TOPVALUE;
-}
-
-int Decode::decodeChar() {
- const long range = (long)(_high - _low) + 1;
- const uint f = (((long)(_value - _low) + 1) * _freq[0] - 1) / range;
- int symbol;
-
- // Find the symbol
- for (symbol = 1; _freq[symbol] > f; symbol++);
-
- _high = _low + range * _freq[symbol - 1] / _freq[0] - 1;
- _low = _low + range * _freq[symbol] / _freq[0];
-
- for (;;) {
- if (_high < HALF) {
- // Do nothing
- } else if (_low >= HALF) {
- _value = _value - HALF;
- _low = _low - HALF;
- _high = _high - HALF;
- } else if (_low >= ONEQUARTER && _high < THREEQUARTER) {
- _value = _value - ONEQUARTER;
- _low = _low - ONEQUARTER;
- _high = _high - ONEQUARTER;
- } else
- break;
-
- // Scale up the range
- _low = 2 * _low;
- _high = 2 * _high + 1;
- _value = 2 * _value + inputBit();
- }
-
- return symbol - 1;
-}
-
-DecodeInfo *Decode::pushDecode() {
- DecodeInfo *info = new DecodeInfo();
-
- info->fpos = _txtFile->pos();
- info->buffer = _decodeBuffer;
- info->bits = _bitsToGo;
- info->value = _value;
- info->high = _high;
- info->low = _low;
-
- return info;
-}
-
-void Decode::popDecode (DecodeInfo *info) {
- _txtFile->seek(info->fpos, SEEK_CUR);
- _decodeBuffer = info->buffer;
- _bitsToGo = info->bits;
- _value = info->value;
- _high = info->high;
- _low = info->low;
-
- delete info;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/decode.h b/engines/glk/alan2/decode.h
deleted file mode 100644
index 75a35dc..0000000
--- a/engines/glk/alan2/decode.h
+++ /dev/null
@@ -1,80 +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 GLK_ALAN2_DECODE
-#define GLK_ALAN2_DECODE
-
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/acode.h"
-#include "common/file.h"
-
-namespace Glk {
-namespace Alan2 {
-
-// Structure for saved decode info
-struct DecodeInfo {
- long fpos;
- int buffer;
- int bits;
- CodeValue value;
- CodeValue high;
- CodeValue low;
-};
-
-class Decode {
-public:
- Decode(Common::File *txtFile, Aword *freq): _txtFile(txtFile), _freq(freq) {}
- void startDecoding();
- int decodeChar();
-
- /**
- * Save so much about the decoding process, so it is possible to restore
- * and continue later.
- */
- DecodeInfo *pushDecode();
-
- /**
- * Restore enough info about the decoding process, so it is possible to
- * continue after having decoded something else.
- */
- void popDecode(DecodeInfo *info);
-
- int inputBit();
-
-private:
- // Bit output
- int _decodeBuffer; // Bits to be input
- int _bitsToGo; // Bits still in buffer
- int _garbageBits; // Bits past EOF
-
- Aword *_freq;
- Common::File *_txtFile;
-
- // Current state of decoding
- CodeValue _value; // Currently seen code value
- CodeValue _low, _high; // Current code region
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/execute.cpp b/engines/glk/alan2/execute.cpp
deleted file mode 100644
index 4fc0acb..0000000
--- a/engines/glk/alan2/execute.cpp
+++ /dev/null
@@ -1,944 +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 "common/stack.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/decode.h"
-#include "glk/alan2/execute.h"
-#include "glk/alan2/interpreter.h"
-#include "glk/alan2/saveload.h"
-#include "glk/alan2/types.h"
-#include "glk/alan2/util.h"
-#include "common/debug.h"
-#include "common/file.h"
-
-namespace Glk {
-namespace Alan2 {
-
-#define WIDTH 80
-
-// Is there an exit from one location to another ?
-bool Execute::exitto(int to, int from) {
- if (_locs[from - LOCMIN].exts == 0)
- return false; // No exits
-
- for (ExtElem *ext = (ExtElem *)addrTo(_locs[from - LOCMIN].exts); !endOfTable(ext); ext++)
- if ((int)ext->next == to)
- return true;
-
- return false;
-}
-
-int Execute::count(int cnt) {
- int j = 0;
-
- for (uint i = OBJMIN; i <= OBJMAX; i++)
- if (in(i, cnt))
- j++; // Then it's in this container also
-
- return j;
-}
-
-int Execute::sumAttributes(Aword atr, Aword cnt) {
- int sum = 0;
-
- for (uint i = OBJMIN; i <= OBJMAX; i++) {
- if (_objs[i - OBJMIN].loc == cnt) { // Then it's in this container
- if (_objs[i - OBJMIN].cont != 0) // This is also a container!
- sum = sum + sumAttributes(atr, i);
- sum = sum + attribute(i, atr);
- }
- }
-
- return sum;
-}
-
-bool Execute::checkContainerLimit(Aword cnt, Aword obj) {
- LimElem *lim;
- Aword props;
-
- _vm->fail = true;
- if (!isCnt(cnt))
- error("Checking limits for a non-container.");
-
- // Find the container properties
- if (isObj(cnt))
- props = _objs[cnt - OBJMIN].cont;
- else if (isAct(cnt))
- props = _acts[cnt - ACTMIN].cont;
- else
- props = cnt;
-
-
- if (_cnts[props - CNTMIN].lims != 0) { /* Any limits at all? */
- for (lim = (LimElem *)addrTo(_cnts[props - CNTMIN].lims); !endOfTable(lim); lim++) {
- if (lim->atr == 0) {
- if (count(cnt) >= (int)lim->val) {
- _vm->_interpreter->interpret(lim->stms);
- return true; // Limit check failed
- }
- } else {
- if (sumAttributes(lim->atr, cnt) + attribute(obj, lim->atr) > lim->val) {
- _vm->_interpreter->interpret(lim->stms);
- return true;
- }
- }
- }
- }
-
- _vm->fail = false;
-
- return false;
-}
-
-void Execute::print(Aword fpos, Aword len) {
- char str[2 * WIDTH]; // String buffer
- int outlen = 0; // Current output length
- int ch = 0;
- int i;
- long savfp = 0; // Temporary saved text file position
- bool printFlag = false; // Printing already?
- bool savedPrintFlag = printFlag;
- DecodeInfo *info = nullptr; // Saved decoding info
-
-
- if (len == 0)
- return;
-
- if (isHere(HERO)) { // Check if the player will see it
- if (printFlag) { // Already printing?
- // Save current text file position and/or decoding info
- if (_vm->header->pack)
- info = _vm->_decode->pushDecode();
- else
- savfp = _vm->_txtFile->pos();
- }
-
- printFlag = true; // We're printing now!
- _vm->_txtFile->seek(fpos, SEEK_CUR); // Position to start of text
- if (_vm->header->pack)
- _vm->_decode->startDecoding();
-
- for (outlen = 0; outlen != (int)len; outlen = outlen + strlen(str)) {
- // Fill the buffer from the beginning
- for (i = 0; i <= WIDTH || (i > WIDTH && ch != ' '); i++) {
- if (outlen + i == (int)len) // No more characters?
- break;
- if (_vm->header->pack)
- ch = _vm->_decode->decodeChar();
- else
- ch = _vm->_txtFile->readSByte();
- if (ch == EOFChar) // Or end of text?
- break;
- str[i] = ch;
- }
-
- str[i] = '\0';
-
- // TODO
- /*
-#if ISO == 0
- fromIso(str, str);
-#endif
- */
- _vm->output(str);
- }
-
- // And restore
- printFlag = savedPrintFlag;
- if (printFlag) {
- if (_vm->header->pack)
- _vm->_decode->popDecode(info);
- else
- _vm->_txtFile->seek(savfp, SEEK_CUR);
- }
- }
-}
-
-void Execute::sys(Aword fpos, Aword len) {
- char *command;
-
- getstr(fpos, len); // Returns address to string on stack
- command = (char *)_vm->_stack->pop();
-
- warning("Request to execute system command %s", command);
- free(command);
-}
-
-void Execute::getstr(Aword fpos, Aword len) {
- char *buf = new char[len + 1];
-
- _vm->_stack->push((Aptr) buf); // Push the address to the string
- _vm->_txtFile->seek(fpos, SEEK_CUR); // Position to start of text
- if (_vm->header->pack)
- _vm->_decode->startDecoding();
- while (len--) {
- if (_vm->header->pack)
- *(buf++) = _vm->_decode->decodeChar();
- else
- *(buf++) = _vm->_txtFile->readSByte();
- }
- *buf = '\0';
-}
-
-void Execute::score(Aword sc) {
- char buf[80];
-
- if (sc == 0) {
- _vm->printMessage(M_SCORE1);
- sprintf(buf, "%d", _vm->cur.score);
- _vm->output(buf);
- _vm->printMessage(M_SCORE2);
- sprintf(buf, "%ld.", (unsigned long)_vm->header->maxscore);
- _vm->output(buf);
- } else {
- _vm->cur.score += _vm->scores[sc - 1];
- _vm->scores[sc - 1] = 0;
- }
-}
-
-void Execute::visits(Aword v) {
- _vm->cur.visits = v;
-}
-
-bool Execute::confirm(MsgKind msgno) {
- char buf[80];
-
- // This is a bit of a hack since we really want to compare the input,
- // it could be affirmative, but for now any input is NOT!
- _vm->printMessage(msgno);
-
- // TODO
-#if 0
- //_vm->glk_request_line_event(_bottomWindow, buf, 80 - 1, 0);
-
-#ifdef USE_READLINE
- if (!readline(buf)) return true;
-#else
- if (gets(buf) == nullptr) return true;
-#endif
-
-#endif
- _vm->col = 1;
-
- return (buf[0] == '\0');
-}
-
-
-void Execute::quit() {
- char buf[80];
-// char choices[10];
-
- _vm->paragraph();
-
- while (true) {
- _vm->col = 1;
- _vm->statusLine();
- _vm->printMessage(M_QUITACTION);
-
- // TODO
-#if 0
-#ifdef USE_READLINE
- if (!readline(buf)) terminate(0);
-#else
- if (gets(buf) == nullptr) terminate(0);
-#endif
-#endif
-
- if (strcmp(buf, "restart") == 0) {
- //longjmp(restart_label, true); // TODO
- } else if (strcmp(buf, "restore") == 0) {
- _vm->_saveLoad->restore();
- return;
- } else if (strcmp(buf, "quit") == 0) {
- _vm->quitGame();
- }
- }
- error("Fallthrough in QUIT");
-}
-
-void Execute::restart() {
- _vm->paragraph();
- if (confirm(M_REALLY)) {
- //longjmp(restart_label, true); // TODO
- } else
- return;
-
- error("Fallthrough in RESTART");
-}
-
-void Execute::eventchk() {
- while (etop != 0 && eventq[etop - 1].time == _vm->cur.tick) {
- etop--;
- if (isLoc(eventq[etop].where))
- _vm->cur.loc = eventq[etop].where;
- else
- _vm->cur.loc = where(eventq[etop].where);
-
- // TODO
-#if 0
- if (trcflg) {
- debug("\n<EVENT %d (at ", eventq[etop].event);
- debugsay(_vm->cur.loc);
- debug("):>\n");
- }
-#endif
- _vm->_interpreter->interpret(_vm->evts[eventq[etop].event - EVTMIN].code);
- }
-}
-
-void Execute::cancl(Aword evt) {
- int i;
-
- for (i = etop - 1; i >= 0; i--) {
- if (eventq[i].event == (int)evt) {
- while (i < etop - 1) {
- eventq[i].event = eventq[i + 1].event;
- eventq[i].time = eventq[i + 1].time;
- eventq[i].where = eventq[i + 1].where;
- i++;
- }
-
- etop--;
- return;
- }
- }
-}
-
-void Execute::schedule(Aword evt, Aword whr, Aword aft) {
- int i;
- int time;
-
- cancl(evt);
- // Check for overflow
- if (etop == N_EVTS)
- error("Out of event space.");
-
- time = _vm->cur.tick+aft;
-
- // Bubble this event down
- for (i = etop; i >= 1 && eventq[i-1].time <= time; i--) {
- eventq[i].event = eventq[i-1].event;
- eventq[i].time = eventq[i-1].time;
- eventq[i].where = eventq[i-1].where;
- }
-
- eventq[i].time = time;
- eventq[i].where = whr;
- eventq[i].event = evt;
- etop++;
-}
-
-Aptr Execute::getAttribute(Aaddr atradr, Aaddr atr) {
- AtrElem *at = (AtrElem *)addrTo(atradr);
- return at[atr - 1].val;
-}
-
-void Execute::setAttribute(Aaddr atradr, Aword atr, Aword val) {
- AtrElem *at = (AtrElem *)addrTo(atradr);
- at[atr - 1].val = val;
-}
-
-void Execute::make(Aword id, Aword atr, Aword val) {
- if (isObj(id))
- setAttribute(_objs[id - OBJMIN].atrs, atr, val);
- else if (isLoc(id))
- setAttribute(_locs[id - LOCMIN].atrs, atr, val);
- else if (isAct(id))
- setAttribute(_acts[id - ACTMIN].atrs, atr, val);
- else
- error("Can't MAKE item (%ld).", (unsigned long)id);
-}
-
-void Execute::set(Aword id, Aword atr, Aword val) {
- if (isObj(id))
- setAttribute(_objs[id - OBJMIN].atrs, atr, val);
- else if (isLoc(id)) {
- setAttribute(_locs[id - LOCMIN].atrs, atr, val);
- _locs[id - LOCMIN].describe = 0;
- } else if (isAct(id))
- setAttribute(_acts[id - ACTMIN].atrs, atr, val);
- else
- error("Can't SET item (%ld).", (unsigned long)id);
-}
-
-void Execute::setstr(Aword id, Aword atr, Aword str) {
- free((char *)attribute(id, atr));
- set(id, atr, str);
-}
-
-void Execute::incAttribute(Aaddr atradr, Aword atr, Aword step) {
- AtrElem *at = (AtrElem *) addrTo(atradr);
- at[atr - 1].val += step;
-}
-
-void Execute::incLocation(Aword loc, Aword atr, Aword step) {
- incAttribute(_locs[loc - LOCMIN].atrs, atr, step);
- _locs[loc - LOCMIN].describe = 0;
-}
-
-void Execute::incObject(Aword obj, Aword atr, Aword step) {
- incAttribute(_objs[obj - OBJMIN].atrs, atr, step);
-}
-
-void Execute::incract(Aword act, Aword atr, Aword step) {
- incAttribute(_acts[act - ACTMIN].atrs, atr, step);
-}
-
-void Execute::incr(Aword id, Aword atr, Aword step) {
- if (isObj(id))
- incObject(id, atr, step);
- else if (isLoc(id))
- incLocation(id, atr, step);
- else if (isAct(id))
- incract(id, atr, step);
- else
- error("Can't INCR item (%ld).", (unsigned long)id);
-}
-
-void Execute::decr(Aword id, Aword atr, Aword step) {
- if (isObj(id))
- incObject(id, atr, -(int)step);
- else if (isLoc(id))
- incLocation(id, atr, -(int)step);
- else if (isAct(id))
- incract(id, atr, -(int)step);
- else
- error("Can't DECR item (%ld).", (unsigned long)id);
-}
-
-Aptr Execute::attribute(Aword id, Aword atr) {
- if (isObj(id))
- return getAttribute(_objs[id - OBJMIN].atrs, atr);
- else if (isLoc(id))
- return getAttribute(_locs[id - LOCMIN].atrs, atr);
- else if (isAct(id))
- return getAttribute(_acts[id - ACTMIN].atrs, atr);
- else if (isLit(id)) {
- if (atr == 1)
- return litValues[id - LITMIN].value;
- else
- error("Unknown attribute for literal (%ld).", (unsigned long)atr);
- } else
- error("Can't ATTRIBUTE item (%ld).", (unsigned long) id);
-}
-
-Aptr Execute::strattr(Aword id, Aword atr) {
- Common::String result = (char *)attribute(id, atr);
- return (Aptr)result.c_str();
-}
-
-Aword Execute::objloc(Aword obj) {
- if (isCnt(_objs[obj - OBJMIN].loc)) { // In something ?
- if (isObj(_objs[obj - OBJMIN].loc) || isAct(_objs[obj - OBJMIN].loc))
- return(where(_objs[obj - OBJMIN].loc));
- else // Containers not anywhere is where the hero is!
- return(where(HERO));
- } else {
- return(_objs[obj - OBJMIN].loc);
- }
-}
-
-Aword Execute::actloc(Aword act) {
- return(_acts[act - ACTMIN].loc);
-}
-
-Aword Execute::where(Aword id) {
- if (isObj(id))
- return objloc(id);
- else if (isAct(id))
- return actloc(id);
- else
- error("Can't WHERE item (%ld).", (unsigned long) id);
-}
-
-Aint Execute::agrmax(Aword atr, Aword whr) {
- Aword i;
- uint max = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr && attribute(i, atr) > max)
- max = attribute(i, atr);
- } else if (_objs[i - OBJMIN].loc == whr && attribute(i, atr) > max)
- max = attribute(i, atr);
- }
-
- return(max);
-}
-
-Aint Execute::agrsum(Aword atr, Aword whr) {
- Aword i;
- uint sum = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr)
- sum += attribute(i, atr);
- } else if (_objs[i-OBJMIN].loc == whr)
- sum += attribute(i, atr);
- }
-
- return(sum);
-}
-
-Aint Execute::agrcount(Aword whr) {
- Aword i;
- Aword countVal = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr)
- countVal++;
- } else if (_objs[i-OBJMIN].loc == whr)
- countVal++;
- }
-
- return(countVal);
-}
-
-void Execute::locobj(Aword obj, Aword whr) {
- if (isCnt(whr)) { // Into a container
- if (whr == obj)
- error("Locating something inside itself.");
- if (checkContainerLimit(whr, obj))
- return;
- else
- _objs[obj-OBJMIN].loc = whr;
- } else {
- _objs[obj-OBJMIN].loc = whr;
- // Make sure the location is described since it's changed
- _locs[whr-LOCMIN].describe = 0;
- }
-}
-
-void Execute::locact(Aword act, Aword whr) {
- Aword prevact = _vm->cur.act;
- Aword prevloc = _vm->cur.loc;
-
- _vm->cur.loc = whr;
- _acts[act - ACTMIN].loc = whr;
-
- if (act == HERO) {
- if (_locs[_acts[act - ACTMIN].loc-LOCMIN].describe % (_vm->cur.visits+1) == 0)
- look();
- else {
- if (_vm->_anyOutput)
- _vm->paragraph();
-
- say(where(HERO));
- _vm->printMessage(M_AGAIN);
- _vm->newLine();
- dscrobjs();
- dscracts();
- }
-
- _locs[where(HERO)-LOCMIN].describe++;
- _locs[where(HERO)-LOCMIN].describe %= (_vm->cur.visits+1);
- } else
- _locs[whr-LOCMIN].describe = 0;
-
- if (_locs[_vm->cur.loc-LOCMIN].does != 0) {
- _vm->cur.act = act;
- _vm->_interpreter->interpret(_locs[_vm->cur.loc-LOCMIN].does);
- _vm->cur.act = prevact;
- }
-
- if (_vm->cur.act != (int)act)
- _vm->cur.loc = prevloc;
-}
-
-
-void Execute::locate(Aword id, Aword whr) {
- if (isObj(id))
- locobj(id, whr);
- else if (isAct(id))
- locact(id, whr);
- else
- error("Can't LOCATE item (%ld).", (unsigned long)id);
-}
-
-Abool Execute::objhere(Aword obj) {
- if (isCnt(_objs[obj - OBJMIN].loc)) { // In something?
- if (isObj(_objs[obj - OBJMIN].loc) || isAct(_objs[obj - OBJMIN].loc))
- return(isHere(_objs[obj - OBJMIN].loc));
- else // If the container wasn't anywhere, assume where HERO is!
- return((int)where(HERO) == _vm->cur.loc);
- } else
- return((int)_objs[obj - OBJMIN].loc == _vm->cur.loc);
-}
-
-Aword Execute::acthere(Aword act) {
- return (int)_acts[act - ACTMIN].loc == _vm->cur.loc;
-}
-
-Abool Execute::isHere(Aword id) {
- if (isObj(id))
- return objhere(id);
- else if (isAct(id))
- return acthere(id);
- else
- error("Can't HERE item (%ld).", (unsigned long)id);
-}
-
-Aword Execute::objnear(Aword obj) {
- if (isCnt(_objs[obj-OBJMIN].loc)) { // In something?
- if (isObj(_objs[obj-OBJMIN].loc) || isAct(_objs[obj-OBJMIN].loc))
- return(isNear(_objs[obj-OBJMIN].loc));
- else // If the container wasn't anywhere, assume here, so not nearby!
- return(false);
- } else {
- return(exitto(where(obj), _vm->cur.loc));
- }
-}
-
-Aword Execute::actnear(Aword act) {
- return(exitto(where(act), _vm->cur.loc));
-}
-
-
-Abool Execute::isNear(Aword id) {
- if (isObj(id))
- return objnear(id);
- else if (isAct(id))
- return actnear(id);
- else
- error("Can't NEAR item (%ld).", (unsigned long) id);
-}
-
-Abool Execute::in(Aword obj, Aword cnt) {
- if (!isObj(obj))
- return(false);
- if (!isCnt(cnt))
- error("IN in a non-container.");
-
- return(_objs[obj - OBJMIN].loc == cnt);
-}
-
-void Execute::sayarticle(Aword id) {
- if (!isObj(id))
- error("Trying to say article of something *not* an object.");
- if (_objs[id - OBJMIN].art != 0)
- _vm->_interpreter->interpret(_objs[id - OBJMIN].art);
- else
- _vm->printMessage(M_ARTICLE);
-}
-
-void Execute::say(Aword id) {
- if (isHere(HERO)) {
- if (isObj(id))
- _vm->_interpreter->interpret(_objs[id - OBJMIN].dscr2);
- else if (isLoc(id))
- _vm->_interpreter->interpret(_locs[id - LOCMIN].nams);
- else if (isAct(id))
- _vm->_interpreter->interpret(_acts[id - ACTMIN].nam);
- else if (isLit(id)) {
- if (isNum(id))
- _vm->output(Common::String::format("%ld", litValues[id - LITMIN].value));
- else
- _vm->output((char *)litValues[id - LITMIN].value);
- } else
- error("Can't SAY item (%ld).", (unsigned long)id);
- }
-}
-
-void Execute::dscrloc(Aword loc) {
- if (_locs[loc - LOCMIN].dscr != 0)
- _vm->_interpreter->interpret(_locs[loc - LOCMIN].dscr);
-}
-
-void Execute::dscrobj(Aword obj) {
- _objs[obj - OBJMIN].describe = false;
- if (_objs[obj - OBJMIN].dscr1 != 0)
- _vm->_interpreter->interpret(_objs[obj - OBJMIN].dscr1);
- else {
- _vm->printMessage(M_SEEOBJ1);
- sayarticle(obj);
- say(obj);
- _vm->printMessage(M_SEEOBJ4);
- if (_objs[obj - OBJMIN].cont != 0)
- list(obj);
- }
-}
-
-
-void Execute::dscract(Aword act) {
- ScrElem *scr = nullptr;
-
- if (_acts[act - ACTMIN].script != 0) {
- for (scr = (ScrElem *) addrTo(_acts[act - ACTMIN].scradr); !endOfTable(scr); scr++)
- if (scr->code == _acts[act - ACTMIN].script)
- break;
- if (endOfTable(scr))
- scr = nullptr;
- }
-
- if (scr != nullptr && scr->dscr != 0)
- _vm->_interpreter->interpret(scr->dscr);
- else if (_acts[act - ACTMIN].dscr != 0)
- _vm->_interpreter->interpret(_acts[act - ACTMIN].dscr);
- else {
- _vm->_interpreter->interpret(_acts[act - ACTMIN].nam);
- _vm->printMessage(M_SEEACT);
- }
-
- _acts[act - ACTMIN].describe = false;
-}
-
-void Execute::describe(Aword id) {
- for (uint i = 0; i < _describeStack.size(); i++) {
- _describeStack.push(id);
-
- if (isObj(id))
- dscrobj(id);
- else if (isLoc(id))
- dscrloc(id);
- else if (isAct(id))
- dscract(id);
- else
- error("Can't DESCRIBE item (%ld).", (unsigned long)id);
- }
-
- _describeStack.pop();
-}
-
-void Execute::use(Aword act, Aword scr) {
- if (!isAct(act))
- error("Item is not an Actor (%ld).", (unsigned long) act);
-
- _acts[act - ACTMIN].script = scr;
- _acts[act - ACTMIN].step = 0;
-}
-
-void Execute::list(Aword cnt) {
- uint i;
- Aword props;
- Aword prevobj = 0;
- bool found = false;
- bool multiple = false;
-
- // Find container properties
- if (isObj(cnt))
- props = _objs[cnt-OBJMIN].cont;
- else if (isAct(cnt))
- props = _acts[cnt-ACTMIN].cont;
- else
- props = cnt;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (in(i, cnt)) { // Yes, it's in this container
- if (!found) {
- found = true;
- if (_cnts[props-CNTMIN].header != 0)
- _vm->_interpreter->interpret(_cnts[props-CNTMIN].header);
- else {
- _vm->printMessage(M_CONTAINS1);
- if (_cnts[props-CNTMIN].nam != 0) // It has it's own name
- _vm->_interpreter->interpret(_cnts[props-CNTMIN].nam);
- else
- say(_cnts[props-CNTMIN].parent); // It is actually an object or actor
-
- _vm->printMessage(M_CONTAINS2);
- }
- } else {
- if (multiple) {
- _vm->_needSpace = false;
- _vm->printMessage(M_CONTAINS3);
- }
-
- multiple = true;
- sayarticle(prevobj);
- say(prevobj);
- }
-
- prevobj = i;
- }
- }
-
- if (found) {
- if (multiple)
- _vm->printMessage(M_CONTAINS4);
-
- sayarticle(prevobj);
- say(prevobj);
- _vm->printMessage(M_CONTAINS5);
- } else {
- if (_cnts[props-CNTMIN].empty != 0)
- _vm->_interpreter->interpret(_cnts[props-CNTMIN].empty);
- else {
- _vm->printMessage(M_EMPTY1);
-
- if (_cnts[props-CNTMIN].nam != 0) // It has it's own name
- _vm->_interpreter->interpret(_cnts[props-CNTMIN].nam);
- else
- say(_cnts[props-CNTMIN].parent); // It is actually an actor or object
-
- _vm->printMessage(M_EMPTY2);
- }
- }
-
- _vm->_needSpace = true;
-}
-
-void Execute::empty(Aword cnt, Aword whr) {
- for (uint i = OBJMIN; i <= OBJMAX; i++)
- if (in(i, cnt))
- locate(i, whr);
-}
-
-void Execute::dscrobjs() {
- uint i;
- int prevobj = 0;
- bool found = false;
- bool multiple = false;
-
- // First describe everything here with its own description
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if ((int)_objs[i - OBJMIN].loc == _vm->cur.loc && _objs[i - OBJMIN].describe && _objs[i - OBJMIN].dscr1)
- describe(i);
- }
-
- // Then list everything else here
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if ((int)_objs[i - OBJMIN].loc == _vm->cur.loc && _objs[i - OBJMIN].describe) {
- if (!found) {
- _vm->printMessage(M_SEEOBJ1);
- sayarticle(i);
- say(i);
- found = true;
- } else {
- if (multiple) {
- _vm->_needSpace = false;
- _vm->printMessage(M_SEEOBJ2);
- sayarticle(prevobj);
- say(prevobj);
- }
-
- multiple = true;
- }
-
- prevobj = i;
- }
- }
-
- if (found) {
- if (multiple) {
- _vm->printMessage(M_SEEOBJ3);
- sayarticle(prevobj);
- say(prevobj);
- }
-
- _vm->printMessage(M_SEEOBJ4);
- }
-
- // Set describe flag for all objects
- for (i = OBJMIN; i <= OBJMAX; i++)
- _objs[i-OBJMIN].describe = true;
-}
-
-
-void Execute::dscracts() {
- for (uint i = HERO+1; i <= ACTMAX; i++)
- if ((int)_acts[i-ACTMIN].loc == _vm->cur.loc &&
- _acts[i-ACTMIN].describe)
- describe(i);
-
- // Set describe flag for all actors
- for (uint i = HERO; i <= ACTMAX; i++)
- _acts[i-ACTMIN].describe = true;
-}
-
-void Execute::look() {
- uint i;
- _vm->looking = true;
-
- // Set describe flag for all objects and actors
- for (i = OBJMIN; i <= OBJMAX; i++)
- _objs[i-OBJMIN].describe = true;
- for (i = ACTMIN; i <= ACTMAX; i++)
- _acts[i-ACTMIN].describe = true;
-
- if (_vm->_anyOutput)
- _vm->paragraph();
-
- //glk_set_style(style_Subheader); // TODO
- _vm->_needSpace = false;
- say(_vm->cur.loc);
-
- _vm->_needSpace = false;
- _vm->output(".");
-
- //glk_set_style(style_Normal); // TODO
- _vm->newLine();
- _vm->_needSpace = false;
- describe(_vm->cur.loc);
- dscrobjs();
- dscracts();
- _vm->looking = false;
-}
-
-Aword Execute::rnd(Aword from, Aword to) {
- if (to == from)
- return to;
- else if (to > from)
- return to; // TODO
- //return (rand()/10)%(to-from+1)+from;
- else
- return to; // TODO
- //return (rand()/10)%(from-to+1)+to;
-}
-
-// Between
-Abool Execute::btw(Aint val, Aint low, Aint high) {
- if (high > low)
- return low <= val && val <= high;
- else
- return high <= val && val <= low;
-}
-
-// TODO: Replace this with Common::String functionality
-Aword Execute::contains(Aptr string, Aptr substring) {
- Common::String str = (char *)string;
- char *substr = (char *)substring;
- bool result = str.contains(substr);
-
- free((char *)string);
- free((char *)substring);
-
- return result;
-}
-
-// TODO: Replace this with Common::String functionality
-// Compare two strings approximately, ignore case
-Abool Execute::streq(char *a, char *b) {
- Common::String str1 = a;
- Common::String str2 = b;
- bool result = str1.equalsIgnoreCase(str2);
-
- free(a);
- free(b);
-
- return result;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/execute.h b/engines/glk/alan2/execute.h
deleted file mode 100644
index 9f04ca5..0000000
--- a/engines/glk/alan2/execute.h
+++ /dev/null
@@ -1,171 +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 GLK_ALAN2_EXECUTE
-#define GLK_ALAN2_EXECUTE
-
-#include "glk/alan2/acode.h"
-#include "glk/alan2/rules.h"
-#include "common/list.h"
-
-namespace Glk {
-namespace Alan2 {
-
-class Execute {
-public:
- Execute() {}
-
- void sys(Aword fpos, Aword len);
- bool confirm(MsgKind msgno);
- Aptr attribute(Aword item, Aword atr);
- void say(Aword item);
- void saynum(Aword num);
- void saystr(char *str);
- Aptr strattr(Aword id, Aword atr);
- void setstr(Aword id, Aword atr, Aword str);
- void getstr(Aword fpos, Aword len);
- void print(Aword fpos, Aword len);
- void look();
- void make(Aword id, Aword atr, Aword val);
- void set(Aword id, Aword atr, Aword val);
- void incr(Aword id, Aword atr, Aword step);
- void decr(Aword id, Aword atr, Aword step);
- void use(Aword act, Aword scr);
- void describe(Aword id);
- void list(Aword cnt);
- void locate(Aword id, Aword whr);
- void empty(Aword cnt, Aword whr);
- void score(Aword sc);
- void visits(Aword v);
-
- /**
- * Check if any events are pending. If so execute them.
- */
- void eventchk();
- void schedule(Aword evt, Aword whr, Aword aft);
- void cancl(Aword evt);
-
- void quit();
- void restart();
- void sayint(Aword val);
- Aword rnd(Aword from, Aword to);
- Abool btw(Aint val, Aint from, Aint to);
- Aword contains(Aptr string, Aptr substring);
- Abool streq(char a[], char b[]);
- Abool in(Aword obj, Aword cnt);
- Aword where(Aword item);
- Aint agrmax(Aword atr, Aword whr);
- Aint agrsum(Aword atr, Aword whr);
- Aint agrcount(Aword whr);
- Abool isHere(Aword item);
- Abool isNear(Aword item);
-
-private:
- bool exitto(int to, int from);
-
- /**
- * Count the number of items in a container.
- *
- * @param cnt The container to count
- */
- int count(int cnt);
-
- /**
- * Sum the values of one attribute in a container. Recursively.
- *
- * @param atr The attribute to sum over
- * @param cnt the container to sum
- */
- int sumAttributes(Aword atr, Aword cnt);
-
- /**
- * Checks if a limit for a container is exceeded.
- *
- * @param cnt Container code
- * @param obj The object to add
- */
- bool checkContainerLimit(Aword cnt, Aword obj);
-
- /**
- * Get an attribute value from an attribute list
- *
- * @param atradr ACODE address to attribute table
- * @param atr The attribute to read
- */
- Aptr getAttribute(Aaddr atradr, Aaddr atr);
-
- /**
- * Set a particular attribute to a value.
- *
- * @param atradr ACODE address to attribute table
- * @param atr Attribute code
- * @param val New value
- */
- void setAttribute(Aaddr atradr, Aword atr, Aword val);
-
- /**
- * Increment a particular attribute by a value.
- *
- * @param atradr ACODE address to attribute table
- * @param atr Attribute code
- * @param step Step to increment by
- */
- void incAttribute(Aaddr atradr, Aword atr, Aword step);
- void incLocation(Aword loc, Aword atr, Aword step);
- void incObject(Aword obj, Aword atr, Aword step);
- void incract(Aword act, Aword atr, Aword step);
- Aword objloc(Aword obj);
- Aword actloc(Aword act);
- void locobj(Aword obj, Aword whr);
- void locact(Aword act, Aword whr);
- Abool objhere(Aword obj);
- Aword acthere(Aword act);
- Aword objnear(Aword obj);
- Aword actnear(Aword act);
- void sayarticle(Aword id);
- void dscrloc(Aword loc);
- void dscrobj(Aword obj);
- void dscract(Aword act);
-
- /**
- * Description of current location
- */
- void dscrobjs();
-
- void dscracts();
-
- // The event queue
- EvtqElem *eventq; // Event queue
- int etop; // Event queue top pointer
-
- // Amachine data structures
- ActElem *_acts; // Actor table pointer
- LocElem *_locs; // Location table pointer
- ObjElem *_objs; // Object table pointer
- CntElem *_cnts; // Container table pointer
- Common::Stack<Aword> _describeStack;
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/interpreter.cpp b/engines/glk/alan2/interpreter.cpp
deleted file mode 100644
index b8906d2..0000000
--- a/engines/glk/alan2/interpreter.cpp
+++ /dev/null
@@ -1,778 +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/alan2/acode.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/execute.h"
-#include "glk/alan2/interpreter.h"
-#include "glk/alan2/saveload.h"
-#include "glk/alan2/types.h"
-#include "common/debug.h"
-
-namespace Glk {
-namespace Alan2 {
-
-// TODO: Refactor these into debug flags
-const bool trcflg = false;
-const bool stpflg = false;
-
-void Interpreter::if_(Aword v) {
- int lev = 1;
- Aword i;
-
- if (!v) {
- // Skip to next ELSE or ENDIF on same level
- while (true) {
- i = _vm->memory[_vm->pc++];
- if (I_CLASS(i) == (Aword)C_STMOP) {
- switch (I_OP(i)) {
- case I_ELSE:
- if (lev == 1)
- return;
- break;
- case I_IF:
- lev++;
- break;
- case I_ENDIF:
- lev--;
- if (lev == 0)
- return;
- break;
- default:
- break;
- }
- }
- }
- }
-}
-
-void Interpreter::else_() {
- int lev = 1;
- Aword i;
-
- while (true) {
- // Skip to ENDIF on the same level
- i = _vm->memory[_vm->pc++];
- if (I_CLASS(i) == (Aword)C_STMOP) {
- switch (I_OP(i)) {
- case I_ENDIF:
- lev--;
- if (lev == 0)
- return;
- break;
- case I_IF:
- lev++;
- break;
- default:
- break;
- }
- }
- }
-}
-
-void Interpreter::depstart() {
- // A DEPSTART was executed, so skip across the redundant DEPCASE to
- // start at the first expression
- _vm->pc++;
-}
-
-void Interpreter::swap() {
- Aptr v1 = _stack->pop();
- Aptr v2 = _stack->pop();
-
- _stack->push(v1);
- _stack->push(v2);
-}
-
-void Interpreter::depexec(Aword v) {
- int lev = 1;
- Aword i;
-
- if (!v) {
- // The expression was not true, skip to next CASE on the same
- // level which could be a DEPCASE or DEPELSE
- while (true) {
- i = _vm->memory[_vm->pc++];
- if (I_CLASS(i) == (Aword)C_STMOP) {
- switch (I_OP(i)) {
- case I_DEPSTART:
- lev++;
- break;
- case I_DEPEND:
- if (lev == 1)
- return;
- lev--;
- break;
- case I_DEPCASE:
- case I_DEPELSE:
- if (lev == 1)
- return;
- break;
- default:
- break;
- }
- }
- }
- }
-}
-
-void Interpreter::depcase() {
- int lev = 1;
- Aword i;
-
- // Skip to end of DEPENDING block (next DEPEND on same level) because
- // we have just executed a DEPCASE/DEPELSE statement as a result of a DEPCASE
- // catching
-
- while (true) {
- i = _vm->memory[_vm->pc++];
- if (I_CLASS(i) == (Aword)C_STMOP) {
- switch (I_OP(i)) {
- case I_DEPSTART:
- lev++;
- break;
- case I_DEPEND:
- lev--;
- if (lev == 0) return;
- break;
- default:
- break;
- }
- }
- }
-}
-
-void Interpreter::curVar(Aword i) {
- switch (I_OP(i)) {
- case V_PARAM:
- if (stpflg)
- debug("PARAM \t%5ld\t\t(%d)", _stack->top(), _vm->params[_stack->top() - 1].code);
- _stack->push(_vm->params[_stack->pop() - 1].code);
- break;
- case V_CURLOC:
- if (stpflg)
- debug("CURLOC \t\t\t(%d)", _vm->cur.loc);
- _stack->push(_vm->cur.loc);
- break;
- case V_CURACT:
- if (stpflg)
- debug("CURACT \t\t\t(%d)", _vm->cur.act);
- _stack->push(_vm->cur.act);
- break;
- case V_CURVRB:
- if (stpflg)
- debug("CURVRB \t\t\t(%d)", _vm->cur.vrb);
- _stack->push(_vm->cur.vrb);
- break;
- case V_SCORE:
- if (stpflg)
- debug("CURSCORE \t\t\t(%d)", _vm->cur.score);
- _stack->push(_vm->cur.score);
- break;
- default:
- error("Unknown CURVAR instruction.");
- }
-}
-
-void Interpreter::adaptOldOpcodes(Aword i) {
- switch (I_OP(i)) {
- case I_AND:
- case I_OR:
- case I_NE:
- case I_EQ:
- case I_STREQ:
- case I_STREXACT:
- case I_LE:
- case I_GE:
- case I_LT:
- case I_GT:
- case I_PLUS:
- case I_MINUS:
- case I_MULT:
- case I_DIV:
- if (_vm->header->vers[0] == 2 && _vm->header->vers[1] == 7) // Check for 2.7 version
- swap();
- }
-}
-
-void Interpreter::stMop(Aword i, Aaddr oldpc) {
- Aptr arg1, arg2, arg3, lh, rh;
-
- adaptOldOpcodes(i);
-
- switch (I_OP(i)) {
- case I_PRINT:
- arg1 = _stack->pop(); // fpos
- arg2 = _stack->pop(); // len
- if (stpflg) {
- debug("PRINT \t%5ld, %5ld\t\"", arg1, arg2);
- _vm->col = 34; // To format it better!
- }
- _execute->print(arg1, arg2);
- if (stpflg)
- debug("\"");
- break;
- case I_SYSTEM:
- arg1 = _stack->pop(); // fpos
- arg2 = _stack->pop(); // len
- if (stpflg) {
- debug("SYSTEM \t%5ld, %5ld\t\"", arg1, arg2);
- _vm->col = 34; // To format it better!
- }
- _execute->sys(arg1, arg2);
- break;
- case I_GETSTR:
- arg1 = _stack->pop(); // fpos
- arg2 = _stack->pop(); // len
- if (stpflg)
- debug("GETSTR\t%5ld, %5ld", arg1, arg2);
- _execute->getstr(arg1, arg2);
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_QUIT:
- if (stpflg)
- debug("QUIT");
- _execute->quit();
- break;
- case I_LOOK:
- if (stpflg)
- debug("LOOK");
- _execute->look();
- break;
- case I_SAVE:
- if (stpflg)
- debug("SAVE");
- _saveLoad->save();
- break;
- case I_RESTORE:
- if (stpflg)
- debug("RESTORE");
- _saveLoad->restore();
- break;
- case I_RESTART:
- if (stpflg)
- debug("RESTART");
- _execute->restart();
- break;
- case I_LIST:
- arg1 = _stack->pop(); // cnt
- if (stpflg)
- debug("LIST \t%5ld", arg1);
- _execute->list(arg1);
- break;
- case I_EMPTY:
- arg1 = _stack->pop(); // cnt
- arg2 = _stack->pop(); // whr
- if (stpflg)
- debug("EMPTY \t%5ld, %5ld", arg1, arg2);
- _execute->empty(arg1, arg2);
- break;
- case I_SCORE:
- arg1 = _stack->pop(); // score
- if (stpflg)
- debug("SCORE \t%5ld\t\t(%d)", arg1, _vm->scores[arg1 - 1]);
- _execute->score(arg1);
- break;
- case I_VISITS:
- arg1 = _stack->pop(); // visits
- if (stpflg)
- debug("VISITS \t%5ld", arg1);
- _execute->visits(arg1);
- break;
- case I_SCHEDULE:
- arg1 = _stack->pop(); // evt
- arg2 = _stack->pop(); // whr
- arg3 = _stack->pop(); // aft
- if (stpflg)
- debug("SCHEDULE \t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _execute->schedule(arg1, arg2, arg3);
- break;
- case I_CANCEL:
- arg1 = _stack->pop(); // evt
- if (stpflg)
- debug("CANCEL \t%5ld", arg1);
- _execute->cancl(arg1);
- break;
- case I_MAKE:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- arg3 = _stack->pop(); // val
- if (stpflg) {
- debug("MAKE \t%5ld, %5ld, ", arg1, arg2);
- if (arg3)
- debug("TRUE");
- else
- debug("FALSE");
- }
- _execute->make(arg1, arg2, arg3);
- break;
- case I_SET:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- arg3 = _stack->pop(); // val
- if (stpflg)
- debug("SET \t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _execute->set(arg1, arg2, arg3);
- break;
- case I_STRSET:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- arg3 = _stack->pop(); // str
- if (stpflg)
- debug("STRSET\t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _execute->setstr(arg1, arg2, arg3);
- break;
- case I_INCR:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- arg3 = _stack->pop(); // step
- if (stpflg)
- debug("INCR\t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _execute->incr(arg1, arg2, arg3);
- break;
- case I_DECR:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- arg3 = _stack->pop(); // step
- if (stpflg)
- debug("DECR\t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _execute->decr(arg1, arg2, arg3);
- break;
- case I_ATTRIBUTE:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- if (stpflg)
- debug("ATTRIBUTE %5ld, %5ld", arg1, arg2);
- _stack->push(_execute->attribute(arg1, arg2));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_STRATTR:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // atr
- if (stpflg)
- debug("STRATTR \t%5ld, %5ld", arg1, arg2);
- _stack->push(_execute->strattr(arg1, arg2));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_LOCATE:
- arg1 = _stack->pop(); // id
- arg2 = _stack->pop(); // whr
- if (stpflg)
- debug("LOCATE \t%5ld, %5ld", arg1, arg2);
- _execute->locate(arg1, arg2);
- break;
- case I_WHERE:
- arg1 = _stack->pop(); // id
- if (stpflg)
- debug("WHERE \t%5ld", arg1);
- _stack->push(_execute->where(arg1));
- if (stpflg)
- debug("\t\t(%ld)", _stack->top());
- break;
- case I_HERE:
- arg1 = _stack->pop(); // id
- if (stpflg)
- debug("HERE \t%5ld", arg1);
- _stack->push(_execute->isHere(arg1));
- if (stpflg) {
- if (_stack->top())
- debug("\t(TRUE)");
- else
- debug("\t(FALSE)");
- }
- break;
- case I_NEAR:
- arg1 = _stack->pop(); // id
- if (stpflg)
- debug("NEAR \t%5ld", arg1);
- _stack->push(_execute->isNear(arg1));
- if (stpflg) {
- if (_stack->top())
- debug("\t(TRUE)");
- else
- debug("\t(FALSE)");
- }
- break;
- case I_USE:
- arg1 = _stack->pop(); // act
- arg2 = _stack->pop(); // scr
- if (stpflg)
- debug("USE \t%5ld, %5ld", arg1, arg2);
- _execute->use(arg1, arg2);
- break;
- case I_IN:
- arg1 = _stack->pop(); // obj
- arg2 = _stack->pop(); // cnt
- if (stpflg)
- debug("IN \t%5ld, %5ld ", arg1, arg2);
- _stack->push(_execute->in(arg1, arg2));
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_DESCRIBE:
- arg1 = _stack->pop(); // id
- if (stpflg) {
- debug("DESCRIBE \t%5ld\t", arg1);
- _vm->col = 34; // To format it better!
- }
- _execute->describe(arg1);
- break;
- case I_SAY:
- arg1 = _stack->pop(); // id
- if (stpflg)
- debug("SAY \t%5ld\t\t\"", arg1);
- _execute->say(arg1);
- if (stpflg)
- debug("\"");
- break;
- case I_SAYINT:
- arg1 = _stack->pop(); // val
- if (stpflg)
- debug("SAYINT\t%5ld\t\t\"", arg1);
- _execute->sayint(arg1);
- if (stpflg)
- debug("\"");
- break;
- case I_SAYSTR:
- arg1 = _stack->pop(); // adr
- if (stpflg)
- debug("SAYSTR\t%5ld\t\t\"", arg1);
- _execute->saystr((char *)arg1);
- if (stpflg)
- debug("\"");
- break;
- case I_IF:
- arg1 = _stack->pop(); // v
- if (stpflg) {
- debug("IF \t");
- if (arg1) debug(" TRUE"); else debug("FALSE");
- }
- if_(arg1);
- break;
- case I_ELSE:
- if (stpflg)
- debug("ELSE");
- else_();
- break;
- case I_ENDIF:
- if (stpflg)
- debug("ENDIF");
- break;
- case I_AND:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg) {
- debug("AND \t");
- if (lh) debug("TRUE, "); else debug("FALSE, ");
- if (rh) debug("TRUE"); else debug("FALSE");
- }
- _stack->push(lh && rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_OR:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg) {
- debug("OR \t");
- if (lh) debug("TRUE, "); else debug("FALSE, ");
- if (rh) debug("TRUE"); else debug("FALSE");
- }
- _stack->push(lh || rh);
- if (stpflg) {
- if (_stack->top())
- debug("\t(TRUE)");
- else
- debug("\t(FALSE)");
- }
- break;
- case I_NE:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("NE \t%5ld, %5ld", lh, rh);
- _stack->push(lh != rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_EQ:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("EQ \t%5ld, %5ld", lh, rh);
- _stack->push(lh == rh);
- if (stpflg) {
- if (_stack->top())
- debug("\t(TRUE)");
- else
- debug("\t(FALSE)");
- }
- break;
- case I_STREQ:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("STREQ \t%5ld, %5ld", lh, rh);
- _stack->push(_execute->streq((char *)lh, (char *)rh));
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_STREXACT:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("STREXACT \t%5ld, %5ld", lh, rh);
- _stack->push(strcmp((char *)lh, (char *)rh) == 0);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- free((void *)lh);
- free((void *)rh);
- break;
- case I_LE:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("LE \t%5ld, %5ld", lh, rh);
- _stack->push(lh <= rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_GE:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("GE \t%5ld, %5ld", lh, rh);
- _stack->push(lh >= rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_LT:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("LT \t%5ld, %5ld", lh, rh);
- _stack->push((signed int)lh < (signed int)rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_GT:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("GT \t%5ld, %5ld", lh, rh);
- _stack->push(lh > rh);
- if (stpflg) {
- if (_stack->top()) debug("\t(TRUE)"); else debug("\t(FALSE)");
- }
- break;
- case I_PLUS:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("PLUS \t%5ld, %5ld", lh, rh);
- _stack->push(lh + rh);
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_MINUS:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("MINUS \t%5ld, %5ld", lh, rh);
- _stack->push(lh - rh);
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_MULT:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("MULT \t%5ld, %5ld", lh, rh);
- _stack->push(lh * rh);
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_DIV:
- rh = _stack->pop();
- lh = _stack->pop();
- if (stpflg)
- debug("DIV \t%5ld, %5ld", lh, rh);
- _stack->push(lh / rh);
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_NOT:
- arg1 = _stack->pop(); // val
- if (stpflg) {
- debug("NOT \t");
- if (arg1) debug("TRUE"); else debug("FALSE");
- }
- _stack->push(!arg1);
- if (stpflg) {
- if (_stack->top()) debug("\t\t(TRUE)"); else debug("\t\t(FALSE)");
- }
- break;
- case I_MAX:
- arg1 = _stack->pop(); // atr
- arg2 = _stack->pop(); // whr
- if (stpflg)
- debug("MAX \t%5ld, %5ld", arg1, arg2);
- _stack->push(_execute->agrmax(arg1, arg2));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_SUM:
- arg1 = _stack->pop(); // atr
- arg2 = _stack->pop(); // whr
- if (stpflg)
- debug("SUM \t%5ld, %5ld", arg1, arg2);
- _stack->push(_execute->agrsum(arg1, arg2));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_COUNT:
- arg1 = _stack->pop(); // whr
- if (stpflg)
- debug("COUNT \t%5ld", arg1);
- _stack->push(_execute->agrcount(arg1));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_RND:
- arg1 = _stack->pop(); // from
- arg2 = _stack->pop(); // to
- if (stpflg)
- debug("RANDOM \t%5ld, %5ld", arg1, arg2);
- _stack->push(_execute->rnd(arg1, arg2));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_BTW:
- arg1 = _stack->pop(); // high
- arg2 = _stack->pop(); // low
- arg3 = _stack->pop(); // val
- if (stpflg)
- debug("BETWEEN \t%5ld, %5ld, %5ld", arg1, arg2, arg3);
- _stack->push(_execute->btw(arg1, arg2, arg3));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_CONTAINS:
- arg1 = _stack->pop(); // substring
- arg2 = _stack->pop(); // string
- if (stpflg)
- debug("CONTAINS \t%5ld, %5ld", arg2, arg1);
- _stack->push(_execute->contains(arg2, arg1));
- if (stpflg)
- debug("\t(%ld)", _stack->top());
- break;
- case I_DEPSTART:
- if (stpflg)
- debug("DEPSTART");
- depstart();
- break;
- case I_DEPCASE:
- if (stpflg)
- debug("DEPCASE");
- depcase();
- break;
- case I_DEPEXEC:
- arg1 = _stack->pop(); // v
- if (stpflg) {
- debug("DEPEXEC \t");
- if (arg1) debug(" TRUE"); else debug("FALSE");
- }
- depexec(arg1);
- break;
- case I_DEPELSE:
- if (stpflg)
- debug("DEPELSE");
- depcase();
- break;
- case I_DEPEND:
- if (stpflg)
- debug("DEPEND");
- break;
- case I_RETURN:
- if (stpflg)
- debug("RETURN\n--------------------------------------------------\n");
- _vm->pc = oldpc;
- return;
- default:
- error("Unknown STMOP instruction.");
- }
-
- if (_vm->fail) {
- _vm->pc = oldpc;
- return; // TODO: Return true/false, and stop execution if necessary
- }
-}
-
-void Interpreter::interpret(Aaddr adr) {
- Aaddr oldpc = _vm->pc;
- Aword i;
-
- if (stpflg)
- debug("\n++++++++++++++++++++++++++++++++++++++++++++++++++");
-
- _vm->pc = adr;
-
- while(true) {
- if (stpflg)
- debug("\n%4x: ", _vm->pc);
-
- if (_vm->pc > _vm->memTop)
- error("Interpreting outside program.");
-
- i = _vm->memory[_vm->pc++];
-
- switch (I_CLASS(i)) {
- case C_CONST:
- if (stpflg)
- debug("PUSH \t%5d", I_OP(i));
- _stack->push(I_OP(i));
- break;
- case C_CURVAR:
- curVar(i);
- break;
- case C_STMOP:
- stMop(i, oldpc);
- break;
- default:
- error("Unknown instruction class.");
- }
- }
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/interpreter.h b/engines/glk/alan2/interpreter.h
deleted file mode 100644
index cbc9bcb..0000000
--- a/engines/glk/alan2/interpreter.h
+++ /dev/null
@@ -1,59 +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 GLK_ALAN2_INTERPRETER
-#define GLK_ALAN2_INTERPRETER
-
-#include "glk/alan2/acode.h"
-#include "glk/alan2/alan2.h"
-
-namespace Glk {
-namespace Alan2 {
-
-class Execute;
-class SaveLoad;
-
-class Interpreter {
-public:
- Interpreter(Execute *execute, SaveLoad *saveLoad, Alan2Stack *stack) : _execute(execute), _saveLoad(saveLoad), _stack(stack) {}
- void interpret(Aaddr adr);
-
-private:
- void if_(Aword v);
- void else_();
- void depstart();
- void swap();
- void depexec(Aword v);
- void depcase();
- void curVar(Aword i);
- void stMop(Aword i, Aaddr oldpc);
- void adaptOldOpcodes(Aword i);
-
- Execute *_execute;
- SaveLoad *_saveLoad;
- Alan2Stack *_stack;
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
deleted file mode 100644
index 8e6427d..0000000
--- a/engines/glk/alan2/parse.cpp
+++ /dev/null
@@ -1,969 +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 "common/stack.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/execute.h"
-#include "glk/alan2/interpreter.h"
-#include "glk/alan2/parse.h"
-#include "glk/alan2/types.h"
-#include "glk/alan2/util.h"
-#include "common/debug.h"
-#include "common/file.h"
-#include "decode.h"
-
-namespace Glk {
-namespace Alan2 {
-
-uint32 litCount = 0;
-
-// All procedures for getting a command and turning it into a list of
-// dictionary entries are placed here.
-
-Parser::Parser() {
- wrds[0] = EOF;
- plural = false;
-
- // TODO
-}
-
-void Parser::unknown(char *inputStr) {
- Common::String str = Common::String::format("'%s'?", inputStr);
-
- // TODO
-#if 0
-#if ISO == 0
- fromIso(str, str);
-#endif
-#endif
-
- _vm->output(str);
- eol = true;
- _vm->printError(M_UNKNOWN_WORD);
-}
-
-int Parser::lookup(char *wrd) {
- for (int i = 0; !endOfTable(&dict[i]); i++) {
- if (strcmp(wrd, (char *)addrTo(dict[i].wrd)) == 0)
- return i;
- }
-
- unknown(wrd);
- return EOF;
-}
-
-char *Parser::gettoken(char *tokenBuffer) {
- static char *marker;
- static char oldch;
-
- if (tokenBuffer == nullptr)
- *marker = oldch;
- else
- marker = tokenBuffer;
-
- while (*marker != '\0' && Common::isSpace(*marker) && *marker != '\n') marker++;
- tokenBuffer = marker;
-
- if (Common::isAlpha(*marker))
- while (*marker && (Common::isAlpha(*marker) || Common::isDigit(*marker) || *marker == '\'')) marker++;
- else if (Common::isDigit(*marker))
- while (Common::isDigit(*marker)) marker++;
- else if (*marker == '\"') {
- marker++;
- while (*marker != '\"') marker++;
- marker++;
- } else if (*marker == '\0' || *marker == '\n')
- return nullptr;
- else
- marker++;
-
- oldch = *marker;
- *marker = '\0';
-
- return tokenBuffer;
-}
-
-void Parser::agetline() {
- // static char buf[LISTLEN + 1]; // The input buffer
- // static char isobuf[LISTLEN + 1]; // The input buffer in ISO
-
- _vm->paragraph();
-
- // TODO
-#if 0
-
- do {
-#if defined(HAVE_ANSI) || defined(GLK)
- statusline();
-#endif
- debug("> ");
-
-#if 0
- if (logflg)
- fprintf(logfil, "> ");
-#endif
-
-#ifdef USE_READLINE
- if (!readline(buf)) {
- newline();
- quit();
- }
-#else
- if (fgets(buf, LISTLEN, stdin) == nullptr) {
- newline();
- quit();
- }
-#endif
-
- getPageSize();
- anyOutput = FALSE;
-
- if (logflg)
- fprintf(logfil, "%s\n", buf);
-
-#if ISO == 0
- toIso(isobuf, buf, NATIVECHARSET);
-#else
- strcpy(isobuf, buf);
-#endif
-
- token = gettoken(isobuf);
-
- if (token != nullptr && strcmp("debug", token) == 0 && _vm->header->debug) {
- dbgflg = true;
- debug();
- token = nullptr;
- }
- } while (token == nullptr);
-
- eol = false;
- lin = 1;
-
-#endif
-}
-
-void Parser::scan() {
- uint i;
- // int w;
-
- agetline();
- wrds[0] = 0;
-
- for (i = 0; i < litCount; i++)
- if (litValues[i].type == TYPSTR && litValues[i].value != 0)
- free((char *) litValues[i].value);
-
- litCount = 0;
-
- do {
- if (Common::isAlpha(token[0])) {
- Common::String tmp = token;
- tmp.toLowercase();
- strcpy(token, tmp.c_str());
-
- // w = lookup(token);
-
- // TODO
- //if (!isNoise(w))
- // wrds[i++] = w;
- } else if (Common::isDigit(token[0])) {
- if (litCount > MAXPARAMS)
- error("Too many parameters.");
-
- wrds[i++] = dictsize + litCount; // Word outside dictionary = literal
- litValues[litCount].type = TYPNUM;
- litValues[litCount++].value = atoi(token);
- } else if (token[0] == '\"') {
- if (litCount > MAXPARAMS)
- error("Too many parameters.");
-
- wrds[i++] = dictsize + litCount; // Word outside dictionary = literal
- litValues[litCount].type = TYPSTR;
-
- // Remove the string quotes while copying
- Common::String tmp = token;
- tmp.deleteChar(0);
- tmp.deleteLastChar();
- char *str = scumm_strdup(tmp.c_str());
-
- litValues[litCount++].value = (Aptr) str;
- } else if (token[0] == ',') {
- //wrds[i++] = conjWord; // TODO
- } else
- unknown(token);
-
- wrds[i] = EOF;
- eol = (token = gettoken(nullptr)) == nullptr;
- } while (!eol);
-}
-
-void Parser::nonverb() {
- if (isDir(wrds[wrdidx])) {
- wrdidx++;
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
- _vm->printError(M_WHAT);
-// TODO
-#if 0
- else
- go(dict[wrds[wrdidx-1]].code);
-#endif
-
- if (wrds[wrdidx] != EOF)
- wrdidx++;
- } else
- _vm->printError(M_WHAT);
-}
-
-Aword Parser::where(Aword id) {
- if (isObj(id))
- return objloc(id);
- else if (isAct(id))
- return acts[id - ACTMIN].loc;
- else
- error("Can't WHERE item (%ld).", (unsigned long)id);
-}
-
-Aword Parser::objloc(Aword obj) {
- if (isCnt(objs[obj - OBJMIN].loc)) // In something ?
- if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
- return where(objs[obj - OBJMIN].loc);
- else // Containers not anywhere is where the hero is!
- return where(HERO);
- else
- return(objs[obj - OBJMIN].loc);
-}
-
-Abool Parser::objhere(Aword obj) {
- if (isCnt(objs[obj - OBJMIN].loc)) { // In something?
- if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
- return isHere(objs[obj - OBJMIN].loc);
- else // If the container wasn't anywhere, assume where HERO is!
- return (int)where(HERO) == _vm->cur.loc;
- } else
- return((int)objs[obj - OBJMIN].loc == _vm->cur.loc);
-}
-
-
-Abool Parser::isHere(Aword id) {
- if (isObj(id))
- return objhere(id);
- else if (isAct(id))
- return (int)acts[id - ACTMIN].loc == _vm->cur.loc;
- else
- error("Can't HERE item (%ld).", (unsigned long)id);
-}
-
-// ----------------------------------------------------------------------------
-
-void Parser::buildall(ParamElem list[]) {
- uint o, i = 0;
- bool found = false;
-
- for (o = OBJMIN; o <= OBJMAX; o++) {
- if (isHere(o)) {
- found = true;
- list[i].code = o;
- list[i++].firstWord = (Aword)EOF;
- }
- }
-
- if (!found)
- _vm->printError(M_WHAT_ALL);
- else
- list[i].code = (Aword)EOF;
-}
-
-void Parser::listCopy(ParamElem a[], ParamElem b[]) {
- int i;
-
- for (i = 0; b[i].code != (Aword)EOF; i++)
- a[i] = b[i];
-
- a[i].code = (Aword)EOF;
-}
-
-bool Parser::listContains(ParamElem l[], Aword e) {
- int i;
-
- for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
-
- return (l[i].code == e);
-}
-
-void Parser::listIntersection(ParamElem a[], ParamElem b[]) {
- int i, last = 0;
-
- for (i = 0; a[i].code != (Aword)EOF; i++)
- if (listContains(b, a[i].code))
- a[last++] = a[i];
-
- a[last].code = (Aword)EOF;
-}
-
-void Parser::listCopyFromDictionary(ParamElem p[], Aword r[]) {
- int i;
-
- for (i = 0; r[i] != (Aword)EOF; i++) {
- p[i].code = r[i];
- p[i].firstWord = (Aword)EOF;
- }
-
- p[i].code = (Aword)EOF;
-}
-
-int Parser::listLength(ParamElem a[]) {
- int i = 0;
-
- while (a[i].code != (Aword)EOF)
- i++;
-
- return (i);
-}
-
-void Parser::listCompact(ParamElem a[]) {
- int i, j;
-
- for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
- if (a[j].code != 0)
- a[i++] = a[j];
-
- a[i].code = (Aword)EOF;
-}
-
-void Parser::listMerge(ParamElem a[], ParamElem b[]) {
- int i, last;
-
- for (last = 0; a[last].code != (Aword)EOF; last++); // Find end of list
-
- for (i = 0; b[i].code != (Aword)EOF; i++) {
- if (!listContains(a, b[i].code)) {
- a[last++] = b[i];
- a[last].code = (Aword)EOF;
- }
- }
-}
-
-void Parser::listSubtract(ParamElem a[], ParamElem b[]) {
- for (int i = 0; a[i].code != (Aword)EOF; i++)
- if (listContains(b, a[i].code))
- a[i].code = 0; // Mark empty
-
- listCompact(a);
-}
-
-void Parser::unambig(ParamElem plst[]) {
- int i;
- bool found = false; // Adjective or noun found?
- static ParamElem *refs; // Entities referenced by word
- static ParamElem *savlst; // Saved list for backup at EOF
- int firstWord, lastWord; // The words the player used
-
- if (refs == nullptr)
- refs = new ParamElem[MAXENTITY + 1];
-
- if (savlst == nullptr)
- savlst = new ParamElem[MAXENTITY + 1];
-
- if (isLiteral(wrds[wrdidx])) {
- // Transform the word into a reference to the literal value
- plst[0].code = wrds[wrdidx++] - dictsize + LITMIN;
- plst[0].firstWord = (Aword)EOF; // No words used!
- plst[1].code = (Aword)EOF;
- return;
- }
-
- plst[0].code = (Aword)EOF; // Make empty
-
- if (isIt(wrds[wrdidx])) {
- wrdidx++;
-
- // Use last object in previous command!
- for (i = listLength(pparams)-1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--);
-
- if (i < 0)
- _vm->printError(M_WHAT_IT);
-
- if (!isHere(pparams[i].code)) {
- params[0].code = pparams[i].code;
- params[0].firstWord = (Aword)EOF;
- params[1].code = (Aword)EOF;
- _vm->printError(M_NO_SUCH);
- }
-
- plst[0] = pparams[i];
- plst[0].firstWord = (Aword)EOF; // No words used!
- plst[1].code = (Aword)EOF;
- return;
- }
-
- firstWord = wrdidx;
-
- while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) {
- // If this word can be a noun and there is no noun following break loop
- if (isNoun(wrds[wrdidx]) && (wrds[wrdidx+1] == EOF || !isNoun(wrds[wrdidx+1])))
- break;
-
- listCopyFromDictionary(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs));
- listCopy(savlst, plst); // To save it for backtracking
-
- if (found)
- listIntersection(plst, refs);
- else {
- listCopy(plst, refs);
- found = true;
- }
-
- wrdidx++;
- }
-
- if (wrds[wrdidx] != EOF) {
- if (isNoun(wrds[wrdidx])) {
- listCopyFromDictionary(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs));
- if (found)
- listIntersection(plst, refs);
- else {
- listCopy(plst, refs);
- found = true;
- }
-
- wrdidx++;
- } else
- _vm->printError(M_NOUN);
- } else if (found) {
- if (isNoun(wrds[wrdidx-1])) {
- // Perhaps the last word was also a noun?
- listCopy(plst, savlst); // Restore to before last adjective
- listCopyFromDictionary(refs, (Aword *)addrTo(dict[wrds[wrdidx-1]].nounrefs));
-
- if (plst[0].code == (Aword)EOF)
- listCopy(plst, refs);
- else
- listIntersection(plst, refs);
- } else
- _vm->printError(M_NOUN);
- }
-
- lastWord = wrdidx - 1;
-
- // Allow remote objects, but resolve ambiguities by presence
- if (listLength(plst) > 1) {
- for (i=0; plst[i].code != (Aword)EOF; i++)
- if (!isHere(plst[i].code))
- plst[i].code = 0;
-
- listCompact(plst);
- }
-
- if (listLength(plst) > 1 || (found && listLength(plst) == 0)) {
- params[0].code = 0; /* Just make it anything != EOF */
- params[0].firstWord = firstWord; /* Remember words for errors below */
- params[0].lastWord = lastWord;
- params[1].code = (Aword)EOF; /* But be sure to terminate */
-
- if (listLength(plst) > 1)
- _vm->printError(M_WHICH_ONE);
- else if (found && listLength(plst) == 0)
- _vm->printError(M_NO_SUCH);
- } else {
- plst[0].firstWord = firstWord;
- plst[0].lastWord = lastWord;
- }
-}
-
-void Parser::simple(ParamElem olst[]) {
- static ParamElem *tlst = nullptr;
- int savidx = wrdidx;
- bool savplur = false;
- int i;
-
- if (tlst == nullptr)
- tlst = new ParamElem[MAXENTITY + 1];
-
- tlst[0].code = (Aword)EOF;
-
- for (;;) {
- if (isThem(wrds[wrdidx])) {
- plural = true;
-
- for (i = 0; pmlst[i].code != (Aword)EOF; i++)
- if (!isHere(pmlst[i].code))
- pmlst[i].code = 0;
-
- listCompact(pmlst);
-
- if (listLength(pmlst) == 0)
- _vm->printError(M_WHAT_THEM);
-
- listCopy(olst, pmlst);
- olst[0].firstWord = (Aword)EOF; // No words used
- wrdidx++;
- } else {
- unambig(olst); // Look for unambigous noun phrase
-
- if (listLength(olst) == 0) { // Failed!
- listCopy(olst, tlst);
- wrdidx = savidx;
- plural = savplur;
- return;
- }
- }
-
- listMerge(tlst, olst);
-
- if (wrds[wrdidx] != EOF
- && (isConj(wrds[wrdidx])
- && (isAdj(wrds[wrdidx+1]) || isNoun(wrds[wrdidx+1])))) {
- // More parameters in a conjunction separated list ?
- savplur = plural;
- savidx = wrdidx;
- wrdidx++;
- plural = true;
- } else {
- listCopy(olst, tlst);
- return;
- }
- }
-}
-
-void Parser::complex(ParamElem olst[]) {
- // Above this procedure we can use the is* tests, but not below since
- // they work on words.Below all is converted to indices into the
- // entity tables.Particularly this goes for literals...
-
- static ParamElem *alst = nullptr;
-
- if (alst == nullptr)
- alst = new ParamElem[MAXENTITY + 1];
-
- if (isAll(wrds[wrdidx])) {
- plural = true;
- buildall(alst); // Build list of all objects
- wrdidx++;
- if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) {
- wrdidx++;
- simple(olst);
-
- if (listLength(olst) == 0)
- _vm->printError(M_AFTER_BUT);
-
- listSubtract(alst, olst);
- if (listLength(alst) == 0)
- _vm->printError(M_NOT_MUCH);
- }
-
- listCopy(olst, alst);
- allLength = listLength(olst);
- } else
- simple(olst); // Look for simple noun group
-}
-
-bool Parser::claCheck(ClaElem *cla) {
- bool ok = false;
-
- if ((cla->classes & (Aword)CLA_OBJ) != 0)
- ok = ok || isObj(params[cla->code - 1].code);
- if ((cla->classes & (Aword)CLA_CNT) != 0)
- ok = ok || isCnt(params[cla->code - 1].code);
- if ((cla->classes & (Aword)CLA_ACT) != 0)
- ok = ok || isAct(params[cla->code - 1].code);
- if ((cla->classes & (Aword)CLA_NUM) != 0)
- ok = ok || isNum(params[cla->code - 1].code);
- if ((cla->classes & (Aword)CLA_STR) != 0)
- ok = ok || isStr(params[cla->code - 1].code);
- if ((cla->classes & (Aword)CLA_COBJ) != 0)
- ok = ok || (isCnt(params[cla->code - 1].code) && isObj(params[cla->code - 1].code));
- if ((cla->classes & (Aword)CLA_CACT) != 0)
- ok = ok || (isCnt(params[cla->code - 1].code) && isAct(params[cla->code - 1].code));
-
- return ok;
-}
-
-void Parser::resolve(ParamElem plst[]) {
- if (allLength > 0)
- return; // ALL has already done this
-
- // Resolve ambiguities by presence
- for (int i = 0; plst[i].code != (Aword)EOF; i++) {
- if (plst[i].code < LITMIN) { // Literals are always 'here'
- if (!isHere(plst[i].code)) {
- params[0] = plst[i]; // Copy error param as first one for message
- params[1].code = (Aword)EOF; // But be sure to terminate
- _vm->printError(M_NO_SUCH);
- }
- }
- }
-}
-
-bool Parser::endOfTable(StxElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(ElmElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(ClaElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(VrbElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(AltElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(ChkElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-bool Parser::endOfTable(WrdElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-AltElem *Parser::findalt(Aword vrbsadr, Aword param) {
- VrbElem *vrb;
- AltElem *alt;
-
- if (vrbsadr == 0)
- return nullptr;
-
- for (vrb = (VrbElem *)addrTo(vrbsadr); !endOfTable(vrb); vrb++) {
- if ((int)vrb->code == _vm->cur.vrb) {
- for (alt = (AltElem *)addrTo(vrb->alts); !endOfTable(alt); alt++)
- if (alt->param == param || alt->param == 0)
- return alt;
- return nullptr;
- }
- }
-
- return nullptr;
-}
-
-bool Parser::trycheck(Aaddr adr, bool act) {
- ChkElem *chk = (ChkElem *)addrTo(adr);
-
- if (chk->exp == 0) {
- _vm->_interpreter->interpret(chk->stms);
- return false;
- } else {
- while (!endOfTable(chk)) {
- _vm->_interpreter->interpret(chk->exp);
- if (!(Abool)_vm->_stack->pop()) {
- if (act)
- _vm->_interpreter->interpret(chk->stms);
- return false;
- }
- chk++;
- }
- return true;
- }
-}
-
-bool Parser::possible() {
- AltElem *alt[MAXPARAMS + 2]; // List of alt-pointers, one for each param
- int i; // Parameter index
-
- _vm->fail = false;
- alt[0] = findalt(_vm->header->vrbs, 0);
-
- // Perform global checks
- if (alt[0] != 0 && alt[0]->checks != 0) {
- if (!trycheck(alt[0]->checks, false))
- return false;
- if (_vm->fail)
- return false;
- }
-
- // Now CHECKs in this location
- alt[1] = findalt(locs[_vm->cur.loc - LOCMIN].vrbs, 0);
- if (alt[1] != 0 && alt[1]->checks != 0)
- if (!trycheck(alt[1]->checks, false))
- return false;
-
- for (i = 0; params[i].code != (Aword)EOF; i++) {
- alt[i + 2] = findalt(objs[params[i].code - OBJMIN].vrbs, i + 1);
- // CHECKs in a possible parameter
- if (alt[i + 2] != 0 && alt[i + 2]->checks != 0)
- if (!trycheck(alt[i + 2]->checks, false))
- return false;
- }
-
- for (i = 0; i < 2 || params[i - 2].code != (Aword)EOF; i++)
- if (alt[i] != 0 && alt[i]->action != 0)
- break;
- if (i >= 2 && params[i - 2].code == (Aword)EOF)
- // Didn't find any code for this verb/object combination
- return false;
- else
- return true;
-}
-
-void Parser::tryMatch(ParamElem mlstArr[]) {
- ElmElem *elms; // Pointer to element list
- StxElem *stx; // Pointer to syntax list
- ClaElem *cla; // Pointer to class definitions
- bool anyPlural = false; // Any parameter that was plural?
- int i, p;
- static ParamElem *tlst = nullptr; // List of params found by complex()
- static bool *checked = nullptr; // Corresponding parameter checked?
-
- if (tlst == nullptr) {
- tlst = new ParamElem[MAXENTITY + 1];
- checked = new bool[MAXENTITY + 1];
- }
-
- for (stx = stxs; !endOfTable(stx); stx++)
- if ((int)stx->code == vrbcode)
- break;
-
- if (endOfTable(stx))
- _vm->printError(M_WHAT);
-
- elms = (ElmElem *) addrTo(stx->elms);
-
- while (true) {
- // End of input?
- if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) {
- while (!endOfTable(elms) && elms->code != (Aword)EOS)
- elms++;
-
- if (endOfTable(elms))
- _vm->printError(M_WHAT);
- else
- break;
- } else {
- // A preposition?
- if (isPrep(wrds[wrdidx])) {
- while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code)
- elms++;
-
- if (endOfTable(elms))
- _vm->printError(M_WHAT);
- else
- wrdidx++;
- } else {
- // Must be a parameter!
- while (!endOfTable(elms) && elms->code != 0)
- elms++;
-
- if (endOfTable(elms))
- _vm->printError(M_WHAT);
-
- // Get it!
- plural = false;
- complex(tlst);
-
- if (listLength(tlst) == 0) // No object!?
- _vm->printError(M_WHAT);
-
- if ((elms->flags & OMNIBIT) == 0) // Omnipotent parameter?
- resolve(tlst); // If its not an omnipotent parameter, resolve by presence
-
- if (plural) {
- if ((elms->flags & MULTIPLEBIT) == 0) // Allowed multiple?
- _vm->printError(M_MULTIPLE);
- else {
- // Mark this as the multiple position in which to insert
- // actual parameter values later
- params[paramidx++].code = 0;
- listCopy(mlstArr, tlst);
- anyPlural = true;
- }
- } else
- params[paramidx++] = tlst[0];
-
- params[paramidx].code = (Aword)EOF;
- }
-
- elms = (ElmElem *) addrTo(elms->next);
- }
- }
-
- // Now perform class checks
- if (elms->next == 0) // No verb code, verb not declared!
- _vm->printError(M_CANT0);
-
- for (p = 0; params[p].code != (Aword)EOF; p++) /* Mark all parameters unchecked */
- checked[p] = false;
-
- for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
- if (params[cla->code - 1].code == 0) {
- // This was a multiple parameter, so check all and remove failing
- for (i = 0; mlstArr[i].code != (Aword)EOF; i++) {
- params[cla->code-1] = mlstArr[i];
- if (!claCheck(cla)) {
- // Multiple could be both an explicit list of params and an ALL
- if (allLength == 0) {
- char marker[80];
- // It wasn't ALL, we need to say something about it, so
- // prepare a printout with $1/2/3
- sprintf(marker, "($%ld)", (unsigned long) cla->code);
- _vm->output(marker);
- _vm->_interpreter->interpret(cla->stms);
- _vm->paragraph();
- }
-
- mlstArr[i].code = 0; // In any case remove it from the list
- }
- }
-
- params[cla->code - 1].code = 0;
- } else {
- if (!claCheck(cla)) {
- _vm->_interpreter->interpret(cla->stms);
- _vm->printError(MSGMAX); // Return to player without saying anything
- }
- }
-
- checked[cla->code - 1] = true; // Remember that it's already checked
- }
-
- // Now check the rest of the parameters, must be objects
- for (p = 0; params[p].code != (Aword)EOF; p++) {
- if (!checked[p]) {
- if (params[p].code == 0) {
- // This was a multiple parameter, check all and remove failing
- for (i = 0; mlstArr[i].code != (Aword)EOF; i++) {
- if (mlstArr[i].code != 0 && !isObj(mlstArr[i].code)) // Skip any empty slots
- mlstArr[i].code = 0;
- }
- } else if (!isObj(params[p].code))
- _vm->printError(M_CANT0);
- }
- }
-
- // Set verb code
- _vm->cur.vrb = ((Aword *) cla)[1]; // Take first word after end of table!
-
- // Finally, if ALL was used, try to find out what was applicable
- if (allLength > 0) {
- for (p = 0; params[p].code != 0; p++); // Find multiple marker
-
- for (i = 0; i < allLength; i++) {
- if (mlstArr[i].code != 0) { // Already empty?
- params[p] = mlstArr[i];
-
- if (!possible())
- mlstArr[i].code = 0; // Remove this from list
- }
- }
-
- params[p].code = 0; // Restore multiple marker
- listCompact(mlstArr);
-
- if (listLength(mlstArr) == 0) {
- params[0].code = (Aword)EOF;
- _vm->printError(M_WHAT_ALL);
- }
- } else if (anyPlural) {
- listCompact(mlstArr);
-
- // If there where multiple parameters but non left, exit without a
- // word, assuming we have already said enough
- if (listLength(mlstArr) == 0)
- _vm->printError(MSGMAX);
- }
-
- plural = anyPlural; // Remember that we found plural objects
-}
-
-void Parser::match(ParamElem *mlstArr) {
- tryMatch(mlstArr); // try to understand what the user said
-
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
- _vm->printError(M_WHAT);
- if (wrds[wrdidx] != EOF) // More on this line?
- wrdidx++; // If so skip the AND
-}
-
-void Parser::action(ParamElem plst[]) {
- int i, mpos;
- char marker[10];
-
- if (plural) {
- // The code == 0 means this is a multiple position. We must loop
- // over this position (and replace it by each present in the plst)
- for (mpos = 0; params[mpos].code != 0; mpos++); // Find multiple position
-
- sprintf(marker, "($%d)", mpos + 1); // Prepare a printout with $1/2/3
-
- for (i = 0; plst[i].code != (Aword)EOF; i++) {
- params[mpos] = plst[i];
- _vm->output(marker);
- //do_it(); // TODO
-
- if (plst[i + 1].code != (Aword)EOF)
- _vm->paragraph();
- }
-
- params[mpos].code = 0;
- } //else // TODO
- //do_it();
-}
-
-void Parser::parse() {
- if (mlst == nullptr) { // Allocate large enough paramlists
- mlst = new ParamElem[MAXENTITY + 1];
- mlst[0].code = (Aword)EOF;
- pmlst = new ParamElem[MAXENTITY + 1];
- params = new ParamElem[MAXENTITY + 1];
- params[0].code = (Aword)EOF;
- pparams = new ParamElem[MAXENTITY + 1];
- }
-
- if (wrds[wrdidx] == EOF) {
- wrdidx = 0;
- scan();
- } else if (false/*anyOutput*/) // TODO
- _vm->paragraph();
-
- allLength = 0;
- paramidx = 0;
- listCopy(pparams, params);
- params[0].code = (Aword)EOF;
- listCopy(pmlst, mlst);
- mlst[0].code = (Aword)EOF;
-
- if (isVerb(wrds[wrdidx])) {
- vrbwrd = wrds[wrdidx];
- vrbcode = dict[vrbwrd].code;
- wrdidx++;
- match(mlst);
- action(mlst); // mlst contains possible multiple params
- } else {
- params[0].code = (Aword)EOF;
- pmlst[0].code = (Aword)EOF;
- nonverb();
- }
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
deleted file mode 100644
index c5b223b..0000000
--- a/engines/glk/alan2/parse.h
+++ /dev/null
@@ -1,185 +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 GLK_ALAN2_PARSE
-#define GLK_ALAN2_PARSE
-
-namespace Glk {
-namespace Alan2 {
-
-#define LISTLEN 100
-
-class Parser {
-public:
- Parser();
-
- /**
- * Parse a new player command
- */
- void parse();
-
-private:
- void unknown(char *inputStr);
- int lookup(char *wrd);
- char *gettoken(char *tokenBuffer);
- void agetline();
- void scan();
-
- /**
- * Search for a non-verb command
- */
- void nonverb();
-
- Abool objhere(Aword obj);
- Aword objloc(Aword obj);
- Abool isHere(Aword id);
- Aword where(Aword id);
-
- /**
- * Build a list of objects matching 'all'
- */
- void buildall(ParamElem list[]);
-
- void listCopy(ParamElem a[], ParamElem b[]);
- bool listContains(ParamElem l[], Aword e);
- void listIntersection(ParamElem a[], ParamElem b[]);
-
- /**
- * Copy the refs (in dictionary) to a paramList
- */
- void listCopyFromDictionary(ParamElem p[], Aword r[]);
-
- int listLength(ParamElem a[]);
-
- /**
- * Compact a list, i.e remove any nullptr elements
- */
- void listCompact(ParamElem a[]);
-
- /**
- * Merge the paramElems of one list into the first
- */
- void listMerge(ParamElem a[], ParamElem b[]);
-
- /**
- * Subtract two lists
- */
- void listSubtract(ParamElem a[], ParamElem b[]);
-
- /**
- * Match an unambigous object reference
- */
- void unambig(ParamElem plst[]);
-
- /**
- * Match a simple verb command
- */
- void simple(ParamElem olst[]);
-
- /**
- * Match a complex verb command
- */
- void complex(ParamElem olst[]);
-
- bool claCheck(ClaElem *cla);
-
- /**
- * In case the syntax did not indicate omnipotent powers (allowed
- * access to remote object), we need to remove non - present parameters
- */
- void resolve(ParamElem plst[]);
-
- bool endOfTable(StxElem *addr);
- bool endOfTable(ElmElem *addr);
- bool endOfTable(ClaElem *addr);
- bool endOfTable(VrbElem *addr);
- bool endOfTable(AltElem *addr);
- bool endOfTable(ChkElem *addr);
- bool endOfTable(WrdElem *addr);
-
- /**
- * Find the verb alternative wanted in a verb list and return
- * the address to it.
- *
- * @param vrbsadr Address to start of list
- * @param param Which parameter to match
- */
- AltElem *findalt(Aword vrbsadr, Aword param);
-
- /**
- * Tries a check, returns TRUE if it passed, FALSE otherwise
- *
- * @param adr ACODE address to check table
- * @param act Act if it fails?
- */
- bool trycheck(Aaddr adr, bool act);
-
- /**
- * Check if current action is possible according to the CHECKs.
- */
- bool possible();
-
- void tryMatch(ParamElem mlstArr[]);
- void match(ParamElem *mlstArr);
-
- /**
- * Execute all activities commanded. Handles possible multiple actions
- * such as THEM or lists of objects.
- */
- void action(ParamElem plst[]);
-
- // TODO: Initialize / move these
- int wrds[LISTLEN / 2]; // List of parsed words
- int wrdidx; // and an index into it
-
- bool plural;
-
- // Syntax Parameters
- int paramidx; // Index in params
- ParamElem *params; // List of params
- static ParamElem *pparams; // Previous parameter list
- static ParamElem *mlst; // Multiple objects list
- static ParamElem *pmlst; // Previous multiple list
-
- StxElem *stxs; // Syntax table pointer
- LocElem *locs; // Location table pointer
-
- // Literals
- LitElem litValues[MAXPARAMS + 1];
-
- // What did the user say?
- int vrbwrd; // The word he used
- int vrbcode; // The code for that verb
-
- bool eol; // Looking at End of line? Yes, initially
- char *token;
-
- WrdElem *dict; // Dictionary pointer
- int dictsize;
-
- int allLength; // No. of objects matching 'all'
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
deleted file mode 100644
index 973bd23..0000000
--- a/engines/glk/alan2/rules.cpp
+++ /dev/null
@@ -1,88 +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/alan2/acode.h"
-#include "glk/alan2/interpreter.h"
-#include "glk/alan2/rules.h"
-#include "glk/alan2/types.h"
-#include "common/debug.h"
-
-namespace Glk {
-namespace Alan2 {
-
-// TODO: Refactor these into debug flags
-const bool trcflg = false;
-const bool stpflg = false;
-
-void Rules::parseRules() {
- bool change = true;
- int i;
-
- for (i = 1; !endOfTable(&_ruls[i - 1]); i++)
- _ruls[i - 1].run = false;
-
- while (change) {
- change = false;
- for (i = 1; !endOfTable(&_ruls[i - 1]); i++) {
- if (!_ruls[i - 1].run) {
- if (trcflg) {
- debug("\n<RULE %d (at ", i); // TODO: Debug output formatting?
- //debugsay(cur.loc); // TODO
- if (!stpflg)
- debug("), Evaluating");
- else
- debug("), Evaluating:>\n");
- }
-
- _interpreter->interpret(_ruls[i - 1].exp);
-
- if (_stack->pop()) {
- change = true;
- _ruls[i - 1].run = true;
-
- if (trcflg) {
- if (!stpflg) {
- debug(", Executing:>\n");
- } else {
- debug("\nRULE %d (at ", i);
- //debugsay(cur.loc); // TODO
- debug("), Executing:>\n");
- }
- }
-
- _interpreter->interpret(_ruls[i - 1].stms);
-
- } else if (trcflg && !stpflg) {
- debug(":>\n");
- }
- }
- }
- }
-}
-
-bool Rules::endOfTable(RulElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/rules.h b/engines/glk/alan2/rules.h
deleted file mode 100644
index 194c7d0..0000000
--- a/engines/glk/alan2/rules.h
+++ /dev/null
@@ -1,51 +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 GLK_ALAN2_RULES
-#define GLK_ALAN2_RULES
-
-#include "common/stack.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/types.h"
-
-namespace Glk {
-namespace Alan2 {
-
-class Interpreter;
-
-class Rules {
-public:
- Rules(RulElem *rules, Alan2Stack *stack, Interpreter *interpreter) : _ruls(rules), _stack(stack), _interpreter(interpreter) {}
- void parseRules();
-
-private:
- bool endOfTable(RulElem *addr);
-
- RulElem *_ruls;
- Alan2Stack *_stack;
- Interpreter *_interpreter;
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/saveload.cpp b/engines/glk/alan2/saveload.cpp
deleted file mode 100644
index 838c258..0000000
--- a/engines/glk/alan2/saveload.cpp
+++ /dev/null
@@ -1,218 +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 "common/savefile.h"
-#include "glk/alan2/acode.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/saveload.h"
-#include "glk/alan2/types.h"
-
-namespace Glk {
-namespace Alan2 {
-
-void SaveLoad::save() {
- uint i;
- Common::SaveFileManager *saveFileMan = _vm->getSaveFileManager();
- Common::OutSaveFile *saveFile = nullptr;
- Common::String str;
- AtrElem *atr;
-
- // TODO
-#if 0
- frefid_t fref = glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Write, 0);
- if (fref == nullptr)
- _vm->printError(M_SAVEFAILED);
-
- strcpy(str, garglk_fileref_get_name(fref));
- glk_fileref_destroy(fref);
-#endif
-
- if (str.empty())
- str = _prevSaveName;
-
- _vm->col = 1;
-
- // TODO
-#if 0
- if ((savfil = fopen(str, READ_MODE)) != nullptr)
- // It already existed
- if (!confirm(M_SAVEOVERWRITE))
- _vm->printError(MSGMAX); // Return to player without saying anything
-
- if ((savfil = fopen(str, WRITE_MODE)) == nullptr)
- _vm->printError(M_SAVEFAILED);
-#endif
-
- saveFile = saveFileMan->openForSaving(str);
-
- _prevSaveName = str;
-
- // Save version of interpreter and name of game
- saveFile->write(_vm->header->vers, sizeof(Aword));
- saveFile->writeString(_gameName);
- saveFile->writeByte('\0');
- // Save current values
- saveFile->write(&_vm->cur, sizeof(_vm->cur));
-
- // Save actors
- for (i = ACTMIN; i <= ACTMAX; i++) {
- saveFile->writeUint32LE(_actors[i - ACTMIN].loc);
- saveFile->writeUint32LE(_actors[i - ACTMIN].script);
- saveFile->writeUint32LE(_actors[i - ACTMIN].step);
- saveFile->writeUint32LE(_actors[i - ACTMIN].count);
- if (_actors[i - ACTMIN].atrs)
- for (atr = (AtrElem *)addrTo(_actors[i - ACTMIN].atrs); !endOfTable(atr); atr++)
- saveFile->writeUint32LE(atr->val);
- }
-
- // Save locations
- for (i = LOCMIN; i <= LOCMAX; i++) {
- saveFile->writeUint32LE(_locations[i - LOCMIN].describe);
- if (_locations[i - LOCMIN].atrs)
- for (atr = (AtrElem *)addrTo(_locations[i - LOCMIN].atrs); !endOfTable(atr); atr++)
- saveFile->writeUint32LE(atr->val);
- }
-
- // Save objects
- for (i = OBJMIN; i <= OBJMAX; i++) {
- saveFile->writeUint32LE(_objects[i - OBJMIN].loc);
- if (_objects[i - OBJMIN].atrs)
- for (atr = (AtrElem *)addrTo(_objects[i - OBJMIN].atrs); !endOfTable(atr); atr++)
- saveFile->writeUint32LE(atr->val);
- }
-
- // Save the event queue
- _events[*_eventTop].time = 0; // Mark the top
- for (i = 0; i < (uint)*_eventTop + 1; i++)
- saveFile->write(&_events[i], sizeof(_events[0]));
-
- // Save scores
- for (i = 0; _vm->scores[i] != EOF; i++)
- saveFile->writeUint32LE(_vm->scores[i]);
-
- delete saveFile;
-}
-
-void SaveLoad::restore() {
- uint i;
- Common::SaveFileManager *saveFileMan = _vm->getSaveFileManager();
- Common::InSaveFile *saveFile = nullptr;
- Common::String str;
- AtrElem *atr;
- char savedVersion[4];
- char savedName[256];
-
- // TODO
-#if 0
- frefid_t fref = glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Read, 0);
- if (fref == nullptr)
- _vm->printError(M_SAVEFAILED);
-
- strcpy(str, garglk_fileref_get_name(fref));
- glk_fileref_destroy(fref);
-#endif
-
- _vm->col = 1;
-
- if (str.empty())
- str = _prevSaveName; // Use the name temporarily
-
- if ((saveFile = saveFileMan->openForLoading(str)) == nullptr) {
- _vm->printError(M_SAVEMISSING);
- return;
- }
-
- _prevSaveName = str; // Save it for future use
-
- saveFile->read(savedVersion, sizeof(Aword));
-
- // 4f - save file version check doesn't seem to work on PC's!
- if (strncmp(savedVersion, _vm->header->vers, 4)) {
- delete saveFile;
- _vm->printError(M_SAVEVERS);
- return;
- }
-
- i = 0;
-
- while ((savedName[i++] = saveFile->readByte()) != '\0');
-
- if (savedName != _gameName) {
- delete saveFile;
- _vm->printError(M_SAVENAME);
- return;
- }
-
- // Restore current values
- saveFile->read(&_vm->cur, sizeof(_vm->cur));
-
- // Restore actors
- for (i = ACTMIN; i <= ACTMAX; i++) {
- _actors[i - ACTMIN].loc = saveFile->readUint32LE();
- _actors[i - ACTMIN].script = saveFile->readUint32LE();
- _actors[i - ACTMIN].step = saveFile->readUint32LE();
- _actors[i - ACTMIN].count = saveFile->readUint32LE();
-
- if (_actors[i - ACTMIN].atrs)
- for (atr = (AtrElem *)addrTo(_actors[i - ACTMIN].atrs); !endOfTable(atr); atr++)
- atr->val = saveFile->readUint32LE();
- }
-
- // Restore locations
- for (i = LOCMIN; i <= LOCMAX; i++) {
- _locations[i - LOCMIN].describe = saveFile->readUint32LE();
- if (_locations[i - LOCMIN].atrs)
- for (atr = (AtrElem *)addrTo(_locations[i - LOCMIN].atrs); !endOfTable(atr); atr++)
- atr->val = saveFile->readUint32LE();
- }
-
- // Restore objects
- for (i = OBJMIN; i <= OBJMAX; i++) {
- _objects[i - OBJMIN].loc = saveFile->readUint32LE();
- if (_objects[i - OBJMIN].atrs)
- for (atr = (AtrElem *)addrTo(_objects[i - OBJMIN].atrs); !endOfTable(atr); atr++)
- atr->val = saveFile->readUint32LE();
- }
-
- // Restore the event queue
- *_eventTop = 0;
- do {
- saveFile->read(&_events[*_eventTop], sizeof(_events[0]));
- (*_eventTop)++;
- } while (_events[*_eventTop - 1].time != 0);
-
- (*_eventTop)--;
-
- // Restore scores
- for (i = 0; _vm->scores[i] != EOF; i++)
- _vm->scores[i] = saveFile->readUint32LE();
-
- delete saveFile;
-}
-
-bool SaveLoad::endOfTable(AtrElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/saveload.h b/engines/glk/alan2/saveload.h
deleted file mode 100644
index 32a02bb..0000000
--- a/engines/glk/alan2/saveload.h
+++ /dev/null
@@ -1,55 +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 GLK_ALAN2_SAVELOAD
-#define GLK_ALAN2_SAVELOAD
-
-#include "common/scummsys.h"
-#include "glk/alan2/types.h"
-
-namespace Glk {
-namespace Alan2 {
-
-class SaveLoad {
-public:
- SaveLoad(Common::String &gameName, ActElem *actors, LocElem *locations, ObjElem *objects, EvtqElem *events, int *eventTop) :
- _gameName(gameName), _actors(actors), _locations(locations), _objects(objects), _events(events), _eventTop(eventTop) {}
- void save();
- void restore();
-private:
- bool endOfTable(AtrElem *addr);
-
- Common::String _prevSaveName;
-
- // Save state related variables
- Common::String _gameName;
- ActElem *_actors;
- LocElem *_locations;
- ObjElem *_objects;
- EvtqElem *_events;
- int *_eventTop;
-};
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 19dc6c9..bfda72d 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -32,13 +32,7 @@ MODULE_OBJS := \
advsys/glk_interface.o \
advsys/vm.o \
alan2/alan2.o \
- alan2/decode.o \
alan2/detection.o \
- alan2/execute.o \
- alan2/interpreter.o \
- alan2/parse.o \
- alan2/rules.o \
- alan2/saveload.o \
frotz/bitmap_font.o \
frotz/config.o \
frotz/detection.o \
Commit: 08bc570308b0698090ce668dc7dca4c0c76dd3df
https://github.com/scummvm/scummvm/commit/08bc570308b0698090ce668dc7dca4c0c76dd3df
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Initial import of full set of interpreter files
Changed paths:
A engines/glk/alan2/acode.h
A engines/glk/alan2/alan_version.cpp
A engines/glk/alan2/alan_version.h
A engines/glk/alan2/args.cpp
A engines/glk/alan2/args.h
A engines/glk/alan2/debug.cpp
A engines/glk/alan2/debug.h
A engines/glk/alan2/decode.cpp
A engines/glk/alan2/decode.h
A engines/glk/alan2/exe.cpp
A engines/glk/alan2/exe.h
A engines/glk/alan2/glkio.cpp
A engines/glk/alan2/glkio.h
A engines/glk/alan2/glkstart.cpp
A engines/glk/alan2/glkstart.h
A engines/glk/alan2/inter.cpp
A engines/glk/alan2/inter.h
A engines/glk/alan2/main.h
A engines/glk/alan2/params.cpp
A engines/glk/alan2/params.h
A engines/glk/alan2/parse.cpp
A engines/glk/alan2/parse.h
A engines/glk/alan2/readline.cpp
A engines/glk/alan2/readline.h
A engines/glk/alan2/reverse.cpp
A engines/glk/alan2/reverse.h
A engines/glk/alan2/rules.cpp
A engines/glk/alan2/rules.h
A engines/glk/alan2/stack.cpp
A engines/glk/alan2/stack.h
A engines/glk/alan2/sysdep.cpp
A engines/glk/alan2/sysdep.h
A engines/glk/alan2/term.cpp
A engines/glk/alan2/term.h
A engines/glk/alan2/version.h
engines/glk/alan2/types.h
engines/glk/alan2/util.h
engines/glk/module.mk
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
new file mode 100644
index 0000000..5fee277
--- /dev/null
+++ b/engines/glk/alan2/acode.h
@@ -0,0 +1,306 @@
+/* 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 GLK_ALAN2_ACODE
+#define GLK_ALAN2_ACODE
+
+namespace Glk {
+namespace Alan2 {
+
+typedef size_t Aptr; /* Type for an ACODE memory address */
+
+typedef unsigned int Aword; /* Type for an ACODE word */
+typedef unsigned int Aaddr; /* Type for an ACODE address */
+typedef unsigned int Abool; /* Type for an ACODE Boolean value */
+typedef signed int Aint; /* Type for an ACODE Integer value */
+typedef int CodeValue; /* Definition for the packing process */
+
+#ifdef UNUSED
+#if INT_MAX==0x7fffffff
+typedef unsigned int Aword; /* Type for an ACODE word */
+typedef unsigned int Aaddr; /* Type for an ACODE address */
+typedef unsigned int Abool; /* Type for an ACODE Boolean value */
+typedef signed int Aint; /* Type for an ACODE Integer value */
+typedef int CodeValue; /* Definition for the packing process */
+#elif LONG_MAX==0x7fffffff
+typedef unsigned long Aword; /* Type for an ACODE word */
+typedef unsigned long Aaddr; /* Type for an ACODE address */
+typedef unsigned long Abool; /* Type for an ACODE Boolean value */
+typedef signed long Aint; /* Type for an ACODE Integer value */
+typedef long CodeValue; /* Definition for the packing process */
+#else
+#error "Can't find a 32-bit integer type"
+#endif
+#endif
+
+/* Constants for the Acode file, words/block & bytes/block */
+#define BLOCKLEN 256L
+#define BLOCKSIZE (BLOCKLEN*sizeof(Aword))
+
+
+/* Definitions for the packing process */
+#define VALUEBITS 16
+
+#define EOFChar 256
+#define TOPVALUE (((CodeValue)1<<VALUEBITS) - 1) /* Highest value possible */
+
+/* Half and quarter points in the code value range */
+#define ONEQUARTER (TOPVALUE/4+1) /* Point after first quarter */
+#define HALF (2*ONEQUARTER) /* Point after first half */
+#define THREEQUARTER (3*ONEQUARTER) /* Point after third quarter */
+
+
+/* AMACHINE Word Classes */
+typedef int WrdKind;
+#define WRD_SYN 0 /* 1 - Synonym */
+#define WRD_ADJ 1 /* 2 - Adjective */
+#define WRD_ALL 2 /* 4 - All */
+#define WRD_BUT 3 /* 8 - But */
+#define WRD_CONJ 4 /* 16 - Conjunction */
+#define WRD_PREP 5 /* 32 - Preposition */
+#define WRD_DIR 6 /* 64 - Direction */
+#define WRD_IT 7 /* 128 - It */
+#define WRD_NOISE 8 /* 256 - Noise word */
+#define WRD_NOUN 9 /* 512 - Noun */
+#define WRD_ACT 10 /* 1024 - Actor */
+#define WRD_THEM 11 /* 2048 - Them */
+#define WRD_VRB 12 /* 4096 - Verb */
+#define WRD_CLASSES 13
+
+
+
+/* Syntax element classifications */
+#define EOS (-2) /* End Of Syntax */
+
+/* Syntax element flag bits */
+#define MULTIPLEBIT 0x1
+#define OMNIBIT 0x2
+
+
+/* Parameter Classes */
+typedef enum ClaKind { /* NOTE! These must have the same order as */
+ CLA_OBJ = 1, /* the name classes in NAM.H */
+ CLA_CNT = (int)CLA_OBJ<<1,
+ CLA_ACT = (int)CLA_CNT<<1,
+ CLA_NUM = (int)CLA_ACT<<1,
+ CLA_STR = (int)CLA_NUM<<1,
+ CLA_COBJ = (int)CLA_STR<<1,
+ CLA_CACT = (int)CLA_COBJ<<1
+} ClaKind;
+
+
+/* Verb Qualifiers */
+typedef enum QualClass {
+ Q_DEFAULT,
+ Q_AFTER,
+ Q_BEFORE,
+ Q_ONLY
+} QualClass;
+
+
+/* The AMACHINE Operations */
+typedef enum OpClass {
+ C_CONST,
+ C_STMOP,
+ C_CURVAR
+} OpClass;
+
+typedef enum InstClass {
+ I_PRINT, /* Print a string from the text file */
+ I_QUIT,
+ I_LOOK,
+ I_SAVE,
+ I_RESTORE,
+ I_LIST, /* List contents of a container */
+ I_EMPTY,
+ I_SCORE,
+ I_VISITS,
+ I_SCHEDULE,
+ I_CANCEL,
+ I_LOCATE,
+ I_MAKE,
+ I_SET, /* Set a numeric attribute to the */
+ /* value on top of stack */
+ I_STRSET, /* Set a string valued attribute to a */
+ /* copy of the string on top of stack, */
+ /* deallocate current contents first */
+ I_GETSTR, /* Get a string contents from text */
+ /* file, create a copy and push it */
+ /* on top of stack */
+ I_INCR, /* Increment an attribute */
+ I_DECR, /* Decrement a numeric attribute */
+ I_USE,
+ I_IN,
+ I_DESCRIBE,
+ I_SAY,
+ I_SAYINT,
+ I_SAYSTR,
+ I_IF,
+ I_ELSE,
+ I_ENDIF,
+ I_ATTRIBUTE,
+ I_STRATTR, /* Push a copy of a string attribute */
+ I_HERE,
+ I_NEAR,
+ I_WHERE,
+ I_AND,
+ I_OR,
+ I_NE,
+ I_EQ,
+ I_STREQ, /* String compare */
+ I_STREXACT,
+ I_LE,
+ I_GE,
+ I_LT,
+ I_GT,
+ I_PLUS,
+ I_MINUS,
+ I_MULT,
+ I_DIV,
+ I_NOT,
+ I_UMINUS,
+ I_RND,
+ I_SUM, /* SUM-aggregate */
+ I_MAX, /* MAX-aggregate */
+ I_COUNT, /* COUNT-aggregate */
+ I_RETURN,
+ I_SYSTEM,
+ I_RESTART, /* INTRODUCED: v2.7 */
+ I_BTW, /* INTRODUCED: v2.8 */
+ I_CONTAINS, /* -""- */
+ I_DEPSTART, /* -""- */
+ I_DEPCASE, /* -""- */
+ I_DEPEXEC, /* -""- */
+ I_DEPELSE, /* -""- */
+ I_DEPEND /* -""- */
+} InstClass;
+
+
+typedef enum VarClass {
+ V_PARAM,
+ V_CURLOC,
+ V_CURACT,
+ V_CURVRB,
+ V_SCORE
+} VarClass;
+
+
+#define I_CLASS(x) ((x)>>28)
+#define I_OP(x) ((x&0x8000000)?(x)|0x0f0000000:(x)&0x0fffffff)
+
+
+typedef struct AcdHdr {
+/* Important info */
+ char vers[4]; /* 01 - Version of compiler */
+ Aword size; /* 02 - Size of ACD-file in Awords */
+/* Options */
+ Abool pack; /* 03 - Is the text packed ? */
+ Aword paglen; /* 04 - Length of a page */
+ Aword pagwidth; /* 05 - and width */
+ Aword debug; /* 06 - Option debug */
+/* Data structures */
+ Aaddr dict; /* 07 - Dictionary */
+ Aaddr oatrs; /* 08 - Object default attributes */
+ Aaddr latrs; /* 09 - Location default attributes */
+ Aaddr aatrs; /* 0a - Actor default attributes */
+ Aaddr acts; /* 0b - Actor table */
+ Aaddr objs; /* 0c - Object table */
+ Aaddr locs; /* 0d - Location table */
+ Aaddr stxs; /* 0e - Syntax table */
+ Aaddr vrbs; /* 0f - Verb table */
+ Aaddr evts; /* 10 - Event table */
+ Aaddr cnts; /* 11 - Container table */
+ Aaddr ruls; /* 12 - Rule table */
+ Aaddr init; /* 13 - String init table */
+ Aaddr start; /* 14 - Start code */
+ Aword msgs; /* 15 - Messages table */
+/* Miscellaneous */
+ Aword objmin, objmax; /* 16 - Interval for object codes */
+ Aword actmin, actmax; /* 18 - Interval for actor codes */
+ Aword cntmin, cntmax; /* 1a - Interval for container codes */
+ Aword locmin, locmax; /* 1c - Interval for location codes */
+ Aword dirmin, dirmax; /* 1e - Interval for direction codes */
+ Aword evtmin, evtmax; /* 20 - Interval for event codes */
+ Aword rulmin, rulmax; /* 22 - Interval for rule codes */
+ Aword maxscore; /* 24 - Maximum score */
+ Aaddr scores; /* 25 - Score table */
+ Aaddr freq; /* 26 - Address to Char freq's for coding */
+ Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
+ Aword txtcrc; /* 28 - Checksum for text data file */
+} AcdHdr;
+
+/* Error message numbers */
+typedef enum MsgKind {
+ M_HUH, /* Obsolete */
+ M_WHAT,
+ M_WHAT_ALL,
+ M_WHAT_IT,
+ M_WHAT_THEM,
+ M_MULTIPLE,
+ M_WANT,
+ M_NOUN,
+ M_AFTER_BUT,
+ M_BUT_ALL,
+ M_NOT_MUCH,
+ M_WHICH_ONE,
+ M_NO_SUCH,
+ M_NO_WAY,
+ M_CANT0,
+ M_CANT,
+ M_NOTHING, /* Obsolete */
+ M_SEEOBJ1,
+ M_SEEOBJ2,
+ M_SEEOBJ3,
+ M_SEEOBJ4,
+ M_SEEACT,
+ M_CONTAINS1,
+ M_CONTAINS2,
+ M_CONTAINS3,
+ M_CONTAINS4,
+ M_CONTAINS5,
+ M_EMPTY1,
+ M_EMPTY2,
+ M_SCORE1,
+ M_SCORE2,
+ M_UNKNOWN_WORD,
+ M_MORE,
+ M_AGAIN,
+ M_SAVEWHERE,
+ M_SAVEOVERWRITE,
+ M_SAVEFAILED,
+ M_SAVEMISSING,
+ M_SAVEVERS,
+ M_SAVENAME,
+ M_RESTOREFROM,
+ M_REALLY, /* CHANGED: v2.7 from M_RESTART */
+ M_QUITACTION, /* INTRODUCED: v2.7, so M_ARTICLE moved */
+ M_ARTICLE, /* INTRODUCED: v2.6 but replaced the M_NOMSG*/
+ MSGMAX
+} MsgKind;
+
+#define M_ARTICLE26 M_QUITACTION
+#define M_MSGMAX26 M_ARTICLE
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/alan_version.cpp b/engines/glk/alan2/alan_version.cpp
new file mode 100644
index 0000000..d3e1b9d
--- /dev/null
+++ b/engines/glk/alan2/alan_version.cpp
@@ -0,0 +1,45 @@
+/* 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/alan2/alan_version.h"
+
+namespace Glk {
+namespace Alan2 {
+
+Product alan = {
+ "Alan",
+ "Adventure Language System",
+ "Alan 2.8(6)",
+ "Alan 2.8(6) -- Adventure Language System (2001-07-13 14:35)",
+ "2001-07-13",
+ "14:35:07",
+ "Thomas Nilsson",
+ "",
+ "cygwin",
+ {"2.8(6)", 2, 8, 6, 995034907, ""}
+};
+
+static char *alanId =
+ "@(#)RELEASE ";
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/alan_version.h b/engines/glk/alan2/alan_version.h
new file mode 100644
index 0000000..1a75394
--- /dev/null
+++ b/engines/glk/alan2/alan_version.h
@@ -0,0 +1,36 @@
+/* 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 GLK_ALAN2_ALAN_VERSION
+#define GLK_ALAN2_ALAN_VERSION
+
+#include "glk/alan2/version.h"
+
+namespace Glk {
+namespace Alan2 {
+
+extern Product alan;
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp
new file mode 100644
index 0000000..aceb00b
--- /dev/null
+++ b/engines/glk/alan2/args.cpp
@@ -0,0 +1,308 @@
+/* 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 <string>
+#ifndef __PACIFIC__
+#include "glk/alan2/args.h"
+#else
+/* I have no idea at all why the include does not work in Pacific C ... */
+extern void args(int argc, char* argv[]);
+#endif
+
+#include "glk/alan2/main.h"
+
+#ifdef __mac__
+#include "glk/alan2/macArgs.h"
+#endif
+
+#ifdef __amiga__
+#include <libraries/dosextens.h>
+#ifdef AZTEC_C
+struct FileHandle *con = NULL;
+#else
+/* Geek Gadgets GCC */
+BPTR window;
+BPTR cd;
+#endif
+#endif
+
+#ifdef GLK
+#include "glk/alan2/alan2.h"
+#include "glk/alan2/glkio.h"
+#include "glk/alan2/sysdep.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+static void switches(
+ unsigned argc,
+ char *argv[]
+)
+#else
+static void switches(argc, argv)
+ unsigned argc;
+ char *argv[];
+#endif
+{
+ uint i;
+
+ advnam = "";
+ for (i = 1; i < argc; i++) {
+ if (argv[i][0] == '-') {
+#ifdef GLK
+ switch (g_vm->glk_char_to_lower(argv[i][1])) {
+#else
+ switch (tolower(argv[i][1])) {
+#endif
+ case 'i':
+ errflg = FALSE;
+ break;
+ case 't':
+ trcflg = TRUE;
+ break;
+ case 'd':
+ dbgflg = TRUE;
+ break;
+ case 's':
+ trcflg = TRUE;
+ stpflg = TRUE;
+ break;
+ case 'l':
+ logflg = TRUE;
+ break;
+ case 'v':
+ verbose = TRUE;
+ break;
+ case 'n':
+ statusflg = FALSE;
+ break;
+ default:
+ printf("Unrecognized switch, -%c\n", argv[i][1]);
+ usage();
+ terminate(0);
+ }
+ } else {
+ advnam = argv[i];
+ if (strcmp(&advnam[strlen(advnam)-4], ".acd") == 0
+ || strcmp(&advnam[strlen(advnam)-4], ".ACD") == 0
+ || strcmp(&advnam[strlen(advnam)-4], ".dat") == 0
+ || strcmp(&advnam[strlen(advnam)-4], ".DAT") == 0)
+ advnam[strlen(advnam)-4] = '\0';
+ }
+ }
+}
+
+
+
+#ifdef __amiga__
+
+#include <intuition/intuition.h>
+#include <workbench/workbench.h>
+
+#include <clib/exec_protos.h>
+#include <clib/dos_protos.h>
+#include <clib/icon_protos.h>
+
+#include <fcntl.h>
+
+extern struct Library *IconBase;
+
+#ifndef AZTEC_C
+/* Actually Geek Gadgets GCC with libnix */
+
+/* Aztec C has its own pre-main wbparse which was used in Arun 2.7, with GCC we
+ need to do it ourselves. */
+
+#include <clib/intuition_protos.h>
+
+extern unsigned long *__stdfiledes; /* The libnix standard I/O file descriptors */
+
+void
+wb_parse(void)
+{
+ char *cp;
+ struct DiskObject *dop;
+ struct FileHandle *fhp;
+
+ if (_WBenchMsg->sm_NumArgs == 1) /* If no argument use program icon/info */
+ dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[0].wa_Name);
+ else {
+ BPTR olddir = CurrentDir(_WBenchMsg->sm_ArgList[1].wa_Lock);
+ dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[1].wa_Name);
+ CurrentDir(olddir);
+ }
+ if (dop != 0 && (cp = (char *)FindToolType((UBYTE **)dop->do_ToolTypes,
+ (UBYTE *)"WINDOW")) != NULL)
+ ;
+ else /* Could not find a WINDOW tool type */
+ cp = "CON:10/10/480/160/Arun:Default Window/CLOSE";
+ if ((window = Open((UBYTE *)cp, (long)MODE_OLDFILE))) {
+ fhp = (struct FileHandle *) ((long)window << 2);
+ SetConsoleTask(fhp->fh_Type);
+ SelectInput(window);
+ SelectOutput(window);
+ __stdfiledes[0] = Input();
+ __stdfiledes[1] = Output();
+ } else
+ exit(-1L);
+ FreeDiskObject(dop);
+}
+#endif
+#endif
+
+
+#ifdef _PROTOTYPES_
+void args(
+ int argc,
+ char * argv[]
+)
+#else
+void args(argc, argv)
+ int argc;
+ char *argv[];
+#endif
+{
+ char *prgnam;
+
+#ifdef __mac__
+#include <console.h>
+#ifdef __MWERKS__
+#include <SIOUX.h>
+#endif
+ short msg, files;
+ static char advbuf[256], prgbuf[256];
+ /*AppFile af;*/
+ OSErr oe;
+
+#ifdef __MWERKS__
+ /*SIOUXSettings.setupmenus = FALSE;*/
+ SIOUXSettings.autocloseonquit = FALSE;
+ SIOUXSettings.asktosaveonclose = FALSE;
+ SIOUXSettings.showstatusline = FALSE;
+#endif
+
+ GetMacArgs(advbuf);
+ advnam = advbuf;
+
+#else
+#ifdef __amiga__
+
+ if (argc == 0) { /* If started from Workbench get WbArgs : Aztec C & GG GCC */
+ struct WBStartup *WBstart;
+
+ if ((IconBase = OpenLibrary("icon.library", 0)) == NULL)
+ syserr("Could not open 'icon.library'");
+ /* If started from WB normal main is called with argc == 0 and argv = WBstartup message */
+ WBstart = (struct WBStartup *)argv;
+#ifndef AZTEC_C
+ /* Geek Gadgets GCC */
+ wb_parse();
+#endif
+ advnam = prgnam = WBstart->sm_ArgList[0].wa_Name;
+ if (WBstart->sm_NumArgs > 0) {
+ cd = CurrentDir(DupLock(WBstart->sm_ArgList[1].wa_Lock));
+ advnam = WBstart->sm_ArgList[1].wa_Name;
+ }
+ /* Possibly other tooltypes ... */
+ } else {
+ /* Started from a CLI */
+ if ((prgnam = strrchr(argv[0], '/')) == NULL
+ && (prgnam = strrchr(argv[0], ':')) == NULL)
+ prgnam = argv[0];
+ else
+ prgnam++;
+ /* Now look at the switches and arguments */
+ switches(argc, argv);
+ if (advnam[0] == '\0')
+ /* No game given, try program name */
+ if (stricmp(prgnam, PROGNAME) != 0
+ && strstr(prgnam, PROGNAME) == 0)
+ advnam = strdup(argv[0]);
+ }
+#else
+#if defined(__dos__) || defined(__win__)
+ if ((prgnam = strrchr(argv[0], '\\')) == NULL
+ && (prgnam = strrchr(argv[0], '/')) == NULL
+ && (prgnam = strrchr(argv[0], ':')) == NULL)
+ prgnam = argv[0];
+ else
+ prgnam++;
+ if (strlen(prgnam) > 4
+ && (strcmp(&prgnam[strlen(prgnam)-4], ".EXE") == 0
+ || strcmp(&prgnam[strlen(prgnam)-4], ".exe") == 0))
+ prgnam[strlen(prgnam)-4] = '\0';
+ /* Now look at the switches and arguments */
+ switches(argc, argv);
+ if (advnam[0] == '\0')
+ /* No game given, try program name */
+ if (stricmp(prgnam, PROGNAME) != 0
+ && strstr(prgnam, PROGNAME) == 0)
+ advnam = strdup(argv[0]);
+#else
+#if defined __vms__
+ if ((prgnam = strrchr(argv[0], ']')) == NULL
+ && (prgnam = strrchr(argv[0], '>')) == NULL
+ && (prgnam = strrchr(argv[0], ':')) == NULL)
+ prgnam = argv[0];
+ else
+ prgnam++;
+ if (strrchr(prgnam, ';') != NULL)
+ *strrchr(prgnam, ';') = '\0';
+ if (strlen(prgnam) > 4
+ && (strcmp(&prgnam[strlen(prgnam)-4], ".EXE") == 0
+ || strcmp(&prgnam[strlen(prgnam)-4], ".exe") == 0))
+ prgnam[strlen(prgnam)-4] = '\0';
+ /* Now look at the switches and arguments */
+ switches(argc, argv);
+ if (advnam[0] == '\0')
+ /* No game given, try program name */
+ if (strcmp(prgnam, PROGNAME) != 0
+ && strstr(prgnam, PROGNAME) == 0)
+ advnam = strdup(argv[0]);
+#else
+#if defined(__unix__) || defined(__APPLE__)
+ if ((prgnam = strrchr(argv[0], '/')) == NULL)
+ prgnam = strdup(argv[0]);
+ else
+ prgnam = strdup(&prgnam[1]);
+ if (strrchr(prgnam, ';') != NULL)
+ *strrchr(prgnam, ';') = '\0';
+ /* Now look at the switches and arguments */
+ switches(argc, argv);
+ if (advnam[0] == '\0')
+ /* No game given, try program name */
+ if (strcmp(prgnam, PROGNAME) != 0
+ && strstr(prgnam, PROGNAME) == 0)
+ advnam = strdup(argv[0]);
+#else
+ Unimplemented OS!
+#endif
+#endif
+#endif
+#endif
+#endif
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/args.h b/engines/glk/alan2/args.h
new file mode 100644
index 0000000..a86d519
--- /dev/null
+++ b/engines/glk/alan2/args.h
@@ -0,0 +1,50 @@
+/* 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 GLK_ALAN2_ARGS
+#define GLK_ALAN2_ARGS
+
+/* Handles the various startup methods on all machines.
+ *
+ * Main function args() will set up global variable advnam and the flags,
+ * the terminal will also be set up and connected.
+ */
+
+#include "glk/alan2/types.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#ifndef PROGNAME
+#define PROGNAME "alan2"
+#endif
+
+#ifdef _PROTOTYPES_
+extern void args(int argc, char *argv[]);
+#else
+extern void args();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
new file mode 100644
index 0000000..dc353c7
--- /dev/null
+++ b/engines/glk/alan2/debug.cpp
@@ -0,0 +1,506 @@
+/* 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/alan2/types.h"
+#ifdef HAVE_SHORT_FILENAMES
+#include "glk/alan2/av.h"
+#else
+#include "glk/alan2/alan_version.h"
+#endif
+
+#ifdef USE_READLINE
+#include "glk/alan2/readline.h"
+#endif
+
+#include "glk/alan2/inter.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/parse.h"
+#include "glk/alan2/exe.h"
+
+#include "glk/alan2/debug.h"
+
+#ifdef GLK
+#include "glk/alan2/glkio.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+static void showatrs(
+ Aword atradr
+)
+#else
+static void showatrs(atradr)
+ Aword atradr;
+#endif
+{
+ AtrElem *at;
+ int i;
+ char str[80];
+
+ if (atradr == 0) return;
+
+ i = 1;
+ for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) {
+ sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr));
+#if ISO == 0
+ fromIso(str, str);
+#endif
+ output(str);
+ i++;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void showobjs(void)
+#else
+static void showobjs()
+#endif
+{
+ char str[80];
+ int obj;
+
+ output("OBJECTS:");
+ for (obj = OBJMIN; obj <= OBJMAX; obj++) {
+ sprintf(str, "$i%3ld: ", (long) obj);
+ output(str);
+ say(obj);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void showobj(
+ int obj
+)
+#else
+static void showobj(obj)
+ int obj;
+#endif
+{
+ char str[80];
+#define OBJ (obj-OBJMIN)
+
+
+ if (!isObj(obj)) {
+ sprintf(str, "Object number out of range. Between %ld and %ld, please.", (unsigned long) OBJMIN, (unsigned long) OBJMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "OBJECT %d :", obj);
+ output(str);
+ say(obj);
+
+ sprintf(str, "$iLocation = %ld", (unsigned long) where(obj));
+ output(str);
+ if (isLoc(objs[OBJ].loc))
+ say(objs[OBJ].loc);
+ else if (isCnt(objs[OBJ].loc)) {
+ if (isObj(objs[OBJ].loc)) {
+ output("in");
+ say(objs[OBJ].loc);
+ } else if (isAct(objs[OBJ].loc)) {
+ output("carried by");
+ say(objs[OBJ].loc);
+ } else
+ interpret(cnts[objs[OBJ].loc-CNTMIN].nam);
+ } else if (objs[OBJ].loc == 0)
+ output("nowhere");
+ else
+ output("Illegal location!");
+
+
+ output("$iAttributes =");
+ showatrs(objs[OBJ].atrs);
+
+#undef OBJ
+}
+
+
+#ifdef _PROTOTYPES_
+static void showcnts(void)
+#else
+static void showcnts()
+#endif
+{
+ char str[80];
+ int cnt;
+#define CNT (cnt-CNTMIN)
+
+ output("CONTAINERS:");
+ for (cnt = CNTMIN; cnt <= CNTMAX; cnt++) {
+ sprintf(str, "$i%3ld: ", (long) cnt);
+ output(str);
+ if (cnts[CNT].nam != 0)
+ interpret(cnts[CNT].nam);
+ if (cnts[CNT].parent != 0)
+ say(cnts[CNT].parent);
+ }
+
+#undef CNT
+}
+
+
+#ifdef _PROTOTYPES_
+static void showcnt(
+ int cnt
+)
+#else
+static void showcnt(cnt)
+ int cnt;
+#endif
+{
+ char str[80];
+ int i;
+ Abool found = FALSE;
+#define CNT (cnt-CNTMIN)
+
+ if (cnt < CNTMIN || cnt > CNTMAX) {
+ sprintf(str, "Container number out of range. Between %ld and %ld, please.", (unsigned long) CNTMIN, (unsigned long) CNTMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "CONTAINER %d :", cnt);
+ output(str);
+ if (cnts[CNT].nam != 0)
+ interpret(cnts[CNT].nam);
+ if (cnts[CNT].parent != 0) {
+ cnt = cnts[CNT].parent;
+ say(cnt);
+ sprintf(str, "$iLocation = %ld", (unsigned long) where(cnt));
+ output(str);
+ }
+ output("$iContains ");
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (in(i, cnt)) { /* Yes, it's in this container */
+ if (!found) {
+ output("$n");
+ found = TRUE;
+ }
+ sprintf(str, "$t$t%d: ", i);
+ output(str);
+ say(i);
+ }
+ }
+ if (!found)
+ output("nothing");
+
+#undef CNT
+}
+
+
+#ifdef _PROTOTYPES_
+static void showlocs(void)
+#else
+static void showlocs()
+#endif
+{
+ char str[80];
+ int loc;
+
+ output("LOCATIONS:");
+ for (loc = LOCMIN; loc <= LOCMAX; loc++) {
+ sprintf(str, "$i%3ld: ", (long) loc);
+ output(str);
+ say(loc);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void showloc(
+ int loc
+)
+#else
+static void showloc(loc)
+ int loc;
+#endif
+{
+ char str[80];
+
+
+ if (!isLoc(loc)) {
+ sprintf(str, "Location number out of range. Between %ld and %ld, please.", (unsigned long) LOCMIN, (unsigned long) LOCMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "LOCATION %d :", loc);
+ output(str);
+ say(loc);
+
+ output("$iAttributes =");
+ showatrs(locs[loc-LOCMIN].atrs);
+}
+
+
+#ifdef _PROTOTYPES_
+static void showacts(void)
+#else
+static void showacts()
+#endif
+{
+ char str[80];
+ int act;
+
+ output("ACTORS:");
+ for (act = ACTMIN; act <= ACTMAX; act++) {
+ sprintf(str, "$i%3ld:", (long) act);
+ output(str);
+ say(act);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void showact(
+ int act
+)
+#else
+static void showact(act)
+ int act;
+#endif
+{
+ char str[80];
+ Boolean oldstp;
+
+ if (!isAct(act)) {
+ sprintf(str, "Actor number out of range. Between %ld and %ld, please.", (unsigned long) ACTMIN, (unsigned long) ACTMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "ACTOR %d :", act);
+ output(str);
+ oldstp = stpflg; stpflg = FALSE; /* Make sure not to trace this! */
+ say(act);
+ stpflg = oldstp;
+
+ sprintf(str, "$iLocation = %ld", (unsigned long) acts[act-ACTMIN].loc);
+ output(str);
+ if (isLoc(acts[act-ACTMIN].loc))
+ say(acts[act-ACTMIN].loc);
+ else if (acts[act-ACTMIN].loc == 0)
+ output("nowhere");
+ else
+ output("Illegal location!");
+
+ sprintf(str, "$iScript = %ld", (unsigned long) acts[act-ACTMIN].script);
+ output(str);
+
+ sprintf(str, "$iStep = %ld", (unsigned long) acts[act-ACTMIN].step);
+ output(str);
+
+ output("$iAttributes =");
+ showatrs(acts[act-ACTMIN].atrs);
+}
+
+
+#ifdef _PROTOTYPES_
+static void showevts(void)
+#else
+static void showevts()
+#endif
+{
+ int evt, i;
+ char str[80];
+ Boolean scheduled;
+
+ output("EVENTS:");
+ for (evt = EVTMIN; evt <= EVTMAX; evt++) {
+ sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt-EVTMIN].stradr));
+#if ISO == 0
+ fromIso(str, str);
+#endif
+ output(str);
+ scheduled = FALSE;
+ for (i = 0; i < etop; i++)
+ if ((scheduled = (eventq[i].event == evt)))
+ break;
+ if (scheduled) {
+ sprintf(str, "Scheduled for +%d, at ", eventq[i].time-cur.tick);
+ output(str);
+ say(eventq[i].where);
+ } else
+ output("Not scheduled.");
+ }
+}
+
+
+static Boolean trc, stp;
+static int loc;
+
+#ifdef _PROTOTYPES_
+void saveInfo(void)
+#else
+void saveInfo()
+#endif
+{
+ /* Save some important things */
+ trc = trcflg; trcflg = FALSE;
+ stp = stpflg; stpflg = FALSE;
+ loc = cur.loc; cur.loc = where(HERO);
+}
+
+#ifdef _PROTOTYPES_
+void restoreInfo(void)
+#else
+void restoreInfo()
+#endif
+{
+ /* Restore! */
+ trcflg = trc;
+ stpflg = stp;
+ cur.loc = loc;
+}
+
+
+#ifdef _PROTOTYPES_
+void debug(void)
+#else
+void debug()
+#endif
+{
+ char buf[256];
+ char c;
+ int i;
+
+ saveInfo();
+ while (TRUE) {
+ if (anyOutput)
+ para();
+ do {
+ output("ABUG> ");
+#ifdef USE_READLINE
+ (void) readline(buf);
+#else
+ fgets(buf, 255, stdin);
+#endif
+ lin = 1;
+ c = buf[0];
+ i = 0;
+ sscanf(&buf[1], "%d", &i);
+ } while (buf && c == '\0');
+
+ switch (toUpper(c)) {
+ case 'H':
+ case '?':
+ output(alan.longHeader);
+ output("$nABUG Commands:\
+ $iO [n] -- show object[s]\
+ $iA [n] -- show actor[s]\
+ $iL [n] -- show location[s]\
+ $iC [n] -- show container[s]\
+ $iE -- show events\
+ $iG -- go on\
+ $iT -- toggle trace mode\
+ $iS -- toggle step mode\
+ $iX -- exit debug mode\
+ $iQ -- quit game");
+ break;
+ case 'Q':
+ terminate(0);
+ case 'X':
+ dbgflg = FALSE; /* Fall through to 'G' */
+ case 'G':
+ restoreInfo();
+ return;
+ case 'O':
+ if (i == 0)
+ showobjs();
+ else
+ showobj(i);
+ break;
+ case 'C':
+ if (i == 0)
+ showcnts();
+ else
+ showcnt(i);
+ break;
+ case 'A':
+ if (i == 0)
+ showacts();
+ else
+ showact(i);
+ break;
+ case 'L':
+ if (i == 0)
+ showlocs();
+ else
+ showloc(i);
+ break;
+ case 'E':
+ showevts();
+ break;
+ case 'S':
+ if ((stp = !stp))
+ printf("Step on.");
+ else
+ printf("Step off.");
+ break;
+ case 'T':
+ if ((trc = !trc))
+ printf("Trace on.");
+ else
+ printf("Trace off.");
+ break;
+ default:
+ output("Unknown ABUG command. ? for help.");
+ break;
+ }
+ }
+}
+
+
+/*======================================================================
+
+ debugsay()
+
+ Say somethin, but make sure we don't disturb anything and that it is
+ shown to the player.
+
+*/
+#ifdef _PROTOTYPES_
+void debugsay(int item)
+#else
+void debugsay(item)
+ int item;
+#endif
+{
+ saveInfo();
+ needsp = FALSE;
+ col = 1;
+ if (item == 0)
+ printf("$null$");
+ else
+ say(item);
+ needsp = FALSE;
+ col = 1;
+ restoreInfo();
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/debug.h b/engines/glk/alan2/debug.h
new file mode 100644
index 0000000..aac870e
--- /dev/null
+++ b/engines/glk/alan2/debug.h
@@ -0,0 +1,47 @@
+/* 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.
+ *
+ */
+
+/* TYPES */
+
+#ifndef GLK_ALAN2_DEBUG
+#define GLK_ALAN2_DEBUG
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+
+extern void saveInfo(void);
+extern void restoreInfo(void);
+extern void debug(void);
+extern void debugsay(int item);
+#else
+extern void saveInfo();
+extern void restoreInfo();
+extern void debug();
+extern void debugsay();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
new file mode 100644
index 0000000..4ffdc2f
--- /dev/null
+++ b/engines/glk/alan2/decode.cpp
@@ -0,0 +1,193 @@
+/* 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 <stdlib.h>
+#include "glk/alan2/main.h"
+#include "glk/alan2/decode.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/* Bit output */
+static int decodeBuffer; /* Bits to be input */
+static int bitsToGo; /* Bits still in buffer */
+static int garbageBits; /* Bits past EOF */
+
+
+#ifdef _PROTOTYPES_
+static int inputBit(void)
+#else
+static int inputBit()
+#endif
+{
+ int bit;
+
+ if (!bitsToGo) { /* More bits available ? */
+ decodeBuffer = txtfil->readByte(); /* No, so get more */
+ if (decodeBuffer == EOF) {
+ garbageBits++;
+ if (garbageBits > VALUEBITS-2)
+ syserr("Error in encoded data file.");
+ } else
+ bitsToGo = 8; /* Another Char, 8 new bits */
+ }
+ bit = decodeBuffer&1; /* Get next bit */
+ decodeBuffer = decodeBuffer>>1; /* and remove it */
+ bitsToGo--;
+ return bit;
+}
+
+
+/* Current state of decoding */
+
+static CodeValue value; /* Currently seen code value */
+static CodeValue low, high; /* Current code region */
+
+
+#ifdef _PROTOTYPES_
+void startDecoding(void)
+#else
+void startDecoding()
+#endif
+{
+ int i;
+
+ bitsToGo = 0;
+ garbageBits = 0;
+
+ value = 0;
+ for (i = 0; i < VALUEBITS; i++)
+ value = 2*value + inputBit();
+ low = 0;
+ high = TOPVALUE;
+}
+
+
+#ifdef _PROTOTYPES_
+int decodeChar(void)
+#else
+int decodeChar()
+#endif
+{
+ long range;
+ int f;
+ int symbol;
+
+ range = (long)(high-low) + 1;
+ f = (((long)(value-low)+1)*freq[0]-1)/range;
+
+ /* Find the symbol */
+ for (symbol = 1; (int)freq[symbol] > f; symbol++);
+
+ high = low + range*freq[symbol-1]/freq[0]-1;
+ low = low + range*freq[symbol]/freq[0];
+
+ for (;;) {
+ if (high < HALF)
+ ;
+ else if (low >= HALF) {
+ value = value - HALF;
+ low = low - HALF;
+ high = high - HALF;
+ } else if (low >= ONEQUARTER && high < THREEQUARTER) {
+ value = value - ONEQUARTER;
+ low = low - ONEQUARTER;
+ high = high - ONEQUARTER;
+ } else
+ break;
+
+ /* Scale up the range */
+ low = 2*low;
+ high = 2*high+1;
+ value = 2*value + inputBit();
+ }
+ return symbol-1;
+}
+
+
+
+/* Structure for saved decode info */
+typedef struct DecodeInfo {
+ long fpos;
+ int buffer;
+ int bits;
+ CodeValue value;
+ CodeValue high;
+ CodeValue low;
+} DecodeInfo;
+
+
+/*======================================================================
+
+ pushDecode()
+
+ Save so much info about the decoding process so it is possible to
+ restore and continue later.
+
+ */
+#ifdef _PROTOTYPES_
+void *pushDecode(void)
+#else
+void *pushDecode()
+#endif
+{
+ DecodeInfo *info;
+
+ info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
+ info->fpos = txtfil->pos();
+ info->buffer = decodeBuffer;
+ info->bits = bitsToGo;
+ info->value = value;
+ info->high = high;
+ info->low = low;
+ return(info);
+}
+
+
+/*======================================================================
+
+ popDecode()
+
+ Restore enough info about the decoding process so it is possible to
+ continue after having decoded something else.
+
+ */
+#ifdef _PROTOTYPES_
+void popDecode(void *i)
+#else
+void popDecode(i)
+ void *i;
+#endif
+{
+ DecodeInfo *info = (DecodeInfo *) i;
+ fseek(txtfil, info->fpos, 0);
+ decodeBuffer = info->buffer;
+ bitsToGo = info->bits;
+ value = info->value;
+ high = info->high;
+ low = info->low;
+
+ free(info);
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/decode.h b/engines/glk/alan2/decode.h
new file mode 100644
index 0000000..7ce15b4
--- /dev/null
+++ b/engines/glk/alan2/decode.h
@@ -0,0 +1,49 @@
+/* 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 GLK_ALAN2_DECODE
+#define GLK_ALAN2_DECODE
+
+#include "glk/alan2/types.h"
+
+/* Arithmetic decoding module in Arun
+ */
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+extern void startDecoding(void);
+extern int decodeChar(void);
+extern void *pushDecode(void);
+extern void popDecode(void *info);
+#else
+extern void startDecoding();
+extern int decodeChar();
+extern void *pushDecode();
+extern void popDecode();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
new file mode 100644
index 0000000..1cccf3d
--- /dev/null
+++ b/engines/glk/alan2/exe.cpp
@@ -0,0 +1,1845 @@
+/* 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/alan2/types.h"
+#include "glk/alan2/alan2.h"
+
+#ifdef USE_READLINE
+#include "glk/alan2/readline.h"
+#endif
+
+#include "glk/alan2/main.h"
+#include "glk/alan2/parse.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/stack.h"
+#include "glk/alan2/decode.h"
+
+#include "glk/alan2/exe.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#define WIDTH 80
+
+#define N_EVTS 100
+
+
+/* PUBLIC DATA */
+
+/* The event queue */
+EvtqElem eventq[N_EVTS]; /* Event queue */
+int etop = 0; /* Event queue top pointer */
+
+Boolean looking = FALSE; /* LOOKING? flag */
+
+int dscrstkp = 0; /* Describe-stack pointer */
+
+
+#ifdef _PROTOTYPES_
+void dscrobjs(void);
+void dscracts(void);
+#else
+void dscrobjs();
+void dscracts();
+#endif
+
+
+
+#ifdef _PROTOTYPES_
+void print(Aword fpos, Aword len)
+#else
+void print(fpos, len)
+ Aword fpos, len;
+#endif
+{
+ char str[2*WIDTH]; /* String buffer */
+ int outlen = 0; /* Current output length */
+ int ch;
+ int i;
+ long savfp; /* Temporary saved text file position */
+ static Boolean printFlag = FALSE; /* Printing already? */
+ Boolean savedPrintFlag = printFlag;
+ void *info; /* Saved decoding info */
+
+
+ if (len == 0) return;
+
+ if (isHere(HERO)) { /* Check if the player will see it */
+ if (printFlag) { /* Already printing? */
+ /* Save current text file position and/or decoding info */
+ if (header->pack)
+ info = pushDecode();
+ else
+ savfp = ftell(txtfil);
+ }
+ printFlag = TRUE; /* We're printing now! */
+ fseek(txtfil, fpos, 0); /* Position to start of text */
+ if (header->pack)
+ startDecoding();
+ for (outlen = 0; outlen != (int)len; outlen = outlen + strlen(str)) {
+ /* Fill the buffer from the beginning */
+ for (i = 0; i <= WIDTH || (i > WIDTH && ch != ' '); i++) {
+ if (outlen + i == (int)len) /* No more characters? */
+ break;
+ if (header->pack)
+ ch = decodeChar();
+ else
+ ch = getc(txtfil);
+ if (ch == EOFChar) /* Or end of text? */
+ break;
+ str[i] = ch;
+ }
+ str[i] = '\0';
+#if ISO == 0
+ fromIso(str, str);
+#endif
+ output(str);
+ }
+ /* And restore */
+ printFlag = savedPrintFlag;
+ if (printFlag) {
+ if (header->pack)
+ popDecode(info);
+ else
+ fseek(txtfil, savfp, 0);
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void sys(Aword fpos, Aword len)
+#else
+void sys(fpos, len)
+ Aword fpos, len;
+#endif
+{
+#ifdef GLK
+ ::error("system calls aren't supported");
+#else
+ char *command;
+
+ getstr(fpos, len); /* Returns address to string on stack */
+ command = (char *)pop();
+ int tmp = system(command);
+ free(command);
+#endif
+}
+
+
+#ifdef _PROTOTYPES_
+void getstr(Aword fpos, Aword len)
+#else
+void getstr(fpos, len)
+ Aword fpos, len;
+#endif
+{
+ char *buf = (char *)allocate(len+1);
+
+ push((Aptr) buf); /* Push the address to the string */
+ fseek(txtfil, fpos, 0); /* Position to start of text */
+ if (header->pack)
+ startDecoding();
+ while (len--)
+ if (header->pack)
+ *(buf++) = decodeChar();
+ else
+ *(buf++) = getc(txtfil);
+ *buf = '\0';
+}
+
+
+
+#ifdef _PROTOTYPES_
+void score(Aword sc)
+#else
+void score(sc)
+ Aword sc;
+#endif
+{
+ char buf[80];
+
+ if (sc == 0) {
+ prmsg(M_SCORE1);
+ sprintf(buf, "%d", cur.score);
+ output(buf);
+ prmsg(M_SCORE2);
+ sprintf(buf, "%ld.", (unsigned long) header->maxscore);
+ output(buf);
+ } else {
+ cur.score += scores[sc-1];
+ scores[sc-1] = 0;
+ }
+}
+
+#ifdef _PROTOTYPES_
+void visits(Aword v)
+#else
+void visits(v)
+ Aword v;
+#endif
+{
+ cur.visits = v;
+}
+
+
+#ifdef _PROTOTYPES_
+Boolean confirm(MsgKind msgno)
+#else
+Boolean confirm(msgno)
+ MsgKind msgno;
+#endif
+{
+ char buf[80];
+
+ /* This is a bit of a hack since we really want to compare the input,
+ it could be affirmative, but for now any input is NOT! */
+ prmsg(msgno);
+
+#ifdef USE_READLINE
+ if (!readline(buf)) return TRUE;
+#else
+ if (gets(buf) == NULL) return TRUE;
+#endif
+ col = 1;
+
+ return (buf[0] == '\0');
+}
+
+
+#ifdef _PROTOTYPES_
+void quit(void)
+#else
+void quit()
+#endif
+{
+ char buf[80];
+ char choices[10];
+
+ para();
+ while (TRUE) {
+ col = 1;
+ statusline();
+ prmsg(M_QUITACTION);
+#ifdef USE_READLINE
+ if (!readline(buf)) terminate(0);
+#else
+ if (gets(buf) == NULL) terminate(0);
+#endif
+ if (strcmp(buf, "restart") == 0)
+ //longjmp(restart_label, TRUE);
+ ::error("TODO: restart");
+ else if (strcmp(buf, "restore") == 0) {
+ restore();
+ return;
+ } else if (strcmp(buf, "quit") == 0)
+ terminate(0);
+ }
+ syserr("Fallthrough in QUIT");
+}
+
+
+
+#ifdef _PROTOTYPES_
+void restart(void)
+#else
+void restart()
+#endif
+{
+ para();
+ if (confirm(M_REALLY)) {
+ //longjmp(restart_label, TRUE);
+ ::error("TODO: restart");
+ } else
+ return;
+ syserr("Fallthrough in RESTART");
+}
+
+
+
+#ifdef _PROTOTYPES_
+void cancl(Aword evt)
+#else
+void cancl(evt)
+ Aword evt;
+#endif
+{
+ int i;
+
+ for(i = etop-1; i>=0; i--)
+ if (eventq[i].event == evt) {
+ while (i < etop-1) {
+ eventq[i].event = eventq[i+1].event;
+ eventq[i].time = eventq[i+1].time;
+ eventq[i].where = eventq[i+1].where;
+ i++;
+ }
+ etop--;
+ return;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void schedule(Aword evt, Aword whr, Aword aft)
+#else
+void schedule(evt, whr, aft)
+ Aword evt, whr, aft;
+#endif
+{ int i;
+ int time;
+
+ cancl(evt);
+ /* Check for overflow */
+ if (etop == N_EVTS) syserr("Out of event space.");
+
+ time = cur.tick+aft;
+
+ /* Bubble this event down */
+ for (i = etop; i >= 1 && eventq[i-1].time <= time; i--) {
+ eventq[i].event = eventq[i-1].event;
+ eventq[i].time = eventq[i-1].time;
+ eventq[i].where = eventq[i-1].where;
+ }
+
+ eventq[i].time = time;
+ eventq[i].where = whr;
+ eventq[i].event = evt;
+ etop++;
+}
+
+
+/*----------------------------------------------------------------------
+
+ getatr()
+
+ Get an attribute value from an attribute list
+
+ */
+#ifdef _PROTOTYPES_
+static Aptr getatr(
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aaddr atr /* IN - The attribute to read */
+)
+#else
+static Aptr getatr(atradr, atr)
+ Aaddr atradr; /* IN - ACODE address to attribute table */
+ Aaddr atr; /* IN - The attribute to read */
+#endif
+{
+ AtrElem *at;
+
+ at = (AtrElem *) addrTo(atradr);
+ return at[atr-1].val;
+}
+
+
+/*----------------------------------------------------------------------
+
+ setatr()
+
+ Set a particular attribute to a value.
+
+ */
+#ifdef _PROTOTYPES_
+static void setatr(
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aword atr, /* IN - attribute code */
+ Aword val /* IN - new value */
+)
+#else
+static void setatr(atradr, atr, val)
+ Aaddr atradr; /* IN - ACODE address to attribute table */
+ Aword atr; /* IN - attribute code */
+ Aword val; /* IN - new value */
+#endif
+{
+ AtrElem *at;
+
+ at = (AtrElem *) addrTo(atradr);
+ at[atr-1].val = val;
+}
+
+
+/*----------------------------------------------------------------------
+
+ make()
+
+ */
+
+#ifdef _PROTOTYPES_
+static void makloc(Aword loc, Aword atr, Aword val)
+#else
+static void makloc(loc, atr, val)
+ Aword loc, atr, val;
+#endif
+{
+ setatr(locs[loc-LOCMIN].atrs, atr, val);
+}
+
+#ifdef _PROTOTYPES_
+static void makobj(Aword obj, Aword atr, Aword val)
+#else
+static void makobj(obj, atr, val)
+ Aword obj, atr, val;
+#endif
+{
+ setatr(objs[obj-OBJMIN].atrs, atr, val);
+}
+
+#ifdef _PROTOTYPES_
+static void makact(Aword act, Aword atr, Aword val)
+#else
+static void makact(act, atr, val)
+ Aword act, atr, val;
+#endif
+{
+ setatr(acts[act-ACTMIN].atrs, atr, val);
+}
+
+
+#ifdef _PROTOTYPES_
+void make(Aword id, Aword atr, Aword val)
+#else
+void make(id, atr, val)
+ Aword id, atr, val;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ makobj(id, atr, val);
+ else if (isLoc(id))
+ makloc(id, atr, val);
+ else if (isAct(id))
+ makact(id, atr, val);
+ else {
+ sprintf(str, "Can't MAKE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+}
+
+
+/*----------------------------------------------------------------------------
+
+ set()
+
+ */
+
+#ifdef _PROTOTYPES_
+static void setloc(Aword loc, Aword atr, Aword val)
+#else
+static void setloc(loc, atr, val)
+ Aword loc, atr, val;
+#endif
+{
+ setatr(locs[loc-LOCMIN].atrs, atr, val);
+ locs[loc-LOCMIN].describe = 0;
+}
+
+
+#ifdef _PROTOTYPES_
+static void setobj(Aword obj, Aword atr, Aword val)
+#else
+static void setobj(obj, atr, val)
+ Aword obj, atr, val;
+#endif
+{
+ setatr(objs[obj-OBJMIN].atrs, atr, val);
+}
+
+#ifdef _PROTOTYPES_
+static void setact(Aword act, Aword atr, Aword val)
+#else
+static void setact(act, atr, val)
+ Aword act, atr, val;
+#endif
+{
+ setatr(acts[act-ACTMIN].atrs, atr, val);
+}
+
+
+#ifdef _PROTOTYPES_
+void set(Aword id, Aword atr, Aword val)
+#else
+void set(id, atr, val)
+ Aword id, atr, val;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ setobj(id, atr, val);
+ else if (isLoc(id))
+ setloc(id, atr, val);
+ else if (isAct(id))
+ setact(id, atr, val);
+ else {
+ sprintf(str, "Can't SET item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void setstr(Aword id, Aword atr, Aword str)
+#else
+void setstr(id, atr, str)
+ Aword id, atr, str;
+#endif
+{
+ free((char *)attribute(id, atr));
+ set(id, atr, str);
+}
+
+
+
+/*-----------------------------------------------------------------------------
+
+ incr/decr
+
+ */
+
+/*----------------------------------------------------------------------
+
+ incratr()
+
+ Increment a particular attribute by a value.
+
+ */
+#ifdef _PROTOTYPES_
+static void incratr(
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aword atr, /* IN - attribute code */
+ Aword step /* IN - step to increment by */
+)
+#else
+static void incratr(atradr, atr, step)
+ Aaddr atradr, atr, step;
+#endif
+{
+ AtrElem *at;
+
+ at = (AtrElem *) addrTo(atradr);
+ at[atr-1].val += step;
+}
+
+
+#ifdef _PROTOTYPES_
+static void incrloc(Aword loc, Aword atr, Aword step)
+#else
+static void incrloc(loc, atr, step)
+ Aword loc, atr, step;
+#endif
+{
+ incratr(locs[loc-LOCMIN].atrs, atr, step);
+ locs[loc-LOCMIN].describe = 0;
+}
+
+
+#ifdef _PROTOTYPES_
+static void incrobj(Aword obj, Aword atr, Aword step)
+#else
+static void incrobj(obj, atr, step)
+ Aword obj, atr, step;
+#endif
+{
+ incratr(objs[obj-OBJMIN].atrs, atr, step);
+}
+
+#ifdef _PROTOTYPES_
+static void incract(Aword act, Aword atr, Aword step)
+#else
+static void incract(act, atr, step)
+ Aword act, atr, step;
+#endif
+{
+ incratr(acts[act-ACTMIN].atrs, atr, step);
+}
+
+
+#ifdef _PROTOTYPES_
+void incr(Aword id, Aword atr, Aword step)
+#else
+void incr(id, atr, step)
+ Aword id, atr, step;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ incrobj(id, atr, step);
+ else if (isLoc(id))
+ incrloc(id, atr, step);
+ else if (isAct(id))
+ incract(id, atr, step);
+ else {
+ sprintf(str, "Can't INCR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+}
+
+#ifdef _PROTOTYPES_
+void decr(Aword id, Aword atr, Aword step)
+#else
+void decr(id, atr, step)
+ Aword id, atr, step;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ incrobj(id, atr, -step);
+ else if (isLoc(id))
+ incrloc(id, atr, -step);
+ else if (isAct(id))
+ incract(id, atr, -step);
+ else {
+ sprintf(str, "Can't DECR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ attribute()
+
+ */
+
+#ifdef _PROTOTYPES_
+static Aptr locatr(Aword loc, Aword atr)
+#else
+static Aptr locatr(loc, atr)
+ Aword loc, atr;
+#endif
+{
+ return getatr(locs[loc-LOCMIN].atrs, atr);
+}
+
+
+
+#ifdef _PROTOTYPES_
+static Aptr objatr(Aword obj, Aword atr)
+#else
+static Aptr objatr(obj, atr)
+ Aword obj, atr;
+#endif
+{
+ return getatr(objs[obj-OBJMIN].atrs, atr);
+}
+
+#ifdef _PROTOTYPES_
+static Aptr actatr(Aword act, Aword atr)
+#else
+static Aptr actatr(act, atr)
+ Aword act, atr;
+#endif
+{
+ return getatr(acts[act-ACTMIN].atrs, atr);
+}
+
+#ifdef _PROTOTYPES_
+static Aptr litatr(Aword lit, Aword atr)
+#else
+static Aptr litatr(lit, atr)
+ Aword lit, atr;
+#endif
+{
+ char str[80];
+
+ if (atr == 1)
+ return litValues[lit-LITMIN].value;
+ else {
+ sprintf(str, "Unknown attribute for literal (%ld).", (unsigned long) atr);
+ syserr(str);
+ }
+ return (Aptr)EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+Aptr attribute(Aword id, Aword atr)
+#else
+Aptr attribute(id, atr)
+ Aword id, atr;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ return objatr(id, atr);
+ else if (isLoc(id))
+ return locatr(id, atr);
+ else if (isAct(id))
+ return actatr(id, atr);
+ else if (isLit(id))
+ return litatr(id, atr);
+ else {
+ sprintf(str, "Can't ATTRIBUTE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Aptr)EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+Aptr strattr(Aword id, Aword atr)
+#else
+Aptr strattr(id, atr)
+ Aword id, atr;
+#endif
+{
+ return (Aptr) strdup((char *)attribute(id, atr));
+}
+
+
+/*----------------------------------------------------------------------
+
+ where()
+
+ */
+
+#ifdef _PROTOTYPES_
+static Aword objloc(Aword obj)
+#else
+static Aword objloc(obj)
+ Aword obj;
+#endif
+{
+ if (isCnt(objs[obj-OBJMIN].loc)) /* In something ? */
+ if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
+ return(where(objs[obj-OBJMIN].loc));
+ else /* Containers not anywhere is where the hero is! */
+ return(where(HERO));
+ else
+ return(objs[obj-OBJMIN].loc);
+}
+
+
+#ifdef _PROTOTYPES_
+static Aword actloc(Aword act)
+#else
+static Aword actloc(act)
+ Aword act;
+#endif
+{
+ return(acts[act-ACTMIN].loc);
+}
+
+
+#ifdef _PROTOTYPES_
+Aword where(Aword id)
+#else
+Aword where(id)
+ Aword id;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ return objloc(id);
+ else if (isAct(id))
+ return actloc(id);
+ else {
+ sprintf(str, "Can't WHERE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Aptr)EOF;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ aggregates
+
+ */
+
+#ifdef _PROTOTYPES_
+Aint agrmax(Aword atr, Aword whr)
+#else
+Aint agrmax(atr, whr)
+ Aword atr, whr;
+#endif
+{
+ Aword i;
+ Aint max = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr && attribute(i, atr) > max)
+ max = attribute(i, atr);
+ } else if (objs[i-OBJMIN].loc == whr && attribute(i, atr) > max)
+ max = attribute(i, atr);
+ }
+ return(max);
+}
+
+#ifdef _PROTOTYPES_
+Aint agrsum(Aword atr, Aword whr)
+#else
+Aint agrsum(atr, whr)
+ Aword atr, whr;
+#endif
+{
+ Aword i;
+ Aint sum = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr)
+ sum += attribute(i, atr);
+ } else if (objs[i-OBJMIN].loc == whr)
+ sum += attribute(i, atr);
+ }
+ return(sum);
+}
+
+
+#ifdef _PROTOTYPES_
+Aint agrcount(Aword whr)
+#else
+Aint agrcount(whr)
+ Aword whr;
+#endif
+{
+ Aword i;
+ Aword count = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr)
+ count++;
+ } else if (objs[i-OBJMIN].loc == whr)
+ count++;
+ }
+ return(count);
+}
+
+
+/*----------------------------------------------------------------------
+
+ locate()
+
+ */
+
+#ifdef _PROTOTYPES_
+static void locobj(Aword obj, Aword whr)
+#else
+static void locobj(obj, whr)
+ Aword obj, whr;
+#endif
+{
+ if (isCnt(whr)) { /* Into a container */
+ if (whr == obj)
+ syserr("Locating something inside itself.");
+ if (checklim(whr, obj))
+ return;
+ else
+ objs[obj-OBJMIN].loc = whr;
+ } else {
+ objs[obj-OBJMIN].loc = whr;
+ /* Make sure the location is described since it's changed */
+ locs[whr-LOCMIN].describe = 0;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void locact(Aword act, Aword whr)
+#else
+static void locact(act, whr)
+ Aword act, whr;
+#endif
+{
+ Aword prevact = cur.act;
+ Aword prevloc = cur.loc;
+
+ cur.loc = whr;
+ acts[act-ACTMIN].loc = whr;
+ if (act == HERO) {
+ if (locs[acts[act-ACTMIN].loc-LOCMIN].describe % (cur.visits+1) == 0)
+ look();
+ else {
+ if (anyOutput)
+ para();
+ say(where(HERO));
+ prmsg(M_AGAIN);
+ newline();
+ dscrobjs();
+ dscracts();
+ }
+ locs[where(HERO)-LOCMIN].describe++;
+ locs[where(HERO)-LOCMIN].describe %= (cur.visits+1);
+ } else
+ locs[whr-LOCMIN].describe = 0;
+ if (locs[cur.loc-LOCMIN].does != 0) {
+ cur.act = act;
+ interpret(locs[cur.loc-LOCMIN].does);
+ cur.act = prevact;
+ }
+
+ if (cur.act != act)
+ cur.loc = prevloc;
+}
+
+
+#ifdef _PROTOTYPES_
+void locate(Aword id, Aword whr)
+#else
+void locate(id, whr)
+ Aword id, whr;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ locobj(id, whr);
+ else if (isAct(id))
+ locact(id, whr);
+ else {
+ sprintf(str, "Can't LOCATE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ isHere()
+
+ */
+
+#ifdef _PROTOTYPES_
+static Abool objhere(Aword obj)
+#else
+static Abool objhere(obj)
+ Aword obj;
+#endif
+{
+ if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
+ if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
+ return(isHere(objs[obj-OBJMIN].loc));
+ else /* If the container wasn't anywhere, assume where HERO is! */
+ return(where(HERO) == cur.loc);
+ } else
+ return(objs[obj-OBJMIN].loc == cur.loc);
+}
+
+
+#ifdef _PROTOTYPES_
+static Aword acthere(Aword act)
+#else
+static Aword acthere(act)
+ Aword act;
+#endif
+{
+ return(acts[act-ACTMIN].loc == cur.loc);
+}
+
+
+#ifdef _PROTOTYPES_
+Abool isHere(Aword id)
+#else
+Abool isHere(id)
+ Aword id;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ return objhere(id);
+ else if (isAct(id))
+ return acthere(id);
+ else {
+ sprintf(str, "Can't HERE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Abool)EOF;
+}
+
+/*----------------------------------------------------------------------
+
+ isNear()
+
+ */
+
+#ifdef _PROTOTYPES_
+static Aword objnear(Aword obj)
+#else
+static Aword objnear(obj)
+ Aword obj;
+#endif
+{
+ if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
+ if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
+ return(isNear(objs[obj-OBJMIN].loc));
+ else /* If the container wasn't anywhere, assume here, so not nearby! */
+ return(FALSE);
+ } else
+ return(exitto(where(obj), cur.loc));
+}
+
+
+#ifdef _PROTOTYPES_
+static Aword actnear(Aword act)
+#else
+static Aword actnear(act)
+ Aword act;
+#endif
+{
+ return(exitto(where(act), cur.loc));
+}
+
+
+#ifdef _PROTOTYPES_
+Abool isNear(Aword id)
+#else
+Abool isNear(id)
+ Aword id;
+#endif
+{
+ char str[80];
+
+ if (isObj(id))
+ return objnear(id);
+ else if (isAct(id))
+ return actnear(id);
+ else {
+ sprintf(str, "Can't NEAR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Abool)EOF;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ in()
+
+ */
+
+#ifdef _PROTOTYPES_
+Abool in(Aword obj, Aword cnt)
+#else
+Abool in(obj, cnt)
+ Aword obj;
+ Aword cnt;
+#endif
+{
+ if (!isObj(obj))
+ return(FALSE);
+ if (!isCnt(cnt))
+ syserr("IN in a non-container.");
+
+ return(objs[obj-OBJMIN].loc == cnt);
+}
+
+
+/*----------------------------------------------------------------------
+
+ say()
+
+ */
+
+#ifdef _PROTOTYPES_
+static void sayloc(Aword loc)
+#else
+static void sayloc(loc)
+ Aword loc;
+#endif
+{
+ interpret(locs[loc-LOCMIN].nams);
+}
+
+
+#ifdef _PROTOTYPES_
+static void sayobj(Aword obj)
+#else
+static void sayobj(obj)
+ Aword obj;
+#endif
+{
+ interpret(objs[obj-OBJMIN].dscr2);
+}
+
+#ifdef _PROTOTYPES_
+static void sayact(Aword act)
+#else
+static void sayact(act)
+ Aword act;
+#endif
+{
+ interpret(acts[act-ACTMIN].nam);
+}
+
+
+#ifdef _PROTOTYPES_
+void sayint(Aword val)
+#else
+void sayint(val)
+ Aword val;
+#endif
+{
+ char buf[25];
+
+ if (isHere(HERO)) {
+ sprintf(buf, "%ld", (unsigned long) val);
+ output(buf);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void saystr(char *str)
+#else
+void saystr(str)
+ char *str;
+#endif
+{
+ if (isHere(HERO))
+ output(str);
+ free(str);
+}
+
+
+#ifdef _PROTOTYPES_
+static void saylit(Aword lit)
+#else
+static void saylit(lit)
+ Aword lit;
+#endif
+{
+ char *str;
+
+ if (isNum(lit))
+ sayint(litValues[lit-LITMIN].value);
+ else {
+ str = (char *)strdup((char *)litValues[lit-LITMIN].value);
+ saystr(str);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void sayarticle(Aword id)
+#else
+void sayarticle(id)
+ Aword id;
+#endif
+{
+ if (!isObj(id))
+ syserr("Trying to say article of something *not* an object.");
+ if (objs[id-OBJMIN].art != 0)
+ interpret(objs[id-OBJMIN].art);
+ else
+ prmsg(M_ARTICLE);
+}
+
+
+#ifdef _PROTOTYPES_
+void say(Aword id)
+#else
+void say(id)
+ Aword id;
+#endif
+{
+ char str[80];
+
+ if (isHere(HERO)) {
+ if (isObj(id))
+ sayobj(id);
+ else if (isLoc(id))
+ sayloc(id);
+ else if (isAct(id))
+ sayact(id);
+ else if (isLit(id))
+ saylit(id);
+ else {
+ sprintf(str, "Can't SAY item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ describe()
+
+ */
+
+#ifdef _PROTOTYPES_
+static void dscrloc(Aword loc)
+#else
+static void dscrloc(loc)
+ Aword loc;
+#endif
+{
+ if (locs[loc-LOCMIN].dscr != 0)
+ interpret(locs[loc-LOCMIN].dscr);
+}
+
+
+#ifdef _PROTOTYPES_
+static void dscrobj(Aword obj)
+#else
+static void dscrobj(obj)
+ Aword obj;
+#endif
+{
+ objs[obj-OBJMIN].describe = FALSE;
+ if (objs[obj-OBJMIN].dscr1 != 0)
+ interpret(objs[obj-OBJMIN].dscr1);
+ else {
+ prmsg(M_SEEOBJ1);
+ sayarticle(obj);
+ say(obj);
+ prmsg(M_SEEOBJ4);
+ if (objs[obj-OBJMIN].cont != 0)
+ list(obj);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void dscract(Aword act)
+#else
+static void dscract(act)
+ Aword act;
+#endif
+{
+ ScrElem *scr = NULL;
+
+ if (acts[act-ACTMIN].script != 0) {
+ for (scr = (ScrElem *) addrTo(acts[act-ACTMIN].scradr); !endOfTable(scr); scr++)
+ if (scr->code == acts[act-ACTMIN].script)
+ break;
+ if (endOfTable(scr)) scr = NULL;
+ }
+ if (scr != NULL && scr->dscr != 0)
+ interpret(scr->dscr);
+ else if (acts[act-ACTMIN].dscr != 0)
+ interpret(acts[act-ACTMIN].dscr);
+ else {
+ interpret(acts[act-ACTMIN].nam);
+ prmsg(M_SEEACT);
+ }
+ acts[act-ACTMIN].describe = FALSE;
+}
+
+
+static Aword dscrstk[255];
+
+#ifdef _PROTOTYPES_
+void describe(Aword id)
+#else
+void describe(id)
+ Aword id;
+#endif
+{
+ int i;
+ char str[80];
+
+ for (i = 0; i < dscrstkp; i++)
+ if (dscrstk[i] == id)
+ syserr("Recursive DESCRIBE.");
+ dscrstk[dscrstkp++] = id;
+
+ if (isObj(id))
+ dscrobj(id);
+ else if (isLoc(id))
+ dscrloc(id);
+ else if (isAct(id))
+ dscract(id);
+ else {
+ sprintf(str, "Can't DESCRIBE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+
+ dscrstkp--;
+}
+
+
+/*----------------------------------------------------------------------
+
+ use()
+
+ */
+
+#ifdef _PROTOTYPES_
+void use(Aword act, Aword scr)
+#else
+void use(act, scr)
+ Aword act, scr;
+#endif
+{
+ char str[80];
+
+ if (!isAct(act)) {
+ sprintf(str, "Item is not an Actor (%ld).", (unsigned long) act);
+ syserr(str);
+ }
+
+ acts[act-ACTMIN].script = scr;
+ acts[act-ACTMIN].step = 0;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ list()
+
+ */
+
+#ifdef _PROTOTYPES_
+void list(Aword cnt)
+#else
+void list(cnt)
+ Aword cnt;
+#endif
+{
+ int i;
+ Aword props;
+ Aword prevobj;
+ Boolean found = FALSE;
+ Boolean multiple = FALSE;
+
+ /* Find container properties */
+ if (isObj(cnt))
+ props = objs[cnt-OBJMIN].cont;
+ else if (isAct(cnt))
+ props = acts[cnt-ACTMIN].cont;
+ else
+ props = cnt;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (in(i, cnt)) { /* Yes, it's in this container */
+ if (!found) {
+ found = TRUE;
+ if (cnts[props-CNTMIN].header != 0)
+ interpret(cnts[props-CNTMIN].header);
+ else {
+ prmsg(M_CONTAINS1);
+ if (cnts[props-CNTMIN].nam != 0) /* It has it's own name */
+ interpret(cnts[props-CNTMIN].nam);
+ else
+ say(cnts[props-CNTMIN].parent); /* It is actually an object or actor */
+ prmsg(M_CONTAINS2);
+ }
+ } else {
+ if (multiple) {
+ needsp = FALSE;
+ prmsg(M_CONTAINS3);
+ }
+ multiple = TRUE;
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ prevobj = i;
+ }
+ }
+
+ if (found) {
+ if (multiple)
+ prmsg(M_CONTAINS4);
+ sayarticle(prevobj);
+ say(prevobj);
+ prmsg(M_CONTAINS5);
+ } else {
+ if (cnts[props-CNTMIN].empty != 0)
+ interpret(cnts[props-CNTMIN].empty);
+ else {
+ prmsg(M_EMPTY1);
+ if (cnts[props-CNTMIN].nam != 0) /* It has it's own name */
+ interpret(cnts[props-CNTMIN].nam);
+ else
+ say(cnts[props-CNTMIN].parent); /* It is actually an actor or object */
+ prmsg(M_EMPTY2);
+ }
+ }
+ needsp = TRUE;
+}
+
+
+/*----------------------------------------------------------------------
+
+ empty()
+
+ */
+
+#ifdef _PROTOTYPES_
+void empty(Aword cnt, Aword whr)
+#else
+void empty(cnt, whr)
+ Aword cnt;
+ Aword whr;
+#endif
+{
+ int i;
+
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (in(i, cnt))
+ locate(i, whr);
+}
+
+
+
+/*----------------------------------------------------------------------*\
+
+ Description of current location
+
+ dscrobjs()
+ dscracts()
+ look()
+
+\*----------------------------------------------------------------------*/
+
+#ifdef _PROTOTYPES_
+void dscrobjs(void)
+#else
+void dscrobjs()
+#endif
+{
+ int i;
+ int prevobj;
+ Boolean found = FALSE;
+ Boolean multiple = FALSE;
+
+ /* First describe everything here with its own description */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i-OBJMIN].loc == cur.loc &&
+ objs[i-OBJMIN].describe &&
+ objs[i-OBJMIN].dscr1)
+ describe(i);
+
+ /* Then list everything else here */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i-OBJMIN].loc == cur.loc &&
+ objs[i-OBJMIN].describe) {
+ if (!found) {
+ prmsg(M_SEEOBJ1);
+ sayarticle(i);
+ say(i);
+ found = TRUE;
+ } else {
+ if (multiple) {
+ needsp = FALSE;
+ prmsg(M_SEEOBJ2);
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ multiple = TRUE;
+ }
+ prevobj = i;
+ }
+
+ if (found) {
+ if (multiple) {
+ prmsg(M_SEEOBJ3);
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ prmsg(M_SEEOBJ4);
+ }
+
+ /* Set describe flag for all objects */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ objs[i-OBJMIN].describe = TRUE;
+}
+
+
+#ifdef _PROTOTYPES_
+void dscracts(void)
+#else
+void dscracts()
+#endif
+{
+ int i;
+
+ for (i = HERO+1; i <= ACTMAX; i++)
+ if (acts[i-ACTMIN].loc == cur.loc &&
+ acts[i-ACTMIN].describe)
+ describe(i);
+
+ /* Set describe flag for all actors */
+ for (i = HERO; i <= ACTMAX; i++)
+ acts[i-ACTMIN].describe = TRUE;
+}
+
+
+#ifdef _PROTOTYPES_
+void look(void)
+#else
+void look()
+#endif
+{
+ int i;
+
+ if (looking)
+ syserr("Recursive LOOK.");
+
+ looking = TRUE;
+ /* Set describe flag for all objects and actors */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ objs[i-OBJMIN].describe = TRUE;
+ for (i = ACTMIN; i <= ACTMAX; i++)
+ acts[i-ACTMIN].describe = TRUE;
+
+ if (anyOutput)
+ para();
+
+g_vm->glk_set_style(style_Subheader);
+needsp = FALSE;
+ say(cur.loc);
+ needsp = FALSE;
+ output(".");
+g_vm->glk_set_style(style_Normal);
+ newline();
+needsp = FALSE;
+ describe(cur.loc);
+ dscrobjs();
+ dscracts();
+ looking = FALSE;
+}
+
+
+
+static char savfnm[256];
+
+
+/*----------------------------------------------------------------------
+
+ save()
+
+ */
+
+#ifdef GARGLK
+void save() {
+ g_vm->saveGame();
+}
+
+#else
+
+#ifdef _PROTOTYPES_
+void save(void)
+#else
+void save()
+#endif
+{
+ int i;
+ char str[256];
+ AtrElem *atr;
+ FILE *savfil;
+
+ /* First save ? */
+ if (savfnm[0] == '\0') {
+ strcpy(savfnm, advnam);
+ strcat(savfnm, ".sav");
+ }
+ prmsg(M_SAVEWHERE);
+ sprintf(str, "(%s) : ", savfnm);
+ output(str);
+
+#ifdef USE_READLINE
+ readline(str);
+#else
+ gets(str);
+#endif
+
+frefid_t fref;
+fref = g_vm->glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Write, 0);
+if (fref == NULL)
+ error(M_SAVEFAILED);
+strcpy(str, g_vm->garglk_fileref_get_name(fref));
+g_vm->glk_fileref_destroy(fref);
+
+ if (str[0] == '\0')
+ strcpy(str, savfnm);
+ col = 1;
+ if ((savfil = fopen(str, READ_MODE)) != NULL)
+ /* It already existed */
+ if (!confirm(M_SAVEOVERWRITE))
+ error(MSGMAX); /* Return to player without saying anything */
+ if ((savfil = fopen(str, WRITE_MODE)) == NULL)
+ error(M_SAVEFAILED);
+ strcpy(savfnm, str);
+
+ /* Save version of interpreter and name of game */
+ fwrite((void *)&header->vers, sizeof(Aword), 1, savfil);
+ fwrite((void *)advnam, strlen(advnam)+1, 1, savfil);
+ /* Save current values */
+ fwrite((void *)&cur, sizeof(cur), 1, savfil);
+ /* Save actors */
+ for (i = ACTMIN; i <= ACTMAX; i++) {
+ fwrite((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil);
+ fwrite((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil);
+ fwrite((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil);
+ fwrite((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil);
+ if (acts[i-ACTMIN].atrs)
+ for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++)
+ fwrite((void *)&atr->val, sizeof(Aword), 1, savfil);
+ }
+
+ /* Save locations */
+ for (i = LOCMIN; i <= LOCMAX; i++) {
+ fwrite((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil);
+ if (locs[i-LOCMIN].atrs)
+ for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
+ fwrite((void *)&atr->val, sizeof(Aword), 1, savfil);
+ }
+
+ /* Save objects */
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ fwrite((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil);
+ if (objs[i-OBJMIN].atrs)
+ for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
+ fwrite((void *)&atr->val, sizeof(atr->val), 1, savfil);
+ }
+
+ /* Save the event queue */
+ eventq[etop].time = 0; /* Mark the top */
+ fwrite((void *)&eventq[0], sizeof(eventq[0]), etop+1, savfil);
+
+ /* Save scores */
+ for (i = 0; scores[i] != EOF; i++)
+ fwrite((void *)&scores[i], sizeof(Aword), 1, savfil);
+
+ fclose(savfil);
+}
+#endif
+
+/*----------------------------------------------------------------------
+
+ restore()
+
+ */
+
+#ifdef GARGLK
+void restore() {
+ g_vm->loadGame();
+}
+
+#else
+
+#ifdef _PROTOTYPES_
+void restore(void)
+#else
+void restore()
+#endif
+{
+ int i,tmp;
+ FILE *savfil;
+ char str[256];
+ AtrElem *atr;
+ char savedVersion[4];
+ char savedName[256];
+
+ /* First save ? */
+ if (savfnm[0] == '\0') {
+ strcpy(savfnm, advnam);
+ strcat(savfnm, ".sav");
+ }
+ prmsg(M_RESTOREFROM);
+ sprintf(str, "(%s) : ", savfnm);
+ output(str);
+#ifdef USE_READLINE
+ readline(str);
+#else
+ gets(str);
+#endif
+
+ if (str[0] == '\0')
+ strcpy(str, savfnm);
+ col = 1;
+ if (str[0] == '\0')
+ strcpy(str, savfnm); /* Use the name temporarily */
+ if ((savfil = fopen(str, READ_MODE)) == NULL)
+ error(M_SAVEMISSING);
+ strcpy(savfnm, str); /* Save it for future use */
+
+ tmp = fread((void *)&savedVersion, sizeof(Aword), 1, savfil);
+ /* 4f - save file version check doesn't seem to work on PC's! */
+ if (strncmp(savedVersion, header->vers, 4)) {
+ fclose(savfil);
+ error(M_SAVEVERS);
+ return;
+ }
+ i = 0;
+ while ((savedName[i++] = fgetc(savfil)) != '\0');
+ if (strcmp(savedName, advnam) != 0) {
+ fclose(savfil);
+ error(M_SAVENAME);
+ return;
+ }
+
+ /* Restore current values */
+ tmp = fread((void *)&cur, sizeof(cur), 1, savfil);
+ /* Restore actors */
+ for (i = ACTMIN; i <= ACTMAX; i++) {
+ tmp = fread((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil);
+ tmp = fread((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil);
+ tmp = fread((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil);
+ tmp = fread((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil);
+ if (acts[i-ACTMIN].atrs)
+ for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++)
+ tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil);
+ }
+
+ /* Restore locations */
+ for (i = LOCMIN; i <= LOCMAX; i++) {
+ tmp = fread((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil);
+ if (locs[i-LOCMIN].atrs)
+ for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
+ tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil);
+ }
+
+ /* Restore objects */
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ tmp = fread((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil);
+ if (objs[i-OBJMIN].atrs)
+ for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
+ tmp = fread((void *)&atr->val, sizeof(atr->val), 1, savfil);
+ }
+
+ /* Restore the eventq */
+ etop = 0;
+ do {
+ tmp = fread((void *)&eventq[etop], sizeof(eventq[0]), 1, savfil);
+ etop++;
+ } while (eventq[etop-1].time != 0);
+ etop--;
+
+ /* Restore scores */
+ for (i = 0; scores[i] != EOF; i++)
+ tmp = fread((void *)&scores[i], sizeof(Aword), 1, savfil);
+
+ fclose(savfil);
+}
+
+#endif
+
+/*----------------------------------------------------------------------
+
+ rnd()
+
+ */
+
+#ifdef _PROTOTYPES_
+Aword rnd(Aword from, Aword to)
+#else
+Aword rnd(from, to)
+ Aword from, to;
+#endif
+{
+ if (to == from)
+ return to;
+ else if (to > from)
+ return (rand()/10)%(to-from+1)+from;
+ else
+ return (rand()/10)%(from-to+1)+to;
+}
+
+/*----------------------------------------------------------------------
+
+ btw()
+
+ BETWEEN
+
+ */
+
+#ifdef _PROTOTYPES_
+Abool btw(Aint val, Aint low, Aint high)
+#else
+Abool btw(val, low, high)
+ Aint val, low, high;
+#endif
+{
+ if (high > low)
+ return low <= val && val <= high;
+ else
+ return high <= val && val <= low;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ contains()
+
+ */
+
+#ifdef _PROTOTYPES_
+Aword contains(Aptr string, Aptr substring)
+#else
+Aword contains(string, substring)
+ Aptr string, substring;;
+#endif
+{
+ Abool found;
+
+ strlow((char *)string);
+ strlow((char *)substring);
+
+ found = (strstr((char *)string, (char *)substring) != 0);
+
+ free((char *)string);
+ free((char *)substring);
+
+ return(found);
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ streq()
+
+ Compare two strings approximately, ignore case
+
+ */
+#ifdef _PROTOTYPES_
+Abool streq(char a[], char b[])
+#else
+Abool streq(a, b)
+ char a[], b[]; /* IN - Strings to compare */
+#endif
+{
+ Boolean eq;
+
+ strlow(a);
+ strlow(b);
+
+ eq = (strcmp(a, b) == 0);
+
+ free(a);
+ free(b);
+
+ return(eq);
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
new file mode 100644
index 0000000..0acfdda
--- /dev/null
+++ b/engines/glk/alan2/exe.h
@@ -0,0 +1,127 @@
+/* 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 GLK_ALAN2_EXE
+#define GLK_ALAN2_EXE
+
+/* Header file for instruction execution unit in Alan interpreter
+ */
+
+namespace Glk {
+namespace Alan2 {
+
+/* The event queue */
+extern EvtqElem eventq[]; /* Event queue */
+extern int etop; /* Event queue top pointer */
+extern Boolean looking; /* LOOKING? flag */
+extern int dscrstkp; /* Point into describe stack */
+
+#ifdef _PROTOTYPES_
+extern void sys(Aword fpos, Aword len);
+extern Boolean confirm(MsgKind msgno);
+extern Aptr attribute(Aword item, Aword atr);
+extern void say(Aword item);
+extern void saynum(Aword num);
+extern void saystr(char *str);
+extern Aptr strattr(Aword id, Aword atr);
+extern void setstr(Aword id, Aword atr, Aword str);
+extern void getstr(Aword fpos, Aword len);
+extern void print(Aword fpos, Aword len);
+extern void look(void);
+extern void make(Aword id, Aword atr, Aword val);
+extern void set(Aword id, Aword atr, Aword val);
+extern void incr(Aword id, Aword atr, Aword step);
+extern void decr(Aword id, Aword atr, Aword step);
+extern void use(Aword act, Aword scr);
+extern void describe(Aword id);
+extern void list(Aword cnt);
+extern void locate(Aword id, Aword whr);
+extern void empty(Aword cnt, Aword whr);
+extern void score(Aword sc);
+extern void visits(Aword v);
+extern void schedule(Aword evt, Aword whr, Aword aft);
+extern void cancl(Aword evt);
+extern void quit(void);
+extern void restart(void);
+extern void save(void);
+extern void restore(void);
+extern void say(Aword id);
+extern void sayint(Aword val);
+extern Aword rnd(Aword from, Aword to);
+extern Abool btw(Aint val, Aint from, Aint to);
+extern Aword contains(Aptr string, Aptr substring);
+extern Abool streq(char a[], char b[]);
+extern Abool in(Aword obj, Aword cnt);
+extern Aword where(Aword item);
+extern Aint agrmax(Aword atr, Aword whr);
+extern Aint agrsum(Aword atr, Aword whr);
+extern Aint agrcount(Aword whr);
+extern Abool isHere(Aword item);
+extern Abool isNear(Aword item);
+
+#else
+extern void sys();
+extern Boolean confirm();
+extern Aptr attribute();
+extern void say();
+extern void saynum();
+extern void saystr();
+extern Aptr strattr();
+extern void setstr();
+extern void getstr();
+extern void print();
+extern void look();
+extern void make();
+extern void set();
+extern void incr();
+extern void decr();
+extern void use();
+extern void describe();
+extern void list();
+extern void locate();
+extern void empty();
+extern void score();
+extern void visits();
+extern void schedule();
+extern void cancl();
+extern void quit();
+extern void restart();
+extern void save();
+extern void restore();
+extern void say();
+extern void sayint();
+extern Aword rnd();
+extern Abool btw();
+extern Aword contains()
+extern Abool streq();
+extern Abool in();
+extern Aword where();
+extern Aword agrmax();
+extern Aword agrsum();
+extern Abool isHere();
+extern Abool isNear();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/glkio.cpp b/engines/glk/alan2/glkio.cpp
new file mode 100644
index 0000000..3464131
--- /dev/null
+++ b/engines/glk/alan2/glkio.cpp
@@ -0,0 +1,47 @@
+/* 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/glk.h"
+#include "glk/alan2/alan2.h"
+#include "glk/alan2/glkio.h"
+
+namespace Glk {
+namespace Alan2 {
+
+void glkio_printf(char *fmt, ...) {
+ va_list argp;
+ va_start(argp, fmt);
+ if (glkMainWin) {
+ char buf[1024]; /* FIXME: buf size should be foolproof */
+ vsprintf(buf, fmt, argp);
+ g_vm->glk_put_string(buf);
+ } else {
+ // assume stdio is available in this case only
+ Common::String str = Common::String::vformat(fmt, argp);
+ warning(fmt, argp);
+ }
+
+ va_end(argp);
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/glkio.h b/engines/glk/alan2/glkio.h
new file mode 100644
index 0000000..7dca2ca
--- /dev/null
+++ b/engines/glk/alan2/glkio.h
@@ -0,0 +1,48 @@
+/* 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 GLK_ALAN2_GLKIO
+#define GLK_ALAN2_GLKIO
+
+/* Header file for Glk output for Alan interpreter
+ */
+
+#include "glk/windows.h"
+
+namespace Glk {
+namespace Alan2 {
+
+winid_t glkMainWin;
+winid_t glkStatusWin;
+
+/* NB: this header must be included in any file which calls print() */
+
+#define print glkio_printf
+#undef printf
+#define printf glkio_printf
+
+void glkio_printf(char *, ...);
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/glkstart.cpp b/engines/glk/alan2/glkstart.cpp
new file mode 100644
index 0000000..1119e18
--- /dev/null
+++ b/engines/glk/alan2/glkstart.cpp
@@ -0,0 +1,65 @@
+/* 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/alan2/alan2.h"
+#include "glk/alan2/glkstart.h"
+#include "glk/alan2/glkio.h"
+#include "glk/alan2/args.h"
+
+#include "glk/alan2/alan_version.h"
+
+namespace Glk {
+namespace Alan2 {
+
+glkunix_argumentlist_t glkunix_arguments[] = {
+ { "-v", glkunix_arg_NoValue, "-v: verbose mode" },
+ { "-l", glkunix_arg_NoValue, "-l: log player command and game output" },
+ { "-i", glkunix_arg_NoValue, "-i: ignore version and checksum errors" },
+ { "-d", glkunix_arg_NoValue, "-d: enter debug mode" },
+ { "-t", glkunix_arg_NoValue, "-t: trace game execution" },
+ { "-s", glkunix_arg_NoValue, "-s: single instruction trace" },
+ { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
+ { NULL, glkunix_arg_End, NULL }
+};
+
+bool glkunix_startup_code(glkunix_startup_t *data) {
+ // first, open a window for error output
+ glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
+ if (glkMainWin == nullptr)
+ error("FATAL ERROR: Cannot open initial window");
+
+ g_vm->glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
+ glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
+ winmethod_Fixed, 1, wintype_TextGrid, 0);
+ g_vm->glk_set_window(glkMainWin);
+
+ /* now process the command line arguments */
+ args(data->argc, data->argv);
+
+ g_vm->garglk_set_program_name(alan.shortHeader);
+ g_vm->garglk_set_program_info("Alan Interpreter 2.8.6 by Thomas Nilsson\n");
+
+ return true;
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/glkstart.h b/engines/glk/alan2/glkstart.h
new file mode 100644
index 0000000..7e3a24b
--- /dev/null
+++ b/engines/glk/alan2/glkstart.h
@@ -0,0 +1,70 @@
+/* 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 GLK_ALAN2_GLK_START
+#define GLK_ALAN2_GLK_START
+
+/* This header defines an interface that must be used by program linked
+ with the various Unix Glk libraries -- at least, the three I wrote.
+ (I encourage anyone writing a Unix Glk library to use this interface,
+ but it's not part of the Glk spec.)
+
+ Because Glk is *almost* perfectly portable, this interface *almost*
+ doesn't have to exist. In practice, it's small.
+*/
+
+namespace Glk {
+namespace Alan2 {
+
+#define glkunix_arg_End (0)
+#define glkunix_arg_ValueFollows (1)
+#define glkunix_arg_NoValue (2)
+#define glkunix_arg_ValueCanFollow (3)
+#define glkunix_arg_NumberValue (4)
+
+typedef struct glkunix_argumentlist_struct {
+ char *name;
+ int argtype;
+ char *desc;
+} glkunix_argumentlist_t;
+
+typedef struct glkunix_startup_struct {
+ int argc;
+ char **argv;
+} glkunix_startup_t;
+
+/* The list of command-line arguments; this should be defined in your code. */
+extern glkunix_argumentlist_t glkunix_arguments[];
+
+/* The external function; this should be defined in your code. */
+extern bool glkunix_startup_code(glkunix_startup_t *data);
+
+/* Some helpful utility functions which the library makes available
+ to your code. Obviously, this is nonportable; so you should
+ only call it from glkunix_startup_code().
+*/
+extern strid_t glkunix_stream_open_pathname(char *pathname, uint textmode, uint rock);
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
new file mode 100644
index 0000000..02b4f48
--- /dev/null
+++ b/engines/glk/alan2/inter.cpp
@@ -0,0 +1,893 @@
+/* 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 <string>
+#include "glk/alan2/types.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/parse.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/stack.h"
+#include "glk/alan2/sysdep.h"
+
+#include "glk/alan2/inter.h"
+
+#ifdef GLK
+#include "glk/alan2/glkio.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+/* PRIVATE DATA */
+
+static int pc;
+
+
+#ifdef _PROTOTYPES_
+static void if_(
+ Aword v
+)
+#else
+static void if_(v)
+ Aword v;
+#endif
+{
+ int lev = 1;
+ Aword i;
+
+ if (!v) {
+ /* Skip to next ELSE or ENDIF on same level */
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_ELSE:
+ if (lev == 1) return;
+ break;
+ case I_IF:
+ lev++;
+ break;
+ case I_ENDIF:
+ lev--;
+ if (lev == 0) return;
+ break;
+ }
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void else_(void)
+#else
+static void else_()
+#endif
+{
+ int lev = 1;
+ Aword i;
+
+ while (TRUE) {
+ /* Skip to ENDIF on the same level */
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_ENDIF:
+ lev--;
+ if (lev == 0) return;
+ break;
+ case I_IF:
+ lev++;
+ break;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void depstart(void)
+#else
+static void depstart(void)
+#endif
+{
+ /* A DEPSTART was executed so skip across the redundant DEPCASE to
+ start at the first expression */
+ pc++;
+}
+
+
+#ifdef _PROTOTYPES_
+static void swap(void)
+#else
+static void swap()
+#endif
+{
+ Aptr v1 = pop();
+ Aptr v2 = pop();
+
+ push(v1);
+ push(v2);
+}
+
+
+
+#ifdef _PROTOTYPES_
+static void depexec(
+ Aword v
+)
+#else
+static void depexec(v)
+ Aword v;
+#endif
+{
+ int lev = 1;
+ Aword i;
+
+ if (!v)
+ /* The expression was not true, skip to next CASE on the same
+ level which could be a DEPCASE or DEPELSE */
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_DEPSTART:
+ lev++;
+ break;
+ case I_DEPEND:
+ if (lev == 1) return;
+ lev--;
+ break;
+ case I_DEPCASE:
+ case I_DEPELSE:
+ if (lev == 1) return;
+ break;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void depcase(void)
+#else
+static void depcase()
+#endif
+{
+ int lev = 1;
+ Aword i;
+
+ /* Skip to end of DEPENDING block (next DEPEND on same level) because
+ we have just executed a DEPCASE/DEPELSE statement as a result of a DEPCASE
+ catching */
+
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_DEPSTART:
+ lev++;
+ break;
+ case I_DEPEND:
+ lev--;
+ if (lev == 0) return;
+ break;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void interpret(Aaddr adr)
+#else
+void interpret(adr)
+ Aaddr adr;
+#endif
+{
+ Aaddr oldpc;
+ Aword i;
+
+ if (stpflg) printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++");
+
+ oldpc = pc;
+ pc = adr;
+ while(TRUE) {
+ if (stpflg) printf("\n%4x: ", pc);
+ if (pc > memTop)
+ syserr("Interpreting outside program.");
+
+ i = memory[pc++];
+
+ switch (I_CLASS(i)) {
+ case C_CONST:
+ if (stpflg) printf("PUSH \t%5ld", I_OP(i));
+ push(I_OP(i));
+ break;
+ case C_CURVAR:
+ switch (I_OP(i)) {
+ case V_PARAM:
+ if (stpflg) printf("PARAM \t%5ld\t\t(%ld)", top(), params[top()-1].code);
+ push(params[pop()-1].code);
+ break;
+ case V_CURLOC:
+ if (stpflg) printf("CURLOC \t\t\t(%d)", cur.loc);
+ push(cur.loc);
+ break;
+ case V_CURACT:
+ if (stpflg) printf("CURACT \t\t\t(%d)", cur.act);
+ push(cur.act);
+ break;
+ case V_CURVRB:
+ if (stpflg) printf("CURVRB \t\t\t(%d)", cur.vrb);
+ push(cur.vrb);
+ break;
+ case V_SCORE:
+ if (stpflg) printf("CURSCORE \t\t\t(%d)", cur.score);
+ push(cur.score);
+ break;
+ default:
+ syserr("Unknown CURVAR instruction.");
+ break;
+ }
+ break;
+
+ case C_STMOP:
+ switch (I_OP(i)) {
+ case I_PRINT: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg) {
+ printf("PRINT \t%5ld, %5ld\t\"", fpos, len);
+ col = 34; /* To format it better! */
+ }
+ print((char *)fpos, len);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SYSTEM: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg) {
+ printf("SYSTEM \t%5ld, %5ld\t\"", fpos, len);
+ col = 34; /* To format it better! */
+ }
+ sys(fpos, len);
+ break;
+ }
+ case I_GETSTR: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg)
+ printf("GETSTR\t%5ld, %5ld", fpos, len);
+ getstr(fpos, len);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_QUIT: {
+ if (stpflg)
+ printf("QUIT");
+ quit();
+ break;
+ }
+ case I_LOOK: {
+ if (stpflg)
+ printf("LOOK");
+ look();
+ break;
+ }
+ case I_SAVE: {
+ if (stpflg)
+ printf("SAVE");
+ save();
+ break;
+ }
+ case I_RESTORE: {
+ if (stpflg)
+ printf("RESTORE");
+ restore();
+ break;
+ }
+ case I_RESTART: {
+ if (stpflg)
+ printf("RESTART");
+ restart();
+ break;
+ }
+ case I_LIST: {
+ Aptr cnt;
+ cnt = pop();
+ if (stpflg)
+ printf("LIST \t%5ld", cnt);
+ list(cnt);
+ break;
+ }
+ case I_EMPTY: {
+ Aptr cnt, whr;
+ cnt = pop();
+ whr = pop();
+ if (stpflg)
+ printf("EMPTY \t%5ld, %5ld", cnt, whr);
+ empty(cnt, whr);
+ break;
+ }
+ case I_SCORE: {
+ Aptr sc;
+ sc = pop();
+ if (stpflg)
+ printf("SCORE \t%5ld\t\t(%ld)", sc, scores[sc-1]);
+ score(sc);
+ break;
+ }
+ case I_VISITS: {
+ Aptr v;
+ v = pop();
+ if (stpflg)
+ printf("VISITS \t%5ld", v);
+ visits(v);
+ break;
+ }
+ case I_SCHEDULE: {
+ Aptr evt, whr, aft;
+ evt = pop();
+ whr = pop();
+ aft = pop();
+ if (stpflg)
+ printf("SCHEDULE \t%5ld, %5ld, %5ld", evt, whr, aft);
+ schedule(evt, whr, aft);
+ break;
+ }
+ case I_CANCEL: {
+ Aptr evt;
+ evt = pop();
+ if (stpflg)
+ printf("CANCEL \t%5ld", evt);
+ cancl(evt);
+ break;
+ }
+ case I_MAKE: {
+ Aptr id, atr, val;
+ id = pop();
+ atr = pop();
+ val = pop();
+ if (stpflg) {
+ printf("MAKE \t%5ld, %5ld, ", id, atr);
+ if (val) printf("TRUE"); else printf("FALSE");
+ }
+ make(id, atr, val);
+ break;
+ }
+ case I_SET: {
+ Aptr id, atr, val;
+ id = pop();
+ atr = pop();
+ val = pop();
+ if (stpflg) {
+ printf("SET \t%5ld, %5ld, %5ld", id, atr, val);
+ }
+ set(id, atr, val);
+ break;
+ }
+ case I_STRSET: {
+ Aptr id, atr, str;
+ id = pop();
+ atr = pop();
+ str = pop();
+ if (stpflg) {
+ printf("STRSET\t%5ld, %5ld, %5ld", id, atr, str);
+ }
+ setstr(id, atr, str);
+ break;
+ }
+ case I_INCR: {
+ Aptr id, atr, step;
+ id = pop();
+ atr = pop();
+ step = pop();
+ if (stpflg) {
+ printf("INCR\t%5ld, %5ld, %5ld", id, atr, step);
+ }
+ incr(id, atr, step);
+ break;
+ }
+ case I_DECR: {
+ Aptr id, atr, step;
+ id = pop();
+ atr = pop();
+ step = pop();
+ if (stpflg) {
+ printf("DECR\t%5ld, %5ld, %5ld", id, atr, step);
+ }
+ decr(id, atr, step);
+ break;
+ }
+ case I_ATTRIBUTE: {
+ Aptr id, atr;
+ id = pop();
+ atr = pop();
+ if (stpflg)
+ printf("ATTRIBUTE %5ld, %5ld", id, atr);
+ push(attribute(id, atr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_STRATTR: {
+ Aptr id, atr;
+ id = pop();
+ atr = pop();
+ if (stpflg)
+ printf("STRATTR \t%5ld, %5ld", id, atr);
+ push(strattr(id, atr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_LOCATE: {
+ Aptr id, whr;
+ id = pop();
+ whr = pop();
+ if (stpflg)
+ printf("LOCATE \t%5ld, %5ld", id, whr);
+ locate(id, whr);
+ break;
+ }
+ case I_WHERE: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("WHERE \t%5ld", id);
+ push(where(id));
+ if (stpflg)
+ printf("\t\t(%ld)", top());
+ break;
+ }
+ case I_HERE: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("HERE \t%5ld", id);
+ push(isHere(id));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_NEAR: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("NEAR \t%5ld", id);
+ push(isNear(id));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_USE: {
+ Aptr act, scr;
+ act = pop();
+ scr = pop();
+ if (stpflg)
+ printf("USE \t%5ld, %5ld", act, scr);
+ use(act, scr);
+ break;
+ }
+ case I_IN: {
+ Aptr obj, cnt;
+ obj = pop();
+ cnt = pop();
+ if (stpflg)
+ printf("IN \t%5ld, %5ld ", obj, cnt);
+ push(in(obj, cnt));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_DESCRIBE: {
+ Aptr id;
+ id = pop();
+ if (stpflg) {
+ printf("DESCRIBE \t%5ld\t", id);
+ col = 34; /* To format it better! */
+ }
+ describe(id);
+ break;
+ }
+ case I_SAY: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("SAY \t%5ld\t\t\"", id);
+ say(id);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SAYINT: {
+ Aptr val;
+ val = pop();
+ if (stpflg)
+ printf("SAYINT\t%5ld\t\t\"", val);
+ sayint(val);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SAYSTR: {
+ Aptr adr;
+ adr = pop();
+ if (stpflg)
+ printf("SAYSTR\t%5ld\t\t\"", adr);
+ saystr((char *)adr);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_IF: {
+ Aptr v;
+ v = pop();
+ if (stpflg) {
+ printf("IF \t");
+ if (v) printf(" TRUE"); else printf("FALSE");
+ }
+ if_(v);
+ break;
+ }
+ case I_ELSE: {
+ if (stpflg)
+ printf("ELSE");
+ else_();
+ break;
+ }
+ case I_ENDIF: {
+ if (stpflg)
+ printf("ENDIF");
+ break;
+ }
+ case I_AND: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg) {
+ printf("AND \t");
+ if (lh) printf("TRUE, "); else printf("FALSE, ");
+ if (rh) printf("TRUE"); else printf("FALSE");
+ }
+ push(lh && rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_OR: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg) {
+ printf("OR \t");
+ if (lh) printf("TRUE, "); else printf("FALSE, ");
+ if (rh) printf("TRUE"); else printf("FALSE");
+ }
+ push(lh || rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_NE: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("NE \t%5ld, %5ld", lh, rh);
+ push(lh != rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_EQ: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("EQ \t%5ld, %5ld", lh, rh);
+ push(lh == rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_STREQ: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("STREQ \t%5ld, %5ld", lh, rh);
+ push(streq((char *)lh, (char *)rh));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_STREXACT: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("STREXACT \t%5ld, %5ld", lh, rh);
+ push(strcmp((char *)lh, (char *)rh) == 0);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ free((void *)lh);
+ free((void *)rh);
+ break;
+ }
+ case I_LE: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("LE \t%5ld, %5ld", lh, rh);
+ push(lh <= rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_GE: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("GE \t%5ld, %5ld", lh, rh);
+ push(lh >= rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_LT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("LT \t%5ld, %5ld", lh, rh);
+ push((signed int)lh < (signed int)rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_GT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("GT \t%5ld, %5ld", lh, rh);
+ push(lh > rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
+ break;
+ }
+ case I_PLUS: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("PLUS \t%5ld, %5ld", lh, rh);
+ push(lh + rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_MINUS: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("MINUS \t%5ld, %5ld", lh, rh);
+ push(lh - rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_MULT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("MULT \t%5ld, %5ld", lh, rh);
+ push(lh * rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_DIV: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("DIV \t%5ld, %5ld", lh, rh);
+ push(lh / rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_NOT: {
+ Aptr val;
+ val = pop();
+ if (stpflg) {
+ printf("NOT \t");
+ if (val) printf("TRUE"); else printf("FALSE");
+ }
+ push(!val);
+ if (stpflg)
+ if (top()) printf("\t\t(TRUE)"); else printf("\t\t(FALSE)");
+ break;
+ }
+ case I_MAX: {
+ Aptr atr, whr;
+ atr = pop();
+ whr = pop();
+ if (stpflg)
+ printf("MAX \t%5ld, %5ld", atr, whr);
+ push(agrmax(atr, whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_SUM: {
+ Aptr atr, whr;
+ atr = pop();
+ whr = pop();
+ if (stpflg)
+ printf("SUM \t%5ld, %5ld", atr, whr);
+ push(agrsum(atr, whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_COUNT: {
+ Aptr whr;
+ whr = pop();
+ if (stpflg)
+ printf("COUNT \t%5ld", whr);
+ push(agrcount(whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_RND: {
+ Aptr from, to;
+ from = pop();
+ to = pop();
+ if (stpflg)
+ printf("RANDOM \t%5ld, %5ld", from, to);
+ push(rnd(from, to));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_BTW: {
+ Aint low, high, val;
+ high = pop();
+ low = pop();
+ val = pop();
+ if (stpflg)
+ printf("BETWEEN \t%5ld, %5ld, %5ld", val, low, high);
+ push(btw(val, low, high));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_CONTAINS: {
+ Aptr string, substring;
+ substring = pop();
+ string = pop();
+ if (stpflg)
+ printf("CONTAINS \t%5ld, %5ld", string, substring);
+ push(contains(string, substring));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+
+ case I_DEPSTART:
+ if (stpflg)
+ printf("DEPSTART");
+ depstart();
+ break;
+
+ case I_DEPCASE:
+ if (stpflg)
+ printf("DEPCASE");
+ depcase();
+ break;
+
+ case I_DEPEXEC: {
+ Aptr v;
+ v = pop();
+ if (stpflg) {
+ printf("DEPEXEC \t");
+ if (v) printf(" TRUE"); else printf("FALSE");
+ }
+ depexec(v);
+ break;
+ }
+
+ case I_DEPELSE:
+ if (stpflg)
+ printf("DEPELSE");
+ depcase();
+ break;
+
+ case I_DEPEND:
+ if (stpflg)
+ printf("DEPEND");
+ break;
+
+ case I_RETURN:
+ if (stpflg)
+ printf("RETURN\n--------------------------------------------------\n");
+ pc = oldpc;
+ return;
+
+ default:
+ syserr("Unknown STMOP instruction.");
+ break;
+ }
+ if (fail) {
+ pc = oldpc;
+ return;
+ }
+ break;
+
+ default:
+ syserr("Unknown instruction class.");
+ break;
+ }
+ }
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/inter.h b/engines/glk/alan2/inter.h
new file mode 100644
index 0000000..a7fafef
--- /dev/null
+++ b/engines/glk/alan2/inter.h
@@ -0,0 +1,38 @@
+/* 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 GLK_ALAN2_INTER
+#define GLK_ALAN2_INTER
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+extern void interpret(Aaddr adr);
+#else
+extern void interpret();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
new file mode 100644
index 0000000..48c6d96
--- /dev/null
+++ b/engines/glk/alan2/main.h
@@ -0,0 +1,155 @@
+/* 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 GLK_ALAN2_MAIN
+#define GLK_ALAN2_MAIN
+
+/* Header file for main unit of ARUN Alan System interpreter */
+
+#include "common/file.h"
+#include "glk/alan2/types.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/* DATA */
+
+#define MEMORYSIZE 1000L
+
+extern int memTop; /* Top of memory */
+
+extern int conjWord; /* First conjunction in dictionary */
+
+/* The Amachine memory */
+extern Aword *memory;
+extern AcdHdr *header;
+
+/* Amachine variables */
+extern CurVars cur;
+
+/* Amachine data structures */
+extern WrdElem *dict; /* Dictionary pointer */
+extern ActElem *acts; /* Actor table pointer */
+extern LocElem *locs; /* Location table pointer */
+extern VrbElem *vrbs; /* Verb table pointer */
+extern StxElem *stxs; /* Syntax table pointer */
+extern ObjElem *objs; /* Object table pointer */
+extern CntElem *cnts; /* Container table pointer */
+extern RulElem *ruls; /* Rule table pointer */
+extern EvtElem *evts; /* Event table pointer */
+extern MsgElem *msgs; /* Message table pointer */
+extern Aword *scores; /* Score table pointer */
+extern Aword *freq; /* Cumulated frequencies */
+
+extern int dictsize; /* Number of entries in dictionary */
+
+/* The text and message file */
+extern Common::File *txtfil;
+extern Common::WriteStream *logfil;
+
+#undef ftell
+#undef fgetc
+#undef getc
+#undef fseek
+#undef fclose
+#define ftell(FP) FP->pos()
+#define fgetc(FP) (FP->pos() >= FP->size()) ? EOF : FP->readByte()
+#define getc(FP) (FP->pos() >= FP->size()) ? EOF : FP->readByte()
+#define fseek(FP, OFS, WHENCE) FP->seek(OFS, WHENCE)
+#define fclose(FP) delete FP
+
+
+/* File names */
+extern char *advnam;
+
+/* Screen formatting info */
+extern int col, lin;
+extern int paglen, pagwidth;
+
+/* Long jump buffer for restart */
+//extern jmp_buf restart_label;
+
+extern Boolean verbose, errflg, trcflg, dbgflg, stpflg, logflg, statusflg;
+extern Boolean fail;
+extern Boolean anyOutput;
+extern Boolean needsp;
+
+#define endOfTable(x) eot((Aword *) x)
+
+
+#ifdef _PROTOTYPES_
+extern void *allocate(unsigned long len);
+extern void terminate(int code);
+extern void usage(void);
+extern void error(MsgKind msg);
+extern void syserr(char *msg);
+extern void statusline(void);
+extern void output(char string[]);
+extern void prmsg(MsgKind msg);
+extern void para(void);
+extern void newline(void);
+
+extern Boolean checklim(Aword cnt, Aword obj);
+extern Boolean possible(void);
+extern Boolean exitto(int to, int from);
+extern void action(ParamElem *plst);
+extern void go(int dir);
+
+extern Boolean eot(Aword *adr);
+extern Boolean isObj(Aword x);
+extern Boolean isCnt(Aword x);
+extern Boolean isAct(Aword x);
+extern Boolean isLoc(Aword x);
+extern Boolean isLit(Aword x);
+extern Boolean isNum(Aword x);
+extern Boolean isStr(Aword x);
+
+/* Run the game! */
+extern void run(void);
+
+#else
+extern void *allocate();
+extern void terminate();
+extern void syserr();
+extern void usage();
+extern void error();
+extern void output();
+extern void statusline();
+extern void prmsg();
+extern void print();
+extern void para();
+extern void newline();
+extern Boolean checklim();
+extern Boolean possible();
+extern Boolean eot();
+extern Boolean isObj();
+extern Boolean isCnt();
+extern Boolean isAct();
+extern Boolean isLoc();
+extern Boolean isLit();
+extern void run();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/params.cpp b/engines/glk/alan2/params.cpp
new file mode 100644
index 0000000..b885103
--- /dev/null
+++ b/engines/glk/alan2/params.cpp
@@ -0,0 +1,159 @@
+/* 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 <stdio.h>
+#include "glk/alan2/types.h"
+#include "glk/alan2/params.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+void compact(ParamElem a[])
+#else
+void compact(a)
+ ParamElem a[];
+#endif
+{
+ int i, j;
+
+ for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
+ if (a[j].code != 0)
+ a[i++] = a[j];
+ a[i].code = (Aword)EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+int lstlen(ParamElem a[])
+#else
+int lstlen(a)
+ ParamElem a[];
+#endif
+{
+ int i = 0;
+
+ while (a[i].code != (Aword)EOF)
+ i++;
+ return (i);
+}
+
+
+#ifdef _PROTOTYPES_
+Boolean inlst(ParamElem l[], Aword e)
+#else
+Boolean inlst(l, e)
+ ParamElem l[];
+ Aword e;
+#endif
+{
+ int i;
+
+ for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
+ return (l[i].code == e);
+}
+
+
+#ifdef _PROTOTYPES_
+void lstcpy(ParamElem a[], ParamElem b[])
+#else
+void lstcpy(a, b)
+ ParamElem a[], b[];
+#endif
+{
+ int i;
+
+ for (i = 0; b[i].code != (Aword)EOF; i++)
+ a[i] = b[i];
+ a[i].code = (Aword)EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+void sublst(ParamElem a[], ParamElem b[])
+#else
+void sublst(a, b)
+ ParamElem a[], b[];
+#endif
+{
+ int i;
+
+ for (i = 0; a[i].code != (Aword)EOF; i++)
+ if (inlst(b, a[i].code))
+ a[i].code = 0; /* Mark empty */
+ compact(a);
+}
+
+
+#ifdef _PROTOTYPES_
+void mrglst(ParamElem a[], ParamElem b[])
+#else
+void mrglst(a, b)
+ ParamElem a[], b[];
+#endif
+{
+ int i,last;
+
+ for (last = 0; a[last].code != (Aword)EOF; last++); /* Find end of list */
+ for (i = 0; b[i].code != (Aword)EOF; i++)
+ if (!inlst(a, b[i].code)) {
+ a[last++] = b[i];
+ a[last].code = (Aword)EOF;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+void isect(ParamElem a[], ParamElem b[])
+#else
+void isect(a, b)
+ ParamElem a[], b[];
+#endif
+{
+ int i, last = 0;
+
+ for (i = 0; a[i].code != (Aword)EOF; i++)
+ if (inlst(b, a[i].code))
+ a[last++] = a[i];
+ a[last].code = (Aword)EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+void cpyrefs(ParamElem p[], Aword r[])
+#else
+void cpyrefs(p, r)
+ ParamElem p[];
+ Aword r[];
+#endif
+{
+ int i;
+
+ for (i = 0; r[i] != (Aword)EOF; i++) {
+ p[i].code = r[i];
+ p[i].firstWord = (Aword)EOF;
+ }
+ p[i].code = (Aword)EOF;
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/params.h b/engines/glk/alan2/params.h
new file mode 100644
index 0000000..82fa84b
--- /dev/null
+++ b/engines/glk/alan2/params.h
@@ -0,0 +1,66 @@
+/* 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 GLK_ALAN2_PARAMS
+#define GLK_ALAN2_PARAMS
+
+#include "glk/alan2/types.h"
+
+/* Various utility functions for handling parameters:
+ *
+ * compact() Compact a list, i.e remove any NULL elements
+ * lstlen() Count number of elements
+ * inlst() Check if an element is in the list
+ * sublst() Subract two lists
+ * lstcpy() Copy one list onto another
+ * mrglst() Merge the paramElems of one list into the first
+ * isect() Take the intersection of two lists
+ * cpyrefs() Copy the refs (in dictionary) to a paramList
+ */
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+extern void compact(ParamElem *a);
+extern int lstlen(ParamElem *a);
+extern Boolean inlst(ParamElem *l, Aword e);
+extern void lstcpy(ParamElem *a, ParamElem *b);
+extern void sublst(ParamElem *a, ParamElem *b);
+extern void mrglst(ParamElem *a, ParamElem *b);
+extern void isect(ParamElem *a, ParamElem *b);
+extern void cpyrefs(ParamElem *p, Aword *r);
+#else
+extern void compact();
+extern int lstlen();
+extern Boolean inlst();
+extern void lstcpy();
+extern void sublst();
+extern void mrglst();
+extern void isect();
+extern void cpyrefs();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
new file mode 100644
index 0000000..4e54c5c
--- /dev/null
+++ b/engines/glk/alan2/parse.cpp
@@ -0,0 +1,846 @@
+/* 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 <string>
+#include "glk/alan2/types.h"
+
+#ifdef USE_READLINE
+#include "glk/alan2/readline.h"
+#endif
+
+#include "glk/alan2/main.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/term.h"
+#include "glk/alan2/debug.h"
+#include "glk/alan2/params.h"
+
+#include "glk/alan2/parse.h"
+
+#ifdef GLK
+#include "glk/alan2/glkio.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+#define LISTLEN 100
+
+
+/* PUBLIC DATA */
+
+int wrds[LISTLEN/2] = {EOF}; /* List of parsed words */
+int wrdidx; /* and an index into it */
+
+Boolean plural = FALSE;
+
+
+/* Syntax Parameters */
+int paramidx; /* Index in params */
+ParamElem *params; /* List of params */
+static ParamElem *pparams; /* Previous parameter list */
+static ParamElem *mlst; /* Multiple objects list */
+static ParamElem *pmlst; /* Previous multiple list */
+
+/* Literals */
+LitElem litValues[MAXPARAMS+1];
+int litCount;
+
+/* What did the user say? */
+int vrbwrd; /* The word he used */
+int vrbcode; /* The code for that verb */
+
+
+/*----------------------------------------------------------------------*\
+
+ SCAN DATA & PROCEDURES
+
+ All procedures for getting a command and turning it into a list of
+ dictionary entries are placed here.
+
+ buf
+ unknown()
+ lookup()
+ token
+ agetline()
+ scan()
+
+\*----------------------------------------------------------------------*/
+
+
+/* PRIVATE DATA */
+
+static char buf[LISTLEN+1]; /* The input buffer */
+static char isobuf[LISTLEN+1]; /* The input buffer in ISO */
+
+
+static Boolean eol = TRUE; /* Looking at End of line? Yes, initially */
+
+
+
+#ifdef _PROTOTYPES_
+static void unknown(
+ char token[]
+)
+#else
+static void unknown(token)
+ char token[];
+#endif
+{
+ char *str = (char *)allocate((int)strlen(token)+4);
+
+ str[0] = '\'';
+ strcpy(&str[1], token);
+ strcat(str, "'?");
+#if ISO == 0
+ fromIso(str, str);
+#endif
+ output(str);
+ free(str);
+ eol = TRUE;
+ error(M_UNKNOWN_WORD);
+}
+
+
+
+static char *token;
+
+
+#ifdef _PROTOTYPES_
+static int lookup(
+ char wrd[]
+)
+#else
+static int lookup(wrd)
+ char wrd[];
+#endif
+{
+ int i;
+
+ for (i = 0; !endOfTable(&dict[i]); i++) {
+ if (strcmp(wrd, (char *) addrTo(dict[i].wrd)) == 0)
+ return (i);
+ }
+ unknown(wrd);
+ return(EOF);
+}
+
+
+#ifdef _PROTOTYPES_
+static int number(
+ char token[] /* IN - The string to convert to a number */
+)
+#else
+static int number(token)
+ char token[]; /* IN - The string to convert to a number */
+#endif
+{
+ int i;
+
+ sscanf(token, "%d", &i);
+ return i;
+}
+
+#ifdef _PROTOTYPES_
+static char *gettoken(
+ char *buf
+)
+#else
+static char *gettoken(buf)
+ char *buf;
+#endif
+{
+ static char *marker;
+ static char oldch;
+
+ if (buf == NULL)
+ *marker = oldch;
+ else
+ marker = buf;
+ while (*marker != '\0' && isSpace(*marker) && *marker != '\n') marker++;
+ buf = marker;
+ if (isISOLetter(*marker))
+ while (*marker&&(isISOLetter(*marker)||isdigit(*marker)||*marker=='\'')) marker++;
+ else if (isdigit(*marker))
+ while (isdigit(*marker)) marker++;
+ else if (*marker == '\"') {
+ marker++;
+ while (*marker != '\"') marker++;
+ marker++;
+ } else if (*marker == '\0' || *marker == '\n')
+ return NULL;
+ else
+ marker++;
+ oldch = *marker;
+ *marker = '\0';
+ return buf;
+}
+
+
+#ifdef _PROTOTYPES_
+static void agetline(void)
+#else
+static void agetline()
+#endif
+{
+ para();
+ do {
+#if defined(HAVE_ANSI) || defined(GLK)
+ statusline();
+#endif
+ printf("> ");
+ if (logflg)
+ fprintf(logfil, "> ");
+#ifdef USE_READLINE
+ if (!readline(buf)) {
+ newline();
+ quit();
+ }
+#else
+ if (fgets(buf, LISTLEN, stdin) == NULL) {
+ newline();
+ quit();
+ }
+#endif
+ getPageSize();
+ anyOutput = FALSE;
+ if (logflg)
+#ifndef __amiga__
+ fprintf(logfil, "%s\n", buf);
+#else
+ fprintf(logfil, "%s", buf);
+#endif
+#if ISO == 0
+ toIso(isobuf, buf, NATIVECHARSET);
+#else
+ strcpy(isobuf, buf);
+#endif
+ token = gettoken(isobuf);
+ if (token != NULL && strcmp("debug", token) == 0 && header->debug) {
+ dbgflg = TRUE;
+ debug();
+ token = NULL;
+ }
+ } while (token == NULL);
+ eol = FALSE;
+ lin = 1;
+}
+
+
+#ifdef _PROTOTYPES_
+static void scan(void)
+#else
+static void scan()
+#endif
+{
+ int i;
+ int w;
+ char *str;
+
+ agetline();
+ wrds[0] = 0;
+ for (i = 0; i < litCount; i++)
+ if (litValues[i].type == TYPSTR && litValues[i].value != 0)
+ free((char *) litValues[i].value);
+ i = 0;
+ litCount = 0;
+ do {
+ if (isISOLetter(token[0])) {
+ (void) stringLower(token);
+ w = lookup(token);
+ if (!isNoise(w))
+ wrds[i++] = w;
+ } else if (isdigit(token[0])) {
+ if (litCount > MAXPARAMS)
+ syserr("Too many parameters.");
+ wrds[i++] = dictsize+litCount; /* Word outside dictionary = literal */
+ litValues[litCount].type = TYPNUM;
+ litValues[litCount++].value = number(token);
+ } else if (token[0] == '\"') {
+ if (litCount > MAXPARAMS)
+ syserr("Too many parameters.");
+ wrds[i++] = dictsize+litCount; /* Word outside dictionary = literal */
+ litValues[litCount].type = TYPSTR;
+ /* Remove the string quotes while copying */
+ str = strdup(&token[1]);
+ str[strlen(token)-2] = '\0';
+ litValues[litCount++].value = (Aptr) str;
+ } else if (token[0] == ',') {
+ wrds[i++] = conjWord;
+ } else
+ unknown(token);
+ wrds[i] = EOF;
+ eol = (token = gettoken(NULL)) == NULL;
+ } while (!eol);
+}
+
+
+
+/*----------------------------------------------------------------------*\
+
+ PARSE DATA & PROCEDURES
+
+ All procedures and data for getting a command and parsing it
+
+ nonverb() - search for a non-verb command
+ buildall() - build a list of objects matching 'all'
+ unambig() - match an unambigous object reference
+ simple() - match a simple verb command
+ complex() - match a complex -"-
+ tryMatch()- to match a verb command
+ match() - find the verb class (not used currently) and 'tryMatch()'
+
+\*---------------------------------------------------------------------- */
+
+static int allLength; /* No. of objects matching 'all' */
+
+
+#ifdef _PROTOTYPES_
+static void nonverb(void)
+#else
+static void nonverb()
+#endif
+{
+ if (isDir(wrds[wrdidx])) {
+ wrdidx++;
+ if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ error(M_WHAT);
+ else
+ go(dict[wrds[wrdidx-1]].code);
+ if (wrds[wrdidx] != EOF)
+ wrdidx++;
+ } else
+ error(M_WHAT);
+}
+
+
+#ifdef _PROTOTYPES_
+static void buildall(
+ ParamElem list[]
+)
+#else
+static void buildall(list)
+ ParamElem list[];
+#endif
+{
+ int o, i = 0;
+ Boolean found = FALSE;
+
+ for (o = OBJMIN; o <= OBJMAX; o++)
+ if (isHere(o)) {
+ found = TRUE;
+ list[i].code = o;
+ list[i++].firstWord = EOF;
+ }
+ if (!found)
+ error(M_WHAT_ALL);
+ else
+ list[i].code = EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+static void unambig(
+ ParamElem plst[]
+)
+#else
+static void unambig(plst)
+ ParamElem plst[];
+#endif
+{
+ int i;
+ Boolean found = FALSE; /* Adjective or noun found ? */
+ static ParamElem *refs; /* Entities referenced by word */
+ static ParamElem *savlst; /* Saved list for backup at EOF */
+ int firstWord, lastWord; /* The words the player used */
+
+ if (refs == NULL)
+ refs = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem));
+
+ if (savlst == NULL)
+ savlst = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem));
+
+ if (isLiteral(wrds[wrdidx])) {
+ /* Transform the word into a reference to the literal value */
+ plst[0].code = wrds[wrdidx++]-dictsize+LITMIN;
+ plst[0].firstWord = EOF; /* No words used! */
+ plst[1].code = EOF;
+ return;
+ }
+
+ plst[0].code = EOF; /* Make empty */
+ if (isIt(wrds[wrdidx])) {
+ wrdidx++;
+ /* Use last object in previous command! */
+ for (i = lstlen(pparams)-1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--);
+ if (i < 0)
+ error(M_WHAT_IT);
+ if (!isHere(pparams[i].code)) {
+ params[0].code = pparams[i].code;
+ params[0].firstWord = EOF;
+ params[1].code = EOF;
+ error(M_NO_SUCH);
+ }
+ plst[0] = pparams[i];
+ plst[0].firstWord = EOF; /* No words used! */
+ plst[1].code = EOF;
+ return;
+ }
+
+ firstWord = wrdidx;
+ while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) {
+ /* If this word can be a noun and there is no noun following break loop */
+ if (isNoun(wrds[wrdidx]) && (wrds[wrdidx+1] == EOF || !isNoun(wrds[wrdidx+1])))
+ break;
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs));
+ lstcpy(savlst, plst); /* To save it for backtracking */
+ if (found)
+ isect(plst, refs);
+ else {
+ lstcpy(plst, refs);
+ found = TRUE;
+ }
+ wrdidx++;
+ }
+ if (wrds[wrdidx] != EOF) {
+ if (isNoun(wrds[wrdidx])) {
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs));
+ if (found)
+ isect(plst, refs);
+ else {
+ lstcpy(plst, refs);
+ found = TRUE;
+ }
+ wrdidx++;
+ } else
+ error(M_NOUN);
+ } else if (found) {
+ if (isNoun(wrds[wrdidx-1])) {
+ /* Perhaps the last word was also a noun? */
+ lstcpy(plst, savlst); /* Restore to before last adjective */
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx-1]].nounrefs));
+ if (plst[0].code == EOF)
+ lstcpy(plst, refs);
+ else
+ isect(plst, refs);
+ } else
+ error(M_NOUN);
+ }
+ lastWord = wrdidx-1;
+
+ /* Allow remote objects, but resolve ambiguities by presence */
+ if (lstlen(plst) > 1) {
+ for (i=0; plst[i].code != EOF; i++)
+ if (!isHere(plst[i].code))
+ plst[i].code = 0;
+ compact(plst);
+ }
+
+ if (lstlen(plst) > 1 || (found && lstlen(plst) == 0)) {
+ params[0].code = 0; /* Just make it anything != EOF */
+ params[0].firstWord = firstWord; /* Remember words for errors below */
+ params[0].lastWord = lastWord;
+ params[1].code = EOF; /* But be sure to terminate */
+ if (lstlen(plst) > 1)
+ error(M_WHICH_ONE);
+ else if (found && lstlen(plst) == 0)
+ error(M_NO_SUCH);
+ } else {
+ plst[0].firstWord = firstWord;
+ plst[0].lastWord = lastWord;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void simple(
+ ParamElem olst[]
+)
+#else
+static void simple(olst)
+ ParamElem olst[];
+#endif
+{
+ static ParamElem *tlst = NULL;
+ int savidx = wrdidx;
+ Boolean savplur = FALSE;
+ int i;
+
+ if (tlst == NULL)
+ tlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
+ tlst[0].code = EOF;
+
+ for (;;) {
+ if (isThem(wrds[wrdidx])) {
+ plural = TRUE;
+ for (i = 0; pmlst[i].code != EOF; i++)
+ if (!isHere(pmlst[i].code))
+ pmlst[i].code = 0;
+ compact(pmlst);
+ if (lstlen(pmlst) == 0)
+ error(M_WHAT_THEM);
+ lstcpy(olst, pmlst);
+ olst[0].firstWord = EOF; /* No words used */
+ wrdidx++;
+ } else {
+ unambig(olst); /* Look for unambigous noun phrase */
+ if (lstlen(olst) == 0) { /* Failed! */
+ lstcpy(olst, tlst);
+ wrdidx = savidx;
+ plural = savplur;
+ return;
+ }
+ }
+ mrglst(tlst, olst);
+ if (wrds[wrdidx] != EOF
+ && (isConj(wrds[wrdidx]) &&
+ (isAdj(wrds[wrdidx+1]) || isNoun(wrds[wrdidx+1])))) {
+ /* More parameters in a conjunction separated list ? */
+ savplur = plural;
+ savidx = wrdidx;
+ wrdidx++;
+ plural = TRUE;
+ } else {
+ lstcpy(olst, tlst);
+ return;
+ }
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ complex()
+
+ Above this procedure we can use the is* tests, but not below since
+ they work on words. Below all is converted to indices into the
+ entity tables. Particularly this goes for literals...
+
+*/
+#ifdef _PROTOTYPES_
+static void complex(
+ ParamElem olst[]
+)
+#else
+static void complex(olst)
+ ParamElem olst[];
+#endif
+{
+ static ParamElem *alst = NULL;
+
+ if (alst == NULL)
+ alst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem));
+
+ if (isAll(wrds[wrdidx])) {
+ plural = TRUE;
+ buildall(alst); /* Build list of all objects */
+ wrdidx++;
+ if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) {
+ wrdidx++;
+ simple(olst);
+ if (lstlen(olst) == 0)
+ error(M_AFTER_BUT);
+ sublst(alst, olst);
+ if (lstlen(alst) == 0)
+ error(M_NOT_MUCH);
+ }
+ lstcpy(olst, alst);
+ allLength = lstlen(olst);
+ } else
+ simple(olst); /* Look for simple noun group */
+}
+
+
+#ifdef _PROTOTYPES_
+static Boolean claCheck(
+ ClaElem *cla /* IN - The cla elem to check */
+)
+#else
+static Boolean claCheck(cla)
+ ClaElem *cla; /* IN - The cla elem to check */
+#endif
+{
+ Boolean ok = FALSE;
+
+ if ((cla->classes&(Aword)CLA_OBJ) != 0)
+ ok = ok || isObj(params[cla->code-1].code);
+ if ((cla->classes&(Aword)CLA_CNT) != 0)
+ ok = ok || isCnt(params[cla->code-1].code);
+ if ((cla->classes&(Aword)CLA_ACT) != 0)
+ ok = ok || isAct(params[cla->code-1].code);
+ if ((cla->classes&(Aword)CLA_NUM) != 0)
+ ok = ok || isNum(params[cla->code-1].code);
+ if ((cla->classes&(Aword)CLA_STR) != 0)
+ ok = ok || isStr(params[cla->code-1].code);
+ if ((cla->classes&(Aword)CLA_COBJ) != 0)
+ ok = ok || (isCnt(params[cla->code-1].code) && isObj(params[cla->code-1].code));
+ if ((cla->classes&(Aword)CLA_CACT) != 0)
+ ok = ok || (isCnt(params[cla->code-1].code) && isAct(params[cla->code-1].code));
+ return ok;
+}
+
+
+/*----------------------------------------------------------------------
+
+ resolve()
+
+ In case the syntax did not indicate omnipotent powers (allowed
+ access to remote object), we need to remove non-present parameters
+
+*/
+static void resolve(ParamElem plst[])
+{
+ int i;
+
+ if (allLength > 0) return; /* ALL has already done this */
+
+ /* Resolve ambiguities by presence */
+ for (i=0; plst[i].code != EOF; i++)
+ if (plst[i].code < LITMIN) /* Literals are always 'here' */
+ if (!isHere(plst[i].code)) {
+ params[0] = plst[i]; /* Copy error param as first one for message */
+ params[1].code = EOF; /* But be sure to terminate */
+ error(M_NO_SUCH);
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void tryMatch(
+ ParamElem mlst[] /* OUT - List of params allowed by multiple */
+)
+#else
+static void tryMatch(mlst)
+ ParamElem mlst[]; /* OUT - List of params allowed by multiple */
+#endif
+{
+ ElmElem *elms; /* Pointer to element list */
+ StxElem *stx; /* Pointer to syntax list */
+ ClaElem *cla; /* Pointer to class definitions */
+ Boolean anyPlural = FALSE; /* Any parameter that was plural? */
+ int i, p;
+ static ParamElem *tlst = NULL; /* List of params found by complex() */
+ static Boolean *checked = NULL; /* Corresponding parameter checked? */
+
+ if (tlst == NULL) {
+ tlst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem));
+ checked = (Boolean *) allocate((MAXENTITY+1)*sizeof(Boolean));
+ }
+
+ for (stx = stxs; !endOfTable(stx); stx++)
+ if (stx->code == vrbcode)
+ break;
+ if (endOfTable(stx))
+ error(M_WHAT);
+
+ elms = (ElmElem *) addrTo(stx->elms);
+
+ while (TRUE) {
+ /* End of input? */
+ if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) {
+ while (!endOfTable(elms) && elms->code != EOS)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ else
+ break;
+ } else {
+ /* A preposition? */
+ if (isPrep(wrds[wrdidx])) {
+ while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ else
+ wrdidx++;
+ } else {
+ /* Must be a parameter! */
+ while (!endOfTable(elms) && elms->code != 0)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ /* Get it! */
+ plural = FALSE;
+ complex(tlst);
+ if (lstlen(tlst) == 0) /* No object!? */
+ error(M_WHAT);
+ if ((elms->flags & OMNIBIT) == 0) /* Omnipotent parameter? */
+ /* If its not an omnipotent parameter, resolve by presence */
+ resolve(tlst);
+ if (plural) {
+ if ((elms->flags & MULTIPLEBIT) == 0) /* Allowed multiple? */
+ error(M_MULTIPLE);
+ else {
+ /*
+ Mark this as the multiple position in which to insert
+ actual parameter values later
+ */
+ params[paramidx++].code = 0;
+ lstcpy(mlst, tlst);
+ anyPlural = TRUE;
+ }
+ } else
+ params[paramidx++] = tlst[0];
+ params[paramidx].code = EOF;
+ }
+ elms = (ElmElem *) addrTo(elms->next);
+ }
+ }
+
+ /* Now perform class checks */
+ if (elms->next == 0) /* No verb code, verb not declared! */
+ error(M_CANT0);
+
+ for (p = 0; params[p].code != EOF; p++) /* Mark all parameters unchecked */
+ checked[p] = FALSE;
+ for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
+ if (params[cla->code-1].code == 0) {
+ /* This was a multiple parameter, so check all and remove failing */
+ for (i = 0; mlst[i].code != EOF; i++) {
+ params[cla->code-1] = mlst[i];
+ if (!claCheck(cla)) {
+ /* Multiple could be both an explicit list of params and an ALL */
+ if (allLength == 0) {
+ char marker[80];
+ /*
+ It wasn't ALL, we need to say something about it, so
+ prepare a printout with $1/2/3
+ */
+ sprintf(marker, "($%ld)", (unsigned long) cla->code);
+ output(marker);
+ interpret(cla->stms);
+ para();
+ }
+ mlst[i].code = 0; /* In any case remove it from the list */
+ }
+ }
+ params[cla->code-1].code = 0;
+ } else {
+ if (!claCheck(cla)) {
+ interpret(cla->stms);
+ error(MSGMAX); /* Return to player without saying anything */
+ }
+ }
+ checked[cla->code-1] = TRUE; /* Remember that it's already checked */
+ }
+ /* Now check the rest of the parameters, must be objects */
+ for (p = 0; params[p].code != EOF; p++)
+ if (!checked[p]) {
+ if (params[p].code == 0) {
+ /* This was a multiple parameter, check all and remove failing */
+ for (i = 0; mlst[i].code != EOF; i++)
+ if (mlst[i].code != 0) /* Skip any empty slots */
+ if (!isObj(mlst[i].code))
+ mlst[i].code = 0;
+ } else if (!isObj(params[p].code))
+ error(M_CANT0);
+ }
+
+ /* Set verb code */
+ cur.vrb = ((Aword *) cla)[1]; /* Take first word after end of table! */
+
+ /* Finally, if ALL was used, try to find out what was applicable */
+ if (allLength > 0) {
+ for (p = 0; params[p].code != 0; p++); /* Find multiple marker */
+ for (i = 0; i < allLength; i++) {
+ if (mlst[i].code != 0) { /* Already empty? */
+ params[p] = mlst[i];
+ if (!possible())
+ mlst[i].code = 0; /* Remove this from list */
+ }
+ }
+ params[p].code = 0; /* Restore multiple marker */
+ compact(mlst);
+ if (lstlen(mlst) == 0) {
+ params[0].code = EOF;
+ error(M_WHAT_ALL);
+ }
+ } else if (anyPlural) {
+ compact(mlst);
+ if (lstlen(mlst) == 0)
+ /* If there where multiple parameters but non left, exit without a */
+ /* word, assuming we have already said enough */
+ error(MSGMAX);
+ }
+ plural = anyPlural; /* Remember that we found plural objects */
+}
+
+
+#ifdef _PROTOTYPES_
+static void match(
+ ParamElem *mlst /* OUT - List of params allowed by multiple */
+)
+#else
+static void match(mlst)
+ ParamElem *mlst; /* OUT - List of params allowed by multiple */
+#endif
+{
+ tryMatch(mlst); /* ... to understand what he said */
+ if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ error(M_WHAT);
+ if (wrds[wrdidx] != EOF) /* More on this line? */
+ wrdidx++; /* If so skip the AND */
+}
+
+
+#ifdef _PROTOTYPES_
+void parse(void)
+#else
+void parse()
+#endif
+{
+ if (mlst == NULL) { /* Allocate large enough paramlists */
+ mlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
+ mlst[0].code = EOF;
+ pmlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
+ params = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
+ params[0].code = EOF;
+ pparams = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
+ }
+
+ if (wrds[wrdidx] == EOF) {
+ wrdidx = 0;
+ scan();
+ } else if (anyOutput)
+ para();
+
+ allLength = 0;
+ paramidx = 0;
+ lstcpy(pparams, params);
+ params[0].code = EOF;
+ lstcpy(pmlst, mlst);
+ mlst[0].code = EOF;
+ if (isVerb(wrds[wrdidx])) {
+ vrbwrd = wrds[wrdidx];
+ vrbcode = dict[vrbwrd].code;
+ wrdidx++;
+ match(mlst);
+ action(mlst); /* mlst contains possible multiple params */
+ } else {
+ params[0].code = EOF;
+ pmlst[0].code = EOF;
+ nonverb();
+ }
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
new file mode 100644
index 0000000..067c73f
--- /dev/null
+++ b/engines/glk/alan2/parse.h
@@ -0,0 +1,54 @@
+/* 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 GLK_ALAN2_PARSE
+#define GLK_ALAN2_PARSE
+
+/* Parse data for ALAN interpreter module. */
+
+namespace Glk {
+namespace Alan2 {
+
+extern int wrds[]; /* List of Parsed Word */
+extern int wrdidx; /* and an index into it */
+
+extern ParamElem *params; /* List of parameters */
+extern Boolean plural;
+
+extern LitElem litValues[];
+extern int litCount;
+
+extern int vrbwrd;
+
+#ifdef _PROTOTYPES_
+
+/* Parse a new player command */
+extern void parse(void);
+
+#else
+extern void parse();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/readline.cpp b/engines/glk/alan2/readline.cpp
new file mode 100644
index 0000000..c96b26c
--- /dev/null
+++ b/engines/glk/alan2/readline.cpp
@@ -0,0 +1,560 @@
+/* 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/alan2/types.h"
+
+#ifdef GLK
+
+#include "glk/alan2/alan2.h"
+#include "glk/alan2/readline.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/glkio.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/*======================================================================
+
+ readline()
+
+ Read a line from the user, with history and editing
+
+ */
+
+/* 4f - length of user buffer should be used */
+Boolean readline(char usrbuf[])
+{
+ event_t event;
+ g_vm->glk_request_line_event(glkMainWin, usrbuf, 255, 0);
+ /* FIXME: buffer size should be infallible: all existing calls use 256 or
+ 80 character buffers, except parse which uses LISTLEN (currently 100)
+ */
+ do
+ {
+ g_vm->glk_select(&event);
+ if (evtype_Arrange == event.type)
+ statusline();
+ } while (event.type != evtype_LineInput);
+ usrbuf[event.val1] = 0;
+ return TRUE;
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#else
+
+#include "glk/alan2/sysdep.h"
+
+#ifdef HAVE_TERMIO
+#include <termios.h>
+#endif
+
+#ifdef __PACIFIC__
+#include <unixio.h>
+#else
+//#include <unistd.h>
+#endif
+
+#include "glk/alan2/readline.h"
+
+#include "glk/alan2/main.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef HAVE_TERMIO
+/*----------------------------------------------------------------------*\
+
+ termio handling
+
+\*----------------------------------------------------------------------*/
+
+static struct termios term;
+
+static void newtermio()
+{
+ struct termios newterm;
+ tcgetattr(0, &term);
+ newterm=term;
+ newterm.c_lflag&=~(ECHO|ICANON);
+ newterm.c_cc[VMIN]=1;
+ newterm.c_cc[VTIME]=0;
+ tcsetattr(0, TCSANOW, &newterm);
+}
+
+static void restoretermio()
+{
+ tcsetattr(0, TCSANOW, &term);
+}
+
+#endif
+
+
+/*----------------------------------------------------------------------*\
+
+ Global character buffers etc.
+
+\*----------------------------------------------------------------------*/
+
+static unsigned char buffer[LINELENGTH+1];
+static int bufidx;
+
+static unsigned char *history[HISTORYLENGTH];
+static int histidx; /* Index where to store next history */
+static int histp; /* Points to the history recalled last */
+
+static unsigned char ch;
+static int endOfInput = 0;
+static Boolean change;
+static Boolean insert = TRUE;
+
+
+/*----------------------------------------------------------------------*\
+
+ Character map types and maps
+
+\*----------------------------------------------------------------------*/
+
+typedef struct {unsigned char min, max; void (*hook)(char ch);} KeyMap;
+
+/* Forward declaration of hooks */
+static void escHook(char ch);
+static void insertCh(char ch);
+static void arrowHook(char ch);
+static void upArrow(char ch);
+static void downArrow(char ch);
+static void rightArrow(char ch);
+static void leftArrow(char ch);
+static void insertToggle(char ch);
+static void newLine(char ch);
+static void delFwd(char ch);
+static void delBwd(char ch);
+
+#ifdef __XXunix__
+static KeyMap keymap[] = {
+ {0x00, 0x07, NULL},
+ {0x08, 0x08, delBwd},
+ {0x09, 0x09, NULL},
+ {0x0a, 0x0a, newLine},
+ {0x1b, 0x1b, escHook},
+ {0x1c, 0x7e, insertCh},
+ {0x7f, 0x7f, delFwd},
+ {0x80, 0xff, insertCh},
+ {0x00, 0x00, NULL}
+};
+
+/* I can't figure out what really coverns the esc-map characters... */
+#ifdef __solarisX__
+static KeyMap escmap[] = {
+ {0x00, 0x4e, NULL},
+ {0x4f, 0x4f, arrowHook},
+ {0x50, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+#else
+static KeyMap escmap[] = {
+ {0x00, 0x5a, NULL},
+ {0x5b, 0x5b, arrowHook},
+ {0x5c, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+#endif
+
+static KeyMap arrowmap[] = {
+ {0x00, 0x31, NULL},
+ {0x32, 0x32, insertToggle},
+ {0x33, 0x40, NULL},
+ {0x41, 0x41, upArrow},
+ {0x42, 0x42, downArrow},
+ {0x43, 0x43, rightArrow},
+ {0x44, 0x44, leftArrow},
+ {0x45, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+
+#endif
+
+#ifdef __win__
+static KeyMap keymap[] = {
+ {0x00, 0x01, NULL},
+ {0x02, 0x02, leftArrow},
+ {0x03, 0x05, NULL},
+ {0x06, 0x06, rightArrow},
+ {0x07, 0x07, NULL},
+ {0x08, 0x08, delBwd},
+ {0x09, 0x09, NULL},
+ {0x0a, 0x0a, newLine},
+ {0x1b, 0x1b, escHook},
+ {0x1c, 0x7e, insertCh},
+ {0x7f, 0x7f, delFwd},
+ {0x80, 0xff, insertCh},
+ {0x00, 0x00, NULL}
+};
+
+static KeyMap escmap[] = {
+ {0x00, 0x5a, NULL},
+ {0x5b, 0x5b, arrowHook},
+ {0x5c, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+
+static KeyMap arrowmap[] = {
+ {0x00, 0x31, NULL},
+ {0x32, 0x32, insertToggle},
+ {0x33, 0x40, NULL},
+ {0x41, 0x41, upArrow},
+ {0x42, 0x42, downArrow},
+ {0x43, 0x43, rightArrow},
+ {0x44, 0x44, leftArrow},
+ {0x45, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+
+#endif
+
+#ifdef __dos__
+static KeyMap keymap[] = {
+ {0x00, 0x01, NULL},
+ {0x02, 0x02, leftArrow},
+ {0x03, 0x05, NULL},
+ {0x06, 0x06, rightArrow},
+ {0x07, 0x07, NULL},
+ {0x08, 0x08, delBwd},
+ {0x09, 0x09, NULL},
+ {0x0a, 0x0a, newLine},
+ {0x1b, 0x1b, escHook},
+ {0x1c, 0x7e, insertCh},
+ {0x7f, 0x7f, delFwd},
+ {0x80, 0xff, insertCh},
+ {0x00, 0x00, NULL}
+};
+
+static KeyMap escmap[] = {
+ {0x00, 0x5a, NULL},
+ {0x5b, 0x5b, arrowHook},
+ {0x5c, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+
+static KeyMap arrowmap[] = {
+ {0x00, 0x31, NULL},
+ {0x32, 0x32, insertToggle},
+ {0x33, 0x40, NULL},
+ {0x41, 0x41, upArrow},
+ {0x42, 0x42, downArrow},
+ {0x43, 0x43, rightArrow},
+ {0x44, 0x44, leftArrow},
+ {0x45, 0xff, NULL},
+ {0x00, 0x00, NULL}
+};
+
+#endif
+
+
+static void doBeep(void)
+{
+ write(1, "\7", 1);
+}
+
+
+static void backspace(void)
+{
+ write(1, "\b", 1);
+}
+
+
+static void erase()
+{
+ int i;
+
+ for (i = 0; i < bufidx; i++) backspace(); /* Backup to beginning of text */
+ for (i = 0; i < strlen((char *)buffer); i++) write(1, " ", 1); /* Erase all text */
+ for (i = 0; i < strlen((char *)buffer); i++) backspace(); /* Backup to beginning of text */
+}
+
+/*----------------------------------------------------------------------*\
+
+ Character handling hook functions
+
+\*----------------------------------------------------------------------*/
+
+static void execute(KeyMap map[], unsigned char ch)
+{
+ int i = 0;
+
+ for (i = 0; i <= 256; i++) {
+ if (i > 0 && map[i].min == 0x00) break; /* End marker is a 0,0,NULL */
+ if (map[i].min <= ch && ch <= map[i].max) {
+ if (map[i].hook != NULL) {
+ map[i].hook(ch);
+ return;
+ } else
+ doBeep();
+ }
+ }
+ doBeep();
+}
+
+
+static void upArrow(char ch)
+{
+ /* Is there more history ? */
+ if (history[(histp+HISTORYLENGTH-1)%HISTORYLENGTH] == NULL ||
+ (histp+HISTORYLENGTH-1)%HISTORYLENGTH == histidx) {
+ write(1, "\7", 1);
+ return;
+ }
+
+ erase();
+
+ /* Backup history pointer */
+ histp = (histp+HISTORYLENGTH-1)%HISTORYLENGTH;
+
+ /* Copy the history and write it */
+ strcpy((char *)buffer, (char *)history[histp]);
+ bufidx = strlen((char *)buffer);
+ write(1, (void *)buffer, strlen((char *)buffer));
+
+}
+
+
+static void downArrow(char ch)
+{
+ /* Is there more history ? */
+ if (histp == histidx) {
+ write(1, "\7", 1);
+ return;
+ }
+
+ erase();
+
+ /* Advance history pointer */
+ histp = (histp+1)%HISTORYLENGTH;
+
+ /* If we are not at the most recent history entry, copy the history and write it */
+ if (histp != histidx) {
+ strcpy((char *)buffer, (char *)history[histp]);
+ bufidx = strlen((char *)buffer);
+ write(1, (void *)buffer, strlen((char *)buffer));
+ } else {
+ bufidx = 0;
+ buffer[0] = '\0';
+ }
+}
+
+
+static void rightArrow(char ch)
+{
+ if (bufidx > LINELENGTH || buffer[bufidx] == '\0')
+ doBeep();
+ else {
+ write(1, (void *)&buffer[bufidx], 1);
+ bufidx++;
+ }
+}
+
+
+static void leftArrow(char ch)
+{
+ if (bufidx == 0)
+ doBeep();
+ else {
+ bufidx--;
+ backspace();
+ }
+}
+
+
+static void insertToggle(char ch)
+{
+ read(0, &ch, 1);
+ if (ch != 'z')
+ doBeep();
+ else
+ insert = !insert;
+}
+
+
+static void delBwd(char ch)
+{
+ if (bufidx == 0)
+ doBeep();
+ else {
+ int i;
+
+ change = TRUE;
+ backspace();
+ bufidx--;
+ for (i = 0; i <= strlen((char *)&buffer[bufidx+1]); i++)
+ buffer[bufidx+i] = buffer[bufidx+1+i];
+ write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
+ write(1, " ", 1);
+ for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace();
+ }
+}
+
+static void delFwd(char ch)
+{
+ if (bufidx > LINELENGTH || buffer[bufidx] == '\0')
+ doBeep();
+ else {
+ int i;
+
+ change = TRUE;
+ strcpy((char *)&buffer[bufidx], (char *)&buffer[bufidx+1]);
+ write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
+ write(1, " ", 1);
+ for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace();
+ }
+}
+
+static void escHook(char ch) {
+ read(0, &ch, 1);
+ execute(escmap, ch);
+}
+
+static void arrowHook(char ch) {
+ read(0, &ch, 1);
+ execute(arrowmap, ch);
+}
+
+static void newLine(char ch)
+{
+ endOfInput = 1;
+ write(1, "\n", 1);
+
+ /* If the input is not the same as the previous, save it in the history */
+ if (change && strlen((char *)buffer) > 0) {
+ if (history[histidx] == NULL)
+ history[histidx] = (unsigned char *)allocate(LINELENGTH+1);
+ strcpy((char *)history[histidx], (char *)buffer);
+ histidx = (histidx+1)%HISTORYLENGTH;
+ }
+}
+
+
+static void insertCh(char ch) {
+ if (bufidx > LINELENGTH)
+ doBeep();
+ else {
+ /* If at end advance the NULL */
+ if (buffer[bufidx] == '\0')
+ buffer[bufidx+1] = '\0';
+ else if (insert) {
+ int i;
+
+ /* If insert mode is on, move the characters ahead */
+ for (i = strlen((char *)buffer); i >= bufidx; i--)
+ buffer[i+1] = buffer[i];
+ write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
+ for (i = strlen((char *)&buffer[bufidx]); i > 0; i--) backspace();
+ }
+ change = TRUE;
+ buffer[bufidx] = ch;
+ write(1, &ch, 1);
+ bufidx++;
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ echoOff()
+
+ */
+static void echoOff()
+{
+#ifdef HAVE_TERMIO
+ newtermio();
+#else
+#ifdef __win__
+#include <windows.h>
+#include <winbase.h>
+#include <wincon.h>
+
+ DWORD handle = GetStdHandle(STD_INPUT_HANDLE);
+
+ (void) SetConsoleMode(handle, 0);
+
+#endif
+#endif
+}
+
+
+/*----------------------------------------------------------------------
+
+ echoOn()
+
+ */
+static void echoOn()
+{
+#ifdef HAVE_TERMIO
+ restoretermio();
+#else
+#ifdef __win__
+#include <windows.h>
+#include <winbase.h>
+#include <wincon.h>
+
+ DWORD handle = GetStdHandle(STD_INPUT_HANDLE);
+ (void) SetConsoleMode(handle, ENABLE_ECHO_INPUT);
+
+#endif
+#endif
+}
+
+
+/*======================================================================
+
+ readline()
+
+ Read a line from the user, with history and editing
+
+ */
+
+/* 4f - length of user buffer should be used */
+Boolean readline(char usrbuf[])
+{
+ fflush(stdout);
+ bufidx = 0;
+ histp = histidx;
+ buffer[0] = '\0';
+ change = TRUE;
+ echoOff();
+ endOfInput = 0;
+ while (!endOfInput) {
+ if (read(0, (void *)&ch, 1) != 1) {
+ echoOn();
+ return FALSE;
+ }
+ execute(keymap, ch);
+ }
+ echoOn();
+ strcpy(usrbuf, (char *)buffer);
+ return TRUE;
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/readline.h b/engines/glk/alan2/readline.h
new file mode 100644
index 0000000..a500224
--- /dev/null
+++ b/engines/glk/alan2/readline.h
@@ -0,0 +1,46 @@
+/* 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 GLK_ALAN2_READLINE
+#define GLK_ALAN2_READLINE
+
+/* Header file for user input, history andediting support */
+
+#include "glk/alan2/types.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#define LINELENGTH 80
+#define HISTORYLENGTH 20
+
+#ifdef _PROTOTYPES_
+extern Boolean readline(char usrbuf[]);
+
+#else
+extern Boolean readline();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/reverse.cpp b/engines/glk/alan2/reverse.cpp
new file mode 100644
index 0000000..cf3e851
--- /dev/null
+++ b/engines/glk/alan2/reverse.cpp
@@ -0,0 +1,552 @@
+/* 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/alan2/types.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/reverse.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/*----------------------------------------------------------------------
+
+ reversed()
+
+ Return the reversed bytes in the Aword
+
+*/
+#ifdef _PROTOTYPES_
+Aword reversed(Aword w) /* IN - The ACODE word to swap bytes of */
+#else
+Aword reversed(w)
+ Aword w; /* IN - The ACODE word to swap bytes of */
+#endif
+{
+ Aword s; /* The swapped ACODE word */
+ char *wp, *sp;
+ int i;
+
+ wp = (char *) &w;
+ sp = (char *) &s;
+
+ for (i = 0; i < sizeof(Aword); i++)
+ sp[sizeof(Aword)-1 - i] = wp[i];
+
+ return s;
+}
+
+
+#ifdef _PROTOTYPES_
+void reverse(Aword *w) /* IN - The ACODE word to reverse bytes in */
+#else
+void reverse(w)
+ Aword *w; /* IN - The ACODE word to reverse bytes in */
+#endif
+{
+ *w = reversed(*w);
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseTable(Aword adr, int len)
+#else
+static void reverseTable(adr, len)
+ Aword adr;
+ int len;
+#endif
+{
+ Aword *e = &memory[adr];
+ int i;
+
+ if (adr != 0)
+ while (!endOfTable(e)) {
+ for (i = 0; i < len/(int)sizeof(Aword); i++) {
+ reverse(e);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseStms(Aword adr)
+#else
+static void reverseStms(adr)
+ Aword adr;
+#endif
+{
+ Aword *e = &memory[adr];
+
+ if (adr != 0)
+ while (TRUE) {
+ reverse(e);
+ if (*e == ((Aword)C_STMOP<<28|(Aword)I_RETURN)) break;
+ e++;
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseMsgs(Aword adr)
+#else
+static void reverseMsgs(adr)
+ Aword adr;
+#endif
+{
+ MsgElem *e = (MsgElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(MsgElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseWrds(Aword adr)
+#else
+static void reverseWrds(adr)
+ Aword adr;
+#endif
+{
+ WrdElem *e = (WrdElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(WrdElem));
+ while (!endOfTable(e)) {
+ if ((e->_class & (1L<<WRD_SYN)) == 0) { /* Do not do this for synonyms */
+ reverseTable(e->adjrefs, sizeof(Aword));
+ reverseTable(e->nounrefs, sizeof(Aword));
+ }
+ e++;
+ }
+ }
+}
+
+#ifdef _PROTOTYPES_
+static void reverseChks(Aword adr)
+#else
+static void reverseChks(adr)
+ Aword adr;
+#endif
+{
+ ChkElem *e = (ChkElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ChkElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
+
+#ifdef _PROTOTYPES_
+static void reverseAlts(Aword adr)
+#else
+static void reverseAlts(adr)
+ Aword adr;
+#endif
+{
+ AltElem *e = (AltElem *)&memory[adr];
+
+ if (adr != 0 && !endOfTable(e) && !e->done) {
+ reverseTable(adr, sizeof(AltElem));
+ e->done = TRUE;
+ while (!endOfTable(e)) {
+ reverseChks(e->checks);
+ reverseStms(e->action);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseVrbs(Aword adr)
+#else
+static void reverseVrbs(adr)
+ Aword adr;
+#endif
+{
+ VrbElem *e = (VrbElem *)&memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(VrbElem));
+ while (!endOfTable(e)) {
+ reverseAlts(e->alts);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseSteps(Aword adr)
+#else
+static void reverseSteps(adr)
+ Aword adr;
+#endif
+{
+ StepElem *e = (StepElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(StepElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stm);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseScrs(Aword adr)
+#else
+static void reverseScrs(adr)
+ Aword adr;
+#endif
+{
+ ScrElem *e = (ScrElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ScrElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->dscr);
+ reverseSteps(e->steps);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseActs(Aword adr)
+#else
+static void reverseActs(adr)
+ Aword adr;
+#endif
+{
+ ActElem *e = (ActElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ActElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->nam);
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseScrs(e->scradr);
+ reverseVrbs(e->vrbs);
+ reverseStms(e->dscr);
+ e++;
+ }
+ }
+}
+
+#ifdef _PROTOTYPES_
+static void reverseObjs(Aword adr, Boolean v2_5)
+#else
+static void reverseObjs(adr, v2_5)
+ Aword adr;
+ Boolean v2_5; /* TRUE if it's a v2.5 format game */
+#endif
+{
+ ObjElem *e = (ObjElem *) &memory[adr];
+ ObjElem25 *e25 = (ObjElem25 *) &memory[adr];
+
+ if (v2_5) {
+ if (adr != 0 && !endOfTable(e25)) {
+ reverseTable(adr, sizeof(ObjElem25));
+ while (!endOfTable(e25)) {
+ reverseTable(e25->atrs, sizeof(AtrElem));
+ reverseVrbs(e25->vrbs);
+ reverseStms(e25->dscr1);
+ reverseStms(e25->dscr2);
+ e25++;
+ }
+ }
+ } else {
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ObjElem));
+ while (!endOfTable(e)) {
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseVrbs(e->vrbs);
+ reverseStms(e->art);
+ reverseStms(e->dscr1);
+ reverseStms(e->dscr2);
+ e++;
+ }
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseExts(Aword adr)
+#else
+static void reverseExts(adr)
+ Aword adr;
+#endif
+{
+ ExtElem *e = (ExtElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ExtElem));
+ while (!endOfTable(e)) {
+ if (!e->done) {
+ reverseChks(e->checks);
+ reverseStms(e->action);
+ }
+ e++;
+ }
+ }
+}
+
+#ifdef _PROTOTYPES_
+static void reverseLocs(Aword adr)
+#else
+static void reverseLocs(adr)
+ Aword adr;
+#endif
+{
+ LocElem *e = (LocElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(LocElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->nams);
+ reverseStms(e->dscr);
+ reverseStms(e->does);
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseExts(e->exts);
+ reverseVrbs(e->vrbs);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseClas(Aword adr)
+#else
+static void reverseClas(adr)
+ Aword adr;
+#endif
+{
+ ClaElem *e = (ClaElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ClaElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+ if (adr)
+ reverse(&((Aword *)e)[1]); /* The verb code is stored after the table */
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseElms(Aword adr)
+#else
+static void reverseElms(adr)
+ Aword adr;
+#endif
+{
+ ElmElem *e = (ElmElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ElmElem));
+ while (!endOfTable(e)) {
+ if (e->code == EOS) reverseClas(e->next);
+ else reverseElms(e->next);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseStxs(Aword adr)
+#else
+static void reverseStxs(adr)
+ Aword adr;
+#endif
+{
+ StxElem *e = (StxElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(StxElem));
+ while (!endOfTable(e)) {
+ reverseElms(e->elms);
+ e++;
+ }
+ }
+}
+
+#ifdef _PROTOTYPES_
+static void reverseEvts(Aword adr)
+#else
+static void reverseEvts(adr)
+ Aword adr;
+#endif
+{
+ EvtElem *e = (EvtElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(EvtElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->code);
+ e++;
+ }
+ }
+}
+
+
+
+#ifdef _PROTOTYPES_
+static void reverseLims(Aword adr)
+#else
+static void reverseLims(adr)
+ Aword adr;
+#endif
+{
+ LimElem *e = (LimElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(LimElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseCnts(Aword adr)
+#else
+static void reverseCnts(adr)
+ Aword adr;
+#endif
+{
+ CntElem *e = (CntElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(CntElem));
+ while (!endOfTable(e)) {
+ reverseLims(e->lims);
+ reverseStms(e->header);
+ reverseStms(e->empty);
+ reverseStms(e->nam);
+ e++;
+ }
+ }
+}
+
+
+#ifdef _PROTOTYPES_
+static void reverseRuls(Aword adr)
+#else
+static void reverseRuls(adr)
+ Aword adr;
+#endif
+{
+ RulElem *e = (RulElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(RulElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ reverseHdr()
+
+ Reverse the header structure.
+
+*/
+#ifdef _PROTOTYPES_
+void reverseHdr(AcdHdr *hdr)
+#else
+void reverseHdr(hdr)
+ AcdHdr *hdr;
+#endif
+{
+ int i;
+
+ /* Reverse all words in the header except the first (version marking) */
+ for (i = 1; i < sizeof(AcdHdr)/sizeof(Aword); i++)
+ reverse(&((Aword *)hdr)[i]);
+}
+
+/*----------------------------------------------------------------------
+
+ reverseACD()
+
+ Traverse all the data structures and reverse all integers.
+ Only performed in architectures with reversed byte ordering, which
+ makes the .ACD files fully compatible across architectures
+
+ */
+#ifdef _PROTOTYPES_
+void reverseACD(Boolean v2_5)
+#else
+void reverseACD(v2_5)
+ Boolean v2_5;
+#endif
+{
+ reverseHdr(header);
+ reverseWrds(header->dict);
+ reverseTable(header->oatrs, sizeof(AtrElem));
+ reverseTable(header->latrs, sizeof(AtrElem));
+ reverseTable(header->aatrs, sizeof(AtrElem));
+ reverseActs(header->acts);
+ reverseObjs(header->objs, v2_5);
+ reverseLocs(header->locs);
+ reverseStxs(header->stxs);
+ reverseVrbs(header->vrbs);
+ reverseEvts(header->evts);
+ reverseCnts(header->cnts);
+ reverseRuls(header->ruls);
+ reverseTable(header->init, sizeof(IniElem));
+ reverseStms(header->start);
+ reverseMsgs(header->msgs);
+
+ reverseTable(header->scores, sizeof(Aword));
+ reverseTable(header->freq, sizeof(Aword));
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/reverse.h b/engines/glk/alan2/reverse.h
new file mode 100644
index 0000000..40807ce
--- /dev/null
+++ b/engines/glk/alan2/reverse.h
@@ -0,0 +1,46 @@
+/* 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 GLK_ALAN2_REVERSE
+#define GLK_ALAN2_REVERSE
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+
+extern void reverseHdr(AcdHdr *hdr);
+extern void reverseACD(Boolean v25);
+extern void reverse(Aword *word);
+extern Aword reversed(Aword word);
+
+#else
+extern void reverseHdr();
+extern void reverseACD();
+extern void reverse();
+extern Aword reversed();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
new file mode 100644
index 0000000..d00d1f3
--- /dev/null
+++ b/engines/glk/alan2/rules.cpp
@@ -0,0 +1,83 @@
+/* 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/alan2/types.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/debug.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/stack.h"
+
+#include "glk/alan2/rules.h"
+
+#ifdef GLK
+#include "glk/alan2/glkio.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+void rules(void)
+#else
+void rules()
+#endif
+{
+ Boolean change = TRUE;
+ int i;
+
+ for (i = 1; !endOfTable(&ruls[i-1]); i++)
+ ruls[i-1].run = FALSE;
+
+ while (change) {
+ change = FALSE;
+ for (i = 1; !endOfTable(&ruls[i-1]); i++)
+ if (!ruls[i-1].run) {
+ if (trcflg) {
+ printf("\n<RULE %d (at ", i);
+ debugsay(cur.loc);
+ if (!stpflg)
+ printf("), Evaluating");
+ else
+ printf("), Evaluating:>\n");
+ }
+ interpret(ruls[i-1].exp);
+ if (pop()) {
+ change = TRUE;
+ ruls[i-1].run = TRUE;
+ if (trcflg)
+ if (!stpflg)
+ printf(", Executing:>\n");
+ else {
+ printf("\nRULE %d (at ", i);
+ debugsay(cur.loc);
+ printf("), Executing:>\n");
+ }
+ interpret(ruls[i-1].stms);
+ } else if (trcflg && !stpflg)
+ printf(":>\n");
+ }
+ }
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/rules.h b/engines/glk/alan2/rules.h
new file mode 100644
index 0000000..1cc0b90
--- /dev/null
+++ b/engines/glk/alan2/rules.h
@@ -0,0 +1,44 @@
+/* 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 GLK_ALAN2_RULES
+#define GLK_ALAN2_RULES
+
+/* Header file for rules handler in Alan interpreter */
+
+namespace Glk {
+namespace Alan2 {
+
+/* TYPES */
+
+#ifdef _PROTOTYPES_
+
+extern void rules(void);
+
+#else
+extern void rules();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/stack.cpp b/engines/glk/alan2/stack.cpp
new file mode 100644
index 0000000..ccce147
--- /dev/null
+++ b/engines/glk/alan2/stack.cpp
@@ -0,0 +1,74 @@
+/* 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/alan2/types.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/stack.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/* PRIVATE DATA */
+
+#define STACKSIZE 100
+
+/* The AMACHINE STACK */
+static Aptr stack[STACKSIZE];
+static int stackp = 0;
+
+
+#ifdef _PROTOTYPES_
+void push(Aptr i)
+#else
+void push(i)
+ Aptr i;
+#endif
+{
+ if (stackp == STACKSIZE)
+ syserr("Out of stack space.");
+ stack[stackp++] = i;
+}
+
+
+#ifdef _PROTOTYPES_
+Aptr pop(void)
+#else
+Aptr pop()
+#endif
+{
+ if (stackp == 0)
+ syserr("Stack underflow.");
+ return(stack[--stackp]);
+}
+
+
+#ifdef _PROTOTYPES_
+Aptr top(void)
+#else
+Aptr top()
+#endif
+{
+ return(stack[stackp-1]);
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/stack.h b/engines/glk/alan2/stack.h
new file mode 100644
index 0000000..7f10c08
--- /dev/null
+++ b/engines/glk/alan2/stack.h
@@ -0,0 +1,48 @@
+/* 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 GLK_ALAN2_STACK
+#define GLK_ALAN2_STACK
+
+/* Header file for stack handler in Alan interpreter */
+
+namespace Glk {
+namespace Alan2 {
+
+/* TYPES */
+
+#ifdef _PROTOTYPES_
+
+extern Aptr pop(void);
+extern void push(Aptr item);
+extern Aptr top(void);
+
+#else
+extern Aptr pop();
+extern void push();
+extern Aptr top();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
new file mode 100644
index 0000000..daa0417
--- /dev/null
+++ b/engines/glk/alan2/sysdep.cpp
@@ -0,0 +1,493 @@
+/* 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 <string.h>
+#include "glk/alan2/sysdep.h"
+
+#ifdef GLK
+#include "glk/alan2/alan2.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+extern void syserr(char str[]);
+#endif
+
+#ifdef __vms__
+
+char *strdup(char str[]) /* IN - String to duplicate */
+{
+ char *new = (char *) malloc(strlen(str)+1);
+
+ if (!new)
+ syserr("Out of memory");
+ strcpy(new, str);
+ return new;
+}
+
+#endif
+
+
+#ifdef __mac__
+
+char *strdup(char str[]) /* IN - String to duplicate */
+{
+ char *new = (char *) malloc((size_t)((int)strlen(str)+1));
+
+ if (!new)
+ syserr("Out of memory");
+ strcpy(new, str);
+ return new;
+}
+
+#endif
+
+
+#ifdef __vms__
+
+/* Cheat implementation of strftime */
+size_t strftime (
+ char *outbuf,
+ size_t len,
+ const char *format,
+ const struct tm *t)
+{
+ char buf[100];
+ time_t ticks;
+
+ time(&ticks);
+ strcpy(buf, ctime(&ticks));
+ buf[strlen(buf)-1] = '\0';
+ strcpy(outbuf, &buf[4]);
+}
+
+#endif
+
+#ifdef __dos__
+#endif
+
+#ifdef GLK
+
+/* Note to Glk maintainers: 'native' characters are used for output, in this
+ case, Glk's Latin-1. ISO characters are Alan's internal representation,
+ stored in the .DAT file, and must be converted to native before printing.
+ Glk could just use the ISO routines directly, but its safer to maintain
+ its own tables to guard against future changes in either Alan or Glk (ie. a
+ move to Unicode).
+ */
+
+static char spcChrs[] =
+{
+ '\x0A', /* linefeed */
+ '\x20', /* space */
+ '\xA0', /* non-breaking space */
+ '\x00'
+};
+
+static char lowChrs[] =
+{
+ '\x61', /* a */ '\x62', /* b */ '\x63', /* c */ '\x64', /* d */
+ '\x65', /* e */ '\x66', /* f */ '\x67', /* g */ '\x68', /* h */
+ '\x69', /* i */ '\x6A', /* j */ '\x6B', /* k */ '\x6C', /* l */
+ '\x6D', /* m */ '\x6E', /* n */ '\x6F', /* o */ '\x70', /* p */
+ '\x71', /* q */ '\x72', /* r */ '\x73', /* s */ '\x74', /* t */
+ '\x75', /* u */ '\x76', /* v */ '\x77', /* w */ '\x78', /* x */
+ '\x79', /* y */ '\x7A', /* z */ '\xDF', /* ss <small sharp s> */
+ '\xE0', /* a grave */ '\xE1', /* a acute */
+ '\xE2', /* a circumflex */ '\xE3', /* a tilde */
+ '\xE4', /* a diaeresis */ '\xE5', /* a ring */
+ '\xE6', /* ae */ '\xE7', /* c cedilla */
+ '\xE8', /* e grave */ '\xE9', /* e acute */
+ '\xEA', /* e circumflex */ '\xEB', /* e diaeresis */
+ '\xEC', /* i grave */ '\xED', /* i acute */
+ '\xEE', /* i circumflex */ '\xEF', /* i diaeresis */
+ '\xF0', /* <small eth> */ '\xF1', /* n tilde */
+ '\xF2', /* o grave */ '\xF3', /* o acute */
+ '\xF4', /* o circumflex */ '\xF5', /* o tilde */
+ '\xF6', /* o diaeresis */ '\xF8', /* o slash */
+ '\xF9', /* u grave */ '\xFA', /* u acute */
+ '\xFB', /* u circumflex */ '\xFC', /* u diaeresis */
+ '\xFD', /* y acute */ '\xFE', /* <small thorn> */
+ '\xFF', /* y diaeresis */ '\x00'
+};
+
+/* FIXME: ss <small sharp s> and y diaeresis have no UC analogues
+ Are they really considered LC?
+ */
+
+static char uppChrs[] =
+{
+ '\x41', /* A */ '\x42', /* B */ '\x43', /* C */ '\x44', /* D */
+ '\x45', /* E */ '\x46', /* F */ '\x47', /* G */ '\x48', /* H */
+ '\x49', /* I */ '\x4A', /* J */ '\x4B', /* K */ '\x4C', /* L */
+ '\x4D', /* M */ '\x4E', /* N */ '\x4F', /* O */ '\x50', /* P */
+ '\x51', /* Q */ '\x52', /* R */ '\x53', /* S */ '\x54', /* T */
+ '\x55', /* U */ '\x56', /* V */ '\x57', /* W */ '\x58', /* X */
+ '\x59', /* Y */ '\x5A', /* Z */
+ '\xC0', /* A grave */ '\xC1', /* A acute */
+ '\xC2', /* A circumflex */ '\xC3', /* A tilde */
+ '\xC4', /* A diaeresis */ '\xC5', /* A ring */
+ '\xC6', /* AE */ '\xC7', /* C cedilla */
+ '\xC8', /* E grave */ '\xC9', /* E acute */
+ '\xCA', /* E circumflex */ '\xCB', /* E diaeresis */
+ '\xCC', /* I grave */ '\xCD', /* I acute */
+ '\xCE', /* I circumflex */ '\xCF', /* I diaeresis */
+ '\xD0', /* <capital eth> */ '\xD1', /* N tilde */
+ '\xD2', /* O grave */ '\xD3', /* O acute */
+ '\xD4', /* O circumflex */ '\xD5', /* O tilde */
+ '\xD6', /* O diaeresis */ '\xD8', /* O slash */
+ '\xD9', /* U grave */ '\xDA', /* U acute */
+ '\xDB', /* U circumflex */ '\xDC', /* U diaeresis */
+ '\xDD', /* Y acute */ '\xDE', /* <capital thorn> */
+ '\x00'
+};
+
+#else
+
+/* Theses work on native character sets */
+
+static char spcChrs[] = " \t\n";
+
+#ifdef __amiga__
+
+/* Which can't read 8-bit chars but is ISO */
+static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
+
+static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
+
+#else
+
+/* Use native characters */
+static char lowChrs[] = "abcdefghijklmnopqrstuvwxyzàáâãäåæçéêëìíîïðñòóôõöøùúûüýþÿ";
+
+static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÛÝÞß";
+
+#endif
+#endif
+
+int isSpace(int c) /* IN - Native character to test */
+{
+ return (c != '\0' && strchr(spcChrs, c) != 0);
+}
+
+
+int isLower(int c) /* IN - Native character to test */
+{
+ return (c != '\0' && strchr(lowChrs, c) != 0);
+}
+
+
+int isUpper(int c) /* IN - Native character to test */
+{
+ return (c != '\0' && strchr(uppChrs, c) != 0);
+}
+
+int isLetter(int c) /* IN - Native character to test */
+{
+ return(c != '\0' && (isLower(c)? !0: isUpper(c)));
+}
+
+
+int toLower(int c) /* IN - Native character to convert */
+{
+#ifdef GLK
+ return g_vm->glk_char_to_lower(c);
+#else
+#ifdef __dos__
+ char *cp;
+
+ if ((cp = strchr(uppChrs, c)) != 0)
+ return(lowChrs[cp-uppChrs]);
+ else
+ return c;
+#else
+#ifdef __mac__
+ char *cp;
+
+ if ((cp = strchr(uppChrs, c)) != 0)
+ return(lowChrs[cp-uppChrs]);
+ else
+ return c;
+#else
+ return (isUpper(c)? c + ('a' - 'A'): c);
+#endif
+#endif
+#endif
+}
+
+int toUpper(int c) /* IN - Native character to convert */
+{
+#ifdef GLK
+ return g_vm->glk_char_to_upper(c);
+#else
+#ifdef __dos__
+ char *cp;
+
+ if ((cp = strchr(lowChrs, c)) != 0)
+ return(uppChrs[cp-lowChrs]);
+ else
+ return c;
+#else
+#ifdef __mac__
+ char *cp;
+
+ if ((cp = strchr(lowChrs, c)) != 0)
+ return(uppChrs[cp-lowChrs]);
+ else
+ return c;
+#else
+ return (isLower(c)? c - ('a' - 'A'): c);
+#endif
+#endif
+#endif
+}
+
+char *strlow(char str[]) /* INOUT - Native string to convert */
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = toLower(*s);
+ return(str);
+}
+
+
+char *strupp(char str[]) /* INOUT - Native string to convert */
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = toUpper(*s);
+ return(str);
+}
+
+
+/* The following work on ISO characters */
+
+int isLowerCase(int c) /* IN - ISO character to test */
+{
+ static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
+ return (c != '\0' && strchr(lowChrs, c) != 0);
+}
+
+
+int isUpperCase(int c) /* IN - ISO character to test */
+{
+ static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
+ return (c != '\0' && strchr(uppChrs, c) != 0);
+}
+
+
+int isISOLetter(int c) /* IN - ISO character to test */
+{
+ return (isLowerCase(c) || isUpperCase(c));
+}
+
+
+char toLowerCase(int c) /* IN - ISO character to convert */
+{
+ return (isUpperCase(c)? c + ('a' - 'A'): c);
+}
+
+
+char toUpperCase(int c) /* IN - ISO character to convert */
+{
+ return (isLowerCase(c)? c - ('a' - 'A'): c);
+}
+
+
+char *stringLower(char str[]) /* INOUT - ISO string to convert */
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = toLowerCase(*s);
+ return(str);
+}
+
+
+char *stringUpper(char str[]) /* INOUT - ISO string to convert */
+{
+ char *s;
+
+ for (s = str; *s; s++)
+ *s = toUpperCase(*s);
+ return(str);
+}
+
+
+/*----------------------------------------------------------------------
+ toIso
+
+ Converts the incoming string to ISO character set. The original is
+ in the current character set which in the case of the compiler might
+ be other than the native.
+
+ */
+void toIso(char copy[], /* OUT - Mapped string */
+ char original[], /* IN - string to convert */
+ int charset) /* IN - the current character set */
+{
+static unsigned char macMap[256]
+= {
+0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0A,0x0E,0x0F,
+0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+0xC4,0xC5,0xC7,0xC9,0xD1,0xD6,0xDC,0xE1,0xE0,0xE2,0xE4,0xE3,0xE5,0xE7,0xE9,0xE8,
+0xEA,0xEB,0xED,0xEC,0xEE,0xEF,0xF1,0xF3,0xF2,0xF4,0xF6,0xF5,0xFA,0xF9,0xFB,0xFC,
+0xB9,0xB0,0xA2,0xA3,0xA7,0xB7,0xB6,0xDF,0xAE,0xA9,0xB2,0xB4,0xA8,0xD7,0xC6,0xD8,
+0xA4,0xB1,0xCD,0xCC,0xA5,0xB5,0xF0,0xCA,0xDE,0xFE,0xA6,0xAA,0xBA,0xD4,0xE6,0xF8,
+0xBF,0xA1,0xAC,0xCE,0xCF,0xC8,0xD0,0xAB,0xBB,0xCB,0xA0,0xC0,0xC3,0xD5,0xDD,0xFD,
+0xAD,0xAF,0xDA,0xD9,0xB8,0xB3,0xF7,0xC2,0xFF,0xBC,0xBD,0xBE,0xC1,0xD2,0xD3,0xDB,
+0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F};
+
+static unsigned char dosMap[256]
+= {
+0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0A,0x0E,0x0F,
+0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+0xC7,0xFC,0xE9,0xE2,0xE4,0xE0,0xE5,0xE7,0xEA,0xEB,0xE8,0xEF,0xEE,0xEC,0xC4,0xC5,
+0xC9,0xE6,0xC6,0xF4,0xF6,0xF2,0xFB,0xF9,0xFF,0xD6,0xDC,0xA2,0xA3,0xA5,0xDE,0xA6,
+0xE1,0xED,0xF3,0xFA,0xF1,0xD1,0xAA,0xBA,0xBF,0xC0,0xC1,0xBD,0xBC,0xCF,0xAB,0xBB,
+0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
+0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
+0xA1,0xA7,0xAD,0xB3,0xB8,0xB9,0xC3,0xCE,0xD2,0xD3,0xDB,0xDD,0xE3,0xF5,0xF8,0xFD,
+0xA9,0xDF,0xC8,0xB6,0xCA,0xA4,0xB5,0xAE,0xD5,0xD0,0xD4,0xF0,0xD7,0xD8,0xCB,0xC2,
+0xBE,0xB1,0xD9,0xDA,0xCD,0xCC,0xF7,0xA8,0xB0,0xB7,0xAF,0xAC,0xFE,0xB2,0xB4,0xA0};
+ unsigned char *o, *c;
+
+ switch (charset) {
+ case 0: /* ISO */
+ if (copy != original)
+ (void)strcpy(copy, original);
+ break;
+ case 1: /* Mac */
+ for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
+ *c = macMap[*o];
+ *c = '\0';
+ break;
+
+ case 2: /* Dos */
+ for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
+ *c = dosMap[*o];
+ *c = '\0';
+ break;
+ }
+}
+
+/*----------------------------------------------------------------------
+
+ fromIso
+
+ Converts a string from global Iso format to native. Only used in
+ interpreter so character set is known at compile time.
+
+ */
+void fromIso(char copy[], /* OUT - Mapped string */
+ char original[]) /* IN - string to convert */
+{
+#if ISO == 0
+ static unsigned char map[256]
+#if defined __mac__
+ = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
+ 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
+ 0xCA,0xC1,0xA2,0xA3,0xB0,0xB4,0xBA,0xA4,0xAC,0xA9,0xBB,0xC7,0xC2,0xD0,0xA8,0xD1,
+ 0xA1,0xB1,0xAA,0xD5,0xAB,0xB5,0xA6,0xA5,0xD4,0xA0,0xBC,0xC8,0xD9,0xDA,0xDB,0xC0,
+ 0xCB,0xDC,0xD7,0xCC,0x80,0x81,0xAE,0x82,0xC5,0x83,0xB7,0xC9,0xB3,0xB2,0xC3,0xC4,
+ 0xC6,0x84,0xDD,0xDE,0xBD,0xCD,0x85,0xAD,0xAF,0xD3,0xD2,0xDF,0x86,0xCE,0xB8,0xA7,
+ 0x88,0x87,0x89,0x8B,0x8A,0x8C,0xBE,0x8D,0x8F,0x8E,0x90,0x91,0x93,0x92,0x94,0x95,
+ 0xB6,0x96,0x98,0x97,0x99,0x9B,0x9A,0xD6,0xBF,0x9D,0x9C,0x9E,0x9F,0xCF,0xB9,0xD8}
+#else
+#if defined __dos__
+ = {
+ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F,
+ 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
+ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
+ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
+ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
+ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
+ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
+ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
+ 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
+ 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
+ 0xFF,0xD0,0x9B,0x9C,0xE5,0x9D,0x9F,0xD1,0xF7,0xE0,0xA6,0xAE,0xFB,0xD2,0xE7,0xFA,
+ 0xF8,0xF1,0xFD,0xD3,0xFE,0xE6,0xE3,0xF9,0xD4,0xD5,0xA7,0xAF,0xAC,0xAB,0xF0,0xA8,
+ 0xA9,0xAA,0xEF,0xD6,0x8E,0x8F,0x92,0x80,0xE2,0x90,0xE4,0xEE,0xF5,0xF4,0xD7,0xAD,
+ 0xE9,0xA5,0xD8,0xD9,0xEA,0xE8,0x99,0xEC,0xED,0xF2,0xF3,0xDA,0x9A,0xDB,0x9E,0xE1,
+ 0x85,0xA0,0x83,0xDC,0x84,0x86,0x91,0x87,0x8A,0x82,0x88,0x89,0x8D,0xA1,0x8C,0x8B,
+ 0xEB,0xA4,0x95,0xA2,0x93,0xDD,0x94,0xF6,0xDE,0x97,0xA3,0x96,0x81,0xDF,0xFC,0x98}
+#endif
+ ;
+#endif
+ unsigned char *o, *c;
+
+ for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
+ *c = map[*o];
+ *c = '\0';
+#else
+ if (copy != original)
+ (void)strcpy(copy, original);
+#endif
+}
+
+
+/*----------------------------------------------------------------------
+ toNative
+
+ Converts the incoming string to the native character set from any of
+ the others. The original is in the current character set which in
+ the case of the compiler might be other than the native.
+
+ */
+void toNative(char copy[], /* OUT - Mapped string */
+ char original[], /* IN - string to convert */
+ int charset) /* IN - the current character set */
+{
+ toIso(copy, original, charset);
+ if (NATIVECHARSET != 0)
+ fromIso(copy, copy);
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h
new file mode 100644
index 0000000..72769cb
--- /dev/null
+++ b/engines/glk/alan2/sysdep.h
@@ -0,0 +1,409 @@
+/* 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 GLK_ALAN2_SYSDEP
+#define GLK_ALAN2_SYSDEP
+
+/* System dependencies file for Alan Adventure Language system
+ *
+ * N.B.The test for symbols used here should really be of three types
+ * - processor name(like PC, x86, ...)
+ * - os name(DOS, WIN32, Solaris2, ...)
+ * - compiler name andversion(DJGPP, CYGWIN, GCC271, THINK-C, ...)
+ *
+ * The set symbols should indicate if a feature is on or off like the GNU
+ * AUTOCONFIG package does.
+ *
+ * This is not completely done yet!
+ */
+
+#include "common/scummsys.h"
+
+namespace Glk {
+namespace Alan2 {
+
+#define GLK
+#define _PROTOTYPES_
+#define __win__
+
+#ifdef GLK
+#undef isdigit
+#define isdigit Common::isDigit
+#undef stricmp
+#define stricmp scumm_stricmp
+#undef strdup
+#define strdup scumm_strdup
+#undef rand
+#define rand() g_vm->getRandomNumber(0x7fffffff)
+#undef fprintf
+#define fprintf(FP, STR) FP->write(STR, strlen(STR) + 1)
+#endif
+
+/* Place definitions of OS and compiler here if necessary */
+#ifdef AZTEC_C
+#define __amiga__
+#endif
+
+#ifndef __sun__
+#ifdef sun
+#define __sun__
+#endif
+#endif
+
+#ifdef _INCLUDE_HPUX_SOURCE
+#define __hp__
+#endif
+
+#ifndef __unix__
+#ifdef unix
+#define __unix__
+#endif
+#endif
+
+#ifdef vax
+#define __vms__
+#endif
+
+#ifdef THINK_C
+#define __mac__
+#endif
+
+#ifdef __MWERKS__
+#ifdef macintosh
+#define __mac__
+#else
+#define __dos__
+#endif
+#endif
+
+#ifdef DOS
+#define __dos__
+#endif
+
+#ifdef __BORLANDC__
+#define __dos__
+#endif
+
+#ifdef __CYGWIN__
+#define __win__
+#endif
+
+#ifdef __MINGW32__
+#define __win__
+#endif
+
+#ifdef __PACIFIC__
+#define __dos__
+#define HAVE_SHORT_FILENAMES
+#endif
+
+
+/*----------------------------------------------------------------------
+
+ Below follows OS and compiler dependent settings. They should not be
+ changed except for introducing new sections when porting to new
+ environments.
+
+ */
+
+/************/
+/* Includes */
+/************/
+
+#ifndef GLK
+#include <stdio.h>
+#include <ctype.h>
+#endif
+
+#ifdef __STDC__
+#define _PROTOTYPES_
+#include <stdlib.h>
+#include <string.h>
+#endif
+
+#ifdef __vms__
+/* Our VAXC doesn't define __STDC__ */
+#define _PROTOTYPES_
+#include <stdlib.h>
+#include <string.h>
+#endif
+
+
+#ifdef __mac__
+#define _PROTOTYPES_
+#include <stdlib.h>
+#include <string.h>
+#include <unix.h>
+#endif
+
+#ifdef __MWERKS__
+#define strdup _strdup
+#endif
+
+/***********************/
+/* ISO character sets? */
+/***********************/
+
+/* Common case first */
+#define ISO 1
+#define NATIVECHARSET 0
+
+#ifdef GLK
+#undef ISO
+#define ISO 1
+#undef NATIVECHARSET
+#define NATIVECHARSET 0
+#else /* Glk is ISO, no matter what the OS */
+
+#ifdef __dos__
+#undef ISO
+#define ISO 0
+#undef NATIVECHARSET
+#define NATIVECHARSET 2
+#endif
+
+#ifdef __win__
+#undef ISO
+#define ISO 1
+#undef NATIVECHARSET
+#define NATIVECHARSET 2
+#endif
+
+#ifdef __mac__
+#undef ISO
+#define ISO 0
+#undef NATIVECHARSET
+#define NATIVECHARSET 1
+#endif
+
+#endif
+
+/**************************/
+/* Strings for file modes */
+/**************************/
+#define READ_MODE "r"
+#define WRITE_MODE "w"
+
+#ifdef __mac__
+/* File open mode (binary) */
+#undef READ_MODE
+#define READ_MODE "rb"
+#undef WRITE_MODE
+#define WRITE_MODE "wb"
+#endif
+
+#ifdef __dos__
+/* File open mode (binary) */
+#undef READ_MODE
+#define READ_MODE "rb"
+#undef WRITE_MODE
+#define WRITE_MODE "wb"
+#endif
+
+#ifdef __win__
+/* File open mode (binary) */
+#undef READ_MODE
+#define READ_MODE "rb"
+#undef WRITE_MODE
+#define WRITE_MODE "wb"
+#endif
+
+/*****************/
+/* Byte ordering */
+/*****************/
+
+#ifdef __dos__
+#define REVERSED
+#endif
+
+#ifdef __vms__
+#define REVERSED
+#endif
+
+#ifdef __win__
+#ifndef REVERSED
+#define REVERSED
+#endif
+#endif
+
+
+/****************************/
+/* Allocates cleared bytes? */
+/****************************/
+
+#ifdef __CYGWIN__
+#define NOTCALLOC
+#endif
+
+#ifdef __MINGW32__
+#define NOTCALLOC
+#endif
+
+#ifdef __unix__
+#define NOTCALLOC
+#endif
+
+
+/****************/
+/* Have termio? */
+/****************/
+
+#ifdef GLK
+/* don't need TERMIO */
+#else
+
+#ifdef __CYGWIN__
+#define HAVE_TERMIO
+#endif
+
+#ifdef __unix__
+#define HAVE_TERMIO
+#endif
+
+#endif
+
+/*******************************/
+/* Is ANSI control available? */
+/*******************************/
+
+#ifdef GLK
+/* don't need ANSI */
+#else
+
+#ifdef __CYGWIN__
+#define HAVE_ANSI
+#endif
+
+#endif
+
+/******************************/
+/* Use the READLINE function? */
+/******************************/
+
+#ifdef GLK
+/* Glk always uses readline(), no matter what the OS */
+#define USE_READLINE
+#else
+
+#ifdef __unix__
+#define USE_READLINE
+#endif
+
+#ifdef x__dos__
+#define USE_READLINE
+#endif
+
+#ifdef __win__
+#define USE_READLINE
+#endif
+
+#endif
+
+/* Special cases and definition overrides */
+#ifdef __unix__
+#define MULTI
+#endif
+
+
+
+
+#ifdef __vms__
+
+#define MULTI
+
+extern char *strdup(char str[]);
+
+/* Cheat implementation of strftime */
+extern size_t strftime (char *, size_t, const char *, const struct tm *);
+
+#endif
+
+#ifdef __mac__
+
+extern char *strdup(char *str);
+
+#endif
+
+
+#ifdef __dos__
+
+/* Return codes */
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
+#endif
+
+
+#ifdef _PROTOTYPES_
+
+/* Native character functions */
+extern int isSpace(int c); /* IN - Native character to test */
+extern int isLower(int c); /* IN - Native character to test */
+extern int isUpper(int c); /* IN - Native character to test */
+extern int isLetter(int c); /* IN - Native character to test */
+extern int toLower(int c); /* IN - Native character to convert */
+extern int toUpper(int c); /* IN - Native character to convert */
+extern char *strlow(char str[]); /* INOUT - Native string to convert */
+extern char *strupp(char str[]); /* INOUT - Native string to convert */
+
+/* ISO character functions */
+extern int isISOLetter(int c); /* IN - ISO character to test */
+extern char toLowerCase(int c); /* IN - ISO character to convert */
+extern char toUpperCase(int c); /* IN - ISO character to convert */
+extern char *stringLower(char str[]); /* INOUT - ISO string to convert */
+extern char *stringUpper(char str[]); /* INOUT - ISO string to convert */
+
+/* ISO string conversion functions */
+extern void toIso(char copy[], /* OUT - Mapped string */
+ char original[], /* IN - string to convert */
+ int charset); /* IN - The current character set */
+
+extern void fromIso(char copy[], /* OUT - Mapped string */
+ char original[]); /* IN - string to convert */
+
+extern void toNative(char copy[], /* OUT - Mapped string */
+ char original[], /* IN - string to convert */
+ int charset); /* IN - current character set */
+#else
+extern int isSpace();
+extern int isLower();
+extern int isUpper();
+extern int isLetter();
+extern int toLower();
+extern int toUpper();
+extern char *strlow();
+extern char *strupp();
+
+extern int isISOLetter();
+extern char toLowerCase();
+extern char toUpperCase();
+extern char *stringLower();
+extern char *stringUpper();
+
+extern void toIso();
+extern void fromIso();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/term.cpp b/engines/glk/alan2/term.cpp
new file mode 100644
index 0000000..cf60fc5
--- /dev/null
+++ b/engines/glk/alan2/term.cpp
@@ -0,0 +1,123 @@
+/* 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/alan2/main.h"
+#include "glk/alan2/term.h"
+
+namespace Glk {
+namespace Alan2 {
+
+/*======================================================================
+
+ getPageSize()
+
+ Try to get the current page size from the system, else use the ones
+ from the header.
+
+ */
+#ifdef _PROTOTYPES_
+void getPageSize(void)
+#else
+void getPageSize()
+#endif
+{
+#ifdef GLK
+ paglen = 0;
+ pagwidth = 0;
+
+#else
+#ifdef HAVE_TERMIO
+
+#include <sys/termios.h>
+
+ extern int ioctl();
+
+ struct winsize win;
+ int ecode;
+
+ ecode = ioctl(1, TIOCGWINSZ, &win);
+
+ if (ecode != 0 || win.ws_row == 0)
+ paglen = header->paglen;
+ else
+ paglen = win.ws_row;
+
+ if (ecode != 0 || win.ws_col == 0)
+ pagwidth = header->pagwidth;
+ else
+ pagwidth = win.ws_col;
+
+#else
+#ifdef __amiga__
+#include <libraries/dosextens.h>
+#include <intuition/intuition.h>
+#include <graphics/text.h>
+#include <clib/exec_protos.h>
+
+ struct Process * proc;
+ struct InfoData *id;
+ struct Window *win;
+ struct TextFont *textFont;
+ struct StandardPacket *packet;
+
+ proc = (struct Process *) FindTask(0L);
+
+ id = (struct InfoData *) allocate(sizeof(struct InfoData));
+
+ if (proc->pr_ConsoleTask) {
+ packet = (struct StandardPacket *) allocate(sizeof(struct StandardPacket));
+ packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
+ packet->sp_Pkt.dp_Link = & packet->sp_Msg;
+ packet->sp_Pkt.dp_Port = & proc->pr_MsgPort;
+ packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
+
+ packet->sp_Pkt.dp_Arg1 = ((LONG) id) >> 2;
+
+ PutMsg ((struct MsgPort *) proc->pr_ConsoleTask, & packet->sp_Msg);
+ WaitPort(&proc->pr_MsgPort);
+ GetMsg(&proc->pr_MsgPort);
+ free((char *)packet);
+
+ win = (struct Window *) id->id_VolumeNode;
+ free(id);
+
+ /* Calculate number of characters and lines w.r.t font size and borders */
+ textFont = win->IFont;
+ paglen = win->Height/textFont->tf_YSize-2;
+ pagwidth = win->Width/textFont->tf_XSize-3;
+ } else {
+ paglen = header->paglen;
+ pagwidth = header->pagwidth;
+ }
+
+#else
+
+ paglen = header->paglen;
+ pagwidth = header->pagwidth;
+
+#endif
+#endif
+#endif
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/term.h b/engines/glk/alan2/term.h
new file mode 100644
index 0000000..339a3b5
--- /dev/null
+++ b/engines/glk/alan2/term.h
@@ -0,0 +1,42 @@
+/* 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 GLK_ALAN2_TERM
+#define GLK_ALAN2_TERM
+
+/* Header file for terminal functions in ARUN, the Alan interpreter */
+
+namespace Glk {
+namespace Alan2 {
+
+#ifdef _PROTOTYPES_
+
+extern void getPageSize(void);
+
+#else
+extern void getPageSize();
+#endif
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 7da9e1d..2de31c0 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -23,248 +23,261 @@
#ifndef GLK_ALAN2_TYPES
#define GLK_ALAN2_TYPES
+#include "glk/alan2/sysdep.h"
#include "glk/alan2/acode.h"
namespace Glk {
namespace Alan2 {
-// CONSTANTS
-
-#define ACTMIN (_vm->header->actmin)
-#define ACTMAX (_vm->header->actmax)
-#define OBJMIN (_vm->header->objmin)
-#define OBJMAX (_vm->header->objmax)
-#define LOCMIN (_vm->header->locmin)
-#define LOCMAX (_vm->header->locmax)
-#define CNTMIN (_vm->header->cntmin)
-#define CNTMAX (_vm->header->cntmax)
-#define LITMIN (_vm->header->locmax + 1)
-#define LITMAX (_vm->header->locmax + 1 + litCount)
-#define EVTMIN (_vm->header->evtmin)
-#define EVTMAX (_vm->header->evtmax)
+/* CONSTANTS */
+
+#ifndef __mac__
+#ifndef TRUE
+#define TRUE (0==0)
+#endif
+#ifndef FALSE
+#define FALSE (!TRUE)
+#endif
+#endif
+
+#define ACTMIN (header->actmin)
+#define ACTMAX (header->actmax)
+#define OBJMIN (header->objmin)
+#define OBJMAX (header->objmax)
+#define LOCMIN (header->locmin)
+#define LOCMAX (header->locmax)
+#define CNTMIN (header->cntmin)
+#define CNTMAX (header->cntmax)
+#define LITMIN (header->locmax+1)
+#define LITMAX (header->locmax+1+litCount)
+#define EVTMIN (header->evtmin)
+#define EVTMAX (header->evtmax)
#define HERO ACTMIN
-#define addrTo(x) (&_vm->memory[x])
-
-// The word classes are represented as numbers but in the dictonary they are generated as bits
-#define isVerb(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_VRB))!=0)
-#define isConj(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_CONJ))!=0)
-#define isBut(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_BUT))!=0)
-#define isThem(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_THEM))!=0)
-#define isIt(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_IT))!=0)
-#define isNoun(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_NOUN))!=0)
-#define isAdj(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_ADJ))!=0)
-#define isPrep(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_PREP))!=0)
-#define isAll(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_ALL))!=0)
-#define isDir(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_DIR))!=0)
-#define isNoise(word) (word < dictsize && (dict[word].wordClass&((Aword)1L<<WRD_NOISE))!=0)
+#define addrTo(x) (&memory[x])
+
+/* The word classes are represented as numbers but in the dictonary they are generated as bits */
+#define isVerb(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_VRB))!=0)
+#define isConj(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_CONJ))!=0)
+#define isBut(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_BUT))!=0)
+#define isThem(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_THEM))!=0)
+#define isIt(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_IT))!=0)
+#define isNoun(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOUN))!=0)
+#define isAdj(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ADJ))!=0)
+#define isPrep(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_PREP))!=0)
+#define isAll(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ALL))!=0)
+#define isDir(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_DIR))!=0)
+#define isNoise(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOISE))!=0)
#define isLiteral(word) (word >= dictsize)
-// TYPES
-
-// Amachine variables
-struct CurVars {
- int vrb;
- int obj;
- int loc;
- int act;
- int tick;
- int score;
- int visits;
-};
-
-// The various tables
-struct WrdElem { // Dictionary
- Aaddr wrd; // ACODE address to string
- Aword wordClass; // Word class
- Aword code;
- Aaddr adjrefs; // Address to reference list
- Aaddr nounrefs; // Address to reference list
-};
-
-struct ActElem { // ACTOR TABLE
- Aword loc; // Location
- Abool describe; // Description flag
- Aaddr nam; // Address to name printing code
- Aaddr atrs; // Address to attribute list
- Aword cont; // Code for the container props if any
- Aword script; // Which script is he using
- Aaddr scradr; // Address to script table
- Aword step;
- Aword count;
- Aaddr vrbs;
- Aaddr dscr; // Address of description code
-};
-
-struct ScrElem { // SCRIPT TABLE
- Aword code; // Script number
- Aaddr dscr; // Optional description statements
- Aaddr steps; // Address to steps
-};
-
-struct StepElem { // STEP TABLE
- Aword after; // After how many ticks?
- Aaddr exp; // Address to expression saying when
- Aaddr stm; // Address to the actual code
-};
-
-struct LocElem { // LOCATION TABLE
- Aaddr nams; // Address of name printing code
- Aaddr dscr; // Address of description code
- Aaddr does; // Address of does code
- Aword describe; // Description flag & counter
- Aaddr atrs; // Address of attribute list
- Aaddr exts; // Address of exit list
- Aaddr vrbs; // Address of local verb list
-};
-
-struct ExtElem { // EXIT TABLE structure
- Abool done; // Flag for reverse/convert process
- Aword code; // Direction code
- Aaddr checks; // Address of check table
- Aaddr action; // Address of action code
- Aword next; // Number of next location
-};
-
-struct ChkElem { // CHECK TABLE
- Aaddr exp; // ACODE address to expression code
- Aaddr stms; // ACODE address to statement code
-};
-
-struct VrbElem { // VERB TABLE
- Aword code; // Code for the verb
- Aaddr alts; // Address to alternatives
-};
-
-struct StxElem { // SYNTAX TABLE
- Aword code; // Code for verb word
- Aaddr elms; // Address to element tables
-};
-
-struct ElmElem26 { // ELEMENT TABLES
- Aword code; // Code for this element, 0 -> parameter
- Abool multiple; // May be multiple (if parameter)
- Aaddr next; // Address to next element table ...
- // ... or class check if EOS
-};
-
-struct ElmElem { // ELEMENT TABLES
- Aword code; // Code for this element, 0 -> parameter
- Aword flags; // Flags for multiple/omni (if parameter)
- // CHANGED: v2.7 from Abool for multiple
- Aaddr next; // Address to next element table ...
- // ... or class check if EOS
-};
-
-struct ClaElem { // CLASS DEFINITION TABLE
- Aword code; // Parameter number
- Aword classes; // Parameter classes
- Aaddr stms; // Exception statements
-};
-
-struct AltElem { // VERB ALTERNATIVE TABLE
- Abool done; // Flag for patching (reverse/convert) process
- Aword param; // Parameter number
- Aword qual; // Verb execution qualifier
- Aaddr checks; // Address of the check table
- Aaddr action; // Address of the action code
-};
-
-struct AtrElem { // ATTRIBUTE LIST
- Aword val; // Its value
- Aaddr stradr; // Address to the name
-};
-
-struct ObjElem25 { // OBJECT TABLE of 2.5 format
- Aword loc; // Current location
- Abool describe; // Describe flag
- Aaddr atrs; // Address of attribute list
- Aword cont; // Index to container properties if any
- Aaddr vrbs; // Address to local verb table
- Aaddr dscr1; // Address to Aword description code
- Aaddr dscr2; // Address to short description code
-};
-
-struct ObjElem { // OBJECT TABLE
- Aword loc; // Current location
- Abool describe; // Describe flag
- Aaddr atrs; // Address of attribute list
- Aword cont; // Index to container properties if any
- Aaddr vrbs; // Address to local verb table
- Aaddr dscr1; // Address to Aword description code
- Aaddr art; // Article printing code? Else use default
- // INTRODUCED: v2.6
- Aaddr dscr2; // Address to short description code
-};
-
-struct CntElem { // CONTAINER TABLE
- Aaddr lims; // Address to limit check code
- Aaddr header; // Address to header code
- Aaddr empty; // Address to empty code
- Aword parent; // Object or actor index
- Aaddr nam; // Address to statement printing name
-};
-
-struct LimElem { // LIMIT Type
- Aword atr; // Attribute that limits
- Aword val; // And the limiting value
- Aaddr stms; // Statements if fail
-};
-
-struct RulElem { // RULE TABLE
- Abool run; // Is rule already run?
- Aaddr exp; // Address to expression code
- Aaddr stms; // Address to run
-};
-
-struct EvtElem { // EVENT TABLE
- Aaddr stradr; // Address to name string
- Aaddr code; // Address of code to run
-};
-
-struct EvtqElem { // EVENT QUEUE ELEMENT
- int time;
- int event;
- int where;
-};
-
-struct IniElem { // STRING INITIALISATION TABLE
- Aword fpos; // File position
- Aword len; // Length
- Aword adr; // Where to store the string
-};
-
-struct MsgElem26 { // MESSAGE TABLE
- Aword fpos; // File position
- Aword len; // Length of message
-};
-
-struct MsgElem { // MESSAGE TABLE
- Aaddr stms; // Address to statements
- // Changed v2.7 from fpos+len in .dat
-};
-
-struct ParamElem { // PARAMETER
- Aword code; // Code for this parameter (0=multiple)
- Aword firstWord; // Index to first word used by player
- Aword lastWord; // d:o to last
-};
-
-enum Type {
- TYPNUM,
- TYPSTR
-};
-
-struct LitElem { // LITERAL
- Type type;
- Aptr value;
-};
+/* TYPES */
+
+#ifndef __mac__
+typedef int Boolean; /* Boolean values within interpreter */
+#endif
+
+/* Amachine variables */
+typedef struct CurVars {
+ int
+ vrb,
+ obj,
+ loc,
+ act,
+ tick,
+ score,
+ visits;
+} CurVars;
+
+/* The various tables */
+typedef struct WrdElem { /* Dictionary */
+ Aaddr wrd; /* ACODE address to string */
+ Aword _class; /* Word class */
+ Aword code;
+ Aaddr adjrefs; /* Address to reference list */
+ Aaddr nounrefs; /* Address to reference list */
+} WrdElem;
+
+typedef struct ActElem { /* ACTOR TABLE */
+ Aword loc; /* Location */
+ Abool describe; /* Description flag */
+ Aaddr nam; /* Address to name printing code */
+ Aaddr atrs; /* Address to attribute list */
+ Aword cont; /* Code for the container props if any */
+ Aword script; /* Which script is he using */
+ Aaddr scradr; /* Address to script table */
+ Aword step;
+ Aword count;
+ Aaddr vrbs;
+ Aaddr dscr; /* Address of description code */
+} ActElem;
+
+typedef struct ScrElem { /* SCRIPT TABLE */
+ Aword code; /* Script number */
+ Aaddr dscr; /* Optional description statements */
+ Aaddr steps; /* Address to steps */
+} ScrElem;
+
+typedef struct StepElem { /* STEP TABLE */
+ Aword after; /* After how many ticks? */
+ Aaddr exp; /* Address to expression saying when */
+ Aaddr stm; /* Address to the actual code */
+} StepElem;
+
+typedef struct LocElem { /* LOCATION TABLE */
+ Aaddr nams; /* Address of name printing code */
+ Aaddr dscr; /* Address of description code */
+ Aaddr does; /* Address of does code */
+ Aword describe; /* Description flag & counter */
+ Aaddr atrs; /* Address of attribute list */
+ Aaddr exts; /* Address of exit list */
+ Aaddr vrbs; /* Address of local verb list */
+} LocElem;
+
+typedef struct ExtElem { /* EXIT TABLE structure */
+ Abool done; /* Flag for reverse/convert process */
+ Aword code; /* Direction code */
+ Aaddr checks; /* Address of check table */
+ Aaddr action; /* Address of action code */
+ Aword next; /* Number of next location */
+} ExtElem;
+
+typedef struct ChkElem { /* CHECK TABLE */
+ Aaddr exp; /* ACODE address to expression code */
+ Aaddr stms; /* ACODE address to statement code */
+} ChkElem;
+
+typedef struct VrbElem { /* VERB TABLE */
+ Aword code; /* Code for the verb */
+ Aaddr alts; /* Address to alternatives */
+} VrbElem;
+
+typedef struct StxElem { /* SYNTAX TABLE */
+ Aword code; /* Code for verb word */
+ Aaddr elms; /* Address to element tables */
+} StxElem;
+
+typedef struct ElmElem26 { /* ELEMENT TABLES */
+ Aword code; /* Code for this element, 0 -> parameter */
+ Abool multiple; /* May be multiple (if parameter) */
+ Aaddr next; /* Address to next element table ... */
+ /* ... or class check if EOS */
+} ElmElem26;
+
+typedef struct ElmElem { /* ELEMENT TABLES */
+ Aword code; /* Code for this element, 0 -> parameter */
+ Aword flags; /* Flags for multiple/omni (if parameter) */
+ /* CHANGED: v2.7 from Abool for multiple */
+ Aaddr next; /* Address to next element table ... */
+ /* ... or class check if EOS */
+} ElmElem;
+
+typedef struct ClaElem { /* CLASS DEFINITION TABLE */
+ Aword code; /* Parameter number */
+ Aword classes; /* Parameter classes */
+ Aaddr stms; /* Exception statements */
+} ClaElem;
+
+typedef struct AltElem { /* VERB ALTERNATIVE TABLE */
+ Abool done; /* Flag for patching (reverse/convert) process */
+ Aword param; /* Parameter number */
+ Aword qual; /* Verb execution qualifier */
+ Aaddr checks; /* Address of the check table */
+ Aaddr action; /* Address of the action code */
+} AltElem;
+
+typedef struct AtrElem { /* ATTRIBUTE LIST */
+ Aword val; /* Its value */
+ Aaddr stradr; /* Address to the name */
+} AtrElem;
+
+typedef struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
+ Aword loc; /* Current location */
+ Abool describe; /* Describe flag */
+ Aaddr atrs; /* Address of attribute list */
+ Aword cont; /* Index to container properties if any */
+ Aaddr vrbs; /* Address to local verb table */
+ Aaddr dscr1; /* Address to Aword description code */
+ Aaddr dscr2; /* Address to short description code */
+} ObjElem25;
+
+typedef struct ObjElem { /* OBJECT TABLE */
+ Aword loc; /* Current location */
+ Abool describe; /* Describe flag */
+ Aaddr atrs; /* Address of attribute list */
+ Aword cont; /* Index to container properties if any */
+ Aaddr vrbs; /* Address to local verb table */
+ Aaddr dscr1; /* Address to Aword description code */
+ Aaddr art; /* Article printing code? Else use default */
+ /* INTRODUCED: v2.6 */
+ Aaddr dscr2; /* Address to short description code */
+} ObjElem;
+
+typedef struct CntElem { /* CONTAINER TABLE */
+ Aaddr lims; /* Address to limit check code */
+ Aaddr header; /* Address to header code */
+ Aaddr empty; /* Address to empty code */
+ Aword parent; /* Object or actor index */
+ Aaddr nam; /* Address to statement printing name */
+} CntElem;
+
+typedef struct LimElem { /* LIMIT Type */
+ Aword atr; /* Attribute that limits */
+ Aword val; /* And the limiting value */
+ Aaddr stms; /* Statements if fail */
+} LimElem;
+
+typedef struct RulElem { /* RULE TABLE */
+ Abool run; /* Is rule already run? */
+ Aaddr exp; /* Address to expression code */
+ Aaddr stms; /* Address to run */
+} RulElem;
+
+typedef struct EvtElem { /* EVENT TABLE */
+ Aaddr stradr; /* Address to name string */
+ Aaddr code; /* Address of code to run */
+} EvtElem;
+
+typedef struct EvtqElem { /* EVENT QUEUE ELEMENT */
+ int time;
+ int event;
+ int where;
+} EvtqElem;
+
+typedef struct IniElem { /* STRING INITIALISATION TABLE */
+ Aword fpos; /* File position */
+ Aword len; /* Length */
+ Aword adr; /* Where to store the string */
+} IniElem;
+
+typedef struct MsgElem26 { /* MESSAGE TABLE */
+ Aword fpos; /* File position */
+ Aword len; /* Length of message */
+} MsgElem26;
+
+typedef struct MsgElem { /* MESSAGE TABLE */
+ Aaddr stms; /* Address to statements*/
+ /* Changed v2.7 from fpos+len in .dat */
+} MsgElem;
+
+
+typedef struct ParamElem { /* PARAMETER */
+ Aword code; /* Code for this parameter (0=multiple) */
+ Aword firstWord; /* Index to first word used by player */
+ Aword lastWord; /* d:o to last */
+} ParamElem;
+
+typedef enum Type {TYPNUM, TYPSTR} Type;
+
+typedef struct LitElem { /* LITERAL */
+ Type type;
+ Aptr value;
+} LitElem;
#define MAXPARAMS 9
-#define MAXENTITY (_vm->header->actmax)
+#define MAXENTITY (header->actmax)
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/util.h b/engines/glk/alan2/util.h
index 5ea1410..21993eb 100644
--- a/engines/glk/alan2/util.h
+++ b/engines/glk/alan2/util.h
@@ -23,65 +23,11 @@
#ifndef GLK_ALAN2_UTIL
#define GLK_ALAN2_UTIL
-#include "glk/alan2/acode.h"
-#include "glk/alan2/alan2.h"
#include "glk/alan2/types.h"
namespace Glk {
namespace Alan2 {
-// TODO: Move these
-extern LitElem *litValues;
-extern uint32 litCount; // for LITMAX - defined in parse.cpp
-extern ActElem *acts; // Actor table pointer
-extern ObjElem *objs; // Object table pointer
-
-// Type checks
-inline bool isObj(Aword x) {
- return x >= OBJMIN && x <= OBJMAX;
-}
-
-inline bool isAct(Aword x) {
- return x >= ACTMIN && x <= ACTMAX;
-}
-
-inline bool isCnt(Aword x) {
- return (x >= CNTMIN && x <= CNTMAX) ||
- (isObj(x) && objs[x - OBJMIN].cont != 0) ||
- (isAct(x) && acts[x - ACTMIN].cont != 0);
-}
-
-inline bool isLoc(Aword x) {
- return x >= LOCMIN && x <= LOCMAX;
-}
-
-inline bool isNum(Aword x) {
- return x >= LITMIN && x <= LITMAX && litValues[x - LITMIN].type == TYPNUM;
-}
-
-inline bool isStr(Aword x) {
- return x >= LITMIN && x <= LITMAX && litValues[x - LITMIN].type == TYPSTR;
-}
-
-inline bool isLit(Aword x) {
- return x >= LITMIN && x <= LITMAX;
-}
-
-inline bool endOfTable(LimElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-inline bool endOfTable(ScrElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
-inline bool endOfTable(ExtElem *addr) {
- Aword *x = (Aword *)addr;
- return *x == (Aword)EOF;
-}
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/version.h b/engines/glk/alan2/version.h
new file mode 100644
index 0000000..3bb90ad
--- /dev/null
+++ b/engines/glk/alan2/version.h
@@ -0,0 +1,59 @@
+/* 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 GLK_ALAN2_VERSION
+#define GLK_ALAN2_VERSION
+
+#include "common/system.h"
+
+namespace Glk {
+namespace Alan2 {
+
+typedef int64 Time;
+
+struct Version {
+ char* string;
+ int version;
+ int revision;
+ int correction;
+ Time time;
+ char *state;
+};
+
+struct Product {
+ char* name;
+ char* slogan;
+ char* shortHeader;
+ char* longHeader;
+ char* date;
+ char* time;
+ char* user;
+ char* host;
+ char* ostype;
+ Version version;
+};
+
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index bfda72d..b87fea9 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -33,6 +33,22 @@ MODULE_OBJS := \
advsys/vm.o \
alan2/alan2.o \
alan2/detection.o \
+ alan2/alan_version.o \
+ alan2/args.o \
+ alan2/debug.o \
+ alan2/decode.o \
+ alan2/exe.o \
+ alan2/glkio.o \
+ alan2/glkstart.o \
+ alan2/inter.o \
+ alan2/params.o \
+ alan2/parse.o \
+ alan2/readline.o \
+ alan2/reverse.o \
+ alan2/rules.o \
+ alan2/stack.o \
+ alan2/sysdep.o \
+ alan2/term.o \
frotz/bitmap_font.o \
frotz/config.o \
frotz/detection.o \
Commit: ed21388e11a928fc965714a035d2c18887ec7f62
https://github.com/scummvm/scummvm/commit/ed21388e11a928fc965714a035d2c18887ec7f62
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Added missing main code file, hooked up to Alan2 engine skeleton
Changed paths:
A engines/glk/alan2/acode.cpp
A engines/glk/alan2/main.cpp
engines/glk/alan2/acode.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/args.cpp
engines/glk/alan2/glkio.cpp
engines/glk/alan2/glkio.h
engines/glk/alan2/main.h
engines/glk/alan2/sysdep.cpp
engines/glk/alan2/sysdep.h
engines/glk/module.mk
diff --git a/engines/glk/alan2/acode.cpp b/engines/glk/alan2/acode.cpp
new file mode 100644
index 0000000..b842c81
--- /dev/null
+++ b/engines/glk/alan2/acode.cpp
@@ -0,0 +1,81 @@
+/* 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/alan2/acode.h"
+
+namespace Glk {
+namespace Alan2 {
+
+AcdHdr::AcdHdr() : size(0), pack(0), paglen(0), pagwidth(0), debug(0), dict(0), oatrs(0),
+ latrs(0), aatrs(0), acts(0), objs(0), locs(0), stxs(0), vrbs(0), evts(0),
+ cnts(0), ruls(0), init(0), start(0), msgs(0), objmin(0), objmax(0), actmin(0),
+ actmax(0), cntmin(0), cntmax(0), locmin(0), locmax(0), dirmin(0), dirmax(0),
+ evtmin(0), evtmax(0), rulmin(0), rulmax(0), maxscore(0), scores(0),
+ freq(0), acdcrc(0), txtcrc(0) {
+ vers[0] = vers[1] = vers[2] = vers[3] = 0;
+}
+
+void AcdHdr::load(Common::SeekableReadStream &s) {
+ s.read(vers, 4);
+ size = s.readUint32LE();
+ pack = s.readUint32LE();
+ paglen = s.readUint32LE();
+ pagwidth = s.readUint32LE();
+ debug = s.readUint32LE();
+ dict = s.readUint32LE();
+ oatrs = s.readUint32LE();
+ latrs = s.readUint32LE();
+ aatrs = s.readUint32LE();
+ acts = s.readUint32LE();
+ objs = s.readUint32LE();
+ locs = s.readUint32LE();
+ stxs = s.readUint32LE();
+ vrbs = s.readUint32LE();
+ evts = s.readUint32LE();
+ cnts = s.readUint32LE();
+ ruls = s.readUint32LE();
+ init = s.readUint32LE();
+ start = s.readUint32LE();
+ msgs = s.readUint32LE();
+ objmin = s.readUint32LE();
+ objmax = s.readUint32LE();
+ actmin = s.readUint32LE();
+ actmax = s.readUint32LE();
+ cntmin = s.readUint32LE();
+ cntmax = s.readUint32LE();
+ locmin = s.readUint32LE();
+ locmax = s.readUint32LE();
+ dirmin = s.readUint32LE();
+ dirmax = s.readUint32LE();
+ evtmin = s.readUint32LE();
+ evtmax = s.readUint32LE();
+ rulmin = s.readUint32LE();
+ rulmax = s.readUint32LE();
+ maxscore = s.readUint32LE();
+ scores = s.readUint32LE();
+ freq = s.readUint32LE();
+ acdcrc = s.readUint32LE();
+ txtcrc = s.readUint32LE();
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index 5fee277..fff5144 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -23,15 +23,17 @@
#ifndef GLK_ALAN2_ACODE
#define GLK_ALAN2_ACODE
+#include "common/stream.h"
+
namespace Glk {
namespace Alan2 {
typedef size_t Aptr; /* Type for an ACODE memory address */
-typedef unsigned int Aword; /* Type for an ACODE word */
-typedef unsigned int Aaddr; /* Type for an ACODE address */
-typedef unsigned int Abool; /* Type for an ACODE Boolean value */
-typedef signed int Aint; /* Type for an ACODE Integer value */
+typedef uint32 Aword; /* Type for an ACODE word */
+typedef uint32 Aaddr; /* Type for an ACODE address */
+typedef uint32 Abool; /* Type for an ACODE Boolean value */
+typedef int32 Aint; /* Type for an ACODE Integer value */
typedef int CodeValue; /* Definition for the packing process */
#ifdef UNUSED
@@ -208,45 +210,55 @@ typedef enum VarClass {
#define I_OP(x) ((x&0x8000000)?(x)|0x0f0000000:(x)&0x0fffffff)
-typedef struct AcdHdr {
-/* Important info */
- char vers[4]; /* 01 - Version of compiler */
- Aword size; /* 02 - Size of ACD-file in Awords */
-/* Options */
- Abool pack; /* 03 - Is the text packed ? */
- Aword paglen; /* 04 - Length of a page */
- Aword pagwidth; /* 05 - and width */
- Aword debug; /* 06 - Option debug */
-/* Data structures */
- Aaddr dict; /* 07 - Dictionary */
- Aaddr oatrs; /* 08 - Object default attributes */
- Aaddr latrs; /* 09 - Location default attributes */
- Aaddr aatrs; /* 0a - Actor default attributes */
- Aaddr acts; /* 0b - Actor table */
- Aaddr objs; /* 0c - Object table */
- Aaddr locs; /* 0d - Location table */
- Aaddr stxs; /* 0e - Syntax table */
- Aaddr vrbs; /* 0f - Verb table */
- Aaddr evts; /* 10 - Event table */
- Aaddr cnts; /* 11 - Container table */
- Aaddr ruls; /* 12 - Rule table */
- Aaddr init; /* 13 - String init table */
- Aaddr start; /* 14 - Start code */
- Aword msgs; /* 15 - Messages table */
-/* Miscellaneous */
- Aword objmin, objmax; /* 16 - Interval for object codes */
- Aword actmin, actmax; /* 18 - Interval for actor codes */
- Aword cntmin, cntmax; /* 1a - Interval for container codes */
- Aword locmin, locmax; /* 1c - Interval for location codes */
- Aword dirmin, dirmax; /* 1e - Interval for direction codes */
- Aword evtmin, evtmax; /* 20 - Interval for event codes */
- Aword rulmin, rulmax; /* 22 - Interval for rule codes */
- Aword maxscore; /* 24 - Maximum score */
- Aaddr scores; /* 25 - Score table */
- Aaddr freq; /* 26 - Address to Char freq's for coding */
- Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
- Aword txtcrc; /* 28 - Checksum for text data file */
-} AcdHdr;
+struct AcdHdr {
+ /* Important info */
+ char vers[4]; /* 01 - Version of compiler */
+ Aword size; /* 02 - Size of ACD-file in Awords */
+ /* Options */
+ Abool pack; /* 03 - Is the text packed ? */
+ Aword paglen; /* 04 - Length of a page */
+ Aword pagwidth; /* 05 - and width */
+ Aword debug; /* 06 - Option debug */
+ /* Data structures */
+ Aaddr dict; /* 07 - Dictionary */
+ Aaddr oatrs; /* 08 - Object default attributes */
+ Aaddr latrs; /* 09 - Location default attributes */
+ Aaddr aatrs; /* 0a - Actor default attributes */
+ Aaddr acts; /* 0b - Actor table */
+ Aaddr objs; /* 0c - Object table */
+ Aaddr locs; /* 0d - Location table */
+ Aaddr stxs; /* 0e - Syntax table */
+ Aaddr vrbs; /* 0f - Verb table */
+ Aaddr evts; /* 10 - Event table */
+ Aaddr cnts; /* 11 - Container table */
+ Aaddr ruls; /* 12 - Rule table */
+ Aaddr init; /* 13 - String init table */
+ Aaddr start; /* 14 - Start code */
+ Aword msgs; /* 15 - Messages table */
+ /* Miscellaneous */
+ Aword objmin, objmax; /* 16 - Interval for object codes */
+ Aword actmin, actmax; /* 18 - Interval for actor codes */
+ Aword cntmin, cntmax; /* 1a - Interval for container codes */
+ Aword locmin, locmax; /* 1c - Interval for location codes */
+ Aword dirmin, dirmax; /* 1e - Interval for direction codes */
+ Aword evtmin, evtmax; /* 20 - Interval for event codes */
+ Aword rulmin, rulmax; /* 22 - Interval for rule codes */
+ Aword maxscore; /* 24 - Maximum score */
+ Aaddr scores; /* 25 - Score table */
+ Aaddr freq; /* 26 - Address to Char freq's for coding */
+ Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
+ Aword txtcrc; /* 28 - Checksum for text data file */
+
+ /**
+ * Constructor
+ */
+ AcdHdr();
+
+ /**
+ * Loads the header from the passed stream
+ */
+ void load(Common::SeekableReadStream &s);
+};
/* Error message numbers */
typedef enum MsgKind {
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 1889c69..fec1c62 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -21,6 +21,7 @@
*/
#include "glk/alan2/alan2.h"
+#include "glk/alan2/main.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
@@ -45,7 +46,16 @@ void Alan2::runGame() {
if (!is_gamefile_valid())
return;
- // TODO
+ Common::String filename = getFilename();
+ while (filename.contains('.'))
+ filename.deleteLastChar();
+ advnam = filename.c_str();
+
+ codfil = &_gameFile;
+ strncpy(codfnm, getFilename().c_str(), 255);
+ codfnm[255] = '\0';
+
+ run();
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp
index aceb00b..1946239 100644
--- a/engines/glk/alan2/args.cpp
+++ b/engines/glk/alan2/args.cpp
@@ -65,6 +65,7 @@ static void switches(argc, argv)
char *argv[];
#endif
{
+#ifndef GLK
uint i;
advnam = "";
@@ -111,6 +112,7 @@ static void switches(argc, argv)
advnam[strlen(advnam)-4] = '\0';
}
}
+#endif
}
diff --git a/engines/glk/alan2/glkio.cpp b/engines/glk/alan2/glkio.cpp
index 3464131..47dbbf2 100644
--- a/engines/glk/alan2/glkio.cpp
+++ b/engines/glk/alan2/glkio.cpp
@@ -27,6 +27,9 @@
namespace Glk {
namespace Alan2 {
+winid_t glkMainWin;
+winid_t glkStatusWin;
+
void glkio_printf(char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
diff --git a/engines/glk/alan2/glkio.h b/engines/glk/alan2/glkio.h
index 7dca2ca..151bb7a 100644
--- a/engines/glk/alan2/glkio.h
+++ b/engines/glk/alan2/glkio.h
@@ -31,8 +31,8 @@
namespace Glk {
namespace Alan2 {
-winid_t glkMainWin;
-winid_t glkStatusWin;
+extern winid_t glkMainWin;
+extern winid_t glkStatusWin;
/* NB: this header must be included in any file which calls print() */
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
new file mode 100644
index 0000000..d2e8323
--- /dev/null
+++ b/engines/glk/alan2/main.cpp
@@ -0,0 +1,1926 @@
+/* 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.
+ *
+ */
+
+#define V27COMPATIBLE
+
+#include "glk/alan2/sysdep.h"
+
+#include "glk/alan2/types.h"
+#include "glk/alan2/main.h"
+
+//#include <time.h>
+#ifdef USE_READLINE
+#include "glk/alan2/readline.h"
+#endif
+
+#ifdef HAVE_SHORT_FILENAMES
+#include "glk/alan2/av.h"
+#else
+#include "glk/alan2/alan_version.h"
+#endif
+
+#include "glk/alan2/args.h"
+#include "glk/alan2/parse.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/rules.h"
+#ifdef REVERSED
+#include "glk/alan2/reverse.h"
+#endif
+#include "glk/alan2/debug.h"
+#include "glk/alan2/stack.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/term.h"
+
+#ifdef GLK
+#include "common/file.h"
+#include "glk/alan2/alan2.h"
+#include "glk/alan2/glkio.h"
+#endif
+
+namespace Glk {
+namespace Alan2 {
+
+/* PUBLIC DATA */
+
+/* The Amachine memory */
+Aword *memory;
+//static AcdHdr dummyHeader; /* Dummy to use until memory allocated */
+AcdHdr *header;
+
+int memTop = 0; /* Top of load memory */
+
+int conjWord; /* First conjunction in dictonary, for ',' */
+
+
+/* Amachine variables */
+CurVars cur;
+
+/* Amachine structures */
+WrdElem *dict; /* Dictionary pointer */
+ActElem *acts; /* Actor table pointer */
+LocElem *locs; /* Location table pointer */
+VrbElem *vrbs; /* Verb table pointer */
+StxElem *stxs; /* Syntax table pointer */
+ObjElem *objs; /* Object table pointer */
+CntElem *cnts; /* Container table pointer */
+RulElem *ruls; /* Rule table pointer */
+EvtElem *evts; /* Event table pointer */
+MsgElem *msgs; /* Message table pointer */
+Aword *scores; /* Score table pointer */
+Aword *freq; /* Cumulative character frequencies */
+
+int dictsize;
+
+Boolean verbose = FALSE;
+Boolean errflg = TRUE;
+Boolean trcflg = FALSE;
+Boolean dbgflg = FALSE;
+Boolean stpflg = FALSE;
+Boolean logflg = FALSE;
+Boolean statusflg = TRUE;
+Boolean fail = FALSE;
+Boolean anyOutput = FALSE;
+
+
+/* The files and filenames */
+const char *advnam;
+Common::File *txtfil;
+Common::WriteStream *logfil;
+
+
+/* Screen formatting info */
+int col, lin;
+int paglen, pagwidth;
+
+Boolean needsp = FALSE;
+Boolean skipsp = FALSE;
+
+/* Restart jump buffer */
+//jmp_buf restart_label;
+
+
+/* PRIVATE DATA */
+//static jmp_buf jmpbuf; /* Error return long jump buffer */
+
+
+
+/*======================================================================
+
+ terminate()
+
+ Terminate the execution of the adventure, e.g. close windows,
+ return buffers...
+
+ */
+#ifdef _PROTOTYPES_
+void terminate(int code)
+#else
+void terminate(code)
+ int code;
+#endif
+{
+#ifdef __amiga__
+#ifdef AZTEC_C
+#include <fcntl.h>
+ extern struct _dev *_devtab;
+ char buf[85];
+
+ if (con) { /* Running from WB, created a console so kill it */
+ /* Running from WB, so we created a console and
+ hacked the Aztec C device table to use it for all I/O
+ so now we need to make it close it (once!) */
+ _devtab[1].fd = _devtab[2].fd = 0;
+ } else
+#else
+ /* Geek Gadgets GCC */
+#include <workbench/startup.h>
+#include <clib/dos_protos.h>
+#include <clib/intuition_protos.h>
+
+ if (_WBenchMsg != NULL) {
+ Close(window);
+ if (_WBenchMsg->sm_ArgList != NULL)
+ UnLock(CurrentDir(cd));
+ } else
+#endif
+#endif
+ newline();
+ free(memory);
+ if (logflg)
+ fclose(logfil);
+
+#ifdef __MWERKS__
+ printf("Command-Q to close window.");
+#endif
+
+#ifdef GLK
+ g_vm->glk_exit();
+#else
+ exit(code);
+#endif
+}
+
+/*======================================================================
+
+ usage()
+
+ */
+#ifdef _PROTOTYPES_
+void usage(void)
+#else
+void usage()
+#endif
+{
+ printf("Usage:\n\n");
+ printf(" %s [<switches>] <adventure>\n\n", PROGNAME);
+ printf("where the possible optional switches are:\n");
+#ifdef GLK
+ g_vm->glk_set_style(style_Preformatted);
+#endif
+ printf(" -v verbose mode\n");
+ printf(" -l log player commands and game output to a file\n");
+ printf(" -i ignore version and checksum errors\n");
+ printf(" -n no Status Line\n");
+ printf(" -d enter debug mode\n");
+ printf(" -t trace game execution\n");
+ printf(" -s single instruction trace\n");
+#ifdef GLK
+ g_vm->glk_set_style(style_Normal);
+#endif
+}
+
+
+/*======================================================================
+
+ syserr()
+
+ Print a little text blaming the user for the system error.
+
+ */
+#ifdef _PROTOTYPES_
+void syserr(char *str)
+#else
+void syserr(str)
+ char *str;
+#endif
+{
+ 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$nSYSTEM ERROR: ");
+ output(str);
+ output("$n$n");
+
+ if (logflg)
+ fclose(logfil);
+ newline();
+
+#ifdef __amiga__
+#ifdef AZTEC_C
+ {
+ char buf[80];
+
+ if (con) { /* Running from WB, wait for user ack. */
+ printf("press RETURN to quit");
+ gets(buf);
+ }
+ }
+#endif
+#endif
+
+ terminate(0);
+}
+
+
+/*======================================================================
+
+ error()
+
+ Print an error message, force new player input and abort.
+
+ */
+#ifdef _PROTOTYPES_
+void error(MsgKind msgno) /* IN - The error message number */
+#else
+void error(msgno)
+ MsgKind msgno; /* IN - The error message number */
+#endif
+{
+ if (msgno != MSGMAX)
+ prmsg(msgno);
+ wrds[wrdidx] = EOF; /* Force new player input */
+ dscrstkp = 0; /* Reset describe stack */
+
+ //longjmp(jmpbuf,TRUE);
+ ::error("Error occurred");
+}
+
+
+/*======================================================================
+
+ statusline()
+
+ Print the the status line on the top of the screen.
+
+ */
+void statusline(void)
+{
+#ifdef GLK
+ uint glkWidth;
+ char line[100];
+ int pcol = col;
+ uint i;
+
+ if (NULL == glkStatusWin)
+ return;
+
+ g_vm->glk_set_window(glkStatusWin);
+ g_vm->glk_window_clear(glkStatusWin);
+ g_vm->glk_window_get_size(glkStatusWin, &glkWidth, NULL);
+
+ g_vm->glk_set_style(style_User1);
+ for (i = 0; i < glkWidth; i++)
+ g_vm->glk_put_char(' ');
+
+ col = 1;
+ g_vm->glk_window_move_cursor(glkStatusWin, 1, 0);
+needsp = FALSE;
+ say(where(HERO));
+ if (header->maxscore > 0)
+ sprintf(line, "Score %d(%d)/%d moves", cur.score, (int)header->maxscore, cur.tick);
+ else
+ sprintf(line, "%d moves", cur.tick);
+ g_vm->glk_window_move_cursor(glkStatusWin, glkWidth - col - strlen(line), 0);
+ printf(line);
+ needsp = FALSE;
+
+ col = pcol;
+
+ g_vm->glk_set_window(glkMainWin);
+#else
+#ifdef HAVE_ANSI
+ char line[100];
+ int i;
+ int pcol = col;
+
+ if (!statusflg) return;
+ /* ansi_position(1,1); ansi_bold_on(); */
+ printf("\x1b[1;1H");
+ printf("\x1b[7m");
+ col = 1;
+ say(where(HERO));
+ if (header->maxscore > 0)
+ sprintf(line, "Score %ld(%ld)/%ld moves", cur.score, (int)header->maxscore, cur.tick);
+ else
+ sprintf(line, "%ld moves", cur.tick);
+ for (i=0; i < pagwidth - col - strlen(line); i++) putchar(' ');
+ printf(line);
+ printf("\x1b[m");
+ printf("\x1b[%d;1H", paglen);
+ needsp = FALSE;
+
+ col = pcol;
+#endif
+#endif
+}
+
+
+/*======================================================================
+
+ logprint()
+
+ Print some text and log it if logging is on.
+
+ */
+void logprint(char str[])
+{
+ printf(str);
+ if (logflg)
+ fprintf(logfil, "%s", str);
+}
+
+
+
+/*======================================================================
+
+ newline()
+
+ Make a newline, but check for screen full.
+
+ */
+#ifdef _PROTOTYPES_
+void newline(void)
+#else
+void newline()
+#endif
+{
+#ifdef GLK
+ g_vm->glk_put_char('\n');
+#else
+ char buf[256];
+
+ col = 1;
+ if (lin >= paglen - 1) {
+ logprint("\n");
+ needsp = FALSE;
+ prmsg(M_MORE);
+#ifdef USE_READLINE
+ (void) readline(buf);
+#else
+ fgets(buf, 256, stdin);
+#endif
+ getPageSize();
+ lin = 0;
+ } else
+ logprint("\n");
+
+ lin++;
+ needsp = FALSE;
+#endif
+}
+
+
+/*======================================================================
+
+ para()
+
+ Make a new paragraph, i.e one empty line (one or two newlines).
+
+ */
+#ifdef _PROTOTYPES_
+void para(void)
+#else
+void para()
+#endif
+{
+ if (col != 1)
+ newline();
+ newline();
+}
+
+
+/*======================================================================
+
+ clear()
+
+ Clear the screen.
+
+ */
+#ifdef _PROTOTYPES_
+void clear(void)
+#else
+void clear()
+#endif
+{
+#ifdef GLK
+ g_vm->glk_window_clear(glkMainWin);
+#else
+#ifdef HAVE_ANSI
+ if (!statusflg) return;
+ printf("\x1b[2J");
+ printf("\x1b[%d;1H", paglen);
+#endif
+#endif
+}
+
+
+/*======================================================================
+
+ allocate()
+
+ Safely allocate new memory.
+
+*/
+#ifdef _PROTOTYPES_
+void *allocate(unsigned long len) /* IN - Length to allocate */
+#else
+void *allocate(len)
+ unsigned long len; /* IN - Length to allocate */
+#endif
+{
+ void *p = (void *)malloc((size_t)len);
+
+ if (p == NULL)
+ syserr("Out of memory.");
+
+ return p;
+}
+
+
+/*----------------------------------------------------------------------
+
+ just()
+
+ Justify a string so that it wraps at end of screen.
+
+ */
+#ifdef _PROTOTYPES_
+static void just(char str[])
+#else
+static void just(str)
+ char str[];
+#endif
+{
+#ifdef GLK
+ logprint(str);
+#else
+ int i;
+ char ch;
+
+ if (col >= pagwidth && !skipsp)
+ newline();
+
+ while (strlen(str) > pagwidth - col) {
+ i = pagwidth - col - 1;
+ while (!isSpace(str[i]) && i > 0) /* First find wrap point */
+ i--;
+ if (i == 0 && col == 1) /* If it doesn't fit at all */
+ /* Wrap immediately after this word */
+ while (!isSpace(str[i]) && str[i] != '\0')
+ i++;
+ if (i > 0) { /* If it fits ... */
+ ch = str[i]; /* Save space or NULL */
+ str[i] = '\0'; /* Terminate string */
+ logprint(str); /* and print it */
+ skipsp = FALSE; /* If skipping, now we're done */
+ str[i] = ch; /* Restore character */
+ /* Skip white after printed portion */
+ for (str = &str[i]; isSpace(str[0]) && str[0] != '\0'; str++);
+ }
+ newline(); /* Then start a new line */
+ }
+ logprint(str); /* Print tail */
+ col = col + strlen(str); /* Update column */
+#endif
+}
+
+
+/*----------------------------------------------------------------------
+
+ space()
+
+ Output a space if needed.
+
+ */
+#ifdef _PROTOTYPES_
+static void space(void)
+#else
+static void space()
+#endif
+{
+ if (skipsp)
+ skipsp = FALSE;
+ else {
+ if (needsp) {
+ logprint(" ");
+ col++;
+ }
+ }
+ needsp = FALSE;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ sayparam()
+
+ A parameter needs to be said, check for words the player used and use
+ them if possible.
+
+*/
+#ifdef _PROTOTYPES_
+static void sayparam(int p)
+#else
+static void sayparam(p)
+ int p;
+#endif
+{
+ int i;
+
+ for (i = 0; i <= p; i++)
+ if (params[i].code == EOF)
+ syserr("Nonexistent parameter referenced.");
+
+ if (params[p].firstWord == EOF) /* Any words he used? */
+ say(params[p].code);
+ else /* Yes, so use them... */
+ for (i = params[p].firstWord; i <= params[p].lastWord; i++) {
+ just((char *)addrTo(dict[wrds[i]].wrd));
+ if (i < params[p].lastWord)
+ just(" ");
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ prsym()
+
+ Print an expanded symbolic reference.
+
+ N = newline
+ I = indent on a new line
+ P = new paragraph
+ L = current location name
+ O = current object -> first parameter!
+ V = current verb
+ A = current actor
+ T = tabulation
+ $ = no space needed after this
+ */
+#ifdef _PROTOTYPES_
+static void prsym(
+ char *str /* IN - The string starting with '$' */
+)
+#else
+static void prsym(str)
+ char *str; /* IN - The string starting with '$' */
+#endif
+{
+ switch (toLower(str[1])) {
+ case 'n':
+ newline();
+ needsp = FALSE;
+ break;
+ case 'i':
+ newline();
+ logprint(" ");
+ col = 5;
+ needsp = FALSE;
+ break;
+ case 'o':
+ sayparam(0);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ sayparam(str[1]-'1');
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'l':
+ say(cur.loc);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'a':
+ say(cur.act);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'v':
+ just((char *)addrTo(dict[vrbwrd].wrd));
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'p':
+ para();
+ needsp = FALSE;
+ break;
+ case 't': {
+ int i;
+ int spaces = 4-(col-1)%4;
+
+ for (i = 0; i<spaces; i++) logprint(" ");
+ col = col + spaces;
+ needsp = FALSE;
+ break;
+ }
+ case '$':
+ skipsp = TRUE;
+ break;
+ default:
+ logprint("$");
+ break;
+ }
+}
+
+
+
+/*======================================================================
+
+ output()
+
+ Output a string to suit the screen. Any symbolic inserts ('$') are
+ recogniced and performed.
+
+ */
+#ifdef _PROTOTYPES_
+void output(char original[])
+#else
+void output(original)
+ char original[];
+#endif
+{
+ char ch;
+ char *str, *copy;
+ char *symptr;
+
+ copy = strdup(original);
+ str = copy;
+
+ if (str[0] != '$' || str[1] != '$')
+ space(); /* Output space if needed (& not inhibited) */
+
+ while ((symptr = strchr(str, '$')) != (char *) NULL) {
+ ch = *symptr; /* Terminate before symbol */
+ *symptr = '\0';
+ if (strlen(str) > 0) {
+ just(str); /* Output part before '$' */
+ if (str[strlen(str)-1] == ' ')
+ needsp = FALSE;
+ }
+ *symptr = ch; /* restore '$' */
+ prsym(symptr); /* Print the symbolic reference */
+ str = &symptr[2]; /* Advance to after symbol and continue */
+ }
+ if (str[0] != 0) {
+ just(str); /* Output trailing part */
+ skipsp = FALSE;
+ if (str[strlen(str)-1] != ' ')
+ needsp = TRUE;
+ }
+ anyOutput = TRUE;
+ free(copy);
+}
+
+
+/*======================================================================
+
+ prmsg()
+
+ Print a message from the message table.
+
+ */
+#ifdef _PROTOTYPES_
+void prmsg(MsgKind msg) /* IN - message number */
+#else
+void prmsg(msg)
+ MsgKind msg; /* IN - message number */
+#endif
+{
+ interpret(msgs[msg].stms);
+}
+
+
+/*----------------------------------------------------------------------*\
+
+ Various check functions
+
+ endOfTable()
+ isObj, isLoc, isAct, IsCnt & isNum
+
+\*----------------------------------------------------------------------*/
+
+/* How to know we are at end of a table */
+#ifdef _PROTOTYPES_
+Boolean eot(Aword *adr)
+#else
+Boolean eot(adr)
+ Aword *adr;
+#endif
+{
+ return *adr == EOF;
+}
+
+
+#ifdef _PROTOTYPES_
+Boolean isObj(Aword x)
+#else
+Boolean isObj(x)
+ Aword x;
+#endif
+{
+ return x >= OBJMIN && x <= OBJMAX;
+}
+
+#ifdef _PROTOTYPES_
+Boolean isCnt(Aword x)
+#else
+Boolean isCnt(x)
+ Aword x;
+#endif
+{
+ return (x >= CNTMIN && x <= CNTMAX) ||
+ (isObj(x) && objs[x-OBJMIN].cont != 0) ||
+ (isAct(x) && acts[x-ACTMIN].cont != 0);
+}
+
+#ifdef _PROTOTYPES_
+Boolean isAct(Aword x)
+#else
+Boolean isAct(x)
+ Aword x;
+#endif
+{
+ return x >= ACTMIN && x <= ACTMAX;
+}
+
+#ifdef _PROTOTYPES_
+Boolean isLoc(Aword x)
+#else
+Boolean isLoc(x)
+ Aword x;
+#endif
+{
+ return x >= LOCMIN && x <= LOCMAX;
+}
+
+#ifdef _PROTOTYPES_
+Boolean isNum(Aword x)
+#else
+Boolean isNum(x)
+ Aword x;
+#endif
+{
+ return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPNUM;
+}
+
+#ifdef _PROTOTYPES_
+Boolean isStr(Aword x)
+#else
+Boolean isStr(x)
+ Aword x;
+#endif
+{
+ return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPSTR;
+}
+
+#ifdef _PROTOTYPES_
+Boolean isLit(Aword x)
+#else
+Boolean isLit(x)
+ Aword x;
+#endif
+{
+ return x >= LITMIN && x <= LITMAX;
+}
+
+
+
+/*======================================================================
+
+ exitto()
+
+ Is there an exit from one location to another?
+
+ */
+#ifdef _PROTOTYPES_
+Boolean exitto(int to, int from)
+#else
+Boolean exitto(to, from)
+ int to, from;
+#endif
+{
+ ExtElem *ext;
+
+ if (locs[from-LOCMIN].exts == 0)
+ return(FALSE); /* No exits */
+
+ for (ext = (ExtElem *) addrTo(locs[from-LOCMIN].exts); !endOfTable(ext); ext++)
+ if (ext->next == to)
+ return(TRUE);
+
+ return(FALSE);
+}
+
+
+
+#ifdef CHECKOBJ
+/*======================================================================
+
+ checkobj()
+
+ Check that the object given is valid, else print an error message
+ or find out what he wanted.
+
+ This routine is not used any longer, kept for sentimental reasons ;-)
+
+ */
+void checkobj(obj)
+ Aword *obj;
+{
+ Aword oldobj;
+
+ if (*obj != EOF)
+ return;
+
+ oldobj = EOF;
+ for (cur.obj = OBJMIN; cur.obj <= OBJMAX; cur.obj++) {
+ /* If an object is present and it is possible to perform his action */
+ if (isHere(cur.obj) && possible())
+ if (oldobj == EOF)
+ oldobj = cur.obj;
+ else
+ error(WANT); /* And we didn't find multiple objects */
+ }
+
+ if (oldobj == EOF)
+ error(WANT); /* But we found ONE */
+
+ *obj = cur.obj = oldobj;
+ output("($o)"); /* Then he surely meant this object */
+}
+#endif
+
+
+
+
+/*----------------------------------------------------------------------
+ count()
+
+ Count the number of items in a container.
+
+ */
+#ifdef _PROTOTYPES_
+static int count(int cnt) /* IN - the container to count */
+#else
+static int count(cnt)
+ int cnt; /* IN - the container to count */
+#endif
+{
+ int i, j = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (in(i, cnt))
+ /* Then it's in this container also */
+ j++;
+ return(j);
+}
+
+
+
+/*----------------------------------------------------------------------
+ sumatr()
+
+ Sum the values of one attribute in a container. Recursively.
+
+ */
+#ifdef _PROTOTYPES_
+static int sumatr(
+ Aword atr, /* IN - the attribute to sum over */
+ Aword cnt /* IN - the container to sum */
+)
+#else
+static int sumatr(atr, cnt)
+ Aword atr; /* IN - the attribute to sum over */
+ Aword cnt; /* IN - the container to sum */
+#endif
+{
+ int i;
+ int sum = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i-OBJMIN].loc == cnt) { /* Then it's in this container */
+ if (objs[i-OBJMIN].cont != 0) /* This is also a container! */
+ sum = sum + sumatr(atr, i);
+ sum = sum + attribute(i, atr);
+ }
+ return(sum);
+}
+
+
+
+
+/*======================================================================
+ checklim()
+
+ Checks if a limit for a container is exceeded.
+
+ */
+#ifdef _PROTOTYPES_
+Boolean checklim(
+ Aword cnt, /* IN - Container code */
+ Aword obj /* IN - The object to add */
+)
+#else
+Boolean checklim(cnt, obj)
+ Aword cnt; /* IN - Container code */
+ Aword obj; /* IN - The object to add */
+#endif
+{
+ LimElem *lim;
+ Aword props;
+
+ fail = TRUE;
+ if (!isCnt(cnt))
+ syserr("Checking limits for a non-container.");
+
+ /* Find the container properties */
+ if (isObj(cnt))
+ props = objs[cnt-OBJMIN].cont;
+ else if (isAct(cnt))
+ props = acts[cnt-ACTMIN].cont;
+ else
+ props = cnt;
+
+ if (cnts[props-CNTMIN].lims != 0) { /* Any limits at all? */
+ for (lim = (LimElem *) addrTo(cnts[props-CNTMIN].lims); !endOfTable(lim); lim++)
+ if (lim->atr == 0) {
+ if (count(cnt) >= lim->val) {
+ interpret(lim->stms);
+ return(TRUE); /* Limit check failed */
+ }
+ } else {
+ if (sumatr(lim->atr, cnt) + attribute(obj, lim->atr) > lim->val) {
+ interpret(lim->stms);
+ return(TRUE);
+ }
+ }
+ }
+ fail = FALSE;
+ return(FALSE);
+}
+
+
+
+
+
+/*----------------------------------------------------------------------*\
+
+ Action routines
+
+\*----------------------------------------------------------------------*/
+
+
+
+/*----------------------------------------------------------------------
+ trycheck()
+
+ Tries a check, returns TRUE if it passed, FALSE else.
+
+ */
+#ifdef _PROTOTYPES_
+static Boolean trycheck(
+ Aaddr adr, /* IN - ACODE address to check table */
+ Boolean act /* IN - Act if it fails ? */
+)
+#else
+static Boolean trycheck(adr, act)
+ Aaddr adr; /* IN - ACODE address to check table */
+ Boolean act; /* IN - Act if it fails ? */
+#endif
+{
+ ChkElem *chk;
+
+ chk = (ChkElem *) addrTo(adr);
+ if (chk->exp == 0) {
+ interpret(chk->stms);
+ return(FALSE);
+ } else {
+ while (!endOfTable(chk)) {
+ interpret(chk->exp);
+ if (!(Abool)pop()) {
+ if (act)
+ interpret(chk->stms);
+ return(FALSE);
+ }
+ chk++;
+ }
+ return(TRUE);
+ }
+}
+
+
+/*======================================================================
+ go()
+
+ Move hero in a direction.
+
+ */
+#ifdef _PROTOTYPES_
+void go(int dir)
+#else
+void go(dir)
+ int dir;
+#endif
+{
+ ExtElem *ext;
+ Boolean ok;
+ Aword oldloc;
+
+ ext = (ExtElem *) addrTo(locs[cur.loc-LOCMIN].exts);
+ if (locs[cur.loc-LOCMIN].exts != 0)
+ while (!endOfTable(ext)) {
+ if (ext->code == dir) {
+ ok = TRUE;
+ if (ext->checks != 0) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Checking:>\n");
+ }
+ ok = trycheck(ext->checks, TRUE);
+ }
+ if (ok) {
+ oldloc = cur.loc;
+ if (ext->action != 0) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Executing:>\n");
+ }
+ interpret(ext->action);
+ }
+ /* Still at the same place? */
+ if (where(HERO) == oldloc) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Moving:>\n");
+ }
+ locate(HERO, ext->next);
+ }
+ }
+ return;
+ }
+ ext++;
+ }
+ error(M_NO_WAY);
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ findalt()
+
+ Find the verb alternative wanted in a verb list and return
+ the address to it.
+
+ */
+#ifdef _PROTOTYPES_
+static AltElem *findalt(
+ Aword vrbsadr, /* IN - Address to start of list */
+ Aword param /* IN - Which parameter to match */
+)
+#else
+static AltElem *findalt(vrbsadr, param)
+ Aword vrbsadr; /* IN - Address to start of list */
+ Aword param; /* IN - Which parameter to match */
+#endif
+{
+ VrbElem *vrb;
+ AltElem *alt;
+
+ if (vrbsadr == 0)
+ return(NULL);
+
+ for (vrb = (VrbElem *) addrTo(vrbsadr); !endOfTable(vrb); vrb++)
+ if (vrb->code == cur.vrb) {
+ for (alt = (AltElem *) addrTo(vrb->alts); !endOfTable(alt); alt++)
+ if (alt->param == param || alt->param == 0)
+ return alt;
+ return NULL;
+ }
+ return NULL;
+}
+
+
+
+
+/*======================================================================
+
+ possible()
+
+ Check if current action is possible according to the CHECKs.
+
+ */
+#ifdef _PROTOTYPES_
+Boolean possible(void)
+#else
+Boolean possible()
+#endif
+{
+ AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
+ int i; /* Parameter index */
+
+ fail = FALSE;
+ alt[0] = findalt(header->vrbs, 0);
+ /* Perform global checks */
+ if (alt[0] != 0 && alt[0]->checks != 0) {
+ if (!trycheck(alt[0]->checks, FALSE)) return FALSE;
+ if (fail) return FALSE;
+ }
+
+ /* Now CHECKs in this location */
+ alt[1] = findalt(locs[cur.loc-LOCMIN].vrbs, 0);
+ if (alt[1] != 0 && alt[1]->checks != 0)
+ if (!trycheck(alt[1]->checks, FALSE))
+ return FALSE;
+
+ for (i = 0; params[i].code != EOF; i++) {
+ alt[i+2] = findalt(objs[params[i].code-OBJMIN].vrbs, i+1);
+ /* CHECKs in a possible parameter */
+ if (alt[i+2] != 0 && alt[i+2]->checks != 0)
+ if (!trycheck(alt[i+2]->checks, FALSE))
+ return FALSE;
+ }
+
+ for (i = 0; i < 2 || params[i-2].code != EOF; i++)
+ if (alt[i] != 0 && alt[i]->action != 0)
+ break;
+ if (i >= 2 && params[i-2].code == EOF)
+ /* Didn't find any code for this verb/object combination */
+ return FALSE;
+ else
+ return TRUE;
+}
+
+
+
+/*----------------------------------------------------------------------
+
+ do_it()
+
+ Execute the action commanded by hero.
+
+ */
+#ifdef _PROTOTYPES_
+static void do_it(void)
+#else
+static void do_it()
+#endif
+{
+ AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
+ Boolean done[MAXPARAMS+2]; /* Is it done */
+ int i; /* Parameter index */
+ char trace[80]; /* Trace string buffer */
+
+ fail = FALSE;
+ alt[0] = findalt(header->vrbs, 0);
+ /* Perform global checks */
+ if (alt[0] != 0 && alt[0]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, GLOBAL:>\n", cur.vrb);
+ if (!trycheck(alt[0]->checks, TRUE)) return;
+ if (fail) return;
+ }
+
+ /* Now CHECKs in this location */
+ alt[1] = findalt(locs[cur.loc-LOCMIN].vrbs, 0);
+ if (alt[1] != 0 && alt[1]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, in LOCATION:>\n", cur.vrb);
+ if (!trycheck(alt[1]->checks, TRUE)) return;
+ if (fail) return;
+ }
+
+ for (i = 0; params[i].code != EOF; i++) {
+ if (isLit(params[i].code))
+ alt[i+2] = 0;
+ else {
+ if (isObj(params[i].code))
+ alt[i+2] = findalt(objs[params[i].code-OBJMIN].vrbs, i+1);
+ else if (isAct(params[i].code))
+ alt[i+2] = findalt(acts[params[i].code-ACTMIN].vrbs, i+1);
+ else
+ syserr("Illegal parameter type.");
+ /* CHECKs in the parameters */
+ if (alt[i+2] != 0 && alt[i+2]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, in Parameter #%d:>\n", cur.vrb, i);
+ if (!trycheck(alt[i+2]->checks, TRUE)) return;
+ if (fail) return;
+ }
+ }
+ }
+
+ /* Check for anything to execute... */
+ for (i = 0; i < 2 || params[i-2].code != EOF; i++)
+ if (alt[i] != 0 && alt[i]->action != 0)
+ break;
+ if (i >= 2 && params[i-2].code == EOF)
+ /* Didn't find any code for this verb/object combination */
+ error(M_CANT0);
+
+ /* Perform actions! */
+
+ /* First try any BEFORE or ONLY from outside in */
+ done[0] = FALSE;
+ done[1] = FALSE;
+ for (i = 2; params[i-2].code != EOF; i++)
+ done[i] = FALSE;
+ i--;
+ while (i >= 0) {
+ if (alt[i] != 0)
+ if (alt[i]->qual == (Aword)Q_BEFORE || alt[i]->qual == (Aword)Q_ONLY) {
+ if (alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i-1);
+ if (alt[i]->qual == (Aword)Q_BEFORE)
+ printf("\n<VERB %d, %s (BEFORE), Body:>\n", cur.vrb, trace);
+ else
+ printf("\n<VERB %d, %s (ONLY), Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ if (alt[i]->qual == (Aword)Q_ONLY) return;
+ }
+ done[i] = TRUE;
+ }
+ i--;
+ }
+
+ /* Then execute any not declared as AFTER, i.e. the default */
+ for (i = 0; i < 2 || params[i-2].code != EOF; i++) {
+ if (alt[i] != 0)
+ if (alt[i]->qual != (Aword)Q_AFTER) {
+ if (!done[i] && alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i-1);
+ printf("\n<VERB %d, %s, Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ }
+ done[i] = TRUE;
+ }
+ }
+
+ /* Finally, the ones declared as after */
+ i--;
+ while (i >= 0) {
+ if (alt[i] != 0)
+ if (!done[i] && alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i-1);
+ printf("\n<VERB %d, %s (AFTER), Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ }
+ i--;
+ }
+}
+
+
+
+/*======================================================================
+
+ action()
+
+ Execute all activities commanded. Handles possible multiple actions
+ such as THEM or lists of objects.
+
+ */
+#ifdef _PROTOTYPES_
+void action(
+ ParamElem plst[] /* IN - Plural parameter list */
+)
+#else
+void action(plst)
+ ParamElem plst[];
+#endif
+{
+ int i, mpos;
+ char marker[10];
+
+ if (plural) {
+ /*
+ The code == 0 means this is a multiple position. We must loop
+ over this position (and replace it by each present in the plst)
+ */
+ for (mpos = 0; params[mpos].code != 0; mpos++); /* Find multiple position */
+ sprintf(marker, "($%d)", mpos+1); /* Prepare a printout with $1/2/3 */
+ for (i = 0; plst[i].code != EOF; i++) {
+ params[mpos] = plst[i];
+ output(marker);
+ do_it();
+ if (plst[i+1].code != EOF)
+ para();
+ }
+ params[mpos].code = 0;
+ } else
+ do_it();
+}
+
+
+
+/*----------------------------------------------------------------------*\
+
+ Event Handling
+
+ eventchk()
+
+\*----------------------------------------------------------------------*/
+
+
+/*----------------------------------------------------------------------
+ eventchk()
+
+ Check if any events are pending. If so execute them.
+ */
+#ifdef _PROTOTYPES_
+static void eventchk(void)
+#else
+static void eventchk()
+#endif
+{
+ while (etop != 0 && eventq[etop-1].time == cur.tick) {
+ etop--;
+ if (isLoc(eventq[etop].where))
+ cur.loc = eventq[etop].where;
+ else
+ cur.loc = where(eventq[etop].where);
+ if (trcflg) {
+ printf("\n<EVENT %d (at ", eventq[etop].event);
+ debugsay(cur.loc);
+ printf("):>\n");
+ }
+ interpret(evts[eventq[etop].event-EVTMIN].code);
+ }
+}
+
+
+
+
+
+/*----------------------------------------------------------------------*\
+
+ Main program and initialisation
+
+ codfil
+ filenames
+
+ checkvers()
+ load()
+ checkdebug()
+ initheader()
+ initstrings()
+ start()
+ init()
+ main()
+
+\*----------------------------------------------------------------------*/
+
+
+Common::SeekableReadStream *codfil;
+char codfnm[256];
+static char txtfnm[256];
+static char logfnm[256];
+
+
+/*----------------------------------------------------------------------
+
+ checkvers()
+
+ */
+#ifdef _PROTOTYPES_
+static void checkvers(AcdHdr *header)
+#else
+static void checkvers(header)
+ AcdHdr *header;
+#endif
+{
+ char vers[4];
+ char state[2];
+
+ /* Construct our own version */
+ vers[0] = alan.version.version;
+ vers[1] = alan.version.revision;
+
+ /* Check version of .ACD file */
+ if (dbgflg) {
+ state[0] = header->vers[3];
+ state[1] = '\0';
+ printf("<Version of '%s' is %d.%d(%d)%s>",
+ advnam,
+ (int)(header->vers[0]),
+ (int)(header->vers[1]),
+ (int)(header->vers[2]),
+ (header->vers[3])==0? "": state);
+ newline();
+ }
+
+ /* Compatible if version and revision match... */
+ if (strncmp(header->vers, vers, 2) != 0) {
+#ifdef V25COMPATIBLE
+ if (header->vers[0] == 2 && header->vers[1] == 5) /* Check for 2.5 version */
+ /* This we can convert later if needed... */;
+ else
+#endif
+#ifdef V27COMPATIBLE
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ /* This we can convert later if needed... */;
+ else
+#endif
+ if (errflg) {
+ char str[80];
+ sprintf(str, "Incompatible version of ACODE program. Game is %ld.%ld, interpreter %ld.%ld.",
+ (long) (header->vers[0]),
+ (long) (header->vers[1]),
+ (long) alan.version.version,
+ (long) alan.version.revision);
+ syserr(str);
+ } else
+ output("<WARNING! Incompatible version of ACODE program.>\n");
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ load()
+
+ */
+#ifdef _PROTOTYPES_
+static void load(void)
+#else
+static void load()
+#endif
+{
+ AcdHdr tmphdr;
+ Aword crc = 0;
+ int i;
+ char err[100];
+
+ codfil->seek(0);
+ tmphdr.load(*codfil);
+ checkvers(&tmphdr);
+
+ /* Allocate and load memory */
+
+#ifdef REVERSED
+ reverseHdr(&tmphdr);
+#endif
+
+ /* No memory allocated yet? */
+ if (memory == NULL) {
+#ifdef V25COMPATIBLE
+ if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5)
+ /* We need some more memory to expand 2.5 format*/
+ memory = allocate((tmphdr.size+tmphdr.objmax-tmphdr.objmin+1+2)*sizeof(Aword));
+ else
+#endif
+ memory = (Aword *)allocate(tmphdr.size * sizeof(Aword));
+ }
+ header = (AcdHdr *) addrTo(0);
+
+ if ((tmphdr.size * sizeof(Aword)) > codfil->size())
+ ::error("Header size is greater than filesize");
+
+ codfil->seek(0);
+ Aword *ptr = addrTo(0);
+ for (int idx = 0; idx < tmphdr.size; ++idx, ++ptr)
+ *ptr = codfil->readUint32LE();
+
+ /* Calculate checksum */
+ for (i = sizeof(tmphdr)/sizeof(Aword); i < memTop; i++) {
+ crc += memory[i]&0xff;
+ crc += (memory[i]>>8)&0xff;
+ crc += (memory[i]>>16)&0xff;
+ crc += (memory[i]>>24)&0xff;
+#ifdef CRCLOG
+ printf("%6x\t%6lx\t%6lx\n", i, crc, memory[i]);
+#endif
+ }
+ if (crc != tmphdr.acdcrc) {
+ sprintf(err, "Checksum error in .ACD file (0x%lx instead of 0x%lx).",
+ (unsigned long) crc, (unsigned long) tmphdr.acdcrc);
+ if (errflg)
+ syserr(err);
+ else {
+ output("<WARNING! $$");
+ output(err);
+ output("$$ Ignored, proceed at your own risk.>$n");
+ }
+ }
+
+#ifdef REVERSED
+ if (dbgflg||trcflg||stpflg)
+ output("<Hmm, this is a little-endian machine, fixing byte ordering....");
+ reverseACD(tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5); /* Reverse all words in the ACD file */
+ if (dbgflg||trcflg||stpflg)
+ output("OK.>$n");
+#endif
+
+#ifdef V25COMPATIBLE
+ /* Check for 2.5 version */
+ if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5) {
+ if (dbgflg||trcflg||stpflg)
+ output("<Hmm, this is a v2.5 game, please wait while I convert it...");
+ c25to26ACD();
+ if (dbgflg||trcflg||stpflg)
+ output("OK.>$n");
+ }
+#endif
+
+}
+
+
+/*----------------------------------------------------------------------
+
+ checkdebug()
+
+ */
+#ifdef _PROTOTYPES_
+static void checkdebug(void)
+#else
+static void checkdebug()
+#endif
+{
+ /* Make sure he can't debug if not allowed! */
+ if (!header->debug) {
+ if (dbgflg|trcflg|stpflg)
+ printf("<Sorry, '%s' is not compiled for debug!>\n", advnam);
+ para();
+ dbgflg = FALSE;
+ trcflg = FALSE;
+ stpflg = FALSE;
+ }
+
+#ifndef GLK
+ if (dbgflg) /* If debugging */
+ srand(0); /* use no randomization */
+ else
+ srand(time(0)); /* seed random generator */
+#endif
+}
+
+
+/*----------------------------------------------------------------------
+
+ initheader()
+
+ */
+#ifdef _PROTOTYPES_
+static void initheader(void)
+#else
+static void initheader()
+#endif
+{
+ dict = (WrdElem *) addrTo(header->dict);
+ /* Find out number of entries in dictionary */
+ for (dictsize = 0; !endOfTable(&dict[dictsize]); dictsize++);
+ vrbs = (VrbElem *) addrTo(header->vrbs);
+ stxs = (StxElem *) addrTo(header->stxs);
+ locs = (LocElem *) addrTo(header->locs);
+ acts = (ActElem *) addrTo(header->acts);
+ objs = (ObjElem *) addrTo(header->objs);
+ evts = (EvtElem *) addrTo(header->evts);
+ cnts = (CntElem *) addrTo(header->cnts);
+ ruls = (RulElem *) addrTo(header->ruls);
+ msgs = (MsgElem *) addrTo(header->msgs);
+ scores = (Aword *) addrTo(header->scores);
+
+ if (header->pack)
+ freq = (Aword *) addrTo(header->freq);
+}
+
+
+/*----------------------------------------------------------------------
+
+ initstrings()
+
+ */
+#ifdef _PROTOTYPES_
+static void initstrings(void)
+#else
+static void initstrings()
+#endif
+{
+ IniElem *init;
+
+ for (init = (IniElem *) addrTo(header->init); !endOfTable(init); init++) {
+ getstr(init->fpos, init->len);
+ memory[init->adr] = pop();
+ }
+}
+
+
+/*----------------------------------------------------------------------
+
+ start()
+
+ */
+#ifdef _PROTOTYPES_
+static void start(void)
+#else
+static void start()
+#endif
+{
+ int startloc;
+
+ cur.tick = -1;
+ cur.loc = startloc = where(HERO);
+ cur.act = HERO;
+ cur.score = 0;
+ if (trcflg)
+ printf("\n<START:>\n");
+ interpret(header->start);
+ para();
+
+ acts[HERO-ACTMIN].loc = 0;
+ locate(HERO, startloc);
+}
+
+
+
+/*----------------------------------------------------------------------
+ init()
+
+ Initialization, program load etc.
+
+ */
+#ifdef _PROTOTYPES_
+static void init(void)
+#else
+static void init()
+#endif
+{
+ int i;
+
+ /* Initialise some status */
+ etop = 0; /* No pending events */
+ looking = FALSE; /* Not looking now */
+ dscrstkp = 0; /* No describe in progress */
+
+ load();
+
+ initheader();
+ checkdebug();
+
+ /* Initialise string attributes */
+ initstrings();
+
+ getPageSize();
+
+ /* Find first conjunction and use that for ',' handling */
+ for (i = 0; i < dictsize; i++)
+ if (isConj(i)) {
+ conjWord = i;
+ break;
+ }
+
+ /* Start the adventure */
+ clear();
+ start();
+}
+
+
+
+/*----------------------------------------------------------------------
+ movactor()
+
+ Let the current actor move. If player, ask him.
+
+ */
+#ifdef _PROTOTYPES_
+static void movactor(void)
+#else
+static void movactor()
+#endif
+{
+ ScrElem *scr;
+ StepElem *step;
+ ActElem *act = (ActElem *) &acts[cur.act-ACTMIN];
+
+ cur.loc = where(cur.act);
+ if (cur.act == HERO) {
+ parse();
+ fail = FALSE; /* fail only aborts one actor */
+ rules();
+ } else if (act->script != 0) {
+ for (scr = (ScrElem *) addrTo(act->scradr); !endOfTable(scr); scr++)
+ if (scr->code == act->script) {
+ /* Find correct step in the list by indexing */
+ step = (StepElem *) addrTo(scr->steps);
+ step = (StepElem *) &step[act->step];
+ /* Now execute it, maybe. First check wait count */
+ if (step->after > act->count) {
+ /* Wait some more */
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Waiting %ld more>\n",
+ act->script, act->step+1, step->after-act->count);
+ }
+ act->count++;
+ rules();
+ return;
+ } else
+ act->count = 0;
+ /* Then check possible expression */
+ if (step->exp != 0) {
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Evaluating:>\n",
+ act->script, act->step+1);
+ }
+ interpret(step->exp);
+ if (!(Abool)pop()) {
+ rules();
+ return; /* Hadn't happened yet */
+ }
+ }
+ /* OK, so finally let him do his thing */
+ act->step++; /* Increment step number before executing... */
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Executing:>\n",
+ act->script, act->step);
+ }
+ interpret(step->stm);
+ step++;
+ /* ... so that we can see if he is USEing another script now */
+ if (act->step != 0 && endOfTable(step))
+ /* No more steps in this script, so stop him */
+ act->script = 0;
+ fail = FALSE; /* fail only aborts one actor */
+ rules();
+ return;
+ }
+ syserr("Unknown actor script.");
+ } else if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), Idle>\n");
+ rules();
+ return;
+ }
+}
+
+/*----------------------------------------------------------------------
+
+ openFiles()
+
+ Open the necessary files.
+
+ */
+#ifdef _PROTOTYPES_
+static void openFiles(void)
+#else
+static void openFiles()
+#endif
+{
+ char str[256];
+ char *usr = "";
+ time_t tick;
+
+#ifndef GLK
+ /* Open Acode file */
+ strcpy(codfnm, advnam);
+ strcat(codfnm, ".acd");
+
+ if ((codfil = fopen(codfnm, READ_MODE)) == NULL) {
+ strcpy(str, "Can't open adventure code file '");
+ strcat(str, codfnm);
+ strcat(str, "'.");
+ syserr(str);
+ }
+#endif
+
+#ifdef GARGLK
+ {
+ char *s = strrchr(codfnm, '\\');
+ if (!s) s = strrchr(codfnm, '/');
+ g_vm->garglk_set_story_name(s ? s + 1 : codfnm);
+ }
+#endif
+
+ /* Open Text file */
+ strcpy(txtfnm, advnam);
+ strcat(txtfnm, ".dat");
+
+ Common::File *f = new Common::File();
+ if (!f->open(txtfnm)) {
+ delete f;
+ Common::String s = Common::String::format("Can't open adventure text data file '%s'.", txtfnm);
+ ::error(s.c_str());
+ }
+
+ // If logging open log file
+ if (logflg) {
+ sprintf(logfnm, "%s.log", advnam);
+ logfil = g_system->getSavefileManager()->openForSaving(logfnm);
+
+ logflg = logfil != nullptr;
+ }
+}
+
+
+/*======================================================================
+
+ run()
+
+ Run the adventure
+
+ */
+void run(void)
+{
+ openFiles();
+
+ //setjmp(restart_label); /* Return here if he wanted to restart */
+
+ init(); /* Load, initialise and start the adventure */
+
+ while (TRUE) {
+#ifdef MALLOC
+ if (malloc_verify() == 0) syserr("Error in heap.");
+#endif
+ if (dbgflg)
+ debug();
+
+ eventchk();
+ cur.tick++;
+// (void) setjmp(jmpbuf);
+
+ /* Move all characters */
+ for (cur.act = ACTMIN; cur.act <= ACTMAX; cur.act++)
+ movactor();
+ }
+}
+
+} // End of namespace Alan2
+} // End of namespace Glk
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 48c6d96..7262a32 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -65,6 +65,7 @@ extern int dictsize; /* Number of entries in dictionary */
/* The text and message file */
extern Common::File *txtfil;
extern Common::WriteStream *logfil;
+extern Common::SeekableReadStream *codfil;
#undef ftell
#undef fgetc
@@ -79,7 +80,8 @@ extern Common::WriteStream *logfil;
/* File names */
-extern char *advnam;
+extern const char *advnam;
+extern char codfnm[256];
/* Screen formatting info */
extern int col, lin;
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
index daa0417..d36722c 100644
--- a/engines/glk/alan2/sysdep.cpp
+++ b/engines/glk/alan2/sysdep.cpp
@@ -30,6 +30,17 @@
namespace Glk {
namespace Alan2 {
+#ifdef GLK
+extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ Common::String s = Common::String::vformat(fmt, args);
+ va_end(args);
+
+ ws->write(s.c_str(), s.size());
+}
+#endif
+
#ifdef _PROTOTYPES_
extern void syserr(char str[]);
#endif
diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h
index 72769cb..5e562cd 100644
--- a/engines/glk/alan2/sysdep.h
+++ b/engines/glk/alan2/sysdep.h
@@ -37,6 +37,7 @@
*/
#include "common/scummsys.h"
+#include "common/stream.h"
namespace Glk {
namespace Alan2 {
@@ -55,7 +56,7 @@ namespace Alan2 {
#undef rand
#define rand() g_vm->getRandomNumber(0x7fffffff)
#undef fprintf
-#define fprintf(FP, STR) FP->write(STR, strlen(STR) + 1)
+extern void fprintf(Common::WriteStream *ws, const char *fmt, ...);
#endif
/* Place definitions of OS and compiler here if necessary */
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index b87fea9..3190b09 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -31,6 +31,7 @@ MODULE_OBJS := \
advsys/game.o \
advsys/glk_interface.o \
advsys/vm.o \
+ alan2/acode.o \
alan2/alan2.o \
alan2/detection.o \
alan2/alan_version.o \
@@ -41,6 +42,7 @@ MODULE_OBJS := \
alan2/glkio.o \
alan2/glkstart.o \
alan2/inter.o \
+ alan2/main.o \
alan2/params.o \
alan2/parse.o \
alan2/readline.o \
Commit: 0bbd9e26385efc19557d3d96ed275f051d7fbd04
https://github.com/scummvm/scummvm/commit/0bbd9e26385efc19557d3d96ed275f051d7fbd04
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Fixes to game header loading and validation
Changed paths:
R engines/glk/alan2/acode.cpp
engines/glk/alan2/acode.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/module.mk
diff --git a/engines/glk/alan2/acode.cpp b/engines/glk/alan2/acode.cpp
deleted file mode 100644
index b842c81..0000000
--- a/engines/glk/alan2/acode.cpp
+++ /dev/null
@@ -1,81 +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/alan2/acode.h"
-
-namespace Glk {
-namespace Alan2 {
-
-AcdHdr::AcdHdr() : size(0), pack(0), paglen(0), pagwidth(0), debug(0), dict(0), oatrs(0),
- latrs(0), aatrs(0), acts(0), objs(0), locs(0), stxs(0), vrbs(0), evts(0),
- cnts(0), ruls(0), init(0), start(0), msgs(0), objmin(0), objmax(0), actmin(0),
- actmax(0), cntmin(0), cntmax(0), locmin(0), locmax(0), dirmin(0), dirmax(0),
- evtmin(0), evtmax(0), rulmin(0), rulmax(0), maxscore(0), scores(0),
- freq(0), acdcrc(0), txtcrc(0) {
- vers[0] = vers[1] = vers[2] = vers[3] = 0;
-}
-
-void AcdHdr::load(Common::SeekableReadStream &s) {
- s.read(vers, 4);
- size = s.readUint32LE();
- pack = s.readUint32LE();
- paglen = s.readUint32LE();
- pagwidth = s.readUint32LE();
- debug = s.readUint32LE();
- dict = s.readUint32LE();
- oatrs = s.readUint32LE();
- latrs = s.readUint32LE();
- aatrs = s.readUint32LE();
- acts = s.readUint32LE();
- objs = s.readUint32LE();
- locs = s.readUint32LE();
- stxs = s.readUint32LE();
- vrbs = s.readUint32LE();
- evts = s.readUint32LE();
- cnts = s.readUint32LE();
- ruls = s.readUint32LE();
- init = s.readUint32LE();
- start = s.readUint32LE();
- msgs = s.readUint32LE();
- objmin = s.readUint32LE();
- objmax = s.readUint32LE();
- actmin = s.readUint32LE();
- actmax = s.readUint32LE();
- cntmin = s.readUint32LE();
- cntmax = s.readUint32LE();
- locmin = s.readUint32LE();
- locmax = s.readUint32LE();
- dirmin = s.readUint32LE();
- dirmax = s.readUint32LE();
- evtmin = s.readUint32LE();
- evtmax = s.readUint32LE();
- rulmin = s.readUint32LE();
- rulmax = s.readUint32LE();
- maxscore = s.readUint32LE();
- scores = s.readUint32LE();
- freq = s.readUint32LE();
- acdcrc = s.readUint32LE();
- txtcrc = s.readUint32LE();
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index fff5144..ef218dd 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -209,7 +209,11 @@ typedef enum VarClass {
#define I_CLASS(x) ((x)>>28)
#define I_OP(x) ((x&0x8000000)?(x)|0x0f0000000:(x)&0x0fffffff)
+#include "common/pack-start.h" // START STRUCT PACKING
+/**
+ * Game header
+ */
struct AcdHdr {
/* Important info */
char vers[4]; /* 01 - Version of compiler */
@@ -248,17 +252,9 @@ struct AcdHdr {
Aaddr freq; /* 26 - Address to Char freq's for coding */
Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
Aword txtcrc; /* 28 - Checksum for text data file */
+} PACKED_STRUCT;
- /**
- * Constructor
- */
- AcdHdr();
-
- /**
- * Loads the header from the passed stream
- */
- void load(Common::SeekableReadStream &s);
-};
+#include "common/pack-end.h" // END STRUCT PACKING
/* Error message numbers */
typedef enum MsgKind {
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index fec1c62..5a00464 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -55,7 +55,7 @@ void Alan2::runGame() {
strncpy(codfnm, getFilename().c_str(), 255);
codfnm[255] = '\0';
- run();
+ Glk::Alan2::run();
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index d2e8323..196ff90 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -66,7 +66,7 @@ Aword *memory;
//static AcdHdr dummyHeader; /* Dummy to use until memory allocated */
AcdHdr *header;
-int memTop = 0; /* Top of load memory */
+int memTop; /* Top of load memory */
int conjWord; /* First conjunction in dictonary, for ',' */
@@ -217,12 +217,15 @@ void usage()
*/
#ifdef _PROTOTYPES_
-void syserr(char *str)
+void syserr(const char *str)
#else
void syserr(str)
char *str;
#endif
{
+#ifdef GLK
+ ::error("%s", str);
+#else
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$nSYSTEM ERROR: ");
@@ -247,6 +250,7 @@ of an Adventure that never was.$n$nSYSTEM ERROR: ");
#endif
terminate(0);
+#endif
}
@@ -1515,8 +1519,10 @@ static void load()
int i;
char err[100];
+ Aword *ptr = (Aword *)&tmphdr;
codfil->seek(0);
- tmphdr.load(*codfil);
+ for (i = 0; i < sizeof(tmphdr) / sizeof(Aword); ++i, ++ptr)
+ *ptr = codfil->readUint32LE();
checkvers(&tmphdr);
/* Allocate and load memory */
@@ -1535,14 +1541,14 @@ static void load()
#endif
memory = (Aword *)allocate(tmphdr.size * sizeof(Aword));
}
+ memTop = tmphdr.size;
header = (AcdHdr *) addrTo(0);
if ((tmphdr.size * sizeof(Aword)) > codfil->size())
::error("Header size is greater than filesize");
codfil->seek(0);
- Aword *ptr = addrTo(0);
- for (int idx = 0; idx < tmphdr.size; ++idx, ++ptr)
+ for (i = 0, ptr = memory; i < tmphdr.size; ++i, ++ptr)
*ptr = codfil->readUint32LE();
/* Calculate checksum */
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 7262a32..c72549f 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -103,7 +103,7 @@ extern void *allocate(unsigned long len);
extern void terminate(int code);
extern void usage(void);
extern void error(MsgKind msg);
-extern void syserr(char *msg);
+extern void syserr(const char *msg);
extern void statusline(void);
extern void output(char string[]);
extern void prmsg(MsgKind msg);
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 3190b09..49f44ad 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -31,7 +31,6 @@ MODULE_OBJS := \
advsys/game.o \
advsys/glk_interface.o \
advsys/vm.o \
- alan2/acode.o \
alan2/alan2.o \
alan2/detection.o \
alan2/alan_version.o \
Commit: 2fba84bf0a220a3515efdaddb6aae4109d777935
https://github.com/scummvm/scummvm/commit/2fba84bf0a220a3515efdaddb6aae4109d777935
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Add Glk window initialization
Changed paths:
R engines/glk/alan2/glkstart.cpp
R engines/glk/alan2/glkstart.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/alan2.h
engines/glk/alan2/main.cpp
engines/glk/module.mk
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 5a00464..05a024d 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -22,6 +22,7 @@
#include "glk/alan2/alan2.h"
#include "glk/alan2/main.h"
+#include "glk/alan2/glkio.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
@@ -46,16 +47,30 @@ void Alan2::runGame() {
if (!is_gamefile_valid())
return;
- Common::String filename = getFilename();
- while (filename.contains('.'))
- filename.deleteLastChar();
- advnam = filename.c_str();
+ initialize();
+
+ Glk::Alan2::run();
+}
+
+void Alan2::initialize() {
+ // first, open a window for error output
+ glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
+ if (glkMainWin == nullptr)
+ ::error("FATAL ERROR: Cannot open initial window");
+
+ g_vm->glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
+ glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
+ winmethod_Fixed, 1, wintype_TextGrid, 0);
+ g_vm->glk_set_window(glkMainWin);
+
+ _advName = getFilename();
+ while (_advName.contains('.'))
+ _advName.deleteLastChar();
+ advnam = _advName.c_str();
codfil = &_gameFile;
strncpy(codfnm, getFilename().c_str(), 255);
codfnm[255] = '\0';
-
- Glk::Alan2::run();
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h
index 3b5c778..78c5107 100644
--- a/engines/glk/alan2/alan2.h
+++ b/engines/glk/alan2/alan2.h
@@ -36,11 +36,17 @@ namespace Alan2 {
class Alan2 : public GlkAPI {
public:
bool vm_exited_cleanly;
+ Common::String _advName;
private:
/**
* Validates the game file, and if it's invalid, displays an error dialog
*/
bool is_gamefile_valid();
+
+ /**
+ * Initialization
+ */
+ void initialize();
public:
/**
* Constructor
diff --git a/engines/glk/alan2/glkstart.cpp b/engines/glk/alan2/glkstart.cpp
deleted file mode 100644
index 1119e18..0000000
--- a/engines/glk/alan2/glkstart.cpp
+++ /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.
- *
- */
-
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/glkstart.h"
-#include "glk/alan2/glkio.h"
-#include "glk/alan2/args.h"
-
-#include "glk/alan2/alan_version.h"
-
-namespace Glk {
-namespace Alan2 {
-
-glkunix_argumentlist_t glkunix_arguments[] = {
- { "-v", glkunix_arg_NoValue, "-v: verbose mode" },
- { "-l", glkunix_arg_NoValue, "-l: log player command and game output" },
- { "-i", glkunix_arg_NoValue, "-i: ignore version and checksum errors" },
- { "-d", glkunix_arg_NoValue, "-d: enter debug mode" },
- { "-t", glkunix_arg_NoValue, "-t: trace game execution" },
- { "-s", glkunix_arg_NoValue, "-s: single instruction trace" },
- { "", glkunix_arg_ValueFollows, "filename: The game file to load." },
- { NULL, glkunix_arg_End, NULL }
-};
-
-bool glkunix_startup_code(glkunix_startup_t *data) {
- // first, open a window for error output
- glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
- if (glkMainWin == nullptr)
- error("FATAL ERROR: Cannot open initial window");
-
- g_vm->glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
- glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
- winmethod_Fixed, 1, wintype_TextGrid, 0);
- g_vm->glk_set_window(glkMainWin);
-
- /* now process the command line arguments */
- args(data->argc, data->argv);
-
- g_vm->garglk_set_program_name(alan.shortHeader);
- g_vm->garglk_set_program_info("Alan Interpreter 2.8.6 by Thomas Nilsson\n");
-
- return true;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
diff --git a/engines/glk/alan2/glkstart.h b/engines/glk/alan2/glkstart.h
deleted file mode 100644
index 7e3a24b..0000000
--- a/engines/glk/alan2/glkstart.h
+++ /dev/null
@@ -1,70 +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 GLK_ALAN2_GLK_START
-#define GLK_ALAN2_GLK_START
-
-/* This header defines an interface that must be used by program linked
- with the various Unix Glk libraries -- at least, the three I wrote.
- (I encourage anyone writing a Unix Glk library to use this interface,
- but it's not part of the Glk spec.)
-
- Because Glk is *almost* perfectly portable, this interface *almost*
- doesn't have to exist. In practice, it's small.
-*/
-
-namespace Glk {
-namespace Alan2 {
-
-#define glkunix_arg_End (0)
-#define glkunix_arg_ValueFollows (1)
-#define glkunix_arg_NoValue (2)
-#define glkunix_arg_ValueCanFollow (3)
-#define glkunix_arg_NumberValue (4)
-
-typedef struct glkunix_argumentlist_struct {
- char *name;
- int argtype;
- char *desc;
-} glkunix_argumentlist_t;
-
-typedef struct glkunix_startup_struct {
- int argc;
- char **argv;
-} glkunix_startup_t;
-
-/* The list of command-line arguments; this should be defined in your code. */
-extern glkunix_argumentlist_t glkunix_arguments[];
-
-/* The external function; this should be defined in your code. */
-extern bool glkunix_startup_code(glkunix_startup_t *data);
-
-/* Some helpful utility functions which the library makes available
- to your code. Obviously, this is nonportable; so you should
- only call it from glkunix_startup_code().
-*/
-extern strid_t glkunix_stream_open_pathname(char *pathname, uint textmode, uint rock);
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 196ff90..2a1b884 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -1903,10 +1903,12 @@ static void openFiles()
Run the adventure
*/
-void run(void)
-{
+void run() {
openFiles();
+ // Set default line and column
+ col = lin = 1;
+
//setjmp(restart_label); /* Return here if he wanted to restart */
init(); /* Load, initialise and start the adventure */
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 49f44ad..3537fcd 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -39,7 +39,6 @@ MODULE_OBJS := \
alan2/decode.o \
alan2/exe.o \
alan2/glkio.o \
- alan2/glkstart.o \
alan2/inter.o \
alan2/main.o \
alan2/params.o \
Commit: 35cfe001c24fea912d59bcb14ce72bd3411ce66a
https://github.com/scummvm/scummvm/commit/35cfe001c24fea912d59bcb14ce72bd3411ce66a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Add structure packing to types
These types map onto the uint32 memory array. Chances are that the
default packing would be fine, since each structure field is always
using four byte types, but better safe than sorry
Changed paths:
engines/glk/alan2/types.h
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 2de31c0..11a17a5 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -80,7 +80,7 @@ typedef int Boolean; /* Boolean values within interpreter */
#endif
/* Amachine variables */
-typedef struct CurVars {
+struct CurVars {
int
vrb,
obj,
@@ -89,18 +89,20 @@ typedef struct CurVars {
tick,
score,
visits;
-} CurVars;
+};
+
+#include "common/pack-start.h" // START STRUCT PACKING
/* The various tables */
-typedef struct WrdElem { /* Dictionary */
+struct WrdElem { /* Dictionary */
Aaddr wrd; /* ACODE address to string */
Aword _class; /* Word class */
Aword code;
Aaddr adjrefs; /* Address to reference list */
Aaddr nounrefs; /* Address to reference list */
-} WrdElem;
+} PACKED_STRUCT;
-typedef struct ActElem { /* ACTOR TABLE */
+struct ActElem { /* ACTOR TABLE */
Aword loc; /* Location */
Abool describe; /* Description flag */
Aaddr nam; /* Address to name printing code */
@@ -112,21 +114,21 @@ typedef struct ActElem { /* ACTOR TABLE */
Aword count;
Aaddr vrbs;
Aaddr dscr; /* Address of description code */
-} ActElem;
+} PACKED_STRUCT;
-typedef struct ScrElem { /* SCRIPT TABLE */
+struct ScrElem { /* SCRIPT TABLE */
Aword code; /* Script number */
Aaddr dscr; /* Optional description statements */
Aaddr steps; /* Address to steps */
-} ScrElem;
+} PACKED_STRUCT;
-typedef struct StepElem { /* STEP TABLE */
+struct StepElem { /* STEP TABLE */
Aword after; /* After how many ticks? */
Aaddr exp; /* Address to expression saying when */
Aaddr stm; /* Address to the actual code */
-} StepElem;
+} PACKED_STRUCT;
-typedef struct LocElem { /* LOCATION TABLE */
+struct LocElem { /* LOCATION TABLE */
Aaddr nams; /* Address of name printing code */
Aaddr dscr; /* Address of description code */
Aaddr does; /* Address of does code */
@@ -134,66 +136,66 @@ typedef struct LocElem { /* LOCATION TABLE */
Aaddr atrs; /* Address of attribute list */
Aaddr exts; /* Address of exit list */
Aaddr vrbs; /* Address of local verb list */
-} LocElem;
+} PACKED_STRUCT;
-typedef struct ExtElem { /* EXIT TABLE structure */
+struct ExtElem { /* EXIT TABLE structure */
Abool done; /* Flag for reverse/convert process */
Aword code; /* Direction code */
Aaddr checks; /* Address of check table */
Aaddr action; /* Address of action code */
Aword next; /* Number of next location */
-} ExtElem;
+} PACKED_STRUCT;
-typedef struct ChkElem { /* CHECK TABLE */
+struct ChkElem { /* CHECK TABLE */
Aaddr exp; /* ACODE address to expression code */
Aaddr stms; /* ACODE address to statement code */
-} ChkElem;
+} PACKED_STRUCT;
-typedef struct VrbElem { /* VERB TABLE */
+struct VrbElem { /* VERB TABLE */
Aword code; /* Code for the verb */
Aaddr alts; /* Address to alternatives */
-} VrbElem;
+} PACKED_STRUCT;
-typedef struct StxElem { /* SYNTAX TABLE */
+struct StxElem { /* SYNTAX TABLE */
Aword code; /* Code for verb word */
Aaddr elms; /* Address to element tables */
-} StxElem;
+} PACKED_STRUCT;
-typedef struct ElmElem26 { /* ELEMENT TABLES */
+struct ElmElem26 { /* ELEMENT TABLES */
Aword code; /* Code for this element, 0 -> parameter */
Abool multiple; /* May be multiple (if parameter) */
Aaddr next; /* Address to next element table ... */
/* ... or class check if EOS */
-} ElmElem26;
+} PACKED_STRUCT;
-typedef struct ElmElem { /* ELEMENT TABLES */
+struct ElmElem { /* ELEMENT TABLES */
Aword code; /* Code for this element, 0 -> parameter */
Aword flags; /* Flags for multiple/omni (if parameter) */
/* CHANGED: v2.7 from Abool for multiple */
Aaddr next; /* Address to next element table ... */
/* ... or class check if EOS */
-} ElmElem;
+} PACKED_STRUCT;
-typedef struct ClaElem { /* CLASS DEFINITION TABLE */
+struct ClaElem { /* CLASS DEFINITION TABLE */
Aword code; /* Parameter number */
Aword classes; /* Parameter classes */
Aaddr stms; /* Exception statements */
-} ClaElem;
+} PACKED_STRUCT;
-typedef struct AltElem { /* VERB ALTERNATIVE TABLE */
+struct AltElem { /* VERB ALTERNATIVE TABLE */
Abool done; /* Flag for patching (reverse/convert) process */
Aword param; /* Parameter number */
Aword qual; /* Verb execution qualifier */
Aaddr checks; /* Address of the check table */
Aaddr action; /* Address of the action code */
-} AltElem;
+} PACKED_STRUCT;
-typedef struct AtrElem { /* ATTRIBUTE LIST */
+struct AtrElem { /* ATTRIBUTE LIST */
Aword val; /* Its value */
Aaddr stradr; /* Address to the name */
-} AtrElem;
+} PACKED_STRUCT;
-typedef struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
+struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
Aword loc; /* Current location */
Abool describe; /* Describe flag */
Aaddr atrs; /* Address of attribute list */
@@ -201,9 +203,9 @@ typedef struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
Aaddr vrbs; /* Address to local verb table */
Aaddr dscr1; /* Address to Aword description code */
Aaddr dscr2; /* Address to short description code */
-} ObjElem25;
+} PACKED_STRUCT;
-typedef struct ObjElem { /* OBJECT TABLE */
+struct ObjElem { /* OBJECT TABLE */
Aword loc; /* Current location */
Abool describe; /* Describe flag */
Aaddr atrs; /* Address of attribute list */
@@ -213,68 +215,70 @@ typedef struct ObjElem { /* OBJECT TABLE */
Aaddr art; /* Article printing code? Else use default */
/* INTRODUCED: v2.6 */
Aaddr dscr2; /* Address to short description code */
-} ObjElem;
+} PACKED_STRUCT;
-typedef struct CntElem { /* CONTAINER TABLE */
+struct CntElem { /* CONTAINER TABLE */
Aaddr lims; /* Address to limit check code */
Aaddr header; /* Address to header code */
Aaddr empty; /* Address to empty code */
Aword parent; /* Object or actor index */
Aaddr nam; /* Address to statement printing name */
-} CntElem;
+} PACKED_STRUCT;
-typedef struct LimElem { /* LIMIT Type */
+struct LimElem { /* LIMIT Type */
Aword atr; /* Attribute that limits */
Aword val; /* And the limiting value */
Aaddr stms; /* Statements if fail */
-} LimElem;
+} PACKED_STRUCT;
-typedef struct RulElem { /* RULE TABLE */
+struct RulElem { /* RULE TABLE */
Abool run; /* Is rule already run? */
Aaddr exp; /* Address to expression code */
Aaddr stms; /* Address to run */
-} RulElem;
+} PACKED_STRUCT;
-typedef struct EvtElem { /* EVENT TABLE */
+struct EvtElem { /* EVENT TABLE */
Aaddr stradr; /* Address to name string */
Aaddr code; /* Address of code to run */
-} EvtElem;
+} PACKED_STRUCT;
-typedef struct EvtqElem { /* EVENT QUEUE ELEMENT */
+struct EvtqElem { /* EVENT QUEUE ELEMENT */
int time;
int event;
int where;
-} EvtqElem;
+} PACKED_STRUCT;
-typedef struct IniElem { /* STRING INITIALISATION TABLE */
+struct IniElem { /* STRING INITIALISATION TABLE */
Aword fpos; /* File position */
Aword len; /* Length */
Aword adr; /* Where to store the string */
-} IniElem;
+} PACKED_STRUCT;
-typedef struct MsgElem26 { /* MESSAGE TABLE */
+struct MsgElem26 { /* MESSAGE TABLE */
Aword fpos; /* File position */
Aword len; /* Length of message */
-} MsgElem26;
+} PACKED_STRUCT;
-typedef struct MsgElem { /* MESSAGE TABLE */
+struct MsgElem { /* MESSAGE TABLE */
Aaddr stms; /* Address to statements*/
/* Changed v2.7 from fpos+len in .dat */
-} MsgElem;
+} PACKED_STRUCT;
-typedef struct ParamElem { /* PARAMETER */
+struct ParamElem { /* PARAMETER */
Aword code; /* Code for this parameter (0=multiple) */
Aword firstWord; /* Index to first word used by player */
Aword lastWord; /* d:o to last */
-} ParamElem;
+} PACKED_STRUCT;
typedef enum Type {TYPNUM, TYPSTR} Type;
-typedef struct LitElem { /* LITERAL */
+struct LitElem { /* LITERAL */
Type type;
Aptr value;
-} LitElem;
+} PACKED_STRUCT;
+
+#include "common/pack-end.h" // END STRUCT PACKING
#define MAXPARAMS 9
#define MAXENTITY (header->actmax)
Commit: 51a142aaf89fc5231b5a7b390ede08b1f7f1e08d
https://github.com/scummvm/scummvm/commit/51a142aaf89fc5231b5a7b390ede08b1f7f1e08d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Loading fixes
Changed paths:
engines/glk/alan2/glkio.h
engines/glk/alan2/inter.cpp
engines/glk/alan2/main.cpp
diff --git a/engines/glk/alan2/glkio.h b/engines/glk/alan2/glkio.h
index 151bb7a..8c1dee2 100644
--- a/engines/glk/alan2/glkio.h
+++ b/engines/glk/alan2/glkio.h
@@ -36,7 +36,6 @@ extern winid_t glkStatusWin;
/* NB: this header must be included in any file which calls print() */
-#define print glkio_printf
#undef printf
#define printf glkio_printf
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 02b4f48..dd3ee9e 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -257,7 +257,7 @@ void interpret(adr)
printf("PRINT \t%5ld, %5ld\t\"", fpos, len);
col = 34; /* To format it better! */
}
- print((char *)fpos, len);
+ print(fpos, len);
if (stpflg)
printf("\"");
break;
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 2a1b884..a508041 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -1519,18 +1519,15 @@ static void load()
int i;
char err[100];
- Aword *ptr = (Aword *)&tmphdr;
+ Aword *ptr = (Aword *)&tmphdr + 1;
codfil->seek(0);
- for (i = 0; i < sizeof(tmphdr) / sizeof(Aword); ++i, ++ptr)
- *ptr = codfil->readUint32LE();
+ codfil->read(&tmphdr.vers[0], 4);
+ for (i = 1; i < sizeof(tmphdr) / sizeof(Aword); ++i, ++ptr)
+ *ptr = codfil->readUint32BE();
checkvers(&tmphdr);
/* Allocate and load memory */
-#ifdef REVERSED
- reverseHdr(&tmphdr);
-#endif
-
/* No memory allocated yet? */
if (memory == NULL) {
#ifdef V25COMPATIBLE
@@ -1548,7 +1545,8 @@ static void load()
::error("Header size is greater than filesize");
codfil->seek(0);
- for (i = 0, ptr = memory; i < tmphdr.size; ++i, ++ptr)
+ codfil->read(&header->vers[0], 4);
+ for (i = 1, ptr = memory + 1; i < tmphdr.size; ++i, ++ptr)
*ptr = codfil->readUint32LE();
/* Calculate checksum */
@@ -1573,7 +1571,7 @@ static void load()
}
}
-#ifdef REVERSED
+#if defined(SCUMM_LITTLE_ENDIAN)
if (dbgflg||trcflg||stpflg)
output("<Hmm, this is a little-endian machine, fixing byte ordering....");
reverseACD(tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5); /* Reverse all words in the ACD file */
Commit: b4ae2ec4374a8f920fa3287b6906e09c6c68f57f
https://github.com/scummvm/scummvm/commit/b4ae2ec4374a8f920fa3287b6906e09c6c68f57f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Open text data file on startup
Changed paths:
engines/glk/alan2/alan2.cpp
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 05a024d..c9625a7 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -63,14 +63,15 @@ void Alan2::initialize() {
winmethod_Fixed, 1, wintype_TextGrid, 0);
g_vm->glk_set_window(glkMainWin);
- _advName = getFilename();
- while (_advName.contains('.'))
- _advName.deleteLastChar();
- advnam = _advName.c_str();
-
+ // Set up the code file to point to the already opened game file
codfil = &_gameFile;
strncpy(codfnm, getFilename().c_str(), 255);
codfnm[255] = '\0';
+
+ // Open up the text file
+ txtfil = new Common::File();
+ if (!txtfil->open(Common::String::format("%s.dat", advnam)))
+ ::error("Could not open adventure text data file");
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
@@ -84,6 +85,12 @@ Common::Error Alan2::writeGameData(Common::WriteStream *ws) {
}
bool Alan2::is_gamefile_valid() {
+ // Set up adventure name
+ _advName = getFilename();
+ while (_advName.contains('.'))
+ _advName.deleteLastChar();
+ advnam = _advName.c_str();
+
if (_gameFile.size() < 8) {
GUIErrorMessage(_("This is too short to be a valid Alan2 file."));
return false;
@@ -94,7 +101,7 @@ bool Alan2::is_gamefile_valid() {
return false;
}
- return true;
+ return Common::File::exists(Common::String::format("%s.dat", advnam));
}
} // End of namespace Alan2
Commit: df7465232108c15ca613db0b5e709e34378dbd8c
https://github.com/scummvm/scummvm/commit/df7465232108c15ca613db0b5e709e34378dbd8c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Added shouldQuit checks to break out of game loops
Changed paths:
engines/glk/alan2/exe.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/parse.cpp
engines/glk/alan2/readline.cpp
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index 1cccf3d..9b06943 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -236,7 +236,7 @@ void quit()
char choices[10];
para();
- while (TRUE) {
+ while (!g_vm->shouldQuit()) {
col = 1;
statusline();
prmsg(M_QUITACTION);
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index a508041..63ab545 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -1763,7 +1763,9 @@ static void movactor()
cur.loc = where(cur.act);
if (cur.act == HERO) {
parse();
- fail = FALSE; /* fail only aborts one actor */
+ if (g_vm->shouldQuit())
+ return;
+ fail = FALSE; /* fail only aborts one actor */
rules();
} else if (act->script != 0) {
for (scr = (ScrElem *) addrTo(act->scradr); !endOfTable(scr); scr++)
@@ -1902,30 +1904,33 @@ static void openFiles()
*/
void run() {
- openFiles();
+ openFiles();
- // Set default line and column
- col = lin = 1;
+ // Set default line and column
+ col = lin = 1;
- //setjmp(restart_label); /* Return here if he wanted to restart */
+ //setjmp(restart_label); /* Return here if he wanted to restart */
- init(); /* Load, initialise and start the adventure */
+ init(); /* Load, initialise and start the adventure */
- while (TRUE) {
+ while (TRUE) {
#ifdef MALLOC
- if (malloc_verify() == 0) syserr("Error in heap.");
+ if (malloc_verify() == 0) syserr("Error in heap.");
#endif
- if (dbgflg)
- debug();
+ if (dbgflg)
+ debug();
- eventchk();
- cur.tick++;
-// (void) setjmp(jmpbuf);
+ eventchk();
+ cur.tick++;
+ // (void) setjmp(jmpbuf);
- /* Move all characters */
- for (cur.act = ACTMIN; cur.act <= ACTMAX; cur.act++)
- movactor();
- }
+ // Move all characters
+ for (cur.act = ACTMIN; cur.act <= ACTMAX; cur.act++) {
+ movactor();
+ if (g_vm->shouldQuit())
+ return;
+ }
+ }
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index 4e54c5c..41a4424 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -21,6 +21,7 @@
*/
#include <string>
+#include "glk/alan2/alan2.h"
#include "glk/alan2/types.h"
#ifdef USE_READLINE
@@ -212,6 +213,9 @@ static void agetline()
fprintf(logfil, "> ");
#ifdef USE_READLINE
if (!readline(buf)) {
+ if (g_vm->shouldQuit())
+ return;
+
newline();
quit();
}
@@ -257,6 +261,9 @@ static void scan()
char *str;
agetline();
+ if (g_vm->shouldQuit())
+ return;
+
wrds[0] = 0;
for (i = 0; i < litCount; i++)
if (litValues[i].type == TYPSTR && litValues[i].value != 0)
@@ -820,6 +827,8 @@ void parse()
if (wrds[wrdidx] == EOF) {
wrdidx = 0;
scan();
+ if (g_vm->shouldQuit())
+ return;
} else if (anyOutput)
para();
diff --git a/engines/glk/alan2/readline.cpp b/engines/glk/alan2/readline.cpp
index c96b26c..5f1192d 100644
--- a/engines/glk/alan2/readline.cpp
+++ b/engines/glk/alan2/readline.cpp
@@ -53,7 +53,11 @@ Boolean readline(char usrbuf[])
g_vm->glk_select(&event);
if (evtype_Arrange == event.type)
statusline();
+ if (g_vm->shouldQuit())
+ return false;
+
} while (event.type != evtype_LineInput);
+
usrbuf[event.val1] = 0;
return TRUE;
}
Commit: ad1cecaeac5d54b0973d6c7edce8181cb965ff68
https://github.com/scummvm/scummvm/commit/ad1cecaeac5d54b0973d6c7edce8181cb965ff68
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:49-07:00
Commit Message:
GLK: ALAN2: Added savegame code
Changed paths:
engines/glk/alan2/alan2.cpp
engines/glk/alan2/alan2.h
engines/glk/alan2/exe.h
engines/glk/alan2/types.h
engines/glk/module.mk
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index c9625a7..73b8a5e 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -21,13 +21,15 @@
*/
#include "glk/alan2/alan2.h"
+#include "glk/alan2/exe.h"
#include "glk/alan2/main.h"
#include "glk/alan2/glkio.h"
+#include "common/system.h"
#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
#include "common/scummsys.h"
-#include "common/system.h"
+#include "common/serializer.h"
#include "glk/glk.h"
#include "glk/streams.h"
@@ -75,13 +77,70 @@ void Alan2::initialize() {
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
- // TODO
- return Common::kReadingFailed;
+ Common::Serializer s(rs, nullptr);
+ synchronizeSave(s);
+
+ return Common::kNoError;
}
Common::Error Alan2::writeGameData(Common::WriteStream *ws) {
- // TODO
- return Common::kWritingFailed;
+ Common::Serializer s(nullptr, ws);
+ synchronizeSave(s);
+
+ ws->flush();
+ return Common::kNoError;
+}
+
+void Alan2::synchronizeSave(Common::Serializer &s) {
+ AtrElem *atr;
+ int i;
+
+ // Sync current values
+ cur.synchronize(s);
+
+ // Save actors
+ for (i = ACTMIN; i <= ACTMAX; ++i) {
+ s.syncAsSint32LE(acts[i-ACTMIN].loc);
+ s.syncAsSint32LE(acts[i-ACTMIN].script);
+ s.syncAsSint32LE(acts[i-ACTMIN].step);
+ s.syncAsSint32LE(acts[i-ACTMIN].count);
+
+ if (acts[i-ACTMIN].atrs) {
+ for (atr = (AtrElem *)addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); ++atr)
+ s.syncAsSint32LE(atr->val);
+ }
+ }
+
+ // Sync locations
+ for (i = LOCMIN; i <= LOCMAX; ++i) {
+ s.syncAsSint32LE(locs[i-LOCMIN].describe);
+ if (locs[i-LOCMIN].atrs)
+ for (atr = (AtrElem *)addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
+ s.syncAsSint32LE(atr->val);
+ }
+
+ // Sync objects
+ for (i = OBJMIN; i <= OBJMAX; ++i) {
+ s.syncAsSint32LE(objs[i-OBJMIN].loc);
+ if (objs[i-OBJMIN].atrs)
+ for (atr = (AtrElem *)addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
+ s.syncAsSint32LE(atr->val);
+ }
+
+ // Sync the event queue
+ if (s.isSaving()) {
+ eventq[etop].time = 0; // Mark the top
+ for (i = 0; i <= etop; ++i)
+ eventq[i].synchronize(s);
+ } else {
+ for (etop = 0; eventq[etop - 1].time; ++etop)
+ eventq[etop].synchronize(s);
+ --etop;
+ }
+
+ // Sync scores
+ for (i = 0; scores[i] != EOF; i++)
+ s.syncAsSint32LE(scores[i]);
}
bool Alan2::is_gamefile_valid() {
diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h
index 78c5107..8960648 100644
--- a/engines/glk/alan2/alan2.h
+++ b/engines/glk/alan2/alan2.h
@@ -24,6 +24,7 @@
#define GLK_ALAN2
#include "common/scummsys.h"
+#include "common/serializer.h"
#include "common/stack.h"
#include "glk/glk_api.h"
@@ -47,6 +48,11 @@ private:
* Initialization
*/
void initialize();
+
+ /**
+ * Synchronize data to or from a save file
+ */
+ void synchronizeSave(Common::Serializer &s);
public:
/**
* Constructor
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
index 0acfdda..fbecac5 100644
--- a/engines/glk/alan2/exe.h
+++ b/engines/glk/alan2/exe.h
@@ -26,6 +26,8 @@
/* Header file for instruction execution unit in Alan interpreter
*/
+#include "glk/alan2/types.h"
+
namespace Glk {
namespace Alan2 {
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 11a17a5..699dd0e 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -25,6 +25,8 @@
#include "glk/alan2/sysdep.h"
#include "glk/alan2/acode.h"
+#include "common/serializer.h"
+#include "common/stream.h"
namespace Glk {
namespace Alan2 {
@@ -89,6 +91,11 @@ struct CurVars {
tick,
score,
visits;
+
+ /**
+ * Read or write data to/from a save file
+ */
+ void synchronize(Common::Serializer &s);
};
#include "common/pack-start.h" // START STRUCT PACKING
@@ -246,6 +253,11 @@ struct EvtqElem { /* EVENT QUEUE ELEMENT */
int time;
int event;
int where;
+
+ /**
+ * Read or write data to/from a save file
+ */
+ void synchronize(Common::Serializer &s);
} PACKED_STRUCT;
struct IniElem { /* STRING INITIALISATION TABLE */
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index 3537fcd..6536cf0 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -49,6 +49,7 @@ MODULE_OBJS := \
alan2/stack.o \
alan2/sysdep.o \
alan2/term.o \
+ alan2/types.o \
frotz/bitmap_font.o \
frotz/config.o \
frotz/detection.o \
Commit: 8f75589971d70b2ca749d5389a332e6761213a5b
https://github.com/scummvm/scummvm/commit/8f75589971d70b2ca749d5389a332e6761213a5b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Remove all prototype ifdef blocks
Changed paths:
A engines/glk/alan2/types.cpp
engines/glk/alan2/args.cpp
engines/glk/alan2/args.h
engines/glk/alan2/debug.cpp
engines/glk/alan2/debug.h
engines/glk/alan2/decode.cpp
engines/glk/alan2/decode.h
engines/glk/alan2/exe.cpp
engines/glk/alan2/exe.h
engines/glk/alan2/inter.cpp
engines/glk/alan2/inter.h
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/params.cpp
engines/glk/alan2/params.h
engines/glk/alan2/parse.cpp
engines/glk/alan2/parse.h
engines/glk/alan2/readline.h
engines/glk/alan2/reverse.cpp
engines/glk/alan2/reverse.h
engines/glk/alan2/rules.cpp
engines/glk/alan2/rules.h
engines/glk/alan2/stack.cpp
engines/glk/alan2/stack.h
engines/glk/alan2/sysdep.cpp
engines/glk/alan2/sysdep.h
engines/glk/alan2/term.cpp
engines/glk/alan2/term.h
diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp
index 1946239..caf32c1 100644
--- a/engines/glk/alan2/args.cpp
+++ b/engines/glk/alan2/args.cpp
@@ -54,17 +54,7 @@ BPTR cd;
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-static void switches(
- unsigned argc,
- char *argv[]
-)
-#else
-static void switches(argc, argv)
- unsigned argc;
- char *argv[];
-#endif
-{
+static void switches(unsigned argc, char *argv[]) {
#ifndef GLK
uint i;
@@ -173,18 +163,7 @@ wb_parse(void)
#endif
#endif
-
-#ifdef _PROTOTYPES_
-void args(
- int argc,
- char * argv[]
-)
-#else
-void args(argc, argv)
- int argc;
- char *argv[];
-#endif
-{
+void args(int argc, char * argv[]) {
char *prgnam;
#ifdef __mac__
diff --git a/engines/glk/alan2/args.h b/engines/glk/alan2/args.h
index a86d519..dc2f088 100644
--- a/engines/glk/alan2/args.h
+++ b/engines/glk/alan2/args.h
@@ -38,11 +38,7 @@ namespace Alan2 {
#define PROGNAME "alan2"
#endif
-#ifdef _PROTOTYPES_
extern void args(int argc, char *argv[]);
-#else
-extern void args();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index dc353c7..785cd54 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -45,15 +45,7 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-static void showatrs(
- Aword atradr
-)
-#else
-static void showatrs(atradr)
- Aword atradr;
-#endif
-{
+static void showatrs(Aword atradr) {
AtrElem *at;
int i;
char str[80];
@@ -71,13 +63,7 @@ static void showatrs(atradr)
}
}
-
-#ifdef _PROTOTYPES_
-static void showobjs(void)
-#else
-static void showobjs()
-#endif
-{
+static void showobjs() {
char str[80];
int obj;
@@ -89,16 +75,7 @@ static void showobjs()
}
}
-
-#ifdef _PROTOTYPES_
-static void showobj(
- int obj
-)
-#else
-static void showobj(obj)
- int obj;
-#endif
-{
+static void showobj(int obj) {
char str[80];
#define OBJ (obj-OBJMIN)
@@ -138,13 +115,7 @@ static void showobj(obj)
#undef OBJ
}
-
-#ifdef _PROTOTYPES_
-static void showcnts(void)
-#else
-static void showcnts()
-#endif
-{
+static void showcnts() {
char str[80];
int cnt;
#define CNT (cnt-CNTMIN)
@@ -162,16 +133,7 @@ static void showcnts()
#undef CNT
}
-
-#ifdef _PROTOTYPES_
-static void showcnt(
- int cnt
-)
-#else
-static void showcnt(cnt)
- int cnt;
-#endif
-{
+static void showcnt(int cnt) {
char str[80];
int i;
Abool found = FALSE;
@@ -211,13 +173,7 @@ static void showcnt(cnt)
#undef CNT
}
-
-#ifdef _PROTOTYPES_
-static void showlocs(void)
-#else
-static void showlocs()
-#endif
-{
+static void showlocs() {
char str[80];
int loc;
@@ -229,16 +185,7 @@ static void showlocs()
}
}
-
-#ifdef _PROTOTYPES_
-static void showloc(
- int loc
-)
-#else
-static void showloc(loc)
- int loc;
-#endif
-{
+static void showloc(int loc) {
char str[80];
@@ -256,13 +203,7 @@ static void showloc(loc)
showatrs(locs[loc-LOCMIN].atrs);
}
-
-#ifdef _PROTOTYPES_
-static void showacts(void)
-#else
-static void showacts()
-#endif
-{
+static void showacts() {
char str[80];
int act;
@@ -274,16 +215,7 @@ static void showacts()
}
}
-
-#ifdef _PROTOTYPES_
-static void showact(
- int act
-)
-#else
-static void showact(act)
- int act;
-#endif
-{
+static void showact(int act) {
char str[80];
Boolean oldstp;
@@ -318,13 +250,7 @@ static void showact(act)
showatrs(acts[act-ACTMIN].atrs);
}
-
-#ifdef _PROTOTYPES_
-static void showevts(void)
-#else
-static void showevts()
-#endif
-{
+static void showevts() {
int evt, i;
char str[80];
Boolean scheduled;
@@ -353,37 +279,21 @@ static void showevts()
static Boolean trc, stp;
static int loc;
-#ifdef _PROTOTYPES_
-void saveInfo(void)
-#else
-void saveInfo()
-#endif
-{
+void saveInfo() {
/* Save some important things */
trc = trcflg; trcflg = FALSE;
stp = stpflg; stpflg = FALSE;
loc = cur.loc; cur.loc = where(HERO);
}
-#ifdef _PROTOTYPES_
-void restoreInfo(void)
-#else
-void restoreInfo()
-#endif
-{
+void restoreInfo() {
/* Restore! */
trcflg = trc;
stpflg = stp;
cur.loc = loc;
}
-
-#ifdef _PROTOTYPES_
-void debug(void)
-#else
-void debug()
-#endif
-{
+void debug() {
char buf[256];
char c;
int i;
@@ -483,13 +393,7 @@ void debug()
shown to the player.
*/
-#ifdef _PROTOTYPES_
-void debugsay(int item)
-#else
-void debugsay(item)
- int item;
-#endif
-{
+void debugsay(int item) {
saveInfo();
needsp = FALSE;
col = 1;
diff --git a/engines/glk/alan2/debug.h b/engines/glk/alan2/debug.h
index aac870e..6f020f9 100644
--- a/engines/glk/alan2/debug.h
+++ b/engines/glk/alan2/debug.h
@@ -28,18 +28,10 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-
-extern void saveInfo(void);
-extern void restoreInfo(void);
-extern void debug(void);
-extern void debugsay(int item);
-#else
extern void saveInfo();
extern void restoreInfo();
extern void debug();
-extern void debugsay();
-#endif
+extern void debugsay(int item);
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
index 4ffdc2f..f1ec3db 100644
--- a/engines/glk/alan2/decode.cpp
+++ b/engines/glk/alan2/decode.cpp
@@ -32,13 +32,7 @@ static int decodeBuffer; /* Bits to be input */
static int bitsToGo; /* Bits still in buffer */
static int garbageBits; /* Bits past EOF */
-
-#ifdef _PROTOTYPES_
-static int inputBit(void)
-#else
-static int inputBit()
-#endif
-{
+static int inputBit() {
int bit;
if (!bitsToGo) { /* More bits available ? */
@@ -63,12 +57,7 @@ static CodeValue value; /* Currently seen code value */
static CodeValue low, high; /* Current code region */
-#ifdef _PROTOTYPES_
-void startDecoding(void)
-#else
-void startDecoding()
-#endif
-{
+void startDecoding() {
int i;
bitsToGo = 0;
@@ -81,13 +70,7 @@ void startDecoding()
high = TOPVALUE;
}
-
-#ifdef _PROTOTYPES_
-int decodeChar(void)
-#else
-int decodeChar()
-#endif
-{
+int decodeChar() {
long range;
int f;
int symbol;
@@ -144,12 +127,7 @@ typedef struct DecodeInfo {
restore and continue later.
*/
-#ifdef _PROTOTYPES_
-void *pushDecode(void)
-#else
-void *pushDecode()
-#endif
-{
+void *pushDecode() {
DecodeInfo *info;
info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
@@ -171,13 +149,7 @@ void *pushDecode()
continue after having decoded something else.
*/
-#ifdef _PROTOTYPES_
-void popDecode(void *i)
-#else
-void popDecode(i)
- void *i;
-#endif
-{
+void popDecode(void *i) {
DecodeInfo *info = (DecodeInfo *) i;
fseek(txtfil, info->fpos, 0);
decodeBuffer = info->buffer;
diff --git a/engines/glk/alan2/decode.h b/engines/glk/alan2/decode.h
index 7ce15b4..2e430de 100644
--- a/engines/glk/alan2/decode.h
+++ b/engines/glk/alan2/decode.h
@@ -31,17 +31,10 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
extern void startDecoding(void);
extern int decodeChar(void);
extern void *pushDecode(void);
extern void popDecode(void *info);
-#else
-extern void startDecoding();
-extern int decodeChar();
-extern void *pushDecode();
-extern void popDecode();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index 9b06943..d91c3aa 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -54,23 +54,11 @@ Boolean looking = FALSE; /* LOOKING? flag */
int dscrstkp = 0; /* Describe-stack pointer */
-#ifdef _PROTOTYPES_
-void dscrobjs(void);
-void dscracts(void);
-#else
void dscrobjs();
void dscracts();
-#endif
-
-#ifdef _PROTOTYPES_
-void print(Aword fpos, Aword len)
-#else
-void print(fpos, len)
- Aword fpos, len;
-#endif
-{
+void print(Aword fpos, Aword len) {
char str[2*WIDTH]; /* String buffer */
int outlen = 0; /* Current output length */
int ch;
@@ -125,14 +113,7 @@ void print(fpos, len)
}
}
-
-#ifdef _PROTOTYPES_
-void sys(Aword fpos, Aword len)
-#else
-void sys(fpos, len)
- Aword fpos, len;
-#endif
-{
+void sys(Aword fpos, Aword len) {
#ifdef GLK
::error("system calls aren't supported");
#else
@@ -145,14 +126,7 @@ void sys(fpos, len)
#endif
}
-
-#ifdef _PROTOTYPES_
-void getstr(Aword fpos, Aword len)
-#else
-void getstr(fpos, len)
- Aword fpos, len;
-#endif
-{
+void getstr(Aword fpos, Aword len) {
char *buf = (char *)allocate(len+1);
push((Aptr) buf); /* Push the address to the string */
@@ -167,15 +141,7 @@ void getstr(fpos, len)
*buf = '\0';
}
-
-
-#ifdef _PROTOTYPES_
-void score(Aword sc)
-#else
-void score(sc)
- Aword sc;
-#endif
-{
+void score(Aword sc) {
char buf[80];
if (sc == 0) {
@@ -191,24 +157,11 @@ void score(sc)
}
}
-#ifdef _PROTOTYPES_
-void visits(Aword v)
-#else
-void visits(v)
- Aword v;
-#endif
-{
+void visits(Aword v) {
cur.visits = v;
}
-
-#ifdef _PROTOTYPES_
-Boolean confirm(MsgKind msgno)
-#else
-Boolean confirm(msgno)
- MsgKind msgno;
-#endif
-{
+Boolean confirm(MsgKind msgno) {
char buf[80];
/* This is a bit of a hack since we really want to compare the input,
@@ -225,13 +178,7 @@ Boolean confirm(msgno)
return (buf[0] == '\0');
}
-
-#ifdef _PROTOTYPES_
-void quit(void)
-#else
-void quit()
-#endif
-{
+void quit() {
char buf[80];
char choices[10];
@@ -257,14 +204,7 @@ void quit()
syserr("Fallthrough in QUIT");
}
-
-
-#ifdef _PROTOTYPES_
-void restart(void)
-#else
-void restart()
-#endif
-{
+void restart() {
para();
if (confirm(M_REALLY)) {
//longjmp(restart_label, TRUE);
@@ -274,15 +214,7 @@ void restart()
syserr("Fallthrough in RESTART");
}
-
-
-#ifdef _PROTOTYPES_
-void cancl(Aword evt)
-#else
-void cancl(evt)
- Aword evt;
-#endif
-{
+void cancl(Aword evt) {
int i;
for(i = etop-1; i>=0; i--)
@@ -298,14 +230,7 @@ void cancl(evt)
}
}
-
-#ifdef _PROTOTYPES_
-void schedule(Aword evt, Aword whr, Aword aft)
-#else
-void schedule(evt, whr, aft)
- Aword evt, whr, aft;
-#endif
-{ int i;
+void schedule(Aword evt, Aword whr, Aword aft) { int i;
int time;
cancl(evt);
@@ -335,17 +260,10 @@ void schedule(evt, whr, aft)
Get an attribute value from an attribute list
*/
-#ifdef _PROTOTYPES_
static Aptr getatr(
Aaddr atradr, /* IN - ACODE address to attribute table */
Aaddr atr /* IN - The attribute to read */
-)
-#else
-static Aptr getatr(atradr, atr)
- Aaddr atradr; /* IN - ACODE address to attribute table */
- Aaddr atr; /* IN - The attribute to read */
-#endif
-{
+) {
AtrElem *at;
at = (AtrElem *) addrTo(atradr);
@@ -360,19 +278,11 @@ static Aptr getatr(atradr, atr)
Set a particular attribute to a value.
*/
-#ifdef _PROTOTYPES_
static void setatr(
Aaddr atradr, /* IN - ACODE address to attribute table */
Aword atr, /* IN - attribute code */
Aword val /* IN - new value */
-)
-#else
-static void setatr(atradr, atr, val)
- Aaddr atradr; /* IN - ACODE address to attribute table */
- Aword atr; /* IN - attribute code */
- Aword val; /* IN - new value */
-#endif
-{
+) {
AtrElem *at;
at = (AtrElem *) addrTo(atradr);
@@ -386,44 +296,19 @@ static void setatr(atradr, atr, val)
*/
-#ifdef _PROTOTYPES_
-static void makloc(Aword loc, Aword atr, Aword val)
-#else
-static void makloc(loc, atr, val)
- Aword loc, atr, val;
-#endif
-{
+static void makloc(Aword loc, Aword atr, Aword val) {
setatr(locs[loc-LOCMIN].atrs, atr, val);
}
-#ifdef _PROTOTYPES_
-static void makobj(Aword obj, Aword atr, Aword val)
-#else
-static void makobj(obj, atr, val)
- Aword obj, atr, val;
-#endif
-{
+static void makobj(Aword obj, Aword atr, Aword val) {
setatr(objs[obj-OBJMIN].atrs, atr, val);
}
-#ifdef _PROTOTYPES_
-static void makact(Aword act, Aword atr, Aword val)
-#else
-static void makact(act, atr, val)
- Aword act, atr, val;
-#endif
-{
+static void makact(Aword act, Aword atr, Aword val) {
setatr(acts[act-ACTMIN].atrs, atr, val);
}
-
-#ifdef _PROTOTYPES_
-void make(Aword id, Aword atr, Aword val)
-#else
-void make(id, atr, val)
- Aword id, atr, val;
-#endif
-{
+void make(Aword id, Aword atr, Aword val) {
char str[80];
if (isObj(id))
@@ -445,46 +330,20 @@ void make(id, atr, val)
*/
-#ifdef _PROTOTYPES_
-static void setloc(Aword loc, Aword atr, Aword val)
-#else
-static void setloc(loc, atr, val)
- Aword loc, atr, val;
-#endif
-{
+static void setloc(Aword loc, Aword atr, Aword val) {
setatr(locs[loc-LOCMIN].atrs, atr, val);
locs[loc-LOCMIN].describe = 0;
}
-
-#ifdef _PROTOTYPES_
-static void setobj(Aword obj, Aword atr, Aword val)
-#else
-static void setobj(obj, atr, val)
- Aword obj, atr, val;
-#endif
-{
+static void setobj(Aword obj, Aword atr, Aword val) {
setatr(objs[obj-OBJMIN].atrs, atr, val);
}
-#ifdef _PROTOTYPES_
-static void setact(Aword act, Aword atr, Aword val)
-#else
-static void setact(act, atr, val)
- Aword act, atr, val;
-#endif
-{
+static void setact(Aword act, Aword atr, Aword val) {
setatr(acts[act-ACTMIN].atrs, atr, val);
}
-
-#ifdef _PROTOTYPES_
-void set(Aword id, Aword atr, Aword val)
-#else
-void set(id, atr, val)
- Aword id, atr, val;
-#endif
-{
+void set(Aword id, Aword atr, Aword val) {
char str[80];
if (isObj(id))
@@ -499,14 +358,7 @@ void set(id, atr, val)
}
}
-
-#ifdef _PROTOTYPES_
-void setstr(Aword id, Aword atr, Aword str)
-#else
-void setstr(id, atr, str)
- Aword id, atr, str;
-#endif
-{
+void setstr(Aword id, Aword atr, Aword str) {
free((char *)attribute(id, atr));
set(id, atr, str);
}
@@ -526,64 +378,31 @@ void setstr(id, atr, str)
Increment a particular attribute by a value.
*/
-#ifdef _PROTOTYPES_
static void incratr(
Aaddr atradr, /* IN - ACODE address to attribute table */
Aword atr, /* IN - attribute code */
Aword step /* IN - step to increment by */
-)
-#else
-static void incratr(atradr, atr, step)
- Aaddr atradr, atr, step;
-#endif
-{
+) {
AtrElem *at;
at = (AtrElem *) addrTo(atradr);
at[atr-1].val += step;
}
-
-#ifdef _PROTOTYPES_
-static void incrloc(Aword loc, Aword atr, Aword step)
-#else
-static void incrloc(loc, atr, step)
- Aword loc, atr, step;
-#endif
-{
+static void incrloc(Aword loc, Aword atr, Aword step) {
incratr(locs[loc-LOCMIN].atrs, atr, step);
locs[loc-LOCMIN].describe = 0;
}
-
-#ifdef _PROTOTYPES_
-static void incrobj(Aword obj, Aword atr, Aword step)
-#else
-static void incrobj(obj, atr, step)
- Aword obj, atr, step;
-#endif
-{
+static void incrobj(Aword obj, Aword atr, Aword step) {
incratr(objs[obj-OBJMIN].atrs, atr, step);
}
-#ifdef _PROTOTYPES_
-static void incract(Aword act, Aword atr, Aword step)
-#else
-static void incract(act, atr, step)
- Aword act, atr, step;
-#endif
-{
+static void incract(Aword act, Aword atr, Aword step) {
incratr(acts[act-ACTMIN].atrs, atr, step);
}
-
-#ifdef _PROTOTYPES_
-void incr(Aword id, Aword atr, Aword step)
-#else
-void incr(id, atr, step)
- Aword id, atr, step;
-#endif
-{
+void incr(Aword id, Aword atr, Aword step) {
char str[80];
if (isObj(id))
@@ -598,13 +417,7 @@ void incr(id, atr, step)
}
}
-#ifdef _PROTOTYPES_
-void decr(Aword id, Aword atr, Aword step)
-#else
-void decr(id, atr, step)
- Aword id, atr, step;
-#endif
-{
+void decr(Aword id, Aword atr, Aword step) {
char str[80];
if (isObj(id))
@@ -620,52 +433,25 @@ void decr(id, atr, step)
}
-
/*----------------------------------------------------------------------
attribute()
*/
-#ifdef _PROTOTYPES_
-static Aptr locatr(Aword loc, Aword atr)
-#else
-static Aptr locatr(loc, atr)
- Aword loc, atr;
-#endif
-{
+static Aptr locatr(Aword loc, Aword atr) {
return getatr(locs[loc-LOCMIN].atrs, atr);
}
-
-
-#ifdef _PROTOTYPES_
-static Aptr objatr(Aword obj, Aword atr)
-#else
-static Aptr objatr(obj, atr)
- Aword obj, atr;
-#endif
-{
+static Aptr objatr(Aword obj, Aword atr) {
return getatr(objs[obj-OBJMIN].atrs, atr);
}
-#ifdef _PROTOTYPES_
-static Aptr actatr(Aword act, Aword atr)
-#else
-static Aptr actatr(act, atr)
- Aword act, atr;
-#endif
-{
+static Aptr actatr(Aword act, Aword atr) {
return getatr(acts[act-ACTMIN].atrs, atr);
}
-#ifdef _PROTOTYPES_
-static Aptr litatr(Aword lit, Aword atr)
-#else
-static Aptr litatr(lit, atr)
- Aword lit, atr;
-#endif
-{
+static Aptr litatr(Aword lit, Aword atr) {
char str[80];
if (atr == 1)
@@ -677,14 +463,7 @@ static Aptr litatr(lit, atr)
return (Aptr)EOF;
}
-
-#ifdef _PROTOTYPES_
-Aptr attribute(Aword id, Aword atr)
-#else
-Aptr attribute(id, atr)
- Aword id, atr;
-#endif
-{
+Aptr attribute(Aword id, Aword atr) {
char str[80];
if (isObj(id))
@@ -702,14 +481,7 @@ Aptr attribute(id, atr)
return (Aptr)EOF;
}
-
-#ifdef _PROTOTYPES_
-Aptr strattr(Aword id, Aword atr)
-#else
-Aptr strattr(id, atr)
- Aword id, atr;
-#endif
-{
+Aptr strattr(Aword id, Aword atr) {
return (Aptr) strdup((char *)attribute(id, atr));
}
@@ -720,13 +492,7 @@ Aptr strattr(id, atr)
*/
-#ifdef _PROTOTYPES_
-static Aword objloc(Aword obj)
-#else
-static Aword objloc(obj)
- Aword obj;
-#endif
-{
+static Aword objloc(Aword obj) {
if (isCnt(objs[obj-OBJMIN].loc)) /* In something ? */
if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
return(where(objs[obj-OBJMIN].loc));
@@ -736,25 +502,11 @@ static Aword objloc(obj)
return(objs[obj-OBJMIN].loc);
}
-
-#ifdef _PROTOTYPES_
-static Aword actloc(Aword act)
-#else
-static Aword actloc(act)
- Aword act;
-#endif
-{
+static Aword actloc(Aword act) {
return(acts[act-ACTMIN].loc);
}
-
-#ifdef _PROTOTYPES_
-Aword where(Aword id)
-#else
-Aword where(id)
- Aword id;
-#endif
-{
+Aword where(Aword id) {
char str[80];
if (isObj(id))
@@ -769,20 +521,13 @@ Aword where(id)
}
-
/*----------------------------------------------------------------------
aggregates
*/
-#ifdef _PROTOTYPES_
-Aint agrmax(Aword atr, Aword whr)
-#else
-Aint agrmax(atr, whr)
- Aword atr, whr;
-#endif
-{
+Aint agrmax(Aword atr, Aword whr) {
Aword i;
Aint max = 0;
@@ -796,13 +541,7 @@ Aint agrmax(atr, whr)
return(max);
}
-#ifdef _PROTOTYPES_
-Aint agrsum(Aword atr, Aword whr)
-#else
-Aint agrsum(atr, whr)
- Aword atr, whr;
-#endif
-{
+Aint agrsum(Aword atr, Aword whr) {
Aword i;
Aint sum = 0;
@@ -816,14 +555,7 @@ Aint agrsum(atr, whr)
return(sum);
}
-
-#ifdef _PROTOTYPES_
-Aint agrcount(Aword whr)
-#else
-Aint agrcount(whr)
- Aword whr;
-#endif
-{
+Aint agrcount(Aword whr) {
Aword i;
Aword count = 0;
@@ -844,13 +576,7 @@ Aint agrcount(whr)
*/
-#ifdef _PROTOTYPES_
-static void locobj(Aword obj, Aword whr)
-#else
-static void locobj(obj, whr)
- Aword obj, whr;
-#endif
-{
+static void locobj(Aword obj, Aword whr) {
if (isCnt(whr)) { /* Into a container */
if (whr == obj)
syserr("Locating something inside itself.");
@@ -865,14 +591,7 @@ static void locobj(obj, whr)
}
}
-
-#ifdef _PROTOTYPES_
-static void locact(Aword act, Aword whr)
-#else
-static void locact(act, whr)
- Aword act, whr;
-#endif
-{
+static void locact(Aword act, Aword whr) {
Aword prevact = cur.act;
Aword prevloc = cur.loc;
@@ -904,14 +623,7 @@ static void locact(act, whr)
cur.loc = prevloc;
}
-
-#ifdef _PROTOTYPES_
-void locate(Aword id, Aword whr)
-#else
-void locate(id, whr)
- Aword id, whr;
-#endif
-{
+void locate(Aword id, Aword whr) {
char str[80];
if (isObj(id))
@@ -931,13 +643,7 @@ void locate(id, whr)
*/
-#ifdef _PROTOTYPES_
-static Abool objhere(Aword obj)
-#else
-static Abool objhere(obj)
- Aword obj;
-#endif
-{
+static Abool objhere(Aword obj) {
if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
return(isHere(objs[obj-OBJMIN].loc));
@@ -947,25 +653,11 @@ static Abool objhere(obj)
return(objs[obj-OBJMIN].loc == cur.loc);
}
-
-#ifdef _PROTOTYPES_
-static Aword acthere(Aword act)
-#else
-static Aword acthere(act)
- Aword act;
-#endif
-{
+static Aword acthere(Aword act) {
return(acts[act-ACTMIN].loc == cur.loc);
}
-
-#ifdef _PROTOTYPES_
-Abool isHere(Aword id)
-#else
-Abool isHere(id)
- Aword id;
-#endif
-{
+Abool isHere(Aword id) {
char str[80];
if (isObj(id))
@@ -985,13 +677,7 @@ Abool isHere(id)
*/
-#ifdef _PROTOTYPES_
-static Aword objnear(Aword obj)
-#else
-static Aword objnear(obj)
- Aword obj;
-#endif
-{
+static Aword objnear(Aword obj) {
if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
return(isNear(objs[obj-OBJMIN].loc));
@@ -1001,25 +687,11 @@ static Aword objnear(obj)
return(exitto(where(obj), cur.loc));
}
-
-#ifdef _PROTOTYPES_
-static Aword actnear(Aword act)
-#else
-static Aword actnear(act)
- Aword act;
-#endif
-{
+static Aword actnear(Aword act) {
return(exitto(where(act), cur.loc));
}
-
-#ifdef _PROTOTYPES_
-Abool isNear(Aword id)
-#else
-Abool isNear(id)
- Aword id;
-#endif
-{
+Abool isNear(Aword id) {
char str[80];
if (isObj(id))
@@ -1034,21 +706,13 @@ Abool isNear(id)
}
-
/*----------------------------------------------------------------------
in()
*/
-#ifdef _PROTOTYPES_
-Abool in(Aword obj, Aword cnt)
-#else
-Abool in(obj, cnt)
- Aword obj;
- Aword cnt;
-#endif
-{
+Abool in(Aword obj, Aword cnt) {
if (!isObj(obj))
return(FALSE);
if (!isCnt(cnt))
@@ -1064,45 +728,19 @@ Abool in(obj, cnt)
*/
-#ifdef _PROTOTYPES_
-static void sayloc(Aword loc)
-#else
-static void sayloc(loc)
- Aword loc;
-#endif
-{
+static void sayloc(Aword loc) {
interpret(locs[loc-LOCMIN].nams);
}
-
-#ifdef _PROTOTYPES_
-static void sayobj(Aword obj)
-#else
-static void sayobj(obj)
- Aword obj;
-#endif
-{
+static void sayobj(Aword obj) {
interpret(objs[obj-OBJMIN].dscr2);
}
-#ifdef _PROTOTYPES_
-static void sayact(Aword act)
-#else
-static void sayact(act)
- Aword act;
-#endif
-{
+static void sayact(Aword act) {
interpret(acts[act-ACTMIN].nam);
}
-
-#ifdef _PROTOTYPES_
-void sayint(Aword val)
-#else
-void sayint(val)
- Aword val;
-#endif
-{
+void sayint(Aword val) {
char buf[25];
if (isHere(HERO)) {
@@ -1111,27 +749,13 @@ void sayint(val)
}
}
-
-#ifdef _PROTOTYPES_
-void saystr(char *str)
-#else
-void saystr(str)
- char *str;
-#endif
-{
+void saystr(char *str) {
if (isHere(HERO))
output(str);
free(str);
}
-
-#ifdef _PROTOTYPES_
-static void saylit(Aword lit)
-#else
-static void saylit(lit)
- Aword lit;
-#endif
-{
+static void saylit(Aword lit) {
char *str;
if (isNum(lit))
@@ -1142,14 +766,7 @@ static void saylit(lit)
}
}
-
-#ifdef _PROTOTYPES_
-void sayarticle(Aword id)
-#else
-void sayarticle(id)
- Aword id;
-#endif
-{
+void sayarticle(Aword id) {
if (!isObj(id))
syserr("Trying to say article of something *not* an object.");
if (objs[id-OBJMIN].art != 0)
@@ -1158,14 +775,7 @@ void sayarticle(id)
prmsg(M_ARTICLE);
}
-
-#ifdef _PROTOTYPES_
-void say(Aword id)
-#else
-void say(id)
- Aword id;
-#endif
-{
+void say(Aword id) {
char str[80];
if (isHere(HERO)) {
@@ -1191,25 +801,12 @@ void say(id)
*/
-#ifdef _PROTOTYPES_
-static void dscrloc(Aword loc)
-#else
-static void dscrloc(loc)
- Aword loc;
-#endif
-{
+static void dscrloc(Aword loc) {
if (locs[loc-LOCMIN].dscr != 0)
interpret(locs[loc-LOCMIN].dscr);
}
-
-#ifdef _PROTOTYPES_
-static void dscrobj(Aword obj)
-#else
-static void dscrobj(obj)
- Aword obj;
-#endif
-{
+static void dscrobj(Aword obj) {
objs[obj-OBJMIN].describe = FALSE;
if (objs[obj-OBJMIN].dscr1 != 0)
interpret(objs[obj-OBJMIN].dscr1);
@@ -1223,14 +820,7 @@ static void dscrobj(obj)
}
}
-
-#ifdef _PROTOTYPES_
-static void dscract(Aword act)
-#else
-static void dscract(act)
- Aword act;
-#endif
-{
+static void dscract(Aword act) {
ScrElem *scr = NULL;
if (acts[act-ACTMIN].script != 0) {
@@ -1253,13 +843,7 @@ static void dscract(act)
static Aword dscrstk[255];
-#ifdef _PROTOTYPES_
-void describe(Aword id)
-#else
-void describe(id)
- Aword id;
-#endif
-{
+void describe(Aword id) {
int i;
char str[80];
@@ -1289,13 +873,7 @@ void describe(id)
*/
-#ifdef _PROTOTYPES_
-void use(Aword act, Aword scr)
-#else
-void use(act, scr)
- Aword act, scr;
-#endif
-{
+void use(Aword act, Aword scr) {
char str[80];
if (!isAct(act)) {
@@ -1308,20 +886,13 @@ void use(act, scr)
}
-
/*----------------------------------------------------------------------
list()
*/
-#ifdef _PROTOTYPES_
-void list(Aword cnt)
-#else
-void list(cnt)
- Aword cnt;
-#endif
-{
+void list(Aword cnt) {
int i;
Aword props;
Aword prevobj;
@@ -1391,14 +962,7 @@ void list(cnt)
*/
-#ifdef _PROTOTYPES_
-void empty(Aword cnt, Aword whr)
-#else
-void empty(cnt, whr)
- Aword cnt;
- Aword whr;
-#endif
-{
+void empty(Aword cnt, Aword whr) {
int i;
for (i = OBJMIN; i <= OBJMAX; i++)
@@ -1407,7 +971,6 @@ void empty(cnt, whr)
}
-
/*----------------------------------------------------------------------*\
Description of current location
@@ -1418,12 +981,7 @@ void empty(cnt, whr)
\*----------------------------------------------------------------------*/
-#ifdef _PROTOTYPES_
-void dscrobjs(void)
-#else
-void dscrobjs()
-#endif
-{
+void dscrobjs() {
int i;
int prevobj;
Boolean found = FALSE;
@@ -1471,13 +1029,7 @@ void dscrobjs()
objs[i-OBJMIN].describe = TRUE;
}
-
-#ifdef _PROTOTYPES_
-void dscracts(void)
-#else
-void dscracts()
-#endif
-{
+void dscracts() {
int i;
for (i = HERO+1; i <= ACTMAX; i++)
@@ -1490,13 +1042,7 @@ void dscracts()
acts[i-ACTMIN].describe = TRUE;
}
-
-#ifdef _PROTOTYPES_
-void look(void)
-#else
-void look()
-#endif
-{
+void look() {
int i;
if (looking)
@@ -1527,7 +1073,6 @@ needsp = FALSE;
}
-
static char savfnm[256];
@@ -1544,12 +1089,7 @@ void save() {
#else
-#ifdef _PROTOTYPES_
-void save(void)
-#else
-void save()
-#endif
-{
+void save() {
int i;
char str[256];
AtrElem *atr;
@@ -1645,12 +1185,7 @@ void restore() {
#else
-#ifdef _PROTOTYPES_
-void restore(void)
-#else
-void restore()
-#endif
-{
+void restore() {
int i,tmp;
FILE *savfil;
char str[256];
@@ -1748,13 +1283,7 @@ void restore()
*/
-#ifdef _PROTOTYPES_
-Aword rnd(Aword from, Aword to)
-#else
-Aword rnd(from, to)
- Aword from, to;
-#endif
-{
+Aword rnd(Aword from, Aword to) {
if (to == from)
return to;
else if (to > from)
@@ -1771,13 +1300,7 @@ Aword rnd(from, to)
*/
-#ifdef _PROTOTYPES_
-Abool btw(Aint val, Aint low, Aint high)
-#else
-Abool btw(val, low, high)
- Aint val, low, high;
-#endif
-{
+Abool btw(Aint val, Aint low, Aint high) {
if (high > low)
return low <= val && val <= high;
else
@@ -1792,13 +1315,7 @@ Abool btw(val, low, high)
*/
-#ifdef _PROTOTYPES_
-Aword contains(Aptr string, Aptr substring)
-#else
-Aword contains(string, substring)
- Aptr string, substring;;
-#endif
-{
+Aword contains(Aptr string, Aptr substring) {
Abool found;
strlow((char *)string);
@@ -1813,7 +1330,6 @@ Aword contains(string, substring)
}
-
/*----------------------------------------------------------------------
streq()
@@ -1821,13 +1337,7 @@ Aword contains(string, substring)
Compare two strings approximately, ignore case
*/
-#ifdef _PROTOTYPES_
-Abool streq(char a[], char b[])
-#else
-Abool streq(a, b)
- char a[], b[]; /* IN - Strings to compare */
-#endif
-{
+Abool streq(char a[], char b[]) {
Boolean eq;
strlow(a);
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
index fbecac5..1b0e5f9 100644
--- a/engines/glk/alan2/exe.h
+++ b/engines/glk/alan2/exe.h
@@ -37,7 +37,6 @@ extern int etop; /* Event queue top pointer */
extern Boolean looking; /* LOOKING? flag */
extern int dscrstkp; /* Point into describe stack */
-#ifdef _PROTOTYPES_
extern void sys(Aword fpos, Aword len);
extern Boolean confirm(MsgKind msgno);
extern Aptr attribute(Aword item, Aword atr);
@@ -80,49 +79,6 @@ extern Aint agrcount(Aword whr);
extern Abool isHere(Aword item);
extern Abool isNear(Aword item);
-#else
-extern void sys();
-extern Boolean confirm();
-extern Aptr attribute();
-extern void say();
-extern void saynum();
-extern void saystr();
-extern Aptr strattr();
-extern void setstr();
-extern void getstr();
-extern void print();
-extern void look();
-extern void make();
-extern void set();
-extern void incr();
-extern void decr();
-extern void use();
-extern void describe();
-extern void list();
-extern void locate();
-extern void empty();
-extern void score();
-extern void visits();
-extern void schedule();
-extern void cancl();
-extern void quit();
-extern void restart();
-extern void save();
-extern void restore();
-extern void say();
-extern void sayint();
-extern Aword rnd();
-extern Abool btw();
-extern Aword contains()
-extern Abool streq();
-extern Abool in();
-extern Aword where();
-extern Aword agrmax();
-extern Aword agrsum();
-extern Abool isHere();
-extern Abool isNear();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index dd3ee9e..1d52b74 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -42,15 +42,7 @@ namespace Alan2 {
static int pc;
-#ifdef _PROTOTYPES_
-static void if_(
- Aword v
-)
-#else
-static void if_(v)
- Aword v;
-#endif
-{
+static void if_(Aword v) {
int lev = 1;
Aword i;
@@ -75,13 +67,7 @@ static void if_(v)
}
}
-
-#ifdef _PROTOTYPES_
-static void else_(void)
-#else
-static void else_()
-#endif
-{
+static void else_() {
int lev = 1;
Aword i;
@@ -101,25 +87,13 @@ static void else_()
}
}
-
-#ifdef _PROTOTYPES_
-static void depstart(void)
-#else
-static void depstart(void)
-#endif
-{
+static void depstart() {
/* A DEPSTART was executed so skip across the redundant DEPCASE to
start at the first expression */
pc++;
}
-
-#ifdef _PROTOTYPES_
-static void swap(void)
-#else
-static void swap()
-#endif
-{
+static void swap() {
Aptr v1 = pop();
Aptr v2 = pop();
@@ -127,17 +101,7 @@ static void swap()
push(v2);
}
-
-
-#ifdef _PROTOTYPES_
-static void depexec(
- Aword v
-)
-#else
-static void depexec(v)
- Aword v;
-#endif
-{
+static void depexec(Aword v) {
int lev = 1;
Aword i;
@@ -163,13 +127,7 @@ static void depexec(v)
}
}
-
-#ifdef _PROTOTYPES_
-static void depcase(void)
-#else
-static void depcase()
-#endif
-{
+static void depcase() {
int lev = 1;
Aword i;
@@ -192,14 +150,7 @@ static void depcase()
}
}
-
-#ifdef _PROTOTYPES_
-void interpret(Aaddr adr)
-#else
-void interpret(adr)
- Aaddr adr;
-#endif
-{
+void interpret(Aaddr adr) {
Aaddr oldpc;
Aword i;
diff --git a/engines/glk/alan2/inter.h b/engines/glk/alan2/inter.h
index a7fafef..b4ae725 100644
--- a/engines/glk/alan2/inter.h
+++ b/engines/glk/alan2/inter.h
@@ -26,11 +26,7 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
extern void interpret(Aaddr adr);
-#else
-extern void interpret();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 63ab545..7f1aa8d 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -131,13 +131,7 @@ Boolean skipsp = FALSE;
return buffers...
*/
-#ifdef _PROTOTYPES_
-void terminate(int code)
-#else
-void terminate(code)
- int code;
-#endif
-{
+void terminate(int code) {
#ifdef __amiga__
#ifdef AZTEC_C
#include <fcntl.h>
@@ -184,12 +178,7 @@ void terminate(code)
usage()
*/
-#ifdef _PROTOTYPES_
-void usage(void)
-#else
-void usage()
-#endif
-{
+void usage() {
printf("Usage:\n\n");
printf(" %s [<switches>] <adventure>\n\n", PROGNAME);
printf("where the possible optional switches are:\n");
@@ -216,13 +205,7 @@ void usage()
Print a little text blaming the user for the system error.
*/
-#ifdef _PROTOTYPES_
-void syserr(const char *str)
-#else
-void syserr(str)
- char *str;
-#endif
-{
+void syserr(const char *str) {
#ifdef GLK
::error("%s", str);
#else
@@ -261,13 +244,7 @@ of an Adventure that never was.$n$nSYSTEM ERROR: ");
Print an error message, force new player input and abort.
*/
-#ifdef _PROTOTYPES_
-void error(MsgKind msgno) /* IN - The error message number */
-#else
-void error(msgno)
- MsgKind msgno; /* IN - The error message number */
-#endif
-{
+void error(MsgKind msgno /* IN - The error message number */) {
if (msgno != MSGMAX)
prmsg(msgno);
wrds[wrdidx] = EOF; /* Force new player input */
@@ -285,8 +262,7 @@ void error(msgno)
Print the the status line on the top of the screen.
*/
-void statusline(void)
-{
+void statusline() {
#ifdef GLK
uint glkWidth;
char line[100];
@@ -354,15 +330,13 @@ needsp = FALSE;
Print some text and log it if logging is on.
*/
-void logprint(char str[])
-{
+void logprint(char str[]) {
printf(str);
if (logflg)
fprintf(logfil, "%s", str);
}
-
/*======================================================================
newline()
@@ -370,12 +344,7 @@ void logprint(char str[])
Make a newline, but check for screen full.
*/
-#ifdef _PROTOTYPES_
-void newline(void)
-#else
-void newline()
-#endif
-{
+void newline() {
#ifdef GLK
g_vm->glk_put_char('\n');
#else
@@ -409,12 +378,7 @@ void newline()
Make a new paragraph, i.e one empty line (one or two newlines).
*/
-#ifdef _PROTOTYPES_
-void para(void)
-#else
-void para()
-#endif
-{
+void para() {
if (col != 1)
newline();
newline();
@@ -428,12 +392,7 @@ void para()
Clear the screen.
*/
-#ifdef _PROTOTYPES_
-void clear(void)
-#else
-void clear()
-#endif
-{
+void clear() {
#ifdef GLK
g_vm->glk_window_clear(glkMainWin);
#else
@@ -453,13 +412,7 @@ void clear()
Safely allocate new memory.
*/
-#ifdef _PROTOTYPES_
-void *allocate(unsigned long len) /* IN - Length to allocate */
-#else
-void *allocate(len)
- unsigned long len; /* IN - Length to allocate */
-#endif
-{
+void *allocate(unsigned long len /* IN - Length to allocate */) {
void *p = (void *)malloc((size_t)len);
if (p == NULL)
@@ -476,13 +429,7 @@ void *allocate(len)
Justify a string so that it wraps at end of screen.
*/
-#ifdef _PROTOTYPES_
-static void just(char str[])
-#else
-static void just(str)
- char str[];
-#endif
-{
+static void just(char str[]) {
#ifdef GLK
logprint(str);
#else
@@ -524,12 +471,7 @@ static void just(str)
Output a space if needed.
*/
-#ifdef _PROTOTYPES_
-static void space(void)
-#else
-static void space()
-#endif
-{
+static void space() {
if (skipsp)
skipsp = FALSE;
else {
@@ -542,7 +484,6 @@ static void space()
}
-
/*----------------------------------------------------------------------
sayparam()
@@ -551,13 +492,7 @@ static void space()
them if possible.
*/
-#ifdef _PROTOTYPES_
-static void sayparam(int p)
-#else
-static void sayparam(p)
- int p;
-#endif
-{
+static void sayparam(int p) {
int i;
for (i = 0; i <= p; i++)
@@ -591,15 +526,9 @@ static void sayparam(p)
T = tabulation
$ = no space needed after this
*/
-#ifdef _PROTOTYPES_
static void prsym(
- char *str /* IN - The string starting with '$' */
-)
-#else
-static void prsym(str)
- char *str; /* IN - The string starting with '$' */
-#endif
-{
+ char *str /* IN - The string starting with '$' */
+) {
switch (toLower(str[1])) {
case 'n':
newline();
@@ -671,13 +600,7 @@ static void prsym(str)
recogniced and performed.
*/
-#ifdef _PROTOTYPES_
-void output(char original[])
-#else
-void output(original)
- char original[];
-#endif
-{
+void output(char original[]) {
char ch;
char *str, *copy;
char *symptr;
@@ -718,13 +641,7 @@ void output(original)
Print a message from the message table.
*/
-#ifdef _PROTOTYPES_
-void prmsg(MsgKind msg) /* IN - message number */
-#else
-void prmsg(msg)
- MsgKind msg; /* IN - message number */
-#endif
-{
+void prmsg(MsgKind msg /* IN - message number */) {
interpret(msgs[msg].stms);
}
@@ -739,91 +656,41 @@ void prmsg(msg)
\*----------------------------------------------------------------------*/
/* How to know we are at end of a table */
-#ifdef _PROTOTYPES_
-Boolean eot(Aword *adr)
-#else
-Boolean eot(adr)
- Aword *adr;
-#endif
-{
+Boolean eot(Aword *adr) {
return *adr == EOF;
}
-
-#ifdef _PROTOTYPES_
-Boolean isObj(Aword x)
-#else
-Boolean isObj(x)
- Aword x;
-#endif
-{
+Boolean isObj(Aword x) {
return x >= OBJMIN && x <= OBJMAX;
}
-#ifdef _PROTOTYPES_
-Boolean isCnt(Aword x)
-#else
-Boolean isCnt(x)
- Aword x;
-#endif
-{
+Boolean isCnt(Aword x) {
return (x >= CNTMIN && x <= CNTMAX) ||
(isObj(x) && objs[x-OBJMIN].cont != 0) ||
(isAct(x) && acts[x-ACTMIN].cont != 0);
}
-#ifdef _PROTOTYPES_
-Boolean isAct(Aword x)
-#else
-Boolean isAct(x)
- Aword x;
-#endif
-{
+Boolean isAct(Aword x) {
return x >= ACTMIN && x <= ACTMAX;
}
-#ifdef _PROTOTYPES_
-Boolean isLoc(Aword x)
-#else
-Boolean isLoc(x)
- Aword x;
-#endif
-{
+Boolean isLoc(Aword x) {
return x >= LOCMIN && x <= LOCMAX;
}
-#ifdef _PROTOTYPES_
-Boolean isNum(Aword x)
-#else
-Boolean isNum(x)
- Aword x;
-#endif
-{
+Boolean isNum(Aword x) {
return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPNUM;
}
-#ifdef _PROTOTYPES_
-Boolean isStr(Aword x)
-#else
-Boolean isStr(x)
- Aword x;
-#endif
-{
+Boolean isStr(Aword x) {
return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPSTR;
}
-#ifdef _PROTOTYPES_
-Boolean isLit(Aword x)
-#else
-Boolean isLit(x)
- Aword x;
-#endif
-{
+Boolean isLit(Aword x) {
return x >= LITMIN && x <= LITMAX;
}
-
/*======================================================================
exitto()
@@ -831,13 +698,7 @@ Boolean isLit(x)
Is there an exit from one location to another?
*/
-#ifdef _PROTOTYPES_
-Boolean exitto(int to, int from)
-#else
-Boolean exitto(to, from)
- int to, from;
-#endif
-{
+Boolean exitto(int to, int from) {
ExtElem *ext;
if (locs[from-LOCMIN].exts == 0)
@@ -849,8 +710,7 @@ Boolean exitto(to, from)
return(FALSE);
}
-
-
+
#ifdef CHECKOBJ
/*======================================================================
@@ -898,13 +758,7 @@ void checkobj(obj)
Count the number of items in a container.
*/
-#ifdef _PROTOTYPES_
-static int count(int cnt) /* IN - the container to count */
-#else
-static int count(cnt)
- int cnt; /* IN - the container to count */
-#endif
-{
+static int count(int cnt /* IN - the container to count */) {
int i, j = 0;
for (i = OBJMIN; i <= OBJMAX; i++)
@@ -915,24 +769,16 @@ static int count(cnt)
}
-
/*----------------------------------------------------------------------
sumatr()
Sum the values of one attribute in a container. Recursively.
*/
-#ifdef _PROTOTYPES_
static int sumatr(
Aword atr, /* IN - the attribute to sum over */
Aword cnt /* IN - the container to sum */
-)
-#else
-static int sumatr(atr, cnt)
- Aword atr; /* IN - the attribute to sum over */
- Aword cnt; /* IN - the container to sum */
-#endif
-{
+) {
int i;
int sum = 0;
@@ -946,25 +792,16 @@ static int sumatr(atr, cnt)
}
-
-
/*======================================================================
checklim()
Checks if a limit for a container is exceeded.
*/
-#ifdef _PROTOTYPES_
Boolean checklim(
Aword cnt, /* IN - Container code */
Aword obj /* IN - The object to add */
-)
-#else
-Boolean checklim(cnt, obj)
- Aword cnt; /* IN - Container code */
- Aword obj; /* IN - The object to add */
-#endif
-{
+) {
LimElem *lim;
Aword props;
@@ -999,9 +836,6 @@ Boolean checklim(cnt, obj)
}
-
-
-
/*----------------------------------------------------------------------*\
Action routines
@@ -1016,17 +850,10 @@ Boolean checklim(cnt, obj)
Tries a check, returns TRUE if it passed, FALSE else.
*/
-#ifdef _PROTOTYPES_
static Boolean trycheck(
Aaddr adr, /* IN - ACODE address to check table */
Boolean act /* IN - Act if it fails ? */
-)
-#else
-static Boolean trycheck(adr, act)
- Aaddr adr; /* IN - ACODE address to check table */
- Boolean act; /* IN - Act if it fails ? */
-#endif
-{
+) {
ChkElem *chk;
chk = (ChkElem *) addrTo(adr);
@@ -1054,13 +881,7 @@ static Boolean trycheck(adr, act)
Move hero in a direction.
*/
-#ifdef _PROTOTYPES_
-void go(int dir)
-#else
-void go(dir)
- int dir;
-#endif
-{
+void go(int dir) {
ExtElem *ext;
Boolean ok;
Aword oldloc;
@@ -1109,7 +930,6 @@ void go(dir)
}
-
/*----------------------------------------------------------------------
findalt()
@@ -1118,17 +938,10 @@ void go(dir)
the address to it.
*/
-#ifdef _PROTOTYPES_
static AltElem *findalt(
Aword vrbsadr, /* IN - Address to start of list */
Aword param /* IN - Which parameter to match */
-)
-#else
-static AltElem *findalt(vrbsadr, param)
- Aword vrbsadr; /* IN - Address to start of list */
- Aword param; /* IN - Which parameter to match */
-#endif
-{
+) {
VrbElem *vrb;
AltElem *alt;
@@ -1146,8 +959,6 @@ static AltElem *findalt(vrbsadr, param)
}
-
-
/*======================================================================
possible()
@@ -1155,12 +966,7 @@ static AltElem *findalt(vrbsadr, param)
Check if current action is possible according to the CHECKs.
*/
-#ifdef _PROTOTYPES_
-Boolean possible(void)
-#else
-Boolean possible()
-#endif
-{
+Boolean possible() {
AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
int i; /* Parameter index */
@@ -1197,7 +1003,6 @@ Boolean possible()
}
-
/*----------------------------------------------------------------------
do_it()
@@ -1205,12 +1010,7 @@ Boolean possible()
Execute the action commanded by hero.
*/
-#ifdef _PROTOTYPES_
-static void do_it(void)
-#else
-static void do_it()
-#endif
-{
+static void do_it() {
AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
Boolean done[MAXPARAMS+2]; /* Is it done */
int i; /* Parameter index */
@@ -1339,7 +1139,6 @@ static void do_it()
}
-
/*======================================================================
action()
@@ -1348,15 +1147,7 @@ static void do_it()
such as THEM or lists of objects.
*/
-#ifdef _PROTOTYPES_
-void action(
- ParamElem plst[] /* IN - Plural parameter list */
-)
-#else
-void action(plst)
- ParamElem plst[];
-#endif
-{
+void action(ParamElem plst[] /* IN - Plural parameter list */) {
int i, mpos;
char marker[10];
@@ -1380,7 +1171,6 @@ void action(plst)
}
-
/*----------------------------------------------------------------------*\
Event Handling
@@ -1395,12 +1185,7 @@ void action(plst)
Check if any events are pending. If so execute them.
*/
-#ifdef _PROTOTYPES_
-static void eventchk(void)
-#else
-static void eventchk()
-#endif
-{
+static void eventchk() {
while (etop != 0 && eventq[etop-1].time == cur.tick) {
etop--;
if (isLoc(eventq[etop].where))
@@ -1417,9 +1202,6 @@ static void eventchk()
}
-
-
-
/*----------------------------------------------------------------------*\
Main program and initialisation
@@ -1450,13 +1232,7 @@ static char logfnm[256];
checkvers()
*/
-#ifdef _PROTOTYPES_
-static void checkvers(AcdHdr *header)
-#else
-static void checkvers(header)
- AcdHdr *header;
-#endif
-{
+static void checkvers(AcdHdr *header) {
char vers[4];
char state[2];
@@ -1508,12 +1284,7 @@ static void checkvers(header)
load()
*/
-#ifdef _PROTOTYPES_
-static void load(void)
-#else
-static void load()
-#endif
-{
+static void load() {
AcdHdr tmphdr;
Aword crc = 0;
int i;
@@ -1598,12 +1369,7 @@ static void load()
checkdebug()
*/
-#ifdef _PROTOTYPES_
-static void checkdebug(void)
-#else
-static void checkdebug()
-#endif
-{
+static void checkdebug() {
/* Make sure he can't debug if not allowed! */
if (!header->debug) {
if (dbgflg|trcflg|stpflg)
@@ -1628,12 +1394,7 @@ static void checkdebug()
initheader()
*/
-#ifdef _PROTOTYPES_
-static void initheader(void)
-#else
-static void initheader()
-#endif
-{
+static void initheader() {
dict = (WrdElem *) addrTo(header->dict);
/* Find out number of entries in dictionary */
for (dictsize = 0; !endOfTable(&dict[dictsize]); dictsize++);
@@ -1658,12 +1419,7 @@ static void initheader()
initstrings()
*/
-#ifdef _PROTOTYPES_
-static void initstrings(void)
-#else
-static void initstrings()
-#endif
-{
+static void initstrings() {
IniElem *init;
for (init = (IniElem *) addrTo(header->init); !endOfTable(init); init++) {
@@ -1678,12 +1434,7 @@ static void initstrings()
start()
*/
-#ifdef _PROTOTYPES_
-static void start(void)
-#else
-static void start()
-#endif
-{
+static void start() {
int startloc;
cur.tick = -1;
@@ -1707,12 +1458,7 @@ static void start()
Initialization, program load etc.
*/
-#ifdef _PROTOTYPES_
-static void init(void)
-#else
-static void init()
-#endif
-{
+static void init() {
int i;
/* Initialise some status */
@@ -1750,12 +1496,7 @@ static void init()
Let the current actor move. If player, ask him.
*/
-#ifdef _PROTOTYPES_
-static void movactor(void)
-#else
-static void movactor()
-#endif
-{
+static void movactor() {
ScrElem *scr;
StepElem *step;
ActElem *act = (ActElem *) &acts[cur.act-ACTMIN];
@@ -1844,12 +1585,7 @@ static void movactor()
Open the necessary files.
*/
-#ifdef _PROTOTYPES_
-static void openFiles(void)
-#else
-static void openFiles()
-#endif
-{
+static void openFiles() {
char str[256];
char *usr = "";
time_t tick;
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index c72549f..4a47b77 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -97,8 +97,6 @@ extern Boolean needsp;
#define endOfTable(x) eot((Aword *) x)
-
-#ifdef _PROTOTYPES_
extern void *allocate(unsigned long len);
extern void terminate(int code);
extern void usage(void);
@@ -128,29 +126,6 @@ extern Boolean isStr(Aword x);
/* Run the game! */
extern void run(void);
-#else
-extern void *allocate();
-extern void terminate();
-extern void syserr();
-extern void usage();
-extern void error();
-extern void output();
-extern void statusline();
-extern void prmsg();
-extern void print();
-extern void para();
-extern void newline();
-extern Boolean checklim();
-extern Boolean possible();
-extern Boolean eot();
-extern Boolean isObj();
-extern Boolean isCnt();
-extern Boolean isAct();
-extern Boolean isLoc();
-extern Boolean isLit();
-extern void run();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/params.cpp b/engines/glk/alan2/params.cpp
index b885103..e5414bd 100644
--- a/engines/glk/alan2/params.cpp
+++ b/engines/glk/alan2/params.cpp
@@ -27,13 +27,7 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-void compact(ParamElem a[])
-#else
-void compact(a)
- ParamElem a[];
-#endif
-{
+void compact(ParamElem a[]) {
int i, j;
for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
@@ -42,14 +36,7 @@ void compact(a)
a[i].code = (Aword)EOF;
}
-
-#ifdef _PROTOTYPES_
-int lstlen(ParamElem a[])
-#else
-int lstlen(a)
- ParamElem a[];
-#endif
-{
+int lstlen(ParamElem a[]) {
int i = 0;
while (a[i].code != (Aword)EOF)
@@ -57,29 +44,14 @@ int lstlen(a)
return (i);
}
-
-#ifdef _PROTOTYPES_
-Boolean inlst(ParamElem l[], Aword e)
-#else
-Boolean inlst(l, e)
- ParamElem l[];
- Aword e;
-#endif
-{
+Boolean inlst(ParamElem l[], Aword e) {
int i;
for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
return (l[i].code == e);
}
-
-#ifdef _PROTOTYPES_
-void lstcpy(ParamElem a[], ParamElem b[])
-#else
-void lstcpy(a, b)
- ParamElem a[], b[];
-#endif
-{
+void lstcpy(ParamElem a[], ParamElem b[]) {
int i;
for (i = 0; b[i].code != (Aword)EOF; i++)
@@ -87,14 +59,7 @@ void lstcpy(a, b)
a[i].code = (Aword)EOF;
}
-
-#ifdef _PROTOTYPES_
-void sublst(ParamElem a[], ParamElem b[])
-#else
-void sublst(a, b)
- ParamElem a[], b[];
-#endif
-{
+void sublst(ParamElem a[], ParamElem b[]) {
int i;
for (i = 0; a[i].code != (Aword)EOF; i++)
@@ -103,14 +68,7 @@ void sublst(a, b)
compact(a);
}
-
-#ifdef _PROTOTYPES_
-void mrglst(ParamElem a[], ParamElem b[])
-#else
-void mrglst(a, b)
- ParamElem a[], b[];
-#endif
-{
+void mrglst(ParamElem a[], ParamElem b[]) {
int i,last;
for (last = 0; a[last].code != (Aword)EOF; last++); /* Find end of list */
@@ -121,14 +79,7 @@ void mrglst(a, b)
}
}
-
-#ifdef _PROTOTYPES_
-void isect(ParamElem a[], ParamElem b[])
-#else
-void isect(a, b)
- ParamElem a[], b[];
-#endif
-{
+void isect(ParamElem a[], ParamElem b[]) {
int i, last = 0;
for (i = 0; a[i].code != (Aword)EOF; i++)
@@ -137,15 +88,7 @@ void isect(a, b)
a[last].code = (Aword)EOF;
}
-
-#ifdef _PROTOTYPES_
-void cpyrefs(ParamElem p[], Aword r[])
-#else
-void cpyrefs(p, r)
- ParamElem p[];
- Aword r[];
-#endif
-{
+void cpyrefs(ParamElem p[], Aword r[]) {
int i;
for (i = 0; r[i] != (Aword)EOF; i++) {
diff --git a/engines/glk/alan2/params.h b/engines/glk/alan2/params.h
index 82fa84b..88bee5d 100644
--- a/engines/glk/alan2/params.h
+++ b/engines/glk/alan2/params.h
@@ -40,7 +40,6 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
extern void compact(ParamElem *a);
extern int lstlen(ParamElem *a);
extern Boolean inlst(ParamElem *l, Aword e);
@@ -49,16 +48,6 @@ extern void sublst(ParamElem *a, ParamElem *b);
extern void mrglst(ParamElem *a, ParamElem *b);
extern void isect(ParamElem *a, ParamElem *b);
extern void cpyrefs(ParamElem *p, Aword *r);
-#else
-extern void compact();
-extern int lstlen();
-extern Boolean inlst();
-extern void lstcpy();
-extern void sublst();
-extern void mrglst();
-extern void isect();
-extern void cpyrefs();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index 41a4424..a399605 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -97,16 +97,7 @@ static char isobuf[LISTLEN+1]; /* The input buffer in ISO */
static Boolean eol = TRUE; /* Looking at End of line? Yes, initially */
-
-#ifdef _PROTOTYPES_
-static void unknown(
- char token[]
-)
-#else
-static void unknown(token)
- char token[];
-#endif
-{
+static void unknown(char token[]) {
char *str = (char *)allocate((int)strlen(token)+4);
str[0] = '\'';
@@ -122,19 +113,10 @@ static void unknown(token)
}
-
static char *token;
-#ifdef _PROTOTYPES_
-static int lookup(
- char wrd[]
-)
-#else
-static int lookup(wrd)
- char wrd[];
-#endif
-{
+static int lookup(char wrd[]) {
int i;
for (i = 0; !endOfTable(&dict[i]); i++) {
@@ -145,31 +127,14 @@ static int lookup(wrd)
return(EOF);
}
-
-#ifdef _PROTOTYPES_
-static int number(
- char token[] /* IN - The string to convert to a number */
-)
-#else
-static int number(token)
- char token[]; /* IN - The string to convert to a number */
-#endif
-{
+static int number(char token[] /* IN - The string to convert to a number */) {
int i;
sscanf(token, "%d", &i);
return i;
}
-#ifdef _PROTOTYPES_
-static char *gettoken(
- char *buf
-)
-#else
-static char *gettoken(buf)
- char *buf;
-#endif
-{
+static char *gettoken(char *buf) {
static char *marker;
static char oldch;
@@ -196,13 +161,7 @@ static char *gettoken(buf)
return buf;
}
-
-#ifdef _PROTOTYPES_
-static void agetline(void)
-#else
-static void agetline()
-#endif
-{
+static void agetline() {
para();
do {
#if defined(HAVE_ANSI) || defined(GLK)
@@ -249,13 +208,7 @@ static void agetline()
lin = 1;
}
-
-#ifdef _PROTOTYPES_
-static void scan(void)
-#else
-static void scan()
-#endif
-{
+static void scan() {
int i;
int w;
char *str;
@@ -301,7 +254,6 @@ static void scan()
}
-
/*----------------------------------------------------------------------*\
PARSE DATA & PROCEDURES
@@ -321,12 +273,7 @@ static void scan()
static int allLength; /* No. of objects matching 'all' */
-#ifdef _PROTOTYPES_
-static void nonverb(void)
-#else
-static void nonverb()
-#endif
-{
+static void nonverb() {
if (isDir(wrds[wrdidx])) {
wrdidx++;
if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
@@ -339,16 +286,7 @@ static void nonverb()
error(M_WHAT);
}
-
-#ifdef _PROTOTYPES_
-static void buildall(
- ParamElem list[]
-)
-#else
-static void buildall(list)
- ParamElem list[];
-#endif
-{
+static void buildall(ParamElem list[]) {
int o, i = 0;
Boolean found = FALSE;
@@ -364,16 +302,7 @@ static void buildall(list)
list[i].code = EOF;
}
-
-#ifdef _PROTOTYPES_
-static void unambig(
- ParamElem plst[]
-)
-#else
-static void unambig(plst)
- ParamElem plst[];
-#endif
-{
+static void unambig(ParamElem plst[]) {
int i;
Boolean found = FALSE; /* Adjective or noun found ? */
static ParamElem *refs; /* Entities referenced by word */
@@ -477,16 +406,7 @@ static void unambig(plst)
}
}
-
-#ifdef _PROTOTYPES_
-static void simple(
- ParamElem olst[]
-)
-#else
-static void simple(olst)
- ParamElem olst[];
-#endif
-{
+static void simple(ParamElem olst[]) {
static ParamElem *tlst = NULL;
int savidx = wrdidx;
Boolean savplur = FALSE;
@@ -543,15 +463,7 @@ static void simple(olst)
entity tables. Particularly this goes for literals...
*/
-#ifdef _PROTOTYPES_
-static void complex(
- ParamElem olst[]
-)
-#else
-static void complex(olst)
- ParamElem olst[];
-#endif
-{
+static void complex(ParamElem olst[]) {
static ParamElem *alst = NULL;
if (alst == NULL)
@@ -576,16 +488,7 @@ static void complex(olst)
simple(olst); /* Look for simple noun group */
}
-
-#ifdef _PROTOTYPES_
-static Boolean claCheck(
- ClaElem *cla /* IN - The cla elem to check */
-)
-#else
-static Boolean claCheck(cla)
- ClaElem *cla; /* IN - The cla elem to check */
-#endif
-{
+static Boolean claCheck(ClaElem *cla /* IN - The cla elem to check */) {
Boolean ok = FALSE;
if ((cla->classes&(Aword)CLA_OBJ) != 0)
@@ -614,8 +517,7 @@ static Boolean claCheck(cla)
access to remote object), we need to remove non-present parameters
*/
-static void resolve(ParamElem plst[])
-{
+static void resolve(ParamElem plst[]) {
int i;
if (allLength > 0) return; /* ALL has already done this */
@@ -630,16 +532,7 @@ static void resolve(ParamElem plst[])
}
}
-
-#ifdef _PROTOTYPES_
-static void tryMatch(
- ParamElem mlst[] /* OUT - List of params allowed by multiple */
-)
-#else
-static void tryMatch(mlst)
- ParamElem mlst[]; /* OUT - List of params allowed by multiple */
-#endif
-{
+static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multiple */) {
ElmElem *elms; /* Pointer to element list */
StxElem *stx; /* Pointer to syntax list */
ClaElem *cla; /* Pointer to class definitions */
@@ -791,16 +684,7 @@ static void tryMatch(mlst)
plural = anyPlural; /* Remember that we found plural objects */
}
-
-#ifdef _PROTOTYPES_
-static void match(
- ParamElem *mlst /* OUT - List of params allowed by multiple */
-)
-#else
-static void match(mlst)
- ParamElem *mlst; /* OUT - List of params allowed by multiple */
-#endif
-{
+static void match(ParamElem *mlst /* OUT - List of params allowed by multiple */) {
tryMatch(mlst); /* ... to understand what he said */
if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
error(M_WHAT);
@@ -808,13 +692,7 @@ static void match(mlst)
wrdidx++; /* If so skip the AND */
}
-
-#ifdef _PROTOTYPES_
-void parse(void)
-#else
-void parse()
-#endif
-{
+void parse() {
if (mlst == NULL) { /* Allocate large enough paramlists */
mlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
mlst[0].code = EOF;
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
index 067c73f..e2c558c 100644
--- a/engines/glk/alan2/parse.h
+++ b/engines/glk/alan2/parse.h
@@ -39,15 +39,9 @@ extern int litCount;
extern int vrbwrd;
-#ifdef _PROTOTYPES_
-
/* Parse a new player command */
extern void parse(void);
-#else
-extern void parse();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/readline.h b/engines/glk/alan2/readline.h
index a500224..249ccbd 100644
--- a/engines/glk/alan2/readline.h
+++ b/engines/glk/alan2/readline.h
@@ -33,13 +33,8 @@ namespace Alan2 {
#define LINELENGTH 80
#define HISTORYLENGTH 20
-#ifdef _PROTOTYPES_
extern Boolean readline(char usrbuf[]);
-#else
-extern Boolean readline();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/reverse.cpp b/engines/glk/alan2/reverse.cpp
index cf3e851..943411e 100644
--- a/engines/glk/alan2/reverse.cpp
+++ b/engines/glk/alan2/reverse.cpp
@@ -34,13 +34,7 @@ namespace Alan2 {
Return the reversed bytes in the Aword
*/
-#ifdef _PROTOTYPES_
-Aword reversed(Aword w) /* IN - The ACODE word to swap bytes of */
-#else
-Aword reversed(w)
- Aword w; /* IN - The ACODE word to swap bytes of */
-#endif
-{
+Aword reversed(Aword w /* IN - The ACODE word to swap bytes of */) {
Aword s; /* The swapped ACODE word */
char *wp, *sp;
int i;
@@ -54,26 +48,11 @@ Aword reversed(w)
return s;
}
-
-#ifdef _PROTOTYPES_
-void reverse(Aword *w) /* IN - The ACODE word to reverse bytes in */
-#else
-void reverse(w)
- Aword *w; /* IN - The ACODE word to reverse bytes in */
-#endif
-{
+void reverse(Aword *w /* IN - The ACODE word to reverse bytes in */) {
*w = reversed(*w);
}
-
-#ifdef _PROTOTYPES_
-static void reverseTable(Aword adr, int len)
-#else
-static void reverseTable(adr, len)
- Aword adr;
- int len;
-#endif
-{
+static void reverseTable(Aword adr, int len) {
Aword *e = &memory[adr];
int i;
@@ -86,14 +65,7 @@ static void reverseTable(adr, len)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseStms(Aword adr)
-#else
-static void reverseStms(adr)
- Aword adr;
-#endif
-{
+static void reverseStms(Aword adr) {
Aword *e = &memory[adr];
if (adr != 0)
@@ -104,14 +76,7 @@ static void reverseStms(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseMsgs(Aword adr)
-#else
-static void reverseMsgs(adr)
- Aword adr;
-#endif
-{
+static void reverseMsgs(Aword adr) {
MsgElem *e = (MsgElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -123,14 +88,7 @@ static void reverseMsgs(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseWrds(Aword adr)
-#else
-static void reverseWrds(adr)
- Aword adr;
-#endif
-{
+static void reverseWrds(Aword adr) {
WrdElem *e = (WrdElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -145,13 +103,7 @@ static void reverseWrds(adr)
}
}
-#ifdef _PROTOTYPES_
-static void reverseChks(Aword adr)
-#else
-static void reverseChks(adr)
- Aword adr;
-#endif
-{
+static void reverseChks(Aword adr) {
ChkElem *e = (ChkElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -164,13 +116,7 @@ static void reverseChks(adr)
}
}
-#ifdef _PROTOTYPES_
-static void reverseAlts(Aword adr)
-#else
-static void reverseAlts(adr)
- Aword adr;
-#endif
-{
+static void reverseAlts(Aword adr) {
AltElem *e = (AltElem *)&memory[adr];
if (adr != 0 && !endOfTable(e) && !e->done) {
@@ -184,14 +130,7 @@ static void reverseAlts(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseVrbs(Aword adr)
-#else
-static void reverseVrbs(adr)
- Aword adr;
-#endif
-{
+static void reverseVrbs(Aword adr) {
VrbElem *e = (VrbElem *)&memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -203,14 +142,7 @@ static void reverseVrbs(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseSteps(Aword adr)
-#else
-static void reverseSteps(adr)
- Aword adr;
-#endif
-{
+static void reverseSteps(Aword adr) {
StepElem *e = (StepElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -223,14 +155,7 @@ static void reverseSteps(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseScrs(Aword adr)
-#else
-static void reverseScrs(adr)
- Aword adr;
-#endif
-{
+static void reverseScrs(Aword adr) {
ScrElem *e = (ScrElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -243,14 +168,7 @@ static void reverseScrs(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseActs(Aword adr)
-#else
-static void reverseActs(adr)
- Aword adr;
-#endif
-{
+static void reverseActs(Aword adr) {
ActElem *e = (ActElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -266,14 +184,7 @@ static void reverseActs(adr)
}
}
-#ifdef _PROTOTYPES_
-static void reverseObjs(Aword adr, Boolean v2_5)
-#else
-static void reverseObjs(adr, v2_5)
- Aword adr;
- Boolean v2_5; /* TRUE if it's a v2.5 format game */
-#endif
-{
+static void reverseObjs(Aword adr, Boolean v2_5) {
ObjElem *e = (ObjElem *) &memory[adr];
ObjElem25 *e25 = (ObjElem25 *) &memory[adr];
@@ -303,14 +214,7 @@ static void reverseObjs(adr, v2_5)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseExts(Aword adr)
-#else
-static void reverseExts(adr)
- Aword adr;
-#endif
-{
+static void reverseExts(Aword adr) {
ExtElem *e = (ExtElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -325,13 +229,7 @@ static void reverseExts(adr)
}
}
-#ifdef _PROTOTYPES_
-static void reverseLocs(Aword adr)
-#else
-static void reverseLocs(adr)
- Aword adr;
-#endif
-{
+static void reverseLocs(Aword adr) {
LocElem *e = (LocElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -348,14 +246,7 @@ static void reverseLocs(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseClas(Aword adr)
-#else
-static void reverseClas(adr)
- Aword adr;
-#endif
-{
+static void reverseClas(Aword adr) {
ClaElem *e = (ClaElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -369,14 +260,7 @@ static void reverseClas(adr)
reverse(&((Aword *)e)[1]); /* The verb code is stored after the table */
}
-
-#ifdef _PROTOTYPES_
-static void reverseElms(Aword adr)
-#else
-static void reverseElms(adr)
- Aword adr;
-#endif
-{
+static void reverseElms(Aword adr) {
ElmElem *e = (ElmElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -389,14 +273,7 @@ static void reverseElms(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseStxs(Aword adr)
-#else
-static void reverseStxs(adr)
- Aword adr;
-#endif
-{
+static void reverseStxs(Aword adr) {
StxElem *e = (StxElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -408,13 +285,7 @@ static void reverseStxs(adr)
}
}
-#ifdef _PROTOTYPES_
-static void reverseEvts(Aword adr)
-#else
-static void reverseEvts(adr)
- Aword adr;
-#endif
-{
+static void reverseEvts(Aword adr) {
EvtElem *e = (EvtElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -426,15 +297,7 @@ static void reverseEvts(adr)
}
}
-
-
-#ifdef _PROTOTYPES_
-static void reverseLims(Aword adr)
-#else
-static void reverseLims(adr)
- Aword adr;
-#endif
-{
+static void reverseLims(Aword adr) {
LimElem *e = (LimElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -446,14 +309,7 @@ static void reverseLims(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseCnts(Aword adr)
-#else
-static void reverseCnts(adr)
- Aword adr;
-#endif
-{
+static void reverseCnts(Aword adr) {
CntElem *e = (CntElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -468,14 +324,7 @@ static void reverseCnts(adr)
}
}
-
-#ifdef _PROTOTYPES_
-static void reverseRuls(Aword adr)
-#else
-static void reverseRuls(adr)
- Aword adr;
-#endif
-{
+static void reverseRuls(Aword adr) {
RulElem *e = (RulElem *) &memory[adr];
if (adr != 0 && !endOfTable(e)) {
@@ -489,7 +338,6 @@ static void reverseRuls(adr)
}
-
/*----------------------------------------------------------------------
reverseHdr()
@@ -497,13 +345,7 @@ static void reverseRuls(adr)
Reverse the header structure.
*/
-#ifdef _PROTOTYPES_
-void reverseHdr(AcdHdr *hdr)
-#else
-void reverseHdr(hdr)
- AcdHdr *hdr;
-#endif
-{
+void reverseHdr(AcdHdr *hdr) {
int i;
/* Reverse all words in the header except the first (version marking) */
@@ -520,13 +362,7 @@ void reverseHdr(hdr)
makes the .ACD files fully compatible across architectures
*/
-#ifdef _PROTOTYPES_
-void reverseACD(Boolean v2_5)
-#else
-void reverseACD(v2_5)
- Boolean v2_5;
-#endif
-{
+void reverseACD(Boolean v2_5) {
reverseHdr(header);
reverseWrds(header->dict);
reverseTable(header->oatrs, sizeof(AtrElem));
diff --git a/engines/glk/alan2/reverse.h b/engines/glk/alan2/reverse.h
index 40807ce..1f88eb6 100644
--- a/engines/glk/alan2/reverse.h
+++ b/engines/glk/alan2/reverse.h
@@ -26,20 +26,11 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-
extern void reverseHdr(AcdHdr *hdr);
extern void reverseACD(Boolean v25);
extern void reverse(Aword *word);
extern Aword reversed(Aword word);
-#else
-extern void reverseHdr();
-extern void reverseACD();
-extern void reverse();
-extern Aword reversed();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
index d00d1f3..b558b18 100644
--- a/engines/glk/alan2/rules.cpp
+++ b/engines/glk/alan2/rules.cpp
@@ -36,12 +36,7 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-void rules(void)
-#else
-void rules()
-#endif
-{
+void rules() {
Boolean change = TRUE;
int i;
diff --git a/engines/glk/alan2/rules.h b/engines/glk/alan2/rules.h
index 1cc0b90..aaa2596 100644
--- a/engines/glk/alan2/rules.h
+++ b/engines/glk/alan2/rules.h
@@ -30,14 +30,8 @@ namespace Alan2 {
/* TYPES */
-#ifdef _PROTOTYPES_
-
extern void rules(void);
-#else
-extern void rules();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/stack.cpp b/engines/glk/alan2/stack.cpp
index ccce147..98423f0 100644
--- a/engines/glk/alan2/stack.cpp
+++ b/engines/glk/alan2/stack.cpp
@@ -36,37 +36,19 @@ static Aptr stack[STACKSIZE];
static int stackp = 0;
-#ifdef _PROTOTYPES_
-void push(Aptr i)
-#else
-void push(i)
- Aptr i;
-#endif
-{
+void push(Aptr i) {
if (stackp == STACKSIZE)
syserr("Out of stack space.");
stack[stackp++] = i;
}
-
-#ifdef _PROTOTYPES_
-Aptr pop(void)
-#else
-Aptr pop()
-#endif
-{
+Aptr pop() {
if (stackp == 0)
syserr("Stack underflow.");
return(stack[--stackp]);
}
-
-#ifdef _PROTOTYPES_
-Aptr top(void)
-#else
-Aptr top()
-#endif
-{
+Aptr top() {
return(stack[stackp-1]);
}
diff --git a/engines/glk/alan2/stack.h b/engines/glk/alan2/stack.h
index 7f10c08..1a6db74 100644
--- a/engines/glk/alan2/stack.h
+++ b/engines/glk/alan2/stack.h
@@ -30,18 +30,10 @@ namespace Alan2 {
/* TYPES */
-#ifdef _PROTOTYPES_
-
extern Aptr pop(void);
extern void push(Aptr item);
extern Aptr top(void);
-#else
-extern Aptr pop();
-extern void push();
-extern Aptr top();
-#endif
-
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
index d36722c..312518f 100644
--- a/engines/glk/alan2/sysdep.cpp
+++ b/engines/glk/alan2/sysdep.cpp
@@ -41,9 +41,7 @@ extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
}
#endif
-#ifdef _PROTOTYPES_
extern void syserr(char str[]);
-#endif
#ifdef __vms__
diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h
index 5e562cd..e58e538 100644
--- a/engines/glk/alan2/sysdep.h
+++ b/engines/glk/alan2/sysdep.h
@@ -43,7 +43,6 @@ namespace Glk {
namespace Alan2 {
#define GLK
-#define _PROTOTYPES_
#define __win__
#ifdef GLK
@@ -136,21 +135,18 @@ extern void fprintf(Common::WriteStream *ws, const char *fmt, ...);
#endif
#ifdef __STDC__
-#define _PROTOTYPES_
#include <stdlib.h>
#include <string.h>
#endif
#ifdef __vms__
/* Our VAXC doesn't define __STDC__ */
-#define _PROTOTYPES_
#include <stdlib.h>
#include <string.h>
#endif
#ifdef __mac__
-#define _PROTOTYPES_
#include <stdlib.h>
#include <string.h>
#include <unix.h>
@@ -354,8 +350,6 @@ extern char *strdup(char *str);
#endif
-#ifdef _PROTOTYPES_
-
/* Native character functions */
extern int isSpace(int c); /* IN - Native character to test */
extern int isLower(int c); /* IN - Native character to test */
@@ -384,25 +378,6 @@ extern void fromIso(char copy[], /* OUT - Mapped string */
extern void toNative(char copy[], /* OUT - Mapped string */
char original[], /* IN - string to convert */
int charset); /* IN - current character set */
-#else
-extern int isSpace();
-extern int isLower();
-extern int isUpper();
-extern int isLetter();
-extern int toLower();
-extern int toUpper();
-extern char *strlow();
-extern char *strupp();
-
-extern int isISOLetter();
-extern char toLowerCase();
-extern char toUpperCase();
-extern char *stringLower();
-extern char *stringUpper();
-
-extern void toIso();
-extern void fromIso();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/term.cpp b/engines/glk/alan2/term.cpp
index cf60fc5..8f7b64a 100644
--- a/engines/glk/alan2/term.cpp
+++ b/engines/glk/alan2/term.cpp
@@ -34,12 +34,7 @@ namespace Alan2 {
from the header.
*/
-#ifdef _PROTOTYPES_
-void getPageSize(void)
-#else
-void getPageSize()
-#endif
-{
+void getPageSize() {
#ifdef GLK
paglen = 0;
pagwidth = 0;
diff --git a/engines/glk/alan2/term.h b/engines/glk/alan2/term.h
index 339a3b5..7667abd 100644
--- a/engines/glk/alan2/term.h
+++ b/engines/glk/alan2/term.h
@@ -28,13 +28,7 @@
namespace Glk {
namespace Alan2 {
-#ifdef _PROTOTYPES_
-
-extern void getPageSize(void);
-
-#else
extern void getPageSize();
-#endif
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/types.cpp b/engines/glk/alan2/types.cpp
new file mode 100644
index 0000000..8419e33
--- /dev/null
+++ b/engines/glk/alan2/types.cpp
@@ -0,0 +1,45 @@
+/* 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/alan2/types.h"
+
+namespace Glk {
+namespace Alan2 {
+
+void CurVars::synchronize(Common::Serializer &s) {
+ s.syncAsSint32LE(vrb);
+ s.syncAsSint32LE(obj);
+ s.syncAsSint32LE(loc);
+ s.syncAsSint32LE(act);
+ s.syncAsSint32LE(tick);
+ s.syncAsSint32LE(score);
+ s.syncAsSint32LE(visits);
+}
+
+void EvtqElem::synchronize(Common::Serializer &s) {
+ s.syncAsSint32LE(time);
+ s.syncAsSint32LE(event);
+ s.syncAsSint32LE(where);
+};
+
+} // End of namespace Alan2
+} // End of namespace Glk
Commit: dd4108e7c79770ec8235bd4440e0cdc06becd9d9
https://github.com/scummvm/scummvm/commit/dd4108e7c79770ec8235bd4440e0cdc06becd9d9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Removing all the existing system specific ifdef blocks
I'm going to be shortly formatting the code and doing refactoring
to work around the setjmp calls in the original, so there's little
point in keeping the system specific ifdef blocks from the original
Changed paths:
engines/glk/alan2/acode.h
engines/glk/alan2/args.cpp
engines/glk/alan2/args.h
engines/glk/alan2/debug.cpp
engines/glk/alan2/exe.cpp
engines/glk/alan2/inter.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/parse.cpp
engines/glk/alan2/readline.cpp
engines/glk/alan2/rules.cpp
engines/glk/alan2/sysdep.cpp
engines/glk/alan2/sysdep.h
engines/glk/alan2/term.cpp
engines/glk/alan2/types.h
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index ef218dd..8cb3c81 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -36,29 +36,10 @@ typedef uint32 Abool; /* Type for an ACODE Boolean value */
typedef int32 Aint; /* Type for an ACODE Integer value */
typedef int CodeValue; /* Definition for the packing process */
-#ifdef UNUSED
-#if INT_MAX==0x7fffffff
-typedef unsigned int Aword; /* Type for an ACODE word */
-typedef unsigned int Aaddr; /* Type for an ACODE address */
-typedef unsigned int Abool; /* Type for an ACODE Boolean value */
-typedef signed int Aint; /* Type for an ACODE Integer value */
-typedef int CodeValue; /* Definition for the packing process */
-#elif LONG_MAX==0x7fffffff
-typedef unsigned long Aword; /* Type for an ACODE word */
-typedef unsigned long Aaddr; /* Type for an ACODE address */
-typedef unsigned long Abool; /* Type for an ACODE Boolean value */
-typedef signed long Aint; /* Type for an ACODE Integer value */
-typedef long CodeValue; /* Definition for the packing process */
-#else
-#error "Can't find a 32-bit integer type"
-#endif
-#endif
-
/* Constants for the Acode file, words/block & bytes/block */
#define BLOCKLEN 256L
#define BLOCKSIZE (BLOCKLEN*sizeof(Aword))
-
/* Definitions for the packing process */
#define VALUEBITS 16
diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp
index caf32c1..2f760ae 100644
--- a/engines/glk/alan2/args.cpp
+++ b/engines/glk/alan2/args.cpp
@@ -21,208 +21,21 @@
*/
#include <string>
-#ifndef __PACIFIC__
-#include "glk/alan2/args.h"
-#else
-/* I have no idea at all why the include does not work in Pacific C ... */
-extern void args(int argc, char* argv[]);
-#endif
-
-#include "glk/alan2/main.h"
-
-#ifdef __mac__
-#include "glk/alan2/macArgs.h"
-#endif
-
-#ifdef __amiga__
-#include <libraries/dosextens.h>
-#ifdef AZTEC_C
-struct FileHandle *con = NULL;
-#else
-/* Geek Gadgets GCC */
-BPTR window;
-BPTR cd;
-#endif
-#endif
-
-#ifdef GLK
#include "glk/alan2/alan2.h"
+#include "glk/alan2/args.h"
#include "glk/alan2/glkio.h"
+#include "glk/alan2/main.h"
#include "glk/alan2/sysdep.h"
-#endif
namespace Glk {
namespace Alan2 {
static void switches(unsigned argc, char *argv[]) {
-#ifndef GLK
- uint i;
-
- advnam = "";
- for (i = 1; i < argc; i++) {
- if (argv[i][0] == '-') {
-#ifdef GLK
- switch (g_vm->glk_char_to_lower(argv[i][1])) {
-#else
- switch (tolower(argv[i][1])) {
-#endif
- case 'i':
- errflg = FALSE;
- break;
- case 't':
- trcflg = TRUE;
- break;
- case 'd':
- dbgflg = TRUE;
- break;
- case 's':
- trcflg = TRUE;
- stpflg = TRUE;
- break;
- case 'l':
- logflg = TRUE;
- break;
- case 'v':
- verbose = TRUE;
- break;
- case 'n':
- statusflg = FALSE;
- break;
- default:
- printf("Unrecognized switch, -%c\n", argv[i][1]);
- usage();
- terminate(0);
- }
- } else {
- advnam = argv[i];
- if (strcmp(&advnam[strlen(advnam)-4], ".acd") == 0
- || strcmp(&advnam[strlen(advnam)-4], ".ACD") == 0
- || strcmp(&advnam[strlen(advnam)-4], ".dat") == 0
- || strcmp(&advnam[strlen(advnam)-4], ".DAT") == 0)
- advnam[strlen(advnam)-4] = '\0';
- }
- }
-#endif
-}
-
-
-
-#ifdef __amiga__
-
-#include <intuition/intuition.h>
-#include <workbench/workbench.h>
-
-#include <clib/exec_protos.h>
-#include <clib/dos_protos.h>
-#include <clib/icon_protos.h>
-
-#include <fcntl.h>
-
-extern struct Library *IconBase;
-
-#ifndef AZTEC_C
-/* Actually Geek Gadgets GCC with libnix */
-
-/* Aztec C has its own pre-main wbparse which was used in Arun 2.7, with GCC we
- need to do it ourselves. */
-
-#include <clib/intuition_protos.h>
-
-extern unsigned long *__stdfiledes; /* The libnix standard I/O file descriptors */
-
-void
-wb_parse(void)
-{
- char *cp;
- struct DiskObject *dop;
- struct FileHandle *fhp;
-
- if (_WBenchMsg->sm_NumArgs == 1) /* If no argument use program icon/info */
- dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[0].wa_Name);
- else {
- BPTR olddir = CurrentDir(_WBenchMsg->sm_ArgList[1].wa_Lock);
- dop = GetDiskObject((UBYTE *)_WBenchMsg->sm_ArgList[1].wa_Name);
- CurrentDir(olddir);
- }
- if (dop != 0 && (cp = (char *)FindToolType((UBYTE **)dop->do_ToolTypes,
- (UBYTE *)"WINDOW")) != NULL)
- ;
- else /* Could not find a WINDOW tool type */
- cp = "CON:10/10/480/160/Arun:Default Window/CLOSE";
- if ((window = Open((UBYTE *)cp, (long)MODE_OLDFILE))) {
- fhp = (struct FileHandle *) ((long)window << 2);
- SetConsoleTask(fhp->fh_Type);
- SelectInput(window);
- SelectOutput(window);
- __stdfiledes[0] = Input();
- __stdfiledes[1] = Output();
- } else
- exit(-1L);
- FreeDiskObject(dop);
}
-#endif
-#endif
void args(int argc, char * argv[]) {
char *prgnam;
-#ifdef __mac__
-#include <console.h>
-#ifdef __MWERKS__
-#include <SIOUX.h>
-#endif
- short msg, files;
- static char advbuf[256], prgbuf[256];
- /*AppFile af;*/
- OSErr oe;
-
-#ifdef __MWERKS__
- /*SIOUXSettings.setupmenus = FALSE;*/
- SIOUXSettings.autocloseonquit = FALSE;
- SIOUXSettings.asktosaveonclose = FALSE;
- SIOUXSettings.showstatusline = FALSE;
-#endif
-
- GetMacArgs(advbuf);
- advnam = advbuf;
-
-#else
-#ifdef __amiga__
-
- if (argc == 0) { /* If started from Workbench get WbArgs : Aztec C & GG GCC */
- struct WBStartup *WBstart;
-
- if ((IconBase = OpenLibrary("icon.library", 0)) == NULL)
- syserr("Could not open 'icon.library'");
- /* If started from WB normal main is called with argc == 0 and argv = WBstartup message */
- WBstart = (struct WBStartup *)argv;
-#ifndef AZTEC_C
- /* Geek Gadgets GCC */
- wb_parse();
-#endif
- advnam = prgnam = WBstart->sm_ArgList[0].wa_Name;
- if (WBstart->sm_NumArgs > 0) {
- cd = CurrentDir(DupLock(WBstart->sm_ArgList[1].wa_Lock));
- advnam = WBstart->sm_ArgList[1].wa_Name;
- }
- /* Possibly other tooltypes ... */
- } else {
- /* Started from a CLI */
- if ((prgnam = strrchr(argv[0], '/')) == NULL
- && (prgnam = strrchr(argv[0], ':')) == NULL)
- prgnam = argv[0];
- else
- prgnam++;
- /* Now look at the switches and arguments */
- switches(argc, argv);
- if (advnam[0] == '\0')
- /* No game given, try program name */
- if (stricmp(prgnam, PROGNAME) != 0
- && strstr(prgnam, PROGNAME) == 0)
- advnam = strdup(argv[0]);
- }
-#else
-#if defined(__dos__) || defined(__win__)
if ((prgnam = strrchr(argv[0], '\\')) == NULL
&& (prgnam = strrchr(argv[0], '/')) == NULL
&& (prgnam = strrchr(argv[0], ':')) == NULL)
@@ -240,49 +53,6 @@ void args(int argc, char * argv[]) {
if (stricmp(prgnam, PROGNAME) != 0
&& strstr(prgnam, PROGNAME) == 0)
advnam = strdup(argv[0]);
-#else
-#if defined __vms__
- if ((prgnam = strrchr(argv[0], ']')) == NULL
- && (prgnam = strrchr(argv[0], '>')) == NULL
- && (prgnam = strrchr(argv[0], ':')) == NULL)
- prgnam = argv[0];
- else
- prgnam++;
- if (strrchr(prgnam, ';') != NULL)
- *strrchr(prgnam, ';') = '\0';
- if (strlen(prgnam) > 4
- && (strcmp(&prgnam[strlen(prgnam)-4], ".EXE") == 0
- || strcmp(&prgnam[strlen(prgnam)-4], ".exe") == 0))
- prgnam[strlen(prgnam)-4] = '\0';
- /* Now look at the switches and arguments */
- switches(argc, argv);
- if (advnam[0] == '\0')
- /* No game given, try program name */
- if (strcmp(prgnam, PROGNAME) != 0
- && strstr(prgnam, PROGNAME) == 0)
- advnam = strdup(argv[0]);
-#else
-#if defined(__unix__) || defined(__APPLE__)
- if ((prgnam = strrchr(argv[0], '/')) == NULL)
- prgnam = strdup(argv[0]);
- else
- prgnam = strdup(&prgnam[1]);
- if (strrchr(prgnam, ';') != NULL)
- *strrchr(prgnam, ';') = '\0';
- /* Now look at the switches and arguments */
- switches(argc, argv);
- if (advnam[0] == '\0')
- /* No game given, try program name */
- if (strcmp(prgnam, PROGNAME) != 0
- && strstr(prgnam, PROGNAME) == 0)
- advnam = strdup(argv[0]);
-#else
- Unimplemented OS!
-#endif
-#endif
-#endif
-#endif
-#endif
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/args.h b/engines/glk/alan2/args.h
index dc2f088..6eb3245 100644
--- a/engines/glk/alan2/args.h
+++ b/engines/glk/alan2/args.h
@@ -34,9 +34,7 @@
namespace Glk {
namespace Alan2 {
-#ifndef PROGNAME
#define PROGNAME "alan2"
-#endif
extern void args(int argc, char *argv[]);
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index 785cd54..3c67fbe 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -21,26 +21,15 @@
*/
#include "glk/alan2/types.h"
-#ifdef HAVE_SHORT_FILENAMES
-#include "glk/alan2/av.h"
-#else
#include "glk/alan2/alan_version.h"
-#endif
-
-#ifdef USE_READLINE
-#include "glk/alan2/readline.h"
-#endif
-
+#include "glk/alan2/debug.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/glkio.h"
#include "glk/alan2/inter.h"
#include "glk/alan2/main.h"
#include "glk/alan2/parse.h"
-#include "glk/alan2/exe.h"
-
-#include "glk/alan2/debug.h"
+#include "glk/alan2/readline.h"
-#ifdef GLK
-#include "glk/alan2/glkio.h"
-#endif
namespace Glk {
namespace Alan2 {
@@ -55,9 +44,6 @@ static void showatrs(Aword atradr) {
i = 1;
for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) {
sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr));
-#if ISO == 0
- fromIso(str, str);
-#endif
output(str);
i++;
}
@@ -258,9 +244,6 @@ static void showevts() {
output("EVENTS:");
for (evt = EVTMIN; evt <= EVTMAX; evt++) {
sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt-EVTMIN].stradr));
-#if ISO == 0
- fromIso(str, str);
-#endif
output(str);
scheduled = FALSE;
for (i = 0; i < etop; i++)
@@ -304,11 +287,8 @@ void debug() {
para();
do {
output("ABUG> ");
-#ifdef USE_READLINE
- (void) readline(buf);
-#else
- fgets(buf, 255, stdin);
-#endif
+ (void)readline(buf);
+
lin = 1;
c = buf[0];
i = 0;
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index d91c3aa..3cd16d8 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -20,21 +20,16 @@
*
*/
-#include "glk/alan2/types.h"
#include "glk/alan2/alan2.h"
-
-#ifdef USE_READLINE
-#include "glk/alan2/readline.h"
-#endif
-
+#include "glk/alan2/types.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/inter.h"
#include "glk/alan2/main.h"
#include "glk/alan2/parse.h"
-#include "glk/alan2/inter.h"
+#include "glk/alan2/readline.h"
#include "glk/alan2/stack.h"
#include "glk/alan2/decode.h"
-#include "glk/alan2/exe.h"
-
namespace Glk {
namespace Alan2 {
@@ -97,9 +92,6 @@ void print(Aword fpos, Aword len) {
str[i] = ch;
}
str[i] = '\0';
-#if ISO == 0
- fromIso(str, str);
-#endif
output(str);
}
/* And restore */
@@ -168,11 +160,7 @@ Boolean confirm(MsgKind msgno) {
it could be affirmative, but for now any input is NOT! */
prmsg(msgno);
-#ifdef USE_READLINE
if (!readline(buf)) return TRUE;
-#else
- if (gets(buf) == NULL) return TRUE;
-#endif
col = 1;
return (buf[0] == '\0');
@@ -187,11 +175,8 @@ void quit() {
col = 1;
statusline();
prmsg(M_QUITACTION);
-#ifdef USE_READLINE
if (!readline(buf)) terminate(0);
-#else
- if (gets(buf) == NULL) terminate(0);
-#endif
+
if (strcmp(buf, "restart") == 0)
//longjmp(restart_label, TRUE);
::error("TODO: restart");
@@ -1082,95 +1067,10 @@ static char savfnm[256];
*/
-#ifdef GARGLK
void save() {
g_vm->saveGame();
}
-#else
-
-void save() {
- int i;
- char str[256];
- AtrElem *atr;
- FILE *savfil;
-
- /* First save ? */
- if (savfnm[0] == '\0') {
- strcpy(savfnm, advnam);
- strcat(savfnm, ".sav");
- }
- prmsg(M_SAVEWHERE);
- sprintf(str, "(%s) : ", savfnm);
- output(str);
-
-#ifdef USE_READLINE
- readline(str);
-#else
- gets(str);
-#endif
-
-frefid_t fref;
-fref = g_vm->glk_fileref_create_by_prompt(fileusage_SavedGame, filemode_Write, 0);
-if (fref == NULL)
- error(M_SAVEFAILED);
-strcpy(str, g_vm->garglk_fileref_get_name(fref));
-g_vm->glk_fileref_destroy(fref);
-
- if (str[0] == '\0')
- strcpy(str, savfnm);
- col = 1;
- if ((savfil = fopen(str, READ_MODE)) != NULL)
- /* It already existed */
- if (!confirm(M_SAVEOVERWRITE))
- error(MSGMAX); /* Return to player without saying anything */
- if ((savfil = fopen(str, WRITE_MODE)) == NULL)
- error(M_SAVEFAILED);
- strcpy(savfnm, str);
-
- /* Save version of interpreter and name of game */
- fwrite((void *)&header->vers, sizeof(Aword), 1, savfil);
- fwrite((void *)advnam, strlen(advnam)+1, 1, savfil);
- /* Save current values */
- fwrite((void *)&cur, sizeof(cur), 1, savfil);
- /* Save actors */
- for (i = ACTMIN; i <= ACTMAX; i++) {
- fwrite((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil);
- fwrite((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil);
- fwrite((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil);
- fwrite((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil);
- if (acts[i-ACTMIN].atrs)
- for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++)
- fwrite((void *)&atr->val, sizeof(Aword), 1, savfil);
- }
-
- /* Save locations */
- for (i = LOCMIN; i <= LOCMAX; i++) {
- fwrite((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil);
- if (locs[i-LOCMIN].atrs)
- for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
- fwrite((void *)&atr->val, sizeof(Aword), 1, savfil);
- }
-
- /* Save objects */
- for (i = OBJMIN; i <= OBJMAX; i++) {
- fwrite((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil);
- if (objs[i-OBJMIN].atrs)
- for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
- fwrite((void *)&atr->val, sizeof(atr->val), 1, savfil);
- }
-
- /* Save the event queue */
- eventq[etop].time = 0; /* Mark the top */
- fwrite((void *)&eventq[0], sizeof(eventq[0]), etop+1, savfil);
-
- /* Save scores */
- for (i = 0; scores[i] != EOF; i++)
- fwrite((void *)&scores[i], sizeof(Aword), 1, savfil);
-
- fclose(savfil);
-}
-#endif
/*----------------------------------------------------------------------
@@ -1178,104 +1078,10 @@ g_vm->glk_fileref_destroy(fref);
*/
-#ifdef GARGLK
void restore() {
g_vm->loadGame();
}
-#else
-
-void restore() {
- int i,tmp;
- FILE *savfil;
- char str[256];
- AtrElem *atr;
- char savedVersion[4];
- char savedName[256];
-
- /* First save ? */
- if (savfnm[0] == '\0') {
- strcpy(savfnm, advnam);
- strcat(savfnm, ".sav");
- }
- prmsg(M_RESTOREFROM);
- sprintf(str, "(%s) : ", savfnm);
- output(str);
-#ifdef USE_READLINE
- readline(str);
-#else
- gets(str);
-#endif
-
- if (str[0] == '\0')
- strcpy(str, savfnm);
- col = 1;
- if (str[0] == '\0')
- strcpy(str, savfnm); /* Use the name temporarily */
- if ((savfil = fopen(str, READ_MODE)) == NULL)
- error(M_SAVEMISSING);
- strcpy(savfnm, str); /* Save it for future use */
-
- tmp = fread((void *)&savedVersion, sizeof(Aword), 1, savfil);
- /* 4f - save file version check doesn't seem to work on PC's! */
- if (strncmp(savedVersion, header->vers, 4)) {
- fclose(savfil);
- error(M_SAVEVERS);
- return;
- }
- i = 0;
- while ((savedName[i++] = fgetc(savfil)) != '\0');
- if (strcmp(savedName, advnam) != 0) {
- fclose(savfil);
- error(M_SAVENAME);
- return;
- }
-
- /* Restore current values */
- tmp = fread((void *)&cur, sizeof(cur), 1, savfil);
- /* Restore actors */
- for (i = ACTMIN; i <= ACTMAX; i++) {
- tmp = fread((void *)&acts[i-ACTMIN].loc, sizeof(Aword), 1, savfil);
- tmp = fread((void *)&acts[i-ACTMIN].script, sizeof(Aword), 1, savfil);
- tmp = fread((void *)&acts[i-ACTMIN].step, sizeof(Aword), 1, savfil);
- tmp = fread((void *)&acts[i-ACTMIN].count, sizeof(Aword), 1, savfil);
- if (acts[i-ACTMIN].atrs)
- for (atr = (AtrElem *) addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); atr++)
- tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil);
- }
-
- /* Restore locations */
- for (i = LOCMIN; i <= LOCMAX; i++) {
- tmp = fread((void *)&locs[i-LOCMIN].describe, sizeof(Aword), 1, savfil);
- if (locs[i-LOCMIN].atrs)
- for (atr = (AtrElem *) addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
- tmp = fread((void *)&atr->val, sizeof(Aword), 1, savfil);
- }
-
- /* Restore objects */
- for (i = OBJMIN; i <= OBJMAX; i++) {
- tmp = fread((void *)&objs[i-OBJMIN].loc, sizeof(Aword), 1, savfil);
- if (objs[i-OBJMIN].atrs)
- for (atr = (AtrElem *) addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
- tmp = fread((void *)&atr->val, sizeof(atr->val), 1, savfil);
- }
-
- /* Restore the eventq */
- etop = 0;
- do {
- tmp = fread((void *)&eventq[etop], sizeof(eventq[0]), 1, savfil);
- etop++;
- } while (eventq[etop-1].time != 0);
- etop--;
-
- /* Restore scores */
- for (i = 0; scores[i] != EOF; i++)
- tmp = fread((void *)&scores[i], sizeof(Aword), 1, savfil);
-
- fclose(savfil);
-}
-
-#endif
/*----------------------------------------------------------------------
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 1d52b74..5e2827f 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -22,18 +22,14 @@
#include <string>
#include "glk/alan2/types.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/glkio.h"
#include "glk/alan2/main.h"
#include "glk/alan2/parse.h"
-#include "glk/alan2/exe.h"
#include "glk/alan2/stack.h"
#include "glk/alan2/sysdep.h"
-#include "glk/alan2/inter.h"
-
-#ifdef GLK
-#include "glk/alan2/glkio.h"
-#endif
-
namespace Glk {
namespace Alan2 {
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 7f1aa8d..6b06e0b 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -22,39 +22,22 @@
#define V27COMPATIBLE
-#include "glk/alan2/sysdep.h"
-
-#include "glk/alan2/types.h"
-#include "glk/alan2/main.h"
-
-//#include <time.h>
-#ifdef USE_READLINE
-#include "glk/alan2/readline.h"
-#endif
-
-#ifdef HAVE_SHORT_FILENAMES
-#include "glk/alan2/av.h"
-#else
+#include "glk/alan2/alan2.h"
#include "glk/alan2/alan_version.h"
-#endif
-
#include "glk/alan2/args.h"
-#include "glk/alan2/parse.h"
+#include "glk/alan2/debug.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/glkio.h"
#include "glk/alan2/inter.h"
-#include "glk/alan2/rules.h"
-#ifdef REVERSED
+#include "glk/alan2/main.h"
+#include "glk/alan2/parse.h"
#include "glk/alan2/reverse.h"
-#endif
-#include "glk/alan2/debug.h"
+#include "glk/alan2/rules.h"
#include "glk/alan2/stack.h"
-#include "glk/alan2/exe.h"
+#include "glk/alan2/sysdep.h"
+#include "glk/alan2/types.h"
#include "glk/alan2/term.h"
-
-#ifdef GLK
#include "common/file.h"
-#include "glk/alan2/alan2.h"
-#include "glk/alan2/glkio.h"
-#endif
namespace Glk {
namespace Alan2 {
@@ -132,45 +115,12 @@ Boolean skipsp = FALSE;
*/
void terminate(int code) {
-#ifdef __amiga__
-#ifdef AZTEC_C
-#include <fcntl.h>
- extern struct _dev *_devtab;
- char buf[85];
-
- if (con) { /* Running from WB, created a console so kill it */
- /* Running from WB, so we created a console and
- hacked the Aztec C device table to use it for all I/O
- so now we need to make it close it (once!) */
- _devtab[1].fd = _devtab[2].fd = 0;
- } else
-#else
- /* Geek Gadgets GCC */
-#include <workbench/startup.h>
-#include <clib/dos_protos.h>
-#include <clib/intuition_protos.h>
-
- if (_WBenchMsg != NULL) {
- Close(window);
- if (_WBenchMsg->sm_ArgList != NULL)
- UnLock(CurrentDir(cd));
- } else
-#endif
-#endif
newline();
free(memory);
if (logflg)
fclose(logfil);
-#ifdef __MWERKS__
- printf("Command-Q to close window.");
-#endif
-
-#ifdef GLK
g_vm->glk_exit();
-#else
- exit(code);
-#endif
}
/*======================================================================
@@ -182,9 +132,8 @@ void usage() {
printf("Usage:\n\n");
printf(" %s [<switches>] <adventure>\n\n", PROGNAME);
printf("where the possible optional switches are:\n");
-#ifdef GLK
g_vm->glk_set_style(style_Preformatted);
-#endif
+
printf(" -v verbose mode\n");
printf(" -l log player commands and game output to a file\n");
printf(" -i ignore version and checksum errors\n");
@@ -192,9 +141,7 @@ void usage() {
printf(" -d enter debug mode\n");
printf(" -t trace game execution\n");
printf(" -s single instruction trace\n");
-#ifdef GLK
g_vm->glk_set_style(style_Normal);
-#endif
}
@@ -206,34 +153,7 @@ void usage() {
*/
void syserr(const char *str) {
-#ifdef GLK
::error("%s", str);
-#else
- 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$nSYSTEM ERROR: ");
- output(str);
- output("$n$n");
-
- if (logflg)
- fclose(logfil);
- newline();
-
-#ifdef __amiga__
-#ifdef AZTEC_C
- {
- char buf[80];
-
- if (con) { /* Running from WB, wait for user ack. */
- printf("press RETURN to quit");
- gets(buf);
- }
- }
-#endif
-#endif
-
- terminate(0);
-#endif
}
@@ -263,7 +183,6 @@ void error(MsgKind msgno /* IN - The error message number */) {
*/
void statusline() {
-#ifdef GLK
uint glkWidth;
char line[100];
int pcol = col;
@@ -295,31 +214,6 @@ needsp = FALSE;
col = pcol;
g_vm->glk_set_window(glkMainWin);
-#else
-#ifdef HAVE_ANSI
- char line[100];
- int i;
- int pcol = col;
-
- if (!statusflg) return;
- /* ansi_position(1,1); ansi_bold_on(); */
- printf("\x1b[1;1H");
- printf("\x1b[7m");
- col = 1;
- say(where(HERO));
- if (header->maxscore > 0)
- sprintf(line, "Score %ld(%ld)/%ld moves", cur.score, (int)header->maxscore, cur.tick);
- else
- sprintf(line, "%ld moves", cur.tick);
- for (i=0; i < pagwidth - col - strlen(line); i++) putchar(' ');
- printf(line);
- printf("\x1b[m");
- printf("\x1b[%d;1H", paglen);
- needsp = FALSE;
-
- col = pcol;
-#endif
-#endif
}
@@ -345,29 +239,7 @@ void logprint(char str[]) {
*/
void newline() {
-#ifdef GLK
g_vm->glk_put_char('\n');
-#else
- char buf[256];
-
- col = 1;
- if (lin >= paglen - 1) {
- logprint("\n");
- needsp = FALSE;
- prmsg(M_MORE);
-#ifdef USE_READLINE
- (void) readline(buf);
-#else
- fgets(buf, 256, stdin);
-#endif
- getPageSize();
- lin = 0;
- } else
- logprint("\n");
-
- lin++;
- needsp = FALSE;
-#endif
}
@@ -393,15 +265,7 @@ void para() {
*/
void clear() {
-#ifdef GLK
g_vm->glk_window_clear(glkMainWin);
-#else
-#ifdef HAVE_ANSI
- if (!statusflg) return;
- printf("\x1b[2J");
- printf("\x1b[%d;1H", paglen);
-#endif
-#endif
}
@@ -430,37 +294,7 @@ void *allocate(unsigned long len /* IN - Length to allocate */) {
*/
static void just(char str[]) {
-#ifdef GLK
logprint(str);
-#else
- int i;
- char ch;
-
- if (col >= pagwidth && !skipsp)
- newline();
-
- while (strlen(str) > pagwidth - col) {
- i = pagwidth - col - 1;
- while (!isSpace(str[i]) && i > 0) /* First find wrap point */
- i--;
- if (i == 0 && col == 1) /* If it doesn't fit at all */
- /* Wrap immediately after this word */
- while (!isSpace(str[i]) && str[i] != '\0')
- i++;
- if (i > 0) { /* If it fits ... */
- ch = str[i]; /* Save space or NULL */
- str[i] = '\0'; /* Terminate string */
- logprint(str); /* and print it */
- skipsp = FALSE; /* If skipping, now we're done */
- str[i] = ch; /* Restore character */
- /* Skip white after printed portion */
- for (str = &str[i]; isSpace(str[0]) && str[0] != '\0'; str++);
- }
- newline(); /* Then start a new line */
- }
- logprint(str); /* Print tail */
- col = col + strlen(str); /* Update column */
-#endif
}
@@ -712,46 +546,6 @@ Boolean exitto(int to, int from) {
}
-#ifdef CHECKOBJ
-/*======================================================================
-
- checkobj()
-
- Check that the object given is valid, else print an error message
- or find out what he wanted.
-
- This routine is not used any longer, kept for sentimental reasons ;-)
-
- */
-void checkobj(obj)
- Aword *obj;
-{
- Aword oldobj;
-
- if (*obj != EOF)
- return;
-
- oldobj = EOF;
- for (cur.obj = OBJMIN; cur.obj <= OBJMAX; cur.obj++) {
- /* If an object is present and it is possible to perform his action */
- if (isHere(cur.obj) && possible())
- if (oldobj == EOF)
- oldobj = cur.obj;
- else
- error(WANT); /* And we didn't find multiple objects */
- }
-
- if (oldobj == EOF)
- error(WANT); /* But we found ONE */
-
- *obj = cur.obj = oldobj;
- output("($o)"); /* Then he surely meant this object */
-}
-#endif
-
-
-
-
/*----------------------------------------------------------------------
count()
@@ -1326,9 +1120,6 @@ static void load() {
crc += (memory[i]>>8)&0xff;
crc += (memory[i]>>16)&0xff;
crc += (memory[i]>>24)&0xff;
-#ifdef CRCLOG
- printf("%6x\t%6lx\t%6lx\n", i, crc, memory[i]);
-#endif
}
if (crc != tmphdr.acdcrc) {
sprintf(err, "Checksum error in .ACD file (0x%lx instead of 0x%lx).",
@@ -1379,13 +1170,6 @@ static void checkdebug() {
trcflg = FALSE;
stpflg = FALSE;
}
-
-#ifndef GLK
- if (dbgflg) /* If debugging */
- srand(0); /* use no randomization */
- else
- srand(time(0)); /* seed random generator */
-#endif
}
@@ -1590,26 +1374,11 @@ static void openFiles() {
char *usr = "";
time_t tick;
-#ifndef GLK
- /* Open Acode file */
- strcpy(codfnm, advnam);
- strcat(codfnm, ".acd");
-
- if ((codfil = fopen(codfnm, READ_MODE)) == NULL) {
- strcpy(str, "Can't open adventure code file '");
- strcat(str, codfnm);
- strcat(str, "'.");
- syserr(str);
- }
-#endif
-
-#ifdef GARGLK
{
char *s = strrchr(codfnm, '\\');
if (!s) s = strrchr(codfnm, '/');
g_vm->garglk_set_story_name(s ? s + 1 : codfnm);
}
-#endif
/* Open Text file */
strcpy(txtfnm, advnam);
@@ -1650,9 +1419,6 @@ void run() {
init(); /* Load, initialise and start the adventure */
while (TRUE) {
-#ifdef MALLOC
- if (malloc_verify() == 0) syserr("Error in heap.");
-#endif
if (dbgflg)
debug();
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index a399605..d83755b 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -22,24 +22,16 @@
#include <string>
#include "glk/alan2/alan2.h"
-#include "glk/alan2/types.h"
-
-#ifdef USE_READLINE
-#include "glk/alan2/readline.h"
-#endif
-
-#include "glk/alan2/main.h"
-#include "glk/alan2/inter.h"
-#include "glk/alan2/exe.h"
-#include "glk/alan2/term.h"
#include "glk/alan2/debug.h"
+#include "glk/alan2/exe.h"
+#include "glk/alan2/glkio.h"
+#include "glk/alan2/inter.h"
+#include "glk/alan2/main.h"
#include "glk/alan2/params.h"
-
#include "glk/alan2/parse.h"
-
-#ifdef GLK
-#include "glk/alan2/glkio.h"
-#endif
+#include "glk/alan2/readline.h"
+#include "glk/alan2/term.h"
+#include "glk/alan2/types.h"
namespace Glk {
namespace Alan2 {
@@ -103,9 +95,6 @@ static void unknown(char token[]) {
str[0] = '\'';
strcpy(&str[1], token);
strcat(str, "'?");
-#if ISO == 0
- fromIso(str, str);
-#endif
output(str);
free(str);
eol = TRUE;
@@ -164,13 +153,12 @@ static char *gettoken(char *buf) {
static void agetline() {
para();
do {
-#if defined(HAVE_ANSI) || defined(GLK)
statusline();
-#endif
+
printf("> ");
if (logflg)
fprintf(logfil, "> ");
-#ifdef USE_READLINE
+
if (!readline(buf)) {
if (g_vm->shouldQuit())
return;
@@ -178,25 +166,13 @@ static void agetline() {
newline();
quit();
}
-#else
- if (fgets(buf, LISTLEN, stdin) == NULL) {
- newline();
- quit();
- }
-#endif
+
getPageSize();
anyOutput = FALSE;
if (logflg)
-#ifndef __amiga__
fprintf(logfil, "%s\n", buf);
-#else
- fprintf(logfil, "%s", buf);
-#endif
-#if ISO == 0
- toIso(isobuf, buf, NATIVECHARSET);
-#else
strcpy(isobuf, buf);
-#endif
+
token = gettoken(isobuf);
if (token != NULL && strcmp("debug", token) == 0 && header->debug) {
dbgflg = TRUE;
diff --git a/engines/glk/alan2/readline.cpp b/engines/glk/alan2/readline.cpp
index 5f1192d..7569721 100644
--- a/engines/glk/alan2/readline.cpp
+++ b/engines/glk/alan2/readline.cpp
@@ -20,14 +20,11 @@
*
*/
-#include "glk/alan2/types.h"
-
-#ifdef GLK
-
#include "glk/alan2/alan2.h"
-#include "glk/alan2/readline.h"
-#include "glk/alan2/main.h"
+#include "glk/alan2/types.h"
#include "glk/alan2/glkio.h"
+#include "glk/alan2/main.h"
+#include "glk/alan2/readline.h"
namespace Glk {
namespace Alan2 {
@@ -65,500 +62,3 @@ Boolean readline(char usrbuf[])
} // End of namespace Alan2
} // End of namespace Glk
-#else
-
-#include "glk/alan2/sysdep.h"
-
-#ifdef HAVE_TERMIO
-#include <termios.h>
-#endif
-
-#ifdef __PACIFIC__
-#include <unixio.h>
-#else
-//#include <unistd.h>
-#endif
-
-#include "glk/alan2/readline.h"
-
-#include "glk/alan2/main.h"
-
-namespace Glk {
-namespace Alan2 {
-
-#ifdef HAVE_TERMIO
-/*----------------------------------------------------------------------*\
-
- termio handling
-
-\*----------------------------------------------------------------------*/
-
-static struct termios term;
-
-static void newtermio()
-{
- struct termios newterm;
- tcgetattr(0, &term);
- newterm=term;
- newterm.c_lflag&=~(ECHO|ICANON);
- newterm.c_cc[VMIN]=1;
- newterm.c_cc[VTIME]=0;
- tcsetattr(0, TCSANOW, &newterm);
-}
-
-static void restoretermio()
-{
- tcsetattr(0, TCSANOW, &term);
-}
-
-#endif
-
-
-/*----------------------------------------------------------------------*\
-
- Global character buffers etc.
-
-\*----------------------------------------------------------------------*/
-
-static unsigned char buffer[LINELENGTH+1];
-static int bufidx;
-
-static unsigned char *history[HISTORYLENGTH];
-static int histidx; /* Index where to store next history */
-static int histp; /* Points to the history recalled last */
-
-static unsigned char ch;
-static int endOfInput = 0;
-static Boolean change;
-static Boolean insert = TRUE;
-
-
-/*----------------------------------------------------------------------*\
-
- Character map types and maps
-
-\*----------------------------------------------------------------------*/
-
-typedef struct {unsigned char min, max; void (*hook)(char ch);} KeyMap;
-
-/* Forward declaration of hooks */
-static void escHook(char ch);
-static void insertCh(char ch);
-static void arrowHook(char ch);
-static void upArrow(char ch);
-static void downArrow(char ch);
-static void rightArrow(char ch);
-static void leftArrow(char ch);
-static void insertToggle(char ch);
-static void newLine(char ch);
-static void delFwd(char ch);
-static void delBwd(char ch);
-
-#ifdef __XXunix__
-static KeyMap keymap[] = {
- {0x00, 0x07, NULL},
- {0x08, 0x08, delBwd},
- {0x09, 0x09, NULL},
- {0x0a, 0x0a, newLine},
- {0x1b, 0x1b, escHook},
- {0x1c, 0x7e, insertCh},
- {0x7f, 0x7f, delFwd},
- {0x80, 0xff, insertCh},
- {0x00, 0x00, NULL}
-};
-
-/* I can't figure out what really coverns the esc-map characters... */
-#ifdef __solarisX__
-static KeyMap escmap[] = {
- {0x00, 0x4e, NULL},
- {0x4f, 0x4f, arrowHook},
- {0x50, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-#else
-static KeyMap escmap[] = {
- {0x00, 0x5a, NULL},
- {0x5b, 0x5b, arrowHook},
- {0x5c, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-#endif
-
-static KeyMap arrowmap[] = {
- {0x00, 0x31, NULL},
- {0x32, 0x32, insertToggle},
- {0x33, 0x40, NULL},
- {0x41, 0x41, upArrow},
- {0x42, 0x42, downArrow},
- {0x43, 0x43, rightArrow},
- {0x44, 0x44, leftArrow},
- {0x45, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-
-#endif
-
-#ifdef __win__
-static KeyMap keymap[] = {
- {0x00, 0x01, NULL},
- {0x02, 0x02, leftArrow},
- {0x03, 0x05, NULL},
- {0x06, 0x06, rightArrow},
- {0x07, 0x07, NULL},
- {0x08, 0x08, delBwd},
- {0x09, 0x09, NULL},
- {0x0a, 0x0a, newLine},
- {0x1b, 0x1b, escHook},
- {0x1c, 0x7e, insertCh},
- {0x7f, 0x7f, delFwd},
- {0x80, 0xff, insertCh},
- {0x00, 0x00, NULL}
-};
-
-static KeyMap escmap[] = {
- {0x00, 0x5a, NULL},
- {0x5b, 0x5b, arrowHook},
- {0x5c, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-
-static KeyMap arrowmap[] = {
- {0x00, 0x31, NULL},
- {0x32, 0x32, insertToggle},
- {0x33, 0x40, NULL},
- {0x41, 0x41, upArrow},
- {0x42, 0x42, downArrow},
- {0x43, 0x43, rightArrow},
- {0x44, 0x44, leftArrow},
- {0x45, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-
-#endif
-
-#ifdef __dos__
-static KeyMap keymap[] = {
- {0x00, 0x01, NULL},
- {0x02, 0x02, leftArrow},
- {0x03, 0x05, NULL},
- {0x06, 0x06, rightArrow},
- {0x07, 0x07, NULL},
- {0x08, 0x08, delBwd},
- {0x09, 0x09, NULL},
- {0x0a, 0x0a, newLine},
- {0x1b, 0x1b, escHook},
- {0x1c, 0x7e, insertCh},
- {0x7f, 0x7f, delFwd},
- {0x80, 0xff, insertCh},
- {0x00, 0x00, NULL}
-};
-
-static KeyMap escmap[] = {
- {0x00, 0x5a, NULL},
- {0x5b, 0x5b, arrowHook},
- {0x5c, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-
-static KeyMap arrowmap[] = {
- {0x00, 0x31, NULL},
- {0x32, 0x32, insertToggle},
- {0x33, 0x40, NULL},
- {0x41, 0x41, upArrow},
- {0x42, 0x42, downArrow},
- {0x43, 0x43, rightArrow},
- {0x44, 0x44, leftArrow},
- {0x45, 0xff, NULL},
- {0x00, 0x00, NULL}
-};
-
-#endif
-
-
-static void doBeep(void)
-{
- write(1, "\7", 1);
-}
-
-
-static void backspace(void)
-{
- write(1, "\b", 1);
-}
-
-
-static void erase()
-{
- int i;
-
- for (i = 0; i < bufidx; i++) backspace(); /* Backup to beginning of text */
- for (i = 0; i < strlen((char *)buffer); i++) write(1, " ", 1); /* Erase all text */
- for (i = 0; i < strlen((char *)buffer); i++) backspace(); /* Backup to beginning of text */
-}
-
-/*----------------------------------------------------------------------*\
-
- Character handling hook functions
-
-\*----------------------------------------------------------------------*/
-
-static void execute(KeyMap map[], unsigned char ch)
-{
- int i = 0;
-
- for (i = 0; i <= 256; i++) {
- if (i > 0 && map[i].min == 0x00) break; /* End marker is a 0,0,NULL */
- if (map[i].min <= ch && ch <= map[i].max) {
- if (map[i].hook != NULL) {
- map[i].hook(ch);
- return;
- } else
- doBeep();
- }
- }
- doBeep();
-}
-
-
-static void upArrow(char ch)
-{
- /* Is there more history ? */
- if (history[(histp+HISTORYLENGTH-1)%HISTORYLENGTH] == NULL ||
- (histp+HISTORYLENGTH-1)%HISTORYLENGTH == histidx) {
- write(1, "\7", 1);
- return;
- }
-
- erase();
-
- /* Backup history pointer */
- histp = (histp+HISTORYLENGTH-1)%HISTORYLENGTH;
-
- /* Copy the history and write it */
- strcpy((char *)buffer, (char *)history[histp]);
- bufidx = strlen((char *)buffer);
- write(1, (void *)buffer, strlen((char *)buffer));
-
-}
-
-
-static void downArrow(char ch)
-{
- /* Is there more history ? */
- if (histp == histidx) {
- write(1, "\7", 1);
- return;
- }
-
- erase();
-
- /* Advance history pointer */
- histp = (histp+1)%HISTORYLENGTH;
-
- /* If we are not at the most recent history entry, copy the history and write it */
- if (histp != histidx) {
- strcpy((char *)buffer, (char *)history[histp]);
- bufidx = strlen((char *)buffer);
- write(1, (void *)buffer, strlen((char *)buffer));
- } else {
- bufidx = 0;
- buffer[0] = '\0';
- }
-}
-
-
-static void rightArrow(char ch)
-{
- if (bufidx > LINELENGTH || buffer[bufidx] == '\0')
- doBeep();
- else {
- write(1, (void *)&buffer[bufidx], 1);
- bufidx++;
- }
-}
-
-
-static void leftArrow(char ch)
-{
- if (bufidx == 0)
- doBeep();
- else {
- bufidx--;
- backspace();
- }
-}
-
-
-static void insertToggle(char ch)
-{
- read(0, &ch, 1);
- if (ch != 'z')
- doBeep();
- else
- insert = !insert;
-}
-
-
-static void delBwd(char ch)
-{
- if (bufidx == 0)
- doBeep();
- else {
- int i;
-
- change = TRUE;
- backspace();
- bufidx--;
- for (i = 0; i <= strlen((char *)&buffer[bufidx+1]); i++)
- buffer[bufidx+i] = buffer[bufidx+1+i];
- write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
- write(1, " ", 1);
- for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace();
- }
-}
-
-static void delFwd(char ch)
-{
- if (bufidx > LINELENGTH || buffer[bufidx] == '\0')
- doBeep();
- else {
- int i;
-
- change = TRUE;
- strcpy((char *)&buffer[bufidx], (char *)&buffer[bufidx+1]);
- write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
- write(1, " ", 1);
- for (i = 0; i <= strlen((char *)&buffer[bufidx]); i++) backspace();
- }
-}
-
-static void escHook(char ch) {
- read(0, &ch, 1);
- execute(escmap, ch);
-}
-
-static void arrowHook(char ch) {
- read(0, &ch, 1);
- execute(arrowmap, ch);
-}
-
-static void newLine(char ch)
-{
- endOfInput = 1;
- write(1, "\n", 1);
-
- /* If the input is not the same as the previous, save it in the history */
- if (change && strlen((char *)buffer) > 0) {
- if (history[histidx] == NULL)
- history[histidx] = (unsigned char *)allocate(LINELENGTH+1);
- strcpy((char *)history[histidx], (char *)buffer);
- histidx = (histidx+1)%HISTORYLENGTH;
- }
-}
-
-
-static void insertCh(char ch) {
- if (bufidx > LINELENGTH)
- doBeep();
- else {
- /* If at end advance the NULL */
- if (buffer[bufidx] == '\0')
- buffer[bufidx+1] = '\0';
- else if (insert) {
- int i;
-
- /* If insert mode is on, move the characters ahead */
- for (i = strlen((char *)buffer); i >= bufidx; i--)
- buffer[i+1] = buffer[i];
- write(1, (void *)&buffer[bufidx], strlen((char *)&buffer[bufidx]));
- for (i = strlen((char *)&buffer[bufidx]); i > 0; i--) backspace();
- }
- change = TRUE;
- buffer[bufidx] = ch;
- write(1, &ch, 1);
- bufidx++;
- }
-}
-
-
-/*----------------------------------------------------------------------
-
- echoOff()
-
- */
-static void echoOff()
-{
-#ifdef HAVE_TERMIO
- newtermio();
-#else
-#ifdef __win__
-#include <windows.h>
-#include <winbase.h>
-#include <wincon.h>
-
- DWORD handle = GetStdHandle(STD_INPUT_HANDLE);
-
- (void) SetConsoleMode(handle, 0);
-
-#endif
-#endif
-}
-
-
-/*----------------------------------------------------------------------
-
- echoOn()
-
- */
-static void echoOn()
-{
-#ifdef HAVE_TERMIO
- restoretermio();
-#else
-#ifdef __win__
-#include <windows.h>
-#include <winbase.h>
-#include <wincon.h>
-
- DWORD handle = GetStdHandle(STD_INPUT_HANDLE);
- (void) SetConsoleMode(handle, ENABLE_ECHO_INPUT);
-
-#endif
-#endif
-}
-
-
-/*======================================================================
-
- readline()
-
- Read a line from the user, with history and editing
-
- */
-
-/* 4f - length of user buffer should be used */
-Boolean readline(char usrbuf[])
-{
- fflush(stdout);
- bufidx = 0;
- histp = histidx;
- buffer[0] = '\0';
- change = TRUE;
- echoOff();
- endOfInput = 0;
- while (!endOfInput) {
- if (read(0, (void *)&ch, 1) != 1) {
- echoOn();
- return FALSE;
- }
- execute(keymap, ch);
- }
- echoOn();
- strcpy(usrbuf, (char *)buffer);
- return TRUE;
-}
-
-} // End of namespace Alan2
-} // End of namespace Glk
-
-#endif
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
index b558b18..323f6e7 100644
--- a/engines/glk/alan2/rules.cpp
+++ b/engines/glk/alan2/rules.cpp
@@ -21,17 +21,13 @@
*/
#include "glk/alan2/types.h"
-#include "glk/alan2/main.h"
-#include "glk/alan2/inter.h"
#include "glk/alan2/debug.h"
#include "glk/alan2/exe.h"
-#include "glk/alan2/stack.h"
-
-#include "glk/alan2/rules.h"
-
-#ifdef GLK
+#include "glk/alan2/inter.h"
#include "glk/alan2/glkio.h"
-#endif
+#include "glk/alan2/main.h"
+#include "glk/alan2/rules.h"
+#include "glk/alan2/stack.h"
namespace Glk {
namespace Alan2 {
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
index 312518f..74d4fc9 100644
--- a/engines/glk/alan2/sysdep.cpp
+++ b/engines/glk/alan2/sysdep.cpp
@@ -21,17 +21,15 @@
*/
#include <string.h>
-#include "glk/alan2/sysdep.h"
-
-#ifdef GLK
#include "glk/alan2/alan2.h"
-#endif
+#include "glk/alan2/sysdep.h"
namespace Glk {
namespace Alan2 {
-#ifdef GLK
-extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
+void syserr(char str[]);
+
+void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
Common::String s = Common::String::vformat(fmt, args);
@@ -39,64 +37,6 @@ extern void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
ws->write(s.c_str(), s.size());
}
-#endif
-
-extern void syserr(char str[]);
-
-#ifdef __vms__
-
-char *strdup(char str[]) /* IN - String to duplicate */
-{
- char *new = (char *) malloc(strlen(str)+1);
-
- if (!new)
- syserr("Out of memory");
- strcpy(new, str);
- return new;
-}
-
-#endif
-
-
-#ifdef __mac__
-
-char *strdup(char str[]) /* IN - String to duplicate */
-{
- char *new = (char *) malloc((size_t)((int)strlen(str)+1));
-
- if (!new)
- syserr("Out of memory");
- strcpy(new, str);
- return new;
-}
-
-#endif
-
-
-#ifdef __vms__
-
-/* Cheat implementation of strftime */
-size_t strftime (
- char *outbuf,
- size_t len,
- const char *format,
- const struct tm *t)
-{
- char buf[100];
- time_t ticks;
-
- time(&ticks);
- strcpy(buf, ctime(&ticks));
- buf[strlen(buf)-1] = '\0';
- strcpy(outbuf, &buf[4]);
-}
-
-#endif
-
-#ifdef __dos__
-#endif
-
-#ifdef GLK
/* Note to Glk maintainers: 'native' characters are used for output, in this
case, Glk's Latin-1. ISO characters are Alan's internal representation,
@@ -172,28 +112,6 @@ static char uppChrs[] =
'\x00'
};
-#else
-
-/* Theses work on native character sets */
-
-static char spcChrs[] = " \t\n";
-
-#ifdef __amiga__
-
-/* Which can't read 8-bit chars but is ISO */
-static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
-
-static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
-
-#else
-
-/* Use native characters */
-static char lowChrs[] = "abcdefghijklmnopqrstuvwxyzàáâãäåæçéêëìíîïðñòóôõöøùúûüýþÿ";
-
-static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÛÝÞß";
-
-#endif
-#endif
int isSpace(int c) /* IN - Native character to test */
{
@@ -220,56 +138,12 @@ int isLetter(int c) /* IN - Native character to test */
int toLower(int c) /* IN - Native character to convert */
{
-#ifdef GLK
return g_vm->glk_char_to_lower(c);
-#else
-#ifdef __dos__
- char *cp;
-
- if ((cp = strchr(uppChrs, c)) != 0)
- return(lowChrs[cp-uppChrs]);
- else
- return c;
-#else
-#ifdef __mac__
- char *cp;
-
- if ((cp = strchr(uppChrs, c)) != 0)
- return(lowChrs[cp-uppChrs]);
- else
- return c;
-#else
- return (isUpper(c)? c + ('a' - 'A'): c);
-#endif
-#endif
-#endif
}
int toUpper(int c) /* IN - Native character to convert */
{
-#ifdef GLK
return g_vm->glk_char_to_upper(c);
-#else
-#ifdef __dos__
- char *cp;
-
- if ((cp = strchr(lowChrs, c)) != 0)
- return(uppChrs[cp-lowChrs]);
- else
- return c;
-#else
-#ifdef __mac__
- char *cp;
-
- if ((cp = strchr(lowChrs, c)) != 0)
- return(uppChrs[cp-lowChrs]);
- else
- return c;
-#else
- return (isLower(c)? c - ('a' - 'A'): c);
-#endif
-#endif
-#endif
}
char *strlow(char str[]) /* INOUT - Native string to convert */
@@ -427,57 +301,8 @@ static unsigned char dosMap[256]
void fromIso(char copy[], /* OUT - Mapped string */
char original[]) /* IN - string to convert */
{
-#if ISO == 0
- static unsigned char map[256]
-#if defined __mac__
- = {
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F,
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
- 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
- 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
- 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,
- 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
- 0xCA,0xC1,0xA2,0xA3,0xB0,0xB4,0xBA,0xA4,0xAC,0xA9,0xBB,0xC7,0xC2,0xD0,0xA8,0xD1,
- 0xA1,0xB1,0xAA,0xD5,0xAB,0xB5,0xA6,0xA5,0xD4,0xA0,0xBC,0xC8,0xD9,0xDA,0xDB,0xC0,
- 0xCB,0xDC,0xD7,0xCC,0x80,0x81,0xAE,0x82,0xC5,0x83,0xB7,0xC9,0xB3,0xB2,0xC3,0xC4,
- 0xC6,0x84,0xDD,0xDE,0xBD,0xCD,0x85,0xAD,0xAF,0xD3,0xD2,0xDF,0x86,0xCE,0xB8,0xA7,
- 0x88,0x87,0x89,0x8B,0x8A,0x8C,0xBE,0x8D,0x8F,0x8E,0x90,0x91,0x93,0x92,0x94,0x95,
- 0xB6,0x96,0x98,0x97,0x99,0x9B,0x9A,0xD6,0xBF,0x9D,0x9C,0x9E,0x9F,0xCF,0xB9,0xD8}
-#else
-#if defined __dos__
- = {
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0D,0x0B,0x0C,0x0D,0x0E,0x0F,
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
- 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
- 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
- 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
- 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,
- 0xFF,0xD0,0x9B,0x9C,0xE5,0x9D,0x9F,0xD1,0xF7,0xE0,0xA6,0xAE,0xFB,0xD2,0xE7,0xFA,
- 0xF8,0xF1,0xFD,0xD3,0xFE,0xE6,0xE3,0xF9,0xD4,0xD5,0xA7,0xAF,0xAC,0xAB,0xF0,0xA8,
- 0xA9,0xAA,0xEF,0xD6,0x8E,0x8F,0x92,0x80,0xE2,0x90,0xE4,0xEE,0xF5,0xF4,0xD7,0xAD,
- 0xE9,0xA5,0xD8,0xD9,0xEA,0xE8,0x99,0xEC,0xED,0xF2,0xF3,0xDA,0x9A,0xDB,0x9E,0xE1,
- 0x85,0xA0,0x83,0xDC,0x84,0x86,0x91,0x87,0x8A,0x82,0x88,0x89,0x8D,0xA1,0x8C,0x8B,
- 0xEB,0xA4,0x95,0xA2,0x93,0xDD,0x94,0xF6,0xDE,0x97,0xA3,0x96,0x81,0xDF,0xFC,0x98}
-#endif
- ;
-#endif
- unsigned char *o, *c;
-
- for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
- *c = map[*o];
- *c = '\0';
-#else
if (copy != original)
(void)strcpy(copy, original);
-#endif
}
diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h
index e58e538..7fce53c 100644
--- a/engines/glk/alan2/sysdep.h
+++ b/engines/glk/alan2/sysdep.h
@@ -45,7 +45,6 @@ namespace Alan2 {
#define GLK
#define __win__
-#ifdef GLK
#undef isdigit
#define isdigit Common::isDigit
#undef stricmp
@@ -56,300 +55,13 @@ namespace Alan2 {
#define rand() g_vm->getRandomNumber(0x7fffffff)
#undef fprintf
extern void fprintf(Common::WriteStream *ws, const char *fmt, ...);
-#endif
-
-/* Place definitions of OS and compiler here if necessary */
-#ifdef AZTEC_C
-#define __amiga__
-#endif
-
-#ifndef __sun__
-#ifdef sun
-#define __sun__
-#endif
-#endif
-
-#ifdef _INCLUDE_HPUX_SOURCE
-#define __hp__
-#endif
-
-#ifndef __unix__
-#ifdef unix
-#define __unix__
-#endif
-#endif
-
-#ifdef vax
-#define __vms__
-#endif
-
-#ifdef THINK_C
-#define __mac__
-#endif
-
-#ifdef __MWERKS__
-#ifdef macintosh
-#define __mac__
-#else
-#define __dos__
-#endif
-#endif
-
-#ifdef DOS
-#define __dos__
-#endif
-
-#ifdef __BORLANDC__
-#define __dos__
-#endif
-
-#ifdef __CYGWIN__
-#define __win__
-#endif
-
-#ifdef __MINGW32__
-#define __win__
-#endif
-
-#ifdef __PACIFIC__
-#define __dos__
-#define HAVE_SHORT_FILENAMES
-#endif
-
-
-/*----------------------------------------------------------------------
-
- Below follows OS and compiler dependent settings. They should not be
- changed except for introducing new sections when porting to new
- environments.
-
- */
-
-/************/
-/* Includes */
-/************/
-
-#ifndef GLK
-#include <stdio.h>
-#include <ctype.h>
-#endif
-
-#ifdef __STDC__
-#include <stdlib.h>
-#include <string.h>
-#endif
-
-#ifdef __vms__
-/* Our VAXC doesn't define __STDC__ */
-#include <stdlib.h>
-#include <string.h>
-#endif
-
-
-#ifdef __mac__
-#include <stdlib.h>
-#include <string.h>
-#include <unix.h>
-#endif
-
-#ifdef __MWERKS__
-#define strdup _strdup
-#endif
/***********************/
-/* ISO character sets? */
-/***********************/
/* Common case first */
#define ISO 1
#define NATIVECHARSET 0
-#ifdef GLK
-#undef ISO
-#define ISO 1
-#undef NATIVECHARSET
-#define NATIVECHARSET 0
-#else /* Glk is ISO, no matter what the OS */
-
-#ifdef __dos__
-#undef ISO
-#define ISO 0
-#undef NATIVECHARSET
-#define NATIVECHARSET 2
-#endif
-
-#ifdef __win__
-#undef ISO
-#define ISO 1
-#undef NATIVECHARSET
-#define NATIVECHARSET 2
-#endif
-
-#ifdef __mac__
-#undef ISO
-#define ISO 0
-#undef NATIVECHARSET
-#define NATIVECHARSET 1
-#endif
-
-#endif
-
-/**************************/
-/* Strings for file modes */
-/**************************/
-#define READ_MODE "r"
-#define WRITE_MODE "w"
-
-#ifdef __mac__
-/* File open mode (binary) */
-#undef READ_MODE
-#define READ_MODE "rb"
-#undef WRITE_MODE
-#define WRITE_MODE "wb"
-#endif
-
-#ifdef __dos__
-/* File open mode (binary) */
-#undef READ_MODE
-#define READ_MODE "rb"
-#undef WRITE_MODE
-#define WRITE_MODE "wb"
-#endif
-
-#ifdef __win__
-/* File open mode (binary) */
-#undef READ_MODE
-#define READ_MODE "rb"
-#undef WRITE_MODE
-#define WRITE_MODE "wb"
-#endif
-
-/*****************/
-/* Byte ordering */
-/*****************/
-
-#ifdef __dos__
-#define REVERSED
-#endif
-
-#ifdef __vms__
-#define REVERSED
-#endif
-
-#ifdef __win__
-#ifndef REVERSED
-#define REVERSED
-#endif
-#endif
-
-
-/****************************/
-/* Allocates cleared bytes? */
-/****************************/
-
-#ifdef __CYGWIN__
-#define NOTCALLOC
-#endif
-
-#ifdef __MINGW32__
-#define NOTCALLOC
-#endif
-
-#ifdef __unix__
-#define NOTCALLOC
-#endif
-
-
-/****************/
-/* Have termio? */
-/****************/
-
-#ifdef GLK
-/* don't need TERMIO */
-#else
-
-#ifdef __CYGWIN__
-#define HAVE_TERMIO
-#endif
-
-#ifdef __unix__
-#define HAVE_TERMIO
-#endif
-
-#endif
-
-/*******************************/
-/* Is ANSI control available? */
-/*******************************/
-
-#ifdef GLK
-/* don't need ANSI */
-#else
-
-#ifdef __CYGWIN__
-#define HAVE_ANSI
-#endif
-
-#endif
-
-/******************************/
-/* Use the READLINE function? */
-/******************************/
-
-#ifdef GLK
-/* Glk always uses readline(), no matter what the OS */
-#define USE_READLINE
-#else
-
-#ifdef __unix__
-#define USE_READLINE
-#endif
-
-#ifdef x__dos__
-#define USE_READLINE
-#endif
-
-#ifdef __win__
-#define USE_READLINE
-#endif
-
-#endif
-
-/* Special cases and definition overrides */
-#ifdef __unix__
-#define MULTI
-#endif
-
-
-
-
-#ifdef __vms__
-
-#define MULTI
-
-extern char *strdup(char str[]);
-
-/* Cheat implementation of strftime */
-extern size_t strftime (char *, size_t, const char *, const struct tm *);
-
-#endif
-
-#ifdef __mac__
-
-extern char *strdup(char *str);
-
-#endif
-
-
-#ifdef __dos__
-
-/* Return codes */
-#define EXIT_SUCCESS 0
-#define EXIT_FAILURE 1
-
-#endif
-
-
/* Native character functions */
extern int isSpace(int c); /* IN - Native character to test */
extern int isLower(int c); /* IN - Native character to test */
diff --git a/engines/glk/alan2/term.cpp b/engines/glk/alan2/term.cpp
index 8f7b64a..c758efe 100644
--- a/engines/glk/alan2/term.cpp
+++ b/engines/glk/alan2/term.cpp
@@ -35,83 +35,8 @@ namespace Alan2 {
*/
void getPageSize() {
-#ifdef GLK
paglen = 0;
pagwidth = 0;
-
-#else
-#ifdef HAVE_TERMIO
-
-#include <sys/termios.h>
-
- extern int ioctl();
-
- struct winsize win;
- int ecode;
-
- ecode = ioctl(1, TIOCGWINSZ, &win);
-
- if (ecode != 0 || win.ws_row == 0)
- paglen = header->paglen;
- else
- paglen = win.ws_row;
-
- if (ecode != 0 || win.ws_col == 0)
- pagwidth = header->pagwidth;
- else
- pagwidth = win.ws_col;
-
-#else
-#ifdef __amiga__
-#include <libraries/dosextens.h>
-#include <intuition/intuition.h>
-#include <graphics/text.h>
-#include <clib/exec_protos.h>
-
- struct Process * proc;
- struct InfoData *id;
- struct Window *win;
- struct TextFont *textFont;
- struct StandardPacket *packet;
-
- proc = (struct Process *) FindTask(0L);
-
- id = (struct InfoData *) allocate(sizeof(struct InfoData));
-
- if (proc->pr_ConsoleTask) {
- packet = (struct StandardPacket *) allocate(sizeof(struct StandardPacket));
- packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
- packet->sp_Pkt.dp_Link = & packet->sp_Msg;
- packet->sp_Pkt.dp_Port = & proc->pr_MsgPort;
- packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
-
- packet->sp_Pkt.dp_Arg1 = ((LONG) id) >> 2;
-
- PutMsg ((struct MsgPort *) proc->pr_ConsoleTask, & packet->sp_Msg);
- WaitPort(&proc->pr_MsgPort);
- GetMsg(&proc->pr_MsgPort);
- free((char *)packet);
-
- win = (struct Window *) id->id_VolumeNode;
- free(id);
-
- /* Calculate number of characters and lines w.r.t font size and borders */
- textFont = win->IFont;
- paglen = win->Height/textFont->tf_YSize-2;
- pagwidth = win->Width/textFont->tf_XSize-3;
- } else {
- paglen = header->paglen;
- pagwidth = header->pagwidth;
- }
-
-#else
-
- paglen = header->paglen;
- pagwidth = header->pagwidth;
-
-#endif
-#endif
-#endif
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 699dd0e..34c5dda 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -33,14 +33,12 @@ namespace Alan2 {
/* CONSTANTS */
-#ifndef __mac__
#ifndef TRUE
#define TRUE (0==0)
#endif
#ifndef FALSE
#define FALSE (!TRUE)
#endif
-#endif
#define ACTMIN (header->actmin)
#define ACTMAX (header->actmax)
@@ -77,9 +75,7 @@ namespace Alan2 {
/* TYPES */
-#ifndef __mac__
typedef int Boolean; /* Boolean values within interpreter */
-#endif
/* Amachine variables */
struct CurVars {
Commit: a3fa9d12a94494f86134f56df6c064d7e48e8580
https://github.com/scummvm/scummvm/commit/a3fa9d12a94494f86134f56df6c064d7e48e8580
Author: dreammaster (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Fix gcc errors for references to packed struct fields
Changed paths:
engines/glk/alan2/alan2.cpp
engines/glk/alan2/types.cpp
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 73b8a5e..05e5233 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -91,6 +91,12 @@ Common::Error Alan2::writeGameData(Common::WriteStream *ws) {
return Common::kNoError;
}
+// This works around gcc errors for passing packed structure fields
+void syncVal(Common::Serializer &s, uint32 *fld) {
+ uint32 &v = *fld;
+ s.syncAsUint32LE(v);
+}
+
void Alan2::synchronizeSave(Common::Serializer &s) {
AtrElem *atr;
int i;
@@ -100,31 +106,31 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
// Save actors
for (i = ACTMIN; i <= ACTMAX; ++i) {
- s.syncAsSint32LE(acts[i-ACTMIN].loc);
- s.syncAsSint32LE(acts[i-ACTMIN].script);
- s.syncAsSint32LE(acts[i-ACTMIN].step);
- s.syncAsSint32LE(acts[i-ACTMIN].count);
+ syncVal(s, &acts[i-ACTMIN].loc);
+ syncVal(s, &acts[i-ACTMIN].script);
+ syncVal(s, &acts[i-ACTMIN].step);
+ syncVal(s, &acts[i-ACTMIN].count);
if (acts[i-ACTMIN].atrs) {
for (atr = (AtrElem *)addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); ++atr)
- s.syncAsSint32LE(atr->val);
+ syncVal(s, &atr->val);
}
}
// Sync locations
for (i = LOCMIN; i <= LOCMAX; ++i) {
- s.syncAsSint32LE(locs[i-LOCMIN].describe);
+ syncVal(s, &locs[i-LOCMIN].describe);
if (locs[i-LOCMIN].atrs)
for (atr = (AtrElem *)addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
- s.syncAsSint32LE(atr->val);
+ syncVal(s, &atr->val);
}
// Sync objects
for (i = OBJMIN; i <= OBJMAX; ++i) {
- s.syncAsSint32LE(objs[i-OBJMIN].loc);
+ syncVal(s, &objs[i-OBJMIN].loc);
if (objs[i-OBJMIN].atrs)
for (atr = (AtrElem *)addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
- s.syncAsSint32LE(atr->val);
+ syncVal(s, &atr->val);
}
// Sync the event queue
@@ -140,7 +146,7 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
// Sync scores
for (i = 0; scores[i] != EOF; i++)
- s.syncAsSint32LE(scores[i]);
+ syncVal(s, &scores[i]);
}
bool Alan2::is_gamefile_valid() {
diff --git a/engines/glk/alan2/types.cpp b/engines/glk/alan2/types.cpp
index 8419e33..9ce4a65 100644
--- a/engines/glk/alan2/types.cpp
+++ b/engines/glk/alan2/types.cpp
@@ -25,21 +25,27 @@
namespace Glk {
namespace Alan2 {
+// This works around gcc errors for passing packed structure fields
+static void syncVal(Common::Serializer &s, int *fld) {
+ int &v = *fld;
+ s.syncAsSint32LE(v);
+}
+
void CurVars::synchronize(Common::Serializer &s) {
- s.syncAsSint32LE(vrb);
- s.syncAsSint32LE(obj);
- s.syncAsSint32LE(loc);
- s.syncAsSint32LE(act);
- s.syncAsSint32LE(tick);
- s.syncAsSint32LE(score);
- s.syncAsSint32LE(visits);
+ syncVal(s, &vrb);
+ syncVal(s, &obj);
+ syncVal(s, &loc);
+ syncVal(s, &act);
+ syncVal(s, &tick);
+ syncVal(s, &score);
+ syncVal(s, &visits);
}
void EvtqElem::synchronize(Common::Serializer &s) {
- s.syncAsSint32LE(time);
- s.syncAsSint32LE(event);
- s.syncAsSint32LE(where);
-};
+ syncVal(s, &time);
+ syncVal(s, &event);
+ syncVal(s, &where);
+}
} // End of namespace Alan2
} // End of namespace Glk
Commit: 2450df501c152249fe1002a7dee70642563d40a3
https://github.com/scummvm/scummvm/commit/2450df501c152249fe1002a7dee70642563d40a3
Author: dreammaster (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: astyle formatting
Changed paths:
engines/glk/alan2/acode.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/alan2.h
engines/glk/alan2/alan_version.cpp
engines/glk/alan2/args.cpp
engines/glk/alan2/debug.cpp
engines/glk/alan2/decode.cpp
engines/glk/alan2/exe.cpp
engines/glk/alan2/exe.h
engines/glk/alan2/glkio.cpp
engines/glk/alan2/inter.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/params.cpp
engines/glk/alan2/parse.cpp
engines/glk/alan2/parse.h
engines/glk/alan2/readline.cpp
engines/glk/alan2/reverse.cpp
engines/glk/alan2/rules.cpp
engines/glk/alan2/stack.cpp
engines/glk/alan2/sysdep.cpp
engines/glk/alan2/sysdep.h
engines/glk/alan2/term.cpp
engines/glk/alan2/types.cpp
engines/glk/alan2/types.h
engines/glk/alan2/version.h
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index 8cb3c81..35153ce 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -47,32 +47,32 @@ typedef int CodeValue; /* Definition for the packing process */
#define TOPVALUE (((CodeValue)1<<VALUEBITS) - 1) /* Highest value possible */
/* Half and quarter points in the code value range */
-#define ONEQUARTER (TOPVALUE/4+1) /* Point after first quarter */
-#define HALF (2*ONEQUARTER) /* Point after first half */
-#define THREEQUARTER (3*ONEQUARTER) /* Point after third quarter */
+#define ONEQUARTER (TOPVALUE/4+1) /* Point after first quarter */
+#define HALF (2*ONEQUARTER) /* Point after first half */
+#define THREEQUARTER (3*ONEQUARTER) /* Point after third quarter */
/* AMACHINE Word Classes */
typedef int WrdKind;
-#define WRD_SYN 0 /* 1 - Synonym */
-#define WRD_ADJ 1 /* 2 - Adjective */
-#define WRD_ALL 2 /* 4 - All */
-#define WRD_BUT 3 /* 8 - But */
-#define WRD_CONJ 4 /* 16 - Conjunction */
-#define WRD_PREP 5 /* 32 - Preposition */
-#define WRD_DIR 6 /* 64 - Direction */
-#define WRD_IT 7 /* 128 - It */
-#define WRD_NOISE 8 /* 256 - Noise word */
-#define WRD_NOUN 9 /* 512 - Noun */
-#define WRD_ACT 10 /* 1024 - Actor */
-#define WRD_THEM 11 /* 2048 - Them */
-#define WRD_VRB 12 /* 4096 - Verb */
+#define WRD_SYN 0 /* 1 - Synonym */
+#define WRD_ADJ 1 /* 2 - Adjective */
+#define WRD_ALL 2 /* 4 - All */
+#define WRD_BUT 3 /* 8 - But */
+#define WRD_CONJ 4 /* 16 - Conjunction */
+#define WRD_PREP 5 /* 32 - Preposition */
+#define WRD_DIR 6 /* 64 - Direction */
+#define WRD_IT 7 /* 128 - It */
+#define WRD_NOISE 8 /* 256 - Noise word */
+#define WRD_NOUN 9 /* 512 - Noun */
+#define WRD_ACT 10 /* 1024 - Actor */
+#define WRD_THEM 11 /* 2048 - Them */
+#define WRD_VRB 12 /* 4096 - Verb */
#define WRD_CLASSES 13
/* Syntax element classifications */
-#define EOS (-2) /* End Of Syntax */
+#define EOS (-2) /* End Of Syntax */
/* Syntax element flag bits */
#define MULTIPLEBIT 0x1
@@ -80,210 +80,210 @@ typedef int WrdKind;
/* Parameter Classes */
-typedef enum ClaKind { /* NOTE! These must have the same order as */
- CLA_OBJ = 1, /* the name classes in NAM.H */
- CLA_CNT = (int)CLA_OBJ<<1,
- CLA_ACT = (int)CLA_CNT<<1,
- CLA_NUM = (int)CLA_ACT<<1,
- CLA_STR = (int)CLA_NUM<<1,
- CLA_COBJ = (int)CLA_STR<<1,
- CLA_CACT = (int)CLA_COBJ<<1
+typedef enum ClaKind { /* NOTE! These must have the same order as */
+ CLA_OBJ = 1, /* the name classes in NAM.H */
+ CLA_CNT = (int)CLA_OBJ << 1,
+ CLA_ACT = (int)CLA_CNT << 1,
+ CLA_NUM = (int)CLA_ACT << 1,
+ CLA_STR = (int)CLA_NUM << 1,
+ CLA_COBJ = (int)CLA_STR << 1,
+ CLA_CACT = (int)CLA_COBJ << 1
} ClaKind;
-
+
/* Verb Qualifiers */
typedef enum QualClass {
- Q_DEFAULT,
- Q_AFTER,
- Q_BEFORE,
- Q_ONLY
+ Q_DEFAULT,
+ Q_AFTER,
+ Q_BEFORE,
+ Q_ONLY
} QualClass;
/* The AMACHINE Operations */
typedef enum OpClass {
- C_CONST,
- C_STMOP,
- C_CURVAR
+ C_CONST,
+ C_STMOP,
+ C_CURVAR
} OpClass;
typedef enum InstClass {
- I_PRINT, /* Print a string from the text file */
- I_QUIT,
- I_LOOK,
- I_SAVE,
- I_RESTORE,
- I_LIST, /* List contents of a container */
- I_EMPTY,
- I_SCORE,
- I_VISITS,
- I_SCHEDULE,
- I_CANCEL,
- I_LOCATE,
- I_MAKE,
- I_SET, /* Set a numeric attribute to the */
- /* value on top of stack */
- I_STRSET, /* Set a string valued attribute to a */
- /* copy of the string on top of stack, */
- /* deallocate current contents first */
- I_GETSTR, /* Get a string contents from text */
- /* file, create a copy and push it */
- /* on top of stack */
- I_INCR, /* Increment an attribute */
- I_DECR, /* Decrement a numeric attribute */
- I_USE,
- I_IN,
- I_DESCRIBE,
- I_SAY,
- I_SAYINT,
- I_SAYSTR,
- I_IF,
- I_ELSE,
- I_ENDIF,
- I_ATTRIBUTE,
- I_STRATTR, /* Push a copy of a string attribute */
- I_HERE,
- I_NEAR,
- I_WHERE,
- I_AND,
- I_OR,
- I_NE,
- I_EQ,
- I_STREQ, /* String compare */
- I_STREXACT,
- I_LE,
- I_GE,
- I_LT,
- I_GT,
- I_PLUS,
- I_MINUS,
- I_MULT,
- I_DIV,
- I_NOT,
- I_UMINUS,
- I_RND,
- I_SUM, /* SUM-aggregate */
- I_MAX, /* MAX-aggregate */
- I_COUNT, /* COUNT-aggregate */
- I_RETURN,
- I_SYSTEM,
- I_RESTART, /* INTRODUCED: v2.7 */
- I_BTW, /* INTRODUCED: v2.8 */
- I_CONTAINS, /* -""- */
- I_DEPSTART, /* -""- */
- I_DEPCASE, /* -""- */
- I_DEPEXEC, /* -""- */
- I_DEPELSE, /* -""- */
- I_DEPEND /* -""- */
+ I_PRINT, /* Print a string from the text file */
+ I_QUIT,
+ I_LOOK,
+ I_SAVE,
+ I_RESTORE,
+ I_LIST, /* List contents of a container */
+ I_EMPTY,
+ I_SCORE,
+ I_VISITS,
+ I_SCHEDULE,
+ I_CANCEL,
+ I_LOCATE,
+ I_MAKE,
+ I_SET, /* Set a numeric attribute to the */
+ /* value on top of stack */
+ I_STRSET, /* Set a string valued attribute to a */
+ /* copy of the string on top of stack, */
+ /* deallocate current contents first */
+ I_GETSTR, /* Get a string contents from text */
+ /* file, create a copy and push it */
+ /* on top of stack */
+ I_INCR, /* Increment an attribute */
+ I_DECR, /* Decrement a numeric attribute */
+ I_USE,
+ I_IN,
+ I_DESCRIBE,
+ I_SAY,
+ I_SAYINT,
+ I_SAYSTR,
+ I_IF,
+ I_ELSE,
+ I_ENDIF,
+ I_ATTRIBUTE,
+ I_STRATTR, /* Push a copy of a string attribute */
+ I_HERE,
+ I_NEAR,
+ I_WHERE,
+ I_AND,
+ I_OR,
+ I_NE,
+ I_EQ,
+ I_STREQ, /* String compare */
+ I_STREXACT,
+ I_LE,
+ I_GE,
+ I_LT,
+ I_GT,
+ I_PLUS,
+ I_MINUS,
+ I_MULT,
+ I_DIV,
+ I_NOT,
+ I_UMINUS,
+ I_RND,
+ I_SUM, /* SUM-aggregate */
+ I_MAX, /* MAX-aggregate */
+ I_COUNT, /* COUNT-aggregate */
+ I_RETURN,
+ I_SYSTEM,
+ I_RESTART, /* INTRODUCED: v2.7 */
+ I_BTW, /* INTRODUCED: v2.8 */
+ I_CONTAINS, /* -""- */
+ I_DEPSTART, /* -""- */
+ I_DEPCASE, /* -""- */
+ I_DEPEXEC, /* -""- */
+ I_DEPELSE, /* -""- */
+ I_DEPEND /* -""- */
} InstClass;
typedef enum VarClass {
- V_PARAM,
- V_CURLOC,
- V_CURACT,
- V_CURVRB,
- V_SCORE
+ V_PARAM,
+ V_CURLOC,
+ V_CURACT,
+ V_CURVRB,
+ V_SCORE
} VarClass;
#define I_CLASS(x) ((x)>>28)
#define I_OP(x) ((x&0x8000000)?(x)|0x0f0000000:(x)&0x0fffffff)
-#include "common/pack-start.h" // START STRUCT PACKING
+#include "common/pack-start.h" // START STRUCT PACKING
/**
- * Game header
+ * Game header
*/
struct AcdHdr {
/* Important info */
- char vers[4]; /* 01 - Version of compiler */
- Aword size; /* 02 - Size of ACD-file in Awords */
+ char vers[4]; /* 01 - Version of compiler */
+ Aword size; /* 02 - Size of ACD-file in Awords */
/* Options */
- Abool pack; /* 03 - Is the text packed ? */
- Aword paglen; /* 04 - Length of a page */
- Aword pagwidth; /* 05 - and width */
- Aword debug; /* 06 - Option debug */
+ Abool pack; /* 03 - Is the text packed ? */
+ Aword paglen; /* 04 - Length of a page */
+ Aword pagwidth; /* 05 - and width */
+ Aword debug; /* 06 - Option debug */
/* Data structures */
- Aaddr dict; /* 07 - Dictionary */
- Aaddr oatrs; /* 08 - Object default attributes */
- Aaddr latrs; /* 09 - Location default attributes */
- Aaddr aatrs; /* 0a - Actor default attributes */
- Aaddr acts; /* 0b - Actor table */
- Aaddr objs; /* 0c - Object table */
- Aaddr locs; /* 0d - Location table */
- Aaddr stxs; /* 0e - Syntax table */
- Aaddr vrbs; /* 0f - Verb table */
- Aaddr evts; /* 10 - Event table */
- Aaddr cnts; /* 11 - Container table */
- Aaddr ruls; /* 12 - Rule table */
- Aaddr init; /* 13 - String init table */
- Aaddr start; /* 14 - Start code */
- Aword msgs; /* 15 - Messages table */
+ Aaddr dict; /* 07 - Dictionary */
+ Aaddr oatrs; /* 08 - Object default attributes */
+ Aaddr latrs; /* 09 - Location default attributes */
+ Aaddr aatrs; /* 0a - Actor default attributes */
+ Aaddr acts; /* 0b - Actor table */
+ Aaddr objs; /* 0c - Object table */
+ Aaddr locs; /* 0d - Location table */
+ Aaddr stxs; /* 0e - Syntax table */
+ Aaddr vrbs; /* 0f - Verb table */
+ Aaddr evts; /* 10 - Event table */
+ Aaddr cnts; /* 11 - Container table */
+ Aaddr ruls; /* 12 - Rule table */
+ Aaddr init; /* 13 - String init table */
+ Aaddr start; /* 14 - Start code */
+ Aword msgs; /* 15 - Messages table */
/* Miscellaneous */
- Aword objmin, objmax; /* 16 - Interval for object codes */
- Aword actmin, actmax; /* 18 - Interval for actor codes */
- Aword cntmin, cntmax; /* 1a - Interval for container codes */
- Aword locmin, locmax; /* 1c - Interval for location codes */
- Aword dirmin, dirmax; /* 1e - Interval for direction codes */
- Aword evtmin, evtmax; /* 20 - Interval for event codes */
- Aword rulmin, rulmax; /* 22 - Interval for rule codes */
- Aword maxscore; /* 24 - Maximum score */
- Aaddr scores; /* 25 - Score table */
- Aaddr freq; /* 26 - Address to Char freq's for coding */
- Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
- Aword txtcrc; /* 28 - Checksum for text data file */
+ Aword objmin, objmax; /* 16 - Interval for object codes */
+ Aword actmin, actmax; /* 18 - Interval for actor codes */
+ Aword cntmin, cntmax; /* 1a - Interval for container codes */
+ Aword locmin, locmax; /* 1c - Interval for location codes */
+ Aword dirmin, dirmax; /* 1e - Interval for direction codes */
+ Aword evtmin, evtmax; /* 20 - Interval for event codes */
+ Aword rulmin, rulmax; /* 22 - Interval for rule codes */
+ Aword maxscore; /* 24 - Maximum score */
+ Aaddr scores; /* 25 - Score table */
+ Aaddr freq; /* 26 - Address to Char freq's for coding */
+ Aword acdcrc; /* 27 - Checksum for acd code (excl. hdr) */
+ Aword txtcrc; /* 28 - Checksum for text data file */
} PACKED_STRUCT;
-#include "common/pack-end.h" // END STRUCT PACKING
+#include "common/pack-end.h" // END STRUCT PACKING
/* Error message numbers */
typedef enum MsgKind {
- M_HUH, /* Obsolete */
- M_WHAT,
- M_WHAT_ALL,
- M_WHAT_IT,
- M_WHAT_THEM,
- M_MULTIPLE,
- M_WANT,
- M_NOUN,
- M_AFTER_BUT,
- M_BUT_ALL,
- M_NOT_MUCH,
- M_WHICH_ONE,
- M_NO_SUCH,
- M_NO_WAY,
- M_CANT0,
- M_CANT,
- M_NOTHING, /* Obsolete */
- M_SEEOBJ1,
- M_SEEOBJ2,
- M_SEEOBJ3,
- M_SEEOBJ4,
- M_SEEACT,
- M_CONTAINS1,
- M_CONTAINS2,
- M_CONTAINS3,
- M_CONTAINS4,
- M_CONTAINS5,
- M_EMPTY1,
- M_EMPTY2,
- M_SCORE1,
- M_SCORE2,
- M_UNKNOWN_WORD,
- M_MORE,
- M_AGAIN,
- M_SAVEWHERE,
- M_SAVEOVERWRITE,
- M_SAVEFAILED,
- M_SAVEMISSING,
- M_SAVEVERS,
- M_SAVENAME,
- M_RESTOREFROM,
- M_REALLY, /* CHANGED: v2.7 from M_RESTART */
- M_QUITACTION, /* INTRODUCED: v2.7, so M_ARTICLE moved */
- M_ARTICLE, /* INTRODUCED: v2.6 but replaced the M_NOMSG*/
- MSGMAX
+ M_HUH, /* Obsolete */
+ M_WHAT,
+ M_WHAT_ALL,
+ M_WHAT_IT,
+ M_WHAT_THEM,
+ M_MULTIPLE,
+ M_WANT,
+ M_NOUN,
+ M_AFTER_BUT,
+ M_BUT_ALL,
+ M_NOT_MUCH,
+ M_WHICH_ONE,
+ M_NO_SUCH,
+ M_NO_WAY,
+ M_CANT0,
+ M_CANT,
+ M_NOTHING, /* Obsolete */
+ M_SEEOBJ1,
+ M_SEEOBJ2,
+ M_SEEOBJ3,
+ M_SEEOBJ4,
+ M_SEEACT,
+ M_CONTAINS1,
+ M_CONTAINS2,
+ M_CONTAINS3,
+ M_CONTAINS4,
+ M_CONTAINS5,
+ M_EMPTY1,
+ M_EMPTY2,
+ M_SCORE1,
+ M_SCORE2,
+ M_UNKNOWN_WORD,
+ M_MORE,
+ M_AGAIN,
+ M_SAVEWHERE,
+ M_SAVEOVERWRITE,
+ M_SAVEFAILED,
+ M_SAVEMISSING,
+ M_SAVEVERS,
+ M_SAVENAME,
+ M_RESTOREFROM,
+ M_REALLY, /* CHANGED: v2.7 from M_RESTART */
+ M_QUITACTION, /* INTRODUCED: v2.7, so M_ARTICLE moved */
+ M_ARTICLE, /* INTRODUCED: v2.6 but replaced the M_NOMSG*/
+ MSGMAX
} MsgKind;
#define M_ARTICLE26 M_QUITACTION
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 05e5233..6f65ddf 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -39,7 +39,7 @@ namespace Alan2 {
Alan2 *g_vm = nullptr;
Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
- vm_exited_cleanly(false) {
+ vm_exited_cleanly(false) {
g_vm = this;
}
@@ -62,7 +62,7 @@ void Alan2::initialize() {
g_vm->glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
- winmethod_Fixed, 1, wintype_TextGrid, 0);
+ winmethod_Fixed, 1, wintype_TextGrid, 0);
g_vm->glk_set_window(glkMainWin);
// Set up the code file to point to the already opened game file
@@ -106,30 +106,30 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
// Save actors
for (i = ACTMIN; i <= ACTMAX; ++i) {
- syncVal(s, &acts[i-ACTMIN].loc);
- syncVal(s, &acts[i-ACTMIN].script);
- syncVal(s, &acts[i-ACTMIN].step);
- syncVal(s, &acts[i-ACTMIN].count);
+ syncVal(s, &acts[i - ACTMIN].loc);
+ syncVal(s, &acts[i - ACTMIN].script);
+ syncVal(s, &acts[i - ACTMIN].step);
+ syncVal(s, &acts[i - ACTMIN].count);
- if (acts[i-ACTMIN].atrs) {
- for (atr = (AtrElem *)addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); ++atr)
+ if (acts[i - ACTMIN].atrs) {
+ for (atr = (AtrElem *)addrTo(acts[i - ACTMIN].atrs); !endOfTable(atr); ++atr)
syncVal(s, &atr->val);
}
}
// Sync locations
for (i = LOCMIN; i <= LOCMAX; ++i) {
- syncVal(s, &locs[i-LOCMIN].describe);
- if (locs[i-LOCMIN].atrs)
- for (atr = (AtrElem *)addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++)
+ syncVal(s, &locs[i - LOCMIN].describe);
+ if (locs[i - LOCMIN].atrs)
+ for (atr = (AtrElem *)addrTo(locs[i - LOCMIN].atrs); !endOfTable(atr); atr++)
syncVal(s, &atr->val);
}
// Sync objects
for (i = OBJMIN; i <= OBJMAX; ++i) {
- syncVal(s, &objs[i-OBJMIN].loc);
- if (objs[i-OBJMIN].atrs)
- for (atr = (AtrElem *)addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++)
+ syncVal(s, &objs[i - OBJMIN].loc);
+ if (objs[i - OBJMIN].atrs)
+ for (atr = (AtrElem *)addrTo(objs[i - OBJMIN].atrs); !endOfTable(atr); atr++)
syncVal(s, &atr->val);
}
diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h
index 8960648..ac67364 100644
--- a/engines/glk/alan2/alan2.h
+++ b/engines/glk/alan2/alan2.h
@@ -67,7 +67,9 @@ public:
/**
* Returns the running interpreter type
*/
- virtual InterpreterType getInterpreterType() const override { return INTERPRETER_ALAN2; }
+ virtual InterpreterType getInterpreterType() const override {
+ return INTERPRETER_ALAN2;
+ }
/**
* Load a savegame from the passed Quetzal file chunk stream
diff --git a/engines/glk/alan2/alan_version.cpp b/engines/glk/alan2/alan_version.cpp
index d3e1b9d..5e88ba3 100644
--- a/engines/glk/alan2/alan_version.cpp
+++ b/engines/glk/alan2/alan_version.cpp
@@ -26,20 +26,20 @@ namespace Glk {
namespace Alan2 {
Product alan = {
- "Alan",
- "Adventure Language System",
- "Alan 2.8(6)",
- "Alan 2.8(6) -- Adventure Language System (2001-07-13 14:35)",
- "2001-07-13",
- "14:35:07",
- "Thomas Nilsson",
- "",
- "cygwin",
- {"2.8(6)", 2, 8, 6, 995034907, ""}
+ "Alan",
+ "Adventure Language System",
+ "Alan 2.8(6)",
+ "Alan 2.8(6) -- Adventure Language System (2001-07-13 14:35)",
+ "2001-07-13",
+ "14:35:07",
+ "Thomas Nilsson",
+ "",
+ "cygwin",
+ {"2.8(6)", 2, 8, 6, 995034907, ""}
};
static char *alanId =
- "@(#)RELEASE ";
+ "@(#)RELEASE ";
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/args.cpp b/engines/glk/alan2/args.cpp
index 2f760ae..dc34949 100644
--- a/engines/glk/alan2/args.cpp
+++ b/engines/glk/alan2/args.cpp
@@ -33,26 +33,26 @@ namespace Alan2 {
static void switches(unsigned argc, char *argv[]) {
}
-void args(int argc, char * argv[]) {
- char *prgnam;
+void args(int argc, char *argv[]) {
+ char *prgnam;
- if ((prgnam = strrchr(argv[0], '\\')) == NULL
- && (prgnam = strrchr(argv[0], '/')) == NULL
- && (prgnam = strrchr(argv[0], ':')) == NULL)
- prgnam = argv[0];
- else
- prgnam++;
- if (strlen(prgnam) > 4
- && (strcmp(&prgnam[strlen(prgnam)-4], ".EXE") == 0
- || strcmp(&prgnam[strlen(prgnam)-4], ".exe") == 0))
- prgnam[strlen(prgnam)-4] = '\0';
- /* Now look at the switches and arguments */
- switches(argc, argv);
- if (advnam[0] == '\0')
- /* No game given, try program name */
- if (stricmp(prgnam, PROGNAME) != 0
- && strstr(prgnam, PROGNAME) == 0)
- advnam = strdup(argv[0]);
+ if ((prgnam = strrchr(argv[0], '\\')) == NULL
+ && (prgnam = strrchr(argv[0], '/')) == NULL
+ && (prgnam = strrchr(argv[0], ':')) == NULL)
+ prgnam = argv[0];
+ else
+ prgnam++;
+ if (strlen(prgnam) > 4
+ && (strcmp(&prgnam[strlen(prgnam) - 4], ".EXE") == 0
+ || strcmp(&prgnam[strlen(prgnam) - 4], ".exe") == 0))
+ prgnam[strlen(prgnam) - 4] = '\0';
+ /* Now look at the switches and arguments */
+ switches(argc, argv);
+ if (advnam[0] == '\0')
+ /* No game given, try program name */
+ if (stricmp(prgnam, PROGNAME) != 0
+ && strstr(prgnam, PROGNAME) == 0)
+ advnam = strdup(argv[0]);
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index 3c67fbe..f7075ca 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -35,227 +35,228 @@ namespace Glk {
namespace Alan2 {
static void showatrs(Aword atradr) {
- AtrElem *at;
- int i;
- char str[80];
-
- if (atradr == 0) return;
-
- i = 1;
- for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) {
- sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr));
- output(str);
- i++;
- }
+ AtrElem *at;
+ int i;
+ char str[80];
+
+ if (atradr == 0) return;
+
+ i = 1;
+ for (at = (AtrElem *) addrTo(atradr); !endOfTable(at); at++) {
+ sprintf(str, "$i%3ld: %ld (%s)", (long) i, (unsigned long) at->val, (char *) addrTo(at->stradr));
+ output(str);
+ i++;
+ }
}
static void showobjs() {
- char str[80];
- int obj;
-
- output("OBJECTS:");
- for (obj = OBJMIN; obj <= OBJMAX; obj++) {
- sprintf(str, "$i%3ld: ", (long) obj);
- output(str);
- say(obj);
- }
+ char str[80];
+ int obj;
+
+ output("OBJECTS:");
+ for (obj = OBJMIN; obj <= OBJMAX; obj++) {
+ sprintf(str, "$i%3ld: ", (long) obj);
+ output(str);
+ say(obj);
+ }
}
static void showobj(int obj) {
- char str[80];
+ char str[80];
#define OBJ (obj-OBJMIN)
- if (!isObj(obj)) {
- sprintf(str, "Object number out of range. Between %ld and %ld, please.", (unsigned long) OBJMIN, (unsigned long) OBJMAX);
- output(str);
- return;
- }
-
- sprintf(str, "OBJECT %d :", obj);
- output(str);
- say(obj);
-
- sprintf(str, "$iLocation = %ld", (unsigned long) where(obj));
- output(str);
- if (isLoc(objs[OBJ].loc))
- say(objs[OBJ].loc);
- else if (isCnt(objs[OBJ].loc)) {
- if (isObj(objs[OBJ].loc)) {
- output("in");
- say(objs[OBJ].loc);
- } else if (isAct(objs[OBJ].loc)) {
- output("carried by");
- say(objs[OBJ].loc);
- } else
- interpret(cnts[objs[OBJ].loc-CNTMIN].nam);
- } else if (objs[OBJ].loc == 0)
- output("nowhere");
- else
- output("Illegal location!");
-
-
- output("$iAttributes =");
- showatrs(objs[OBJ].atrs);
+ if (!isObj(obj)) {
+ sprintf(str, "Object number out of range. Between %ld and %ld, please.", (unsigned long) OBJMIN, (unsigned long) OBJMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "OBJECT %d :", obj);
+ output(str);
+ say(obj);
+
+ sprintf(str, "$iLocation = %ld", (unsigned long) where(obj));
+ output(str);
+ if (isLoc(objs[OBJ].loc))
+ say(objs[OBJ].loc);
+ else if (isCnt(objs[OBJ].loc)) {
+ if (isObj(objs[OBJ].loc)) {
+ output("in");
+ say(objs[OBJ].loc);
+ } else if (isAct(objs[OBJ].loc)) {
+ output("carried by");
+ say(objs[OBJ].loc);
+ } else
+ interpret(cnts[objs[OBJ].loc - CNTMIN].nam);
+ } else if (objs[OBJ].loc == 0)
+ output("nowhere");
+ else
+ output("Illegal location!");
+
+
+ output("$iAttributes =");
+ showatrs(objs[OBJ].atrs);
#undef OBJ
}
static void showcnts() {
- char str[80];
- int cnt;
+ char str[80];
+ int cnt;
#define CNT (cnt-CNTMIN)
- output("CONTAINERS:");
- for (cnt = CNTMIN; cnt <= CNTMAX; cnt++) {
- sprintf(str, "$i%3ld: ", (long) cnt);
- output(str);
- if (cnts[CNT].nam != 0)
- interpret(cnts[CNT].nam);
- if (cnts[CNT].parent != 0)
- say(cnts[CNT].parent);
- }
+ output("CONTAINERS:");
+ for (cnt = CNTMIN; cnt <= CNTMAX; cnt++) {
+ sprintf(str, "$i%3ld: ", (long) cnt);
+ output(str);
+ if (cnts[CNT].nam != 0)
+ interpret(cnts[CNT].nam);
+ if (cnts[CNT].parent != 0)
+ say(cnts[CNT].parent);
+ }
#undef CNT
}
static void showcnt(int cnt) {
- char str[80];
- int i;
- Abool found = FALSE;
+ char str[80];
+ int i;
+ Abool found = FALSE;
#define CNT (cnt-CNTMIN)
- if (cnt < CNTMIN || cnt > CNTMAX) {
- sprintf(str, "Container number out of range. Between %ld and %ld, please.", (unsigned long) CNTMIN, (unsigned long) CNTMAX);
- output(str);
- return;
- }
-
- sprintf(str, "CONTAINER %d :", cnt);
- output(str);
- if (cnts[CNT].nam != 0)
- interpret(cnts[CNT].nam);
- if (cnts[CNT].parent != 0) {
- cnt = cnts[CNT].parent;
- say(cnt);
- sprintf(str, "$iLocation = %ld", (unsigned long) where(cnt));
- output(str);
- }
- output("$iContains ");
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (in(i, cnt)) { /* Yes, it's in this container */
- if (!found) {
- output("$n");
- found = TRUE;
- }
- sprintf(str, "$t$t%d: ", i);
- output(str);
- say(i);
- }
- }
- if (!found)
- output("nothing");
+ if (cnt < CNTMIN || cnt > CNTMAX) {
+ sprintf(str, "Container number out of range. Between %ld and %ld, please.", (unsigned long) CNTMIN, (unsigned long) CNTMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "CONTAINER %d :", cnt);
+ output(str);
+ if (cnts[CNT].nam != 0)
+ interpret(cnts[CNT].nam);
+ if (cnts[CNT].parent != 0) {
+ cnt = cnts[CNT].parent;
+ say(cnt);
+ sprintf(str, "$iLocation = %ld", (unsigned long) where(cnt));
+ output(str);
+ }
+ output("$iContains ");
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (in(i, cnt)) { /* Yes, it's in this container */
+ if (!found) {
+ output("$n");
+ found = TRUE;
+ }
+ sprintf(str, "$t$t%d: ", i);
+ output(str);
+ say(i);
+ }
+ }
+ if (!found)
+ output("nothing");
#undef CNT
}
static void showlocs() {
- char str[80];
- int loc;
-
- output("LOCATIONS:");
- for (loc = LOCMIN; loc <= LOCMAX; loc++) {
- sprintf(str, "$i%3ld: ", (long) loc);
- output(str);
- say(loc);
- }
+ char str[80];
+ int loc;
+
+ output("LOCATIONS:");
+ for (loc = LOCMIN; loc <= LOCMAX; loc++) {
+ sprintf(str, "$i%3ld: ", (long) loc);
+ output(str);
+ say(loc);
+ }
}
static void showloc(int loc) {
- char str[80];
+ char str[80];
-
- if (!isLoc(loc)) {
- sprintf(str, "Location number out of range. Between %ld and %ld, please.", (unsigned long) LOCMIN, (unsigned long) LOCMAX);
- output(str);
- return;
- }
- sprintf(str, "LOCATION %d :", loc);
- output(str);
- say(loc);
+ if (!isLoc(loc)) {
+ sprintf(str, "Location number out of range. Between %ld and %ld, please.", (unsigned long) LOCMIN, (unsigned long) LOCMAX);
+ output(str);
+ return;
+ }
- output("$iAttributes =");
- showatrs(locs[loc-LOCMIN].atrs);
+ sprintf(str, "LOCATION %d :", loc);
+ output(str);
+ say(loc);
+
+ output("$iAttributes =");
+ showatrs(locs[loc - LOCMIN].atrs);
}
static void showacts() {
- char str[80];
- int act;
-
- output("ACTORS:");
- for (act = ACTMIN; act <= ACTMAX; act++) {
- sprintf(str, "$i%3ld:", (long) act);
- output(str);
- say(act);
- }
+ char str[80];
+ int act;
+
+ output("ACTORS:");
+ for (act = ACTMIN; act <= ACTMAX; act++) {
+ sprintf(str, "$i%3ld:", (long) act);
+ output(str);
+ say(act);
+ }
}
static void showact(int act) {
- char str[80];
- Boolean oldstp;
-
- if (!isAct(act)) {
- sprintf(str, "Actor number out of range. Between %ld and %ld, please.", (unsigned long) ACTMIN, (unsigned long) ACTMAX);
- output(str);
- return;
- }
-
- sprintf(str, "ACTOR %d :", act);
- output(str);
- oldstp = stpflg; stpflg = FALSE; /* Make sure not to trace this! */
- say(act);
- stpflg = oldstp;
-
- sprintf(str, "$iLocation = %ld", (unsigned long) acts[act-ACTMIN].loc);
- output(str);
- if (isLoc(acts[act-ACTMIN].loc))
- say(acts[act-ACTMIN].loc);
- else if (acts[act-ACTMIN].loc == 0)
- output("nowhere");
- else
- output("Illegal location!");
-
- sprintf(str, "$iScript = %ld", (unsigned long) acts[act-ACTMIN].script);
- output(str);
-
- sprintf(str, "$iStep = %ld", (unsigned long) acts[act-ACTMIN].step);
- output(str);
-
- output("$iAttributes =");
- showatrs(acts[act-ACTMIN].atrs);
+ char str[80];
+ Boolean oldstp;
+
+ if (!isAct(act)) {
+ sprintf(str, "Actor number out of range. Between %ld and %ld, please.", (unsigned long) ACTMIN, (unsigned long) ACTMAX);
+ output(str);
+ return;
+ }
+
+ sprintf(str, "ACTOR %d :", act);
+ output(str);
+ oldstp = stpflg;
+ stpflg = FALSE; /* Make sure not to trace this! */
+ say(act);
+ stpflg = oldstp;
+
+ sprintf(str, "$iLocation = %ld", (unsigned long) acts[act - ACTMIN].loc);
+ output(str);
+ if (isLoc(acts[act - ACTMIN].loc))
+ say(acts[act - ACTMIN].loc);
+ else if (acts[act - ACTMIN].loc == 0)
+ output("nowhere");
+ else
+ output("Illegal location!");
+
+ sprintf(str, "$iScript = %ld", (unsigned long) acts[act - ACTMIN].script);
+ output(str);
+
+ sprintf(str, "$iStep = %ld", (unsigned long) acts[act - ACTMIN].step);
+ output(str);
+
+ output("$iAttributes =");
+ showatrs(acts[act - ACTMIN].atrs);
}
static void showevts() {
- int evt, i;
- char str[80];
- Boolean scheduled;
-
- output("EVENTS:");
- for (evt = EVTMIN; evt <= EVTMAX; evt++) {
- sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt-EVTMIN].stradr));
- output(str);
- scheduled = FALSE;
- for (i = 0; i < etop; i++)
- if ((scheduled = (eventq[i].event == evt)))
- break;
- if (scheduled) {
- sprintf(str, "Scheduled for +%d, at ", eventq[i].time-cur.tick);
- output(str);
- say(eventq[i].where);
- } else
- output("Not scheduled.");
- }
+ int evt, i;
+ char str[80];
+ Boolean scheduled;
+
+ output("EVENTS:");
+ for (evt = EVTMIN; evt <= EVTMAX; evt++) {
+ sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt - EVTMIN].stradr));
+ output(str);
+ scheduled = FALSE;
+ for (i = 0; i < etop; i++)
+ if ((scheduled = (eventq[i].event == evt)))
+ break;
+ if (scheduled) {
+ sprintf(str, "Scheduled for +%d, at ", eventq[i].time - cur.tick);
+ output(str);
+ say(eventq[i].where);
+ } else
+ output("Not scheduled.");
+ }
}
@@ -263,43 +264,46 @@ static Boolean trc, stp;
static int loc;
void saveInfo() {
- /* Save some important things */
- trc = trcflg; trcflg = FALSE;
- stp = stpflg; stpflg = FALSE;
- loc = cur.loc; cur.loc = where(HERO);
+ /* Save some important things */
+ trc = trcflg;
+ trcflg = FALSE;
+ stp = stpflg;
+ stpflg = FALSE;
+ loc = cur.loc;
+ cur.loc = where(HERO);
}
void restoreInfo() {
- /* Restore! */
- trcflg = trc;
- stpflg = stp;
- cur.loc = loc;
+ /* Restore! */
+ trcflg = trc;
+ stpflg = stp;
+ cur.loc = loc;
}
void debug() {
- char buf[256];
- char c;
- int i;
-
- saveInfo();
- while (TRUE) {
- if (anyOutput)
- para();
- do {
- output("ABUG> ");
- (void)readline(buf);
-
- lin = 1;
- c = buf[0];
- i = 0;
- sscanf(&buf[1], "%d", &i);
- } while (buf && c == '\0');
-
- switch (toUpper(c)) {
- case 'H':
- case '?':
- output(alan.longHeader);
- output("$nABUG Commands:\
+ char buf[256];
+ char c;
+ int i;
+
+ saveInfo();
+ while (TRUE) {
+ if (anyOutput)
+ para();
+ do {
+ output("ABUG> ");
+ (void)readline(buf);
+
+ lin = 1;
+ c = buf[0];
+ i = 0;
+ sscanf(&buf[1], "%d", &i);
+ } while (buf && c == '\0');
+
+ switch (toUpper(c)) {
+ case 'H':
+ case '?':
+ output(alan.longHeader);
+ output("$nABUG Commands:\
$iO [n] -- show object[s]\
$iA [n] -- show actor[s]\
$iL [n] -- show location[s]\
@@ -310,58 +314,58 @@ void debug() {
$iS -- toggle step mode\
$iX -- exit debug mode\
$iQ -- quit game");
- break;
- case 'Q':
- terminate(0);
- case 'X':
- dbgflg = FALSE; /* Fall through to 'G' */
- case 'G':
- restoreInfo();
- return;
- case 'O':
- if (i == 0)
- showobjs();
- else
- showobj(i);
- break;
- case 'C':
- if (i == 0)
- showcnts();
- else
- showcnt(i);
- break;
- case 'A':
- if (i == 0)
- showacts();
- else
- showact(i);
- break;
- case 'L':
- if (i == 0)
- showlocs();
- else
- showloc(i);
- break;
- case 'E':
- showevts();
- break;
- case 'S':
- if ((stp = !stp))
- printf("Step on.");
- else
- printf("Step off.");
- break;
- case 'T':
- if ((trc = !trc))
- printf("Trace on.");
- else
- printf("Trace off.");
- break;
- default:
- output("Unknown ABUG command. ? for help.");
- break;
- }
- }
+ break;
+ case 'Q':
+ terminate(0);
+ case 'X':
+ dbgflg = FALSE; /* Fall through to 'G' */
+ case 'G':
+ restoreInfo();
+ return;
+ case 'O':
+ if (i == 0)
+ showobjs();
+ else
+ showobj(i);
+ break;
+ case 'C':
+ if (i == 0)
+ showcnts();
+ else
+ showcnt(i);
+ break;
+ case 'A':
+ if (i == 0)
+ showacts();
+ else
+ showact(i);
+ break;
+ case 'L':
+ if (i == 0)
+ showlocs();
+ else
+ showloc(i);
+ break;
+ case 'E':
+ showevts();
+ break;
+ case 'S':
+ if ((stp = !stp))
+ printf("Step on.");
+ else
+ printf("Step off.");
+ break;
+ case 'T':
+ if ((trc = !trc))
+ printf("Trace on.");
+ else
+ printf("Trace off.");
+ break;
+ default:
+ output("Unknown ABUG command. ? for help.");
+ break;
+ }
+ }
}
@@ -374,16 +378,16 @@ void debug() {
*/
void debugsay(int item) {
- saveInfo();
- needsp = FALSE;
- col = 1;
- if (item == 0)
- printf("$null$");
- else
- say(item);
- needsp = FALSE;
- col = 1;
- restoreInfo();
+ saveInfo();
+ needsp = FALSE;
+ col = 1;
+ if (item == 0)
+ printf("$null$");
+ else
+ say(item);
+ needsp = FALSE;
+ col = 1;
+ restoreInfo();
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
index f1ec3db..2955c37 100644
--- a/engines/glk/alan2/decode.cpp
+++ b/engines/glk/alan2/decode.cpp
@@ -28,94 +28,94 @@ namespace Glk {
namespace Alan2 {
/* Bit output */
-static int decodeBuffer; /* Bits to be input */
-static int bitsToGo; /* Bits still in buffer */
-static int garbageBits; /* Bits past EOF */
+static int decodeBuffer; /* Bits to be input */
+static int bitsToGo; /* Bits still in buffer */
+static int garbageBits; /* Bits past EOF */
static int inputBit() {
- int bit;
-
- if (!bitsToGo) { /* More bits available ? */
- decodeBuffer = txtfil->readByte(); /* No, so get more */
- if (decodeBuffer == EOF) {
- garbageBits++;
- if (garbageBits > VALUEBITS-2)
- syserr("Error in encoded data file.");
- } else
- bitsToGo = 8; /* Another Char, 8 new bits */
- }
- bit = decodeBuffer&1; /* Get next bit */
- decodeBuffer = decodeBuffer>>1; /* and remove it */
- bitsToGo--;
- return bit;
+ int bit;
+
+ if (!bitsToGo) { /* More bits available ? */
+ decodeBuffer = txtfil->readByte(); /* No, so get more */
+ if (decodeBuffer == EOF) {
+ garbageBits++;
+ if (garbageBits > VALUEBITS - 2)
+ syserr("Error in encoded data file.");
+ } else
+ bitsToGo = 8; /* Another Char, 8 new bits */
+ }
+ bit = decodeBuffer & 1; /* Get next bit */
+ decodeBuffer = decodeBuffer >> 1; /* and remove it */
+ bitsToGo--;
+ return bit;
}
/* Current state of decoding */
-static CodeValue value; /* Currently seen code value */
-static CodeValue low, high; /* Current code region */
+static CodeValue value; /* Currently seen code value */
+static CodeValue low, high; /* Current code region */
void startDecoding() {
- int i;
+ int i;
- bitsToGo = 0;
- garbageBits = 0;
+ bitsToGo = 0;
+ garbageBits = 0;
- value = 0;
- for (i = 0; i < VALUEBITS; i++)
- value = 2*value + inputBit();
- low = 0;
- high = TOPVALUE;
+ value = 0;
+ for (i = 0; i < VALUEBITS; i++)
+ value = 2 * value + inputBit();
+ low = 0;
+ high = TOPVALUE;
}
int decodeChar() {
- long range;
- int f;
- int symbol;
-
- range = (long)(high-low) + 1;
- f = (((long)(value-low)+1)*freq[0]-1)/range;
-
- /* Find the symbol */
- for (symbol = 1; (int)freq[symbol] > f; symbol++);
-
- high = low + range*freq[symbol-1]/freq[0]-1;
- low = low + range*freq[symbol]/freq[0];
-
- for (;;) {
- if (high < HALF)
- ;
- else if (low >= HALF) {
- value = value - HALF;
- low = low - HALF;
- high = high - HALF;
- } else if (low >= ONEQUARTER && high < THREEQUARTER) {
- value = value - ONEQUARTER;
- low = low - ONEQUARTER;
- high = high - ONEQUARTER;
- } else
- break;
-
- /* Scale up the range */
- low = 2*low;
- high = 2*high+1;
- value = 2*value + inputBit();
- }
- return symbol-1;
+ long range;
+ int f;
+ int symbol;
+
+ range = (long)(high - low) + 1;
+ f = (((long)(value - low) + 1) * freq[0] - 1) / range;
+
+ /* Find the symbol */
+ for (symbol = 1; (int)freq[symbol] > f; symbol++);
+
+ high = low + range * freq[symbol - 1] / freq[0] - 1;
+ low = low + range * freq[symbol] / freq[0];
+
+ for (;;) {
+ if (high < HALF)
+ ;
+ else if (low >= HALF) {
+ value = value - HALF;
+ low = low - HALF;
+ high = high - HALF;
+ } else if (low >= ONEQUARTER && high < THREEQUARTER) {
+ value = value - ONEQUARTER;
+ low = low - ONEQUARTER;
+ high = high - ONEQUARTER;
+ } else
+ break;
+
+ /* Scale up the range */
+ low = 2 * low;
+ high = 2 * high + 1;
+ value = 2 * value + inputBit();
+ }
+ return symbol - 1;
}
/* Structure for saved decode info */
typedef struct DecodeInfo {
- long fpos;
- int buffer;
- int bits;
- CodeValue value;
- CodeValue high;
- CodeValue low;
+ long fpos;
+ int buffer;
+ int bits;
+ CodeValue value;
+ CodeValue high;
+ CodeValue low;
} DecodeInfo;
@@ -128,16 +128,16 @@ typedef struct DecodeInfo {
*/
void *pushDecode() {
- DecodeInfo *info;
-
- info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
- info->fpos = txtfil->pos();
- info->buffer = decodeBuffer;
- info->bits = bitsToGo;
- info->value = value;
- info->high = high;
- info->low = low;
- return(info);
+ DecodeInfo *info;
+
+ info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
+ info->fpos = txtfil->pos();
+ info->buffer = decodeBuffer;
+ info->bits = bitsToGo;
+ info->value = value;
+ info->high = high;
+ info->low = low;
+ return (info);
}
@@ -150,15 +150,15 @@ void *pushDecode() {
*/
void popDecode(void *i) {
- DecodeInfo *info = (DecodeInfo *) i;
- fseek(txtfil, info->fpos, 0);
- decodeBuffer = info->buffer;
- bitsToGo = info->bits;
- value = info->value;
- high = info->high;
- low = info->low;
-
- free(info);
+ DecodeInfo *info = (DecodeInfo *) i;
+ fseek(txtfil, info->fpos, 0);
+ decodeBuffer = info->buffer;
+ bitsToGo = info->bits;
+ value = info->value;
+ high = info->high;
+ low = info->low;
+
+ free(info);
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index 3cd16d8..f749425 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -54,55 +54,55 @@ void dscracts();
void print(Aword fpos, Aword len) {
- char str[2*WIDTH]; /* String buffer */
- int outlen = 0; /* Current output length */
- int ch;
- int i;
- long savfp; /* Temporary saved text file position */
- static Boolean printFlag = FALSE; /* Printing already? */
- Boolean savedPrintFlag = printFlag;
- void *info; /* Saved decoding info */
-
-
- if (len == 0) return;
-
- if (isHere(HERO)) { /* Check if the player will see it */
- if (printFlag) { /* Already printing? */
- /* Save current text file position and/or decoding info */
- if (header->pack)
- info = pushDecode();
- else
- savfp = ftell(txtfil);
- }
- printFlag = TRUE; /* We're printing now! */
- fseek(txtfil, fpos, 0); /* Position to start of text */
- if (header->pack)
- startDecoding();
- for (outlen = 0; outlen != (int)len; outlen = outlen + strlen(str)) {
- /* Fill the buffer from the beginning */
- for (i = 0; i <= WIDTH || (i > WIDTH && ch != ' '); i++) {
- if (outlen + i == (int)len) /* No more characters? */
- break;
- if (header->pack)
- ch = decodeChar();
- else
- ch = getc(txtfil);
- if (ch == EOFChar) /* Or end of text? */
- break;
- str[i] = ch;
- }
- str[i] = '\0';
- output(str);
- }
- /* And restore */
- printFlag = savedPrintFlag;
- if (printFlag) {
- if (header->pack)
- popDecode(info);
- else
- fseek(txtfil, savfp, 0);
- }
- }
+ char str[2 * WIDTH]; /* String buffer */
+ int outlen = 0; /* Current output length */
+ int ch;
+ int i;
+ long savfp; /* Temporary saved text file position */
+ static Boolean printFlag = FALSE; /* Printing already? */
+ Boolean savedPrintFlag = printFlag;
+ void *info; /* Saved decoding info */
+
+
+ if (len == 0) return;
+
+ if (isHere(HERO)) { /* Check if the player will see it */
+ if (printFlag) { /* Already printing? */
+ /* Save current text file position and/or decoding info */
+ if (header->pack)
+ info = pushDecode();
+ else
+ savfp = ftell(txtfil);
+ }
+ printFlag = TRUE; /* We're printing now! */
+ fseek(txtfil, fpos, 0); /* Position to start of text */
+ if (header->pack)
+ startDecoding();
+ for (outlen = 0; outlen != (int)len; outlen = outlen + strlen(str)) {
+ /* Fill the buffer from the beginning */
+ for (i = 0; i <= WIDTH || (i > WIDTH && ch != ' '); i++) {
+ if (outlen + i == (int)len) /* No more characters? */
+ break;
+ if (header->pack)
+ ch = decodeChar();
+ else
+ ch = getc(txtfil);
+ if (ch == EOFChar) /* Or end of text? */
+ break;
+ str[i] = ch;
+ }
+ str[i] = '\0';
+ output(str);
+ }
+ /* And restore */
+ printFlag = savedPrintFlag;
+ if (printFlag) {
+ if (header->pack)
+ popDecode(info);
+ else
+ fseek(txtfil, savfp, 0);
+ }
+ }
}
void sys(Aword fpos, Aword len) {
@@ -111,130 +111,131 @@ void sys(Aword fpos, Aword len) {
#else
char *command;
- getstr(fpos, len); /* Returns address to string on stack */
- command = (char *)pop();
- int tmp = system(command);
- free(command);
+ getstr(fpos, len); /* Returns address to string on stack */
+ command = (char *)pop();
+ int tmp = system(command);
+ free(command);
#endif
}
void getstr(Aword fpos, Aword len) {
- char *buf = (char *)allocate(len+1);
+ char *buf = (char *)allocate(len + 1);
- push((Aptr) buf); /* Push the address to the string */
- fseek(txtfil, fpos, 0); /* Position to start of text */
- if (header->pack)
- startDecoding();
- while (len--)
- if (header->pack)
- *(buf++) = decodeChar();
- else
- *(buf++) = getc(txtfil);
- *buf = '\0';
+ push((Aptr) buf); /* Push the address to the string */
+ fseek(txtfil, fpos, 0); /* Position to start of text */
+ if (header->pack)
+ startDecoding();
+ while (len--)
+ if (header->pack)
+ *(buf++) = decodeChar();
+ else
+ *(buf++) = getc(txtfil);
+ *buf = '\0';
}
void score(Aword sc) {
- char buf[80];
-
- if (sc == 0) {
- prmsg(M_SCORE1);
- sprintf(buf, "%d", cur.score);
- output(buf);
- prmsg(M_SCORE2);
- sprintf(buf, "%ld.", (unsigned long) header->maxscore);
- output(buf);
- } else {
- cur.score += scores[sc-1];
- scores[sc-1] = 0;
- }
+ char buf[80];
+
+ if (sc == 0) {
+ prmsg(M_SCORE1);
+ sprintf(buf, "%d", cur.score);
+ output(buf);
+ prmsg(M_SCORE2);
+ sprintf(buf, "%ld.", (unsigned long) header->maxscore);
+ output(buf);
+ } else {
+ cur.score += scores[sc - 1];
+ scores[sc - 1] = 0;
+ }
}
void visits(Aword v) {
- cur.visits = v;
+ cur.visits = v;
}
Boolean confirm(MsgKind msgno) {
- char buf[80];
+ char buf[80];
- /* This is a bit of a hack since we really want to compare the input,
- it could be affirmative, but for now any input is NOT! */
- prmsg(msgno);
+ /* This is a bit of a hack since we really want to compare the input,
+ it could be affirmative, but for now any input is NOT! */
+ prmsg(msgno);
- if (!readline(buf)) return TRUE;
- col = 1;
+ if (!readline(buf)) return TRUE;
+ col = 1;
- return (buf[0] == '\0');
+ return (buf[0] == '\0');
}
void quit() {
- char buf[80];
- char choices[10];
-
- para();
- while (!g_vm->shouldQuit()) {
- col = 1;
- statusline();
- prmsg(M_QUITACTION);
- if (!readline(buf)) terminate(0);
+ char buf[80];
+ char choices[10];
- if (strcmp(buf, "restart") == 0)
- //longjmp(restart_label, TRUE);
- ::error("TODO: restart");
- else if (strcmp(buf, "restore") == 0) {
- restore();
- return;
- } else if (strcmp(buf, "quit") == 0)
- terminate(0);
- }
- syserr("Fallthrough in QUIT");
+ para();
+ while (!g_vm->shouldQuit()) {
+ col = 1;
+ statusline();
+ prmsg(M_QUITACTION);
+ if (!readline(buf)) terminate(0);
+
+ if (strcmp(buf, "restart") == 0)
+ //longjmp(restart_label, TRUE);
+ ::error("TODO: restart");
+ else if (strcmp(buf, "restore") == 0) {
+ restore();
+ return;
+ } else if (strcmp(buf, "quit") == 0)
+ terminate(0);
+ }
+ syserr("Fallthrough in QUIT");
}
void restart() {
- para();
- if (confirm(M_REALLY)) {
- //longjmp(restart_label, TRUE);
- ::error("TODO: restart");
- } else
- return;
- syserr("Fallthrough in RESTART");
+ para();
+ if (confirm(M_REALLY)) {
+ //longjmp(restart_label, TRUE);
+ ::error("TODO: restart");
+ } else
+ return;
+ syserr("Fallthrough in RESTART");
}
void cancl(Aword evt) {
- int i;
-
- for(i = etop-1; i>=0; i--)
- if (eventq[i].event == evt) {
- while (i < etop-1) {
- eventq[i].event = eventq[i+1].event;
- eventq[i].time = eventq[i+1].time;
- eventq[i].where = eventq[i+1].where;
- i++;
- }
- etop--;
- return;
- }
-}
-
-void schedule(Aword evt, Aword whr, Aword aft) { int i;
- int time;
-
- cancl(evt);
- /* Check for overflow */
- if (etop == N_EVTS) syserr("Out of event space.");
-
- time = cur.tick+aft;
-
- /* Bubble this event down */
- for (i = etop; i >= 1 && eventq[i-1].time <= time; i--) {
- eventq[i].event = eventq[i-1].event;
- eventq[i].time = eventq[i-1].time;
- eventq[i].where = eventq[i-1].where;
- }
-
- eventq[i].time = time;
- eventq[i].where = whr;
- eventq[i].event = evt;
- etop++;
+ int i;
+
+ for (i = etop - 1; i >= 0; i--)
+ if (eventq[i].event == evt) {
+ while (i < etop - 1) {
+ eventq[i].event = eventq[i + 1].event;
+ eventq[i].time = eventq[i + 1].time;
+ eventq[i].where = eventq[i + 1].where;
+ i++;
+ }
+ etop--;
+ return;
+ }
+}
+
+void schedule(Aword evt, Aword whr, Aword aft) {
+ int i;
+ int time;
+
+ cancl(evt);
+ /* Check for overflow */
+ if (etop == N_EVTS) syserr("Out of event space.");
+
+ time = cur.tick + aft;
+
+ /* Bubble this event down */
+ for (i = etop; i >= 1 && eventq[i - 1].time <= time; i--) {
+ eventq[i].event = eventq[i - 1].event;
+ eventq[i].time = eventq[i - 1].time;
+ eventq[i].where = eventq[i - 1].where;
+ }
+
+ eventq[i].time = time;
+ eventq[i].where = whr;
+ eventq[i].event = evt;
+ etop++;
}
@@ -246,15 +247,15 @@ void schedule(Aword evt, Aword whr, Aword aft) { int i;
*/
static Aptr getatr(
- Aaddr atradr, /* IN - ACODE address to attribute table */
- Aaddr atr /* IN - The attribute to read */
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aaddr atr /* IN - The attribute to read */
) {
- AtrElem *at;
+ AtrElem *at;
- at = (AtrElem *) addrTo(atradr);
- return at[atr-1].val;
+ at = (AtrElem *) addrTo(atradr);
+ return at[atr - 1].val;
}
-
+
/*----------------------------------------------------------------------
@@ -264,14 +265,14 @@ static Aptr getatr(
*/
static void setatr(
- Aaddr atradr, /* IN - ACODE address to attribute table */
- Aword atr, /* IN - attribute code */
- Aword val /* IN - new value */
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aword atr, /* IN - attribute code */
+ Aword val /* IN - new value */
) {
- AtrElem *at;
-
- at = (AtrElem *) addrTo(atradr);
- at[atr-1].val = val;
+ AtrElem *at;
+
+ at = (AtrElem *) addrTo(atradr);
+ at[atr - 1].val = val;
}
@@ -282,30 +283,30 @@ static void setatr(
*/
static void makloc(Aword loc, Aword atr, Aword val) {
- setatr(locs[loc-LOCMIN].atrs, atr, val);
+ setatr(locs[loc - LOCMIN].atrs, atr, val);
}
static void makobj(Aword obj, Aword atr, Aword val) {
- setatr(objs[obj-OBJMIN].atrs, atr, val);
+ setatr(objs[obj - OBJMIN].atrs, atr, val);
}
static void makact(Aword act, Aword atr, Aword val) {
- setatr(acts[act-ACTMIN].atrs, atr, val);
+ setatr(acts[act - ACTMIN].atrs, atr, val);
}
void make(Aword id, Aword atr, Aword val) {
- char str[80];
-
- if (isObj(id))
- makobj(id, atr, val);
- else if (isLoc(id))
- makloc(id, atr, val);
- else if (isAct(id))
- makact(id, atr, val);
- else {
- sprintf(str, "Can't MAKE item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ char str[80];
+
+ if (isObj(id))
+ makobj(id, atr, val);
+ else if (isLoc(id))
+ makloc(id, atr, val);
+ else if (isAct(id))
+ makact(id, atr, val);
+ else {
+ sprintf(str, "Can't MAKE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
}
@@ -316,36 +317,36 @@ void make(Aword id, Aword atr, Aword val) {
*/
static void setloc(Aword loc, Aword atr, Aword val) {
- setatr(locs[loc-LOCMIN].atrs, atr, val);
- locs[loc-LOCMIN].describe = 0;
+ setatr(locs[loc - LOCMIN].atrs, atr, val);
+ locs[loc - LOCMIN].describe = 0;
}
static void setobj(Aword obj, Aword atr, Aword val) {
- setatr(objs[obj-OBJMIN].atrs, atr, val);
+ setatr(objs[obj - OBJMIN].atrs, atr, val);
}
static void setact(Aword act, Aword atr, Aword val) {
- setatr(acts[act-ACTMIN].atrs, atr, val);
+ setatr(acts[act - ACTMIN].atrs, atr, val);
}
void set(Aword id, Aword atr, Aword val) {
- char str[80];
-
- if (isObj(id))
- setobj(id, atr, val);
- else if (isLoc(id))
- setloc(id, atr, val);
- else if (isAct(id))
- setact(id, atr, val);
- else {
- sprintf(str, "Can't SET item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ char str[80];
+
+ if (isObj(id))
+ setobj(id, atr, val);
+ else if (isLoc(id))
+ setloc(id, atr, val);
+ else if (isAct(id))
+ setact(id, atr, val);
+ else {
+ sprintf(str, "Can't SET item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
}
void setstr(Aword id, Aword atr, Aword str) {
- free((char *)attribute(id, atr));
- set(id, atr, str);
+ free((char *)attribute(id, atr));
+ set(id, atr, str);
}
@@ -364,57 +365,57 @@ void setstr(Aword id, Aword atr, Aword str) {
*/
static void incratr(
- Aaddr atradr, /* IN - ACODE address to attribute table */
- Aword atr, /* IN - attribute code */
- Aword step /* IN - step to increment by */
+ Aaddr atradr, /* IN - ACODE address to attribute table */
+ Aword atr, /* IN - attribute code */
+ Aword step /* IN - step to increment by */
) {
- AtrElem *at;
-
- at = (AtrElem *) addrTo(atradr);
- at[atr-1].val += step;
+ AtrElem *at;
+
+ at = (AtrElem *) addrTo(atradr);
+ at[atr - 1].val += step;
}
static void incrloc(Aword loc, Aword atr, Aword step) {
- incratr(locs[loc-LOCMIN].atrs, atr, step);
- locs[loc-LOCMIN].describe = 0;
+ incratr(locs[loc - LOCMIN].atrs, atr, step);
+ locs[loc - LOCMIN].describe = 0;
}
static void incrobj(Aword obj, Aword atr, Aword step) {
- incratr(objs[obj-OBJMIN].atrs, atr, step);
+ incratr(objs[obj - OBJMIN].atrs, atr, step);
}
static void incract(Aword act, Aword atr, Aword step) {
- incratr(acts[act-ACTMIN].atrs, atr, step);
+ incratr(acts[act - ACTMIN].atrs, atr, step);
}
void incr(Aword id, Aword atr, Aword step) {
- char str[80];
-
- if (isObj(id))
- incrobj(id, atr, step);
- else if (isLoc(id))
- incrloc(id, atr, step);
- else if (isAct(id))
- incract(id, atr, step);
- else {
- sprintf(str, "Can't INCR item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ char str[80];
+
+ if (isObj(id))
+ incrobj(id, atr, step);
+ else if (isLoc(id))
+ incrloc(id, atr, step);
+ else if (isAct(id))
+ incract(id, atr, step);
+ else {
+ sprintf(str, "Can't INCR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
}
void decr(Aword id, Aword atr, Aword step) {
- char str[80];
-
- if (isObj(id))
- incrobj(id, atr, -step);
- else if (isLoc(id))
- incrloc(id, atr, -step);
- else if (isAct(id))
- incract(id, atr, -step);
- else {
- sprintf(str, "Can't DECR item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ char str[80];
+
+ if (isObj(id))
+ incrobj(id, atr, -step);
+ else if (isLoc(id))
+ incrloc(id, atr, -step);
+ else if (isAct(id))
+ incract(id, atr, -step);
+ else {
+ sprintf(str, "Can't DECR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
}
@@ -425,49 +426,49 @@ void decr(Aword id, Aword atr, Aword step) {
*/
static Aptr locatr(Aword loc, Aword atr) {
- return getatr(locs[loc-LOCMIN].atrs, atr);
+ return getatr(locs[loc - LOCMIN].atrs, atr);
}
static Aptr objatr(Aword obj, Aword atr) {
- return getatr(objs[obj-OBJMIN].atrs, atr);
+ return getatr(objs[obj - OBJMIN].atrs, atr);
}
static Aptr actatr(Aword act, Aword atr) {
- return getatr(acts[act-ACTMIN].atrs, atr);
+ return getatr(acts[act - ACTMIN].atrs, atr);
}
static Aptr litatr(Aword lit, Aword atr) {
- char str[80];
+ char str[80];
- if (atr == 1)
- return litValues[lit-LITMIN].value;
- else {
- sprintf(str, "Unknown attribute for literal (%ld).", (unsigned long) atr);
- syserr(str);
- }
- return (Aptr)EOF;
+ if (atr == 1)
+ return litValues[lit - LITMIN].value;
+ else {
+ sprintf(str, "Unknown attribute for literal (%ld).", (unsigned long) atr);
+ syserr(str);
+ }
+ return (Aptr)EOF;
}
Aptr attribute(Aword id, Aword atr) {
- char str[80];
-
- if (isObj(id))
- return objatr(id, atr);
- else if (isLoc(id))
- return locatr(id, atr);
- else if (isAct(id))
- return actatr(id, atr);
- else if (isLit(id))
- return litatr(id, atr);
- else {
- sprintf(str, "Can't ATTRIBUTE item (%ld).", (unsigned long) id);
- syserr(str);
- }
- return (Aptr)EOF;
+ char str[80];
+
+ if (isObj(id))
+ return objatr(id, atr);
+ else if (isLoc(id))
+ return locatr(id, atr);
+ else if (isAct(id))
+ return actatr(id, atr);
+ else if (isLit(id))
+ return litatr(id, atr);
+ else {
+ sprintf(str, "Can't ATTRIBUTE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Aptr)EOF;
}
Aptr strattr(Aword id, Aword atr) {
- return (Aptr) strdup((char *)attribute(id, atr));
+ return (Aptr) strdup((char *)attribute(id, atr));
}
@@ -478,31 +479,31 @@ Aptr strattr(Aword id, Aword atr) {
*/
static Aword objloc(Aword obj) {
- if (isCnt(objs[obj-OBJMIN].loc)) /* In something ? */
- if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
- return(where(objs[obj-OBJMIN].loc));
- else /* Containers not anywhere is where the hero is! */
- return(where(HERO));
- else
- return(objs[obj-OBJMIN].loc);
+ if (isCnt(objs[obj - OBJMIN].loc)) /* In something ? */
+ if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
+ return (where(objs[obj - OBJMIN].loc));
+ else /* Containers not anywhere is where the hero is! */
+ return (where(HERO));
+ else
+ return (objs[obj - OBJMIN].loc);
}
static Aword actloc(Aword act) {
- return(acts[act-ACTMIN].loc);
+ return (acts[act - ACTMIN].loc);
}
Aword where(Aword id) {
- char str[80];
+ char str[80];
- if (isObj(id))
- return objloc(id);
- else if (isAct(id))
- return actloc(id);
- else {
- sprintf(str, "Can't WHERE item (%ld).", (unsigned long) id);
- syserr(str);
- }
- return (Aptr)EOF;
+ if (isObj(id))
+ return objloc(id);
+ else if (isAct(id))
+ return actloc(id);
+ else {
+ sprintf(str, "Can't WHERE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Aptr)EOF;
}
@@ -513,45 +514,45 @@ Aword where(Aword id) {
*/
Aint agrmax(Aword atr, Aword whr) {
- Aword i;
- Aint max = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr && attribute(i, atr) > max)
- max = attribute(i, atr);
- } else if (objs[i-OBJMIN].loc == whr && attribute(i, atr) > max)
- max = attribute(i, atr);
- }
- return(max);
+ Aword i;
+ Aint max = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr && attribute(i, atr) > max)
+ max = attribute(i, atr);
+ } else if (objs[i - OBJMIN].loc == whr && attribute(i, atr) > max)
+ max = attribute(i, atr);
+ }
+ return (max);
}
Aint agrsum(Aword atr, Aword whr) {
- Aword i;
- Aint sum = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr)
- sum += attribute(i, atr);
- } else if (objs[i-OBJMIN].loc == whr)
- sum += attribute(i, atr);
- }
- return(sum);
+ Aword i;
+ Aint sum = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr)
+ sum += attribute(i, atr);
+ } else if (objs[i - OBJMIN].loc == whr)
+ sum += attribute(i, atr);
+ }
+ return (sum);
}
Aint agrcount(Aword whr) {
- Aword i;
- Aword count = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (isLoc(whr)) {
- if (where(i) == whr)
- count++;
- } else if (objs[i-OBJMIN].loc == whr)
- count++;
- }
- return(count);
+ Aword i;
+ Aword count = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (isLoc(whr)) {
+ if (where(i) == whr)
+ count++;
+ } else if (objs[i - OBJMIN].loc == whr)
+ count++;
+ }
+ return (count);
}
@@ -562,63 +563,63 @@ Aint agrcount(Aword whr) {
*/
static void locobj(Aword obj, Aword whr) {
- if (isCnt(whr)) { /* Into a container */
- if (whr == obj)
- syserr("Locating something inside itself.");
- if (checklim(whr, obj))
- return;
- else
- objs[obj-OBJMIN].loc = whr;
- } else {
- objs[obj-OBJMIN].loc = whr;
- /* Make sure the location is described since it's changed */
- locs[whr-LOCMIN].describe = 0;
- }
+ if (isCnt(whr)) { /* Into a container */
+ if (whr == obj)
+ syserr("Locating something inside itself.");
+ if (checklim(whr, obj))
+ return;
+ else
+ objs[obj - OBJMIN].loc = whr;
+ } else {
+ objs[obj - OBJMIN].loc = whr;
+ /* Make sure the location is described since it's changed */
+ locs[whr - LOCMIN].describe = 0;
+ }
}
static void locact(Aword act, Aword whr) {
- Aword prevact = cur.act;
- Aword prevloc = cur.loc;
-
- cur.loc = whr;
- acts[act-ACTMIN].loc = whr;
- if (act == HERO) {
- if (locs[acts[act-ACTMIN].loc-LOCMIN].describe % (cur.visits+1) == 0)
- look();
- else {
- if (anyOutput)
- para();
- say(where(HERO));
- prmsg(M_AGAIN);
- newline();
- dscrobjs();
- dscracts();
- }
- locs[where(HERO)-LOCMIN].describe++;
- locs[where(HERO)-LOCMIN].describe %= (cur.visits+1);
- } else
- locs[whr-LOCMIN].describe = 0;
- if (locs[cur.loc-LOCMIN].does != 0) {
- cur.act = act;
- interpret(locs[cur.loc-LOCMIN].does);
- cur.act = prevact;
- }
-
- if (cur.act != act)
- cur.loc = prevloc;
+ Aword prevact = cur.act;
+ Aword prevloc = cur.loc;
+
+ cur.loc = whr;
+ acts[act - ACTMIN].loc = whr;
+ if (act == HERO) {
+ if (locs[acts[act - ACTMIN].loc - LOCMIN].describe % (cur.visits + 1) == 0)
+ look();
+ else {
+ if (anyOutput)
+ para();
+ say(where(HERO));
+ prmsg(M_AGAIN);
+ newline();
+ dscrobjs();
+ dscracts();
+ }
+ locs[where(HERO) - LOCMIN].describe++;
+ locs[where(HERO) - LOCMIN].describe %= (cur.visits + 1);
+ } else
+ locs[whr - LOCMIN].describe = 0;
+ if (locs[cur.loc - LOCMIN].does != 0) {
+ cur.act = act;
+ interpret(locs[cur.loc - LOCMIN].does);
+ cur.act = prevact;
+ }
+
+ if (cur.act != act)
+ cur.loc = prevloc;
}
void locate(Aword id, Aword whr) {
- char str[80];
+ char str[80];
- if (isObj(id))
- locobj(id, whr);
- else if (isAct(id))
- locact(id, whr);
- else {
- sprintf(str, "Can't LOCATE item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ if (isObj(id))
+ locobj(id, whr);
+ else if (isAct(id))
+ locact(id, whr);
+ else {
+ sprintf(str, "Can't LOCATE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
}
@@ -629,31 +630,31 @@ void locate(Aword id, Aword whr) {
*/
static Abool objhere(Aword obj) {
- if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
- if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
- return(isHere(objs[obj-OBJMIN].loc));
- else /* If the container wasn't anywhere, assume where HERO is! */
- return(where(HERO) == cur.loc);
- } else
- return(objs[obj-OBJMIN].loc == cur.loc);
+ if (isCnt(objs[obj - OBJMIN].loc)) { /* In something? */
+ if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
+ return (isHere(objs[obj - OBJMIN].loc));
+ else /* If the container wasn't anywhere, assume where HERO is! */
+ return (where(HERO) == cur.loc);
+ } else
+ return (objs[obj - OBJMIN].loc == cur.loc);
}
static Aword acthere(Aword act) {
- return(acts[act-ACTMIN].loc == cur.loc);
+ return (acts[act - ACTMIN].loc == cur.loc);
}
Abool isHere(Aword id) {
- char str[80];
+ char str[80];
- if (isObj(id))
- return objhere(id);
- else if (isAct(id))
- return acthere(id);
- else {
- sprintf(str, "Can't HERE item (%ld).", (unsigned long) id);
- syserr(str);
- }
- return (Abool)EOF;
+ if (isObj(id))
+ return objhere(id);
+ else if (isAct(id))
+ return acthere(id);
+ else {
+ sprintf(str, "Can't HERE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Abool)EOF;
}
/*----------------------------------------------------------------------
@@ -663,31 +664,31 @@ Abool isHere(Aword id) {
*/
static Aword objnear(Aword obj) {
- if (isCnt(objs[obj-OBJMIN].loc)) { /* In something? */
- if (isObj(objs[obj-OBJMIN].loc) || isAct(objs[obj-OBJMIN].loc))
- return(isNear(objs[obj-OBJMIN].loc));
- else /* If the container wasn't anywhere, assume here, so not nearby! */
- return(FALSE);
- } else
- return(exitto(where(obj), cur.loc));
+ if (isCnt(objs[obj - OBJMIN].loc)) { /* In something? */
+ if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
+ return (isNear(objs[obj - OBJMIN].loc));
+ else /* If the container wasn't anywhere, assume here, so not nearby! */
+ return (FALSE);
+ } else
+ return (exitto(where(obj), cur.loc));
}
static Aword actnear(Aword act) {
- return(exitto(where(act), cur.loc));
+ return (exitto(where(act), cur.loc));
}
Abool isNear(Aword id) {
- char str[80];
+ char str[80];
- if (isObj(id))
- return objnear(id);
- else if (isAct(id))
- return actnear(id);
- else {
- sprintf(str, "Can't NEAR item (%ld).", (unsigned long) id);
- syserr(str);
- }
- return (Abool)EOF;
+ if (isObj(id))
+ return objnear(id);
+ else if (isAct(id))
+ return actnear(id);
+ else {
+ sprintf(str, "Can't NEAR item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ return (Abool)EOF;
}
@@ -698,12 +699,12 @@ Abool isNear(Aword id) {
*/
Abool in(Aword obj, Aword cnt) {
- if (!isObj(obj))
- return(FALSE);
- if (!isCnt(cnt))
- syserr("IN in a non-container.");
+ if (!isObj(obj))
+ return (FALSE);
+ if (!isCnt(cnt))
+ syserr("IN in a non-container.");
- return(objs[obj-OBJMIN].loc == cnt);
+ return (objs[obj - OBJMIN].loc == cnt);
}
@@ -714,69 +715,69 @@ Abool in(Aword obj, Aword cnt) {
*/
static void sayloc(Aword loc) {
- interpret(locs[loc-LOCMIN].nams);
+ interpret(locs[loc - LOCMIN].nams);
}
static void sayobj(Aword obj) {
- interpret(objs[obj-OBJMIN].dscr2);
+ interpret(objs[obj - OBJMIN].dscr2);
}
static void sayact(Aword act) {
- interpret(acts[act-ACTMIN].nam);
+ interpret(acts[act - ACTMIN].nam);
}
void sayint(Aword val) {
- char buf[25];
+ char buf[25];
- if (isHere(HERO)) {
- sprintf(buf, "%ld", (unsigned long) val);
- output(buf);
- }
+ if (isHere(HERO)) {
+ sprintf(buf, "%ld", (unsigned long) val);
+ output(buf);
+ }
}
void saystr(char *str) {
- if (isHere(HERO))
- output(str);
- free(str);
+ if (isHere(HERO))
+ output(str);
+ free(str);
}
static void saylit(Aword lit) {
- char *str;
+ char *str;
- if (isNum(lit))
- sayint(litValues[lit-LITMIN].value);
- else {
- str = (char *)strdup((char *)litValues[lit-LITMIN].value);
- saystr(str);
- }
+ if (isNum(lit))
+ sayint(litValues[lit - LITMIN].value);
+ else {
+ str = (char *)strdup((char *)litValues[lit - LITMIN].value);
+ saystr(str);
+ }
}
void sayarticle(Aword id) {
- if (!isObj(id))
- syserr("Trying to say article of something *not* an object.");
- if (objs[id-OBJMIN].art != 0)
- interpret(objs[id-OBJMIN].art);
- else
- prmsg(M_ARTICLE);
+ if (!isObj(id))
+ syserr("Trying to say article of something *not* an object.");
+ if (objs[id - OBJMIN].art != 0)
+ interpret(objs[id - OBJMIN].art);
+ else
+ prmsg(M_ARTICLE);
}
void say(Aword id) {
- char str[80];
-
- if (isHere(HERO)) {
- if (isObj(id))
- sayobj(id);
- else if (isLoc(id))
- sayloc(id);
- else if (isAct(id))
- sayact(id);
- else if (isLit(id))
- saylit(id);
- else {
- sprintf(str, "Can't SAY item (%ld).", (unsigned long) id);
- syserr(str);
- }
- }
+ char str[80];
+
+ if (isHere(HERO)) {
+ if (isObj(id))
+ sayobj(id);
+ else if (isLoc(id))
+ sayloc(id);
+ else if (isAct(id))
+ sayact(id);
+ else if (isLit(id))
+ saylit(id);
+ else {
+ sprintf(str, "Can't SAY item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
+ }
}
@@ -787,68 +788,68 @@ void say(Aword id) {
*/
static void dscrloc(Aword loc) {
- if (locs[loc-LOCMIN].dscr != 0)
- interpret(locs[loc-LOCMIN].dscr);
+ if (locs[loc - LOCMIN].dscr != 0)
+ interpret(locs[loc - LOCMIN].dscr);
}
static void dscrobj(Aword obj) {
- objs[obj-OBJMIN].describe = FALSE;
- if (objs[obj-OBJMIN].dscr1 != 0)
- interpret(objs[obj-OBJMIN].dscr1);
- else {
- prmsg(M_SEEOBJ1);
- sayarticle(obj);
- say(obj);
- prmsg(M_SEEOBJ4);
- if (objs[obj-OBJMIN].cont != 0)
- list(obj);
- }
+ objs[obj - OBJMIN].describe = FALSE;
+ if (objs[obj - OBJMIN].dscr1 != 0)
+ interpret(objs[obj - OBJMIN].dscr1);
+ else {
+ prmsg(M_SEEOBJ1);
+ sayarticle(obj);
+ say(obj);
+ prmsg(M_SEEOBJ4);
+ if (objs[obj - OBJMIN].cont != 0)
+ list(obj);
+ }
}
static void dscract(Aword act) {
- ScrElem *scr = NULL;
-
- if (acts[act-ACTMIN].script != 0) {
- for (scr = (ScrElem *) addrTo(acts[act-ACTMIN].scradr); !endOfTable(scr); scr++)
- if (scr->code == acts[act-ACTMIN].script)
- break;
- if (endOfTable(scr)) scr = NULL;
- }
- if (scr != NULL && scr->dscr != 0)
- interpret(scr->dscr);
- else if (acts[act-ACTMIN].dscr != 0)
- interpret(acts[act-ACTMIN].dscr);
- else {
- interpret(acts[act-ACTMIN].nam);
- prmsg(M_SEEACT);
- }
- acts[act-ACTMIN].describe = FALSE;
+ ScrElem *scr = NULL;
+
+ if (acts[act - ACTMIN].script != 0) {
+ for (scr = (ScrElem *) addrTo(acts[act - ACTMIN].scradr); !endOfTable(scr); scr++)
+ if (scr->code == acts[act - ACTMIN].script)
+ break;
+ if (endOfTable(scr)) scr = NULL;
+ }
+ if (scr != NULL && scr->dscr != 0)
+ interpret(scr->dscr);
+ else if (acts[act - ACTMIN].dscr != 0)
+ interpret(acts[act - ACTMIN].dscr);
+ else {
+ interpret(acts[act - ACTMIN].nam);
+ prmsg(M_SEEACT);
+ }
+ acts[act - ACTMIN].describe = FALSE;
}
static Aword dscrstk[255];
void describe(Aword id) {
- int i;
- char str[80];
-
- for (i = 0; i < dscrstkp; i++)
- if (dscrstk[i] == id)
- syserr("Recursive DESCRIBE.");
- dscrstk[dscrstkp++] = id;
-
- if (isObj(id))
- dscrobj(id);
- else if (isLoc(id))
- dscrloc(id);
- else if (isAct(id))
- dscract(id);
- else {
- sprintf(str, "Can't DESCRIBE item (%ld).", (unsigned long) id);
- syserr(str);
- }
+ int i;
+ char str[80];
+
+ for (i = 0; i < dscrstkp; i++)
+ if (dscrstk[i] == id)
+ syserr("Recursive DESCRIBE.");
+ dscrstk[dscrstkp++] = id;
+
+ if (isObj(id))
+ dscrobj(id);
+ else if (isLoc(id))
+ dscrloc(id);
+ else if (isAct(id))
+ dscract(id);
+ else {
+ sprintf(str, "Can't DESCRIBE item (%ld).", (unsigned long) id);
+ syserr(str);
+ }
- dscrstkp--;
+ dscrstkp--;
}
@@ -859,15 +860,15 @@ void describe(Aword id) {
*/
void use(Aword act, Aword scr) {
- char str[80];
+ char str[80];
- if (!isAct(act)) {
- sprintf(str, "Item is not an Actor (%ld).", (unsigned long) act);
- syserr(str);
- }
+ if (!isAct(act)) {
+ sprintf(str, "Item is not an Actor (%ld).", (unsigned long) act);
+ syserr(str);
+ }
- acts[act-ACTMIN].script = scr;
- acts[act-ACTMIN].step = 0;
+ acts[act - ACTMIN].script = scr;
+ acts[act - ACTMIN].step = 0;
}
@@ -878,66 +879,66 @@ void use(Aword act, Aword scr) {
*/
void list(Aword cnt) {
- int i;
- Aword props;
- Aword prevobj;
- Boolean found = FALSE;
- Boolean multiple = FALSE;
-
- /* Find container properties */
- if (isObj(cnt))
- props = objs[cnt-OBJMIN].cont;
- else if (isAct(cnt))
- props = acts[cnt-ACTMIN].cont;
- else
- props = cnt;
-
- for (i = OBJMIN; i <= OBJMAX; i++) {
- if (in(i, cnt)) { /* Yes, it's in this container */
- if (!found) {
- found = TRUE;
- if (cnts[props-CNTMIN].header != 0)
- interpret(cnts[props-CNTMIN].header);
- else {
- prmsg(M_CONTAINS1);
- if (cnts[props-CNTMIN].nam != 0) /* It has it's own name */
- interpret(cnts[props-CNTMIN].nam);
- else
- say(cnts[props-CNTMIN].parent); /* It is actually an object or actor */
- prmsg(M_CONTAINS2);
+ int i;
+ Aword props;
+ Aword prevobj;
+ Boolean found = FALSE;
+ Boolean multiple = FALSE;
+
+ /* Find container properties */
+ if (isObj(cnt))
+ props = objs[cnt - OBJMIN].cont;
+ else if (isAct(cnt))
+ props = acts[cnt - ACTMIN].cont;
+ else
+ props = cnt;
+
+ for (i = OBJMIN; i <= OBJMAX; i++) {
+ if (in(i, cnt)) { /* Yes, it's in this container */
+ if (!found) {
+ found = TRUE;
+ if (cnts[props - CNTMIN].header != 0)
+ interpret(cnts[props - CNTMIN].header);
+ else {
+ prmsg(M_CONTAINS1);
+ if (cnts[props - CNTMIN].nam != 0) /* It has it's own name */
+ interpret(cnts[props - CNTMIN].nam);
+ else
+ say(cnts[props - CNTMIN].parent); /* It is actually an object or actor */
+ prmsg(M_CONTAINS2);
+ }
+ } else {
+ if (multiple) {
+ needsp = FALSE;
+ prmsg(M_CONTAINS3);
+ }
+ multiple = TRUE;
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ prevobj = i;
+ }
}
- } else {
- if (multiple) {
- needsp = FALSE;
- prmsg(M_CONTAINS3);
+
+ if (found) {
+ if (multiple)
+ prmsg(M_CONTAINS4);
+ sayarticle(prevobj);
+ say(prevobj);
+ prmsg(M_CONTAINS5);
+ } else {
+ if (cnts[props - CNTMIN].empty != 0)
+ interpret(cnts[props - CNTMIN].empty);
+ else {
+ prmsg(M_EMPTY1);
+ if (cnts[props - CNTMIN].nam != 0) /* It has it's own name */
+ interpret(cnts[props - CNTMIN].nam);
+ else
+ say(cnts[props - CNTMIN].parent); /* It is actually an actor or object */
+ prmsg(M_EMPTY2);
+ }
}
- multiple = TRUE;
- sayarticle(prevobj);
- say(prevobj);
- }
- prevobj = i;
- }
- }
-
- if (found) {
- if (multiple)
- prmsg(M_CONTAINS4);
- sayarticle(prevobj);
- say(prevobj);
- prmsg(M_CONTAINS5);
- } else {
- if (cnts[props-CNTMIN].empty != 0)
- interpret(cnts[props-CNTMIN].empty);
- else {
- prmsg(M_EMPTY1);
- if (cnts[props-CNTMIN].nam != 0) /* It has it's own name */
- interpret(cnts[props-CNTMIN].nam);
- else
- say(cnts[props-CNTMIN].parent); /* It is actually an actor or object */
- prmsg(M_EMPTY2);
- }
- }
- needsp = TRUE;
+ needsp = TRUE;
}
@@ -948,11 +949,11 @@ void list(Aword cnt) {
*/
void empty(Aword cnt, Aword whr) {
- int i;
+ int i;
- for (i = OBJMIN; i <= OBJMAX; i++)
- if (in(i, cnt))
- locate(i, whr);
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (in(i, cnt))
+ locate(i, whr);
}
@@ -967,94 +968,94 @@ void empty(Aword cnt, Aword whr) {
\*----------------------------------------------------------------------*/
void dscrobjs() {
- int i;
- int prevobj;
- Boolean found = FALSE;
- Boolean multiple = FALSE;
-
- /* First describe everything here with its own description */
- for (i = OBJMIN; i <= OBJMAX; i++)
- if (objs[i-OBJMIN].loc == cur.loc &&
- objs[i-OBJMIN].describe &&
- objs[i-OBJMIN].dscr1)
- describe(i);
-
- /* Then list everything else here */
- for (i = OBJMIN; i <= OBJMAX; i++)
- if (objs[i-OBJMIN].loc == cur.loc &&
- objs[i-OBJMIN].describe) {
- if (!found) {
- prmsg(M_SEEOBJ1);
- sayarticle(i);
- say(i);
- found = TRUE;
- } else {
- if (multiple) {
- needsp = FALSE;
- prmsg(M_SEEOBJ2);
- sayarticle(prevobj);
- say(prevobj);
+ int i;
+ int prevobj;
+ Boolean found = FALSE;
+ Boolean multiple = FALSE;
+
+ /* First describe everything here with its own description */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i - OBJMIN].loc == cur.loc &&
+ objs[i - OBJMIN].describe &&
+ objs[i - OBJMIN].dscr1)
+ describe(i);
+
+ /* Then list everything else here */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i - OBJMIN].loc == cur.loc &&
+ objs[i - OBJMIN].describe) {
+ if (!found) {
+ prmsg(M_SEEOBJ1);
+ sayarticle(i);
+ say(i);
+ found = TRUE;
+ } else {
+ if (multiple) {
+ needsp = FALSE;
+ prmsg(M_SEEOBJ2);
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ multiple = TRUE;
+ }
+ prevobj = i;
+ }
+
+ if (found) {
+ if (multiple) {
+ prmsg(M_SEEOBJ3);
+ sayarticle(prevobj);
+ say(prevobj);
+ }
+ prmsg(M_SEEOBJ4);
}
- multiple = TRUE;
- }
- prevobj = i;
- }
-
- if (found) {
- if (multiple) {
- prmsg(M_SEEOBJ3);
- sayarticle(prevobj);
- say(prevobj);
- }
- prmsg(M_SEEOBJ4);
- }
-
- /* Set describe flag for all objects */
- for (i = OBJMIN; i <= OBJMAX; i++)
- objs[i-OBJMIN].describe = TRUE;
+
+ /* Set describe flag for all objects */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ objs[i - OBJMIN].describe = TRUE;
}
void dscracts() {
- int i;
-
- for (i = HERO+1; i <= ACTMAX; i++)
- if (acts[i-ACTMIN].loc == cur.loc &&
- acts[i-ACTMIN].describe)
- describe(i);
+ int i;
+
+ for (i = HERO + 1; i <= ACTMAX; i++)
+ if (acts[i - ACTMIN].loc == cur.loc &&
+ acts[i - ACTMIN].describe)
+ describe(i);
- /* Set describe flag for all actors */
- for (i = HERO; i <= ACTMAX; i++)
- acts[i-ACTMIN].describe = TRUE;
+ /* Set describe flag for all actors */
+ for (i = HERO; i <= ACTMAX; i++)
+ acts[i - ACTMIN].describe = TRUE;
}
void look() {
- int i;
+ int i;
- if (looking)
- syserr("Recursive LOOK.");
+ if (looking)
+ syserr("Recursive LOOK.");
- looking = TRUE;
- /* Set describe flag for all objects and actors */
- for (i = OBJMIN; i <= OBJMAX; i++)
- objs[i-OBJMIN].describe = TRUE;
- for (i = ACTMIN; i <= ACTMAX; i++)
- acts[i-ACTMIN].describe = TRUE;
+ looking = TRUE;
+ /* Set describe flag for all objects and actors */
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ objs[i - OBJMIN].describe = TRUE;
+ for (i = ACTMIN; i <= ACTMAX; i++)
+ acts[i - ACTMIN].describe = TRUE;
- if (anyOutput)
- para();
+ if (anyOutput)
+ para();
-g_vm->glk_set_style(style_Subheader);
-needsp = FALSE;
- say(cur.loc);
- needsp = FALSE;
- output(".");
-g_vm->glk_set_style(style_Normal);
- newline();
-needsp = FALSE;
- describe(cur.loc);
- dscrobjs();
- dscracts();
- looking = FALSE;
+ g_vm->glk_set_style(style_Subheader);
+ needsp = FALSE;
+ say(cur.loc);
+ needsp = FALSE;
+ output(".");
+ g_vm->glk_set_style(style_Normal);
+ newline();
+ needsp = FALSE;
+ describe(cur.loc);
+ dscrobjs();
+ dscracts();
+ looking = FALSE;
}
@@ -1090,27 +1091,27 @@ void restore() {
*/
Aword rnd(Aword from, Aword to) {
- if (to == from)
- return to;
- else if (to > from)
- return (rand()/10)%(to-from+1)+from;
- else
- return (rand()/10)%(from-to+1)+to;
+ if (to == from)
+ return to;
+ else if (to > from)
+ return (rand() / 10) % (to - from + 1) + from;
+ else
+ return (rand() / 10) % (from - to + 1) + to;
}
/*----------------------------------------------------------------------
btw()
- BETWEEN
+ BETWEEN
*/
Abool btw(Aint val, Aint low, Aint high) {
- if (high > low)
- return low <= val && val <= high;
- else
- return high <= val && val <= low;
+ if (high > low)
+ return low <= val && val <= high;
+ else
+ return high <= val && val <= low;
}
@@ -1122,17 +1123,17 @@ Abool btw(Aint val, Aint low, Aint high) {
*/
Aword contains(Aptr string, Aptr substring) {
- Abool found;
+ Abool found;
- strlow((char *)string);
- strlow((char *)substring);
+ strlow((char *)string);
+ strlow((char *)substring);
- found = (strstr((char *)string, (char *)substring) != 0);
+ found = (strstr((char *)string, (char *)substring) != 0);
- free((char *)string);
- free((char *)substring);
+ free((char *)string);
+ free((char *)substring);
- return(found);
+ return (found);
}
@@ -1144,17 +1145,17 @@ Aword contains(Aptr string, Aptr substring) {
*/
Abool streq(char a[], char b[]) {
- Boolean eq;
+ Boolean eq;
- strlow(a);
- strlow(b);
+ strlow(a);
+ strlow(b);
- eq = (strcmp(a, b) == 0);
+ eq = (strcmp(a, b) == 0);
- free(a);
- free(b);
+ free(a);
+ free(b);
- return(eq);
+ return (eq);
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
index 1b0e5f9..cc99719 100644
--- a/engines/glk/alan2/exe.h
+++ b/engines/glk/alan2/exe.h
@@ -32,10 +32,10 @@ namespace Glk {
namespace Alan2 {
/* The event queue */
-extern EvtqElem eventq[]; /* Event queue */
-extern int etop; /* Event queue top pointer */
-extern Boolean looking; /* LOOKING? flag */
-extern int dscrstkp; /* Point into describe stack */
+extern EvtqElem eventq[]; /* Event queue */
+extern int etop; /* Event queue top pointer */
+extern Boolean looking; /* LOOKING? flag */
+extern int dscrstkp; /* Point into describe stack */
extern void sys(Aword fpos, Aword len);
extern Boolean confirm(MsgKind msgno);
diff --git a/engines/glk/alan2/glkio.cpp b/engines/glk/alan2/glkio.cpp
index 47dbbf2..29c4875 100644
--- a/engines/glk/alan2/glkio.cpp
+++ b/engines/glk/alan2/glkio.cpp
@@ -34,7 +34,7 @@ void glkio_printf(char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
if (glkMainWin) {
- char buf[1024]; /* FIXME: buf size should be foolproof */
+ char buf[1024]; /* FIXME: buf size should be foolproof */
vsprintf(buf, fmt, argp);
g_vm->glk_put_string(buf);
} else {
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 5e2827f..82486ee 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -39,801 +39,823 @@ static int pc;
static void if_(Aword v) {
- int lev = 1;
- Aword i;
-
- if (!v) {
- /* Skip to next ELSE or ENDIF on same level */
- while (TRUE) {
- i = memory[pc++];
- if (I_CLASS(i) == (Aword)C_STMOP)
- switch (I_OP(i)) {
- case I_ELSE:
- if (lev == 1) return;
- break;
- case I_IF:
- lev++;
- break;
- case I_ENDIF:
- lev--;
- if (lev == 0) return;
- break;
+ int lev = 1;
+ Aword i;
+
+ if (!v) {
+ /* Skip to next ELSE or ENDIF on same level */
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_ELSE:
+ if (lev == 1) return;
+ break;
+ case I_IF:
+ lev++;
+ break;
+ case I_ENDIF:
+ lev--;
+ if (lev == 0) return;
+ break;
+ }
+ }
}
- }
- }
}
static void else_() {
- int lev = 1;
- Aword i;
-
- while (TRUE) {
- /* Skip to ENDIF on the same level */
- i = memory[pc++];
- if (I_CLASS(i) == (Aword)C_STMOP)
- switch (I_OP(i)) {
- case I_ENDIF:
- lev--;
- if (lev == 0) return;
- break;
- case I_IF:
- lev++;
- break;
- }
- }
+ int lev = 1;
+ Aword i;
+
+ while (TRUE) {
+ /* Skip to ENDIF on the same level */
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_ENDIF:
+ lev--;
+ if (lev == 0) return;
+ break;
+ case I_IF:
+ lev++;
+ break;
+ }
+ }
}
static void depstart() {
- /* A DEPSTART was executed so skip across the redundant DEPCASE to
- start at the first expression */
- pc++;
+ /* A DEPSTART was executed so skip across the redundant DEPCASE to
+ start at the first expression */
+ pc++;
}
static void swap() {
- Aptr v1 = pop();
- Aptr v2 = pop();
+ Aptr v1 = pop();
+ Aptr v2 = pop();
- push(v1);
- push(v2);
+ push(v1);
+ push(v2);
}
static void depexec(Aword v) {
- int lev = 1;
- Aword i;
-
- if (!v)
- /* The expression was not true, skip to next CASE on the same
- level which could be a DEPCASE or DEPELSE */
- while (TRUE) {
- i = memory[pc++];
- if (I_CLASS(i) == (Aword)C_STMOP)
- switch (I_OP(i)) {
- case I_DEPSTART:
- lev++;
- break;
- case I_DEPEND:
- if (lev == 1) return;
- lev--;
- break;
- case I_DEPCASE:
- case I_DEPELSE:
- if (lev == 1) return;
- break;
- }
- }
+ int lev = 1;
+ Aword i;
+
+ if (!v)
+ /* The expression was not true, skip to next CASE on the same
+ level which could be a DEPCASE or DEPELSE */
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_DEPSTART:
+ lev++;
+ break;
+ case I_DEPEND:
+ if (lev == 1) return;
+ lev--;
+ break;
+ case I_DEPCASE:
+ case I_DEPELSE:
+ if (lev == 1) return;
+ break;
+ }
+ }
}
static void depcase() {
- int lev = 1;
- Aword i;
-
- /* Skip to end of DEPENDING block (next DEPEND on same level) because
- we have just executed a DEPCASE/DEPELSE statement as a result of a DEPCASE
- catching */
-
- while (TRUE) {
- i = memory[pc++];
- if (I_CLASS(i) == (Aword)C_STMOP)
- switch (I_OP(i)) {
- case I_DEPSTART:
- lev++;
- break;
- case I_DEPEND:
- lev--;
- if (lev == 0) return;
- break;
- }
- }
+ int lev = 1;
+ Aword i;
+
+ /* Skip to end of DEPENDING block (next DEPEND on same level) because
+ we have just executed a DEPCASE/DEPELSE statement as a result of a DEPCASE
+ catching */
+
+ while (TRUE) {
+ i = memory[pc++];
+ if (I_CLASS(i) == (Aword)C_STMOP)
+ switch (I_OP(i)) {
+ case I_DEPSTART:
+ lev++;
+ break;
+ case I_DEPEND:
+ lev--;
+ if (lev == 0) return;
+ break;
+ }
+ }
}
void interpret(Aaddr adr) {
- Aaddr oldpc;
- Aword i;
-
- if (stpflg) printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++");
-
- oldpc = pc;
- pc = adr;
- while(TRUE) {
- if (stpflg) printf("\n%4x: ", pc);
- if (pc > memTop)
- syserr("Interpreting outside program.");
-
- i = memory[pc++];
-
- switch (I_CLASS(i)) {
- case C_CONST:
- if (stpflg) printf("PUSH \t%5ld", I_OP(i));
- push(I_OP(i));
- break;
- case C_CURVAR:
- switch (I_OP(i)) {
- case V_PARAM:
- if (stpflg) printf("PARAM \t%5ld\t\t(%ld)", top(), params[top()-1].code);
- push(params[pop()-1].code);
- break;
- case V_CURLOC:
- if (stpflg) printf("CURLOC \t\t\t(%d)", cur.loc);
- push(cur.loc);
- break;
- case V_CURACT:
- if (stpflg) printf("CURACT \t\t\t(%d)", cur.act);
- push(cur.act);
- break;
- case V_CURVRB:
- if (stpflg) printf("CURVRB \t\t\t(%d)", cur.vrb);
- push(cur.vrb);
- break;
- case V_SCORE:
- if (stpflg) printf("CURSCORE \t\t\t(%d)", cur.score);
- push(cur.score);
- break;
- default:
- syserr("Unknown CURVAR instruction.");
- break;
- }
- break;
-
- case C_STMOP:
- switch (I_OP(i)) {
- case I_PRINT: {
- Aptr fpos, len;
- fpos = pop();
- len = pop();
- if (stpflg) {
- printf("PRINT \t%5ld, %5ld\t\"", fpos, len);
- col = 34; /* To format it better! */
- }
- print(fpos, len);
- if (stpflg)
- printf("\"");
- break;
- }
- case I_SYSTEM: {
- Aptr fpos, len;
- fpos = pop();
- len = pop();
- if (stpflg) {
- printf("SYSTEM \t%5ld, %5ld\t\"", fpos, len);
- col = 34; /* To format it better! */
- }
- sys(fpos, len);
- break;
- }
- case I_GETSTR: {
- Aptr fpos, len;
- fpos = pop();
- len = pop();
- if (stpflg)
- printf("GETSTR\t%5ld, %5ld", fpos, len);
- getstr(fpos, len);
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_QUIT: {
- if (stpflg)
- printf("QUIT");
- quit();
- break;
- }
- case I_LOOK: {
- if (stpflg)
- printf("LOOK");
- look();
- break;
- }
- case I_SAVE: {
- if (stpflg)
- printf("SAVE");
- save();
- break;
- }
- case I_RESTORE: {
- if (stpflg)
- printf("RESTORE");
- restore();
- break;
- }
- case I_RESTART: {
- if (stpflg)
- printf("RESTART");
- restart();
- break;
- }
- case I_LIST: {
- Aptr cnt;
- cnt = pop();
- if (stpflg)
- printf("LIST \t%5ld", cnt);
- list(cnt);
- break;
- }
- case I_EMPTY: {
- Aptr cnt, whr;
- cnt = pop();
- whr = pop();
- if (stpflg)
- printf("EMPTY \t%5ld, %5ld", cnt, whr);
- empty(cnt, whr);
- break;
- }
- case I_SCORE: {
- Aptr sc;
- sc = pop();
- if (stpflg)
- printf("SCORE \t%5ld\t\t(%ld)", sc, scores[sc-1]);
- score(sc);
- break;
- }
- case I_VISITS: {
- Aptr v;
- v = pop();
- if (stpflg)
- printf("VISITS \t%5ld", v);
- visits(v);
- break;
- }
- case I_SCHEDULE: {
- Aptr evt, whr, aft;
- evt = pop();
- whr = pop();
- aft = pop();
- if (stpflg)
- printf("SCHEDULE \t%5ld, %5ld, %5ld", evt, whr, aft);
- schedule(evt, whr, aft);
- break;
- }
- case I_CANCEL: {
- Aptr evt;
- evt = pop();
- if (stpflg)
- printf("CANCEL \t%5ld", evt);
- cancl(evt);
- break;
- }
- case I_MAKE: {
- Aptr id, atr, val;
- id = pop();
- atr = pop();
- val = pop();
- if (stpflg) {
- printf("MAKE \t%5ld, %5ld, ", id, atr);
- if (val) printf("TRUE"); else printf("FALSE");
- }
- make(id, atr, val);
- break;
- }
- case I_SET: {
- Aptr id, atr, val;
- id = pop();
- atr = pop();
- val = pop();
- if (stpflg) {
- printf("SET \t%5ld, %5ld, %5ld", id, atr, val);
- }
- set(id, atr, val);
- break;
- }
- case I_STRSET: {
- Aptr id, atr, str;
- id = pop();
- atr = pop();
- str = pop();
- if (stpflg) {
- printf("STRSET\t%5ld, %5ld, %5ld", id, atr, str);
- }
- setstr(id, atr, str);
- break;
- }
- case I_INCR: {
- Aptr id, atr, step;
- id = pop();
- atr = pop();
- step = pop();
- if (stpflg) {
- printf("INCR\t%5ld, %5ld, %5ld", id, atr, step);
- }
- incr(id, atr, step);
- break;
- }
- case I_DECR: {
- Aptr id, atr, step;
- id = pop();
- atr = pop();
- step = pop();
- if (stpflg) {
- printf("DECR\t%5ld, %5ld, %5ld", id, atr, step);
- }
- decr(id, atr, step);
- break;
- }
- case I_ATTRIBUTE: {
- Aptr id, atr;
- id = pop();
- atr = pop();
- if (stpflg)
- printf("ATTRIBUTE %5ld, %5ld", id, atr);
- push(attribute(id, atr));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_STRATTR: {
- Aptr id, atr;
- id = pop();
- atr = pop();
- if (stpflg)
- printf("STRATTR \t%5ld, %5ld", id, atr);
- push(strattr(id, atr));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_LOCATE: {
- Aptr id, whr;
- id = pop();
- whr = pop();
- if (stpflg)
- printf("LOCATE \t%5ld, %5ld", id, whr);
- locate(id, whr);
- break;
- }
- case I_WHERE: {
- Aptr id;
- id = pop();
- if (stpflg)
- printf("WHERE \t%5ld", id);
- push(where(id));
- if (stpflg)
- printf("\t\t(%ld)", top());
- break;
- }
- case I_HERE: {
- Aptr id;
- id = pop();
- if (stpflg)
- printf("HERE \t%5ld", id);
- push(isHere(id));
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_NEAR: {
- Aptr id;
- id = pop();
- if (stpflg)
- printf("NEAR \t%5ld", id);
- push(isNear(id));
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_USE: {
- Aptr act, scr;
- act = pop();
- scr = pop();
- if (stpflg)
- printf("USE \t%5ld, %5ld", act, scr);
- use(act, scr);
- break;
- }
- case I_IN: {
- Aptr obj, cnt;
- obj = pop();
- cnt = pop();
- if (stpflg)
- printf("IN \t%5ld, %5ld ", obj, cnt);
- push(in(obj, cnt));
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_DESCRIBE: {
- Aptr id;
- id = pop();
- if (stpflg) {
- printf("DESCRIBE \t%5ld\t", id);
- col = 34; /* To format it better! */
- }
- describe(id);
- break;
- }
- case I_SAY: {
- Aptr id;
- id = pop();
- if (stpflg)
- printf("SAY \t%5ld\t\t\"", id);
- say(id);
- if (stpflg)
- printf("\"");
- break;
- }
- case I_SAYINT: {
- Aptr val;
- val = pop();
- if (stpflg)
- printf("SAYINT\t%5ld\t\t\"", val);
- sayint(val);
- if (stpflg)
- printf("\"");
- break;
- }
- case I_SAYSTR: {
- Aptr adr;
- adr = pop();
- if (stpflg)
- printf("SAYSTR\t%5ld\t\t\"", adr);
- saystr((char *)adr);
- if (stpflg)
- printf("\"");
- break;
- }
- case I_IF: {
- Aptr v;
- v = pop();
- if (stpflg) {
- printf("IF \t");
- if (v) printf(" TRUE"); else printf("FALSE");
- }
- if_(v);
- break;
- }
- case I_ELSE: {
- if (stpflg)
- printf("ELSE");
- else_();
- break;
- }
- case I_ENDIF: {
- if (stpflg)
- printf("ENDIF");
- break;
- }
- case I_AND: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg) {
- printf("AND \t");
- if (lh) printf("TRUE, "); else printf("FALSE, ");
- if (rh) printf("TRUE"); else printf("FALSE");
- }
- push(lh && rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_OR: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg) {
- printf("OR \t");
- if (lh) printf("TRUE, "); else printf("FALSE, ");
- if (rh) printf("TRUE"); else printf("FALSE");
- }
- push(lh || rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_NE: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("NE \t%5ld, %5ld", lh, rh);
- push(lh != rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_EQ: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("EQ \t%5ld, %5ld", lh, rh);
- push(lh == rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_STREQ: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("STREQ \t%5ld, %5ld", lh, rh);
- push(streq((char *)lh, (char *)rh));
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_STREXACT: {
- Aptr lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("STREXACT \t%5ld, %5ld", lh, rh);
- push(strcmp((char *)lh, (char *)rh) == 0);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- free((void *)lh);
- free((void *)rh);
- break;
- }
- case I_LE: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("LE \t%5ld, %5ld", lh, rh);
- push(lh <= rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_GE: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("GE \t%5ld, %5ld", lh, rh);
- push(lh >= rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_LT: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("LT \t%5ld, %5ld", lh, rh);
- push((signed int)lh < (signed int)rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_GT: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("GT \t%5ld, %5ld", lh, rh);
- push(lh > rh);
- if (stpflg)
- if (top()) printf("\t(TRUE)"); else printf("\t(FALSE)");
- break;
- }
- case I_PLUS: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("PLUS \t%5ld, %5ld", lh, rh);
- push(lh + rh);
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_MINUS: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("MINUS \t%5ld, %5ld", lh, rh);
- push(lh - rh);
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_MULT: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("MULT \t%5ld, %5ld", lh, rh);
- push(lh * rh);
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_DIV: {
- Aint lh, rh;
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- swap();
- rh = pop();
- lh = pop();
- if (stpflg)
- printf("DIV \t%5ld, %5ld", lh, rh);
- push(lh / rh);
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_NOT: {
- Aptr val;
- val = pop();
- if (stpflg) {
- printf("NOT \t");
- if (val) printf("TRUE"); else printf("FALSE");
- }
- push(!val);
- if (stpflg)
- if (top()) printf("\t\t(TRUE)"); else printf("\t\t(FALSE)");
- break;
- }
- case I_MAX: {
- Aptr atr, whr;
- atr = pop();
- whr = pop();
- if (stpflg)
- printf("MAX \t%5ld, %5ld", atr, whr);
- push(agrmax(atr, whr));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_SUM: {
- Aptr atr, whr;
- atr = pop();
- whr = pop();
- if (stpflg)
- printf("SUM \t%5ld, %5ld", atr, whr);
- push(agrsum(atr, whr));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_COUNT: {
- Aptr whr;
- whr = pop();
- if (stpflg)
- printf("COUNT \t%5ld", whr);
- push(agrcount(whr));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_RND: {
- Aptr from, to;
- from = pop();
- to = pop();
- if (stpflg)
- printf("RANDOM \t%5ld, %5ld", from, to);
- push(rnd(from, to));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_BTW: {
- Aint low, high, val;
- high = pop();
- low = pop();
- val = pop();
- if (stpflg)
- printf("BETWEEN \t%5ld, %5ld, %5ld", val, low, high);
- push(btw(val, low, high));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
- case I_CONTAINS: {
- Aptr string, substring;
- substring = pop();
- string = pop();
- if (stpflg)
- printf("CONTAINS \t%5ld, %5ld", string, substring);
- push(contains(string, substring));
- if (stpflg)
- printf("\t(%ld)", top());
- break;
- }
-
- case I_DEPSTART:
- if (stpflg)
- printf("DEPSTART");
- depstart();
- break;
-
- case I_DEPCASE:
- if (stpflg)
- printf("DEPCASE");
- depcase();
- break;
-
- case I_DEPEXEC: {
- Aptr v;
- v = pop();
- if (stpflg) {
- printf("DEPEXEC \t");
- if (v) printf(" TRUE"); else printf("FALSE");
+ Aaddr oldpc;
+ Aword i;
+
+ if (stpflg) printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++");
+
+ oldpc = pc;
+ pc = adr;
+ while (TRUE) {
+ if (stpflg) printf("\n%4x: ", pc);
+ if (pc > memTop)
+ syserr("Interpreting outside program.");
+
+ i = memory[pc++];
+
+ switch (I_CLASS(i)) {
+ case C_CONST:
+ if (stpflg) printf("PUSH \t%5ld", I_OP(i));
+ push(I_OP(i));
+ break;
+ case C_CURVAR:
+ switch (I_OP(i)) {
+ case V_PARAM:
+ if (stpflg) printf("PARAM \t%5ld\t\t(%ld)", top(), params[top() - 1].code);
+ push(params[pop() - 1].code);
+ break;
+ case V_CURLOC:
+ if (stpflg) printf("CURLOC \t\t\t(%d)", cur.loc);
+ push(cur.loc);
+ break;
+ case V_CURACT:
+ if (stpflg) printf("CURACT \t\t\t(%d)", cur.act);
+ push(cur.act);
+ break;
+ case V_CURVRB:
+ if (stpflg) printf("CURVRB \t\t\t(%d)", cur.vrb);
+ push(cur.vrb);
+ break;
+ case V_SCORE:
+ if (stpflg) printf("CURSCORE \t\t\t(%d)", cur.score);
+ push(cur.score);
+ break;
+ default:
+ syserr("Unknown CURVAR instruction.");
+ break;
+ }
+ break;
+
+ case C_STMOP:
+ switch (I_OP(i)) {
+ case I_PRINT: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg) {
+ printf("PRINT \t%5ld, %5ld\t\"", fpos, len);
+ col = 34; /* To format it better! */
+ }
+ print(fpos, len);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SYSTEM: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg) {
+ printf("SYSTEM \t%5ld, %5ld\t\"", fpos, len);
+ col = 34; /* To format it better! */
+ }
+ sys(fpos, len);
+ break;
+ }
+ case I_GETSTR: {
+ Aptr fpos, len;
+ fpos = pop();
+ len = pop();
+ if (stpflg)
+ printf("GETSTR\t%5ld, %5ld", fpos, len);
+ getstr(fpos, len);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_QUIT: {
+ if (stpflg)
+ printf("QUIT");
+ quit();
+ break;
+ }
+ case I_LOOK: {
+ if (stpflg)
+ printf("LOOK");
+ look();
+ break;
+ }
+ case I_SAVE: {
+ if (stpflg)
+ printf("SAVE");
+ save();
+ break;
+ }
+ case I_RESTORE: {
+ if (stpflg)
+ printf("RESTORE");
+ restore();
+ break;
+ }
+ case I_RESTART: {
+ if (stpflg)
+ printf("RESTART");
+ restart();
+ break;
+ }
+ case I_LIST: {
+ Aptr cnt;
+ cnt = pop();
+ if (stpflg)
+ printf("LIST \t%5ld", cnt);
+ list(cnt);
+ break;
+ }
+ case I_EMPTY: {
+ Aptr cnt, whr;
+ cnt = pop();
+ whr = pop();
+ if (stpflg)
+ printf("EMPTY \t%5ld, %5ld", cnt, whr);
+ empty(cnt, whr);
+ break;
+ }
+ case I_SCORE: {
+ Aptr sc;
+ sc = pop();
+ if (stpflg)
+ printf("SCORE \t%5ld\t\t(%ld)", sc, scores[sc - 1]);
+ score(sc);
+ break;
+ }
+ case I_VISITS: {
+ Aptr v;
+ v = pop();
+ if (stpflg)
+ printf("VISITS \t%5ld", v);
+ visits(v);
+ break;
+ }
+ case I_SCHEDULE: {
+ Aptr evt, whr, aft;
+ evt = pop();
+ whr = pop();
+ aft = pop();
+ if (stpflg)
+ printf("SCHEDULE \t%5ld, %5ld, %5ld", evt, whr, aft);
+ schedule(evt, whr, aft);
+ break;
+ }
+ case I_CANCEL: {
+ Aptr evt;
+ evt = pop();
+ if (stpflg)
+ printf("CANCEL \t%5ld", evt);
+ cancl(evt);
+ break;
+ }
+ case I_MAKE: {
+ Aptr id, atr, val;
+ id = pop();
+ atr = pop();
+ val = pop();
+ if (stpflg) {
+ printf("MAKE \t%5ld, %5ld, ", id, atr);
+ if (val) printf("TRUE");
+ else printf("FALSE");
+ }
+ make(id, atr, val);
+ break;
+ }
+ case I_SET: {
+ Aptr id, atr, val;
+ id = pop();
+ atr = pop();
+ val = pop();
+ if (stpflg) {
+ printf("SET \t%5ld, %5ld, %5ld", id, atr, val);
+ }
+ set(id, atr, val);
+ break;
+ }
+ case I_STRSET: {
+ Aptr id, atr, str;
+ id = pop();
+ atr = pop();
+ str = pop();
+ if (stpflg) {
+ printf("STRSET\t%5ld, %5ld, %5ld", id, atr, str);
+ }
+ setstr(id, atr, str);
+ break;
+ }
+ case I_INCR: {
+ Aptr id, atr, step;
+ id = pop();
+ atr = pop();
+ step = pop();
+ if (stpflg) {
+ printf("INCR\t%5ld, %5ld, %5ld", id, atr, step);
+ }
+ incr(id, atr, step);
+ break;
+ }
+ case I_DECR: {
+ Aptr id, atr, step;
+ id = pop();
+ atr = pop();
+ step = pop();
+ if (stpflg) {
+ printf("DECR\t%5ld, %5ld, %5ld", id, atr, step);
+ }
+ decr(id, atr, step);
+ break;
+ }
+ case I_ATTRIBUTE: {
+ Aptr id, atr;
+ id = pop();
+ atr = pop();
+ if (stpflg)
+ printf("ATTRIBUTE %5ld, %5ld", id, atr);
+ push(attribute(id, atr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_STRATTR: {
+ Aptr id, atr;
+ id = pop();
+ atr = pop();
+ if (stpflg)
+ printf("STRATTR \t%5ld, %5ld", id, atr);
+ push(strattr(id, atr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_LOCATE: {
+ Aptr id, whr;
+ id = pop();
+ whr = pop();
+ if (stpflg)
+ printf("LOCATE \t%5ld, %5ld", id, whr);
+ locate(id, whr);
+ break;
+ }
+ case I_WHERE: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("WHERE \t%5ld", id);
+ push(where(id));
+ if (stpflg)
+ printf("\t\t(%ld)", top());
+ break;
+ }
+ case I_HERE: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("HERE \t%5ld", id);
+ push(isHere(id));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_NEAR: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("NEAR \t%5ld", id);
+ push(isNear(id));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_USE: {
+ Aptr act, scr;
+ act = pop();
+ scr = pop();
+ if (stpflg)
+ printf("USE \t%5ld, %5ld", act, scr);
+ use(act, scr);
+ break;
+ }
+ case I_IN: {
+ Aptr obj, cnt;
+ obj = pop();
+ cnt = pop();
+ if (stpflg)
+ printf("IN \t%5ld, %5ld ", obj, cnt);
+ push(in(obj, cnt));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_DESCRIBE: {
+ Aptr id;
+ id = pop();
+ if (stpflg) {
+ printf("DESCRIBE \t%5ld\t", id);
+ col = 34; /* To format it better! */
+ }
+ describe(id);
+ break;
+ }
+ case I_SAY: {
+ Aptr id;
+ id = pop();
+ if (stpflg)
+ printf("SAY \t%5ld\t\t\"", id);
+ say(id);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SAYINT: {
+ Aptr val;
+ val = pop();
+ if (stpflg)
+ printf("SAYINT\t%5ld\t\t\"", val);
+ sayint(val);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_SAYSTR: {
+ Aptr adr;
+ adr = pop();
+ if (stpflg)
+ printf("SAYSTR\t%5ld\t\t\"", adr);
+ saystr((char *)adr);
+ if (stpflg)
+ printf("\"");
+ break;
+ }
+ case I_IF: {
+ Aptr v;
+ v = pop();
+ if (stpflg) {
+ printf("IF \t");
+ if (v) printf(" TRUE");
+ else printf("FALSE");
+ }
+ if_(v);
+ break;
+ }
+ case I_ELSE: {
+ if (stpflg)
+ printf("ELSE");
+ else_();
+ break;
+ }
+ case I_ENDIF: {
+ if (stpflg)
+ printf("ENDIF");
+ break;
+ }
+ case I_AND: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg) {
+ printf("AND \t");
+ if (lh) printf("TRUE, ");
+ else printf("FALSE, ");
+ if (rh) printf("TRUE");
+ else printf("FALSE");
+ }
+ push(lh && rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_OR: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg) {
+ printf("OR \t");
+ if (lh) printf("TRUE, ");
+ else printf("FALSE, ");
+ if (rh) printf("TRUE");
+ else printf("FALSE");
+ }
+ push(lh || rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_NE: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("NE \t%5ld, %5ld", lh, rh);
+ push(lh != rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_EQ: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("EQ \t%5ld, %5ld", lh, rh);
+ push(lh == rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_STREQ: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("STREQ \t%5ld, %5ld", lh, rh);
+ push(streq((char *)lh, (char *)rh));
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_STREXACT: {
+ Aptr lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("STREXACT \t%5ld, %5ld", lh, rh);
+ push(strcmp((char *)lh, (char *)rh) == 0);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ free((void *)lh);
+ free((void *)rh);
+ break;
+ }
+ case I_LE: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("LE \t%5ld, %5ld", lh, rh);
+ push(lh <= rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_GE: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("GE \t%5ld, %5ld", lh, rh);
+ push(lh >= rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_LT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("LT \t%5ld, %5ld", lh, rh);
+ push((signed int)lh < (signed int)rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_GT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("GT \t%5ld, %5ld", lh, rh);
+ push(lh > rh);
+ if (stpflg)
+ if (top()) printf("\t(TRUE)");
+ else printf("\t(FALSE)");
+ break;
+ }
+ case I_PLUS: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("PLUS \t%5ld, %5ld", lh, rh);
+ push(lh + rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_MINUS: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("MINUS \t%5ld, %5ld", lh, rh);
+ push(lh - rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_MULT: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("MULT \t%5ld, %5ld", lh, rh);
+ push(lh * rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_DIV: {
+ Aint lh, rh;
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ swap();
+ rh = pop();
+ lh = pop();
+ if (stpflg)
+ printf("DIV \t%5ld, %5ld", lh, rh);
+ push(lh / rh);
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_NOT: {
+ Aptr val;
+ val = pop();
+ if (stpflg) {
+ printf("NOT \t");
+ if (val) printf("TRUE");
+ else printf("FALSE");
+ }
+ push(!val);
+ if (stpflg)
+ if (top()) printf("\t\t(TRUE)");
+ else printf("\t\t(FALSE)");
+ break;
+ }
+ case I_MAX: {
+ Aptr atr, whr;
+ atr = pop();
+ whr = pop();
+ if (stpflg)
+ printf("MAX \t%5ld, %5ld", atr, whr);
+ push(agrmax(atr, whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_SUM: {
+ Aptr atr, whr;
+ atr = pop();
+ whr = pop();
+ if (stpflg)
+ printf("SUM \t%5ld, %5ld", atr, whr);
+ push(agrsum(atr, whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_COUNT: {
+ Aptr whr;
+ whr = pop();
+ if (stpflg)
+ printf("COUNT \t%5ld", whr);
+ push(agrcount(whr));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_RND: {
+ Aptr from, to;
+ from = pop();
+ to = pop();
+ if (stpflg)
+ printf("RANDOM \t%5ld, %5ld", from, to);
+ push(rnd(from, to));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_BTW: {
+ Aint low, high, val;
+ high = pop();
+ low = pop();
+ val = pop();
+ if (stpflg)
+ printf("BETWEEN \t%5ld, %5ld, %5ld", val, low, high);
+ push(btw(val, low, high));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+ case I_CONTAINS: {
+ Aptr string, substring;
+ substring = pop();
+ string = pop();
+ if (stpflg)
+ printf("CONTAINS \t%5ld, %5ld", string, substring);
+ push(contains(string, substring));
+ if (stpflg)
+ printf("\t(%ld)", top());
+ break;
+ }
+
+ case I_DEPSTART:
+ if (stpflg)
+ printf("DEPSTART");
+ depstart();
+ break;
+
+ case I_DEPCASE:
+ if (stpflg)
+ printf("DEPCASE");
+ depcase();
+ break;
+
+ case I_DEPEXEC: {
+ Aptr v;
+ v = pop();
+ if (stpflg) {
+ printf("DEPEXEC \t");
+ if (v) printf(" TRUE");
+ else printf("FALSE");
+ }
+ depexec(v);
+ break;
+ }
+
+ case I_DEPELSE:
+ if (stpflg)
+ printf("DEPELSE");
+ depcase();
+ break;
+
+ case I_DEPEND:
+ if (stpflg)
+ printf("DEPEND");
+ break;
+
+ case I_RETURN:
+ if (stpflg)
+ printf("RETURN\n--------------------------------------------------\n");
+ pc = oldpc;
+ return;
+
+ default:
+ syserr("Unknown STMOP instruction.");
+ break;
+ }
+ if (fail) {
+ pc = oldpc;
+ return;
+ }
+ break;
+
+ default:
+ syserr("Unknown instruction class.");
+ break;
+ }
}
- depexec(v);
- break;
- }
-
- case I_DEPELSE:
- if (stpflg)
- printf("DEPELSE");
- depcase();
- break;
-
- case I_DEPEND:
- if (stpflg)
- printf("DEPEND");
- break;
-
- case I_RETURN:
- if (stpflg)
- printf("RETURN\n--------------------------------------------------\n");
- pc = oldpc;
- return;
-
- default:
- syserr("Unknown STMOP instruction.");
- break;
- }
- if (fail) {
- pc = oldpc;
- return;
- }
- break;
-
- default:
- syserr("Unknown instruction class.");
- break;
- }
- }
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 6b06e0b..7dadbea 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -46,30 +46,30 @@ namespace Alan2 {
/* The Amachine memory */
Aword *memory;
-//static AcdHdr dummyHeader; /* Dummy to use until memory allocated */
+//static AcdHdr dummyHeader; /* Dummy to use until memory allocated */
AcdHdr *header;
-int memTop; /* Top of load memory */
+int memTop; /* Top of load memory */
-int conjWord; /* First conjunction in dictonary, for ',' */
+int conjWord; /* First conjunction in dictonary, for ',' */
/* Amachine variables */
CurVars cur;
/* Amachine structures */
-WrdElem *dict; /* Dictionary pointer */
-ActElem *acts; /* Actor table pointer */
-LocElem *locs; /* Location table pointer */
-VrbElem *vrbs; /* Verb table pointer */
-StxElem *stxs; /* Syntax table pointer */
-ObjElem *objs; /* Object table pointer */
-CntElem *cnts; /* Container table pointer */
-RulElem *ruls; /* Rule table pointer */
-EvtElem *evts; /* Event table pointer */
-MsgElem *msgs; /* Message table pointer */
-Aword *scores; /* Score table pointer */
-Aword *freq; /* Cumulative character frequencies */
+WrdElem *dict; /* Dictionary pointer */
+ActElem *acts; /* Actor table pointer */
+LocElem *locs; /* Location table pointer */
+VrbElem *vrbs; /* Verb table pointer */
+StxElem *stxs; /* Syntax table pointer */
+ObjElem *objs; /* Object table pointer */
+CntElem *cnts; /* Container table pointer */
+RulElem *ruls; /* Rule table pointer */
+EvtElem *evts; /* Event table pointer */
+MsgElem *msgs; /* Message table pointer */
+Aword *scores; /* Score table pointer */
+Aword *freq; /* Cumulative character frequencies */
int dictsize;
@@ -102,7 +102,7 @@ Boolean skipsp = FALSE;
/* PRIVATE DATA */
-//static jmp_buf jmpbuf; /* Error return long jump buffer */
+//static jmp_buf jmpbuf; /* Error return long jump buffer */
@@ -115,12 +115,12 @@ Boolean skipsp = FALSE;
*/
void terminate(int code) {
- newline();
- free(memory);
- if (logflg)
- fclose(logfil);
+ newline();
+ free(memory);
+ if (logflg)
+ fclose(logfil);
- g_vm->glk_exit();
+ g_vm->glk_exit();
}
/*======================================================================
@@ -129,19 +129,19 @@ void terminate(int code) {
*/
void usage() {
- printf("Usage:\n\n");
- printf(" %s [<switches>] <adventure>\n\n", PROGNAME);
- printf("where the possible optional switches are:\n");
- g_vm->glk_set_style(style_Preformatted);
-
- printf(" -v verbose mode\n");
- printf(" -l log player commands and game output to a file\n");
- printf(" -i ignore version and checksum errors\n");
- printf(" -n no Status Line\n");
- printf(" -d enter debug mode\n");
- printf(" -t trace game execution\n");
- printf(" -s single instruction trace\n");
- g_vm->glk_set_style(style_Normal);
+ printf("Usage:\n\n");
+ printf(" %s [<switches>] <adventure>\n\n", PROGNAME);
+ printf("where the possible optional switches are:\n");
+ g_vm->glk_set_style(style_Preformatted);
+
+ printf(" -v verbose mode\n");
+ printf(" -l log player commands and game output to a file\n");
+ printf(" -i ignore version and checksum errors\n");
+ printf(" -n no Status Line\n");
+ printf(" -d enter debug mode\n");
+ printf(" -t trace game execution\n");
+ printf(" -s single instruction trace\n");
+ g_vm->glk_set_style(style_Normal);
}
@@ -165,13 +165,13 @@ void syserr(const char *str) {
*/
void error(MsgKind msgno /* IN - The error message number */) {
- if (msgno != MSGMAX)
- prmsg(msgno);
- wrds[wrdidx] = EOF; /* Force new player input */
- dscrstkp = 0; /* Reset describe stack */
-
+ if (msgno != MSGMAX)
+ prmsg(msgno);
+ wrds[wrdidx] = EOF; /* Force new player input */
+ dscrstkp = 0; /* Reset describe stack */
+
//longjmp(jmpbuf,TRUE);
- ::error("Error occurred");
+ ::error("Error occurred");
}
@@ -183,37 +183,37 @@ void error(MsgKind msgno /* IN - The error message number */) {
*/
void statusline() {
- uint glkWidth;
- char line[100];
- int pcol = col;
- uint i;
-
- if (NULL == glkStatusWin)
- return;
-
- g_vm->glk_set_window(glkStatusWin);
- g_vm->glk_window_clear(glkStatusWin);
- g_vm->glk_window_get_size(glkStatusWin, &glkWidth, NULL);
-
- g_vm->glk_set_style(style_User1);
- for (i = 0; i < glkWidth; i++)
- g_vm->glk_put_char(' ');
-
- col = 1;
- g_vm->glk_window_move_cursor(glkStatusWin, 1, 0);
-needsp = FALSE;
- say(where(HERO));
- if (header->maxscore > 0)
- sprintf(line, "Score %d(%d)/%d moves", cur.score, (int)header->maxscore, cur.tick);
- else
- sprintf(line, "%d moves", cur.tick);
- g_vm->glk_window_move_cursor(glkStatusWin, glkWidth - col - strlen(line), 0);
- printf(line);
- needsp = FALSE;
-
- col = pcol;
-
- g_vm->glk_set_window(glkMainWin);
+ uint glkWidth;
+ char line[100];
+ int pcol = col;
+ uint i;
+
+ if (NULL == glkStatusWin)
+ return;
+
+ g_vm->glk_set_window(glkStatusWin);
+ g_vm->glk_window_clear(glkStatusWin);
+ g_vm->glk_window_get_size(glkStatusWin, &glkWidth, NULL);
+
+ g_vm->glk_set_style(style_User1);
+ for (i = 0; i < glkWidth; i++)
+ g_vm->glk_put_char(' ');
+
+ col = 1;
+ g_vm->glk_window_move_cursor(glkStatusWin, 1, 0);
+ needsp = FALSE;
+ say(where(HERO));
+ if (header->maxscore > 0)
+ sprintf(line, "Score %d(%d)/%d moves", cur.score, (int)header->maxscore, cur.tick);
+ else
+ sprintf(line, "%d moves", cur.tick);
+ g_vm->glk_window_move_cursor(glkStatusWin, glkWidth - col - strlen(line), 0);
+ printf(line);
+ needsp = FALSE;
+
+ col = pcol;
+
+ g_vm->glk_set_window(glkMainWin);
}
@@ -225,9 +225,9 @@ needsp = FALSE;
*/
void logprint(char str[]) {
- printf(str);
- if (logflg)
- fprintf(logfil, "%s", str);
+ printf(str);
+ if (logflg)
+ fprintf(logfil, "%s", str);
}
@@ -251,9 +251,9 @@ void newline() {
*/
void para() {
- if (col != 1)
- newline();
- newline();
+ if (col != 1)
+ newline();
+ newline();
}
@@ -277,12 +277,12 @@ void clear() {
*/
void *allocate(unsigned long len /* IN - Length to allocate */) {
- void *p = (void *)malloc((size_t)len);
+ void *p = (void *)malloc((size_t)len);
- if (p == NULL)
- syserr("Out of memory.");
+ if (p == NULL)
+ syserr("Out of memory.");
- return p;
+ return p;
}
@@ -294,7 +294,7 @@ void *allocate(unsigned long len /* IN - Length to allocate */) {
*/
static void just(char str[]) {
- logprint(str);
+ logprint(str);
}
@@ -306,15 +306,15 @@ static void just(char str[]) {
*/
static void space() {
- if (skipsp)
- skipsp = FALSE;
- else {
- if (needsp) {
- logprint(" ");
- col++;
- }
- }
- needsp = FALSE;
+ if (skipsp)
+ skipsp = FALSE;
+ else {
+ if (needsp) {
+ logprint(" ");
+ col++;
+ }
+ }
+ needsp = FALSE;
}
@@ -327,20 +327,20 @@ static void space() {
*/
static void sayparam(int p) {
- int i;
-
- for (i = 0; i <= p; i++)
- if (params[i].code == EOF)
- syserr("Nonexistent parameter referenced.");
-
- if (params[p].firstWord == EOF) /* Any words he used? */
- say(params[p].code);
- else /* Yes, so use them... */
- for (i = params[p].firstWord; i <= params[p].lastWord; i++) {
- just((char *)addrTo(dict[wrds[i]].wrd));
- if (i < params[p].lastWord)
- just(" ");
- }
+ int i;
+
+ for (i = 0; i <= p; i++)
+ if (params[i].code == EOF)
+ syserr("Nonexistent parameter referenced.");
+
+ if (params[p].firstWord == EOF) /* Any words he used? */
+ say(params[p].code);
+ else /* Yes, so use them... */
+ for (i = params[p].firstWord; i <= params[p].lastWord; i++) {
+ just((char *)addrTo(dict[wrds[i]].wrd));
+ if (i < params[p].lastWord)
+ just(" ");
+ }
}
@@ -361,67 +361,67 @@ static void sayparam(int p) {
$ = no space needed after this
*/
static void prsym(
- char *str /* IN - The string starting with '$' */
+ char *str /* IN - The string starting with '$' */
) {
- switch (toLower(str[1])) {
- case 'n':
- newline();
- needsp = FALSE;
- break;
- case 'i':
- newline();
- logprint(" ");
- col = 5;
- needsp = FALSE;
- break;
- case 'o':
- sayparam(0);
- needsp = TRUE; /* We did print something non-white */
- break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- sayparam(str[1]-'1');
- needsp = TRUE; /* We did print something non-white */
- break;
- case 'l':
- say(cur.loc);
- needsp = TRUE; /* We did print something non-white */
- break;
- case 'a':
- say(cur.act);
- needsp = TRUE; /* We did print something non-white */
- break;
- case 'v':
- just((char *)addrTo(dict[vrbwrd].wrd));
- needsp = TRUE; /* We did print something non-white */
- break;
- case 'p':
- para();
- needsp = FALSE;
- break;
- case 't': {
- int i;
- int spaces = 4-(col-1)%4;
-
- for (i = 0; i<spaces; i++) logprint(" ");
- col = col + spaces;
- needsp = FALSE;
- break;
- }
- case '$':
- skipsp = TRUE;
- break;
- default:
- logprint("$");
- break;
- }
+ switch (toLower(str[1])) {
+ case 'n':
+ newline();
+ needsp = FALSE;
+ break;
+ case 'i':
+ newline();
+ logprint(" ");
+ col = 5;
+ needsp = FALSE;
+ break;
+ case 'o':
+ sayparam(0);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ sayparam(str[1] - '1');
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'l':
+ say(cur.loc);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'a':
+ say(cur.act);
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'v':
+ just((char *)addrTo(dict[vrbwrd].wrd));
+ needsp = TRUE; /* We did print something non-white */
+ break;
+ case 'p':
+ para();
+ needsp = FALSE;
+ break;
+ case 't': {
+ int i;
+ int spaces = 4 - (col - 1) % 4;
+
+ for (i = 0; i < spaces; i++) logprint(" ");
+ col = col + spaces;
+ needsp = FALSE;
+ break;
+ }
+ case '$':
+ skipsp = TRUE;
+ break;
+ default:
+ logprint("$");
+ break;
+ }
}
@@ -435,36 +435,36 @@ static void prsym(
*/
void output(char original[]) {
- char ch;
- char *str, *copy;
- char *symptr;
-
- copy = strdup(original);
- str = copy;
-
- if (str[0] != '$' || str[1] != '$')
- space(); /* Output space if needed (& not inhibited) */
-
- while ((symptr = strchr(str, '$')) != (char *) NULL) {
- ch = *symptr; /* Terminate before symbol */
- *symptr = '\0';
- if (strlen(str) > 0) {
- just(str); /* Output part before '$' */
- if (str[strlen(str)-1] == ' ')
- needsp = FALSE;
- }
- *symptr = ch; /* restore '$' */
- prsym(symptr); /* Print the symbolic reference */
- str = &symptr[2]; /* Advance to after symbol and continue */
- }
- if (str[0] != 0) {
- just(str); /* Output trailing part */
- skipsp = FALSE;
- if (str[strlen(str)-1] != ' ')
- needsp = TRUE;
- }
- anyOutput = TRUE;
- free(copy);
+ char ch;
+ char *str, *copy;
+ char *symptr;
+
+ copy = strdup(original);
+ str = copy;
+
+ if (str[0] != '$' || str[1] != '$')
+ space(); /* Output space if needed (& not inhibited) */
+
+ while ((symptr = strchr(str, '$')) != (char *) NULL) {
+ ch = *symptr; /* Terminate before symbol */
+ *symptr = '\0';
+ if (strlen(str) > 0) {
+ just(str); /* Output part before '$' */
+ if (str[strlen(str) - 1] == ' ')
+ needsp = FALSE;
+ }
+ *symptr = ch; /* restore '$' */
+ prsym(symptr); /* Print the symbolic reference */
+ str = &symptr[2]; /* Advance to after symbol and continue */
+ }
+ if (str[0] != 0) {
+ just(str); /* Output trailing part */
+ skipsp = FALSE;
+ if (str[strlen(str) - 1] != ' ')
+ needsp = TRUE;
+ }
+ anyOutput = TRUE;
+ free(copy);
}
@@ -473,10 +473,10 @@ void output(char original[]) {
prmsg()
Print a message from the message table.
-
+
*/
void prmsg(MsgKind msg /* IN - message number */) {
- interpret(msgs[msg].stms);
+ interpret(msgs[msg].stms);
}
@@ -491,37 +491,37 @@ void prmsg(MsgKind msg /* IN - message number */) {
/* How to know we are at end of a table */
Boolean eot(Aword *adr) {
- return *adr == EOF;
+ return *adr == EOF;
}
Boolean isObj(Aword x) {
- return x >= OBJMIN && x <= OBJMAX;
+ return x >= OBJMIN && x <= OBJMAX;
}
Boolean isCnt(Aword x) {
- return (x >= CNTMIN && x <= CNTMAX) ||
- (isObj(x) && objs[x-OBJMIN].cont != 0) ||
- (isAct(x) && acts[x-ACTMIN].cont != 0);
+ return (x >= CNTMIN && x <= CNTMAX) ||
+ (isObj(x) && objs[x - OBJMIN].cont != 0) ||
+ (isAct(x) && acts[x - ACTMIN].cont != 0);
}
Boolean isAct(Aword x) {
- return x >= ACTMIN && x <= ACTMAX;
+ return x >= ACTMIN && x <= ACTMAX;
}
Boolean isLoc(Aword x) {
- return x >= LOCMIN && x <= LOCMAX;
+ return x >= LOCMIN && x <= LOCMAX;
}
Boolean isNum(Aword x) {
- return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPNUM;
+ return x >= LITMIN && x <= LITMAX && litValues[x - LITMIN].type == TYPNUM;
}
Boolean isStr(Aword x) {
- return x >= LITMIN && x <= LITMAX && litValues[x-LITMIN].type == TYPSTR;
+ return x >= LITMIN && x <= LITMAX && litValues[x - LITMIN].type == TYPSTR;
}
Boolean isLit(Aword x) {
- return x >= LITMIN && x <= LITMAX;
+ return x >= LITMIN && x <= LITMAX;
}
@@ -533,16 +533,16 @@ Boolean isLit(Aword x) {
*/
Boolean exitto(int to, int from) {
- ExtElem *ext;
+ ExtElem *ext;
- if (locs[from-LOCMIN].exts == 0)
- return(FALSE); /* No exits */
+ if (locs[from - LOCMIN].exts == 0)
+ return (FALSE); /* No exits */
- for (ext = (ExtElem *) addrTo(locs[from-LOCMIN].exts); !endOfTable(ext); ext++)
- if (ext->next == to)
- return(TRUE);
+ for (ext = (ExtElem *) addrTo(locs[from - LOCMIN].exts); !endOfTable(ext); ext++)
+ if (ext->next == to)
+ return (TRUE);
- return(FALSE);
+ return (FALSE);
}
@@ -553,13 +553,13 @@ Boolean exitto(int to, int from) {
*/
static int count(int cnt /* IN - the container to count */) {
- int i, j = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++)
- if (in(i, cnt))
- /* Then it's in this container also */
- j++;
- return(j);
+ int i, j = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (in(i, cnt))
+ /* Then it's in this container also */
+ j++;
+ return (j);
}
@@ -570,19 +570,19 @@ static int count(int cnt /* IN - the container to count */) {
*/
static int sumatr(
- Aword atr, /* IN - the attribute to sum over */
- Aword cnt /* IN - the container to sum */
+ Aword atr, /* IN - the attribute to sum over */
+ Aword cnt /* IN - the container to sum */
) {
- int i;
- int sum = 0;
-
- for (i = OBJMIN; i <= OBJMAX; i++)
- if (objs[i-OBJMIN].loc == cnt) { /* Then it's in this container */
- if (objs[i-OBJMIN].cont != 0) /* This is also a container! */
- sum = sum + sumatr(atr, i);
- sum = sum + attribute(i, atr);
- }
- return(sum);
+ int i;
+ int sum = 0;
+
+ for (i = OBJMIN; i <= OBJMAX; i++)
+ if (objs[i - OBJMIN].loc == cnt) { /* Then it's in this container */
+ if (objs[i - OBJMIN].cont != 0) /* This is also a container! */
+ sum = sum + sumatr(atr, i);
+ sum = sum + attribute(i, atr);
+ }
+ return (sum);
}
@@ -593,40 +593,40 @@ static int sumatr(
*/
Boolean checklim(
- Aword cnt, /* IN - Container code */
- Aword obj /* IN - The object to add */
+ Aword cnt, /* IN - Container code */
+ Aword obj /* IN - The object to add */
) {
- LimElem *lim;
- Aword props;
-
- fail = TRUE;
- if (!isCnt(cnt))
- syserr("Checking limits for a non-container.");
-
- /* Find the container properties */
- if (isObj(cnt))
- props = objs[cnt-OBJMIN].cont;
- else if (isAct(cnt))
- props = acts[cnt-ACTMIN].cont;
- else
- props = cnt;
-
- if (cnts[props-CNTMIN].lims != 0) { /* Any limits at all? */
- for (lim = (LimElem *) addrTo(cnts[props-CNTMIN].lims); !endOfTable(lim); lim++)
- if (lim->atr == 0) {
- if (count(cnt) >= lim->val) {
- interpret(lim->stms);
- return(TRUE); /* Limit check failed */
- }
- } else {
- if (sumatr(lim->atr, cnt) + attribute(obj, lim->atr) > lim->val) {
- interpret(lim->stms);
- return(TRUE);
+ LimElem *lim;
+ Aword props;
+
+ fail = TRUE;
+ if (!isCnt(cnt))
+ syserr("Checking limits for a non-container.");
+
+ /* Find the container properties */
+ if (isObj(cnt))
+ props = objs[cnt - OBJMIN].cont;
+ else if (isAct(cnt))
+ props = acts[cnt - ACTMIN].cont;
+ else
+ props = cnt;
+
+ if (cnts[props - CNTMIN].lims != 0) { /* Any limits at all? */
+ for (lim = (LimElem *) addrTo(cnts[props - CNTMIN].lims); !endOfTable(lim); lim++)
+ if (lim->atr == 0) {
+ if (count(cnt) >= lim->val) {
+ interpret(lim->stms);
+ return (TRUE); /* Limit check failed */
+ }
+ } else {
+ if (sumatr(lim->atr, cnt) + attribute(obj, lim->atr) > lim->val) {
+ interpret(lim->stms);
+ return (TRUE);
+ }
+ }
}
- }
- }
- fail = FALSE;
- return(FALSE);
+ fail = FALSE;
+ return (FALSE);
}
@@ -645,27 +645,27 @@ Boolean checklim(
*/
static Boolean trycheck(
- Aaddr adr, /* IN - ACODE address to check table */
- Boolean act /* IN - Act if it fails ? */
+ Aaddr adr, /* IN - ACODE address to check table */
+ Boolean act /* IN - Act if it fails ? */
) {
- ChkElem *chk;
-
- chk = (ChkElem *) addrTo(adr);
- if (chk->exp == 0) {
- interpret(chk->stms);
- return(FALSE);
- } else {
- while (!endOfTable(chk)) {
- interpret(chk->exp);
- if (!(Abool)pop()) {
- if (act)
- interpret(chk->stms);
- return(FALSE);
- }
- chk++;
- }
- return(TRUE);
- }
+ ChkElem *chk;
+
+ chk = (ChkElem *) addrTo(adr);
+ if (chk->exp == 0) {
+ interpret(chk->stms);
+ return (FALSE);
+ } else {
+ while (!endOfTable(chk)) {
+ interpret(chk->exp);
+ if (!(Abool)pop()) {
+ if (act)
+ interpret(chk->stms);
+ return (FALSE);
+ }
+ chk++;
+ }
+ return (TRUE);
+ }
}
@@ -676,51 +676,51 @@ static Boolean trycheck(
*/
void go(int dir) {
- ExtElem *ext;
- Boolean ok;
- Aword oldloc;
-
- ext = (ExtElem *) addrTo(locs[cur.loc-LOCMIN].exts);
- if (locs[cur.loc-LOCMIN].exts != 0)
- while (!endOfTable(ext)) {
- if (ext->code == dir) {
- ok = TRUE;
- if (ext->checks != 0) {
- if (trcflg) {
- printf("\n<EXIT %d (%s) from %d (", dir,
- (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
- debugsay(cur.loc);
- printf("), Checking:>\n");
- }
- ok = trycheck(ext->checks, TRUE);
- }
- if (ok) {
- oldloc = cur.loc;
- if (ext->action != 0) {
- if (trcflg) {
- printf("\n<EXIT %d (%s) from %d (", dir,
- (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
- debugsay(cur.loc);
- printf("), Executing:>\n");
- }
- interpret(ext->action);
- }
- /* Still at the same place? */
- if (where(HERO) == oldloc) {
- if (trcflg) {
- printf("\n<EXIT %d (%s) from %d (", dir,
- (char *)addrTo(dict[wrds[wrdidx-1]].wrd), cur.loc);
- debugsay(cur.loc);
- printf("), Moving:>\n");
- }
- locate(HERO, ext->next);
- }
- }
- return;
- }
- ext++;
- }
- error(M_NO_WAY);
+ ExtElem *ext;
+ Boolean ok;
+ Aword oldloc;
+
+ ext = (ExtElem *) addrTo(locs[cur.loc - LOCMIN].exts);
+ if (locs[cur.loc - LOCMIN].exts != 0)
+ while (!endOfTable(ext)) {
+ if (ext->code == dir) {
+ ok = TRUE;
+ if (ext->checks != 0) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx - 1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Checking:>\n");
+ }
+ ok = trycheck(ext->checks, TRUE);
+ }
+ if (ok) {
+ oldloc = cur.loc;
+ if (ext->action != 0) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx - 1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Executing:>\n");
+ }
+ interpret(ext->action);
+ }
+ /* Still at the same place? */
+ if (where(HERO) == oldloc) {
+ if (trcflg) {
+ printf("\n<EXIT %d (%s) from %d (", dir,
+ (char *)addrTo(dict[wrds[wrdidx - 1]].wrd), cur.loc);
+ debugsay(cur.loc);
+ printf("), Moving:>\n");
+ }
+ locate(HERO, ext->next);
+ }
+ }
+ return;
+ }
+ ext++;
+ }
+ error(M_NO_WAY);
}
@@ -733,23 +733,23 @@ void go(int dir) {
*/
static AltElem *findalt(
- Aword vrbsadr, /* IN - Address to start of list */
- Aword param /* IN - Which parameter to match */
+ Aword vrbsadr, /* IN - Address to start of list */
+ Aword param /* IN - Which parameter to match */
) {
- VrbElem *vrb;
- AltElem *alt;
-
- if (vrbsadr == 0)
- return(NULL);
-
- for (vrb = (VrbElem *) addrTo(vrbsadr); !endOfTable(vrb); vrb++)
- if (vrb->code == cur.vrb) {
- for (alt = (AltElem *) addrTo(vrb->alts); !endOfTable(alt); alt++)
- if (alt->param == param || alt->param == 0)
- return alt;
- return NULL;
- }
- return NULL;
+ VrbElem *vrb;
+ AltElem *alt;
+
+ if (vrbsadr == 0)
+ return (NULL);
+
+ for (vrb = (VrbElem *) addrTo(vrbsadr); !endOfTable(vrb); vrb++)
+ if (vrb->code == cur.vrb) {
+ for (alt = (AltElem *) addrTo(vrb->alts); !endOfTable(alt); alt++)
+ if (alt->param == param || alt->param == 0)
+ return alt;
+ return NULL;
+ }
+ return NULL;
}
@@ -761,39 +761,39 @@ static AltElem *findalt(
*/
Boolean possible() {
- AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
- int i; /* Parameter index */
-
- fail = FALSE;
- alt[0] = findalt(header->vrbs, 0);
- /* Perform global checks */
- if (alt[0] != 0 && alt[0]->checks != 0) {
- if (!trycheck(alt[0]->checks, FALSE)) return FALSE;
- if (fail) return FALSE;
- }
-
- /* Now CHECKs in this location */
- alt[1] = findalt(locs[cur.loc-LOCMIN].vrbs, 0);
- if (alt[1] != 0 && alt[1]->checks != 0)
- if (!trycheck(alt[1]->checks, FALSE))
- return FALSE;
-
- for (i = 0; params[i].code != EOF; i++) {
- alt[i+2] = findalt(objs[params[i].code-OBJMIN].vrbs, i+1);
- /* CHECKs in a possible parameter */
- if (alt[i+2] != 0 && alt[i+2]->checks != 0)
- if (!trycheck(alt[i+2]->checks, FALSE))
- return FALSE;
- }
-
- for (i = 0; i < 2 || params[i-2].code != EOF; i++)
- if (alt[i] != 0 && alt[i]->action != 0)
- break;
- if (i >= 2 && params[i-2].code == EOF)
- /* Didn't find any code for this verb/object combination */
- return FALSE;
- else
- return TRUE;
+ AltElem *alt[MAXPARAMS + 2]; /* List of alt-pointers, one for each param */
+ int i; /* Parameter index */
+
+ fail = FALSE;
+ alt[0] = findalt(header->vrbs, 0);
+ /* Perform global checks */
+ if (alt[0] != 0 && alt[0]->checks != 0) {
+ if (!trycheck(alt[0]->checks, FALSE)) return FALSE;
+ if (fail) return FALSE;
+ }
+
+ /* Now CHECKs in this location */
+ alt[1] = findalt(locs[cur.loc - LOCMIN].vrbs, 0);
+ if (alt[1] != 0 && alt[1]->checks != 0)
+ if (!trycheck(alt[1]->checks, FALSE))
+ return FALSE;
+
+ for (i = 0; params[i].code != EOF; i++) {
+ alt[i + 2] = findalt(objs[params[i].code - OBJMIN].vrbs, i + 1);
+ /* CHECKs in a possible parameter */
+ if (alt[i + 2] != 0 && alt[i + 2]->checks != 0)
+ if (!trycheck(alt[i + 2]->checks, FALSE))
+ return FALSE;
+ }
+
+ for (i = 0; i < 2 || params[i - 2].code != EOF; i++)
+ if (alt[i] != 0 && alt[i]->action != 0)
+ break;
+ if (i >= 2 && params[i - 2].code == EOF)
+ /* Didn't find any code for this verb/object combination */
+ return FALSE;
+ else
+ return TRUE;
}
@@ -805,131 +805,131 @@ Boolean possible() {
*/
static void do_it() {
- AltElem *alt[MAXPARAMS+2]; /* List of alt-pointers, one for each param */
- Boolean done[MAXPARAMS+2]; /* Is it done */
- int i; /* Parameter index */
- char trace[80]; /* Trace string buffer */
-
- fail = FALSE;
- alt[0] = findalt(header->vrbs, 0);
- /* Perform global checks */
- if (alt[0] != 0 && alt[0]->checks != 0) {
- if (trcflg)
- printf("\n<VERB %d, CHECK, GLOBAL:>\n", cur.vrb);
- if (!trycheck(alt[0]->checks, TRUE)) return;
- if (fail) return;
- }
-
- /* Now CHECKs in this location */
- alt[1] = findalt(locs[cur.loc-LOCMIN].vrbs, 0);
- if (alt[1] != 0 && alt[1]->checks != 0) {
- if (trcflg)
- printf("\n<VERB %d, CHECK, in LOCATION:>\n", cur.vrb);
- if (!trycheck(alt[1]->checks, TRUE)) return;
- if (fail) return;
- }
-
- for (i = 0; params[i].code != EOF; i++) {
- if (isLit(params[i].code))
- alt[i+2] = 0;
- else {
- if (isObj(params[i].code))
- alt[i+2] = findalt(objs[params[i].code-OBJMIN].vrbs, i+1);
- else if (isAct(params[i].code))
- alt[i+2] = findalt(acts[params[i].code-ACTMIN].vrbs, i+1);
- else
- syserr("Illegal parameter type.");
- /* CHECKs in the parameters */
- if (alt[i+2] != 0 && alt[i+2]->checks != 0) {
- if (trcflg)
- printf("\n<VERB %d, CHECK, in Parameter #%d:>\n", cur.vrb, i);
- if (!trycheck(alt[i+2]->checks, TRUE)) return;
- if (fail) return;
- }
- }
- }
-
- /* Check for anything to execute... */
- for (i = 0; i < 2 || params[i-2].code != EOF; i++)
- if (alt[i] != 0 && alt[i]->action != 0)
- break;
- if (i >= 2 && params[i-2].code == EOF)
- /* Didn't find any code for this verb/object combination */
- error(M_CANT0);
-
- /* Perform actions! */
-
- /* First try any BEFORE or ONLY from outside in */
- done[0] = FALSE;
- done[1] = FALSE;
- for (i = 2; params[i-2].code != EOF; i++)
- done[i] = FALSE;
- i--;
- while (i >= 0) {
- if (alt[i] != 0)
- if (alt[i]->qual == (Aword)Q_BEFORE || alt[i]->qual == (Aword)Q_ONLY) {
- if (alt[i]->action != 0) {
- if (trcflg) {
- if (i == 0)
- strcpy(trace, "GLOBAL");
- else if (i == 1)
- strcpy(trace, "in LOCATION");
- else
- sprintf(trace, "in PARAMETER %d", i-1);
- if (alt[i]->qual == (Aword)Q_BEFORE)
- printf("\n<VERB %d, %s (BEFORE), Body:>\n", cur.vrb, trace);
- else
- printf("\n<VERB %d, %s (ONLY), Body:>\n", cur.vrb, trace);
- }
- interpret(alt[i]->action);
- if (fail) return;
- if (alt[i]->qual == (Aword)Q_ONLY) return;
+ AltElem *alt[MAXPARAMS + 2]; /* List of alt-pointers, one for each param */
+ Boolean done[MAXPARAMS + 2]; /* Is it done */
+ int i; /* Parameter index */
+ char trace[80]; /* Trace string buffer */
+
+ fail = FALSE;
+ alt[0] = findalt(header->vrbs, 0);
+ /* Perform global checks */
+ if (alt[0] != 0 && alt[0]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, GLOBAL:>\n", cur.vrb);
+ if (!trycheck(alt[0]->checks, TRUE)) return;
+ if (fail) return;
}
- done[i] = TRUE;
- }
- i--;
- }
-
- /* Then execute any not declared as AFTER, i.e. the default */
- for (i = 0; i < 2 || params[i-2].code != EOF; i++) {
- if (alt[i] != 0)
- if (alt[i]->qual != (Aword)Q_AFTER) {
- if (!done[i] && alt[i]->action != 0) {
- if (trcflg) {
- if (i == 0)
- strcpy(trace, "GLOBAL");
- else if (i == 1)
- strcpy(trace, "in LOCATION");
- else
- sprintf(trace, "in PARAMETER %d", i-1);
- printf("\n<VERB %d, %s, Body:>\n", cur.vrb, trace);
- }
- interpret(alt[i]->action);
- if (fail) return;
+
+ /* Now CHECKs in this location */
+ alt[1] = findalt(locs[cur.loc - LOCMIN].vrbs, 0);
+ if (alt[1] != 0 && alt[1]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, in LOCATION:>\n", cur.vrb);
+ if (!trycheck(alt[1]->checks, TRUE)) return;
+ if (fail) return;
}
- done[i] = TRUE;
- }
- }
-
- /* Finally, the ones declared as after */
- i--;
- while (i >= 0) {
- if (alt[i] != 0)
- if (!done[i] && alt[i]->action != 0) {
- if (trcflg) {
- if (i == 0)
- strcpy(trace, "GLOBAL");
- else if (i == 1)
- strcpy(trace, "in LOCATION");
- else
- sprintf(trace, "in PARAMETER %d", i-1);
- printf("\n<VERB %d, %s (AFTER), Body:>\n", cur.vrb, trace);
+
+ for (i = 0; params[i].code != EOF; i++) {
+ if (isLit(params[i].code))
+ alt[i + 2] = 0;
+ else {
+ if (isObj(params[i].code))
+ alt[i + 2] = findalt(objs[params[i].code - OBJMIN].vrbs, i + 1);
+ else if (isAct(params[i].code))
+ alt[i + 2] = findalt(acts[params[i].code - ACTMIN].vrbs, i + 1);
+ else
+ syserr("Illegal parameter type.");
+ /* CHECKs in the parameters */
+ if (alt[i + 2] != 0 && alt[i + 2]->checks != 0) {
+ if (trcflg)
+ printf("\n<VERB %d, CHECK, in Parameter #%d:>\n", cur.vrb, i);
+ if (!trycheck(alt[i + 2]->checks, TRUE)) return;
+ if (fail) return;
+ }
+ }
+ }
+
+ /* Check for anything to execute... */
+ for (i = 0; i < 2 || params[i - 2].code != EOF; i++)
+ if (alt[i] != 0 && alt[i]->action != 0)
+ break;
+ if (i >= 2 && params[i - 2].code == EOF)
+ /* Didn't find any code for this verb/object combination */
+ error(M_CANT0);
+
+ /* Perform actions! */
+
+ /* First try any BEFORE or ONLY from outside in */
+ done[0] = FALSE;
+ done[1] = FALSE;
+ for (i = 2; params[i - 2].code != EOF; i++)
+ done[i] = FALSE;
+ i--;
+ while (i >= 0) {
+ if (alt[i] != 0)
+ if (alt[i]->qual == (Aword)Q_BEFORE || alt[i]->qual == (Aword)Q_ONLY) {
+ if (alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i - 1);
+ if (alt[i]->qual == (Aword)Q_BEFORE)
+ printf("\n<VERB %d, %s (BEFORE), Body:>\n", cur.vrb, trace);
+ else
+ printf("\n<VERB %d, %s (ONLY), Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ if (alt[i]->qual == (Aword)Q_ONLY) return;
+ }
+ done[i] = TRUE;
+ }
+ i--;
+ }
+
+ /* Then execute any not declared as AFTER, i.e. the default */
+ for (i = 0; i < 2 || params[i - 2].code != EOF; i++) {
+ if (alt[i] != 0)
+ if (alt[i]->qual != (Aword)Q_AFTER) {
+ if (!done[i] && alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i - 1);
+ printf("\n<VERB %d, %s, Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ }
+ done[i] = TRUE;
+ }
+ }
+
+ /* Finally, the ones declared as after */
+ i--;
+ while (i >= 0) {
+ if (alt[i] != 0)
+ if (!done[i] && alt[i]->action != 0) {
+ if (trcflg) {
+ if (i == 0)
+ strcpy(trace, "GLOBAL");
+ else if (i == 1)
+ strcpy(trace, "in LOCATION");
+ else
+ sprintf(trace, "in PARAMETER %d", i - 1);
+ printf("\n<VERB %d, %s (AFTER), Body:>\n", cur.vrb, trace);
+ }
+ interpret(alt[i]->action);
+ if (fail) return;
+ }
+ i--;
}
- interpret(alt[i]->action);
- if (fail) return;
- }
- i--;
- }
}
@@ -942,26 +942,26 @@ static void do_it() {
*/
void action(ParamElem plst[] /* IN - Plural parameter list */) {
- int i, mpos;
- char marker[10];
-
- if (plural) {
- /*
- The code == 0 means this is a multiple position. We must loop
- over this position (and replace it by each present in the plst)
- */
- for (mpos = 0; params[mpos].code != 0; mpos++); /* Find multiple position */
- sprintf(marker, "($%d)", mpos+1); /* Prepare a printout with $1/2/3 */
- for (i = 0; plst[i].code != EOF; i++) {
- params[mpos] = plst[i];
- output(marker);
- do_it();
- if (plst[i+1].code != EOF)
- para();
- }
- params[mpos].code = 0;
- } else
- do_it();
+ int i, mpos;
+ char marker[10];
+
+ if (plural) {
+ /*
+ The code == 0 means this is a multiple position. We must loop
+ over this position (and replace it by each present in the plst)
+ */
+ for (mpos = 0; params[mpos].code != 0; mpos++); /* Find multiple position */
+ sprintf(marker, "($%d)", mpos + 1); /* Prepare a printout with $1/2/3 */
+ for (i = 0; plst[i].code != EOF; i++) {
+ params[mpos] = plst[i];
+ output(marker);
+ do_it();
+ if (plst[i + 1].code != EOF)
+ para();
+ }
+ params[mpos].code = 0;
+ } else
+ do_it();
}
@@ -980,19 +980,19 @@ void action(ParamElem plst[] /* IN - Plural parameter list */) {
Check if any events are pending. If so execute them.
*/
static void eventchk() {
- while (etop != 0 && eventq[etop-1].time == cur.tick) {
- etop--;
- if (isLoc(eventq[etop].where))
- cur.loc = eventq[etop].where;
- else
- cur.loc = where(eventq[etop].where);
- if (trcflg) {
- printf("\n<EVENT %d (at ", eventq[etop].event);
- debugsay(cur.loc);
- printf("):>\n");
- }
- interpret(evts[eventq[etop].event-EVTMIN].code);
- }
+ while (etop != 0 && eventq[etop - 1].time == cur.tick) {
+ etop--;
+ if (isLoc(eventq[etop].where))
+ cur.loc = eventq[etop].where;
+ else
+ cur.loc = where(eventq[etop].where);
+ if (trcflg) {
+ printf("\n<EVENT %d (at ", eventq[etop].event);
+ debugsay(cur.loc);
+ printf("):>\n");
+ }
+ interpret(evts[eventq[etop].event - EVTMIN].code);
+ }
}
@@ -1027,49 +1027,49 @@ static char logfnm[256];
*/
static void checkvers(AcdHdr *header) {
- char vers[4];
- char state[2];
-
- /* Construct our own version */
- vers[0] = alan.version.version;
- vers[1] = alan.version.revision;
-
- /* Check version of .ACD file */
- if (dbgflg) {
- state[0] = header->vers[3];
- state[1] = '\0';
- printf("<Version of '%s' is %d.%d(%d)%s>",
- advnam,
- (int)(header->vers[0]),
- (int)(header->vers[1]),
- (int)(header->vers[2]),
- (header->vers[3])==0? "": state);
- newline();
- }
-
- /* Compatible if version and revision match... */
- if (strncmp(header->vers, vers, 2) != 0) {
+ char vers[4];
+ char state[2];
+
+ /* Construct our own version */
+ vers[0] = alan.version.version;
+ vers[1] = alan.version.revision;
+
+ /* Check version of .ACD file */
+ if (dbgflg) {
+ state[0] = header->vers[3];
+ state[1] = '\0';
+ printf("<Version of '%s' is %d.%d(%d)%s>",
+ advnam,
+ (int)(header->vers[0]),
+ (int)(header->vers[1]),
+ (int)(header->vers[2]),
+ (header->vers[3]) == 0 ? "" : state);
+ newline();
+ }
+
+ /* Compatible if version and revision match... */
+ if (strncmp(header->vers, vers, 2) != 0) {
#ifdef V25COMPATIBLE
- if (header->vers[0] == 2 && header->vers[1] == 5) /* Check for 2.5 version */
- /* This we can convert later if needed... */;
- else
+ if (header->vers[0] == 2 && header->vers[1] == 5) /* Check for 2.5 version */
+ /* This we can convert later if needed... */;
+ else
#endif
#ifdef V27COMPATIBLE
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
- /* This we can convert later if needed... */;
- else
+ if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ /* This we can convert later if needed... */;
+ else
#endif
- if (errflg) {
- char str[80];
- sprintf(str, "Incompatible version of ACODE program. Game is %ld.%ld, interpreter %ld.%ld.",
- (long) (header->vers[0]),
- (long) (header->vers[1]),
- (long) alan.version.version,
- (long) alan.version.revision);
- syserr(str);
- } else
- output("<WARNING! Incompatible version of ACODE program.>\n");
- }
+ if (errflg) {
+ char str[80];
+ sprintf(str, "Incompatible version of ACODE program. Game is %ld.%ld, interpreter %ld.%ld.",
+ (long)(header->vers[0]),
+ (long)(header->vers[1]),
+ (long) alan.version.version,
+ (long) alan.version.revision);
+ syserr(str);
+ } else
+ output("<WARNING! Incompatible version of ACODE program.>\n");
+ }
}
@@ -1079,77 +1079,77 @@ static void checkvers(AcdHdr *header) {
*/
static void load() {
- AcdHdr tmphdr;
- Aword crc = 0;
- int i;
- char err[100];
-
- Aword *ptr = (Aword *)&tmphdr + 1;
- codfil->seek(0);
- codfil->read(&tmphdr.vers[0], 4);
- for (i = 1; i < sizeof(tmphdr) / sizeof(Aword); ++i, ++ptr)
- *ptr = codfil->readUint32BE();
- checkvers(&tmphdr);
-
- /* Allocate and load memory */
-
- /* No memory allocated yet? */
- if (memory == NULL) {
+ AcdHdr tmphdr;
+ Aword crc = 0;
+ int i;
+ char err[100];
+
+ Aword *ptr = (Aword *)&tmphdr + 1;
+ codfil->seek(0);
+ codfil->read(&tmphdr.vers[0], 4);
+ for (i = 1; i < sizeof(tmphdr) / sizeof(Aword); ++i, ++ptr)
+ *ptr = codfil->readUint32BE();
+ checkvers(&tmphdr);
+
+ /* Allocate and load memory */
+
+ /* No memory allocated yet? */
+ if (memory == NULL) {
#ifdef V25COMPATIBLE
- if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5)
- /* We need some more memory to expand 2.5 format*/
- memory = allocate((tmphdr.size+tmphdr.objmax-tmphdr.objmin+1+2)*sizeof(Aword));
- else
+ if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5)
+ /* We need some more memory to expand 2.5 format*/
+ memory = allocate((tmphdr.size + tmphdr.objmax - tmphdr.objmin + 1 + 2) * sizeof(Aword));
+ else
#endif
- memory = (Aword *)allocate(tmphdr.size * sizeof(Aword));
- }
- memTop = tmphdr.size;
- header = (AcdHdr *) addrTo(0);
-
- if ((tmphdr.size * sizeof(Aword)) > codfil->size())
- ::error("Header size is greater than filesize");
-
- codfil->seek(0);
- codfil->read(&header->vers[0], 4);
- for (i = 1, ptr = memory + 1; i < tmphdr.size; ++i, ++ptr)
- *ptr = codfil->readUint32LE();
-
- /* Calculate checksum */
- for (i = sizeof(tmphdr)/sizeof(Aword); i < memTop; i++) {
- crc += memory[i]&0xff;
- crc += (memory[i]>>8)&0xff;
- crc += (memory[i]>>16)&0xff;
- crc += (memory[i]>>24)&0xff;
- }
- if (crc != tmphdr.acdcrc) {
- sprintf(err, "Checksum error in .ACD file (0x%lx instead of 0x%lx).",
- (unsigned long) crc, (unsigned long) tmphdr.acdcrc);
- if (errflg)
- syserr(err);
- else {
- output("<WARNING! $$");
- output(err);
- output("$$ Ignored, proceed at your own risk.>$n");
- }
- }
+ memory = (Aword *)allocate(tmphdr.size * sizeof(Aword));
+ }
+ memTop = tmphdr.size;
+ header = (AcdHdr *) addrTo(0);
+
+ if ((tmphdr.size * sizeof(Aword)) > codfil->size())
+ ::error("Header size is greater than filesize");
+
+ codfil->seek(0);
+ codfil->read(&header->vers[0], 4);
+ for (i = 1, ptr = memory + 1; i < tmphdr.size; ++i, ++ptr)
+ *ptr = codfil->readUint32LE();
+
+ /* Calculate checksum */
+ for (i = sizeof(tmphdr) / sizeof(Aword); i < memTop; i++) {
+ crc += memory[i] & 0xff;
+ crc += (memory[i] >> 8) & 0xff;
+ crc += (memory[i] >> 16) & 0xff;
+ crc += (memory[i] >> 24) & 0xff;
+ }
+ if (crc != tmphdr.acdcrc) {
+ sprintf(err, "Checksum error in .ACD file (0x%lx instead of 0x%lx).",
+ (unsigned long) crc, (unsigned long) tmphdr.acdcrc);
+ if (errflg)
+ syserr(err);
+ else {
+ output("<WARNING! $$");
+ output(err);
+ output("$$ Ignored, proceed at your own risk.>$n");
+ }
+ }
#if defined(SCUMM_LITTLE_ENDIAN)
- if (dbgflg||trcflg||stpflg)
- output("<Hmm, this is a little-endian machine, fixing byte ordering....");
- reverseACD(tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5); /* Reverse all words in the ACD file */
- if (dbgflg||trcflg||stpflg)
- output("OK.>$n");
+ if (dbgflg || trcflg || stpflg)
+ output("<Hmm, this is a little-endian machine, fixing byte ordering....");
+ reverseACD(tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5); /* Reverse all words in the ACD file */
+ if (dbgflg || trcflg || stpflg)
+ output("OK.>$n");
#endif
#ifdef V25COMPATIBLE
- /* Check for 2.5 version */
- if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5) {
- if (dbgflg||trcflg||stpflg)
- output("<Hmm, this is a v2.5 game, please wait while I convert it...");
- c25to26ACD();
- if (dbgflg||trcflg||stpflg)
- output("OK.>$n");
- }
+ /* Check for 2.5 version */
+ if (tmphdr.vers[0] == 2 && tmphdr.vers[1] == 5) {
+ if (dbgflg || trcflg || stpflg)
+ output("<Hmm, this is a v2.5 game, please wait while I convert it...");
+ c25to26ACD();
+ if (dbgflg || trcflg || stpflg)
+ output("OK.>$n");
+ }
#endif
}
@@ -1161,15 +1161,15 @@ static void load() {
*/
static void checkdebug() {
- /* Make sure he can't debug if not allowed! */
- if (!header->debug) {
- if (dbgflg|trcflg|stpflg)
- printf("<Sorry, '%s' is not compiled for debug!>\n", advnam);
- para();
- dbgflg = FALSE;
- trcflg = FALSE;
- stpflg = FALSE;
- }
+ /* Make sure he can't debug if not allowed! */
+ if (!header->debug) {
+ if (dbgflg | trcflg | stpflg)
+ printf("<Sorry, '%s' is not compiled for debug!>\n", advnam);
+ para();
+ dbgflg = FALSE;
+ trcflg = FALSE;
+ stpflg = FALSE;
+ }
}
@@ -1179,22 +1179,22 @@ static void checkdebug() {
*/
static void initheader() {
- dict = (WrdElem *) addrTo(header->dict);
- /* Find out number of entries in dictionary */
- for (dictsize = 0; !endOfTable(&dict[dictsize]); dictsize++);
- vrbs = (VrbElem *) addrTo(header->vrbs);
- stxs = (StxElem *) addrTo(header->stxs);
- locs = (LocElem *) addrTo(header->locs);
- acts = (ActElem *) addrTo(header->acts);
- objs = (ObjElem *) addrTo(header->objs);
- evts = (EvtElem *) addrTo(header->evts);
- cnts = (CntElem *) addrTo(header->cnts);
- ruls = (RulElem *) addrTo(header->ruls);
- msgs = (MsgElem *) addrTo(header->msgs);
- scores = (Aword *) addrTo(header->scores);
-
- if (header->pack)
- freq = (Aword *) addrTo(header->freq);
+ dict = (WrdElem *) addrTo(header->dict);
+ /* Find out number of entries in dictionary */
+ for (dictsize = 0; !endOfTable(&dict[dictsize]); dictsize++);
+ vrbs = (VrbElem *) addrTo(header->vrbs);
+ stxs = (StxElem *) addrTo(header->stxs);
+ locs = (LocElem *) addrTo(header->locs);
+ acts = (ActElem *) addrTo(header->acts);
+ objs = (ObjElem *) addrTo(header->objs);
+ evts = (EvtElem *) addrTo(header->evts);
+ cnts = (CntElem *) addrTo(header->cnts);
+ ruls = (RulElem *) addrTo(header->ruls);
+ msgs = (MsgElem *) addrTo(header->msgs);
+ scores = (Aword *) addrTo(header->scores);
+
+ if (header->pack)
+ freq = (Aword *) addrTo(header->freq);
}
@@ -1204,12 +1204,12 @@ static void initheader() {
*/
static void initstrings() {
- IniElem *init;
+ IniElem *init;
- for (init = (IniElem *) addrTo(header->init); !endOfTable(init); init++) {
- getstr(init->fpos, init->len);
- memory[init->adr] = pop();
- }
+ for (init = (IniElem *) addrTo(header->init); !endOfTable(init); init++) {
+ getstr(init->fpos, init->len);
+ memory[init->adr] = pop();
+ }
}
@@ -1219,19 +1219,19 @@ static void initstrings() {
*/
static void start() {
- int startloc;
-
- cur.tick = -1;
- cur.loc = startloc = where(HERO);
- cur.act = HERO;
- cur.score = 0;
- if (trcflg)
- printf("\n<START:>\n");
- interpret(header->start);
- para();
-
- acts[HERO-ACTMIN].loc = 0;
- locate(HERO, startloc);
+ int startloc;
+
+ cur.tick = -1;
+ cur.loc = startloc = where(HERO);
+ cur.act = HERO;
+ cur.score = 0;
+ if (trcflg)
+ printf("\n<START:>\n");
+ interpret(header->start);
+ para();
+
+ acts[HERO - ACTMIN].loc = 0;
+ locate(HERO, startloc);
}
@@ -1243,33 +1243,33 @@ static void start() {
*/
static void init() {
- int i;
+ int i;
- /* Initialise some status */
- etop = 0; /* No pending events */
- looking = FALSE; /* Not looking now */
- dscrstkp = 0; /* No describe in progress */
+ /* Initialise some status */
+ etop = 0; /* No pending events */
+ looking = FALSE; /* Not looking now */
+ dscrstkp = 0; /* No describe in progress */
- load();
+ load();
- initheader();
- checkdebug();
+ initheader();
+ checkdebug();
- /* Initialise string attributes */
- initstrings();
+ /* Initialise string attributes */
+ initstrings();
- getPageSize();
+ getPageSize();
- /* Find first conjunction and use that for ',' handling */
- for (i = 0; i < dictsize; i++)
- if (isConj(i)) {
- conjWord = i;
- break;
- }
+ /* Find first conjunction and use that for ',' handling */
+ for (i = 0; i < dictsize; i++)
+ if (isConj(i)) {
+ conjWord = i;
+ break;
+ }
- /* Start the adventure */
- clear();
- start();
+ /* Start the adventure */
+ clear();
+ start();
}
@@ -1281,85 +1281,85 @@ static void init() {
*/
static void movactor() {
- ScrElem *scr;
- StepElem *step;
- ActElem *act = (ActElem *) &acts[cur.act-ACTMIN];
-
- cur.loc = where(cur.act);
- if (cur.act == HERO) {
- parse();
- if (g_vm->shouldQuit())
+ ScrElem *scr;
+ StepElem *step;
+ ActElem *act = (ActElem *) &acts[cur.act - ACTMIN];
+
+ cur.loc = where(cur.act);
+ if (cur.act == HERO) {
+ parse();
+ if (g_vm->shouldQuit())
+ return;
+ fail = FALSE; /* fail only aborts one actor */
+ rules();
+ } else if (act->script != 0) {
+ for (scr = (ScrElem *) addrTo(act->scradr); !endOfTable(scr); scr++)
+ if (scr->code == act->script) {
+ /* Find correct step in the list by indexing */
+ step = (StepElem *) addrTo(scr->steps);
+ step = (StepElem *) &step[act->step];
+ /* Now execute it, maybe. First check wait count */
+ if (step->after > act->count) {
+ /* Wait some more */
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Waiting %ld more>\n",
+ act->script, act->step + 1, step->after - act->count);
+ }
+ act->count++;
+ rules();
+ return;
+ } else
+ act->count = 0;
+ /* Then check possible expression */
+ if (step->exp != 0) {
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Evaluating:>\n",
+ act->script, act->step + 1);
+ }
+ interpret(step->exp);
+ if (!(Abool)pop()) {
+ rules();
+ return; /* Hadn't happened yet */
+ }
+ }
+ /* OK, so finally let him do his thing */
+ act->step++; /* Increment step number before executing... */
+ if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), SCRIPT %ld, STEP %ld, Executing:>\n",
+ act->script, act->step);
+ }
+ interpret(step->stm);
+ step++;
+ /* ... so that we can see if he is USEing another script now */
+ if (act->step != 0 && endOfTable(step))
+ /* No more steps in this script, so stop him */
+ act->script = 0;
+ fail = FALSE; /* fail only aborts one actor */
+ rules();
+ return;
+ }
+ syserr("Unknown actor script.");
+ } else if (trcflg) {
+ printf("\n<ACTOR %d, ", cur.act);
+ debugsay(cur.act);
+ printf(" (at ");
+ debugsay(cur.loc);
+ printf("), Idle>\n");
+ rules();
return;
- fail = FALSE; /* fail only aborts one actor */
- rules();
- } else if (act->script != 0) {
- for (scr = (ScrElem *) addrTo(act->scradr); !endOfTable(scr); scr++)
- if (scr->code == act->script) {
- /* Find correct step in the list by indexing */
- step = (StepElem *) addrTo(scr->steps);
- step = (StepElem *) &step[act->step];
- /* Now execute it, maybe. First check wait count */
- if (step->after > act->count) {
- /* Wait some more */
- if (trcflg) {
- printf("\n<ACTOR %d, ", cur.act);
- debugsay(cur.act);
- printf(" (at ");
- debugsay(cur.loc);
- printf("), SCRIPT %ld, STEP %ld, Waiting %ld more>\n",
- act->script, act->step+1, step->after-act->count);
- }
- act->count++;
- rules();
- return;
- } else
- act->count = 0;
- /* Then check possible expression */
- if (step->exp != 0) {
- if (trcflg) {
- printf("\n<ACTOR %d, ", cur.act);
- debugsay(cur.act);
- printf(" (at ");
- debugsay(cur.loc);
- printf("), SCRIPT %ld, STEP %ld, Evaluating:>\n",
- act->script, act->step+1);
- }
- interpret(step->exp);
- if (!(Abool)pop()) {
- rules();
- return; /* Hadn't happened yet */
- }
- }
- /* OK, so finally let him do his thing */
- act->step++; /* Increment step number before executing... */
- if (trcflg) {
- printf("\n<ACTOR %d, ", cur.act);
- debugsay(cur.act);
- printf(" (at ");
- debugsay(cur.loc);
- printf("), SCRIPT %ld, STEP %ld, Executing:>\n",
- act->script, act->step);
}
- interpret(step->stm);
- step++;
- /* ... so that we can see if he is USEing another script now */
- if (act->step != 0 && endOfTable(step))
- /* No more steps in this script, so stop him */
- act->script = 0;
- fail = FALSE; /* fail only aborts one actor */
- rules();
- return;
- }
- syserr("Unknown actor script.");
- } else if (trcflg) {
- printf("\n<ACTOR %d, ", cur.act);
- debugsay(cur.act);
- printf(" (at ");
- debugsay(cur.loc);
- printf("), Idle>\n");
- rules();
- return;
- }
}
/*----------------------------------------------------------------------
@@ -1370,9 +1370,9 @@ static void movactor() {
*/
static void openFiles() {
- char str[256];
- char *usr = "";
- time_t tick;
+ char str[256];
+ char *usr = "";
+ time_t tick;
{
char *s = strrchr(codfnm, '\\');
@@ -1383,7 +1383,7 @@ static void openFiles() {
/* Open Text file */
strcpy(txtfnm, advnam);
strcat(txtfnm, ".dat");
-
+
Common::File *f = new Common::File();
if (!f->open(txtfnm)) {
delete f;
@@ -1399,7 +1399,7 @@ static void openFiles() {
logflg = logfil != nullptr;
}
}
-
+
/*======================================================================
@@ -1414,9 +1414,9 @@ void run() {
// Set default line and column
col = lin = 1;
- //setjmp(restart_label); /* Return here if he wanted to restart */
+ //setjmp(restart_label); /* Return here if he wanted to restart */
- init(); /* Load, initialise and start the adventure */
+ init(); /* Load, initialise and start the adventure */
while (TRUE) {
if (dbgflg)
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 4a47b77..1c21dc8 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
-
+
#ifndef GLK_ALAN2_MAIN
#define GLK_ALAN2_MAIN
@@ -35,9 +35,9 @@ namespace Alan2 {
#define MEMORYSIZE 1000L
-extern int memTop; /* Top of memory */
+extern int memTop; /* Top of memory */
-extern int conjWord; /* First conjunction in dictionary */
+extern int conjWord; /* First conjunction in dictionary */
/* The Amachine memory */
extern Aword *memory;
@@ -47,20 +47,20 @@ extern AcdHdr *header;
extern CurVars cur;
/* Amachine data structures */
-extern WrdElem *dict; /* Dictionary pointer */
-extern ActElem *acts; /* Actor table pointer */
-extern LocElem *locs; /* Location table pointer */
-extern VrbElem *vrbs; /* Verb table pointer */
-extern StxElem *stxs; /* Syntax table pointer */
-extern ObjElem *objs; /* Object table pointer */
-extern CntElem *cnts; /* Container table pointer */
-extern RulElem *ruls; /* Rule table pointer */
-extern EvtElem *evts; /* Event table pointer */
-extern MsgElem *msgs; /* Message table pointer */
-extern Aword *scores; /* Score table pointer */
-extern Aword *freq; /* Cumulated frequencies */
-
-extern int dictsize; /* Number of entries in dictionary */
+extern WrdElem *dict; /* Dictionary pointer */
+extern ActElem *acts; /* Actor table pointer */
+extern LocElem *locs; /* Location table pointer */
+extern VrbElem *vrbs; /* Verb table pointer */
+extern StxElem *stxs; /* Syntax table pointer */
+extern ObjElem *objs; /* Object table pointer */
+extern CntElem *cnts; /* Container table pointer */
+extern RulElem *ruls; /* Rule table pointer */
+extern EvtElem *evts; /* Event table pointer */
+extern MsgElem *msgs; /* Message table pointer */
+extern Aword *scores; /* Score table pointer */
+extern Aword *freq; /* Cumulated frequencies */
+
+extern int dictsize; /* Number of entries in dictionary */
/* The text and message file */
extern Common::File *txtfil;
diff --git a/engines/glk/alan2/params.cpp b/engines/glk/alan2/params.cpp
index e5414bd..8273518 100644
--- a/engines/glk/alan2/params.cpp
+++ b/engines/glk/alan2/params.cpp
@@ -28,74 +28,74 @@ namespace Glk {
namespace Alan2 {
void compact(ParamElem a[]) {
- int i, j;
-
- for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
- if (a[j].code != 0)
- a[i++] = a[j];
- a[i].code = (Aword)EOF;
+ int i, j;
+
+ for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
+ if (a[j].code != 0)
+ a[i++] = a[j];
+ a[i].code = (Aword)EOF;
}
int lstlen(ParamElem a[]) {
- int i = 0;
+ int i = 0;
- while (a[i].code != (Aword)EOF)
- i++;
- return (i);
+ while (a[i].code != (Aword)EOF)
+ i++;
+ return (i);
}
Boolean inlst(ParamElem l[], Aword e) {
- int i;
+ int i;
- for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
- return (l[i].code == e);
+ for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
+ return (l[i].code == e);
}
void lstcpy(ParamElem a[], ParamElem b[]) {
- int i;
+ int i;
- for (i = 0; b[i].code != (Aword)EOF; i++)
- a[i] = b[i];
- a[i].code = (Aword)EOF;
+ for (i = 0; b[i].code != (Aword)EOF; i++)
+ a[i] = b[i];
+ a[i].code = (Aword)EOF;
}
void sublst(ParamElem a[], ParamElem b[]) {
- int i;
+ int i;
- for (i = 0; a[i].code != (Aword)EOF; i++)
- if (inlst(b, a[i].code))
- a[i].code = 0; /* Mark empty */
- compact(a);
+ for (i = 0; a[i].code != (Aword)EOF; i++)
+ if (inlst(b, a[i].code))
+ a[i].code = 0; /* Mark empty */
+ compact(a);
}
void mrglst(ParamElem a[], ParamElem b[]) {
- int i,last;
-
- for (last = 0; a[last].code != (Aword)EOF; last++); /* Find end of list */
- for (i = 0; b[i].code != (Aword)EOF; i++)
- if (!inlst(a, b[i].code)) {
- a[last++] = b[i];
- a[last].code = (Aword)EOF;
- }
+ int i, last;
+
+ for (last = 0; a[last].code != (Aword)EOF; last++); /* Find end of list */
+ for (i = 0; b[i].code != (Aword)EOF; i++)
+ if (!inlst(a, b[i].code)) {
+ a[last++] = b[i];
+ a[last].code = (Aword)EOF;
+ }
}
void isect(ParamElem a[], ParamElem b[]) {
- int i, last = 0;
+ int i, last = 0;
- for (i = 0; a[i].code != (Aword)EOF; i++)
- if (inlst(b, a[i].code))
- a[last++] = a[i];
- a[last].code = (Aword)EOF;
+ for (i = 0; a[i].code != (Aword)EOF; i++)
+ if (inlst(b, a[i].code))
+ a[last++] = a[i];
+ a[last].code = (Aword)EOF;
}
void cpyrefs(ParamElem p[], Aword r[]) {
- int i;
+ int i;
- for (i = 0; r[i] != (Aword)EOF; i++) {
- p[i].code = r[i];
- p[i].firstWord = (Aword)EOF;
- }
- p[i].code = (Aword)EOF;
+ for (i = 0; r[i] != (Aword)EOF; i++) {
+ p[i].code = r[i];
+ p[i].firstWord = (Aword)EOF;
+ }
+ p[i].code = (Aword)EOF;
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index d83755b..db478ff 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -41,26 +41,26 @@ namespace Alan2 {
/* PUBLIC DATA */
-int wrds[LISTLEN/2] = {EOF}; /* List of parsed words */
-int wrdidx; /* and an index into it */
+int wrds[LISTLEN / 2] = {EOF}; /* List of parsed words */
+int wrdidx; /* and an index into it */
Boolean plural = FALSE;
/* Syntax Parameters */
-int paramidx; /* Index in params */
-ParamElem *params; /* List of params */
-static ParamElem *pparams; /* Previous parameter list */
-static ParamElem *mlst; /* Multiple objects list */
-static ParamElem *pmlst; /* Previous multiple list */
+int paramidx; /* Index in params */
+ParamElem *params; /* List of params */
+static ParamElem *pparams; /* Previous parameter list */
+static ParamElem *mlst; /* Multiple objects list */
+static ParamElem *pmlst; /* Previous multiple list */
/* Literals */
-LitElem litValues[MAXPARAMS+1];
+LitElem litValues[MAXPARAMS + 1];
int litCount;
/* What did the user say? */
-int vrbwrd; /* The word he used */
-int vrbcode; /* The code for that verb */
+int vrbwrd; /* The word he used */
+int vrbcode; /* The code for that verb */
/*----------------------------------------------------------------------*\
@@ -82,23 +82,23 @@ int vrbcode; /* The code for that verb */
/* PRIVATE DATA */
-static char buf[LISTLEN+1]; /* The input buffer */
-static char isobuf[LISTLEN+1]; /* The input buffer in ISO */
+static char buf[LISTLEN + 1]; /* The input buffer */
+static char isobuf[LISTLEN + 1]; /* The input buffer in ISO */
-static Boolean eol = TRUE; /* Looking at End of line? Yes, initially */
+static Boolean eol = TRUE; /* Looking at End of line? Yes, initially */
static void unknown(char token[]) {
- char *str = (char *)allocate((int)strlen(token)+4);
-
- str[0] = '\'';
- strcpy(&str[1], token);
- strcat(str, "'?");
- output(str);
- free(str);
- eol = TRUE;
- error(M_UNKNOWN_WORD);
+ char *str = (char *)allocate((int)strlen(token) + 4);
+
+ str[0] = '\'';
+ strcpy(&str[1], token);
+ strcat(str, "'?");
+ output(str);
+ free(str);
+ eol = TRUE;
+ error(M_UNKNOWN_WORD);
}
@@ -106,127 +106,127 @@ static char *token;
static int lookup(char wrd[]) {
- int i;
-
- for (i = 0; !endOfTable(&dict[i]); i++) {
- if (strcmp(wrd, (char *) addrTo(dict[i].wrd)) == 0)
- return (i);
- }
- unknown(wrd);
- return(EOF);
+ int i;
+
+ for (i = 0; !endOfTable(&dict[i]); i++) {
+ if (strcmp(wrd, (char *) addrTo(dict[i].wrd)) == 0)
+ return (i);
+ }
+ unknown(wrd);
+ return (EOF);
}
-static int number(char token[] /* IN - The string to convert to a number */) {
- int i;
+static int number(char token[] /* IN - The string to convert to a number */) {
+ int i;
- sscanf(token, "%d", &i);
- return i;
+ sscanf(token, "%d", &i);
+ return i;
}
static char *gettoken(char *buf) {
- static char *marker;
- static char oldch;
-
- if (buf == NULL)
- *marker = oldch;
- else
- marker = buf;
- while (*marker != '\0' && isSpace(*marker) && *marker != '\n') marker++;
- buf = marker;
- if (isISOLetter(*marker))
- while (*marker&&(isISOLetter(*marker)||isdigit(*marker)||*marker=='\'')) marker++;
- else if (isdigit(*marker))
- while (isdigit(*marker)) marker++;
- else if (*marker == '\"') {
- marker++;
- while (*marker != '\"') marker++;
- marker++;
- } else if (*marker == '\0' || *marker == '\n')
- return NULL;
- else
- marker++;
- oldch = *marker;
- *marker = '\0';
- return buf;
+ static char *marker;
+ static char oldch;
+
+ if (buf == NULL)
+ *marker = oldch;
+ else
+ marker = buf;
+ while (*marker != '\0' && isSpace(*marker) && *marker != '\n') marker++;
+ buf = marker;
+ if (isISOLetter(*marker))
+ while (*marker && (isISOLetter(*marker) || isdigit(*marker) || *marker == '\'')) marker++;
+ else if (isdigit(*marker))
+ while (isdigit(*marker)) marker++;
+ else if (*marker == '\"') {
+ marker++;
+ while (*marker != '\"') marker++;
+ marker++;
+ } else if (*marker == '\0' || *marker == '\n')
+ return NULL;
+ else
+ marker++;
+ oldch = *marker;
+ *marker = '\0';
+ return buf;
}
static void agetline() {
- para();
- do {
- statusline();
-
- printf("> ");
- if (logflg)
- fprintf(logfil, "> ");
-
- if (!readline(buf)) {
- if (g_vm->shouldQuit())
- return;
-
- newline();
- quit();
- }
-
- getPageSize();
- anyOutput = FALSE;
- if (logflg)
- fprintf(logfil, "%s\n", buf);
- strcpy(isobuf, buf);
-
- token = gettoken(isobuf);
- if (token != NULL && strcmp("debug", token) == 0 && header->debug) {
- dbgflg = TRUE;
- debug();
- token = NULL;
- }
- } while (token == NULL);
- eol = FALSE;
- lin = 1;
+ para();
+ do {
+ statusline();
+
+ printf("> ");
+ if (logflg)
+ fprintf(logfil, "> ");
+
+ if (!readline(buf)) {
+ if (g_vm->shouldQuit())
+ return;
+
+ newline();
+ quit();
+ }
+
+ getPageSize();
+ anyOutput = FALSE;
+ if (logflg)
+ fprintf(logfil, "%s\n", buf);
+ strcpy(isobuf, buf);
+
+ token = gettoken(isobuf);
+ if (token != NULL && strcmp("debug", token) == 0 && header->debug) {
+ dbgflg = TRUE;
+ debug();
+ token = NULL;
+ }
+ } while (token == NULL);
+ eol = FALSE;
+ lin = 1;
}
static void scan() {
- int i;
- int w;
- char *str;
-
- agetline();
- if (g_vm->shouldQuit())
- return;
-
- wrds[0] = 0;
- for (i = 0; i < litCount; i++)
- if (litValues[i].type == TYPSTR && litValues[i].value != 0)
- free((char *) litValues[i].value);
- i = 0;
- litCount = 0;
- do {
- if (isISOLetter(token[0])) {
- (void) stringLower(token);
- w = lookup(token);
- if (!isNoise(w))
- wrds[i++] = w;
- } else if (isdigit(token[0])) {
- if (litCount > MAXPARAMS)
- syserr("Too many parameters.");
- wrds[i++] = dictsize+litCount; /* Word outside dictionary = literal */
- litValues[litCount].type = TYPNUM;
- litValues[litCount++].value = number(token);
- } else if (token[0] == '\"') {
- if (litCount > MAXPARAMS)
- syserr("Too many parameters.");
- wrds[i++] = dictsize+litCount; /* Word outside dictionary = literal */
- litValues[litCount].type = TYPSTR;
- /* Remove the string quotes while copying */
- str = strdup(&token[1]);
- str[strlen(token)-2] = '\0';
- litValues[litCount++].value = (Aptr) str;
- } else if (token[0] == ',') {
- wrds[i++] = conjWord;
- } else
- unknown(token);
- wrds[i] = EOF;
- eol = (token = gettoken(NULL)) == NULL;
- } while (!eol);
+ int i;
+ int w;
+ char *str;
+
+ agetline();
+ if (g_vm->shouldQuit())
+ return;
+
+ wrds[0] = 0;
+ for (i = 0; i < litCount; i++)
+ if (litValues[i].type == TYPSTR && litValues[i].value != 0)
+ free((char *) litValues[i].value);
+ i = 0;
+ litCount = 0;
+ do {
+ if (isISOLetter(token[0])) {
+ (void) stringLower(token);
+ w = lookup(token);
+ if (!isNoise(w))
+ wrds[i++] = w;
+ } else if (isdigit(token[0])) {
+ if (litCount > MAXPARAMS)
+ syserr("Too many parameters.");
+ wrds[i++] = dictsize + litCount; /* Word outside dictionary = literal */
+ litValues[litCount].type = TYPNUM;
+ litValues[litCount++].value = number(token);
+ } else if (token[0] == '\"') {
+ if (litCount > MAXPARAMS)
+ syserr("Too many parameters.");
+ wrds[i++] = dictsize + litCount; /* Word outside dictionary = literal */
+ litValues[litCount].type = TYPSTR;
+ /* Remove the string quotes while copying */
+ str = strdup(&token[1]);
+ str[strlen(token) - 2] = '\0';
+ litValues[litCount++].value = (Aptr) str;
+ } else if (token[0] == ',') {
+ wrds[i++] = conjWord;
+ } else
+ unknown(token);
+ wrds[i] = EOF;
+ eol = (token = gettoken(NULL)) == NULL;
+ } while (!eol);
}
@@ -236,200 +236,200 @@ static void scan() {
All procedures and data for getting a command and parsing it
- nonverb() - search for a non-verb command
- buildall() - build a list of objects matching 'all'
- unambig() - match an unambigous object reference
- simple() - match a simple verb command
- complex() - match a complex -"-
+ nonverb() - search for a non-verb command
+ buildall() - build a list of objects matching 'all'
+ unambig() - match an unambigous object reference
+ simple() - match a simple verb command
+ complex() - match a complex -"-
tryMatch()- to match a verb command
- match() - find the verb class (not used currently) and 'tryMatch()'
+ match() - find the verb class (not used currently) and 'tryMatch()'
\*---------------------------------------------------------------------- */
-static int allLength; /* No. of objects matching 'all' */
+static int allLength; /* No. of objects matching 'all' */
static void nonverb() {
- if (isDir(wrds[wrdidx])) {
- wrdidx++;
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
- error(M_WHAT);
- else
- go(dict[wrds[wrdidx-1]].code);
- if (wrds[wrdidx] != EOF)
- wrdidx++;
- } else
- error(M_WHAT);
+ if (isDir(wrds[wrdidx])) {
+ wrdidx++;
+ if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ error(M_WHAT);
+ else
+ go(dict[wrds[wrdidx - 1]].code);
+ if (wrds[wrdidx] != EOF)
+ wrdidx++;
+ } else
+ error(M_WHAT);
}
static void buildall(ParamElem list[]) {
- int o, i = 0;
- Boolean found = FALSE;
-
- for (o = OBJMIN; o <= OBJMAX; o++)
- if (isHere(o)) {
- found = TRUE;
- list[i].code = o;
- list[i++].firstWord = EOF;
- }
- if (!found)
- error(M_WHAT_ALL);
- else
- list[i].code = EOF;
+ int o, i = 0;
+ Boolean found = FALSE;
+
+ for (o = OBJMIN; o <= OBJMAX; o++)
+ if (isHere(o)) {
+ found = TRUE;
+ list[i].code = o;
+ list[i++].firstWord = EOF;
+ }
+ if (!found)
+ error(M_WHAT_ALL);
+ else
+ list[i].code = EOF;
}
static void unambig(ParamElem plst[]) {
- int i;
- Boolean found = FALSE; /* Adjective or noun found ? */
- static ParamElem *refs; /* Entities referenced by word */
- static ParamElem *savlst; /* Saved list for backup at EOF */
- int firstWord, lastWord; /* The words the player used */
-
- if (refs == NULL)
- refs = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem));
-
- if (savlst == NULL)
- savlst = (ParamElem *)allocate((MAXENTITY+1)*sizeof(ParamElem));
-
- if (isLiteral(wrds[wrdidx])) {
- /* Transform the word into a reference to the literal value */
- plst[0].code = wrds[wrdidx++]-dictsize+LITMIN;
- plst[0].firstWord = EOF; /* No words used! */
- plst[1].code = EOF;
- return;
- }
-
- plst[0].code = EOF; /* Make empty */
- if (isIt(wrds[wrdidx])) {
- wrdidx++;
- /* Use last object in previous command! */
- for (i = lstlen(pparams)-1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--);
- if (i < 0)
- error(M_WHAT_IT);
- if (!isHere(pparams[i].code)) {
- params[0].code = pparams[i].code;
- params[0].firstWord = EOF;
- params[1].code = EOF;
- error(M_NO_SUCH);
- }
- plst[0] = pparams[i];
- plst[0].firstWord = EOF; /* No words used! */
- plst[1].code = EOF;
- return;
- }
-
- firstWord = wrdidx;
- while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) {
- /* If this word can be a noun and there is no noun following break loop */
- if (isNoun(wrds[wrdidx]) && (wrds[wrdidx+1] == EOF || !isNoun(wrds[wrdidx+1])))
- break;
- cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs));
- lstcpy(savlst, plst); /* To save it for backtracking */
- if (found)
- isect(plst, refs);
- else {
- lstcpy(plst, refs);
- found = TRUE;
- }
- wrdidx++;
- }
- if (wrds[wrdidx] != EOF) {
- if (isNoun(wrds[wrdidx])) {
- cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs));
- if (found)
- isect(plst, refs);
- else {
- lstcpy(plst, refs);
- found = TRUE;
- }
- wrdidx++;
- } else
- error(M_NOUN);
- } else if (found) {
- if (isNoun(wrds[wrdidx-1])) {
- /* Perhaps the last word was also a noun? */
- lstcpy(plst, savlst); /* Restore to before last adjective */
- cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx-1]].nounrefs));
- if (plst[0].code == EOF)
- lstcpy(plst, refs);
- else
- isect(plst, refs);
- } else
- error(M_NOUN);
- }
- lastWord = wrdidx-1;
-
- /* Allow remote objects, but resolve ambiguities by presence */
- if (lstlen(plst) > 1) {
- for (i=0; plst[i].code != EOF; i++)
- if (!isHere(plst[i].code))
- plst[i].code = 0;
- compact(plst);
- }
-
- if (lstlen(plst) > 1 || (found && lstlen(plst) == 0)) {
- params[0].code = 0; /* Just make it anything != EOF */
- params[0].firstWord = firstWord; /* Remember words for errors below */
- params[0].lastWord = lastWord;
- params[1].code = EOF; /* But be sure to terminate */
- if (lstlen(plst) > 1)
- error(M_WHICH_ONE);
- else if (found && lstlen(plst) == 0)
- error(M_NO_SUCH);
- } else {
- plst[0].firstWord = firstWord;
- plst[0].lastWord = lastWord;
- }
+ int i;
+ Boolean found = FALSE; /* Adjective or noun found ? */
+ static ParamElem *refs; /* Entities referenced by word */
+ static ParamElem *savlst; /* Saved list for backup at EOF */
+ int firstWord, lastWord; /* The words the player used */
+
+ if (refs == NULL)
+ refs = (ParamElem *)allocate((MAXENTITY + 1) * sizeof(ParamElem));
+
+ if (savlst == NULL)
+ savlst = (ParamElem *)allocate((MAXENTITY + 1) * sizeof(ParamElem));
+
+ if (isLiteral(wrds[wrdidx])) {
+ /* Transform the word into a reference to the literal value */
+ plst[0].code = wrds[wrdidx++] - dictsize + LITMIN;
+ plst[0].firstWord = EOF; /* No words used! */
+ plst[1].code = EOF;
+ return;
+ }
+
+ plst[0].code = EOF; /* Make empty */
+ if (isIt(wrds[wrdidx])) {
+ wrdidx++;
+ /* Use last object in previous command! */
+ for (i = lstlen(pparams) - 1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--);
+ if (i < 0)
+ error(M_WHAT_IT);
+ if (!isHere(pparams[i].code)) {
+ params[0].code = pparams[i].code;
+ params[0].firstWord = EOF;
+ params[1].code = EOF;
+ error(M_NO_SUCH);
+ }
+ plst[0] = pparams[i];
+ plst[0].firstWord = EOF; /* No words used! */
+ plst[1].code = EOF;
+ return;
+ }
+
+ firstWord = wrdidx;
+ while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) {
+ /* If this word can be a noun and there is no noun following break loop */
+ if (isNoun(wrds[wrdidx]) && (wrds[wrdidx + 1] == EOF || !isNoun(wrds[wrdidx + 1])))
+ break;
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs));
+ lstcpy(savlst, plst); /* To save it for backtracking */
+ if (found)
+ isect(plst, refs);
+ else {
+ lstcpy(plst, refs);
+ found = TRUE;
+ }
+ wrdidx++;
+ }
+ if (wrds[wrdidx] != EOF) {
+ if (isNoun(wrds[wrdidx])) {
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs));
+ if (found)
+ isect(plst, refs);
+ else {
+ lstcpy(plst, refs);
+ found = TRUE;
+ }
+ wrdidx++;
+ } else
+ error(M_NOUN);
+ } else if (found) {
+ if (isNoun(wrds[wrdidx - 1])) {
+ /* Perhaps the last word was also a noun? */
+ lstcpy(plst, savlst); /* Restore to before last adjective */
+ cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx - 1]].nounrefs));
+ if (plst[0].code == EOF)
+ lstcpy(plst, refs);
+ else
+ isect(plst, refs);
+ } else
+ error(M_NOUN);
+ }
+ lastWord = wrdidx - 1;
+
+ /* Allow remote objects, but resolve ambiguities by presence */
+ if (lstlen(plst) > 1) {
+ for (i = 0; plst[i].code != EOF; i++)
+ if (!isHere(plst[i].code))
+ plst[i].code = 0;
+ compact(plst);
+ }
+
+ if (lstlen(plst) > 1 || (found && lstlen(plst) == 0)) {
+ params[0].code = 0; /* Just make it anything != EOF */
+ params[0].firstWord = firstWord; /* Remember words for errors below */
+ params[0].lastWord = lastWord;
+ params[1].code = EOF; /* But be sure to terminate */
+ if (lstlen(plst) > 1)
+ error(M_WHICH_ONE);
+ else if (found && lstlen(plst) == 0)
+ error(M_NO_SUCH);
+ } else {
+ plst[0].firstWord = firstWord;
+ plst[0].lastWord = lastWord;
+ }
}
-
+
static void simple(ParamElem olst[]) {
- static ParamElem *tlst = NULL;
- int savidx = wrdidx;
- Boolean savplur = FALSE;
- int i;
-
- if (tlst == NULL)
- tlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
- tlst[0].code = EOF;
-
- for (;;) {
- if (isThem(wrds[wrdidx])) {
- plural = TRUE;
- for (i = 0; pmlst[i].code != EOF; i++)
- if (!isHere(pmlst[i].code))
- pmlst[i].code = 0;
- compact(pmlst);
- if (lstlen(pmlst) == 0)
- error(M_WHAT_THEM);
- lstcpy(olst, pmlst);
- olst[0].firstWord = EOF; /* No words used */
- wrdidx++;
- } else {
- unambig(olst); /* Look for unambigous noun phrase */
- if (lstlen(olst) == 0) { /* Failed! */
- lstcpy(olst, tlst);
- wrdidx = savidx;
- plural = savplur;
- return;
- }
- }
- mrglst(tlst, olst);
- if (wrds[wrdidx] != EOF
- && (isConj(wrds[wrdidx]) &&
- (isAdj(wrds[wrdidx+1]) || isNoun(wrds[wrdidx+1])))) {
- /* More parameters in a conjunction separated list ? */
- savplur = plural;
- savidx = wrdidx;
- wrdidx++;
- plural = TRUE;
- } else {
- lstcpy(olst, tlst);
- return;
- }
- }
+ static ParamElem *tlst = NULL;
+ int savidx = wrdidx;
+ Boolean savplur = FALSE;
+ int i;
+
+ if (tlst == NULL)
+ tlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
+ tlst[0].code = EOF;
+
+ for (;;) {
+ if (isThem(wrds[wrdidx])) {
+ plural = TRUE;
+ for (i = 0; pmlst[i].code != EOF; i++)
+ if (!isHere(pmlst[i].code))
+ pmlst[i].code = 0;
+ compact(pmlst);
+ if (lstlen(pmlst) == 0)
+ error(M_WHAT_THEM);
+ lstcpy(olst, pmlst);
+ olst[0].firstWord = EOF; /* No words used */
+ wrdidx++;
+ } else {
+ unambig(olst); /* Look for unambigous noun phrase */
+ if (lstlen(olst) == 0) { /* Failed! */
+ lstcpy(olst, tlst);
+ wrdidx = savidx;
+ plural = savplur;
+ return;
+ }
+ }
+ mrglst(tlst, olst);
+ if (wrds[wrdidx] != EOF
+ && (isConj(wrds[wrdidx]) &&
+ (isAdj(wrds[wrdidx + 1]) || isNoun(wrds[wrdidx + 1])))) {
+ /* More parameters in a conjunction separated list ? */
+ savplur = plural;
+ savidx = wrdidx;
+ wrdidx++;
+ plural = TRUE;
+ } else {
+ lstcpy(olst, tlst);
+ return;
+ }
+ }
}
-
-
+
+
/*----------------------------------------------------------------------
complex()
@@ -440,51 +440,51 @@ static void simple(ParamElem olst[]) {
*/
static void complex(ParamElem olst[]) {
- static ParamElem *alst = NULL;
-
- if (alst == NULL)
- alst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem));
-
- if (isAll(wrds[wrdidx])) {
- plural = TRUE;
- buildall(alst); /* Build list of all objects */
- wrdidx++;
- if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) {
- wrdidx++;
- simple(olst);
- if (lstlen(olst) == 0)
- error(M_AFTER_BUT);
- sublst(alst, olst);
- if (lstlen(alst) == 0)
- error(M_NOT_MUCH);
- }
- lstcpy(olst, alst);
- allLength = lstlen(olst);
- } else
- simple(olst); /* Look for simple noun group */
+ static ParamElem *alst = NULL;
+
+ if (alst == NULL)
+ alst = (ParamElem *) allocate((MAXENTITY + 1) * sizeof(ParamElem));
+
+ if (isAll(wrds[wrdidx])) {
+ plural = TRUE;
+ buildall(alst); /* Build list of all objects */
+ wrdidx++;
+ if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) {
+ wrdidx++;
+ simple(olst);
+ if (lstlen(olst) == 0)
+ error(M_AFTER_BUT);
+ sublst(alst, olst);
+ if (lstlen(alst) == 0)
+ error(M_NOT_MUCH);
+ }
+ lstcpy(olst, alst);
+ allLength = lstlen(olst);
+ } else
+ simple(olst); /* Look for simple noun group */
}
static Boolean claCheck(ClaElem *cla /* IN - The cla elem to check */) {
- Boolean ok = FALSE;
-
- if ((cla->classes&(Aword)CLA_OBJ) != 0)
- ok = ok || isObj(params[cla->code-1].code);
- if ((cla->classes&(Aword)CLA_CNT) != 0)
- ok = ok || isCnt(params[cla->code-1].code);
- if ((cla->classes&(Aword)CLA_ACT) != 0)
- ok = ok || isAct(params[cla->code-1].code);
- if ((cla->classes&(Aword)CLA_NUM) != 0)
- ok = ok || isNum(params[cla->code-1].code);
- if ((cla->classes&(Aword)CLA_STR) != 0)
- ok = ok || isStr(params[cla->code-1].code);
- if ((cla->classes&(Aword)CLA_COBJ) != 0)
- ok = ok || (isCnt(params[cla->code-1].code) && isObj(params[cla->code-1].code));
- if ((cla->classes&(Aword)CLA_CACT) != 0)
- ok = ok || (isCnt(params[cla->code-1].code) && isAct(params[cla->code-1].code));
- return ok;
+ Boolean ok = FALSE;
+
+ if ((cla->classes & (Aword)CLA_OBJ) != 0)
+ ok = ok || isObj(params[cla->code - 1].code);
+ if ((cla->classes & (Aword)CLA_CNT) != 0)
+ ok = ok || isCnt(params[cla->code - 1].code);
+ if ((cla->classes & (Aword)CLA_ACT) != 0)
+ ok = ok || isAct(params[cla->code - 1].code);
+ if ((cla->classes & (Aword)CLA_NUM) != 0)
+ ok = ok || isNum(params[cla->code - 1].code);
+ if ((cla->classes & (Aword)CLA_STR) != 0)
+ ok = ok || isStr(params[cla->code - 1].code);
+ if ((cla->classes & (Aword)CLA_COBJ) != 0)
+ ok = ok || (isCnt(params[cla->code - 1].code) && isObj(params[cla->code - 1].code));
+ if ((cla->classes & (Aword)CLA_CACT) != 0)
+ ok = ok || (isCnt(params[cla->code - 1].code) && isAct(params[cla->code - 1].code));
+ return ok;
}
-
+
/*----------------------------------------------------------------------
resolve()
@@ -494,215 +494,215 @@ static Boolean claCheck(ClaElem *cla /* IN - The cla elem to check */) {
*/
static void resolve(ParamElem plst[]) {
- int i;
-
- if (allLength > 0) return; /* ALL has already done this */
-
- /* Resolve ambiguities by presence */
- for (i=0; plst[i].code != EOF; i++)
- if (plst[i].code < LITMIN) /* Literals are always 'here' */
- if (!isHere(plst[i].code)) {
- params[0] = plst[i]; /* Copy error param as first one for message */
- params[1].code = EOF; /* But be sure to terminate */
- error(M_NO_SUCH);
- }
+ int i;
+
+ if (allLength > 0) return; /* ALL has already done this */
+
+ /* Resolve ambiguities by presence */
+ for (i = 0; plst[i].code != EOF; i++)
+ if (plst[i].code < LITMIN) /* Literals are always 'here' */
+ if (!isHere(plst[i].code)) {
+ params[0] = plst[i]; /* Copy error param as first one for message */
+ params[1].code = EOF; /* But be sure to terminate */
+ error(M_NO_SUCH);
+ }
}
static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multiple */) {
- ElmElem *elms; /* Pointer to element list */
- StxElem *stx; /* Pointer to syntax list */
- ClaElem *cla; /* Pointer to class definitions */
- Boolean anyPlural = FALSE; /* Any parameter that was plural? */
- int i, p;
- static ParamElem *tlst = NULL; /* List of params found by complex() */
- static Boolean *checked = NULL; /* Corresponding parameter checked? */
-
- if (tlst == NULL) {
- tlst = (ParamElem *) allocate((MAXENTITY+1)*sizeof(ParamElem));
- checked = (Boolean *) allocate((MAXENTITY+1)*sizeof(Boolean));
- }
-
- for (stx = stxs; !endOfTable(stx); stx++)
- if (stx->code == vrbcode)
- break;
- if (endOfTable(stx))
- error(M_WHAT);
-
- elms = (ElmElem *) addrTo(stx->elms);
-
- while (TRUE) {
- /* End of input? */
- if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) {
- while (!endOfTable(elms) && elms->code != EOS)
- elms++;
- if (endOfTable(elms))
- error(M_WHAT);
- else
- break;
- } else {
- /* A preposition? */
- if (isPrep(wrds[wrdidx])) {
- while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code)
- elms++;
- if (endOfTable(elms))
- error(M_WHAT);
- else
- wrdidx++;
- } else {
- /* Must be a parameter! */
- while (!endOfTable(elms) && elms->code != 0)
- elms++;
- if (endOfTable(elms))
- error(M_WHAT);
- /* Get it! */
- plural = FALSE;
- complex(tlst);
- if (lstlen(tlst) == 0) /* No object!? */
- error(M_WHAT);
- if ((elms->flags & OMNIBIT) == 0) /* Omnipotent parameter? */
- /* If its not an omnipotent parameter, resolve by presence */
- resolve(tlst);
- if (plural) {
- if ((elms->flags & MULTIPLEBIT) == 0) /* Allowed multiple? */
- error(M_MULTIPLE);
- else {
- /*
- Mark this as the multiple position in which to insert
- actual parameter values later
- */
- params[paramidx++].code = 0;
- lstcpy(mlst, tlst);
- anyPlural = TRUE;
- }
- } else
- params[paramidx++] = tlst[0];
- params[paramidx].code = EOF;
- }
- elms = (ElmElem *) addrTo(elms->next);
- }
- }
-
- /* Now perform class checks */
- if (elms->next == 0) /* No verb code, verb not declared! */
- error(M_CANT0);
-
- for (p = 0; params[p].code != EOF; p++) /* Mark all parameters unchecked */
- checked[p] = FALSE;
- for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
- if (params[cla->code-1].code == 0) {
- /* This was a multiple parameter, so check all and remove failing */
- for (i = 0; mlst[i].code != EOF; i++) {
- params[cla->code-1] = mlst[i];
- if (!claCheck(cla)) {
- /* Multiple could be both an explicit list of params and an ALL */
- if (allLength == 0) {
- char marker[80];
- /*
- It wasn't ALL, we need to say something about it, so
- prepare a printout with $1/2/3
- */
- sprintf(marker, "($%ld)", (unsigned long) cla->code);
- output(marker);
- interpret(cla->stms);
- para();
- }
- mlst[i].code = 0; /* In any case remove it from the list */
+ ElmElem *elms; /* Pointer to element list */
+ StxElem *stx; /* Pointer to syntax list */
+ ClaElem *cla; /* Pointer to class definitions */
+ Boolean anyPlural = FALSE; /* Any parameter that was plural? */
+ int i, p;
+ static ParamElem *tlst = NULL; /* List of params found by complex() */
+ static Boolean *checked = NULL; /* Corresponding parameter checked? */
+
+ if (tlst == NULL) {
+ tlst = (ParamElem *) allocate((MAXENTITY + 1) * sizeof(ParamElem));
+ checked = (Boolean *) allocate((MAXENTITY + 1) * sizeof(Boolean));
}
- }
- params[cla->code-1].code = 0;
- } else {
- if (!claCheck(cla)) {
- interpret(cla->stms);
- error(MSGMAX); /* Return to player without saying anything */
- }
- }
- checked[cla->code-1] = TRUE; /* Remember that it's already checked */
- }
- /* Now check the rest of the parameters, must be objects */
- for (p = 0; params[p].code != EOF; p++)
- if (!checked[p]) {
- if (params[p].code == 0) {
- /* This was a multiple parameter, check all and remove failing */
- for (i = 0; mlst[i].code != EOF; i++)
- if (mlst[i].code != 0) /* Skip any empty slots */
- if (!isObj(mlst[i].code))
- mlst[i].code = 0;
- } else if (!isObj(params[p].code))
- error(M_CANT0);
- }
-
- /* Set verb code */
- cur.vrb = ((Aword *) cla)[1]; /* Take first word after end of table! */
-
- /* Finally, if ALL was used, try to find out what was applicable */
- if (allLength > 0) {
- for (p = 0; params[p].code != 0; p++); /* Find multiple marker */
- for (i = 0; i < allLength; i++) {
- if (mlst[i].code != 0) { /* Already empty? */
- params[p] = mlst[i];
- if (!possible())
- mlst[i].code = 0; /* Remove this from list */
- }
- }
- params[p].code = 0; /* Restore multiple marker */
- compact(mlst);
- if (lstlen(mlst) == 0) {
- params[0].code = EOF;
- error(M_WHAT_ALL);
- }
- } else if (anyPlural) {
- compact(mlst);
- if (lstlen(mlst) == 0)
- /* If there where multiple parameters but non left, exit without a */
- /* word, assuming we have already said enough */
- error(MSGMAX);
- }
- plural = anyPlural; /* Remember that we found plural objects */
+
+ for (stx = stxs; !endOfTable(stx); stx++)
+ if (stx->code == vrbcode)
+ break;
+ if (endOfTable(stx))
+ error(M_WHAT);
+
+ elms = (ElmElem *) addrTo(stx->elms);
+
+ while (TRUE) {
+ /* End of input? */
+ if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) {
+ while (!endOfTable(elms) && elms->code != EOS)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ else
+ break;
+ } else {
+ /* A preposition? */
+ if (isPrep(wrds[wrdidx])) {
+ while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ else
+ wrdidx++;
+ } else {
+ /* Must be a parameter! */
+ while (!endOfTable(elms) && elms->code != 0)
+ elms++;
+ if (endOfTable(elms))
+ error(M_WHAT);
+ /* Get it! */
+ plural = FALSE;
+ complex(tlst);
+ if (lstlen(tlst) == 0) /* No object!? */
+ error(M_WHAT);
+ if ((elms->flags & OMNIBIT) == 0) /* Omnipotent parameter? */
+ /* If its not an omnipotent parameter, resolve by presence */
+ resolve(tlst);
+ if (plural) {
+ if ((elms->flags & MULTIPLEBIT) == 0) /* Allowed multiple? */
+ error(M_MULTIPLE);
+ else {
+ /*
+ Mark this as the multiple position in which to insert
+ actual parameter values later
+ */
+ params[paramidx++].code = 0;
+ lstcpy(mlst, tlst);
+ anyPlural = TRUE;
+ }
+ } else
+ params[paramidx++] = tlst[0];
+ params[paramidx].code = EOF;
+ }
+ elms = (ElmElem *) addrTo(elms->next);
+ }
+ }
+
+ /* Now perform class checks */
+ if (elms->next == 0) /* No verb code, verb not declared! */
+ error(M_CANT0);
+
+ for (p = 0; params[p].code != EOF; p++) /* Mark all parameters unchecked */
+ checked[p] = FALSE;
+ for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
+ if (params[cla->code - 1].code == 0) {
+ /* This was a multiple parameter, so check all and remove failing */
+ for (i = 0; mlst[i].code != EOF; i++) {
+ params[cla->code - 1] = mlst[i];
+ if (!claCheck(cla)) {
+ /* Multiple could be both an explicit list of params and an ALL */
+ if (allLength == 0) {
+ char marker[80];
+ /*
+ It wasn't ALL, we need to say something about it, so
+ prepare a printout with $1/2/3
+ */
+ sprintf(marker, "($%ld)", (unsigned long) cla->code);
+ output(marker);
+ interpret(cla->stms);
+ para();
+ }
+ mlst[i].code = 0; /* In any case remove it from the list */
+ }
+ }
+ params[cla->code - 1].code = 0;
+ } else {
+ if (!claCheck(cla)) {
+ interpret(cla->stms);
+ error(MSGMAX); /* Return to player without saying anything */
+ }
+ }
+ checked[cla->code - 1] = TRUE; /* Remember that it's already checked */
+ }
+ /* Now check the rest of the parameters, must be objects */
+ for (p = 0; params[p].code != EOF; p++)
+ if (!checked[p]) {
+ if (params[p].code == 0) {
+ /* This was a multiple parameter, check all and remove failing */
+ for (i = 0; mlst[i].code != EOF; i++)
+ if (mlst[i].code != 0) /* Skip any empty slots */
+ if (!isObj(mlst[i].code))
+ mlst[i].code = 0;
+ } else if (!isObj(params[p].code))
+ error(M_CANT0);
+ }
+
+ /* Set verb code */
+ cur.vrb = ((Aword *) cla)[1]; /* Take first word after end of table! */
+
+ /* Finally, if ALL was used, try to find out what was applicable */
+ if (allLength > 0) {
+ for (p = 0; params[p].code != 0; p++); /* Find multiple marker */
+ for (i = 0; i < allLength; i++) {
+ if (mlst[i].code != 0) { /* Already empty? */
+ params[p] = mlst[i];
+ if (!possible())
+ mlst[i].code = 0; /* Remove this from list */
+ }
+ }
+ params[p].code = 0; /* Restore multiple marker */
+ compact(mlst);
+ if (lstlen(mlst) == 0) {
+ params[0].code = EOF;
+ error(M_WHAT_ALL);
+ }
+ } else if (anyPlural) {
+ compact(mlst);
+ if (lstlen(mlst) == 0)
+ /* If there where multiple parameters but non left, exit without a */
+ /* word, assuming we have already said enough */
+ error(MSGMAX);
+ }
+ plural = anyPlural; /* Remember that we found plural objects */
}
static void match(ParamElem *mlst /* OUT - List of params allowed by multiple */) {
- tryMatch(mlst); /* ... to understand what he said */
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
- error(M_WHAT);
- if (wrds[wrdidx] != EOF) /* More on this line? */
- wrdidx++; /* If so skip the AND */
+ tryMatch(mlst); /* ... to understand what he said */
+ if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ error(M_WHAT);
+ if (wrds[wrdidx] != EOF) /* More on this line? */
+ wrdidx++; /* If so skip the AND */
}
void parse() {
- if (mlst == NULL) { /* Allocate large enough paramlists */
- mlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
- mlst[0].code = EOF;
- pmlst = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
- params = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
- params[0].code = EOF;
- pparams = (ParamElem *) allocate(sizeof(ParamElem)*(MAXENTITY+1));
- }
-
- if (wrds[wrdidx] == EOF) {
- wrdidx = 0;
- scan();
- if (g_vm->shouldQuit())
- return;
- } else if (anyOutput)
- para();
-
- allLength = 0;
- paramidx = 0;
- lstcpy(pparams, params);
- params[0].code = EOF;
- lstcpy(pmlst, mlst);
- mlst[0].code = EOF;
- if (isVerb(wrds[wrdidx])) {
- vrbwrd = wrds[wrdidx];
- vrbcode = dict[vrbwrd].code;
- wrdidx++;
- match(mlst);
- action(mlst); /* mlst contains possible multiple params */
- } else {
- params[0].code = EOF;
- pmlst[0].code = EOF;
- nonverb();
- }
+ if (mlst == NULL) { /* Allocate large enough paramlists */
+ mlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
+ mlst[0].code = EOF;
+ pmlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
+ params = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
+ params[0].code = EOF;
+ pparams = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
+ }
+
+ if (wrds[wrdidx] == EOF) {
+ wrdidx = 0;
+ scan();
+ if (g_vm->shouldQuit())
+ return;
+ } else if (anyOutput)
+ para();
+
+ allLength = 0;
+ paramidx = 0;
+ lstcpy(pparams, params);
+ params[0].code = EOF;
+ lstcpy(pmlst, mlst);
+ mlst[0].code = EOF;
+ if (isVerb(wrds[wrdidx])) {
+ vrbwrd = wrds[wrdidx];
+ vrbcode = dict[vrbwrd].code;
+ wrdidx++;
+ match(mlst);
+ action(mlst); /* mlst contains possible multiple params */
+ } else {
+ params[0].code = EOF;
+ pmlst[0].code = EOF;
+ nonverb();
+ }
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
index e2c558c..1e51301 100644
--- a/engines/glk/alan2/parse.h
+++ b/engines/glk/alan2/parse.h
@@ -28,10 +28,10 @@
namespace Glk {
namespace Alan2 {
-extern int wrds[]; /* List of Parsed Word */
-extern int wrdidx; /* and an index into it */
+extern int wrds[]; /* List of Parsed Word */
+extern int wrdidx; /* and an index into it */
-extern ParamElem *params; /* List of parameters */
+extern ParamElem *params; /* List of parameters */
extern Boolean plural;
extern LitElem litValues[];
diff --git a/engines/glk/alan2/readline.cpp b/engines/glk/alan2/readline.cpp
index 7569721..cd05435 100644
--- a/engines/glk/alan2/readline.cpp
+++ b/engines/glk/alan2/readline.cpp
@@ -38,25 +38,23 @@ namespace Alan2 {
*/
/* 4f - length of user buffer should be used */
-Boolean readline(char usrbuf[])
-{
- event_t event;
- g_vm->glk_request_line_event(glkMainWin, usrbuf, 255, 0);
- /* FIXME: buffer size should be infallible: all existing calls use 256 or
- 80 character buffers, except parse which uses LISTLEN (currently 100)
- */
- do
- {
- g_vm->glk_select(&event);
- if (evtype_Arrange == event.type)
- statusline();
- if (g_vm->shouldQuit())
- return false;
-
- } while (event.type != evtype_LineInput);
-
- usrbuf[event.val1] = 0;
- return TRUE;
+Boolean readline(char usrbuf[]) {
+ event_t event;
+ g_vm->glk_request_line_event(glkMainWin, usrbuf, 255, 0);
+ /* FIXME: buffer size should be infallible: all existing calls use 256 or
+ 80 character buffers, except parse which uses LISTLEN (currently 100)
+ */
+ do {
+ g_vm->glk_select(&event);
+ if (evtype_Arrange == event.type)
+ statusline();
+ if (g_vm->shouldQuit())
+ return false;
+
+ } while (event.type != evtype_LineInput);
+
+ usrbuf[event.val1] = 0;
+ return TRUE;
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/reverse.cpp b/engines/glk/alan2/reverse.cpp
index 943411e..a79ae02 100644
--- a/engines/glk/alan2/reverse.cpp
+++ b/engines/glk/alan2/reverse.cpp
@@ -35,307 +35,307 @@ namespace Alan2 {
*/
Aword reversed(Aword w /* IN - The ACODE word to swap bytes of */) {
- Aword s; /* The swapped ACODE word */
- char *wp, *sp;
- int i;
-
- wp = (char *) &w;
- sp = (char *) &s;
+ Aword s; /* The swapped ACODE word */
+ char *wp, *sp;
+ int i;
- for (i = 0; i < sizeof(Aword); i++)
- sp[sizeof(Aword)-1 - i] = wp[i];
+ wp = (char *) &w;
+ sp = (char *) &s;
- return s;
+ for (i = 0; i < sizeof(Aword); i++)
+ sp[sizeof(Aword) - 1 - i] = wp[i];
+
+ return s;
}
void reverse(Aword *w /* IN - The ACODE word to reverse bytes in */) {
- *w = reversed(*w);
+ *w = reversed(*w);
}
static void reverseTable(Aword adr, int len) {
- Aword *e = &memory[adr];
- int i;
-
- if (adr != 0)
- while (!endOfTable(e)) {
- for (i = 0; i < len/(int)sizeof(Aword); i++) {
- reverse(e);
- e++;
- }
- }
+ Aword *e = &memory[adr];
+ int i;
+
+ if (adr != 0)
+ while (!endOfTable(e)) {
+ for (i = 0; i < len / (int)sizeof(Aword); i++) {
+ reverse(e);
+ e++;
+ }
+ }
}
static void reverseStms(Aword adr) {
- Aword *e = &memory[adr];
-
- if (adr != 0)
- while (TRUE) {
- reverse(e);
- if (*e == ((Aword)C_STMOP<<28|(Aword)I_RETURN)) break;
- e++;
- }
+ Aword *e = &memory[adr];
+
+ if (adr != 0)
+ while (TRUE) {
+ reverse(e);
+ if (*e == ((Aword)C_STMOP << 28 | (Aword)I_RETURN)) break;
+ e++;
+ }
}
static void reverseMsgs(Aword adr) {
- MsgElem *e = (MsgElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(MsgElem));
- while (!endOfTable(e)) {
- reverseStms(e->stms);
- e++;
- }
- }
-}
+ MsgElem *e = (MsgElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(MsgElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
static void reverseWrds(Aword adr) {
- WrdElem *e = (WrdElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(WrdElem));
- while (!endOfTable(e)) {
- if ((e->_class & (1L<<WRD_SYN)) == 0) { /* Do not do this for synonyms */
- reverseTable(e->adjrefs, sizeof(Aword));
- reverseTable(e->nounrefs, sizeof(Aword));
- }
- e++;
- }
- }
-}
+ WrdElem *e = (WrdElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(WrdElem));
+ while (!endOfTable(e)) {
+ if ((e->_class & (1L << WRD_SYN)) == 0) { /* Do not do this for synonyms */
+ reverseTable(e->adjrefs, sizeof(Aword));
+ reverseTable(e->nounrefs, sizeof(Aword));
+ }
+ e++;
+ }
+ }
+}
static void reverseChks(Aword adr) {
- ChkElem *e = (ChkElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ChkElem));
- while (!endOfTable(e)) {
- reverseStms(e->exp);
- reverseStms(e->stms);
- e++;
- }
- }
-}
+ ChkElem *e = (ChkElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ChkElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
static void reverseAlts(Aword adr) {
- AltElem *e = (AltElem *)&memory[adr];
-
- if (adr != 0 && !endOfTable(e) && !e->done) {
- reverseTable(adr, sizeof(AltElem));
- e->done = TRUE;
- while (!endOfTable(e)) {
- reverseChks(e->checks);
- reverseStms(e->action);
- e++;
- }
- }
-}
+ AltElem *e = (AltElem *)&memory[adr];
+
+ if (adr != 0 && !endOfTable(e) && !e->done) {
+ reverseTable(adr, sizeof(AltElem));
+ e->done = TRUE;
+ while (!endOfTable(e)) {
+ reverseChks(e->checks);
+ reverseStms(e->action);
+ e++;
+ }
+ }
+}
static void reverseVrbs(Aword adr) {
- VrbElem *e = (VrbElem *)&memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(VrbElem));
- while (!endOfTable(e)) {
- reverseAlts(e->alts);
- e++;
- }
- }
-}
+ VrbElem *e = (VrbElem *)&memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(VrbElem));
+ while (!endOfTable(e)) {
+ reverseAlts(e->alts);
+ e++;
+ }
+ }
+}
static void reverseSteps(Aword adr) {
- StepElem *e = (StepElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(StepElem));
- while (!endOfTable(e)) {
- reverseStms(e->exp);
- reverseStms(e->stm);
- e++;
- }
- }
-}
+ StepElem *e = (StepElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(StepElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stm);
+ e++;
+ }
+ }
+}
static void reverseScrs(Aword adr) {
- ScrElem *e = (ScrElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ScrElem));
- while (!endOfTable(e)) {
- reverseStms(e->dscr);
- reverseSteps(e->steps);
- e++;
- }
- }
-}
+ ScrElem *e = (ScrElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ScrElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->dscr);
+ reverseSteps(e->steps);
+ e++;
+ }
+ }
+}
static void reverseActs(Aword adr) {
- ActElem *e = (ActElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ActElem));
- while (!endOfTable(e)) {
- reverseStms(e->nam);
- reverseTable(e->atrs, sizeof(AtrElem));
- reverseScrs(e->scradr);
- reverseVrbs(e->vrbs);
- reverseStms(e->dscr);
- e++;
- }
- }
-}
+ ActElem *e = (ActElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ActElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->nam);
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseScrs(e->scradr);
+ reverseVrbs(e->vrbs);
+ reverseStms(e->dscr);
+ e++;
+ }
+ }
+}
static void reverseObjs(Aword adr, Boolean v2_5) {
- ObjElem *e = (ObjElem *) &memory[adr];
- ObjElem25 *e25 = (ObjElem25 *) &memory[adr];
-
- if (v2_5) {
- if (adr != 0 && !endOfTable(e25)) {
- reverseTable(adr, sizeof(ObjElem25));
- while (!endOfTable(e25)) {
- reverseTable(e25->atrs, sizeof(AtrElem));
- reverseVrbs(e25->vrbs);
- reverseStms(e25->dscr1);
- reverseStms(e25->dscr2);
- e25++;
- }
- }
- } else {
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ObjElem));
- while (!endOfTable(e)) {
- reverseTable(e->atrs, sizeof(AtrElem));
- reverseVrbs(e->vrbs);
- reverseStms(e->art);
- reverseStms(e->dscr1);
- reverseStms(e->dscr2);
- e++;
- }
- }
- }
+ ObjElem *e = (ObjElem *) &memory[adr];
+ ObjElem25 *e25 = (ObjElem25 *) &memory[adr];
+
+ if (v2_5) {
+ if (adr != 0 && !endOfTable(e25)) {
+ reverseTable(adr, sizeof(ObjElem25));
+ while (!endOfTable(e25)) {
+ reverseTable(e25->atrs, sizeof(AtrElem));
+ reverseVrbs(e25->vrbs);
+ reverseStms(e25->dscr1);
+ reverseStms(e25->dscr2);
+ e25++;
+ }
+ }
+ } else {
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ObjElem));
+ while (!endOfTable(e)) {
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseVrbs(e->vrbs);
+ reverseStms(e->art);
+ reverseStms(e->dscr1);
+ reverseStms(e->dscr2);
+ e++;
+ }
+ }
+ }
}
static void reverseExts(Aword adr) {
- ExtElem *e = (ExtElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ExtElem));
- while (!endOfTable(e)) {
- if (!e->done) {
- reverseChks(e->checks);
- reverseStms(e->action);
- }
- e++;
- }
- }
-}
+ ExtElem *e = (ExtElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ExtElem));
+ while (!endOfTable(e)) {
+ if (!e->done) {
+ reverseChks(e->checks);
+ reverseStms(e->action);
+ }
+ e++;
+ }
+ }
+}
static void reverseLocs(Aword adr) {
- LocElem *e = (LocElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(LocElem));
- while (!endOfTable(e)) {
- reverseStms(e->nams);
- reverseStms(e->dscr);
- reverseStms(e->does);
- reverseTable(e->atrs, sizeof(AtrElem));
- reverseExts(e->exts);
- reverseVrbs(e->vrbs);
- e++;
- }
- }
-}
+ LocElem *e = (LocElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(LocElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->nams);
+ reverseStms(e->dscr);
+ reverseStms(e->does);
+ reverseTable(e->atrs, sizeof(AtrElem));
+ reverseExts(e->exts);
+ reverseVrbs(e->vrbs);
+ e++;
+ }
+ }
+}
static void reverseClas(Aword adr) {
- ClaElem *e = (ClaElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ClaElem));
- while (!endOfTable(e)) {
- reverseStms(e->stms);
- e++;
- }
- }
- if (adr)
- reverse(&((Aword *)e)[1]); /* The verb code is stored after the table */
-}
+ ClaElem *e = (ClaElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ClaElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+ if (adr)
+ reverse(&((Aword *)e)[1]); /* The verb code is stored after the table */
+}
static void reverseElms(Aword adr) {
- ElmElem *e = (ElmElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(ElmElem));
- while (!endOfTable(e)) {
- if (e->code == EOS) reverseClas(e->next);
- else reverseElms(e->next);
- e++;
- }
- }
-}
+ ElmElem *e = (ElmElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(ElmElem));
+ while (!endOfTable(e)) {
+ if (e->code == EOS) reverseClas(e->next);
+ else reverseElms(e->next);
+ e++;
+ }
+ }
+}
static void reverseStxs(Aword adr) {
- StxElem *e = (StxElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(StxElem));
- while (!endOfTable(e)) {
- reverseElms(e->elms);
- e++;
- }
- }
-}
+ StxElem *e = (StxElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(StxElem));
+ while (!endOfTable(e)) {
+ reverseElms(e->elms);
+ e++;
+ }
+ }
+}
static void reverseEvts(Aword adr) {
- EvtElem *e = (EvtElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(EvtElem));
- while (!endOfTable(e)) {
- reverseStms(e->code);
- e++;
- }
- }
-}
+ EvtElem *e = (EvtElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(EvtElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->code);
+ e++;
+ }
+ }
+}
static void reverseLims(Aword adr) {
- LimElem *e = (LimElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(LimElem));
- while (!endOfTable(e)) {
- reverseStms(e->stms);
- e++;
- }
- }
-}
+ LimElem *e = (LimElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(LimElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
static void reverseCnts(Aword adr) {
- CntElem *e = (CntElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(CntElem));
- while (!endOfTable(e)) {
- reverseLims(e->lims);
- reverseStms(e->header);
- reverseStms(e->empty);
- reverseStms(e->nam);
- e++;
- }
- }
-}
+ CntElem *e = (CntElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(CntElem));
+ while (!endOfTable(e)) {
+ reverseLims(e->lims);
+ reverseStms(e->header);
+ reverseStms(e->empty);
+ reverseStms(e->nam);
+ e++;
+ }
+ }
+}
static void reverseRuls(Aword adr) {
- RulElem *e = (RulElem *) &memory[adr];
-
- if (adr != 0 && !endOfTable(e)) {
- reverseTable(adr, sizeof(RulElem));
- while (!endOfTable(e)) {
- reverseStms(e->exp);
- reverseStms(e->stms);
- e++;
- }
- }
-}
+ RulElem *e = (RulElem *) &memory[adr];
+
+ if (adr != 0 && !endOfTable(e)) {
+ reverseTable(adr, sizeof(RulElem));
+ while (!endOfTable(e)) {
+ reverseStms(e->exp);
+ reverseStms(e->stms);
+ e++;
+ }
+ }
+}
/*----------------------------------------------------------------------
@@ -346,11 +346,11 @@ static void reverseRuls(Aword adr) {
*/
void reverseHdr(AcdHdr *hdr) {
- int i;
+ int i;
- /* Reverse all words in the header except the first (version marking) */
- for (i = 1; i < sizeof(AcdHdr)/sizeof(Aword); i++)
- reverse(&((Aword *)hdr)[i]);
+ /* Reverse all words in the header except the first (version marking) */
+ for (i = 1; i < sizeof(AcdHdr) / sizeof(Aword); i++)
+ reverse(&((Aword *)hdr)[i]);
}
/*----------------------------------------------------------------------
@@ -363,25 +363,25 @@ void reverseHdr(AcdHdr *hdr) {
*/
void reverseACD(Boolean v2_5) {
- reverseHdr(header);
- reverseWrds(header->dict);
- reverseTable(header->oatrs, sizeof(AtrElem));
- reverseTable(header->latrs, sizeof(AtrElem));
- reverseTable(header->aatrs, sizeof(AtrElem));
- reverseActs(header->acts);
- reverseObjs(header->objs, v2_5);
- reverseLocs(header->locs);
- reverseStxs(header->stxs);
- reverseVrbs(header->vrbs);
- reverseEvts(header->evts);
- reverseCnts(header->cnts);
- reverseRuls(header->ruls);
- reverseTable(header->init, sizeof(IniElem));
- reverseStms(header->start);
- reverseMsgs(header->msgs);
-
- reverseTable(header->scores, sizeof(Aword));
- reverseTable(header->freq, sizeof(Aword));
+ reverseHdr(header);
+ reverseWrds(header->dict);
+ reverseTable(header->oatrs, sizeof(AtrElem));
+ reverseTable(header->latrs, sizeof(AtrElem));
+ reverseTable(header->aatrs, sizeof(AtrElem));
+ reverseActs(header->acts);
+ reverseObjs(header->objs, v2_5);
+ reverseLocs(header->locs);
+ reverseStxs(header->stxs);
+ reverseVrbs(header->vrbs);
+ reverseEvts(header->evts);
+ reverseCnts(header->cnts);
+ reverseRuls(header->ruls);
+ reverseTable(header->init, sizeof(IniElem));
+ reverseStms(header->start);
+ reverseMsgs(header->msgs);
+
+ reverseTable(header->scores, sizeof(Aword));
+ reverseTable(header->freq, sizeof(Aword));
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
index 323f6e7..516b0d2 100644
--- a/engines/glk/alan2/rules.cpp
+++ b/engines/glk/alan2/rules.cpp
@@ -33,41 +33,41 @@ namespace Glk {
namespace Alan2 {
void rules() {
- Boolean change = TRUE;
- int i;
-
- for (i = 1; !endOfTable(&ruls[i-1]); i++)
- ruls[i-1].run = FALSE;
-
- while (change) {
- change = FALSE;
- for (i = 1; !endOfTable(&ruls[i-1]); i++)
- if (!ruls[i-1].run) {
- if (trcflg) {
- printf("\n<RULE %d (at ", i);
- debugsay(cur.loc);
- if (!stpflg)
- printf("), Evaluating");
- else
- printf("), Evaluating:>\n");
+ Boolean change = TRUE;
+ int i;
+
+ for (i = 1; !endOfTable(&ruls[i - 1]); i++)
+ ruls[i - 1].run = FALSE;
+
+ while (change) {
+ change = FALSE;
+ for (i = 1; !endOfTable(&ruls[i - 1]); i++)
+ if (!ruls[i - 1].run) {
+ if (trcflg) {
+ printf("\n<RULE %d (at ", i);
+ debugsay(cur.loc);
+ if (!stpflg)
+ printf("), Evaluating");
+ else
+ printf("), Evaluating:>\n");
+ }
+ interpret(ruls[i - 1].exp);
+ if (pop()) {
+ change = TRUE;
+ ruls[i - 1].run = TRUE;
+ if (trcflg)
+ if (!stpflg)
+ printf(", Executing:>\n");
+ else {
+ printf("\nRULE %d (at ", i);
+ debugsay(cur.loc);
+ printf("), Executing:>\n");
+ }
+ interpret(ruls[i - 1].stms);
+ } else if (trcflg && !stpflg)
+ printf(":>\n");
+ }
}
- interpret(ruls[i-1].exp);
- if (pop()) {
- change = TRUE;
- ruls[i-1].run = TRUE;
- if (trcflg)
- if (!stpflg)
- printf(", Executing:>\n");
- else {
- printf("\nRULE %d (at ", i);
- debugsay(cur.loc);
- printf("), Executing:>\n");
- }
- interpret(ruls[i-1].stms);
- } else if (trcflg && !stpflg)
- printf(":>\n");
- }
- }
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/stack.cpp b/engines/glk/alan2/stack.cpp
index 98423f0..6695fed 100644
--- a/engines/glk/alan2/stack.cpp
+++ b/engines/glk/alan2/stack.cpp
@@ -37,19 +37,19 @@ static int stackp = 0;
void push(Aptr i) {
- if (stackp == STACKSIZE)
- syserr("Out of stack space.");
- stack[stackp++] = i;
+ if (stackp == STACKSIZE)
+ syserr("Out of stack space.");
+ stack[stackp++] = i;
}
Aptr pop() {
- if (stackp == 0)
- syserr("Stack underflow.");
- return(stack[--stackp]);
+ if (stackp == 0)
+ syserr("Stack underflow.");
+ return (stack[--stackp]);
}
Aptr top() {
- return(stack[stackp-1]);
+ return (stack[stackp - 1]);
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
index 74d4fc9..dc6e0b6 100644
--- a/engines/glk/alan2/sysdep.cpp
+++ b/engines/glk/alan2/sysdep.cpp
@@ -40,183 +40,165 @@ void fprintf(Common::WriteStream *ws, const char *fmt, ...) {
/* Note to Glk maintainers: 'native' characters are used for output, in this
case, Glk's Latin-1. ISO characters are Alan's internal representation,
- stored in the .DAT file, and must be converted to native before printing.
- Glk could just use the ISO routines directly, but its safer to maintain
+ stored in the .DAT file, and must be converted to native before printing.
+ Glk could just use the ISO routines directly, but its safer to maintain
its own tables to guard against future changes in either Alan or Glk (ie. a
move to Unicode).
*/
-
-static char spcChrs[] =
-{
- '\x0A', /* linefeed */
- '\x20', /* space */
- '\xA0', /* non-breaking space */
- '\x00'
+
+static char spcChrs[] = {
+ '\x0A', /* linefeed */
+ '\x20', /* space */
+ '\xA0', /* non-breaking space */
+ '\x00'
};
-static char lowChrs[] =
-{
- '\x61', /* a */ '\x62', /* b */ '\x63', /* c */ '\x64', /* d */
- '\x65', /* e */ '\x66', /* f */ '\x67', /* g */ '\x68', /* h */
- '\x69', /* i */ '\x6A', /* j */ '\x6B', /* k */ '\x6C', /* l */
- '\x6D', /* m */ '\x6E', /* n */ '\x6F', /* o */ '\x70', /* p */
- '\x71', /* q */ '\x72', /* r */ '\x73', /* s */ '\x74', /* t */
- '\x75', /* u */ '\x76', /* v */ '\x77', /* w */ '\x78', /* x */
- '\x79', /* y */ '\x7A', /* z */ '\xDF', /* ss <small sharp s> */
- '\xE0', /* a grave */ '\xE1', /* a acute */
- '\xE2', /* a circumflex */ '\xE3', /* a tilde */
- '\xE4', /* a diaeresis */ '\xE5', /* a ring */
- '\xE6', /* ae */ '\xE7', /* c cedilla */
- '\xE8', /* e grave */ '\xE9', /* e acute */
- '\xEA', /* e circumflex */ '\xEB', /* e diaeresis */
- '\xEC', /* i grave */ '\xED', /* i acute */
- '\xEE', /* i circumflex */ '\xEF', /* i diaeresis */
- '\xF0', /* <small eth> */ '\xF1', /* n tilde */
- '\xF2', /* o grave */ '\xF3', /* o acute */
- '\xF4', /* o circumflex */ '\xF5', /* o tilde */
- '\xF6', /* o diaeresis */ '\xF8', /* o slash */
- '\xF9', /* u grave */ '\xFA', /* u acute */
- '\xFB', /* u circumflex */ '\xFC', /* u diaeresis */
- '\xFD', /* y acute */ '\xFE', /* <small thorn> */
- '\xFF', /* y diaeresis */ '\x00'
+static char lowChrs[] = {
+ '\x61', /* a */ '\x62', /* b */ '\x63', /* c */ '\x64', /* d */
+ '\x65', /* e */ '\x66', /* f */ '\x67', /* g */ '\x68', /* h */
+ '\x69', /* i */ '\x6A', /* j */ '\x6B', /* k */ '\x6C', /* l */
+ '\x6D', /* m */ '\x6E', /* n */ '\x6F', /* o */ '\x70', /* p */
+ '\x71', /* q */ '\x72', /* r */ '\x73', /* s */ '\x74', /* t */
+ '\x75', /* u */ '\x76', /* v */ '\x77', /* w */ '\x78', /* x */
+ '\x79', /* y */ '\x7A', /* z */ '\xDF', /* ss <small sharp s> */
+ '\xE0', /* a grave */ '\xE1', /* a acute */
+ '\xE2', /* a circumflex */ '\xE3', /* a tilde */
+ '\xE4', /* a diaeresis */ '\xE5', /* a ring */
+ '\xE6', /* ae */ '\xE7', /* c cedilla */
+ '\xE8', /* e grave */ '\xE9', /* e acute */
+ '\xEA', /* e circumflex */ '\xEB', /* e diaeresis */
+ '\xEC', /* i grave */ '\xED', /* i acute */
+ '\xEE', /* i circumflex */ '\xEF', /* i diaeresis */
+ '\xF0', /* <small eth> */ '\xF1', /* n tilde */
+ '\xF2', /* o grave */ '\xF3', /* o acute */
+ '\xF4', /* o circumflex */ '\xF5', /* o tilde */
+ '\xF6', /* o diaeresis */ '\xF8', /* o slash */
+ '\xF9', /* u grave */ '\xFA', /* u acute */
+ '\xFB', /* u circumflex */ '\xFC', /* u diaeresis */
+ '\xFD', /* y acute */ '\xFE', /* <small thorn> */
+ '\xFF', /* y diaeresis */ '\x00'
};
/* FIXME: ss <small sharp s> and y diaeresis have no UC analogues
- Are they really considered LC?
+ Are they really considered LC?
*/
-static char uppChrs[] =
-{
- '\x41', /* A */ '\x42', /* B */ '\x43', /* C */ '\x44', /* D */
- '\x45', /* E */ '\x46', /* F */ '\x47', /* G */ '\x48', /* H */
- '\x49', /* I */ '\x4A', /* J */ '\x4B', /* K */ '\x4C', /* L */
- '\x4D', /* M */ '\x4E', /* N */ '\x4F', /* O */ '\x50', /* P */
- '\x51', /* Q */ '\x52', /* R */ '\x53', /* S */ '\x54', /* T */
- '\x55', /* U */ '\x56', /* V */ '\x57', /* W */ '\x58', /* X */
- '\x59', /* Y */ '\x5A', /* Z */
- '\xC0', /* A grave */ '\xC1', /* A acute */
- '\xC2', /* A circumflex */ '\xC3', /* A tilde */
- '\xC4', /* A diaeresis */ '\xC5', /* A ring */
- '\xC6', /* AE */ '\xC7', /* C cedilla */
- '\xC8', /* E grave */ '\xC9', /* E acute */
- '\xCA', /* E circumflex */ '\xCB', /* E diaeresis */
- '\xCC', /* I grave */ '\xCD', /* I acute */
- '\xCE', /* I circumflex */ '\xCF', /* I diaeresis */
- '\xD0', /* <capital eth> */ '\xD1', /* N tilde */
- '\xD2', /* O grave */ '\xD3', /* O acute */
- '\xD4', /* O circumflex */ '\xD5', /* O tilde */
- '\xD6', /* O diaeresis */ '\xD8', /* O slash */
- '\xD9', /* U grave */ '\xDA', /* U acute */
- '\xDB', /* U circumflex */ '\xDC', /* U diaeresis */
- '\xDD', /* Y acute */ '\xDE', /* <capital thorn> */
- '\x00'
+static char uppChrs[] = {
+ '\x41', /* A */ '\x42', /* B */ '\x43', /* C */ '\x44', /* D */
+ '\x45', /* E */ '\x46', /* F */ '\x47', /* G */ '\x48', /* H */
+ '\x49', /* I */ '\x4A', /* J */ '\x4B', /* K */ '\x4C', /* L */
+ '\x4D', /* M */ '\x4E', /* N */ '\x4F', /* O */ '\x50', /* P */
+ '\x51', /* Q */ '\x52', /* R */ '\x53', /* S */ '\x54', /* T */
+ '\x55', /* U */ '\x56', /* V */ '\x57', /* W */ '\x58', /* X */
+ '\x59', /* Y */ '\x5A', /* Z */
+ '\xC0', /* A grave */ '\xC1', /* A acute */
+ '\xC2', /* A circumflex */ '\xC3', /* A tilde */
+ '\xC4', /* A diaeresis */ '\xC5', /* A ring */
+ '\xC6', /* AE */ '\xC7', /* C cedilla */
+ '\xC8', /* E grave */ '\xC9', /* E acute */
+ '\xCA', /* E circumflex */ '\xCB', /* E diaeresis */
+ '\xCC', /* I grave */ '\xCD', /* I acute */
+ '\xCE', /* I circumflex */ '\xCF', /* I diaeresis */
+ '\xD0', /* <capital eth> */ '\xD1', /* N tilde */
+ '\xD2', /* O grave */ '\xD3', /* O acute */
+ '\xD4', /* O circumflex */ '\xD5', /* O tilde */
+ '\xD6', /* O diaeresis */ '\xD8', /* O slash */
+ '\xD9', /* U grave */ '\xDA', /* U acute */
+ '\xDB', /* U circumflex */ '\xDC', /* U diaeresis */
+ '\xDD', /* Y acute */ '\xDE', /* <capital thorn> */
+ '\x00'
};
-int isSpace(int c) /* IN - Native character to test */
-{
- return (c != '\0' && strchr(spcChrs, c) != 0);
+int isSpace(int c) { /* IN - Native character to test */
+ return (c != '\0' && strchr(spcChrs, c) != 0);
}
-int isLower(int c) /* IN - Native character to test */
-{
- return (c != '\0' && strchr(lowChrs, c) != 0);
+int isLower(int c) { /* IN - Native character to test */
+ return (c != '\0' && strchr(lowChrs, c) != 0);
}
-int isUpper(int c) /* IN - Native character to test */
-{
- return (c != '\0' && strchr(uppChrs, c) != 0);
+int isUpper(int c) { /* IN - Native character to test */
+ return (c != '\0' && strchr(uppChrs, c) != 0);
}
-int isLetter(int c) /* IN - Native character to test */
-{
- return(c != '\0' && (isLower(c)? !0: isUpper(c)));
+int isLetter(int c) { /* IN - Native character to test */
+ return (c != '\0' && (isLower(c) ? !0 : isUpper(c)));
}
-int toLower(int c) /* IN - Native character to convert */
-{
- return g_vm->glk_char_to_lower(c);
+int toLower(int c) { /* IN - Native character to convert */
+ return g_vm->glk_char_to_lower(c);
}
-int toUpper(int c) /* IN - Native character to convert */
-{
- return g_vm->glk_char_to_upper(c);
+int toUpper(int c) { /* IN - Native character to convert */
+ return g_vm->glk_char_to_upper(c);
}
-char *strlow(char str[]) /* INOUT - Native string to convert */
-{
- char *s;
+char *strlow(char str[]) { /* INOUT - Native string to convert */
+ char *s;
- for (s = str; *s; s++)
- *s = toLower(*s);
- return(str);
+ for (s = str; *s; s++)
+ *s = toLower(*s);
+ return (str);
}
-char *strupp(char str[]) /* INOUT - Native string to convert */
-{
- char *s;
+char *strupp(char str[]) { /* INOUT - Native string to convert */
+ char *s;
- for (s = str; *s; s++)
- *s = toUpper(*s);
- return(str);
+ for (s = str; *s; s++)
+ *s = toUpper(*s);
+ return (str);
}
/* The following work on ISO characters */
-int isLowerCase(int c) /* IN - ISO character to test */
-{
- static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
- return (c != '\0' && strchr(lowChrs, c) != 0);
+int isLowerCase(int c) { /* IN - ISO character to test */
+ static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
+ return (c != '\0' && strchr(lowChrs, c) != 0);
}
-int isUpperCase(int c) /* IN - ISO character to test */
-{
- static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
- return (c != '\0' && strchr(uppChrs, c) != 0);
+int isUpperCase(int c) { /* IN - ISO character to test */
+ static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
+ return (c != '\0' && strchr(uppChrs, c) != 0);
}
-int isISOLetter(int c) /* IN - ISO character to test */
-{
- return (isLowerCase(c) || isUpperCase(c));
+int isISOLetter(int c) { /* IN - ISO character to test */
+ return (isLowerCase(c) || isUpperCase(c));
}
-char toLowerCase(int c) /* IN - ISO character to convert */
-{
- return (isUpperCase(c)? c + ('a' - 'A'): c);
+char toLowerCase(int c) { /* IN - ISO character to convert */
+ return (isUpperCase(c) ? c + ('a' - 'A') : c);
}
-char toUpperCase(int c) /* IN - ISO character to convert */
-{
- return (isLowerCase(c)? c - ('a' - 'A'): c);
+char toUpperCase(int c) { /* IN - ISO character to convert */
+ return (isLowerCase(c) ? c - ('a' - 'A') : c);
}
-char *stringLower(char str[]) /* INOUT - ISO string to convert */
-{
- char *s;
+char *stringLower(char str[]) { /* INOUT - ISO string to convert */
+ char *s;
- for (s = str; *s; s++)
- *s = toLowerCase(*s);
- return(str);
+ for (s = str; *s; s++)
+ *s = toLowerCase(*s);
+ return (str);
}
-char *stringUpper(char str[]) /* INOUT - ISO string to convert */
-{
- char *s;
+char *stringUpper(char str[]) { /* INOUT - ISO string to convert */
+ char *s;
- for (s = str; *s; s++)
- *s = toUpperCase(*s);
- return(str);
+ for (s = str; *s; s++)
+ *s = toUpperCase(*s);
+ return (str);
}
@@ -229,65 +211,66 @@ char *stringUpper(char str[]) /* INOUT - ISO string to convert */
*/
void toIso(char copy[], /* OUT - Mapped string */
- char original[], /* IN - string to convert */
- int charset) /* IN - the current character set */
-{
-static unsigned char macMap[256]
-= {
-0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0A,0x0E,0x0F,
-0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
-0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
-0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
-0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
-0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
-0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
-0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
-0xC4,0xC5,0xC7,0xC9,0xD1,0xD6,0xDC,0xE1,0xE0,0xE2,0xE4,0xE3,0xE5,0xE7,0xE9,0xE8,
-0xEA,0xEB,0xED,0xEC,0xEE,0xEF,0xF1,0xF3,0xF2,0xF4,0xF6,0xF5,0xFA,0xF9,0xFB,0xFC,
-0xB9,0xB0,0xA2,0xA3,0xA7,0xB7,0xB6,0xDF,0xAE,0xA9,0xB2,0xB4,0xA8,0xD7,0xC6,0xD8,
-0xA4,0xB1,0xCD,0xCC,0xA5,0xB5,0xF0,0xCA,0xDE,0xFE,0xA6,0xAA,0xBA,0xD4,0xE6,0xF8,
-0xBF,0xA1,0xAC,0xCE,0xCF,0xC8,0xD0,0xAB,0xBB,0xCB,0xA0,0xC0,0xC3,0xD5,0xDD,0xFD,
-0xAD,0xAF,0xDA,0xD9,0xB8,0xB3,0xF7,0xC2,0xFF,0xBC,0xBD,0xBE,0xC1,0xD2,0xD3,0xDB,
-0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
-0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F};
-
-static unsigned char dosMap[256]
-= {
-0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0A,0x0E,0x0F,
-0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
-0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
-0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
-0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
-0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
-0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
-0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
-0xC7,0xFC,0xE9,0xE2,0xE4,0xE0,0xE5,0xE7,0xEA,0xEB,0xE8,0xEF,0xEE,0xEC,0xC4,0xC5,
-0xC9,0xE6,0xC6,0xF4,0xF6,0xF2,0xFB,0xF9,0xFF,0xD6,0xDC,0xA2,0xA3,0xA5,0xDE,0xA6,
-0xE1,0xED,0xF3,0xFA,0xF1,0xD1,0xAA,0xBA,0xBF,0xC0,0xC1,0xBD,0xBC,0xCF,0xAB,0xBB,
-0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
-0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
-0xA1,0xA7,0xAD,0xB3,0xB8,0xB9,0xC3,0xCE,0xD2,0xD3,0xDB,0xDD,0xE3,0xF5,0xF8,0xFD,
-0xA9,0xDF,0xC8,0xB6,0xCA,0xA4,0xB5,0xAE,0xD5,0xD0,0xD4,0xF0,0xD7,0xD8,0xCB,0xC2,
-0xBE,0xB1,0xD9,0xDA,0xCD,0xCC,0xF7,0xA8,0xB0,0xB7,0xAF,0xAC,0xFE,0xB2,0xB4,0xA0};
- unsigned char *o, *c;
-
- switch (charset) {
- case 0: /* ISO */
- if (copy != original)
- (void)strcpy(copy, original);
- break;
- case 1: /* Mac */
- for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
- *c = macMap[*o];
- *c = '\0';
- break;
-
- case 2: /* Dos */
- for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
- *c = dosMap[*o];
- *c = '\0';
- break;
- }
+ char original[], /* IN - string to convert */
+ int charset) { /* IN - the current character set */
+ static unsigned char macMap[256]
+ = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0A, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+ 0xC4, 0xC5, 0xC7, 0xC9, 0xD1, 0xD6, 0xDC, 0xE1, 0xE0, 0xE2, 0xE4, 0xE3, 0xE5, 0xE7, 0xE9, 0xE8,
+ 0xEA, 0xEB, 0xED, 0xEC, 0xEE, 0xEF, 0xF1, 0xF3, 0xF2, 0xF4, 0xF6, 0xF5, 0xFA, 0xF9, 0xFB, 0xFC,
+ 0xB9, 0xB0, 0xA2, 0xA3, 0xA7, 0xB7, 0xB6, 0xDF, 0xAE, 0xA9, 0xB2, 0xB4, 0xA8, 0xD7, 0xC6, 0xD8,
+ 0xA4, 0xB1, 0xCD, 0xCC, 0xA5, 0xB5, 0xF0, 0xCA, 0xDE, 0xFE, 0xA6, 0xAA, 0xBA, 0xD4, 0xE6, 0xF8,
+ 0xBF, 0xA1, 0xAC, 0xCE, 0xCF, 0xC8, 0xD0, 0xAB, 0xBB, 0xCB, 0xA0, 0xC0, 0xC3, 0xD5, 0xDD, 0xFD,
+ 0xAD, 0xAF, 0xDA, 0xD9, 0xB8, 0xB3, 0xF7, 0xC2, 0xFF, 0xBC, 0xBD, 0xBE, 0xC1, 0xD2, 0xD3, 0xDB,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F
+ };
+
+ static unsigned char dosMap[256]
+ = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0A, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+ 0xC7, 0xFC, 0xE9, 0xE2, 0xE4, 0xE0, 0xE5, 0xE7, 0xEA, 0xEB, 0xE8, 0xEF, 0xEE, 0xEC, 0xC4, 0xC5,
+ 0xC9, 0xE6, 0xC6, 0xF4, 0xF6, 0xF2, 0xFB, 0xF9, 0xFF, 0xD6, 0xDC, 0xA2, 0xA3, 0xA5, 0xDE, 0xA6,
+ 0xE1, 0xED, 0xF3, 0xFA, 0xF1, 0xD1, 0xAA, 0xBA, 0xBF, 0xC0, 0xC1, 0xBD, 0xBC, 0xCF, 0xAB, 0xBB,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
+ 0xA1, 0xA7, 0xAD, 0xB3, 0xB8, 0xB9, 0xC3, 0xCE, 0xD2, 0xD3, 0xDB, 0xDD, 0xE3, 0xF5, 0xF8, 0xFD,
+ 0xA9, 0xDF, 0xC8, 0xB6, 0xCA, 0xA4, 0xB5, 0xAE, 0xD5, 0xD0, 0xD4, 0xF0, 0xD7, 0xD8, 0xCB, 0xC2,
+ 0xBE, 0xB1, 0xD9, 0xDA, 0xCD, 0xCC, 0xF7, 0xA8, 0xB0, 0xB7, 0xAF, 0xAC, 0xFE, 0xB2, 0xB4, 0xA0
+ };
+ unsigned char *o, *c;
+
+ switch (charset) {
+ case 0: /* ISO */
+ if (copy != original)
+ (void)strcpy(copy, original);
+ break;
+ case 1: /* Mac */
+ for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
+ *c = macMap[*o];
+ *c = '\0';
+ break;
+
+ case 2: /* Dos */
+ for (o = (unsigned char *)original, c = (unsigned char *)copy; *o; o++, c++)
+ *c = dosMap[*o];
+ *c = '\0';
+ break;
+ }
}
/*----------------------------------------------------------------------
@@ -299,10 +282,9 @@ static unsigned char dosMap[256]
*/
void fromIso(char copy[], /* OUT - Mapped string */
- char original[]) /* IN - string to convert */
-{
- if (copy != original)
- (void)strcpy(copy, original);
+ char original[]) { /* IN - string to convert */
+ if (copy != original)
+ (void)strcpy(copy, original);
}
@@ -314,13 +296,12 @@ void fromIso(char copy[], /* OUT - Mapped string */
the case of the compiler might be other than the native.
*/
-void toNative(char copy[], /* OUT - Mapped string */
- char original[], /* IN - string to convert */
- int charset) /* IN - the current character set */
-{
- toIso(copy, original, charset);
- if (NATIVECHARSET != 0)
- fromIso(copy, copy);
+void toNative(char copy[], /* OUT - Mapped string */
+ char original[], /* IN - string to convert */
+ int charset) { /* IN - the current character set */
+ toIso(copy, original, charset);
+ if (NATIVECHARSET != 0)
+ fromIso(copy, copy);
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/sysdep.h b/engines/glk/alan2/sysdep.h
index 7fce53c..ea513aa 100644
--- a/engines/glk/alan2/sysdep.h
+++ b/engines/glk/alan2/sysdep.h
@@ -81,15 +81,15 @@ extern char *stringUpper(char str[]); /* INOUT - ISO string to convert */
/* ISO string conversion functions */
extern void toIso(char copy[], /* OUT - Mapped string */
- char original[], /* IN - string to convert */
- int charset); /* IN - The current character set */
+ char original[], /* IN - string to convert */
+ int charset); /* IN - The current character set */
extern void fromIso(char copy[], /* OUT - Mapped string */
- char original[]); /* IN - string to convert */
+ char original[]); /* IN - string to convert */
extern void toNative(char copy[], /* OUT - Mapped string */
- char original[], /* IN - string to convert */
- int charset); /* IN - current character set */
+ char original[], /* IN - string to convert */
+ int charset); /* IN - current character set */
} // End of namespace Alan2
} // End of namespace Glk
diff --git a/engines/glk/alan2/term.cpp b/engines/glk/alan2/term.cpp
index c758efe..df3a245 100644
--- a/engines/glk/alan2/term.cpp
+++ b/engines/glk/alan2/term.cpp
@@ -35,8 +35,8 @@ namespace Alan2 {
*/
void getPageSize() {
- paglen = 0;
- pagwidth = 0;
+ paglen = 0;
+ pagwidth = 0;
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/types.cpp b/engines/glk/alan2/types.cpp
index 9ce4a65..d0c3c83 100644
--- a/engines/glk/alan2/types.cpp
+++ b/engines/glk/alan2/types.cpp
@@ -27,8 +27,8 @@ namespace Alan2 {
// This works around gcc errors for passing packed structure fields
static void syncVal(Common::Serializer &s, int *fld) {
- int &v = *fld;
- s.syncAsSint32LE(v);
+ int &v = *fld;
+ s.syncAsSint32LE(v);
}
void CurVars::synchronize(Common::Serializer &s) {
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 34c5dda..7c8a414 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -75,218 +75,218 @@ namespace Alan2 {
/* TYPES */
-typedef int Boolean; /* Boolean values within interpreter */
+typedef int Boolean; /* Boolean values within interpreter */
/* Amachine variables */
struct CurVars {
- int
- vrb,
- obj,
- loc,
- act,
- tick,
- score,
- visits;
+ int
+ vrb,
+ obj,
+ loc,
+ act,
+ tick,
+ score,
+ visits;
/**
* Read or write data to/from a save file
*/
- void synchronize(Common::Serializer &s);
+ void synchronize(Common::Serializer &s);
};
-#include "common/pack-start.h" // START STRUCT PACKING
+#include "common/pack-start.h" // START STRUCT PACKING
/* The various tables */
-struct WrdElem { /* Dictionary */
- Aaddr wrd; /* ACODE address to string */
- Aword _class; /* Word class */
- Aword code;
- Aaddr adjrefs; /* Address to reference list */
- Aaddr nounrefs; /* Address to reference list */
+struct WrdElem { /* Dictionary */
+ Aaddr wrd; /* ACODE address to string */
+ Aword _class; /* Word class */
+ Aword code;
+ Aaddr adjrefs; /* Address to reference list */
+ Aaddr nounrefs; /* Address to reference list */
} PACKED_STRUCT;
-struct ActElem { /* ACTOR TABLE */
- Aword loc; /* Location */
- Abool describe; /* Description flag */
- Aaddr nam; /* Address to name printing code */
- Aaddr atrs; /* Address to attribute list */
- Aword cont; /* Code for the container props if any */
- Aword script; /* Which script is he using */
- Aaddr scradr; /* Address to script table */
- Aword step;
- Aword count;
- Aaddr vrbs;
- Aaddr dscr; /* Address of description code */
+struct ActElem { /* ACTOR TABLE */
+ Aword loc; /* Location */
+ Abool describe; /* Description flag */
+ Aaddr nam; /* Address to name printing code */
+ Aaddr atrs; /* Address to attribute list */
+ Aword cont; /* Code for the container props if any */
+ Aword script; /* Which script is he using */
+ Aaddr scradr; /* Address to script table */
+ Aword step;
+ Aword count;
+ Aaddr vrbs;
+ Aaddr dscr; /* Address of description code */
} PACKED_STRUCT;
-struct ScrElem { /* SCRIPT TABLE */
- Aword code; /* Script number */
- Aaddr dscr; /* Optional description statements */
- Aaddr steps; /* Address to steps */
+struct ScrElem { /* SCRIPT TABLE */
+ Aword code; /* Script number */
+ Aaddr dscr; /* Optional description statements */
+ Aaddr steps; /* Address to steps */
} PACKED_STRUCT;
-struct StepElem { /* STEP TABLE */
- Aword after; /* After how many ticks? */
- Aaddr exp; /* Address to expression saying when */
- Aaddr stm; /* Address to the actual code */
+struct StepElem { /* STEP TABLE */
+ Aword after; /* After how many ticks? */
+ Aaddr exp; /* Address to expression saying when */
+ Aaddr stm; /* Address to the actual code */
} PACKED_STRUCT;
-struct LocElem { /* LOCATION TABLE */
- Aaddr nams; /* Address of name printing code */
- Aaddr dscr; /* Address of description code */
- Aaddr does; /* Address of does code */
- Aword describe; /* Description flag & counter */
- Aaddr atrs; /* Address of attribute list */
- Aaddr exts; /* Address of exit list */
- Aaddr vrbs; /* Address of local verb list */
+struct LocElem { /* LOCATION TABLE */
+ Aaddr nams; /* Address of name printing code */
+ Aaddr dscr; /* Address of description code */
+ Aaddr does; /* Address of does code */
+ Aword describe; /* Description flag & counter */
+ Aaddr atrs; /* Address of attribute list */
+ Aaddr exts; /* Address of exit list */
+ Aaddr vrbs; /* Address of local verb list */
} PACKED_STRUCT;
-struct ExtElem { /* EXIT TABLE structure */
- Abool done; /* Flag for reverse/convert process */
- Aword code; /* Direction code */
- Aaddr checks; /* Address of check table */
- Aaddr action; /* Address of action code */
- Aword next; /* Number of next location */
+struct ExtElem { /* EXIT TABLE structure */
+ Abool done; /* Flag for reverse/convert process */
+ Aword code; /* Direction code */
+ Aaddr checks; /* Address of check table */
+ Aaddr action; /* Address of action code */
+ Aword next; /* Number of next location */
} PACKED_STRUCT;
-struct ChkElem { /* CHECK TABLE */
- Aaddr exp; /* ACODE address to expression code */
- Aaddr stms; /* ACODE address to statement code */
+struct ChkElem { /* CHECK TABLE */
+ Aaddr exp; /* ACODE address to expression code */
+ Aaddr stms; /* ACODE address to statement code */
} PACKED_STRUCT;
-struct VrbElem { /* VERB TABLE */
- Aword code; /* Code for the verb */
- Aaddr alts; /* Address to alternatives */
+struct VrbElem { /* VERB TABLE */
+ Aword code; /* Code for the verb */
+ Aaddr alts; /* Address to alternatives */
} PACKED_STRUCT;
-struct StxElem { /* SYNTAX TABLE */
- Aword code; /* Code for verb word */
- Aaddr elms; /* Address to element tables */
+struct StxElem { /* SYNTAX TABLE */
+ Aword code; /* Code for verb word */
+ Aaddr elms; /* Address to element tables */
} PACKED_STRUCT;
-struct ElmElem26 { /* ELEMENT TABLES */
- Aword code; /* Code for this element, 0 -> parameter */
- Abool multiple; /* May be multiple (if parameter) */
- Aaddr next; /* Address to next element table ... */
- /* ... or class check if EOS */
+struct ElmElem26 { /* ELEMENT TABLES */
+ Aword code; /* Code for this element, 0 -> parameter */
+ Abool multiple; /* May be multiple (if parameter) */
+ Aaddr next; /* Address to next element table ... */
+ /* ... or class check if EOS */
} PACKED_STRUCT;
-struct ElmElem { /* ELEMENT TABLES */
- Aword code; /* Code for this element, 0 -> parameter */
- Aword flags; /* Flags for multiple/omni (if parameter) */
- /* CHANGED: v2.7 from Abool for multiple */
- Aaddr next; /* Address to next element table ... */
- /* ... or class check if EOS */
+struct ElmElem { /* ELEMENT TABLES */
+ Aword code; /* Code for this element, 0 -> parameter */
+ Aword flags; /* Flags for multiple/omni (if parameter) */
+ /* CHANGED: v2.7 from Abool for multiple */
+ Aaddr next; /* Address to next element table ... */
+ /* ... or class check if EOS */
} PACKED_STRUCT;
-struct ClaElem { /* CLASS DEFINITION TABLE */
- Aword code; /* Parameter number */
- Aword classes; /* Parameter classes */
- Aaddr stms; /* Exception statements */
+struct ClaElem { /* CLASS DEFINITION TABLE */
+ Aword code; /* Parameter number */
+ Aword classes; /* Parameter classes */
+ Aaddr stms; /* Exception statements */
} PACKED_STRUCT;
-struct AltElem { /* VERB ALTERNATIVE TABLE */
- Abool done; /* Flag for patching (reverse/convert) process */
- Aword param; /* Parameter number */
- Aword qual; /* Verb execution qualifier */
- Aaddr checks; /* Address of the check table */
- Aaddr action; /* Address of the action code */
+struct AltElem { /* VERB ALTERNATIVE TABLE */
+ Abool done; /* Flag for patching (reverse/convert) process */
+ Aword param; /* Parameter number */
+ Aword qual; /* Verb execution qualifier */
+ Aaddr checks; /* Address of the check table */
+ Aaddr action; /* Address of the action code */
} PACKED_STRUCT;
-struct AtrElem { /* ATTRIBUTE LIST */
- Aword val; /* Its value */
- Aaddr stradr; /* Address to the name */
+struct AtrElem { /* ATTRIBUTE LIST */
+ Aword val; /* Its value */
+ Aaddr stradr; /* Address to the name */
} PACKED_STRUCT;
-struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
- Aword loc; /* Current location */
- Abool describe; /* Describe flag */
- Aaddr atrs; /* Address of attribute list */
- Aword cont; /* Index to container properties if any */
- Aaddr vrbs; /* Address to local verb table */
- Aaddr dscr1; /* Address to Aword description code */
- Aaddr dscr2; /* Address to short description code */
+struct ObjElem25 { /* OBJECT TABLE of 2.5 format*/
+ Aword loc; /* Current location */
+ Abool describe; /* Describe flag */
+ Aaddr atrs; /* Address of attribute list */
+ Aword cont; /* Index to container properties if any */
+ Aaddr vrbs; /* Address to local verb table */
+ Aaddr dscr1; /* Address to Aword description code */
+ Aaddr dscr2; /* Address to short description code */
} PACKED_STRUCT;
-struct ObjElem { /* OBJECT TABLE */
- Aword loc; /* Current location */
- Abool describe; /* Describe flag */
- Aaddr atrs; /* Address of attribute list */
- Aword cont; /* Index to container properties if any */
- Aaddr vrbs; /* Address to local verb table */
- Aaddr dscr1; /* Address to Aword description code */
- Aaddr art; /* Article printing code? Else use default */
- /* INTRODUCED: v2.6 */
- Aaddr dscr2; /* Address to short description code */
+struct ObjElem { /* OBJECT TABLE */
+ Aword loc; /* Current location */
+ Abool describe; /* Describe flag */
+ Aaddr atrs; /* Address of attribute list */
+ Aword cont; /* Index to container properties if any */
+ Aaddr vrbs; /* Address to local verb table */
+ Aaddr dscr1; /* Address to Aword description code */
+ Aaddr art; /* Article printing code? Else use default */
+ /* INTRODUCED: v2.6 */
+ Aaddr dscr2; /* Address to short description code */
} PACKED_STRUCT;
-struct CntElem { /* CONTAINER TABLE */
- Aaddr lims; /* Address to limit check code */
- Aaddr header; /* Address to header code */
- Aaddr empty; /* Address to empty code */
- Aword parent; /* Object or actor index */
- Aaddr nam; /* Address to statement printing name */
+struct CntElem { /* CONTAINER TABLE */
+ Aaddr lims; /* Address to limit check code */
+ Aaddr header; /* Address to header code */
+ Aaddr empty; /* Address to empty code */
+ Aword parent; /* Object or actor index */
+ Aaddr nam; /* Address to statement printing name */
} PACKED_STRUCT;
-struct LimElem { /* LIMIT Type */
- Aword atr; /* Attribute that limits */
- Aword val; /* And the limiting value */
- Aaddr stms; /* Statements if fail */
+struct LimElem { /* LIMIT Type */
+ Aword atr; /* Attribute that limits */
+ Aword val; /* And the limiting value */
+ Aaddr stms; /* Statements if fail */
} PACKED_STRUCT;
-struct RulElem { /* RULE TABLE */
- Abool run; /* Is rule already run? */
- Aaddr exp; /* Address to expression code */
- Aaddr stms; /* Address to run */
+struct RulElem { /* RULE TABLE */
+ Abool run; /* Is rule already run? */
+ Aaddr exp; /* Address to expression code */
+ Aaddr stms; /* Address to run */
} PACKED_STRUCT;
-struct EvtElem { /* EVENT TABLE */
- Aaddr stradr; /* Address to name string */
- Aaddr code; /* Address of code to run */
+struct EvtElem { /* EVENT TABLE */
+ Aaddr stradr; /* Address to name string */
+ Aaddr code; /* Address of code to run */
} PACKED_STRUCT;
-struct EvtqElem { /* EVENT QUEUE ELEMENT */
- int time;
- int event;
- int where;
+struct EvtqElem { /* EVENT QUEUE ELEMENT */
+ int time;
+ int event;
+ int where;
- /**
- * Read or write data to/from a save file
- */
- void synchronize(Common::Serializer &s);
+ /**
+ * Read or write data to/from a save file
+ */
+ void synchronize(Common::Serializer &s);
} PACKED_STRUCT;
-struct IniElem { /* STRING INITIALISATION TABLE */
- Aword fpos; /* File position */
- Aword len; /* Length */
- Aword adr; /* Where to store the string */
+struct IniElem { /* STRING INITIALISATION TABLE */
+ Aword fpos; /* File position */
+ Aword len; /* Length */
+ Aword adr; /* Where to store the string */
} PACKED_STRUCT;
-struct MsgElem26 { /* MESSAGE TABLE */
- Aword fpos; /* File position */
- Aword len; /* Length of message */
+struct MsgElem26 { /* MESSAGE TABLE */
+ Aword fpos; /* File position */
+ Aword len; /* Length of message */
} PACKED_STRUCT;
-struct MsgElem { /* MESSAGE TABLE */
- Aaddr stms; /* Address to statements*/
- /* Changed v2.7 from fpos+len in .dat */
+struct MsgElem { /* MESSAGE TABLE */
+ Aaddr stms; /* Address to statements*/
+ /* Changed v2.7 from fpos+len in .dat */
} PACKED_STRUCT;
-struct ParamElem { /* PARAMETER */
- Aword code; /* Code for this parameter (0=multiple) */
- Aword firstWord; /* Index to first word used by player */
- Aword lastWord; /* d:o to last */
+struct ParamElem { /* PARAMETER */
+ Aword code; /* Code for this parameter (0=multiple) */
+ Aword firstWord; /* Index to first word used by player */
+ Aword lastWord; /* d:o to last */
} PACKED_STRUCT;
typedef enum Type {TYPNUM, TYPSTR} Type;
-struct LitElem { /* LITERAL */
- Type type;
- Aptr value;
+struct LitElem { /* LITERAL */
+ Type type;
+ Aptr value;
} PACKED_STRUCT;
-#include "common/pack-end.h" // END STRUCT PACKING
+#include "common/pack-end.h" // END STRUCT PACKING
#define MAXPARAMS 9
#define MAXENTITY (header->actmax)
diff --git a/engines/glk/alan2/version.h b/engines/glk/alan2/version.h
index 3bb90ad..7efee97 100644
--- a/engines/glk/alan2/version.h
+++ b/engines/glk/alan2/version.h
@@ -31,25 +31,25 @@ namespace Alan2 {
typedef int64 Time;
struct Version {
- char* string;
- int version;
- int revision;
- int correction;
- Time time;
- char *state;
+ char *string;
+ int version;
+ int revision;
+ int correction;
+ Time time;
+ char *state;
};
struct Product {
- char* name;
- char* slogan;
- char* shortHeader;
- char* longHeader;
- char* date;
- char* time;
- char* user;
- char* host;
- char* ostype;
- Version version;
+ char *name;
+ char *slogan;
+ char *shortHeader;
+ char *longHeader;
+ char *date;
+ char *time;
+ char *user;
+ char *host;
+ char *ostype;
+ Version version;
};
Commit: 2cf0320569c80c8e389e44d1b0463792ddf8e7cd
https://github.com/scummvm/scummvm/commit/2cf0320569c80c8e389e44d1b0463792ddf8e7cd
Author: dreammaster (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Fixing gcc warnings
Changed paths:
engines/glk/alan2/acode.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/glkio.cpp
engines/glk/alan2/glkio.h
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/reverse.cpp
engines/glk/alan2/version.h
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index 35153ce..dcc292b 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -72,7 +72,13 @@ typedef int WrdKind;
/* Syntax element classifications */
-#define EOS (-2) /* End Of Syntax */
+// End of file
+#ifdef EOF
+#undef EOF
+#endif
+#define EOF ((uint32)-1)
+// End of syntax
+#define EOS ((uint32)-2)
/* Syntax element flag bits */
#define MULTIPLEBIT 0x1
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 6f65ddf..4e6babc 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -99,7 +99,7 @@ void syncVal(Common::Serializer &s, uint32 *fld) {
void Alan2::synchronizeSave(Common::Serializer &s) {
AtrElem *atr;
- int i;
+ Aword i;
// Sync current values
cur.synchronize(s);
@@ -136,7 +136,7 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
// Sync the event queue
if (s.isSaving()) {
eventq[etop].time = 0; // Mark the top
- for (i = 0; i <= etop; ++i)
+ for (i = 0; i <= (Aword)etop; ++i)
eventq[i].synchronize(s);
} else {
for (etop = 0; eventq[etop - 1].time; ++etop)
@@ -145,7 +145,7 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
}
// Sync scores
- for (i = 0; scores[i] != EOF; i++)
+ for (i = 0; (int)scores[i] != EOF; i++)
syncVal(s, &scores[i]);
}
diff --git a/engines/glk/alan2/glkio.cpp b/engines/glk/alan2/glkio.cpp
index 29c4875..fda54de 100644
--- a/engines/glk/alan2/glkio.cpp
+++ b/engines/glk/alan2/glkio.cpp
@@ -30,7 +30,7 @@ namespace Alan2 {
winid_t glkMainWin;
winid_t glkStatusWin;
-void glkio_printf(char *fmt, ...) {
+void glkio_printf(const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
if (glkMainWin) {
@@ -48,3 +48,4 @@ void glkio_printf(char *fmt, ...) {
} // End of namespace Alan2
} // End of namespace Glk
+
diff --git a/engines/glk/alan2/glkio.h b/engines/glk/alan2/glkio.h
index 8c1dee2..2dff66f 100644
--- a/engines/glk/alan2/glkio.h
+++ b/engines/glk/alan2/glkio.h
@@ -39,9 +39,10 @@ extern winid_t glkStatusWin;
#undef printf
#define printf glkio_printf
-void glkio_printf(char *, ...);
+void glkio_printf(const char *, ...);
} // End of namespace Alan2
} // End of namespace Glk
#endif
+
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 7dadbea..f585e7d 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -434,7 +434,7 @@ static void prsym(
recogniced and performed.
*/
-void output(char original[]) {
+void output(const char original[]) {
char ch;
char *str, *copy;
char *symptr;
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 1c21dc8..10b0015 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -103,7 +103,7 @@ extern void usage(void);
extern void error(MsgKind msg);
extern void syserr(const char *msg);
extern void statusline(void);
-extern void output(char string[]);
+extern void output(const char string[]);
extern void prmsg(MsgKind msg);
extern void para(void);
extern void newline(void);
diff --git a/engines/glk/alan2/reverse.cpp b/engines/glk/alan2/reverse.cpp
index a79ae02..34d50d9 100644
--- a/engines/glk/alan2/reverse.cpp
+++ b/engines/glk/alan2/reverse.cpp
@@ -37,12 +37,11 @@ namespace Alan2 {
Aword reversed(Aword w /* IN - The ACODE word to swap bytes of */) {
Aword s; /* The swapped ACODE word */
char *wp, *sp;
- int i;
wp = (char *) &w;
sp = (char *) &s;
- for (i = 0; i < sizeof(Aword); i++)
+ for (uint i = 0; i < sizeof(Aword); i++)
sp[sizeof(Aword) - 1 - i] = wp[i];
return s;
@@ -346,10 +345,8 @@ static void reverseRuls(Aword adr) {
*/
void reverseHdr(AcdHdr *hdr) {
- int i;
-
- /* Reverse all words in the header except the first (version marking) */
- for (i = 1; i < sizeof(AcdHdr) / sizeof(Aword); i++)
+ // Reverse all words in the header except the first (version marking)
+ for (uint i = 1; i < sizeof(AcdHdr) / sizeof(Aword); i++)
reverse(&((Aword *)hdr)[i]);
}
diff --git a/engines/glk/alan2/version.h b/engines/glk/alan2/version.h
index 7efee97..3268259 100644
--- a/engines/glk/alan2/version.h
+++ b/engines/glk/alan2/version.h
@@ -31,25 +31,25 @@ namespace Alan2 {
typedef int64 Time;
struct Version {
- char *string;
+ const char *string;
int version;
int revision;
int correction;
Time time;
- char *state;
+ const char *state;
};
struct Product {
- char *name;
- char *slogan;
- char *shortHeader;
- char *longHeader;
- char *date;
- char *time;
- char *user;
- char *host;
- char *ostype;
- Version version;
+ const char *name;
+ const char *slogan;
+ const char *shortHeader;
+ const char *longHeader;
+ const char *date;
+ const char *time;
+ const char *user;
+ const char *host;
+ const char *ostype;
+ const Version version;
};
Commit: 1249c335392d7cc2d5492a5bc8718b9a034fbb11
https://github.com/scummvm/scummvm/commit/1249c335392d7cc2d5492a5bc8718b9a034fbb11
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Change all EOF to EOD that is case to uint
Changed paths:
engines/glk/alan2/acode.h
engines/glk/alan2/alan2.cpp
engines/glk/alan2/decode.cpp
engines/glk/alan2/exe.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/params.cpp
engines/glk/alan2/parse.cpp
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h
index dcc292b..74f0e54 100644
--- a/engines/glk/alan2/acode.h
+++ b/engines/glk/alan2/acode.h
@@ -72,11 +72,8 @@ typedef int WrdKind;
/* Syntax element classifications */
-// End of file
-#ifdef EOF
-#undef EOF
-#endif
-#define EOF ((uint32)-1)
+// End of data
+#define EOD ((uint32)-1)
// End of syntax
#define EOS ((uint32)-2)
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 4e6babc..5953f83 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -145,7 +145,7 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
}
// Sync scores
- for (i = 0; (int)scores[i] != EOF; i++)
+ for (i = 0; (int)scores[i] != EOD; i++)
syncVal(s, &scores[i]);
}
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
index 2955c37..4f89380 100644
--- a/engines/glk/alan2/decode.cpp
+++ b/engines/glk/alan2/decode.cpp
@@ -30,14 +30,14 @@ namespace Alan2 {
/* Bit output */
static int decodeBuffer; /* Bits to be input */
static int bitsToGo; /* Bits still in buffer */
-static int garbageBits; /* Bits past EOF */
+static int garbageBits; /* Bits past EOD */
static int inputBit() {
int bit;
if (!bitsToGo) { /* More bits available ? */
decodeBuffer = txtfil->readByte(); /* No, so get more */
- if (decodeBuffer == EOF) {
+ if (decodeBuffer == EOD) {
garbageBits++;
if (garbageBits > VALUEBITS - 2)
syserr("Error in encoded data file.");
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index f749425..6072f5e 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -446,7 +446,7 @@ static Aptr litatr(Aword lit, Aword atr) {
sprintf(str, "Unknown attribute for literal (%ld).", (unsigned long) atr);
syserr(str);
}
- return (Aptr)EOF;
+ return (Aptr)EOD;
}
Aptr attribute(Aword id, Aword atr) {
@@ -464,7 +464,7 @@ Aptr attribute(Aword id, Aword atr) {
sprintf(str, "Can't ATTRIBUTE item (%ld).", (unsigned long) id);
syserr(str);
}
- return (Aptr)EOF;
+ return (Aptr)EOD;
}
Aptr strattr(Aword id, Aword atr) {
@@ -503,7 +503,7 @@ Aword where(Aword id) {
sprintf(str, "Can't WHERE item (%ld).", (unsigned long) id);
syserr(str);
}
- return (Aptr)EOF;
+ return (Aptr)EOD;
}
@@ -654,7 +654,7 @@ Abool isHere(Aword id) {
sprintf(str, "Can't HERE item (%ld).", (unsigned long) id);
syserr(str);
}
- return (Abool)EOF;
+ return (Abool)EOD;
}
/*----------------------------------------------------------------------
@@ -688,7 +688,7 @@ Abool isNear(Aword id) {
sprintf(str, "Can't NEAR item (%ld).", (unsigned long) id);
syserr(str);
}
- return (Abool)EOF;
+ return (Abool)EOD;
}
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index f585e7d..8f9752d 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -167,7 +167,7 @@ void syserr(const char *str) {
void error(MsgKind msgno /* IN - The error message number */) {
if (msgno != MSGMAX)
prmsg(msgno);
- wrds[wrdidx] = EOF; /* Force new player input */
+ wrds[wrdidx] = EOD; /* Force new player input */
dscrstkp = 0; /* Reset describe stack */
//longjmp(jmpbuf,TRUE);
@@ -330,10 +330,10 @@ static void sayparam(int p) {
int i;
for (i = 0; i <= p; i++)
- if (params[i].code == EOF)
+ if (params[i].code == EOD)
syserr("Nonexistent parameter referenced.");
- if (params[p].firstWord == EOF) /* Any words he used? */
+ if (params[p].firstWord == EOD) /* Any words he used? */
say(params[p].code);
else /* Yes, so use them... */
for (i = params[p].firstWord; i <= params[p].lastWord; i++) {
@@ -491,7 +491,7 @@ void prmsg(MsgKind msg /* IN - message number */) {
/* How to know we are at end of a table */
Boolean eot(Aword *adr) {
- return *adr == EOF;
+ return *adr == EOD;
}
Boolean isObj(Aword x) {
@@ -778,7 +778,7 @@ Boolean possible() {
if (!trycheck(alt[1]->checks, FALSE))
return FALSE;
- for (i = 0; params[i].code != EOF; i++) {
+ for (i = 0; params[i].code != EOD; i++) {
alt[i + 2] = findalt(objs[params[i].code - OBJMIN].vrbs, i + 1);
/* CHECKs in a possible parameter */
if (alt[i + 2] != 0 && alt[i + 2]->checks != 0)
@@ -786,10 +786,10 @@ Boolean possible() {
return FALSE;
}
- for (i = 0; i < 2 || params[i - 2].code != EOF; i++)
+ for (i = 0; i < 2 || params[i - 2].code != EOD; i++)
if (alt[i] != 0 && alt[i]->action != 0)
break;
- if (i >= 2 && params[i - 2].code == EOF)
+ if (i >= 2 && params[i - 2].code == EOD)
/* Didn't find any code for this verb/object combination */
return FALSE;
else
@@ -829,7 +829,7 @@ static void do_it() {
if (fail) return;
}
- for (i = 0; params[i].code != EOF; i++) {
+ for (i = 0; params[i].code != EOD; i++) {
if (isLit(params[i].code))
alt[i + 2] = 0;
else {
@@ -850,10 +850,10 @@ static void do_it() {
}
/* Check for anything to execute... */
- for (i = 0; i < 2 || params[i - 2].code != EOF; i++)
+ for (i = 0; i < 2 || params[i - 2].code != EOD; i++)
if (alt[i] != 0 && alt[i]->action != 0)
break;
- if (i >= 2 && params[i - 2].code == EOF)
+ if (i >= 2 && params[i - 2].code == EOD)
/* Didn't find any code for this verb/object combination */
error(M_CANT0);
@@ -862,7 +862,7 @@ static void do_it() {
/* First try any BEFORE or ONLY from outside in */
done[0] = FALSE;
done[1] = FALSE;
- for (i = 2; params[i - 2].code != EOF; i++)
+ for (i = 2; params[i - 2].code != EOD; i++)
done[i] = FALSE;
i--;
while (i >= 0) {
@@ -891,7 +891,7 @@ static void do_it() {
}
/* Then execute any not declared as AFTER, i.e. the default */
- for (i = 0; i < 2 || params[i - 2].code != EOF; i++) {
+ for (i = 0; i < 2 || params[i - 2].code != EOD; i++) {
if (alt[i] != 0)
if (alt[i]->qual != (Aword)Q_AFTER) {
if (!done[i] && alt[i]->action != 0) {
@@ -952,11 +952,11 @@ void action(ParamElem plst[] /* IN - Plural parameter list */) {
*/
for (mpos = 0; params[mpos].code != 0; mpos++); /* Find multiple position */
sprintf(marker, "($%d)", mpos + 1); /* Prepare a printout with $1/2/3 */
- for (i = 0; plst[i].code != EOF; i++) {
+ for (i = 0; plst[i].code != EOD; i++) {
params[mpos] = plst[i];
output(marker);
do_it();
- if (plst[i + 1].code != EOF)
+ if (plst[i + 1].code != EOD)
para();
}
params[mpos].code = 0;
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 10b0015..3d0f308 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -73,8 +73,8 @@ extern Common::SeekableReadStream *codfil;
#undef fseek
#undef fclose
#define ftell(FP) FP->pos()
-#define fgetc(FP) (FP->pos() >= FP->size()) ? EOF : FP->readByte()
-#define getc(FP) (FP->pos() >= FP->size()) ? EOF : FP->readByte()
+#define fgetc(FP) (FP->pos() >= FP->size()) ? EOD : FP->readByte()
+#define getc(FP) (FP->pos() >= FP->size()) ? EOD : FP->readByte()
#define fseek(FP, OFS, WHENCE) FP->seek(OFS, WHENCE)
#define fclose(FP) delete FP
diff --git a/engines/glk/alan2/params.cpp b/engines/glk/alan2/params.cpp
index 8273518..1d5da8e 100644
--- a/engines/glk/alan2/params.cpp
+++ b/engines/glk/alan2/params.cpp
@@ -30,16 +30,16 @@ namespace Alan2 {
void compact(ParamElem a[]) {
int i, j;
- for (i = 0, j = 0; a[j].code != (Aword)EOF; j++)
+ for (i = 0, j = 0; a[j].code != (Aword)EOD; j++)
if (a[j].code != 0)
a[i++] = a[j];
- a[i].code = (Aword)EOF;
+ a[i].code = (Aword)EOD;
}
int lstlen(ParamElem a[]) {
int i = 0;
- while (a[i].code != (Aword)EOF)
+ while (a[i].code != (Aword)EOD)
i++;
return (i);
}
@@ -47,22 +47,22 @@ int lstlen(ParamElem a[]) {
Boolean inlst(ParamElem l[], Aword e) {
int i;
- for (i = 0; l[i].code != (Aword)EOF && l[i].code != e; i++);
+ for (i = 0; l[i].code != (Aword)EOD && l[i].code != e; i++);
return (l[i].code == e);
}
void lstcpy(ParamElem a[], ParamElem b[]) {
int i;
- for (i = 0; b[i].code != (Aword)EOF; i++)
+ for (i = 0; b[i].code != (Aword)EOD; i++)
a[i] = b[i];
- a[i].code = (Aword)EOF;
+ a[i].code = (Aword)EOD;
}
void sublst(ParamElem a[], ParamElem b[]) {
int i;
- for (i = 0; a[i].code != (Aword)EOF; i++)
+ for (i = 0; a[i].code != (Aword)EOD; i++)
if (inlst(b, a[i].code))
a[i].code = 0; /* Mark empty */
compact(a);
@@ -71,31 +71,31 @@ void sublst(ParamElem a[], ParamElem b[]) {
void mrglst(ParamElem a[], ParamElem b[]) {
int i, last;
- for (last = 0; a[last].code != (Aword)EOF; last++); /* Find end of list */
- for (i = 0; b[i].code != (Aword)EOF; i++)
+ for (last = 0; a[last].code != (Aword)EOD; last++); /* Find end of list */
+ for (i = 0; b[i].code != (Aword)EOD; i++)
if (!inlst(a, b[i].code)) {
a[last++] = b[i];
- a[last].code = (Aword)EOF;
+ a[last].code = (Aword)EOD;
}
}
void isect(ParamElem a[], ParamElem b[]) {
int i, last = 0;
- for (i = 0; a[i].code != (Aword)EOF; i++)
+ for (i = 0; a[i].code != (Aword)EOD; i++)
if (inlst(b, a[i].code))
a[last++] = a[i];
- a[last].code = (Aword)EOF;
+ a[last].code = (Aword)EOD;
}
void cpyrefs(ParamElem p[], Aword r[]) {
int i;
- for (i = 0; r[i] != (Aword)EOF; i++) {
+ for (i = 0; r[i] != (Aword)EOD; i++) {
p[i].code = r[i];
- p[i].firstWord = (Aword)EOF;
+ p[i].firstWord = (Aword)EOD;
}
- p[i].code = (Aword)EOF;
+ p[i].code = (Aword)EOD;
}
} // End of namespace Alan2
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index db478ff..a12a655 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -41,7 +41,7 @@ namespace Alan2 {
/* PUBLIC DATA */
-int wrds[LISTLEN / 2] = {EOF}; /* List of parsed words */
+int wrds[LISTLEN / 2] = {EOD}; /* List of parsed words */
int wrdidx; /* and an index into it */
Boolean plural = FALSE;
@@ -113,7 +113,7 @@ static int lookup(char wrd[]) {
return (i);
}
unknown(wrd);
- return (EOF);
+ return (EOD);
}
static int number(char token[] /* IN - The string to convert to a number */) {
@@ -224,7 +224,7 @@ static void scan() {
wrds[i++] = conjWord;
} else
unknown(token);
- wrds[i] = EOF;
+ wrds[i] = EOD;
eol = (token = gettoken(NULL)) == NULL;
} while (!eol);
}
@@ -252,11 +252,11 @@ static int allLength; /* No. of objects matching 'all' */
static void nonverb() {
if (isDir(wrds[wrdidx])) {
wrdidx++;
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx]))
error(M_WHAT);
else
go(dict[wrds[wrdidx - 1]].code);
- if (wrds[wrdidx] != EOF)
+ if (wrds[wrdidx] != EOD)
wrdidx++;
} else
error(M_WHAT);
@@ -270,19 +270,19 @@ static void buildall(ParamElem list[]) {
if (isHere(o)) {
found = TRUE;
list[i].code = o;
- list[i++].firstWord = EOF;
+ list[i++].firstWord = EOD;
}
if (!found)
error(M_WHAT_ALL);
else
- list[i].code = EOF;
+ list[i].code = EOD;
}
static void unambig(ParamElem plst[]) {
int i;
Boolean found = FALSE; /* Adjective or noun found ? */
static ParamElem *refs; /* Entities referenced by word */
- static ParamElem *savlst; /* Saved list for backup at EOF */
+ static ParamElem *savlst; /* Saved list for backup at EOD */
int firstWord, lastWord; /* The words the player used */
if (refs == NULL)
@@ -294,12 +294,12 @@ static void unambig(ParamElem plst[]) {
if (isLiteral(wrds[wrdidx])) {
/* Transform the word into a reference to the literal value */
plst[0].code = wrds[wrdidx++] - dictsize + LITMIN;
- plst[0].firstWord = EOF; /* No words used! */
- plst[1].code = EOF;
+ plst[0].firstWord = EOD; /* No words used! */
+ plst[1].code = EOD;
return;
}
- plst[0].code = EOF; /* Make empty */
+ plst[0].code = EOD; /* Make empty */
if (isIt(wrds[wrdidx])) {
wrdidx++;
/* Use last object in previous command! */
@@ -308,20 +308,20 @@ static void unambig(ParamElem plst[]) {
error(M_WHAT_IT);
if (!isHere(pparams[i].code)) {
params[0].code = pparams[i].code;
- params[0].firstWord = EOF;
- params[1].code = EOF;
+ params[0].firstWord = EOD;
+ params[1].code = EOD;
error(M_NO_SUCH);
}
plst[0] = pparams[i];
- plst[0].firstWord = EOF; /* No words used! */
- plst[1].code = EOF;
+ plst[0].firstWord = EOD; /* No words used! */
+ plst[1].code = EOD;
return;
}
firstWord = wrdidx;
- while (wrds[wrdidx] != EOF && isAdj(wrds[wrdidx])) {
+ while (wrds[wrdidx] != EOD && isAdj(wrds[wrdidx])) {
/* If this word can be a noun and there is no noun following break loop */
- if (isNoun(wrds[wrdidx]) && (wrds[wrdidx + 1] == EOF || !isNoun(wrds[wrdidx + 1])))
+ if (isNoun(wrds[wrdidx]) && (wrds[wrdidx + 1] == EOD || !isNoun(wrds[wrdidx + 1])))
break;
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].adjrefs));
lstcpy(savlst, plst); /* To save it for backtracking */
@@ -333,7 +333,7 @@ static void unambig(ParamElem plst[]) {
}
wrdidx++;
}
- if (wrds[wrdidx] != EOF) {
+ if (wrds[wrdidx] != EOD) {
if (isNoun(wrds[wrdidx])) {
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx]].nounrefs));
if (found)
@@ -350,7 +350,7 @@ static void unambig(ParamElem plst[]) {
/* Perhaps the last word was also a noun? */
lstcpy(plst, savlst); /* Restore to before last adjective */
cpyrefs(refs, (Aword *)addrTo(dict[wrds[wrdidx - 1]].nounrefs));
- if (plst[0].code == EOF)
+ if (plst[0].code == EOD)
lstcpy(plst, refs);
else
isect(plst, refs);
@@ -361,17 +361,17 @@ static void unambig(ParamElem plst[]) {
/* Allow remote objects, but resolve ambiguities by presence */
if (lstlen(plst) > 1) {
- for (i = 0; plst[i].code != EOF; i++)
+ for (i = 0; plst[i].code != EOD; i++)
if (!isHere(plst[i].code))
plst[i].code = 0;
compact(plst);
}
if (lstlen(plst) > 1 || (found && lstlen(plst) == 0)) {
- params[0].code = 0; /* Just make it anything != EOF */
+ params[0].code = 0; /* Just make it anything != EOD */
params[0].firstWord = firstWord; /* Remember words for errors below */
params[0].lastWord = lastWord;
- params[1].code = EOF; /* But be sure to terminate */
+ params[1].code = EOD; /* But be sure to terminate */
if (lstlen(plst) > 1)
error(M_WHICH_ONE);
else if (found && lstlen(plst) == 0)
@@ -390,19 +390,19 @@ static void simple(ParamElem olst[]) {
if (tlst == NULL)
tlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
- tlst[0].code = EOF;
+ tlst[0].code = EOD;
for (;;) {
if (isThem(wrds[wrdidx])) {
plural = TRUE;
- for (i = 0; pmlst[i].code != EOF; i++)
+ for (i = 0; pmlst[i].code != EOD; i++)
if (!isHere(pmlst[i].code))
pmlst[i].code = 0;
compact(pmlst);
if (lstlen(pmlst) == 0)
error(M_WHAT_THEM);
lstcpy(olst, pmlst);
- olst[0].firstWord = EOF; /* No words used */
+ olst[0].firstWord = EOD; /* No words used */
wrdidx++;
} else {
unambig(olst); /* Look for unambigous noun phrase */
@@ -414,7 +414,7 @@ static void simple(ParamElem olst[]) {
}
}
mrglst(tlst, olst);
- if (wrds[wrdidx] != EOF
+ if (wrds[wrdidx] != EOD
&& (isConj(wrds[wrdidx]) &&
(isAdj(wrds[wrdidx + 1]) || isNoun(wrds[wrdidx + 1])))) {
/* More parameters in a conjunction separated list ? */
@@ -449,7 +449,7 @@ static void complex(ParamElem olst[]) {
plural = TRUE;
buildall(alst); /* Build list of all objects */
wrdidx++;
- if (wrds[wrdidx] != EOF && isBut(wrds[wrdidx])) {
+ if (wrds[wrdidx] != EOD && isBut(wrds[wrdidx])) {
wrdidx++;
simple(olst);
if (lstlen(olst) == 0)
@@ -499,11 +499,11 @@ static void resolve(ParamElem plst[]) {
if (allLength > 0) return; /* ALL has already done this */
/* Resolve ambiguities by presence */
- for (i = 0; plst[i].code != EOF; i++)
+ for (i = 0; plst[i].code != EOD; i++)
if (plst[i].code < LITMIN) /* Literals are always 'here' */
if (!isHere(plst[i].code)) {
params[0] = plst[i]; /* Copy error param as first one for message */
- params[1].code = EOF; /* But be sure to terminate */
+ params[1].code = EOD; /* But be sure to terminate */
error(M_NO_SUCH);
}
}
@@ -532,7 +532,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
while (TRUE) {
/* End of input? */
- if (wrds[wrdidx] == EOF || isConj(wrds[wrdidx])) {
+ if (wrds[wrdidx] == EOD || isConj(wrds[wrdidx])) {
while (!endOfTable(elms) && elms->code != EOS)
elms++;
if (endOfTable(elms))
@@ -576,7 +576,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
}
} else
params[paramidx++] = tlst[0];
- params[paramidx].code = EOF;
+ params[paramidx].code = EOD;
}
elms = (ElmElem *) addrTo(elms->next);
}
@@ -586,12 +586,12 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
if (elms->next == 0) /* No verb code, verb not declared! */
error(M_CANT0);
- for (p = 0; params[p].code != EOF; p++) /* Mark all parameters unchecked */
+ for (p = 0; params[p].code != EOD; p++) /* Mark all parameters unchecked */
checked[p] = FALSE;
for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
if (params[cla->code - 1].code == 0) {
/* This was a multiple parameter, so check all and remove failing */
- for (i = 0; mlst[i].code != EOF; i++) {
+ for (i = 0; mlst[i].code != EOD; i++) {
params[cla->code - 1] = mlst[i];
if (!claCheck(cla)) {
/* Multiple could be both an explicit list of params and an ALL */
@@ -619,11 +619,11 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
checked[cla->code - 1] = TRUE; /* Remember that it's already checked */
}
/* Now check the rest of the parameters, must be objects */
- for (p = 0; params[p].code != EOF; p++)
+ for (p = 0; params[p].code != EOD; p++)
if (!checked[p]) {
if (params[p].code == 0) {
/* This was a multiple parameter, check all and remove failing */
- for (i = 0; mlst[i].code != EOF; i++)
+ for (i = 0; mlst[i].code != EOD; i++)
if (mlst[i].code != 0) /* Skip any empty slots */
if (!isObj(mlst[i].code))
mlst[i].code = 0;
@@ -647,7 +647,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
params[p].code = 0; /* Restore multiple marker */
compact(mlst);
if (lstlen(mlst) == 0) {
- params[0].code = EOF;
+ params[0].code = EOD;
error(M_WHAT_ALL);
}
} else if (anyPlural) {
@@ -662,23 +662,23 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
static void match(ParamElem *mlst /* OUT - List of params allowed by multiple */) {
tryMatch(mlst); /* ... to understand what he said */
- if (wrds[wrdidx] != EOF && !isConj(wrds[wrdidx]))
+ if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx]))
error(M_WHAT);
- if (wrds[wrdidx] != EOF) /* More on this line? */
+ if (wrds[wrdidx] != EOD) /* More on this line? */
wrdidx++; /* If so skip the AND */
}
void parse() {
if (mlst == NULL) { /* Allocate large enough paramlists */
mlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
- mlst[0].code = EOF;
+ mlst[0].code = EOD;
pmlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
params = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
- params[0].code = EOF;
+ params[0].code = EOD;
pparams = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
}
- if (wrds[wrdidx] == EOF) {
+ if (wrds[wrdidx] == EOD) {
wrdidx = 0;
scan();
if (g_vm->shouldQuit())
@@ -689,9 +689,9 @@ void parse() {
allLength = 0;
paramidx = 0;
lstcpy(pparams, params);
- params[0].code = EOF;
+ params[0].code = EOD;
lstcpy(pmlst, mlst);
- mlst[0].code = EOF;
+ mlst[0].code = EOD;
if (isVerb(wrds[wrdidx])) {
vrbwrd = wrds[wrdidx];
vrbcode = dict[vrbwrd].code;
@@ -699,8 +699,8 @@ void parse() {
match(mlst);
action(mlst); /* mlst contains possible multiple params */
} else {
- params[0].code = EOF;
- pmlst[0].code = EOF;
+ params[0].code = EOD;
+ pmlst[0].code = EOD;
nonverb();
}
}
Commit: 8b509bbfee6d9c82d8f05e569f61f5781917cbda
https://github.com/scummvm/scummvm/commit/8b509bbfee6d9c82d8f05e569f61f5781917cbda
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Warning fixes
Changed paths:
engines/glk/alan2/debug.cpp
engines/glk/alan2/exe.cpp
engines/glk/alan2/inter.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/parse.cpp
engines/glk/alan2/sysdep.cpp
engines/glk/glulxe/serial.cpp
engines/glk/quetzal.cpp
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index f7075ca..96ce46c 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -51,7 +51,7 @@ static void showatrs(Aword atradr) {
static void showobjs() {
char str[80];
- int obj;
+ uint obj;
output("OBJECTS:");
for (obj = OBJMIN; obj <= OBJMAX; obj++) {
@@ -103,7 +103,7 @@ static void showobj(int obj) {
static void showcnts() {
char str[80];
- int cnt;
+ uint cnt;
#define CNT (cnt-CNTMIN)
output("CONTAINERS:");
@@ -121,11 +121,11 @@ static void showcnts() {
static void showcnt(int cnt) {
char str[80];
- int i;
+ uint i;
Abool found = FALSE;
-#define CNT (cnt-CNTMIN)
+#define CNT (int)(cnt - CNTMIN)
- if (cnt < CNTMIN || cnt > CNTMAX) {
+ if (cnt < (int)CNTMIN || cnt >(int)CNTMAX) {
sprintf(str, "Container number out of range. Between %ld and %ld, please.", (unsigned long) CNTMIN, (unsigned long) CNTMAX);
output(str);
return;
@@ -161,7 +161,7 @@ static void showcnt(int cnt) {
static void showlocs() {
char str[80];
- int loc;
+ uint loc;
output("LOCATIONS:");
for (loc = LOCMIN; loc <= LOCMAX; loc++) {
@@ -191,7 +191,7 @@ static void showloc(int loc) {
static void showacts() {
char str[80];
- int act;
+ uint act;
output("ACTORS:");
for (act = ACTMIN; act <= ACTMAX; act++) {
@@ -238,17 +238,17 @@ static void showact(int act) {
}
static void showevts() {
- int evt, i;
+ int i;
char str[80];
Boolean scheduled;
output("EVENTS:");
- for (evt = EVTMIN; evt <= EVTMAX; evt++) {
+ for (uint evt = EVTMIN; evt <= EVTMAX; evt++) {
sprintf(str, "$i%d (%s):", evt, (char *)addrTo(evts[evt - EVTMIN].stradr));
output(str);
scheduled = FALSE;
for (i = 0; i < etop; i++)
- if ((scheduled = (eventq[i].event == evt)))
+ if ((scheduled = (eventq[i].event == (int)evt)))
break;
if (scheduled) {
sprintf(str, "Scheduled for +%d, at ", eventq[i].time - cur.tick);
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index 6072f5e..fd5e36c 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -54,14 +54,14 @@ void dscracts();
void print(Aword fpos, Aword len) {
- char str[2 * WIDTH]; /* String buffer */
- int outlen = 0; /* Current output length */
- int ch;
+ char str[2 * WIDTH]; // String buffer
+ int outlen = 0; // Current output length
+ int ch = 0;
int i;
- long savfp; /* Temporary saved text file position */
- static Boolean printFlag = FALSE; /* Printing already? */
+ long savfp = 0; // Temporary saved text file position
+ static Boolean printFlag = FALSE; // Printing already?
Boolean savedPrintFlag = printFlag;
- void *info; /* Saved decoding info */
+ void *info = nullptr; // Saved decoding info
if (len == 0) return;
@@ -168,7 +168,6 @@ Boolean confirm(MsgKind msgno) {
void quit() {
char buf[80];
- char choices[10];
para();
while (!g_vm->shouldQuit()) {
@@ -203,7 +202,7 @@ void cancl(Aword evt) {
int i;
for (i = etop - 1; i >= 0; i--)
- if (eventq[i].event == evt) {
+ if (eventq[i].event == (int)evt) {
while (i < etop - 1) {
eventq[i].event = eventq[i + 1].event;
eventq[i].time = eventq[i + 1].time;
@@ -406,12 +405,14 @@ void incr(Aword id, Aword atr, Aword step) {
void decr(Aword id, Aword atr, Aword step) {
char str[80];
+ // TODO: Original did explicit negation on an unsigned value. Make sure that the
+ // casts added to ignore the warnings are okay
if (isObj(id))
- incrobj(id, atr, -step);
+ incrobj(id, atr, static_cast<uint>(-(int)step));
else if (isLoc(id))
- incrloc(id, atr, -step);
+ incrloc(id, atr, static_cast<uint>(-(int)step));
else if (isAct(id))
- incract(id, atr, -step);
+ incract(id, atr, static_cast<uint>(-(int)step));
else {
sprintf(str, "Can't DECR item (%ld).", (unsigned long) id);
syserr(str);
@@ -519,9 +520,9 @@ Aint agrmax(Aword atr, Aword whr) {
for (i = OBJMIN; i <= OBJMAX; i++) {
if (isLoc(whr)) {
- if (where(i) == whr && attribute(i, atr) > max)
+ if (where(i) == whr && (int)attribute(i, atr) > max)
max = attribute(i, atr);
- } else if (objs[i - OBJMIN].loc == whr && attribute(i, atr) > max)
+ } else if (objs[i - OBJMIN].loc == whr && (int)attribute(i, atr) > max)
max = attribute(i, atr);
}
return (max);
@@ -605,7 +606,7 @@ static void locact(Aword act, Aword whr) {
cur.act = prevact;
}
- if (cur.act != act)
+ if (cur.act != (int)act)
cur.loc = prevloc;
}
@@ -634,13 +635,14 @@ static Abool objhere(Aword obj) {
if (isObj(objs[obj - OBJMIN].loc) || isAct(objs[obj - OBJMIN].loc))
return (isHere(objs[obj - OBJMIN].loc));
else /* If the container wasn't anywhere, assume where HERO is! */
- return (where(HERO) == cur.loc);
- } else
- return (objs[obj - OBJMIN].loc == cur.loc);
+ return ((int)where(HERO) == cur.loc);
+ } else {
+ return (int)(objs[obj - OBJMIN].loc) == cur.loc;
+ }
}
static Aword acthere(Aword act) {
- return (acts[act - ACTMIN].loc == cur.loc);
+ return (int)(acts[act - ACTMIN].loc) == cur.loc;
}
Abool isHere(Aword id) {
@@ -879,9 +881,9 @@ void use(Aword act, Aword scr) {
*/
void list(Aword cnt) {
- int i;
+ uint i;
Aword props;
- Aword prevobj;
+ Aword prevobj = 0;
Boolean found = FALSE;
Boolean multiple = FALSE;
@@ -949,9 +951,7 @@ void list(Aword cnt) {
*/
void empty(Aword cnt, Aword whr) {
- int i;
-
- for (i = OBJMIN; i <= OBJMAX; i++)
+ for (uint i = OBJMIN; i <= OBJMAX; i++)
if (in(i, cnt))
locate(i, whr);
}
@@ -968,22 +968,21 @@ void empty(Aword cnt, Aword whr) {
\*----------------------------------------------------------------------*/
void dscrobjs() {
- int i;
- int prevobj;
+ uint i;
+ int prevobj = 0;
Boolean found = FALSE;
Boolean multiple = FALSE;
/* First describe everything here with its own description */
for (i = OBJMIN; i <= OBJMAX; i++)
- if (objs[i - OBJMIN].loc == cur.loc &&
+ if ((int)objs[i - OBJMIN].loc == cur.loc &&
objs[i - OBJMIN].describe &&
objs[i - OBJMIN].dscr1)
describe(i);
/* Then list everything else here */
for (i = OBJMIN; i <= OBJMAX; i++)
- if (objs[i - OBJMIN].loc == cur.loc &&
- objs[i - OBJMIN].describe) {
+ if ((int)objs[i - OBJMIN].loc == cur.loc && objs[i - OBJMIN].describe) {
if (!found) {
prmsg(M_SEEOBJ1);
sayarticle(i);
@@ -1016,11 +1015,10 @@ void dscrobjs() {
}
void dscracts() {
- int i;
+ uint i;
for (i = HERO + 1; i <= ACTMAX; i++)
- if (acts[i - ACTMIN].loc == cur.loc &&
- acts[i - ACTMIN].describe)
+ if ((int)acts[i - ACTMIN].loc == cur.loc && acts[i - ACTMIN].describe)
describe(i);
/* Set describe flag for all actors */
@@ -1029,7 +1027,7 @@ void dscracts() {
}
void look() {
- int i;
+ uint i;
if (looking)
syserr("Recursive LOOK.");
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 82486ee..0c7d51d 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -156,7 +156,7 @@ void interpret(Aaddr adr) {
pc = adr;
while (TRUE) {
if (stpflg) printf("\n%4x: ", pc);
- if (pc > memTop)
+ if (pc > (int)memTop)
syserr("Interpreting outside program.");
i = memory[pc++];
@@ -484,11 +484,11 @@ void interpret(Aaddr adr) {
break;
}
case I_SAYSTR: {
- Aptr adr;
- adr = pop();
+ Aptr sayAdr;
+ sayAdr = pop();
if (stpflg)
- printf("SAYSTR\t%5ld\t\t\"", adr);
- saystr((char *)adr);
+ printf("SAYSTR\t%5ld\t\t\"", sayAdr);
+ saystr((char *)sayAdr);
if (stpflg)
printf("\"");
break;
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 8f9752d..56e5f72 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -46,12 +46,12 @@ namespace Alan2 {
/* The Amachine memory */
Aword *memory;
-//static AcdHdr dummyHeader; /* Dummy to use until memory allocated */
+//static AcdHdr dummyHeader; // Dummy to use until memory allocated
AcdHdr *header;
-int memTop; /* Top of load memory */
+Aaddr memTop; // Top of load memory
-int conjWord; /* First conjunction in dictonary, for ',' */
+int conjWord; // First conjunction in dictonary, for ','
/* Amachine variables */
@@ -327,20 +327,22 @@ static void space() {
*/
static void sayparam(int p) {
- int i;
-
- for (i = 0; i <= p; i++)
+ for (int i = 0; i <= p; i++) {
if (params[i].code == EOD)
syserr("Nonexistent parameter referenced.");
+ }
- if (params[p].firstWord == EOD) /* Any words he used? */
+ // Any words he used?
+ if (params[p].firstWord == EOD) {
say(params[p].code);
- else /* Yes, so use them... */
- for (i = params[p].firstWord; i <= params[p].lastWord; i++) {
+ } else {
+ // Yes, so use them...
+ for (uint i = params[p].firstWord; i <= params[p].lastWord; i++) {
just((char *)addrTo(dict[wrds[i]].wrd));
if (i < params[p].lastWord)
just(" ");
}
+ }
}
@@ -539,7 +541,7 @@ Boolean exitto(int to, int from) {
return (FALSE); /* No exits */
for (ext = (ExtElem *) addrTo(locs[from - LOCMIN].exts); !endOfTable(ext); ext++)
- if (ext->next == to)
+ if ((int)ext->next == to)
return (TRUE);
return (FALSE);
@@ -553,13 +555,13 @@ Boolean exitto(int to, int from) {
*/
static int count(int cnt /* IN - the container to count */) {
- int i, j = 0;
+ int j = 0;
- for (i = OBJMIN; i <= OBJMAX; i++)
+ for (uint i = OBJMIN; i <= OBJMAX; i++)
if (in(i, cnt))
/* Then it's in this container also */
j++;
- return (j);
+ return j;
}
@@ -573,7 +575,7 @@ static int sumatr(
Aword atr, /* IN - the attribute to sum over */
Aword cnt /* IN - the container to sum */
) {
- int i;
+ uint i;
int sum = 0;
for (i = OBJMIN; i <= OBJMAX; i++)
@@ -614,7 +616,7 @@ Boolean checklim(
if (cnts[props - CNTMIN].lims != 0) { /* Any limits at all? */
for (lim = (LimElem *) addrTo(cnts[props - CNTMIN].lims); !endOfTable(lim); lim++)
if (lim->atr == 0) {
- if (count(cnt) >= lim->val) {
+ if (count(cnt) >= (int)lim->val) {
interpret(lim->stms);
return (TRUE); /* Limit check failed */
}
@@ -683,7 +685,7 @@ void go(int dir) {
ext = (ExtElem *) addrTo(locs[cur.loc - LOCMIN].exts);
if (locs[cur.loc - LOCMIN].exts != 0)
while (!endOfTable(ext)) {
- if (ext->code == dir) {
+ if ((int)ext->code == dir) {
ok = TRUE;
if (ext->checks != 0) {
if (trcflg) {
@@ -743,7 +745,7 @@ static AltElem *findalt(
return (NULL);
for (vrb = (VrbElem *) addrTo(vrbsadr); !endOfTable(vrb); vrb++)
- if (vrb->code == cur.vrb) {
+ if ((int)vrb->code == cur.vrb) {
for (alt = (AltElem *) addrTo(vrb->alts); !endOfTable(alt); alt++)
if (alt->param == param || alt->param == 0)
return alt;
@@ -1026,7 +1028,7 @@ static char logfnm[256];
checkvers()
*/
-static void checkvers(AcdHdr *header) {
+static void checkvers(AcdHdr *hdr) {
char vers[4];
char state[2];
@@ -1036,34 +1038,34 @@ static void checkvers(AcdHdr *header) {
/* Check version of .ACD file */
if (dbgflg) {
- state[0] = header->vers[3];
+ state[0] = hdr->vers[3];
state[1] = '\0';
printf("<Version of '%s' is %d.%d(%d)%s>",
advnam,
- (int)(header->vers[0]),
- (int)(header->vers[1]),
- (int)(header->vers[2]),
- (header->vers[3]) == 0 ? "" : state);
+ (int)(hdr->vers[0]),
+ (int)(hdr->vers[1]),
+ (int)(hdr->vers[2]),
+ (hdr->vers[3]) == 0 ? "" : state);
newline();
}
/* Compatible if version and revision match... */
- if (strncmp(header->vers, vers, 2) != 0) {
+ if (strncmp(hdr->vers, vers, 2) != 0) {
#ifdef V25COMPATIBLE
- if (header->vers[0] == 2 && header->vers[1] == 5) /* Check for 2.5 version */
+ if (hdr->vers[0] == 2 && hdr->vers[1] == 5) /* Check for 2.5 version */
/* This we can convert later if needed... */;
else
#endif
#ifdef V27COMPATIBLE
- if (header->vers[0] == 2 && header->vers[1] == 7) /* Check for 2.7 version */
+ if (hdr->vers[0] == 2 && hdr->vers[1] == 7) /* Check for 2.7 version */
/* This we can convert later if needed... */;
else
#endif
if (errflg) {
char str[80];
sprintf(str, "Incompatible version of ACODE program. Game is %ld.%ld, interpreter %ld.%ld.",
- (long)(header->vers[0]),
- (long)(header->vers[1]),
+ (long)(hdr->vers[0]),
+ (long)(hdr->vers[1]),
(long) alan.version.version,
(long) alan.version.revision);
syserr(str);
@@ -1081,7 +1083,7 @@ static void checkvers(AcdHdr *header) {
static void load() {
AcdHdr tmphdr;
Aword crc = 0;
- int i;
+ uint i;
char err[100];
Aword *ptr = (Aword *)&tmphdr + 1;
@@ -1106,7 +1108,7 @@ static void load() {
memTop = tmphdr.size;
header = (AcdHdr *) addrTo(0);
- if ((tmphdr.size * sizeof(Aword)) > codfil->size())
+ if ((int)(tmphdr.size * sizeof(Aword)) > codfil->size())
::error("Header size is greater than filesize");
codfil->seek(0);
@@ -1286,7 +1288,7 @@ static void movactor() {
ActElem *act = (ActElem *) &acts[cur.act - ACTMIN];
cur.loc = where(cur.act);
- if (cur.act == HERO) {
+ if (cur.act == (int)HERO) {
parse();
if (g_vm->shouldQuit())
return;
@@ -1370,17 +1372,13 @@ static void movactor() {
*/
static void openFiles() {
- char str[256];
- char *usr = "";
- time_t tick;
-
{
char *s = strrchr(codfnm, '\\');
if (!s) s = strrchr(codfnm, '/');
g_vm->garglk_set_story_name(s ? s + 1 : codfnm);
}
- /* Open Text file */
+ // Open Text file
strcpy(txtfnm, advnam);
strcat(txtfnm, ".dat");
@@ -1427,7 +1425,7 @@ void run() {
// (void) setjmp(jmpbuf);
// Move all characters
- for (cur.act = ACTMIN; cur.act <= ACTMAX; cur.act++) {
+ for (cur.act = ACTMIN; cur.act <= (int)ACTMAX; cur.act++) {
movactor();
if (g_vm->shouldQuit())
return;
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 3d0f308..9dffbc3 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -35,9 +35,9 @@ namespace Alan2 {
#define MEMORYSIZE 1000L
-extern int memTop; /* Top of memory */
+extern Aaddr memTop; // Top of memory
-extern int conjWord; /* First conjunction in dictionary */
+extern int conjWord; // First conjunction in dictionary
/* The Amachine memory */
extern Aword *memory;
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index a12a655..a977546 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -116,23 +116,24 @@ static int lookup(char wrd[]) {
return (EOD);
}
-static int number(char token[] /* IN - The string to convert to a number */) {
+/* IN - The string to convert to a number */
+static int number(char tok[]) {
int i;
- sscanf(token, "%d", &i);
+ sscanf(tok, "%d", &i);
return i;
}
-static char *gettoken(char *buf) {
+static char *gettoken(char *tokBuf) {
static char *marker;
static char oldch;
- if (buf == NULL)
+ if (tokBuf == NULL)
*marker = oldch;
else
- marker = buf;
+ marker = tokBuf;
while (*marker != '\0' && isSpace(*marker) && *marker != '\n') marker++;
- buf = marker;
+ tokBuf = marker;
if (isISOLetter(*marker))
while (*marker && (isISOLetter(*marker) || isdigit(*marker) || *marker == '\'')) marker++;
else if (isdigit(*marker))
@@ -147,7 +148,7 @@ static char *gettoken(char *buf) {
marker++;
oldch = *marker;
*marker = '\0';
- return buf;
+ return tokBuf;
}
static void agetline() {
@@ -263,10 +264,10 @@ static void nonverb() {
}
static void buildall(ParamElem list[]) {
- int o, i = 0;
+ int i = 0;
Boolean found = FALSE;
- for (o = OBJMIN; o <= OBJMAX; o++)
+ for (uint o = OBJMIN; o <= OBJMAX; o++)
if (isHere(o)) {
found = TRUE;
list[i].code = o;
@@ -508,7 +509,7 @@ static void resolve(ParamElem plst[]) {
}
}
-static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multiple */) {
+static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by multiple */) {
ElmElem *elms; /* Pointer to element list */
StxElem *stx; /* Pointer to syntax list */
ClaElem *cla; /* Pointer to class definitions */
@@ -523,7 +524,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
}
for (stx = stxs; !endOfTable(stx); stx++)
- if (stx->code == vrbcode)
+ if ((int)stx->code == vrbcode)
break;
if (endOfTable(stx))
error(M_WHAT);
@@ -571,7 +572,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
actual parameter values later
*/
params[paramidx++].code = 0;
- lstcpy(mlst, tlst);
+ lstcpy(matchLst, tlst);
anyPlural = TRUE;
}
} else
@@ -591,8 +592,8 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
for (cla = (ClaElem *) addrTo(elms->next); !endOfTable(cla); cla++) {
if (params[cla->code - 1].code == 0) {
/* This was a multiple parameter, so check all and remove failing */
- for (i = 0; mlst[i].code != EOD; i++) {
- params[cla->code - 1] = mlst[i];
+ for (i = 0; matchLst[i].code != EOD; i++) {
+ params[cla->code - 1] = matchLst[i];
if (!claCheck(cla)) {
/* Multiple could be both an explicit list of params and an ALL */
if (allLength == 0) {
@@ -606,7 +607,7 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
interpret(cla->stms);
para();
}
- mlst[i].code = 0; /* In any case remove it from the list */
+ matchLst[i].code = 0; /* In any case remove it from the list */
}
}
params[cla->code - 1].code = 0;
@@ -623,10 +624,10 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
if (!checked[p]) {
if (params[p].code == 0) {
/* This was a multiple parameter, check all and remove failing */
- for (i = 0; mlst[i].code != EOD; i++)
- if (mlst[i].code != 0) /* Skip any empty slots */
- if (!isObj(mlst[i].code))
- mlst[i].code = 0;
+ for (i = 0; matchLst[i].code != EOD; i++)
+ if (matchLst[i].code != 0) /* Skip any empty slots */
+ if (!isObj(matchLst[i].code))
+ matchLst[i].code = 0;
} else if (!isObj(params[p].code))
error(M_CANT0);
}
@@ -638,21 +639,21 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
if (allLength > 0) {
for (p = 0; params[p].code != 0; p++); /* Find multiple marker */
for (i = 0; i < allLength; i++) {
- if (mlst[i].code != 0) { /* Already empty? */
- params[p] = mlst[i];
+ if (matchLst[i].code != 0) { /* Already empty? */
+ params[p] = matchLst[i];
if (!possible())
- mlst[i].code = 0; /* Remove this from list */
+ matchLst[i].code = 0; /* Remove this from list */
}
}
params[p].code = 0; /* Restore multiple marker */
- compact(mlst);
- if (lstlen(mlst) == 0) {
+ compact(matchLst);
+ if (lstlen(matchLst) == 0) {
params[0].code = EOD;
error(M_WHAT_ALL);
}
} else if (anyPlural) {
- compact(mlst);
- if (lstlen(mlst) == 0)
+ compact(matchLst);
+ if (lstlen(matchLst) == 0)
/* If there where multiple parameters but non left, exit without a */
/* word, assuming we have already said enough */
error(MSGMAX);
@@ -660,8 +661,9 @@ static void tryMatch(ParamElem mlst[] /* OUT - List of params allowed by multipl
plural = anyPlural; /* Remember that we found plural objects */
}
-static void match(ParamElem *mlst /* OUT - List of params allowed by multiple */) {
- tryMatch(mlst); /* ... to understand what he said */
+/* OUT - List of params allowed by multiple */
+static void match(ParamElem *matchLst) {
+ tryMatch(matchLst); /* ... to understand what he said */
if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx]))
error(M_WHAT);
if (wrds[wrdidx] != EOD) /* More on this line? */
diff --git a/engines/glk/alan2/sysdep.cpp b/engines/glk/alan2/sysdep.cpp
index dc6e0b6..98b8ca6 100644
--- a/engines/glk/alan2/sysdep.cpp
+++ b/engines/glk/alan2/sysdep.cpp
@@ -158,14 +158,14 @@ char *strupp(char str[]) { /* INOUT - Native string to convert */
/* The following work on ISO characters */
int isLowerCase(int c) { /* IN - ISO character to test */
- static char lowChrs[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
- return (c != '\0' && strchr(lowChrs, c) != 0);
+ static char lowChars[] = "abcdefghijklmnopqrstuvwxyz\340\341\342\343\344\345\346\347\351\352\353\354\355\356\357\360\361\362\363\364\365\366\370\371\372\373\374\375\376\377";
+ return (c != '\0' && strchr(lowChars, c) != 0);
}
int isUpperCase(int c) { /* IN - ISO character to test */
- static char uppChrs[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
- return (c != '\0' && strchr(uppChrs, c) != 0);
+ static char upperChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
+ return (c != '\0' && strchr(upperChars, c) != 0);
}
diff --git a/engines/glk/glulxe/serial.cpp b/engines/glk/glulxe/serial.cpp
index 81cfa9e..983053a 100644
--- a/engines/glk/glulxe/serial.cpp
+++ b/engines/glk/glulxe/serial.cpp
@@ -364,7 +364,7 @@ Common::Error Glulxe::writeGameData(Common::WriteStream *ws) {
Common::Error Glulxe::readSaveData(Common::SeekableReadStream *rs) {
dest_t dest;
int ix;
- uint lx, res, val;
+ uint lx = 0, res, val;
uint filestart, filelen = 0;
uint heapsumlen = 0;
uint *heapsumarr = nullptr;
diff --git a/engines/glk/quetzal.cpp b/engines/glk/quetzal.cpp
index 68c11d0..b83d855 100644
--- a/engines/glk/quetzal.cpp
+++ b/engines/glk/quetzal.cpp
@@ -203,7 +203,7 @@ void QuetzalWriter::addCommonChunks(const Common::String &saveName) {
ws.write(saveName.c_str(), saveName.size());
ws.writeByte(0);
}
- Common::Language l;
+
// Write 'SCVM' chunk with game version & gameplay statistics
{
Common::WriteStream &ws = add(ID_SCVM);
Commit: d4075b188d9834c9901639f517aebf38ee584ee0
https://github.com/scummvm/scummvm/commit/d4075b188d9834c9901639f517aebf38ee584ee0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Further gcc warning fixes
Changed paths:
engines/glk/alan2/alan2.cpp
engines/glk/alan2/debug.cpp
engines/glk/alan2/decode.cpp
engines/glk/alan2/exe.cpp
engines/glk/alan2/inter.cpp
engines/glk/alan2/main.cpp
engines/glk/alan2/parse.cpp
engines/glk/alan2/parse.h
engines/glk/alan2/types.h
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 5953f83..1ae5dda 100644
--- a/engines/glk/alan2/alan2.cpp
+++ b/engines/glk/alan2/alan2.cpp
@@ -145,7 +145,7 @@ void Alan2::synchronizeSave(Common::Serializer &s) {
}
// Sync scores
- for (i = 0; (int)scores[i] != EOD; i++)
+ for (i = 0; scores[i] != EOD; i++)
syncVal(s, &scores[i]);
}
diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index 96ce46c..b455db6 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -296,8 +296,8 @@ void debug() {
lin = 1;
c = buf[0];
i = 0;
- sscanf(&buf[1], "%d", &i);
- } while (buf && c == '\0');
+ (void)sscanf(&buf[1], "%d", &i);
+ } while (/*buf &&*/ c == '\0');
switch (toUpper(c)) {
case 'H':
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
index 4f89380..1995637 100644
--- a/engines/glk/alan2/decode.cpp
+++ b/engines/glk/alan2/decode.cpp
@@ -37,7 +37,7 @@ static int inputBit() {
if (!bitsToGo) { /* More bits available ? */
decodeBuffer = txtfil->readByte(); /* No, so get more */
- if (decodeBuffer == EOD) {
+ if ((uint)decodeBuffer == EOD) {
garbageBits++;
if (garbageBits > VALUEBITS - 2)
syserr("Error in encoded data file.");
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index fd5e36c..fd3b065 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -1057,9 +1057,6 @@ void look() {
}
-static char savfnm[256];
-
-
/*----------------------------------------------------------------------
save()
@@ -1067,7 +1064,7 @@ static char savfnm[256];
*/
void save() {
- g_vm->saveGame();
+ (void)g_vm->saveGame();
}
@@ -1078,7 +1075,7 @@ void save() {
*/
void restore() {
- g_vm->loadGame();
+ (void)g_vm->loadGame();
}
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 0c7d51d..8675739 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -416,9 +416,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("HERE \t%5ld", id);
push(isHere(id));
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_NEAR: {
@@ -427,9 +428,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("NEAR \t%5ld", id);
push(isNear(id));
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_USE: {
@@ -448,9 +450,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("IN \t%5ld, %5ld ", obj, cnt);
push(in(obj, cnt));
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_DESCRIBE: {
@@ -529,9 +532,10 @@ void interpret(Aaddr adr) {
else printf("FALSE");
}
push(lh && rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_OR: {
@@ -548,9 +552,10 @@ void interpret(Aaddr adr) {
else printf("FALSE");
}
push(lh || rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_NE: {
@@ -562,9 +567,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("NE \t%5ld, %5ld", lh, rh);
push(lh != rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_EQ: {
@@ -576,9 +582,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("EQ \t%5ld, %5ld", lh, rh);
push(lh == rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_STREQ: {
@@ -590,9 +597,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("STREQ \t%5ld, %5ld", lh, rh);
push(streq((char *)lh, (char *)rh));
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_STREXACT: {
@@ -604,9 +612,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("STREXACT \t%5ld, %5ld", lh, rh);
push(strcmp((char *)lh, (char *)rh) == 0);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
free((void *)lh);
free((void *)rh);
break;
@@ -620,9 +629,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("LE \t%5ld, %5ld", lh, rh);
push(lh <= rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_GE: {
@@ -634,9 +644,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("GE \t%5ld, %5ld", lh, rh);
push(lh >= rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_LT: {
@@ -648,9 +659,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("LT \t%5ld, %5ld", lh, rh);
push((signed int)lh < (signed int)rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_GT: {
@@ -662,9 +674,10 @@ void interpret(Aaddr adr) {
if (stpflg)
printf("GT \t%5ld, %5ld", lh, rh);
push(lh > rh);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t(TRUE)");
else printf("\t(FALSE)");
+ }
break;
}
case I_PLUS: {
@@ -728,9 +741,10 @@ void interpret(Aaddr adr) {
else printf("FALSE");
}
push(!val);
- if (stpflg)
+ if (stpflg) {
if (top()) printf("\t\t(TRUE)");
else printf("\t\t(FALSE)");
+ }
break;
}
case I_MAX: {
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 56e5f72..f0c2d0e 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -224,7 +224,7 @@ void statusline() {
Print some text and log it if logging is on.
*/
-void logprint(char str[]) {
+static void logprint(const char str[]) {
printf(str);
if (logflg)
fprintf(logfil, "%s", str);
@@ -293,7 +293,7 @@ void *allocate(unsigned long len /* IN - Length to allocate */) {
Justify a string so that it wraps at end of screen.
*/
-static void just(char str[]) {
+static void just(const char str[]) {
logprint(str);
}
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index a977546..24961c9 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -41,8 +41,8 @@ namespace Alan2 {
/* PUBLIC DATA */
-int wrds[LISTLEN / 2] = {EOD}; /* List of parsed words */
-int wrdidx; /* and an index into it */
+Aword wrds[LISTLEN / 2] = {EOD}; // List of parsed words
+int wrdidx; // and an index into it
Boolean plural = FALSE;
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
index 1e51301..af3276f 100644
--- a/engines/glk/alan2/parse.h
+++ b/engines/glk/alan2/parse.h
@@ -28,10 +28,10 @@
namespace Glk {
namespace Alan2 {
-extern int wrds[]; /* List of Parsed Word */
-extern int wrdidx; /* and an index into it */
+extern Aword wrds[]; // List of Parsed Word
+extern int wrdidx; // and an index into it
-extern ParamElem *params; /* List of parameters */
+extern ParamElem *params; // List of parameters
extern Boolean plural;
extern LitElem litValues[];
@@ -39,7 +39,7 @@ extern int litCount;
extern int vrbwrd;
-/* Parse a new player command */
+// Parse a new player command
extern void parse(void);
} // End of namespace Alan2
diff --git a/engines/glk/alan2/types.h b/engines/glk/alan2/types.h
index 7c8a414..b6be432 100644
--- a/engines/glk/alan2/types.h
+++ b/engines/glk/alan2/types.h
@@ -59,18 +59,18 @@ namespace Alan2 {
#define addrTo(x) (&memory[x])
/* The word classes are represented as numbers but in the dictonary they are generated as bits */
-#define isVerb(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_VRB))!=0)
-#define isConj(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_CONJ))!=0)
-#define isBut(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_BUT))!=0)
-#define isThem(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_THEM))!=0)
-#define isIt(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_IT))!=0)
-#define isNoun(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOUN))!=0)
-#define isAdj(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ADJ))!=0)
-#define isPrep(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_PREP))!=0)
-#define isAll(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ALL))!=0)
-#define isDir(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_DIR))!=0)
-#define isNoise(word) (word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOISE))!=0)
-#define isLiteral(word) (word >= dictsize)
+#define isVerb(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_VRB))!=0)
+#define isConj(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_CONJ))!=0)
+#define isBut(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_BUT))!=0)
+#define isThem(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_THEM))!=0)
+#define isIt(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_IT))!=0)
+#define isNoun(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOUN))!=0)
+#define isAdj(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ADJ))!=0)
+#define isPrep(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_PREP))!=0)
+#define isAll(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_ALL))!=0)
+#define isDir(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_DIR))!=0)
+#define isNoise(word) ((int)word < dictsize && (dict[word]._class&((Aword)1L<<WRD_NOISE))!=0)
+#define isLiteral(word) ((int)word >= dictsize)
/* TYPES */
Commit: 62eb0be065cc2bd911d3e14f4b6356f3081b7817
https://github.com/scummvm/scummvm/commit/62eb0be065cc2bd911d3e14f4b6356f3081b7817
Author: dreammaster (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Further gcc warning fixes
Changed paths:
engines/glk/alan2/main.cpp
engines/glk/alan2/rules.cpp
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index f0c2d0e..6732bfb 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -1386,7 +1386,7 @@ static void openFiles() {
if (!f->open(txtfnm)) {
delete f;
Common::String s = Common::String::format("Can't open adventure text data file '%s'.", txtfnm);
- ::error(s.c_str());
+ ::error("%s", s.c_str());
}
// If logging open log file
diff --git a/engines/glk/alan2/rules.cpp b/engines/glk/alan2/rules.cpp
index 516b0d2..7b5729d 100644
--- a/engines/glk/alan2/rules.cpp
+++ b/engines/glk/alan2/rules.cpp
@@ -55,7 +55,7 @@ void rules() {
if (pop()) {
change = TRUE;
ruls[i - 1].run = TRUE;
- if (trcflg)
+ if (trcflg) {
if (!stpflg)
printf(", Executing:>\n");
else {
@@ -63,6 +63,8 @@ void rules() {
debugsay(cur.loc);
printf("), Executing:>\n");
}
+ }
+
interpret(ruls[i - 1].stms);
} else if (trcflg && !stpflg)
printf(":>\n");
Commit: bad3ecd643132a09422117b63a687bf758139c01
https://github.com/scummvm/scummvm/commit/bad3ecd643132a09422117b63a687bf758139c01
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T14:40:50-07:00
Commit Message:
GLK: ALAN2: Create jump context system to replace original setjmp
This is basically a simplified version of the ScummVM coroutines,
since we just need the ability to consistently break out to the
main game loop when a call is made to the error method
Changed paths:
A engines/glk/alan2/jumps.h
engines/glk/alan2/main.cpp
engines/glk/alan2/main.h
engines/glk/alan2/parse.cpp
engines/glk/alan2/parse.h
diff --git a/engines/glk/alan2/jumps.h b/engines/glk/alan2/jumps.h
new file mode 100644
index 0000000..b477354
--- /dev/null
+++ b/engines/glk/alan2/jumps.h
@@ -0,0 +1,70 @@
+/* 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 GLK_ALAN2_JUMPS
+#define GLK_ALAN2_JUMPS
+
+/* This provides a simplified version of the ScummVM coroutines to allow for automated
+ * breakouts to the main game loop from subroutinese rather than using unportable setjmps
+ */
+
+namespace Glk {
+namespace Alan2 {
+
+/**
+ * Context used for flagging when a break to the outer game loop
+ */
+struct Context {
+ bool _break;
+ Context() : _break(false) {}
+};
+
+#define CALL0(METHOD) { METHOD(context); if (context._break) return; }
+#define CALL1(METHOD, P1) { METHOD(context, P1); if (context._break) return; }
+#define CALL2(METHOD, P1, P2) { METHOD(context, P2); if (context._break) return; }
+#define CALL3(METHOD, P1, P2, P3) { METHOD(context, P3); if (context._break) return; }
+#define CALL4(METHOD, P1, P2, P3, P4) { METHOD(context, P4); if (context._break) return; }
+#define FUNC0(METHOD, RET) { RET = METHOD(context); if (context._break) return; }
+#define FUNC1(METHOD, RET, P1) { RET = METHOD(context, P1); if (context._break) return; }
+#define FUNC2(METHOD, RET, P1, P2) { RET = METHOD(context, P2); if (context._break) return; }
+#define FUNC3(METHOD, RET, P1, P2, P3) { RET = METHOD(context, P3); if (context._break) return; }
+#define FUNC4(METHOD, RET, P1, P2, P3, P4) { RET = METHOD(context, P4); if (context._break) return; }
+
+#define R0CALL0(METHOD) { METHOD(context); if (context._break) return 0; }
+#define R0CALL1(METHOD, P1) { METHOD(context, P1); if (context._break) return 0; }
+#define R0CALL2(METHOD, P1, P2) { METHOD(context, P2); if (context._break) return 0; }
+#define R0CALL3(METHOD, P1, P2, P3) { METHOD(context, P3); if (context._break) return 0; }
+#define R0CALL4(METHOD, P1, P2, P3, P4) { METHOD(context, P4); if (context._break) return 0; }
+#define R0FUNC0(METHOD, RET) { RET = METHOD(context); if (context._break) return 0; }
+#define R0FUNC1(METHOD, RET, P1) { RET = METHOD(context, P1); if (context._break) return 0; }
+#define R0FUNC2(METHOD, RET, P1, P2) { RET = METHOD(context, P2); if (context._break) return 0; }
+#define R0FUNC3(METHOD, RET, P1, P2, P3) { RET = METHOD(context, P3); if (context._break) return 0; }
+#define R0FUNC4(METHOD, RET, P1, P2, P3, P4) { RET = METHOD(context, P4); if (context._break) return 0; }
+
+#define CONTEXT Context &context
+#define LONG_JUMP { context._break = true; return; }
+#define LONG_JUMP0 { context._break = true; return 0; }
+
+} // End of namespace Alan2
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 6732bfb..2dea451 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -162,16 +162,15 @@ void syserr(const char *str) {
error()
Print an error message, force new player input and abort.
-
*/
-void error(MsgKind msgno /* IN - The error message number */) {
+ /* IN - The error message number */
+void error(CONTEXT, MsgKind msgno) {
if (msgno != MSGMAX)
prmsg(msgno);
wrds[wrdidx] = EOD; /* Force new player input */
dscrstkp = 0; /* Reset describe stack */
- //longjmp(jmpbuf,TRUE);
- ::error("Error occurred");
+ LONG_JUMP
}
@@ -677,13 +676,13 @@ static Boolean trycheck(
Move hero in a direction.
*/
-void go(int dir) {
+void go(CONTEXT, int dir) {
ExtElem *ext;
Boolean ok;
Aword oldloc;
ext = (ExtElem *) addrTo(locs[cur.loc - LOCMIN].exts);
- if (locs[cur.loc - LOCMIN].exts != 0)
+ if (locs[cur.loc - LOCMIN].exts != 0) {
while (!endOfTable(ext)) {
if ((int)ext->code == dir) {
ok = TRUE;
@@ -722,7 +721,9 @@ void go(int dir) {
}
ext++;
}
- error(M_NO_WAY);
+ }
+
+ CALL1(error, M_NO_WAY)
}
@@ -806,7 +807,7 @@ Boolean possible() {
Execute the action commanded by hero.
*/
-static void do_it() {
+static void do_it(CONTEXT) {
AltElem *alt[MAXPARAMS + 2]; /* List of alt-pointers, one for each param */
Boolean done[MAXPARAMS + 2]; /* Is it done */
int i; /* Parameter index */
@@ -855,9 +856,10 @@ static void do_it() {
for (i = 0; i < 2 || params[i - 2].code != EOD; i++)
if (alt[i] != 0 && alt[i]->action != 0)
break;
- if (i >= 2 && params[i - 2].code == EOD)
- /* Didn't find any code for this verb/object combination */
- error(M_CANT0);
+ if (i >= 2 && params[i - 2].code == EOD) {
+ // Didn't find any code for this verb/object combination
+ CALL1(error, M_CANT0)
+ }
/* Perform actions! */
@@ -943,7 +945,7 @@ static void do_it() {
such as THEM or lists of objects.
*/
-void action(ParamElem plst[] /* IN - Plural parameter list */) {
+void action(CONTEXT, ParamElem plst[] /* IN - Plural parameter list */) {
int i, mpos;
char marker[10];
@@ -957,13 +959,14 @@ void action(ParamElem plst[] /* IN - Plural parameter list */) {
for (i = 0; plst[i].code != EOD; i++) {
params[mpos] = plst[i];
output(marker);
- do_it();
+ CALL0(do_it)
if (plst[i + 1].code != EOD)
para();
}
params[mpos].code = 0;
- } else
- do_it();
+ } else {
+ CALL0(do_it)
+ }
}
@@ -1282,14 +1285,14 @@ static void init() {
Let the current actor move. If player, ask him.
*/
-static void movactor() {
+static void movactor(CONTEXT) {
ScrElem *scr;
StepElem *step;
ActElem *act = (ActElem *) &acts[cur.act - ACTMIN];
cur.loc = where(cur.act);
if (cur.act == (int)HERO) {
- parse();
+ CALL0(parse)
if (g_vm->shouldQuit())
return;
fail = FALSE; /* fail only aborts one actor */
@@ -1416,17 +1419,23 @@ void run() {
init(); /* Load, initialise and start the adventure */
- while (TRUE) {
- if (dbgflg)
- debug();
+ Context ctx;
+ for (;;) {
+ if (!ctx._break) {
+ if (dbgflg)
+ debug();
- eventchk();
- cur.tick++;
- // (void) setjmp(jmpbuf);
+ eventchk();
+ cur.tick++;
+ }
+
+ // Execution ends up here after calls to the error method
// Move all characters
- for (cur.act = ACTMIN; cur.act <= (int)ACTMAX; cur.act++) {
- movactor();
+ ctx._break = false;
+ for (cur.act = ACTMIN; cur.act <= (int)ACTMAX && !ctx._break; cur.act++) {
+ movactor(ctx);
+
if (g_vm->shouldQuit())
return;
}
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 9dffbc3..9672899 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -27,6 +27,7 @@
#include "common/file.h"
#include "glk/alan2/types.h"
+#include "glk/alan2/jumps.h"
namespace Glk {
namespace Alan2 {
@@ -100,7 +101,7 @@ extern Boolean needsp;
extern void *allocate(unsigned long len);
extern void terminate(int code);
extern void usage(void);
-extern void error(MsgKind msg);
+extern void error(CONTEXT, MsgKind msg);
extern void syserr(const char *msg);
extern void statusline(void);
extern void output(const char string[]);
@@ -111,8 +112,8 @@ extern void newline(void);
extern Boolean checklim(Aword cnt, Aword obj);
extern Boolean possible(void);
extern Boolean exitto(int to, int from);
-extern void action(ParamElem *plst);
-extern void go(int dir);
+extern void action(CONTEXT, ParamElem *plst);
+extern void go(CONTEXT, int dir);
extern Boolean eot(Aword *adr);
extern Boolean isObj(Aword x);
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index 24961c9..9e1c340 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -89,7 +89,7 @@ static char isobuf[LISTLEN + 1]; /* The input buffer in ISO */
static Boolean eol = TRUE; /* Looking at End of line? Yes, initially */
-static void unknown(char token[]) {
+static void unknown(CONTEXT, char token[]) {
char *str = (char *)allocate((int)strlen(token) + 4);
str[0] = '\'';
@@ -98,29 +98,29 @@ static void unknown(char token[]) {
output(str);
free(str);
eol = TRUE;
- error(M_UNKNOWN_WORD);
+ CALL1(error, M_UNKNOWN_WORD)
}
static char *token;
-static int lookup(char wrd[]) {
+static int lookup(CONTEXT, char wrd[]) {
int i;
for (i = 0; !endOfTable(&dict[i]); i++) {
if (strcmp(wrd, (char *) addrTo(dict[i].wrd)) == 0)
return (i);
}
- unknown(wrd);
- return (EOD);
+ R0CALL1(unknown, wrd)
+ return EOD;
}
/* IN - The string to convert to a number */
static int number(char tok[]) {
int i;
- sscanf(tok, "%d", &i);
+ (void)sscanf(tok, "%d", &i);
return i;
}
@@ -185,7 +185,7 @@ static void agetline() {
lin = 1;
}
-static void scan() {
+static void scan(CONTEXT) {
int i;
int w;
char *str;
@@ -203,7 +203,8 @@ static void scan() {
do {
if (isISOLetter(token[0])) {
(void) stringLower(token);
- w = lookup(token);
+ FUNC1(lookup, w, token);
+
if (!isNoise(w))
wrds[i++] = w;
} else if (isdigit(token[0])) {
@@ -223,8 +224,9 @@ static void scan() {
litValues[litCount++].value = (Aptr) str;
} else if (token[0] == ',') {
wrds[i++] = conjWord;
- } else
- unknown(token);
+ } else {
+ CALL1(unknown, token)
+ }
wrds[i] = EOD;
eol = (token = gettoken(NULL)) == NULL;
} while (!eol);
@@ -250,20 +252,22 @@ static void scan() {
static int allLength; /* No. of objects matching 'all' */
-static void nonverb() {
+static void nonverb(CONTEXT) {
if (isDir(wrds[wrdidx])) {
wrdidx++;
- if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx]))
- error(M_WHAT);
- else
- go(dict[wrds[wrdidx - 1]].code);
+ if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx])) {
+ CALL1(error, M_WHAT)
+ } else {
+ CALL1(go, dict[wrds[wrdidx - 1]].code)
+ }
if (wrds[wrdidx] != EOD)
wrdidx++;
- } else
- error(M_WHAT);
+ } else {
+ CALL1(error, M_WHAT)
+ }
}
-static void buildall(ParamElem list[]) {
+static void buildall(CONTEXT, ParamElem list[]) {
int i = 0;
Boolean found = FALSE;
@@ -273,13 +277,14 @@ static void buildall(ParamElem list[]) {
list[i].code = o;
list[i++].firstWord = EOD;
}
- if (!found)
- error(M_WHAT_ALL);
- else
+ if (!found) {
+ CALL1(error, M_WHAT_ALL)
+ } else {
list[i].code = EOD;
+ }
}
-static void unambig(ParamElem plst[]) {
+static void unambig(CONTEXT, ParamElem plst[]) {
int i;
Boolean found = FALSE; /* Adjective or noun found ? */
static ParamElem *refs; /* Entities referenced by word */
@@ -305,13 +310,14 @@ static void unambig(ParamElem plst[]) {
wrdidx++;
/* Use last object in previous command! */
for (i = lstlen(pparams) - 1; i >= 0 && (pparams[i].code == 0 || pparams[i].code >= LITMIN); i--);
- if (i < 0)
- error(M_WHAT_IT);
+ if (i < 0) {
+ CALL1(error, M_WHAT_IT)
+ }
if (!isHere(pparams[i].code)) {
params[0].code = pparams[i].code;
params[0].firstWord = EOD;
params[1].code = EOD;
- error(M_NO_SUCH);
+ CALL1(error, M_NO_SUCH)
}
plst[0] = pparams[i];
plst[0].firstWord = EOD; /* No words used! */
@@ -345,7 +351,7 @@ static void unambig(ParamElem plst[]) {
}
wrdidx++;
} else
- error(M_NOUN);
+ CALL1(error, M_NOUN)
} else if (found) {
if (isNoun(wrds[wrdidx - 1])) {
/* Perhaps the last word was also a noun? */
@@ -355,8 +361,9 @@ static void unambig(ParamElem plst[]) {
lstcpy(plst, refs);
else
isect(plst, refs);
- } else
- error(M_NOUN);
+ } else {
+ CALL1(error, M_NOUN)
+ }
}
lastWord = wrdidx - 1;
@@ -373,17 +380,18 @@ static void unambig(ParamElem plst[]) {
params[0].firstWord = firstWord; /* Remember words for errors below */
params[0].lastWord = lastWord;
params[1].code = EOD; /* But be sure to terminate */
- if (lstlen(plst) > 1)
- error(M_WHICH_ONE);
- else if (found && lstlen(plst) == 0)
- error(M_NO_SUCH);
+ if (lstlen(plst) > 1) {
+ CALL1(error, M_WHICH_ONE)
+ } else if (found && lstlen(plst) == 0) {
+ CALL1(error, M_NO_SUCH)
+ }
} else {
plst[0].firstWord = firstWord;
plst[0].lastWord = lastWord;
}
}
-static void simple(ParamElem olst[]) {
+static void simple(CONTEXT, ParamElem olst[]) {
static ParamElem *tlst = NULL;
int savidx = wrdidx;
Boolean savplur = FALSE;
@@ -400,13 +408,16 @@ static void simple(ParamElem olst[]) {
if (!isHere(pmlst[i].code))
pmlst[i].code = 0;
compact(pmlst);
- if (lstlen(pmlst) == 0)
- error(M_WHAT_THEM);
+ if (lstlen(pmlst) == 0) {
+ CALL1(error, M_WHAT_THEM)
+ }
+
lstcpy(olst, pmlst);
olst[0].firstWord = EOD; /* No words used */
wrdidx++;
} else {
- unambig(olst); /* Look for unambigous noun phrase */
+ // Look for unambigous noun phrase
+ CALL1(unambig, olst)
if (lstlen(olst) == 0) { /* Failed! */
lstcpy(olst, tlst);
wrdidx = savidx;
@@ -440,7 +451,7 @@ static void simple(ParamElem olst[]) {
entity tables. Particularly this goes for literals...
*/
-static void complex(ParamElem olst[]) {
+static void complex(CONTEXT, ParamElem olst[]) {
static ParamElem *alst = NULL;
if (alst == NULL)
@@ -448,21 +459,24 @@ static void complex(ParamElem olst[]) {
if (isAll(wrds[wrdidx])) {
plural = TRUE;
- buildall(alst); /* Build list of all objects */
+ // Build list of all objects
+ CALL1(buildall, alst)
wrdidx++;
if (wrds[wrdidx] != EOD && isBut(wrds[wrdidx])) {
wrdidx++;
- simple(olst);
+ CALL1(simple, olst)
if (lstlen(olst) == 0)
- error(M_AFTER_BUT);
+ CALL1(error, M_AFTER_BUT)
sublst(alst, olst);
if (lstlen(alst) == 0)
- error(M_NOT_MUCH);
+ CALL1(error, M_NOT_MUCH)
}
lstcpy(olst, alst);
allLength = lstlen(olst);
- } else
- simple(olst); /* Look for simple noun group */
+ } else {
+ // Look for simple noun group
+ CALL1(simple, olst)
+ }
}
static Boolean claCheck(ClaElem *cla /* IN - The cla elem to check */) {
@@ -494,7 +508,7 @@ static Boolean claCheck(ClaElem *cla /* IN - The cla elem to check */) {
access to remote object), we need to remove non-present parameters
*/
-static void resolve(ParamElem plst[]) {
+static void resolve(CONTEXT, ParamElem plst[]) {
int i;
if (allLength > 0) return; /* ALL has already done this */
@@ -505,11 +519,12 @@ static void resolve(ParamElem plst[]) {
if (!isHere(plst[i].code)) {
params[0] = plst[i]; /* Copy error param as first one for message */
params[1].code = EOD; /* But be sure to terminate */
- error(M_NO_SUCH);
+ CALL1(error, M_NO_SUCH)
}
}
-static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by multiple */) {
+/* OUT - List of params allowed by multiple */
+static void tryMatch(CONTEXT, ParamElem matchLst[]) {
ElmElem *elms; /* Pointer to element list */
StxElem *stx; /* Pointer to syntax list */
ClaElem *cla; /* Pointer to class definitions */
@@ -526,8 +541,9 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
for (stx = stxs; !endOfTable(stx); stx++)
if ((int)stx->code == vrbcode)
break;
- if (endOfTable(stx))
- error(M_WHAT);
+ if (endOfTable(stx)) {
+ CALL1(error, M_WHAT)
+ }
elms = (ElmElem *) addrTo(stx->elms);
@@ -536,37 +552,43 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
if (wrds[wrdidx] == EOD || isConj(wrds[wrdidx])) {
while (!endOfTable(elms) && elms->code != EOS)
elms++;
- if (endOfTable(elms))
- error(M_WHAT);
- else
+ if (endOfTable(elms)) {
+ CALL1(error, M_WHAT)
+ } else
break;
} else {
/* A preposition? */
if (isPrep(wrds[wrdidx])) {
while (!endOfTable(elms) && elms->code != dict[wrds[wrdidx]].code)
elms++;
- if (endOfTable(elms))
- error(M_WHAT);
- else
+ if (endOfTable(elms)) {
+ CALL1(error, M_WHAT)
+ } else
wrdidx++;
} else {
/* Must be a parameter! */
while (!endOfTable(elms) && elms->code != 0)
elms++;
- if (endOfTable(elms))
- error(M_WHAT);
+ if (endOfTable(elms)) {
+ CALL1(error, M_WHAT)
+ }
/* Get it! */
plural = FALSE;
- complex(tlst);
- if (lstlen(tlst) == 0) /* No object!? */
- error(M_WHAT);
- if ((elms->flags & OMNIBIT) == 0) /* Omnipotent parameter? */
+ CALL1(complex, tlst)
+ if (lstlen(tlst) == 0) {
+ /* No object!? */
+ CALL1(error, M_WHAT)
+ }
+ /* Omnipotent parameter? */
+ if ((elms->flags & OMNIBIT) == 0) {
/* If its not an omnipotent parameter, resolve by presence */
- resolve(tlst);
+ CALL1(resolve, tlst)
+ }
if (plural) {
- if ((elms->flags & MULTIPLEBIT) == 0) /* Allowed multiple? */
- error(M_MULTIPLE);
- else {
+ /* Allowed multiple? */
+ if ((elms->flags & MULTIPLEBIT) == 0) {
+ CALL1(error, M_MULTIPLE)
+ } else {
/*
Mark this as the multiple position in which to insert
actual parameter values later
@@ -584,8 +606,10 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
}
/* Now perform class checks */
- if (elms->next == 0) /* No verb code, verb not declared! */
- error(M_CANT0);
+ if (elms->next == 0) {
+ /* No verb code, verb not declared! */
+ CALL1(error, M_CANT0)
+ }
for (p = 0; params[p].code != EOD; p++) /* Mark all parameters unchecked */
checked[p] = FALSE;
@@ -613,8 +637,9 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
params[cla->code - 1].code = 0;
} else {
if (!claCheck(cla)) {
+ /* Return to player without saying anything */
interpret(cla->stms);
- error(MSGMAX); /* Return to player without saying anything */
+ CALL1(error, MSGMAX)
}
}
checked[cla->code - 1] = TRUE; /* Remember that it's already checked */
@@ -628,8 +653,9 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
if (matchLst[i].code != 0) /* Skip any empty slots */
if (!isObj(matchLst[i].code))
matchLst[i].code = 0;
- } else if (!isObj(params[p].code))
- error(M_CANT0);
+ } else if (!isObj(params[p].code)) {
+ CALL1(error, M_CANT0)
+ }
}
/* Set verb code */
@@ -649,28 +675,30 @@ static void tryMatch(ParamElem matchLst[] /* OUT - List of params allowed by mul
compact(matchLst);
if (lstlen(matchLst) == 0) {
params[0].code = EOD;
- error(M_WHAT_ALL);
+ CALL1(error, M_WHAT_ALL)
}
} else if (anyPlural) {
compact(matchLst);
if (lstlen(matchLst) == 0)
/* If there where multiple parameters but non left, exit without a */
/* word, assuming we have already said enough */
- error(MSGMAX);
+ CALL1(error, MSGMAX)
}
plural = anyPlural; /* Remember that we found plural objects */
}
/* OUT - List of params allowed by multiple */
-static void match(ParamElem *matchLst) {
- tryMatch(matchLst); /* ... to understand what he said */
- if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx]))
- error(M_WHAT);
+static void match(CONTEXT, ParamElem *matchLst) {
+ /* ... to understand what he said */
+ CALL1(tryMatch, matchLst)
+ if (wrds[wrdidx] != EOD && !isConj(wrds[wrdidx])) {
+ CALL1(error, M_WHAT)
+ }
if (wrds[wrdidx] != EOD) /* More on this line? */
wrdidx++; /* If so skip the AND */
}
-void parse() {
+void parse(CONTEXT) {
if (mlst == NULL) { /* Allocate large enough paramlists */
mlst = (ParamElem *) allocate(sizeof(ParamElem) * (MAXENTITY + 1));
mlst[0].code = EOD;
@@ -682,7 +710,8 @@ void parse() {
if (wrds[wrdidx] == EOD) {
wrdidx = 0;
- scan();
+ CALL0(scan)
+
if (g_vm->shouldQuit())
return;
} else if (anyOutput)
@@ -698,12 +727,13 @@ void parse() {
vrbwrd = wrds[wrdidx];
vrbcode = dict[vrbwrd].code;
wrdidx++;
- match(mlst);
- action(mlst); /* mlst contains possible multiple params */
+ CALL1(match, mlst)
+ /* mlst contains possible multiple params */
+ CALL1(action, mlst)
} else {
params[0].code = EOD;
pmlst[0].code = EOD;
- nonverb();
+ CALL0(nonverb)
}
}
diff --git a/engines/glk/alan2/parse.h b/engines/glk/alan2/parse.h
index af3276f..100d739 100644
--- a/engines/glk/alan2/parse.h
+++ b/engines/glk/alan2/parse.h
@@ -25,6 +25,8 @@
/* Parse data for ALAN interpreter module. */
+#include "engines/glk/alan2/jumps.h"
+
namespace Glk {
namespace Alan2 {
@@ -40,7 +42,7 @@ extern int litCount;
extern int vrbwrd;
// Parse a new player command
-extern void parse(void);
+extern void parse(CONTEXT);
} // End of namespace Alan2
} // End of namespace Glk
More information about the Scummvm-git-logs
mailing list