Apply values to short options
This commit is contained in:
parent
4e10b72586
commit
fb3610c4d5
9 changed files with 31 additions and 19 deletions
|
@ -6,6 +6,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, gargoyle_flag_type flags);
|
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
|
#endif
|
||||||
|
|
|
@ -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_SYMBL = 1 << 3;
|
||||||
static const gargoyle_flag_type GARGOYLE_FLG_GREED = 1 << 4;
|
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_FILL0 = 1 << 5;
|
||||||
|
static const gargoyle_flag_type GARGOYLE_FLG_STRCT = 1 << 6;
|
||||||
|
|
||||||
static const gargoyle_flag_type GARGOYLE_FLG_FLXBL = GARGOYLE_FLG_BCASE |
|
static const gargoyle_flag_type GARGOYLE_FLG_FLXBL = GARGOYLE_FLG_BCASE |
|
||||||
GARGOYLE_FLG_ECASE |
|
GARGOYLE_FLG_ECASE |
|
||||||
|
|
|
@ -13,5 +13,6 @@ struct gargoyle_opt {
|
||||||
#define GARGOYLE_MK_OPT(brand) brand, (sizeof(brand) - 1)
|
#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_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_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
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <gargoyle/sleuth.h>
|
#include <gargoyle/sleuth.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
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);
|
uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand_val, gargoyle_flag_type flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <gargoyle/privledge.h>
|
#include <gargoyle/privledge.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
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);
|
struct gargoyle_opt *gargoyle_find_emblem(uint16_t optc, struct gargoyle_opt *optv, const char emblem, gargoyle_flag_type flags);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <gargoyle.h>
|
#include <gargoyle.h>
|
||||||
#include <gargoyle/scribe.h>
|
#include <gargoyle/scribe.h>
|
||||||
#include <gargoyle/sleuth.h>
|
#include <gargoyle/sleuth.h>
|
||||||
|
#include <gargoyle/twine.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, gargoyle_flag_type flags) {
|
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) == '-') {
|
if(*(arg + 1) == '-') {
|
||||||
const char *brand = arg + 2;
|
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) {
|
if(!opt) {
|
||||||
return GARGOYLE_ERR_UNKNOWN_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;
|
uint8_t res = 0;
|
||||||
|
|
||||||
if(opt->type & GARGOYLE_TYPE_BOOL) {
|
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) == '=') {
|
} else if(*(brand + opt->brand_sz) == '=') {
|
||||||
res = gargoyle_from_rope(opt, brand + opt->brand_sz + 1, flags);
|
res = gargoyle_from_rope(opt, brand + opt->brand_sz + 1, flags);
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,6 +63,23 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc
|
||||||
if(!opt) {
|
if(!opt) {
|
||||||
return GARGOYLE_ERR_UNKNOWN_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;
|
return GARGOYLE_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gargoyle_digest_envh(/* ... */) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#include <gargoyle/twine.h>
|
#include <gargoyle/twine.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
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) {
|
if(opt->val) {
|
||||||
uint8_t *val = opt->val;
|
uint8_t *val = opt->val;
|
||||||
*val = !gargoyle_cmp(brand, "no-", 3, flags);
|
*val = !gargoyle_cmp(brand, neg, neg_sz, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -4,15 +4,11 @@
|
||||||
#include <gargoyle/twine.h>
|
#include <gargoyle/twine.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
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) {
|
||||||
if(flags & GARGOYLE_FLG_BCASE) {
|
|
||||||
flags |= GARGOYLE_FLG_ICASE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(; optc; optc -= 1, optv += 1) {
|
for(; optc; optc -= 1, optv += 1) {
|
||||||
const char *idx = brand;
|
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;
|
idx += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ uint8_t is_sep(char tok) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t is_eql(char lhs, char rhs) {
|
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) {
|
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;
|
len -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return !len || *s1 == *s2;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type flags) {
|
char *gargoyle_cpy(char *dst, const char *src, uint16_t len, gargoyle_flag_type flags) {
|
||||||
|
|
Loading…
Reference in a new issue