* @brief Parse a string into a bool, accepting the common spellings. * * Recognises (case-insensitively) `true`/`false`, `yes`/`no`, `on`/`off`, and * `1`/`0`. Any other string is rejected (returns false) so a typo doesn't * silently become `false`. * * @param value Null-terminated string to parse. May be NULL (returns false). * @param out Receives the parsed value on success. Must not be
| 2016 | int ch; |
| 2017 | while ((ch = getchar()) != EOF && ch != '\n') { |
| 2018 | /* discard the rest of an over-long line */ |
| 2019 | } |
| 2020 | if (ch == EOF) { |
| 2021 | return false; |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | char* answer = response; |
| 2026 | while (*answer == ' ' || *answer == '\t') { |
| 2027 | answer++; |
| 2028 | } |
| 2029 | if (strcasecmp(answer, "y") == 0 || strcasecmp(answer, "yes") == 0) { |
| 2030 | return true; |
| 2031 | } |
| 2032 | if (strcasecmp(answer, "n") == 0 || strcasecmp(answer, "no") == 0) { |
| 2033 | return false; |
| 2034 | } |
| 2035 | printf("Invalid input. Please enter 'y' or 'n'.\n"); |
nothing calls this directly
no test coverage detected