Read string values from the command line into desired variables

This commit is contained in:
Nick Chambers 2022-06-22 16:45:57 -05:00
parent a1f9b3a9b8
commit 8ea191c696
4 changed files with 22 additions and 1 deletions

View File

@ -13,7 +13,8 @@ struct gargoyle_opt {
};
#define GARGOYLE_MK_OPT(brand) brand, (sizeof(brand) - 1)
#define GARGOYLE_EZ_OPT(brand, val) brand, (sizeof(brand) - 1), 0[brand], &val, sizeof(val)
#define GARGOYLE_EZ_OPT(brand, val) GARGOYLE_MK_OPT(brand), 0[brand], &val, sizeof(val)
#define GARGOYLE_CS_OPT(brand, val) GARGOYLE_MK_OPT(brand), 0[brand], &val[0], sizeof(val)
struct gargoyle_opt *gargoyle_find_brand(uint16_t optc, struct gargoyle_opt *optv, const char *brand);
struct gargoyle_opt *gargoyle_find_emblem(uint16_t optc, struct gargoyle_opt *optv, const char emblem);

View File

@ -8,5 +8,6 @@ static const uint8_t GARGOYLE_CMP_SYMBL = 1 << 1;
static const uint8_t GARGOYLE_CMP_FLXBL = GARGOYLE_CMP_ICASE | GARGOYLE_CMP_SYMBL;
uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, uint8_t flags);
char *gargoyle_cpy(char *dst, const char *src, uint16_t len);
#endif

View File

@ -29,6 +29,10 @@ uint8_t gargoyle_from_rope(struct gargoyle_opt *opt, const char *brand) {
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;

View File

@ -22,3 +22,18 @@ uint8_t gargoyle_cmp(const char *s1, const char *s2, uint16_t len, uint8_t flags
return 1;
}
char *gargoyle_cpy(char *dst, const char *src, uint16_t len) {
uint16_t idx = 1;
for(; len; dst += 1, len -= 1, idx += 1) {
if(*src) {
*dst = *src;
src += 1;
} else {
*dst = '\0';
}
}
return dst;
}