jx_int_t parse_int(const char *fname, struct jx *spec, const char *key, jx_int_t default_value) { int found = 0; struct jx *val = jx_lookup_guard(spec, key, &found); int result = default_value; if(found) { if(jx_istype(val, JX_INTEGER)) { result = val->u.integer_value; } else { fatal("Value of %s for '%s' is not an integer.", key, fname); } } return result; }
int parse_boolean(const char *fname, struct jx *spec, const char *key, int default_value) { int found = 0; struct jx *val = jx_lookup_guard(spec, key, &found); int result = default_value; if(found) { if(jx_istype(val, JX_BOOLEAN)) { result = jx_istrue(val); } else { fatal("Value of %s for '%s' is not boolean.", key, fname); } } return result; }
char *parse_str(const char *fname, struct jx *spec, const char *key, const char *default_value) { int found = 0; struct jx *val = jx_lookup_guard(spec, key, &found); const char *result = default_value; if(found) { if(jx_istype(val, JX_STRING)) { result = val->u.string_value; } else { fatal("Value of %s for '%s' is not a string.", key, fname); } } if(result) { return xxstrdup(result); } else { return NULL; } }
struct jx * jx_lookup( struct jx *j, const char *key ) { return jx_lookup_guard(j, key, NULL); }