Skip to content
Snippets Groups Projects
Commit f6d49cc7 authored by Jakob Olsson's avatar Jakob Olsson
Browse files

remove development debugging prints

parent 1dbdd943
Branches
No related tags found
No related merge requests found
......@@ -73,15 +73,12 @@ int get_idx(char *key, int *idx, char *out)
char buffer[64] = {0};
char *ptr;
printf("%s %d key=%s\n", __func__, __LINE__, key);
if(!key)
return -1;
strncpy(buffer, key, sizeof(buffer) - 1);
ptr = (char *)buffer;
printf("%s %d ptr=%s\n", __func__, __LINE__, ptr);
while((open_brace = strchr(ptr, '['))) {
char *close_brace = strchr(open_brace, ']');
......@@ -102,7 +99,7 @@ int get_idx(char *key, int *idx, char *out)
}
strncpy(out, buffer, 31);
printf("%s %d, out=%s, buffer=%s\n", __func__, __LINE__, out, buffer);
return len;
}
......@@ -145,7 +142,6 @@ int add_array(struct json_object *ptr, int *idx, int len, char *val, enum json_t
j_val = dummy_val(val, type);
if (!j_val)
return -1;
json_object_object_get_ex(ptr, key, &tmp);
if (!tmp || !json_object_is_type(tmp, json_type_array)) {
tmp = json_object_new_array();
......@@ -156,7 +152,6 @@ int add_array(struct json_object *ptr, int *idx, int len, char *val, enum json_t
struct json_object *tmp1;
tmp1 = json_object_array_get_idx(tmp, idx[i]);
printf("%s %d ptr = %s, tmp = %s\n", __func__, __LINE__, json_object_get_string(ptr), json_object_get_string(tmp));
if (i < len -1) {
if (!tmp1 || !json_object_is_type(tmp1, json_type_array)) {
tmp1 = json_object_new_array();
......@@ -167,7 +162,6 @@ int add_array(struct json_object *ptr, int *idx, int len, char *val, enum json_t
}
tmp = tmp1;
} else {
printf("%s %d ptr = %s, tmp = %s, tmp1=%s\n", __func__, __LINE__, json_object_get_string(ptr), json_object_get_string(tmp), json_object_get_string(tmp1));
if (idx[i] > -1)
json_object_array_put_idx(tmp, idx[i], j_val);
else
......@@ -176,9 +170,6 @@ int add_array(struct json_object *ptr, int *idx, int len, char *val, enum json_t
}
printf("%s %d ptr = %s, tmp = %s\n", __func__, __LINE__, json_object_get_string(ptr), json_object_get_string(tmp));
return 0;
}
......@@ -190,18 +181,13 @@ int add_val(struct json_object *ptr, char *key, char *val, enum json_type type)
char parsed_key[32] = {0};
len = get_idx(key, idx, parsed_key);
printf("%s %d parsed_key=%s\n", __func__, __LINE__, parsed_key);
j_val = dummy_val(val, type);
if (!j_val || !json_object_is_type(j_val, type)) {
fprintf(stderr, "Invalid input value!\n");
return -1;
}
printf("%s %d val=%s, j_val=%s, ptr=%s\n", __func__, __LINE__, val, json_object_get_string(j_val), json_object_get_string(ptr));
if (json_type_object == type) {
printf("%s %d\n", __func__, __LINE__);
/* TODO: does this actually work? what would be the test case for this? */
if (len < 1) {
struct json_object *tmp = ptr;
......@@ -211,18 +197,15 @@ int add_val(struct json_object *ptr, char *key, char *val, enum json_type type)
json_object_object_foreach(j_val, key1, val1)
json_object_object_add(ptr, key1, val1);
if (key) {
printf("%s %d\n", __func__, __LINE__);
json_object_object_add(tmp, parsed_key, ptr);
}
} else {
printf("%s %d\n", __func__, __LINE__);
add_array(ptr, idx, len, val, type, parsed_key);
}
return 0;
}
if (len < 1 || type == json_type_array)
json_object_object_add(ptr, parsed_key, j_val);
else {
......@@ -246,9 +229,6 @@ int set_by_string(struct json_object **src, char *fmt, char *val, enum json_type
*src = json_object_new_object();
}
printf("format = %s\n", fmt);
printf("set val = %s\n", val);
ptr = outer_obj = *src;
if (!fmt)
goto add_key;
......@@ -262,16 +242,10 @@ int set_by_string(struct json_object **src, char *fmt, char *val, enum json_type
/* if next key exists, parse key, let switch-case add/alter last key */
if (p) {
/* TODO: pretty wonky order with get idx first to overwrite braces?*/
memset(idx, 0, sizeof(idx));
len = get_idx(key, idx, parsed_key);
printf("parsed_key=%s\n", parsed_key);
printf("len=%d\n", len);
/* if we need to step further and currently marked value isnt an object, we need to overwrite it */
json_object_object_get_ex(outer_obj, parsed_key, &ptr);
if (!json_object_is_type(ptr, json_type_object) && !json_object_is_type(ptr, json_type_array)) {
......@@ -279,12 +253,9 @@ int set_by_string(struct json_object **src, char *fmt, char *val, enum json_type
json_object_object_add(outer_obj, parsed_key, ptr);
}
/* TODO: make enums for rv of get_idx */
if (len > 0) {
for (int i = 0; i < len; i++) {
printf("%s %d, ptr = %s\n", __func__, __LINE__, json_object_get_string(ptr));
if (ptr && json_object_get_type(ptr) == json_type_array) {
printf("%s %d\n", __func__, __LINE__);
if (idx[i] > -1 && idx[i] < json_object_array_length(ptr)) {
tmp = json_object_array_get_idx(ptr, idx[i]);
if (!json_object_is_type(tmp, json_type_object)) {
......@@ -298,27 +269,19 @@ int set_by_string(struct json_object **src, char *fmt, char *val, enum json_type
ptr = tmp;
}
else {
printf("%s %d\n", __func__, __LINE__);
if (i == len - 1)
json_object_array_add(ptr, json_object_new_object());
else if (i < len -1)
json_object_array_add(ptr, json_object_new_array());
printf("ptr=%s\n", json_object_get_string(ptr));
ptr = json_object_array_get_idx(ptr, json_object_array_length(ptr) - 1);
printf("ptr=%s\n", json_object_get_string(ptr));
}
} else {
ptr = json_object_new_array();
printf("%s %d type=%s, ptr_type=%s\n", __func__, __LINE__, json_type_to_name(json_object_get_type(outer_obj)), json_type_to_name(json_object_get_type(ptr)));
printf("outer_obj=%s\n", json_object_get_string(outer_obj));
printf("ptr=%s\n", json_object_get_string(ptr));
printf("key=%s\n", key);
json_object_object_add(outer_obj, parsed_key, ptr);
if (i == len - 1) {
json_object_array_add(ptr, json_object_new_object());
ptr = json_object_array_get_idx(ptr, json_object_array_length(ptr) - 1);
}
//json_object_array_add(outer_obj, ptr);
}
}
}
......@@ -330,18 +293,13 @@ int set_by_string(struct json_object **src, char *fmt, char *val, enum json_type
json_object_array_add(outer_obj, ptr);
else if (json_object_get_type(outer_obj) == json_type_object)
json_object_object_add(outer_obj, parsed_key, ptr);
printf("%s %d: ptr=%s\n", __func__, __LINE__, json_object_get_string(ptr));
printf("%s %d: outer_obj=%s\n", __func__, __LINE__, json_object_get_string(outer_obj));
}
}
outer_obj = ptr;
}
printf("%s %d key=%s\n", __func__, __LINE__, parsed_key);
add_key:
printf("%s %d\n", __func__, __LINE__);
add_val(ptr, key, val, type);
return 0;
......@@ -362,7 +320,6 @@ int set(struct json_object *src, char *fmt, struct json_object *val)
strcpy(fmt_cpy, fmt);
/* TODO: put this in some separate function */
for (p = strtok(fmt_cpy,delimiter); p != NULL; p = strtok(NULL, delimiter)) {
struct json_object *ptr, *tmp = src;
......@@ -396,15 +353,12 @@ struct json_object *get(struct json_object *src, char *fmt)
len = get_idx(key, idx, parsed_key);
json_object_object_get_ex(tmp, parsed_key, &ptr);
printf("%s %d ptr = %s\n", __func__, __LINE__, json_object_get_string(ptr));
for (int i = 0; i < len; i++) {
if (!json_object_is_type(ptr, json_type_array))
return NULL;
int index = (idx[i] == -1 ? json_object_array_length(ptr) -1 : idx[i]);
ptr = json_object_array_get_idx(ptr, index);
printf("%s %d ptr = %s\n", __func__, __LINE__, json_object_get_string(ptr));
}
tmp = ptr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment