X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=misc.c;h=e9d833e30ef3d547bd741ff927f4fba104282316;hp=be2599098d70d5398e12934485ab982299e8b87d;hb=9056fa7a2c429bef0b5abca1f7f0f9bbecefd4b6;hpb=73608b6307938818e32c57ae2eb536e19b10480e diff --git a/misc.c b/misc.c index be25990..e9d833e 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); @@ -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); } @@ -607,7 +620,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;