Accurately parse boolean options

This commit is contained in:
Nick Chambers 2022-06-19 02:55:16 -05:00
parent 9a8e74cb0d
commit 4f2ec58b6e
3 changed files with 11 additions and 4 deletions

View File

@ -5,6 +5,6 @@
#include <gargoyle/sleuth.h>
#include <stdint.h>
uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv);
uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv);
#endif

View File

@ -1,7 +1,7 @@
#include <gargoyle.h>
#include <stddef.h>
uint8_t gargoyle_digest(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) {
uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc, char ***argv) {
while(1) {
const char *arg = **argv;

View File

@ -4,9 +4,16 @@
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand) {
for(; optc; optc -= 1, optv += 1) {
uint8_t end = !*(brand + optv->brand_sz) || *(brand + optv->brand_sz) == '=';
const char *idx = brand;
if(gargoyle_cmp(brand, optv->brand, optv->brand_sz, GARGOYLE_CMP_FLXBL) && end) {
if(optv->type == GARGOYLE_TYPE_BOOL && gargoyle_cmp(idx, "no-", 3, GARGOYLE_CMP_ICASE)) {
idx += 3;
}
uint8_t end = !*(idx + optv->brand_sz);
uint8_t eql = *(idx + optv->brand_sz) == '=';
if(gargoyle_cmp(idx, optv->brand, optv->brand_sz, GARGOYLE_CMP_ICASE) && (end || eql)) {
return optv;
}
}