1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "glk/alan3/syntax.h"
24 #include "glk/alan3/word.h"
25 #include "glk/alan3/msg.h"
26 #include "glk/alan3/lists.h"
27 #include "glk/alan3/compatibility.h"
28
29 namespace Glk {
30 namespace Alan3 {
31
32 /* PUBLIC DATA */
33 SyntaxEntry *stxs; /* Syntax table pointer */
34
35
36 /* PRIVATE TYPES & DATA */
37
38
39 /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/
40
41 /*======================================================================*/
elementTreeOf(SyntaxEntry * stx)42 ElementEntry *elementTreeOf(SyntaxEntry *stx) {
43 return (ElementEntry *) pointerTo(stx->elms);
44 }
45
46
47 /*----------------------------------------------------------------------*/
findSyntaxEntryForPreBeta2(int verbCode,SyntaxEntry * foundStx)48 static SyntaxEntry *findSyntaxEntryForPreBeta2(int verbCode, SyntaxEntry *foundStx) {
49 SyntaxEntryPreBeta2 *stx;
50 for (stx = (SyntaxEntryPreBeta2 *)stxs; !isEndOfArray(stx); stx++)
51 if (stx->code == verbCode) {
52 foundStx = (SyntaxEntry *)stx;
53 break;
54 }
55 return (foundStx);
56 }
57
58
59 /*----------------------------------------------------------------------*/
findSyntaxEntry(int verbCode)60 static SyntaxEntry *findSyntaxEntry(int verbCode) {
61 SyntaxEntry *stx;
62 for (stx = stxs; !isEndOfArray(stx); stx++)
63 if (stx->code == verbCode) {
64 return stx;
65 break;
66 }
67 return NULL;
68 }
69
70
71 /*======================================================================*/
findSyntaxTreeForVerb(CONTEXT,int verbCode)72 SyntaxEntry *findSyntaxTreeForVerb(CONTEXT, int verbCode) {
73 SyntaxEntry *foundStx = NULL;
74 if (isPreBeta2(header->version)) {
75 foundStx = findSyntaxEntryForPreBeta2(verbCode, foundStx);
76 } else {
77 foundStx = findSyntaxEntry(verbCode);
78 }
79 if (foundStx == NULL)
80 // No matching syntax
81 R0CALL1(error, M_WHAT)
82 return foundStx;
83 }
84
85
86 /*======================================================================*/
parameterNameInSyntax(int syntaxNumber,int parameterNumber)87 char *parameterNameInSyntax(int syntaxNumber, int parameterNumber) {
88 Aaddr adr = addressAfterTable(header->parameterMapAddress, sizeof(ParameterMapEntry));
89 Aaddr *syntaxParameterNameTable = (Aaddr *)pointerTo(memory[adr]);
90 Aaddr *parameterNameTable = (Aaddr *)pointerTo(syntaxParameterNameTable[syntaxNumber - 1]);
91 return stringAt(parameterNameTable[parameterNumber - 1]);
92 }
93
94 } // End of namespace Alan3
95 } // End of namespace Glk
96