X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=cef36519e82e5d9d250da92e4784373b234f8461;hb=2bdf9e2803c83d19f375d97dd8147e8d221ec057;hp=be2599098d70d5398e12934485ab982299e8b87d;hpb=73608b6307938818e32c57ae2eb536e19b10480e;p=open-adventure.git diff --git a/misc.c b/misc.c index be25990..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); @@ -607,7 +619,8 @@ void drop(obj_t object, loc_t where) --game.holdng; game.place[object] = where; } - if (where <= 0) + if (where == LOC_NOWHERE || + where == CARRIED) return; game.link[object] = game.atloc[where]; game.atloc[where] = object;