From f97be5af3b0886a550009c2bb68270805bba7b1b Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Thu, 30 Jun 2022 01:21:42 -0500 Subject: [PATCH] Add support for signed integers --- include/gargoyle/codex.h | 10 ++++++---- src/scribe.c | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/gargoyle/codex.h b/include/gargoyle/codex.h index cc3eba2..cb0ec3a 100644 --- a/include/gargoyle/codex.h +++ b/include/gargoyle/codex.h @@ -7,8 +7,9 @@ typedef uint8_t gargoyle_opt_type; static const gargoyle_opt_type GARGOYLE_TYPE_BOOL = 1 << 0; static const gargoyle_opt_type GARGOYLE_TYPE_UINT = 1 << 1; -static const gargoyle_opt_type GARGOYLE_TYPE_DBLE = 1 << 2; -static const gargoyle_opt_type GARGOYLE_TYPE_ROPE = 1 << 3; +static const gargoyle_opt_type GARGOYLE_TYPE_SINT = 1 << 2; +static const gargoyle_opt_type GARGOYLE_TYPE_DBLE = 1 << 3; +static const gargoyle_opt_type GARGOYLE_TYPE_ROPE = 1 << 4; typedef uint8_t gargoyle_err_type; @@ -16,8 +17,9 @@ static const gargoyle_err_type GARGOYLE_ERR_SUCCESS = 1 << 0; static const gargoyle_err_type GARGOYLE_ERR_UNKNOWN_OPT = 1 << 1; static const gargoyle_err_type GARGOYLE_ERR_VALUE_REQUIRED = 1 << 2; static const gargoyle_err_type GARGOYLE_ERR_INVALID_UINT = 1 << 3; -static const gargoyle_err_type GARGOYLE_ERR_INVALID_DBLE = 1 << 4; -static const gargoyle_err_type GARGOYLE_ERR_UNKNOWN_TYPE = 1 << 5; +static const gargoyle_err_type GARGOYLE_ERR_INVALID_SINT = 1 << 4; +static const gargoyle_err_type GARGOYLE_ERR_INVALID_DBLE = 1 << 5; +static const gargoyle_err_type GARGOYLE_ERR_UNKNOWN_TYPE = 1 << 6; typedef uint8_t gargoyle_flag_type; diff --git a/src/scribe.c b/src/scribe.c index a10502e..1c55aa4 100644 --- a/src/scribe.c +++ b/src/scribe.c @@ -21,6 +21,14 @@ uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand_val, garg if(*end) { return GARGOYLE_ERR_INVALID_UINT; } + } else if(opt->type & GARGOYLE_TYPE_SINT) { + char *end = NULL; + int64_t *val = opt->val; + *val = strtoll(brand_val, &end, 10); + + if(*end) { + return GARGOYLE_ERR_INVALID_SINT; + } } else if(opt->type & GARGOYLE_TYPE_DBLE) { char *end = NULL; double *val = opt->val;