diff --git a/include/rjp_array.h b/include/rjp_array.h index 097466d..5b337a3 100644 --- a/include/rjp_array.h +++ b/include/rjp_array.h @@ -31,7 +31,6 @@ typedef struct RJP_array{ }RJP_array; void irjp_add_element(RJP_array* j); -void irjp_delete_value(RJP_value* root); void irjp_copy_array(RJP_value* dest, const RJP_value* src); RJP_index rjp_dump_array(const RJP_value* arr, char* dest); diff --git a/include/rjp_internal.h b/include/rjp_internal.h index 14bf5a6..f0ea9ba 100644 --- a/include/rjp_internal.h +++ b/include/rjp_internal.h @@ -41,17 +41,4 @@ static inline void irjp_ignore_unused(FILE* fp, ...){ } #endif - - -RJP_value irjp_integer(RJP_int i); -RJP_value irjp_boolean(RJP_bool b); -RJP_value irjp_dfloat(RJP_float d); -RJP_value irjp_string(char* c, RJP_index len); -RJP_value irjp_string_copy(const char* c); -RJP_value irjp_null(void); -RJP_value irjp_object(void); -RJP_value irjp_ordered_object(void); -RJP_value irjp_array(void); - - #endif diff --git a/include/rjp_value.h b/include/rjp_value.h index 79fd19a..5896947 100644 --- a/include/rjp_value.h +++ b/include/rjp_value.h @@ -40,4 +40,6 @@ typedef struct RJP_value{ enum RJP_data_type type; //flag to determine active member of union }RJP_value; +void irjp_delete_value(RJP_value* root); + #endif diff --git a/include/tree.h b/include/tree.h index ff2cd47..38e2c88 100644 --- a/include/tree.h +++ b/include/tree.h @@ -20,8 +20,8 @@ #define RJP_TREE_H #include "rjp.h" -#include "rjp_object.h" #include "rjp_object_member.h" +#include "rjp_value.h" #define RJP_TREE_SUCCESS 0 #define RJP_TREE_ERR_NULL_ROOT 1 @@ -45,7 +45,4 @@ RJP_tree_node* irjp_tree_search_value(RJP_tree_node* root, const char* key); RJP_tree_node* irjp_copy_tree(const RJP_tree_node* root); void irjp_free_tree(RJP_tree_node* root); -void irjp_dbg_print_tree(RJP_tree_node* root); -void irjp_dbg_print_tree_bfs(RJP_tree_node* root); - #endif diff --git a/src/output.c b/src/output.c index e7eaf16..99556b4 100644 --- a/src/output.c +++ b/src/output.c @@ -21,10 +21,10 @@ #include "rjp.h" #include "rjp_internal.h" -#include "memory.h" #include "rjp_string.h" #include "rjp_object.h" #include "rjp_value.h" +#include "rjp_array.h" #include //strlen #include //sprintf diff --git a/src/rjp.c b/src/rjp.c index 7584b6b..63a0a25 100644 --- a/src/rjp.c +++ b/src/rjp.c @@ -19,6 +19,7 @@ #include "rjp_internal.h" #include "rjp_string.h" #include "rjp_object.h" +#include "rjp_array.h" #include "rjp_value.h" #include //free, malloc @@ -134,35 +135,3 @@ RJP_string* rjp_get_string(RJP_value* value){ const RJP_string* rjp_get_cstring(const RJP_value* value){ return &(value->string); } - - -RJP_value irjp_integer(RJP_int i){ - return (RJP_value){.integer = i, .type = rjp_json_integer}; -} -RJP_value irjp_boolean(RJP_bool b){ - return (RJP_value){.boolean = b, .type = rjp_json_boolean}; -} -RJP_value irjp_dfloat(RJP_float d){ - return (RJP_value){.dfloat = d, .type = rjp_json_dfloat}; -} -RJP_value irjp_string(char* c, RJP_index len){ - return (RJP_value){.string = {.value = c, .length = len}, .type = rjp_json_string}; -} -RJP_value irjp_string_copy(const char* c){ - RJP_index esclen = rjp_escape_strlen(c); - char* tmp = rjp_alloc(esclen+1); - rjp_escape_strcpy(tmp, c); - return (RJP_value){.string = {.value = tmp, .length = esclen}, .type = rjp_json_string}; -} -RJP_value irjp_null(void){ - return (RJP_value){.integer = 0, .type = rjp_json_null}; -} -RJP_value irjp_object(void){ - return (RJP_value){.object = {0}, .type = rjp_json_object}; -} -RJP_value irjp_ordered_object(void){ - return (RJP_value){.object = {0}, .type = rjp_json_ordered_object}; -} -RJP_value irjp_array(void){ - return (RJP_value){.array = {0}, .type = rjp_json_array}; -} diff --git a/src/rjp_array.c b/src/rjp_array.c index bbf3708..d439227 100644 --- a/src/rjp_array.c +++ b/src/rjp_array.c @@ -16,8 +16,10 @@ along with this program. If not, see . */ -#include "rjp_array.h" +#include + #include "rjp_internal.h" +#include "rjp_array.h" #include "rjp_value.h" #include "rjp_array_element.h" diff --git a/src/rjp_object.c b/src/rjp_object.c index 54681f9..336440e 100644 --- a/src/rjp_object.c +++ b/src/rjp_object.c @@ -19,6 +19,8 @@ #include "rjp_internal.h" #include "tree.h" #include "rjp_object.h" +#include "rjp_object_member.h" +#include "rjp_value.h" #include //strlen, strncpy diff --git a/src/rjp_parse.c b/src/rjp_parse.c index 9c95ac8..54aaa7c 100644 --- a/src/rjp_parse.c +++ b/src/rjp_parse.c @@ -22,7 +22,6 @@ #include "rjp_internal.h" #include "rjp_value.h" #include "rjp_string.h" -#include "memory.h" #include "rjp_lex.h" #include //strtod, strtol #include //memcpy diff --git a/src/rjp_string.c b/src/rjp_string.c index 92964dc..ec2e148 100644 --- a/src/rjp_string.c +++ b/src/rjp_string.c @@ -19,13 +19,11 @@ #define __STDC_FORMAT_MACROS #include -#include "rjp_string.h" #include "rjp_internal.h" -#include "rjp_object.h" +#include "rjp_string.h" #include "rjp_value.h" #include //fprintf -#include //malloc, free #include //uintN_t #include //strcpy diff --git a/src/rjp_unordered_object.c b/src/rjp_unordered_object.c index 0353cd4..123daa0 100644 --- a/src/rjp_unordered_object.c +++ b/src/rjp_unordered_object.c @@ -19,7 +19,7 @@ #include "rjp_internal.h" #include "rjp_unordered_object.h" #include "rjp_value.h" -#include "rjp_string.h" +#include "rjp_object_member.h" #include "tree.h" #include //strlen diff --git a/src/tree.c b/src/tree.c index 6307e25..813b38e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -19,12 +19,11 @@ #include "tree.h" #include -#include #include #include "rjp_string.h" #include "rjp_internal.h" -#include "rjp_object.h" +#include "rjp_value.h" #define BLACK 0 #define RED 1 @@ -269,73 +268,6 @@ RJP_tree_node* irjp_tree_search_value(RJP_tree_node* root, const char* key){ } return NULL; } -//Debug printouts -void irjp_dbg_print_tree(RJP_tree_node* root){ - if(!root){ - return; - } - RJP_tree_node* current = root, *pre; - while(current){ - if(!current->left){ - printf("%s\n", current->data.name.value); - current = current->right; - }else{ - pre = current->left; - while(pre->right && pre->right != current){ - pre = pre->right; - } - if(!pre->right){ - pre->right = current; - current = current->left; - }else{ - pre->right = NULL; - printf("%s\n", current->data.name.value); - current = current->right; - } - } - } -} -#define pop() front = (front+1)%queuelen -#define push(val, dp) do{queue[rear].n = (val);queue[rear].depth = (dp);rear = (rear+1)%queuelen;}while(0) -struct tmpthing{ - RJP_tree_node* n; - int depth; -}; - -void irjp_dbg_print_tree_bfs(RJP_tree_node* root){ - int queuelen = 64; - struct tmpthing queue[64]; - int front = 0, rear = 0; - int lastdepth = 0; - - push(root, lastdepth); - while(front != rear){ - if(lastdepth != queue[front].depth){ - lastdepth = queue[front].depth; - printf("\n"); - } - if(!queue[front].n){ - printf("*"); - }else{ - printf("%s ", queue[front].n->data.name.value); - if(queue[front].n->left){ - push(queue[front].n->left, queue[front].depth+1); - }else{ - push(NULL,queue[front].depth+1); - } - if(queue[front].n->right){ - push(queue[front].n->right, queue[front].depth+1); - }else{ - push(NULL,queue[front].depth+1); - } - } - pop(); - } - printf("\n"); -} -#undef pop -#undef push - RJP_tree_node* irjp_tree_remove_value(RJP_tree_node* restrict root, RJP_tree_node* restrict member, RJP_tree_node** removed_node){ if(!root) return root;