refactored fallback_handler() to use command_t, isolating from side effects
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index 0c2a5439edf9aec4ab7492d0a83526e3326e3072..e9d833e30ef3d547bd741ff927f4fba104282316 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -328,11 +328,12 @@ char* get_input()
 
         if (input == NULL) // Got EOF; return with it.
             return (input);
-        else if (input[0] == '#') { // Ignore comments.
+        if (input[0] == '#') { // Ignore comments.
             free(input);
             continue;
-        } else // We have a 'normal' line; leave the loop.
-            break;
+        }
+        // We have a 'normal' line; leave the loop.
+        break;
     }
 
     // Strip trailing newlines from the input
@@ -351,7 +352,7 @@ char* get_input()
 
 bool silent_yes()
 {
-    bool outcome;
+    bool outcome = false;
 
     for (;;) {
         char* reply = get_input();
@@ -362,6 +363,11 @@ bool silent_yes()
             exit(EXIT_SUCCESS);
             // LCOV_EXCL_STOP
         }
+        if (strlen(reply) == 0) {
+            free(reply);
+            rspeak(PLEASE_ANSWER);
+            continue;
+        }
 
         char* firstword = (char*) xmalloc(strlen(reply) + 1);
         sscanf(reply, "%s", firstword);
@@ -397,7 +403,7 @@ 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. */
 {
-    bool outcome;
+    bool outcome = false;
 
     for (;;) {
         speak(question);
@@ -411,6 +417,12 @@ bool yes(const char* question, const char* yes_response, const char* no_response
             // LCOV_EXCL_STOP
         }
 
+        if (strlen(reply) == 0) {
+            free(reply);
+            rspeak(PLEASE_ANSWER);
+            continue;
+        }
+
         char* firstword = (char*) xmalloc(strlen(reply) + 1);
         sscanf(reply, "%s", firstword);
 
@@ -559,7 +571,8 @@ void move(obj_t object, loc_t where)
         from = game.fixed[object - NOBJECTS];
     else
         from = game.place[object];
-    if (from != LOC_NOWHERE && from != CARRIED && !SPECIAL(from))
+    /* (ESR) Used to check for !SPECIAL(from). I *think* that was wrong... */
+    if (from != LOC_NOWHERE && from != CARRIED)
         carry(object, from);
     drop(object, where);
 }