MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / parse_reader_params

Function parse_reader_params

libCacheSim/bin/cli_reader_utils.c:88–187  ·  view source on GitHub ↗

* @brief parse the reader parameters * * @param reader_params_str * @param params */

Source from the content-addressed store, hash-verified

86 * @param params
87 */
88void parse_reader_params(const char *reader_params_str,
89 reader_init_param_t *params) {
90 params->delimiter = '\0';
91 params->obj_id_is_num = false;
92 params->obj_id_is_num_set = false;
93
94 if (reader_params_str == NULL) return;
95 char *params_str = strdup(reader_params_str);
96 char *old_params_str = params_str;
97 char *end;
98
99 while (params_str != NULL && params_str[0] != '\0') {
100 /* different parameters are separated by comma,
101 * key and value are separated by '=' */
102 char *key = strsep((char **)&params_str, "=");
103 char *value = strsep((char **)&params_str, ",");
104
105 // skip the white space and comma
106 while (params_str != NULL && (*params_str == ' ' || *params_str == ',')) {
107 params_str++;
108 }
109
110 key = replace_char(key, '_', '-');
111
112 if (strcasecmp(key, "time-col") == 0) {
113 params->time_field = (int)strtol(value, &end, 0);
114 _check_parsed_result(end, params->time_field);
115 } else if (strcasecmp(key, "obj-id-col") == 0) {
116 params->obj_id_field = (int)strtol(value, &end, 0);
117 _check_parsed_result(end, params->obj_id_field);
118 } else if (strcasecmp(key, "obj-size-col") == 0 ||
119 strcasecmp(key, "size-col") == 0) {
120 params->obj_size_field = (int)strtol(value, &end, 0);
121 _check_parsed_result(end, params->obj_size_field);
122 } else if (strcasecmp(key, "cnt-col") == 0) {
123 params->cnt_field = (int)strtol(value, &end, 0);
124 } else if (strcasecmp(key, "op-col") == 0) {
125 params->op_field = (int)strtol(value, &end, 0);
126 _check_parsed_result(end, params->op_field);
127 } else if (strcasecmp(key, "tenant-col") == 0) {
128 params->tenant_field = (int)(strtol(value, &end, 0));
129 _check_parsed_result(end, params->tenant_field);
130 } else if (strcasecmp(key, "feature-cols") == 0) {
131 // feature-cols=1|2|3
132 char *feature_str = strdup(value);
133 char *feature = strsep(&feature_str, "|");
134 int i = 0;
135 while (feature != NULL) {
136 params->feature_fields[i] = (int)strtol(feature, &end, 0);
137 _check_parsed_result(end, params->feature_fields[i]);
138 i++;
139 feature = strsep(&feature_str, ",");
140 }
141 params->n_feature_fields = i;
142 } else if (strcasecmp(key, "ttl-col") == 0) {
143 params->ttl_field = (int)strtol(value, &end, 0);
144 _check_parsed_result(end, params->ttl_field);
145 } else if (strcasecmp(key, "obj-id-is-num") == 0) {

Callers 6

create_readerFunction · 0.85
parse_cmdFunction · 0.85
parse_mini_cmdFunction · 0.85
parse_mrc_cmdFunction · 0.85
parse_cmdFunction · 0.85
parse_cmdFunction · 0.85

Calls 3

replace_charFunction · 0.85
_check_parsed_resultFunction · 0.85
is_trueFunction · 0.85

Tested by

no test coverage detected