diff options
author | dreammaster | 2019-06-22 03:43:17 +0100 |
---|---|---|
committer | Paul Gilbert | 2019-06-22 14:40:50 -0700 |
commit | 2450df501c152249fe1002a7dee70642563d40a3 (patch) | |
tree | 226adf311a755ca71d2c18317199a74b2c130864 | |
parent | a3fa9d12a94494f86134f56df6c064d7e48e8580 (diff) | |
download | scummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.tar.gz scummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.tar.bz2 scummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.zip |
GLK: ALAN2: astyle formatting
26 files changed, 4117 insertions, 4109 deletions
diff --git a/engines/glk/alan2/acode.h b/engines/glk/alan2/acode.h index 8cb3c8149b..35153ceb7b 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 05e52335b5..6f65ddfc42 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 8960648dd7..ac67364910 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 d3e1b9dde7..5e88ba35bf 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 2f760aedbb..dc34949d3e 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 3c67fbe109..f7075ca5c8 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 f1ec3db89c..2955c37745 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 3cd16d8721..f749425cd0 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 1b0e5f9483..cc99719ded 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 47dbbf2ff0..29c4875a4a 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 5e2827f482..82486ee854 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 6b06e0bd80..7dadbea171 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 4a47b775f5..1c21dc83b5 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 e5414bdf32..8273518522 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 d83755bada..db478ff632 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 e2c558c5c3..1e513011fa 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 7569721f22..cd05435c18 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 943411e873..a79ae02a47 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 323f6e72a4..516b0d22fb 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 98423f02cd..6695fedf07 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 74d4fc98c8..dc6e0b6f95 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 7fce53c3e7..ea513aa9ec 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 c758efe434..df3a245d18 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 9ce4a657b0..d0c3c83d65 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 34c5dda87f..7c8a414af3 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 3bb90ad066..7efee9797b 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; }; |