From: Nguyễn Thái Ngọc Duy Date: Fri, 03 Feb 2012 13:34:28 GMT Subject: [PATCH v4 03/13] parseopt: make OPT_INTEGER support hexadecimal as well Message-ID: <1328276078-27955-4-git-send-email-pclouds@gmail.com> In-Reply-To: <1328276078-27955-1-git-send-email-pclouds@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy --- parse-options.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/parse-options.c b/parse-options.c index f0098eb..7c9109d 100644 --- a/parse-options.c +++ b/parse-options.c @@ -139,7 +139,10 @@ static int get_value(struct parse_opt_ctx_t *p, } if (get_arg(p, opt, flags, &arg)) return -1; - *(int *)opt->value = strtol(arg, (char **)&s, 10); + if (!prefixcmp(arg, "0x") || !prefixcmp(arg, "0X")) + *(int *)opt->value = strtol(arg + 2, (char **)&s, 16); + else + *(int *)opt->value = strtol(arg, (char **)&s, 10); if (*s) return opterror(opt, "expects a numerical value", flags); return 0; -- 1.7.8.36.g69ee2