Parse and apply environment variables
This commit is contained in:
parent
fb3610c4d5
commit
8b8f6a2b3f
|
@ -89,3 +89,38 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc
|
|||
|
||||
return GARGOYLE_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
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) {
|
||||
if(flags & GARGOYLE_FLG_BCASE) {
|
||||
flags |= GARGOYLE_FLG_ICASE;
|
||||
}
|
||||
|
||||
for(; **envh; *envh += 1) {
|
||||
const char *var = **envh;
|
||||
|
||||
if(!gargoyle_cmp(prefix, var, prefix_sz, flags) || *(var + prefix_sz) != '_') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *brand = var + prefix_sz + 1;
|
||||
struct gargoyle_opt *opt = gargoyle_find_brand(optc, optv, brand, "NO_", 3, flags);
|
||||
|
||||
if(!opt) {
|
||||
if(flags & GARGOYLE_FLG_STRCT) {
|
||||
return GARGOYLE_ERR_UNKNOWN_OPT;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t res = 0;
|
||||
|
||||
if(opt->type & GARGOYLE_TYPE_BOOL) {
|
||||
res = gargoyle_from_bool(opt, brand, "NO_", 3, flags);
|
||||
} else {
|
||||
res = gargoyle_from_rope(opt, brand + opt->brand_sz + 1, flags);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue