X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=misc.c;h=25808a2c4353ff5a76f301603392e21a7f802f3d;hp=120a503351a0d899349d98c162dd7c0f35900866;hb=878efdddfbb1cd134c4ceed6cbc80e64aa43d2a5;hpb=a3c159660bb03f220b7de52ba0ac4977098f389e diff --git a/misc.c b/misc.c index 120a503..25808a2 100644 --- a/misc.c +++ b/misc.c @@ -386,17 +386,29 @@ static int get_action_vocab_id(const char* word) return (WORD_NOT_FOUND); } -static int get_special_vocab_id(const char* word) -// Return the first special number that has 'word' as one of its words. +static bool is_valid_int(const char *str) +/* Returns true if the string passed in is represents a valid integer, + * that could then be parsed by atoi() */ { - for (int i = 0; i < NSPECIALS; ++i) { - for (int j = 0; j < specials[i].words.n; ++j) { - if (strncasecmp(word, specials[i].words.strs[j], TOKLEN) == 0) - return (i); - } + // Handle negative number + if (*str == '-') + ++str; + + // Handle empty string or just "-". Should never reach this + // point, because this is only used with transitive verbs. + if (!*str) + return false; // LCOV_EXCL_LINE + + // Check for non-digit chars in the rest of the stirng. + while (*str) + { + if (!isdigit(*str)) + return false; + else + ++str; } - // If execution reaches here, we didn't find the word. - return (WORD_NOT_FOUND); + + return true; } static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* type) @@ -431,13 +443,6 @@ static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* typ return; } - ref_num = get_special_vocab_id(word); - if (ref_num != WORD_NOT_FOUND) { - *id = ref_num; - *type = SPECIAL; - return; - } - // Check for the reservoir magic word. if (strcasecmp(word, game.zzword) == 0) { *id = PART; @@ -445,6 +450,13 @@ static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* typ return; } + // Check words that are actually numbers. + if (is_valid_int(word)) { + *id = WORD_EMPTY; + *type = NUMERIC; + return; + } + *id = WORD_NOT_FOUND; *type = NO_WORD_TYPE; return; @@ -642,7 +654,7 @@ void set_seed(long seedval) game.zzword[5] = '\0'; } -unsigned long get_next_lcg_value(void) +static unsigned long get_next_lcg_value(void) /* Return the LCG's current value, and then iterate it. */ { unsigned long old_x = game.lcg_x;