diff options
Diffstat (limited to 'src/plist.c')
-rw-r--r-- | src/plist.c | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/src/plist.c b/src/plist.c index ccb7359..d78f748 100644 --- a/src/plist.c +++ b/src/plist.c @@ -47,6 +47,10 @@ #include <hashtable.h> #include <ptrarray.h> +#ifdef _MSC_VER +typedef SSIZE_T ssize_t; +#endif + extern void plist_xml_init(void); extern void plist_xml_deinit(void); extern void plist_bin_init(void); @@ -199,7 +203,7 @@ int plist_is_binary(const char *plist_data, uint32_t length) plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format) { - int res = -1; + plist_err_t res = PLIST_ERR_UNKNOWN; if (!plist) { return PLIST_ERR_INVALID_ARG; } @@ -284,7 +288,7 @@ plist_err_t plist_read_from_file(const char *filename, plist_t *plist, plist_for if (total == 0) { return PLIST_ERR_PARSE; } - char *buf = malloc(total); + char *buf = (char*)malloc(total); if (!buf) { fclose(f); return PLIST_ERR_NO_MEM; @@ -316,7 +320,7 @@ plist_data_t plist_get_data(plist_t node) { if (!node) return NULL; - return ((node_t)node)->data; + return (plist_data_t)((node_t)node)->data; } plist_data_t plist_new_plist_data(void) @@ -364,10 +368,10 @@ void plist_free_data(plist_data_t data) free(data->buff); break; case PLIST_ARRAY: - ptr_array_free(data->hashtable); + ptr_array_free((ptrarray_t*)data->hashtable); break; case PLIST_DICT: - hash_table_destroy(data->hashtable); + hash_table_destroy((hashtable_t*)data->hashtable); break; default: break; @@ -506,7 +510,7 @@ void plist_free(plist_t plist) { if (plist) { - plist_free_node(plist); + plist_free_node((node_t)plist); } } @@ -565,7 +569,7 @@ static plist_t plist_copy_node(node_t node) /* copy child node */ plist_t newch = plist_copy_node(ch); /* attach to new parent node */ - node_attach(newnode, newch); + node_attach((node_t)newnode, (node_t)newch); /* if needed, add child node to lookup table of parent node */ switch (node_type) { case PLIST_ARRAY: @@ -588,7 +592,7 @@ static plist_t plist_copy_node(node_t node) plist_t plist_copy(plist_t node) { - return node ? plist_copy_node(node) : NULL; + return node ? plist_copy_node((node_t)node) : NULL; } uint32_t plist_array_get_size(plist_t node) @@ -596,7 +600,7 @@ uint32_t plist_array_get_size(plist_t node) uint32_t ret = 0; if (node && PLIST_ARRAY == plist_get_node_type(node)) { - ret = node_n_children(node); + ret = node_n_children((node_t)node); } return ret; } @@ -606,11 +610,11 @@ plist_t plist_array_get_item(plist_t node, uint32_t n) plist_t ret = NULL; if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) { - ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; + ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (pa) { ret = (plist_t)ptr_array_index(pa, n); } else { - ret = (plist_t)node_nth_child(node, n); + ret = (plist_t)node_nth_child((node_t)node, n); } } return ret; @@ -621,14 +625,14 @@ uint32_t plist_array_get_item_index(plist_t node) plist_t father = plist_get_parent(node); if (PLIST_ARRAY == plist_get_node_type(father)) { - return node_child_position(father, node); + return node_child_position((node_t)father, (node_t)node); } return UINT_MAX; } static void _plist_array_post_insert(plist_t node, plist_t item, long n) { - ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; + ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (pa) { /* store pointer to item in array */ ptr_array_insert(pa, item, n); @@ -637,9 +641,9 @@ static void _plist_array_post_insert(plist_t node, plist_t item, long n) /* make new lookup array */ pa = ptr_array_new(128); plist_t current = NULL; - for (current = (plist_t)node_first_child(node); + for (current = (plist_t)node_first_child((node_t)node); pa && current; - current = (plist_t)node_next_sibling(current)) + current = (plist_t)node_next_sibling((node_t)current)) { ptr_array_add(pa, current); } @@ -655,13 +659,13 @@ void plist_array_set_item(plist_t node, plist_t item, uint32_t n) plist_t old_item = plist_array_get_item(node, n); if (old_item) { - int idx = plist_free_node(old_item); + int idx = plist_free_node((node_t)old_item); assert(idx >= 0); if (idx < 0) { return; } - node_insert(node, idx, item); - ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; + node_insert((node_t)node, idx, (node_t)item); + ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (pa) { ptr_array_set(pa, item, idx); } @@ -673,7 +677,7 @@ void plist_array_append_item(plist_t node, plist_t item) { if (node && PLIST_ARRAY == plist_get_node_type(node)) { - node_attach(node, item); + node_attach((node_t)node, (node_t)item); _plist_array_post_insert(node, item, -1); } } @@ -682,7 +686,7 @@ void plist_array_insert_item(plist_t node, plist_t item, uint32_t n) { if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) { - node_insert(node, n, item); + node_insert((node_t)node, n, (node_t)item); _plist_array_post_insert(node, item, (long)n); } } @@ -694,7 +698,7 @@ void plist_array_remove_item(plist_t node, uint32_t n) plist_t old_item = plist_array_get_item(node, n); if (old_item) { - ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; + ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (pa) { ptr_array_remove(pa, n); } @@ -708,9 +712,9 @@ void plist_array_item_remove(plist_t node) plist_t father = plist_get_parent(node); if (PLIST_ARRAY == plist_get_node_type(father)) { - int n = node_child_position(father, node); + int n = node_child_position((node_t)father, (node_t)node); if (n < 0) return; - ptrarray_t* pa = ((plist_data_t)((node_t)father)->data)->hashtable; + ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)father)->data)->hashtable; if (pa) { ptr_array_remove(pa, n); } @@ -723,7 +727,7 @@ void plist_array_new_iter(plist_t node, plist_array_iter *iter) if (iter) { *iter = malloc(sizeof(node_t)); - *((node_t*)(*iter)) = node_first_child(node); + *((node_t*)(*iter)) = node_first_child((node_t)node); } } @@ -751,7 +755,7 @@ uint32_t plist_dict_get_size(plist_t node) uint32_t ret = 0; if (node && PLIST_DICT == plist_get_node_type(node)) { - ret = node_n_children(node) / 2; + ret = node_n_children((node_t)node) / 2; } return ret; } @@ -761,7 +765,7 @@ void plist_dict_new_iter(plist_t node, plist_dict_iter *iter) if (iter) { *iter = malloc(sizeof(node_t)); - *((node_t*)(*iter)) = node_first_child(node); + *((node_t*)(*iter)) = node_first_child((node_t)node); } } @@ -798,7 +802,7 @@ void plist_dict_get_item_key(plist_t node, char **key) plist_t father = plist_get_parent(node); if (PLIST_DICT == plist_get_node_type(father)) { - plist_get_key_val( (plist_t) node_prev_sibling(node), key); + plist_get_key_val( (plist_t) node_prev_sibling((node_t)node), key); } } @@ -808,7 +812,7 @@ plist_t plist_dict_item_get_key(plist_t node) plist_t father = plist_get_parent(node); if (PLIST_DICT == plist_get_node_type(father)) { - ret = (plist_t)node_prev_sibling(node); + ret = (plist_t)node_prev_sibling((node_t)node); } return ret; } @@ -828,16 +832,16 @@ plist_t plist_dict_get_item(plist_t node, const char* key) ret = (plist_t)hash_table_lookup(ht, &sdata); } else { plist_t current = NULL; - for (current = (plist_t)node_first_child(node); + for (current = (plist_t)node_first_child((node_t)node); current; - current = (plist_t)node_next_sibling(node_next_sibling(current))) + current = (plist_t)node_next_sibling(node_next_sibling((node_t)current))) { data = plist_get_data(current); assert( PLIST_KEY == plist_get_node_type(current) ); if (data && !strcmp(key, data->strval)) { - ret = (plist_t)node_next_sibling(current); + ret = (plist_t)node_next_sibling((node_t)current); break; } } @@ -849,23 +853,23 @@ plist_t plist_dict_get_item(plist_t node, const char* key) void plist_dict_set_item(plist_t node, const char* key, plist_t item) { if (node && PLIST_DICT == plist_get_node_type(node)) { - node_t old_item = plist_dict_get_item(node, key); + plist_t old_item = plist_dict_get_item(node, key); plist_t key_node = NULL; if (old_item) { - int idx = plist_free_node(old_item); + int idx = plist_free_node((node_t)old_item); assert(idx >= 0); if (idx < 0) { return; } - node_insert(node, idx, item); - key_node = node_prev_sibling(item); + node_insert((node_t)node, idx, (node_t)item); + key_node = node_prev_sibling((node_t)item); } else { key_node = plist_new_key(key); - node_attach(node, key_node); - node_attach(node, item); + node_attach((node_t)node, (node_t)key_node); + node_attach((node_t)node, (node_t)item); } - hashtable_t *ht = ((plist_data_t)((node_t)node)->data)->hashtable; + hashtable_t *ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (ht) { /* store pointer to item in hash table */ hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item); @@ -875,11 +879,11 @@ void plist_dict_set_item(plist_t node, const char* key, plist_t item) ht = hash_table_new(dict_key_hash, dict_key_compare, NULL); /* calculate the hashes for all entries we have so far */ plist_t current = NULL; - for (current = (plist_t)node_first_child(node); + for (current = (plist_t)node_first_child((node_t)node); ht && current; - current = (plist_t)node_next_sibling(node_next_sibling(current))) + current = (plist_t)node_next_sibling(node_next_sibling((node_t)current))) { - hash_table_insert(ht, ((node_t)current)->data, node_next_sibling(current)); + hash_table_insert(ht, ((node_t)current)->data, node_next_sibling((node_t)current)); } ((plist_data_t)((node_t)node)->data)->hashtable = ht; } @@ -894,8 +898,8 @@ void plist_dict_remove_item(plist_t node, const char* key) plist_t old_item = plist_dict_get_item(node, key); if (old_item) { - plist_t key_node = node_prev_sibling(old_item); - hashtable_t* ht = ((plist_data_t)((node_t)node)->data)->hashtable; + plist_t key_node = node_prev_sibling((node_t)old_item); + hashtable_t* ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable; if (ht) { hash_table_remove(ht, ((node_t)key_node)->data); } |