Debian Codegraph @

terps/alan3/word.c

raw symbols SCIP
1 /*----------------------------------------------------------------------
2
3 word
4
5 ----------------------------------------------------------------------*/
6 #include "word.h"
7
8 /* IMPORTS */
9 #include "types.h"
10 #include "memory.h"
11 #include "syserr.h"
12 #include "lists.h"
13
14
15 /* CONSTANTS */
16
17
18 /* PUBLIC DATA */
19
20 /* List of parsed words, index into dictionary */
21 Word *playerWords = NULL;
22 int currentWordIndex; /* An index into the list of playerWords */
23 int firstWord, lastWord; /* Index for the first and last words for this command */
24
25 /* Some variable for dynamically allocating the playerWords, which will happen in scan() */
26 static int playerWordsLength = 0;
27 #define PLAYER_WORDS_EXTENT 20
28
29 /* What did the user say? */
30 int verbWord; /* The word he used as a verb, dictionary index */
31 int verbWordCode; /* The code for that verb */
32
33
34 /* PRIVATE TYPES & DATA */
35
36
37 /*+++++++++++++++++++++++++++++++++++++++++++++++++++*/
38
39 void ensureSpaceForPlayerWords(int size) {
40 int newLength = playerWordsLength+PLAYER_WORDS_EXTENT;
41
42 if (playerWordsLength < size+1) {
43 playerWords = realloc(playerWords, newLength*sizeof(Word));
44 if (playerWords == NULL)
45 syserr("Out of memory in 'ensureSpaceForPlayerWords()'");
46 playerWordsLength = newLength;
47 }
48 }
49
50
51 /*======================================================================*/
52 char *playerWordsAsCommandString(void) {
53 char *commandString;
54 int size = playerWords[lastWord].end - playerWords[firstWord].start;
55 commandString = allocate(size + 1);
56 strncpy(commandString, playerWords[firstWord].start, size);
57 commandString[size] = '\0';
58 return commandString;
59 }
60
61
62 /*======================================================================*/
63 void clearWordList(Word list[]) {
64 implementationOfSetEndOfArray((Aword *)list);
65 }