- for (;;) {
- reply = get_input();
- if (reply == NULL) {
- // LCOV_EXCL_START
- // Should be unreachable. Reply should never be NULL
- free(reply);
- exit(EXIT_SUCCESS);
- // LCOV_EXCL_STOP
- }
-
- char* firstword = (char*) xmalloc(strlen(reply) + 1);
- sscanf(reply, "%s", firstword);
-
- free(reply);
-
- for (int i = 0; i < (int)strlen(firstword); ++i)
- firstword[i] = tolower(firstword[i]);
-
- int yes = strncmp("yes", firstword, sizeof("yes") - 1);
- int y = strncmp("y", firstword, sizeof("y") - 1);
- int no = strncmp("no", firstword, sizeof("no") - 1);
- int n = strncmp("n", firstword, sizeof("n") - 1);
-
- free(firstword);
-
- if (yes == 0 ||
- y == 0) {
- outcome = true;
- break;
- } else if (no == 0 ||
- n == 0) {
- outcome = false;
- break;
- } else
- rspeak(PLEASE_ANSWER);
- }
- return (outcome);
-}
-
-
-bool yes(const char* question, const char* yes_response, const char* no_response)
-/* Print message X, wait for yes/no answer. If yes, print Y and return true;
- * if no, print Z and return false. */
-{
- char* reply;
- bool outcome;
-
- for (;;) {
- speak(question);
-
- reply = get_input();
- if (reply == NULL) {
- // LCOV_EXCL_START
- // Should be unreachable. Reply should never be NULL
- free(reply);
- exit(EXIT_SUCCESS);
- // LCOV_EXCL_STOP
- }
-
- char* firstword = (char*) xmalloc(strlen(reply) + 1);
- sscanf(reply, "%s", firstword);
-
- free(reply);
-
- for (int i = 0; i < (int)strlen(firstword); ++i)
- firstword[i] = tolower(firstword[i]);
-
- int yes = strncmp("yes", firstword, sizeof("yes") - 1);
- int y = strncmp("y", firstword, sizeof("y") - 1);
- int no = strncmp("no", firstword, sizeof("no") - 1);
- int n = strncmp("n", firstword, sizeof("n") - 1);
-
- free(firstword);
-
- if (yes == 0 ||
- y == 0) {
- speak(yes_response);
- outcome = true;
- break;
- } else if (no == 0 ||
- n == 0) {
- speak(no_response);
- outcome = false;
- break;
- } else
- rspeak(PLEASE_ANSWER);
-
- }
-
- return (outcome);
-}
-
-/* Data structure routines */
-
-int get_motion_vocab_id(const char* word)
-// Return the first motion number that has 'word' as one of its words.
-{
- for (int i = 0; i < NMOTIONS; ++i) {
- for (int j = 0; j < motions[i].words.n; ++j) {
- if (strcasecmp(word, motions[i].words.strs[j]) == 0 && (strlen(word) > 1 ||
- strchr(ignore, word[0]) == NULL ||
- !settings.oldstyle))
- return (i);
- }
- }
- // If execution reaches here, we didn't find the word.
- return (WORD_NOT_FOUND);
-}
-
-int get_object_vocab_id(const char* word)
-// Return the first object number that has 'word' as one of its words.
-{
- for (int i = 0; i < NOBJECTS + 1; ++i) { // FIXME: the + 1 should go when 1-indexing for objects is removed
- for (int j = 0; j < objects[i].words.n; ++j) {
- if (strcasecmp(word, objects[i].words.strs[j]) == 0)
- return (i);
- }
- }
- // If execution reaches here, we didn't find the word.
- return (WORD_NOT_FOUND);
-}
-
-int get_action_vocab_id(const char* word)
-// Return the first motion number that has 'word' as one of its words.
-{
- for (int i = 0; i < NACTIONS; ++i) {
- for (int j = 0; j < actions[i].words.n; ++j) {
- if (strcasecmp(word, actions[i].words.strs[j]) == 0 && (strlen(word) > 1 ||
- strchr(ignore, word[0]) == NULL ||
- !settings.oldstyle))
- return (i);
- }
- }
- // If execution reaches here, we didn't find the word.
- return (WORD_NOT_FOUND);
-}
-
-int get_special_vocab_id(const char* word)
-// Return the first special number that has 'word' as one of its words.
-{
- for (int i = 0; i < NSPECIALS; ++i) {
- for (int j = 0; j < specials[i].words.n; ++j) {
- if (strcasecmp(word, specials[i].words.strs[j]) == 0)
- return (i);
- }
- }
- // If execution reaches here, we didn't find the word.
- return (WORD_NOT_FOUND);
-}
-
-long get_vocab_id(const char* word)
-// Search the vocab categories in order for the supplied word.
-{
- /* Check for an empty string */
- if (strncmp(word, "", sizeof("")) == 0)
- return (WORD_EMPTY);
-
- long ref_num;
-
- /* FIXME: Magic numbers related to vocabulary */
- ref_num = get_motion_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return (ref_num + 0); // FIXME: replace with a proper hash
-
- ref_num = get_object_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return (ref_num + 1000); // FIXME: replace with a proper hash
-
- ref_num = get_action_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return (ref_num + 2000); // FIXME: replace with a proper hash
-
- ref_num = get_special_vocab_id(word);
- if (ref_num != WORD_NOT_FOUND)
- return (ref_num + 3000); // FIXME: replace with a proper hash
-
- // Check for the reservoir magic word.
- if (strcasecmp(word, game.zzword) == 0)
- return (PART + 2000); // FIXME: replace with a proper hash
-
- return (WORD_NOT_FOUND);
-}
-
-void juggle(long object)
-/* Juggle an object by picking it up and putting it down again, the purpose
- * being to get the object to the front of the chain of things at its loc. */
-{
- long i, j;
-
- i = game.place[object];
- j = game.fixed[object];
- move(object, i);
- move(object + NOBJECTS, j);
-}
-
-void move(long object, long where)
-/* Place any object anywhere by picking it up and dropping it. May
- * already be toting, in which case the carry is a no-op. Mustn't
- * pick up objects which are not at any loc, since carry wants to
- * remove objects from game.atloc chains. */
-{
- long from;
-
- if (object > NOBJECTS)
- from = game.fixed[object - NOBJECTS];
- else
- from = game.place[object];
- if (from != LOC_NOWHERE && from != CARRIED && !SPECIAL(from))
- carry(object, from);
- drop(object, where);
-}
-
-long put(long object, long where, long pval)
-/* PUT is the same as MOVE, except it returns a value used to set up the
- * negated game.prop values for the repository objects. */
-{
- move(object, where);
- return (-1) - pval;;
-}
-
-void carry(long object, long where)
-/* Start toting an object, removing it from the list of things at its former
- * location. Incr holdng unless it was already being toted. If object>NOBJECTS
- * (moving "fixed" second loc), don't change game.place or game.holdng. */
-{
- long temp;
-
- if (object <= NOBJECTS) {
- if (game.place[object] == CARRIED)
- return;
- game.place[object] = CARRIED;
- ++game.holdng;
- }
- if (game.atloc[where] == object) {
- game.atloc[where] = game.link[object];
- return;
- }
- temp = game.atloc[where];
- while (game.link[temp] != object) {
- temp = game.link[temp];
- }
- game.link[temp] = game.link[object];
-}
-
-void drop(long object, long where)
-/* Place an object at a given loc, prefixing it onto the game.atloc list. Decr
- * game.holdng if the object was being toted. */
-{
- if (object > NOBJECTS)
- game.fixed[object - NOBJECTS] = where;
- else {
- if (game.place[object] == CARRIED)
- --game.holdng;
- game.place[object] = where;
- }
- if (where <= 0)
- return;
- game.link[object] = game.atloc[where];
- game.atloc[where] = object;
-}
-
-long atdwrf(long where)
-/* Return the index of first dwarf at the given location, zero if no dwarf is
- * there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore
- * the pirate (6th dwarf). */
-{
- long at;
-
- at = 0;
- if (game.dflag < 2)
- return (at);
- at = -1;
- for (long i = 1; i <= NDWARVES - 1; i++) {
- if (game.dloc[i] == where)
- return i;
- if (game.dloc[i] != 0)
- at = 0;
- }
- return (at);
+static int get_motion_vocab_id(const char *word) {
+ // Return the first motion number that has 'word' as one of its words.
+ for (int i = 0; i < NMOTIONS; ++i) {
+ for (int j = 0; j < motions[i].words.n; ++j) {
+ if (strncasecmp(word, motions[i].words.strs[j],
+ TOKLEN) == 0 &&
+ (strlen(word) > 1 ||
+ strchr(ignore, word[0]) == NULL ||
+ !settings.oldstyle))
+ return (i);
+ }
+ }
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
+}
+
+static int get_object_vocab_id(const char *word) {
+ // Return the first object number that has 'word' as one of its words.
+ for (int i = 0; i < NOBJECTS + 1;
+ ++i) { // FIXME: the + 1 should go when 1-indexing for objects is
+ // removed
+ for (int j = 0; j < objects[i].words.n; ++j) {
+ if (strncasecmp(word, objects[i].words.strs[j],
+ TOKLEN) == 0)
+ return (i);
+ }
+ }
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);
+}
+
+static int get_action_vocab_id(const char *word) {
+ // Return the first motion number that has 'word' as one of its words.
+ for (int i = 0; i < NACTIONS; ++i) {
+ for (int j = 0; j < actions[i].words.n; ++j) {
+ if (strncasecmp(word, actions[i].words.strs[j],
+ TOKLEN) == 0 &&
+ (strlen(word) > 1 ||
+ strchr(ignore, word[0]) == NULL ||
+ !settings.oldstyle)) {
+ return (i);
+ }
+ }
+ }
+ // If execution reaches here, we didn't find the word.
+ return (WORD_NOT_FOUND);