From fb3610c4d5a513c846a58b1fbe07915036231f59 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Tue, 28 Jun 2022 20:24:07 -0500 Subject: [PATCH] Apply values to short options --- include/gargoyle.h | 2 +- include/gargoyle/codex.h | 1 + include/gargoyle/privledge.h | 1 + include/gargoyle/scribe.h | 2 +- include/gargoyle/sleuth.h | 2 +- src/gargoyle.c | 26 ++++++++++++++++++++------ src/scribe.c | 4 ++-- src/sleuth.c | 8 ++------ src/twine.c | 4 ++-- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/gargoyle.h b/include/gargoyle.h index 63bf53d..32c5730 100644 --- a/include/gargoyle.h +++ b/include/gargoyle.h @@ -6,6 +6,6 @@ #include uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, gargoyle_flag_type flags); -uint8_t gargoyle_digest_envh(/* ... */); +uint8_t gargoyle_digest_envh(uint16_t optc, struct gargoyle_opt *optv, const char *prefix, uint16_t prefix_sz, char ***envh, gargoyle_flag_type flags); #endif diff --git a/include/gargoyle/codex.h b/include/gargoyle/codex.h index c2172f6..df459c4 100644 --- a/include/gargoyle/codex.h +++ b/include/gargoyle/codex.h @@ -23,6 +23,7 @@ static const gargoyle_flag_type GARGOYLE_FLG_ICASE = 1 << 2; static const gargoyle_flag_type GARGOYLE_FLG_SYMBL = 1 << 3; static const gargoyle_flag_type GARGOYLE_FLG_GREED = 1 << 4; static const gargoyle_flag_type GARGOYLE_FLG_FILL0 = 1 << 5; +static const gargoyle_flag_type GARGOYLE_FLG_STRCT = 1 << 6; static const gargoyle_flag_type GARGOYLE_FLG_FLXBL = GARGOYLE_FLG_BCASE | GARGOYLE_FLG_ECASE | diff --git a/include/gargoyle/privledge.h b/include/gargoyle/privledge.h index 559bae7..729a576 100644 --- a/include/gargoyle/privledge.h +++ b/include/gargoyle/privledge.h @@ -13,5 +13,6 @@ struct gargoyle_opt { #define GARGOYLE_MK_OPT(brand) brand, (sizeof(brand) - 1) #define GARGOYLE_EZ_OPT(brand, val) GARGOYLE_MK_OPT(brand), 0[brand], &val, sizeof(val) #define GARGOYLE_CS_OPT(brand, val) GARGOYLE_MK_OPT(brand), 0[brand], &val[0], sizeof(val) +#define GARGOYLE_EM_OPT(brand, emblem, val) GARGOYLE_MK_OPT(brand), emblem, &val, sizeof(val) #endif diff --git a/include/gargoyle/scribe.h b/include/gargoyle/scribe.h index f3e5fab..1984eca 100644 --- a/include/gargoyle/scribe.h +++ b/include/gargoyle/scribe.h @@ -4,7 +4,7 @@ #include #include -uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand, gargoyle_flag_type flags); +uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand, const char *neg, uint16_t neg_sz, gargoyle_flag_type flags); uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand_val, gargoyle_flag_type flags); #endif diff --git a/include/gargoyle/sleuth.h b/include/gargoyle/sleuth.h index d2bf636..4d5e805 100644 --- a/include/gargoyle/sleuth.h +++ b/include/gargoyle/sleuth.h @@ -5,7 +5,7 @@ #include #include -struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand, gargoyle_flag_type flags); +struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand, const char *neg, uint16_t neg_sz, gargoyle_flag_type flags); struct gargoyle_opt *gargoyle_find_emblem(uint16_t optc, struct gargoyle_opt *optv, const char emblem, gargoyle_flag_type flags); #endif diff --git a/src/gargoyle.c b/src/gargoyle.c index 36e8839..044fe0b 100644 --- a/src/gargoyle.c +++ b/src/gargoyle.c @@ -1,6 +1,7 @@ #include #include #include +#include #include uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, gargoyle_flag_type flags) { @@ -28,7 +29,7 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc if(*(arg + 1) == '-') { const char *brand = arg + 2; - opt = gargoyle_find_brand(optc, optv, brand, flags); + opt = gargoyle_find_brand(optc, optv, brand, "no-", 3, flags); if(!opt) { return GARGOYLE_ERR_UNKNOWN_OPT; @@ -37,7 +38,7 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc uint8_t res = 0; if(opt->type & GARGOYLE_TYPE_BOOL) { - res = gargoyle_from_bool(opt, brand, flags); + res = gargoyle_from_bool(opt, brand, "no-", 3, flags); } else if(*(brand + opt->brand_sz) == '=') { res = gargoyle_from_rope(opt, brand + opt->brand_sz + 1, flags); } else { @@ -62,6 +63,23 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc if(!opt) { return GARGOYLE_ERR_UNKNOWN_OPT; } + + uint8_t res = 0; + + if(opt->type & GARGOYLE_TYPE_BOOL) { + res = gargoyle_from_bool(opt, "", "*", 1, flags); + } else if(*(idx + 1)) { + res = gargoyle_from_rope(opt, idx + 1, flags); + break; + } else { + if(!*(*argv + 1)) { + return GARGOYLE_ERR_VALUE_REQUIRED; + } + + *argc -= 1; + *argv += 1; + res = gargoyle_from_rope(opt, **argv, flags); + } } } @@ -71,7 +89,3 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc return GARGOYLE_ERR_SUCCESS; } - -uint8_t gargoyle_digest_envh(/* ... */) { - return 0; -} diff --git a/src/scribe.c b/src/scribe.c index 4dfbeb4..661a5d4 100644 --- a/src/scribe.c +++ b/src/scribe.c @@ -3,10 +3,10 @@ #include #include -uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand, gargoyle_flag_type flags) { +uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand, const char *neg, uint16_t neg_sz, gargoyle_flag_type flags) { if(opt->val) { uint8_t *val = opt->val; - *val = !gargoyle_cmp(brand, "no-", 3, flags); + *val = !gargoyle_cmp(brand, neg, neg_sz, flags); } return 0; diff --git a/src/sleuth.c b/src/sleuth.c index 717352c..7c73598 100644 --- a/src/sleuth.c +++ b/src/sleuth.c @@ -4,15 +4,11 @@ #include #include -struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand, gargoyle_flag_type flags) { - if(flags & GARGOYLE_FLG_BCASE) { - flags |= GARGOYLE_FLG_ICASE; - } - +struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand, const char *neg, uint16_t neg_sz, gargoyle_flag_type flags) { for(; optc; optc -= 1, optv += 1) { const char *idx = brand; - if(optv->type & GARGOYLE_TYPE_BOOL && gargoyle_cmp(idx, "no-", 3, flags)) { + if(optv->type & GARGOYLE_TYPE_BOOL && gargoyle_cmp(idx, neg, neg_sz, flags)) { idx += 3; } diff --git a/src/twine.c b/src/twine.c index 45923e7..834284a 100644 --- a/src/twine.c +++ b/src/twine.c @@ -7,7 +7,7 @@ uint8_t is_sep(char tok) { } uint8_t is_eql(char lhs, char rhs) { - return lhs == rhs; + return tolower(lhs) == tolower(rhs); } uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag_type flags) { @@ -25,7 +25,7 @@ uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, gargoyle_flag len -= 1; } - return 1; + return !len || *s1 == *s2; } char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type flags) {