/* * clo_parse_ranges -- (internal) parse ranges/values separated by commas */ static int clo_parse_ranges(struct benchmark_clo *clo, const char *arg, struct clo_vec *clovec, clo_parse_single_fn parse_single, clo_eval_range_fn eval_range) { struct clo_vec_vlist *vlist = clo_vec_vlist_alloc(); assert(vlist != NULL); int ret = 0; char *args = strdup(arg); assert(args != NULL); char *curr = args; char *next; /* iterate through all values separated by comma */ while ((next = strchr(curr, ',')) != NULL) { *next = '\0'; next++; /* parse each comma separated value as range or single value */ if ((ret = clo_parse_range(clo, curr, parse_single, eval_range, vlist))) goto out; curr = next; } /* parse each comma separated value as range or single value */ if ((ret = clo_parse_range(clo, curr, parse_single, eval_range, vlist))) goto out; /* add list of values to CLO vector */ ret = clo_vec_memcpy_list(clovec, clo->off, clo->type_uint.size, vlist); out: free(args); clo_vec_vlist_free(vlist); return ret; }
/* * clo_parse_str -- (internal) parse string value */ static int clo_parse_str(struct benchmark_clo *clo, const char *arg, struct clo_vec *clovec) { struct clo_vec_vlist *vlist = clo_vec_vlist_alloc(); assert(vlist != NULL); char *str = strdup(arg); assert(str != NULL); clo_vec_add_alloc(clovec, str); char *next = strtok(str, ","); while (next) { clo_vec_vlist_add(vlist, &next, sizeof(next)); next = strtok(NULL, ","); } int ret = clo_vec_memcpy_list(clovec, clo->off, sizeof(str), vlist); clo_vec_vlist_free(vlist); return ret; }