Properly toggle boolean flag values

This commit is contained in:
Nick Chambers 2022-06-19 20:30:01 -05:00
parent b39e377f4f
commit 624646663d
6 changed files with 51 additions and 2 deletions

View File

@ -1,6 +1,6 @@
CFLAGS ?= -Wall -Wextra -g -O1 -fpic
LDFLAGS ?= -g -O1 -shared
GARGOYLE_OBJS := gargoyle sleuth twine
GARGOYLE_OBJS := gargoyle sleuth twine scribe
.PHONY: all gargoyle init docs test clean

View File

@ -2,6 +2,7 @@
#define __GARGOYLE_H_
#include <gargoyle/codex.h>
#include <gargoyle/scribe.h>
#include <gargoyle/sleuth.h>
#include <stdint.h>

View File

@ -11,5 +11,6 @@ static const uint8_t GARGOYLE_TYPE_DBLE = 1 << 4;
static const uint8_t GARGOYLE_ERR_SUCCESS = 0;
static const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1;
static const uint8_t GARGOYLE_ERR_VALUE_REQUIRED = 2;
#endif

10
include/gargoyle/scribe.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __GARGOYLE_SCRIBE_H_
#define __GARGOYLE_SCRIBE_H_
#include <gargoyle/sleuth.h>
#include <stdint.h>
uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand);
uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand);
#endif

View File

@ -21,11 +21,32 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc
struct gargoyle_opt *opt = NULL;
if(*(arg + 1) == '-') {
opt = gargoyle_find_brand(optc, optv, arg + 2);
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);
} 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;

16
src/scribe.c Normal file
View File

@ -0,0 +1,16 @@
#include <gargoyle/codex.h>
#include <gargoyle/scribe.h>
#include <gargoyle/twine.h>
uint8_t gargoyle_from_bool(struct gargoyle_opt *opt, const char *brand) {
if(opt->val) {
uint8_t *val = opt->val;
*val = !gargoyle_cmp(brand, "no-", 3, GARGOYLE_CMP_ICASE);
}
return 0;
}
uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand) {
return 0;
}