Accurately parse boolean options
This commit is contained in:
parent
9a8e74cb0d
commit
4f2ec58b6e
3 changed files with 11 additions and 4 deletions
|
@ -5,6 +5,6 @@
|
||||||
#include <gargoyle/sleuth.h>
|
#include <gargoyle/sleuth.h>
|
||||||
#include <stdint.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
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <gargoyle.h>
|
#include <gargoyle.h>
|
||||||
#include <stddef.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) {
|
while(1) {
|
||||||
const char *arg = **argv;
|
const char *arg = **argv;
|
||||||
|
|
||||||
|
|
11
src/sleuth.c
11
src/sleuth.c
|
@ -4,9 +4,16 @@
|
||||||
|
|
||||||
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand) {
|
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand) {
|
||||||
for(; optc; optc -= 1, optv += 1) {
|
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;
|
return optv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue