diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-03-29 12:40:07 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-29 15:39:34 -0700 |
commit | 97bf36c9d3ad3d96ad6dea7cd6e6f3e164297c43 (patch) | |
tree | 5d4ba65334beb071e4cc09d8a404e859bca398ac /include/util.h | |
parent | c317992194ea089a97c4d54ef77ff4b1e283c248 (diff) | |
download | chrome-ec-97bf36c9d3ad3d96ad6dea7cd6e6f3e164297c43.tar.gz |
Add parse_bool() to centralize parsing boolean options
This way debug commands which previously took only yes/no or on/off or
enable/disable can take any of those options.
BUG=chrome-os-partner:18467
BRANCH=none
TEST=Try "on", "off", "yes", "no", "true", "false", "ena", "disable", for
each of the following commands:
- ilim (spring)
- pll (link)
- power (spring/snow)
- hcdebug (all)
- kblog (link)
- ksscan (all)
- lp5562 (spring)
Change-Id: Ie8e0fae3775b1da711864bcba6682ba5e68a06f1
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/46900
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'include/util.h')
-rw-r--r-- | include/util.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h index eca264a3f7..c953e468f8 100644 --- a/include/util.h +++ b/include/util.h @@ -84,6 +84,25 @@ int strtoi(const char *nptr, char **endptr, int base); /* Like strncpy(), but guarantees null termination. */ char *strzcpy(char *dest, const char *src, int len); +/** + * Parses a boolean option from a string. + * + * Strings that set *dest=0 and return 1 (all case-insensitive): + * "off" + * "dis*" + * "n*" + * "f*" + * + * Strings that set *dest=1 and return 1 (all case-insensitive): + * "on" + * "ena*" + * "y*" + * "t*" + * + * Other strings return 0 and leave *dest unchanged. + */ +int parse_bool(const char *s, int *dest); + int tolower(int c); /* 64-bit divide-and-modulo. Does the equivalent of: |