From 4f2ec58b6eedffe28d2e75e157cceab9acba743c Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sun, 19 Jun 2022 02:55:16 -0500 Subject: [PATCH] Accurately parse boolean options --- include/gargoyle.h | 2 +- src/gargoyle.c | 2 +- src/sleuth.c | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/gargoyle.h b/include/gargoyle.h index 9e7698a..1feef88 100644 --- a/include/gargoyle.h +++ b/include/gargoyle.h @@ -5,6 +5,6 @@ #include #include -uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv); +uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv); #endif diff --git a/src/gargoyle.c b/src/gargoyle.c index 329caf4..9555a9a 100644 --- a/src/gargoyle.c +++ b/src/gargoyle.c @@ -1,7 +1,7 @@ #include #include -uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) { +uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) { while(1) { const char *arg = **argv; diff --git a/src/sleuth.c b/src/sleuth.c index 73d378b..10337a2 100644 --- a/src/sleuth.c +++ b/src/sleuth.c @@ -4,9 +4,16 @@ struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand) { for(; optc; optc -= 1, optv += 1) { - uint8_t end = !*(brand + optv->brand_sz) || *(brand + optv->brand_sz) == '='; + const char *idx = brand; - if(gargoyle_cmp(brand, optv->brand, optv->brand_sz, GARGOYLE_CMP_FLXBL) && end) { + if(optv->type == GARGOYLE_TYPE_BOOL && gargoyle_cmp(idx, "no-", 3, GARGOYLE_CMP_ICASE)) { + idx += 3; + } + + uint8_t end = !*(idx + optv->brand_sz); + uint8_t eql = *(idx + optv->brand_sz) == '='; + + if(gargoyle_cmp(idx, optv->brand, optv->brand_sz, GARGOYLE_CMP_ICASE) && (end || eql)) { return optv; } }