| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "word.h" |
| 7 |
|
| 8 |
|
| 9 |
#include "types.h" |
| 10 |
#include "memory.h" |
| 11 |
#include "syserr.h" |
| 12 |
#include "lists.h" |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
Word *playerWords = NULL; |
| 22 |
int currentWordIndex; |
| 23 |
int firstWord, lastWord; |
| 24 |
|
| 25 |
|
| 26 |
static int playerWordsLength = 0; |
| 27 |
#define PLAYER_WORDS_EXTENT 20 |
| 28 |
|
| 29 |
|
| 30 |
int verbWord; |
| 31 |
int verbWordCode; |
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
} |