#include #include uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv, uint8_t flags) { if(!(flags & GARGOYLE_DIGEST_ALL)) { *argc -= 1; *argv += 1; } while(1) { const char *arg = **argv; if(!arg || *arg != '-' || !*(arg + 1)) { return GARGOYLE_ERR_SUCCESS; } else if(*arg == '-' && *(arg + 1) == '-' && !*(arg + 2)) { *argc -= 1; *argv += 1; return GARGOYLE_ERR_SUCCESS; } struct gargoyle_opt *opt = NULL; if(*(arg + 1) == '-') { 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 + 1); } 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; for(; *idx; idx += 1) { opt = gargoyle_find_emblem(optc, optv, *idx); if(!opt) { return GARGOYLE_ERR_UNKNOWN_OPT; } } } *argc -= 1; *argv += 1; } return GARGOYLE_ERR_SUCCESS; }