gargoyle/src/scribe.c

36 lines
783 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;
}
}
return 0;
}