Use YAML block-literal syntax to avoid wrapped lines.
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index 0d2311c945318805be770491ae9890b035d535ce..cd1b5bf1f94d487c7996b7fb0d90b29b7c2ee050 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -243,6 +243,11 @@ void vspeak(const char* msg, va_list ap)
     }
     *renderp = 0;
 
+    // Deal with messages that are in YAML block format and therefore
+    // have their own trailing \n
+    if (renderp > rendered && renderp[-1] == '\n')
+       *--renderp = '\0';
+    
     // Print the message.
     printf("%s\n", rendered);
 
@@ -351,9 +356,10 @@ char* get_input()
 
         if (input == NULL) // Got EOF; return with it.
             return (input);
-        else if (input[0] == '#') // Ignore comments.
+        else if (input[0] == '#') { // Ignore comments.
+            linenoiseFree(input);
             continue;
-        else // We have a 'normal' line; leave the loop.
+        else // We have a 'normal' line; leave the loop.
             break;
     }
 
@@ -389,6 +395,8 @@ bool silent_yes()
         char* firstword = (char*) xmalloc(strlen(reply) + 1);
         sscanf(reply, "%s", firstword);
 
+        linenoiseFree(reply);
+
         for (int i = 0; i < (int)strlen(firstword); ++i)
             firstword[i] = tolower(firstword[i]);
 
@@ -408,7 +416,6 @@ bool silent_yes()
         } else
             rspeak(PLEASE_ANSWER);
     }
-    linenoiseFree(reply);
     return (outcome);
 }
 
@@ -435,6 +442,8 @@ bool yes(const char* question, const char* yes_response, const char* no_response
         char* firstword = (char*) xmalloc(strlen(reply) + 1);
         sscanf(reply, "%s", firstword);
 
+        linenoiseFree(reply);
+
         for (int i = 0; i < (int)strlen(firstword); ++i)
             firstword[i] = tolower(firstword[i]);
 
@@ -455,8 +464,9 @@ bool yes(const char* question, const char* yes_response, const char* no_response
             break;
         } else
             rspeak(PLEASE_ANSWER);
+
     }
-    linenoiseFree(reply);
+
     return (outcome);
 }