40 lines
931 B
C
40 lines
931 B
C
#include <gargoyle/codex.h>
|
|
#include <gargoyle/scribe.h>
|
|
#include <gargoyle/twine.h>
|
|
#include <stdlib.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) {
|
|
if(opt->type & GARGOYLE_TYPE_UINT) {
|
|
char *end = NULL;
|
|
uint64_t *val = opt->val;
|
|
*val = strtoull(brand, &end, 10);
|
|
|
|
if(*end) {
|
|
return GARGOYLE_ERR_INVALID_UINT;
|
|
}
|
|
} else if(opt->type & GARGOYLE_TYPE_DBLE) {
|
|
char *end = NULL;
|
|
double *val = opt->val;
|
|
*val = strtod(brand, &end);
|
|
|
|
if(*end) {
|
|
return GARGOYLE_ERR_INVALID_DBLE;
|
|
}
|
|
} else if(opt->type & GARGOYLE_TYPE_ROPE) {
|
|
char *val = opt->val;
|
|
char *end = gargoyle_cpy(val, brand, opt->val_sz - 1);
|
|
*end = '\0';
|
|
}
|
|
|
|
return 0;
|
|
}
|