Skip to content

Commit

Permalink
more mcmc changes
Browse files Browse the repository at this point in the history
should have all of the accessors now
  • Loading branch information
dormando committed Aug 6, 2024
1 parent be0ba7f commit 28a05ad
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions vendor/mcmc/mcmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,26 +670,41 @@ const char *mcmc_token_get_flag(const char *l, mcmc_tokenizer_t *t, char flag, i
return NULL;
}

// TODO: once tested, turn to macro for u64/32/64
int mcmc_token_get_flag_u32(const char *l, mcmc_tokenizer_t *t, char flag, uint32_t *val) {
for (int x = t->mstart; x < t->ntokens; x++) {
const char *tflag = l + t->tokens[x];
if (tflag[0] == flag) {
int tlen = _mcmc_token_len(l, t, x);
return mcmc_toktou32(tflag+1, tlen-1, val);
}
int tlen = 0;
const char *tok = mcmc_token_get_flag(l, t, flag, &tlen);
if (tok) {
return mcmc_toktou32(tok, tlen, val);
}

return MCMC_NOK;
}

int mcmc_token_get_flag_u64(const char *l, mcmc_tokenizer_t *t, char flag, uint64_t *val) {
int tlen = 0;
const char *tok = mcmc_token_get_flag(l, t, flag, &tlen);
if (tok) {
return mcmc_toktou64(tok, tlen, val);
}

return MCMC_NOK;
}

int mcmc_token_get_flag_32(const char *l, mcmc_tokenizer_t *t, char flag, int32_t *val) {
int tlen = 0;
const char *tok = mcmc_token_get_flag(l, t, flag, &tlen);
if (tok) {
return mcmc_tokto32(tok, tlen, val);
}

return MCMC_NOK;
}

int mcmc_token_get_flag_64(const char *l, mcmc_tokenizer_t *t, char flag, int64_t *val) {
for (int x = t->mstart; x < t->ntokens; x++) {
const char *tflag = l + t->tokens[x];
if (tflag[0] == flag) {
int tlen = _mcmc_token_len(l, t, x);
return mcmc_tokto64(tflag+1, tlen-1, val);
}
int tlen = 0;
const char *tok = mcmc_token_get_flag(l, t, flag, &tlen);
if (tok) {
return mcmc_tokto64(tok, tlen, val);
}

return MCMC_NOK;
Expand Down

0 comments on commit 28a05ad

Please sign in to comment.