MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / cli_parse_bool

Function cli_parse_bool

cli/cli.c:2018–2032  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

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");

Callers

nothing calls this directly

Calls 1

clip_ieqFunction · 0.85

Tested by

no test coverage detected