diff --git a/Makefile b/Makefile index d35a504..14f5d00 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CFLAGS ?= -Wall -Wextra -g -O1 -fpic LDFLAGS ?= -g -O1 -shared -GARGOYLE_OBJS := gargoyle sleuth twine +GARGOYLE_OBJS := gargoyle sleuth twine scribe .PHONY: all gargoyle init docs test clean diff --git a/include/gargoyle.h b/include/gargoyle.h index 85024be..2ecb121 100644 --- a/include/gargoyle.h +++ b/include/gargoyle.h @@ -2,6 +2,7 @@ #define __GARGOYLE_H_ #include +#include #include #include diff --git a/include/gargoyle/codex.h b/include/gargoyle/codex.h index e5ecd01..0d09ba1 100644 --- a/include/gargoyle/codex.h +++ b/include/gargoyle/codex.h @@ -11,5 +11,6 @@ static const uint8_t GARGOYLE_TYPE_DBLE = 1 << 4; static const uint8_t GARGOYLE_ERR_SUCCESS = 0; static const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1; +static const uint8_t GARGOYLE_ERR_VALUE_REQUIRED = 2; #endif diff --git a/include/gargoyle/scribe.h b/include/gargoyle/scribe.h new file mode 100644 index 0000000..eb921fb --- /dev/null +++ b/include/gargoyle/scribe.h @@ -0,0 +1,10 @@ +#ifndef __GARGOYLE_SCRIBE_H_ +#define __GARGOYLE_SCRIBE_H_ + +#include +#include + +uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand); +uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand); + +#endif diff --git a/src/gargoyle.c b/src/gargoyle.c index 5609abd..2147a4a 100644 --- a/src/gargoyle.c +++ b/src/gargoyle.c @@ -21,11 +21,32 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc struct gargoyle_opt *opt = NULL; if(*(arg + 1) == '-') { - opt = gargoyle_find_brand(optc, optv, arg + 2); + const char *brand = arg + 2; + opt = gargoyle_find_brand(optc, optv, brand); if(!opt) { return GARGOYLE_ERR_UNKNOWN_OPT; } + + uint8_t res = 0; + + if(opt->type & GARGOYLE_TYPE_BOOL) { + res = gargoyle_from_bool(opt, brand); + } else if(*(brand + opt->brand_sz) == '=') { + res = gargoyle_from_rope(opt, brand + opt->brand_sz); + } else { + if(!(*argv + 1)) { + return GARGOYLE_ERR_VALUE_REQUIRED; + } + + *argc -= 1; + *argv += 1; + res = gargoyle_from_rope(opt, **argv); + } + + if(res) { + return res; + } } else { const char *idx = arg + 1; diff --git a/src/scribe.c b/src/scribe.c new file mode 100644 index 0000000..4701faf --- /dev/null +++ b/src/scribe.c @@ -0,0 +1,16 @@ +#include +#include +#include + +uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand) { + if(opt->val) { + uint8_t *val = opt->val; + *val = !gargoyle_cmp(brand, "no-", 3, GARGOYLE_CMP_ICASE); + } + + return 0; +} + +uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand) { + return 0; +}