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/word.h"
24 #include "glk/alan3/types.h"
25 #include "glk/alan3/memory.h"
26 #include "glk/alan3/syserr.h"
27 #include "glk/alan3/lists.h"
28
29 namespace Glk {
30 namespace Alan3 {
31
32 /* PUBLIC DATA */
33
34 /* List of parsed words, index into dictionary */
35 Word *playerWords = NULL;
36 int currentWordIndex; /* An index into the list of playerWords */
37 int firstWord, lastWord; /* Index for the first and last words for this command */
38
39 /* Some variable for dynamically allocating the playerWords, which will happen in scan() */
40 static int playerWordsLength = 0;
41 #define PLAYER_WORDS_EXTENT 20
42
43 /* What did the user say? */
44 int verbWord; /* The word he used as a verb, dictionary index */
45 int verbWordCode; /* The code for that verb */
46
47
48 /* PRIVATE TYPES & DATA */
49
50
51 /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/
52
ensureSpaceForPlayerWords(int size)53 void ensureSpaceForPlayerWords(int size) {
54 int newLength = playerWordsLength + PLAYER_WORDS_EXTENT;
55
56 if (playerWordsLength < size + 1) {
57 playerWords = (Word *)realloc(playerWords, newLength * sizeof(Word));
58 if (playerWords == NULL)
59 syserr("Out of memory in 'ensureSpaceForPlayerWords()'");
60 playerWordsLength = newLength;
61 }
62 }
63
64
65 /*======================================================================*/
playerWordsAsCommandString(void)66 char *playerWordsAsCommandString(void) {
67 char *commandString;
68 int size = playerWords[lastWord].end - playerWords[firstWord].start;
69 commandString = (char *)allocate(size + 1);
70 strncpy(commandString, playerWords[firstWord].start, size);
71 commandString[size] = '\0';
72 return commandString;
73 }
74
75
76 /*======================================================================*/
clearWordList(Word list[])77 void clearWordList(Word list[]) {
78 implementationOfSetEndOfArray((Aword *)list);
79 }
80
81 } // End of namespace Alan3
82 } // End of namespace Glk
83