X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=cef36519e82e5d9d250da92e4784373b234f8461;hb=2bdf9e2803c83d19f375d97dd8147e8d221ec057;hp=0c2a5439edf9aec4ab7492d0a83526e3326e3072;hpb=ca7ac4063f162290491c68124a13d75f2f5c010a;p=open-adventure.git diff --git a/misc.c b/misc.c index 0c2a543..cef3651 100644 --- 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);