Fix to Gitlab issue #32. Now SEED and WASTE are in adventure.yaml
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index 120a503351a0d899349d98c162dd7c0f35900866..2fe1363826eef89a4b85a76c0667a210cb6d936e 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -399,6 +399,30 @@ static int get_special_vocab_id(const char* word)
     return (WORD_NOT_FOUND);
 }
 
+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() */
+{
+    // Handle negative number
+    if (*str == '-')
+        ++str;
+
+    // Handle empty string or just "-"
+    if (!*str)
+        return false;
+
+    // Check for non-digit chars in the rest of the stirng.
+    while (*str)
+    {
+        if (!isdigit(*str))
+            return false;
+        else
+            ++str;
+    }
+
+    return true;
+}
+
 static void get_vocab_metadata(const char* word, vocab_t* id, enum wordtype* type)
 {
     /* Check for an empty string */
@@ -445,6 +469,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;