Properly toggle boolean flag values
This commit is contained in:
parent
b39e377f4f
commit
624646663d
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
||||||
CFLAGS ?= -Wall -Wextra -g -O1 -fpic
|
CFLAGS ?= -Wall -Wextra -g -O1 -fpic
|
||||||
LDFLAGS ?= -g -O1 -shared
|
LDFLAGS ?= -g -O1 -shared
|
||||||
GARGOYLE_OBJS := gargoyle sleuth twine
|
GARGOYLE_OBJS := gargoyle sleuth twine scribe
|
||||||
|
|
||||||
.PHONY: all gargoyle init docs test clean
|
.PHONY: all gargoyle init docs test clean
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define __GARGOYLE_H_
|
#define __GARGOYLE_H_
|
||||||
|
|
||||||
#include <gargoyle/codex.h>
|
#include <gargoyle/codex.h>
|
||||||
|
#include <gargoyle/scribe.h>
|
||||||
#include <gargoyle/sleuth.h>
|
#include <gargoyle/sleuth.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
|
@ -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_SUCCESS = 0;
|
||||||
static const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1;
|
static const uint8_t GARGOYLE_ERR_UNKNOWN_OPT = 1;
|
||||||
|
static const uint8_t GARGOYLE_ERR_VALUE_REQUIRED = 2;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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
|
|
@ -21,11 +21,32 @@ uint8_t gargoyle_digest_args(uint16_t optc, struct gargoyle_opt *optv, int *argc
|
||||||
struct gargoyle_opt *opt = NULL;
|
struct gargoyle_opt *opt = NULL;
|
||||||
|
|
||||||
if(*(arg + 1) == '-') {
|
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) {
|
if(!opt) {
|
||||||
return GARGOYLE_ERR_UNKNOWN_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 {
|
} else {
|
||||||
const char *idx = arg + 1;
|
const char *idx = arg + 1;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue