diff options
Diffstat (limited to 'src/plist.c')
| -rw-r--r-- | src/plist.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/src/plist.c b/src/plist.c index 0fcd926..689fc79 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -266,7 +266,7 @@ plist_data_t plist_get_data(plist_t node) | |||
| 266 | { | 266 | { |
| 267 | if (!node) | 267 | if (!node) |
| 268 | return NULL; | 268 | return NULL; |
| 269 | return ((node_t*)node)->data; | 269 | return ((node_t)node)->data; |
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | plist_data_t plist_new_plist_data(void) | 272 | plist_data_t plist_new_plist_data(void) |
| @@ -326,7 +326,7 @@ void plist_free_data(plist_data_t data) | |||
| 326 | } | 326 | } |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | static int plist_free_node(node_t* node) | 329 | static int plist_free_node(node_t node) |
| 330 | { | 330 | { |
| 331 | plist_data_t data = NULL; | 331 | plist_data_t data = NULL; |
| 332 | int node_index = node_detach(node->parent, node); | 332 | int node_index = node_detach(node->parent, node); |
| @@ -334,9 +334,9 @@ static int plist_free_node(node_t* node) | |||
| 334 | plist_free_data(data); | 334 | plist_free_data(data); |
| 335 | node->data = NULL; | 335 | node->data = NULL; |
| 336 | 336 | ||
| 337 | node_t *ch; | 337 | node_t ch; |
| 338 | for (ch = node_first_child(node); ch; ) { | 338 | for (ch = node_first_child(node); ch; ) { |
| 339 | node_t *next = node_next_sibling(ch); | 339 | node_t next = node_next_sibling(ch); |
| 340 | plist_free_node(ch); | 340 | plist_free_node(ch); |
| 341 | ch = next; | 341 | ch = next; |
| 342 | } | 342 | } |
| @@ -468,7 +468,7 @@ PLIST_API void plist_mem_free(void* ptr) | |||
| 468 | } | 468 | } |
| 469 | } | 469 | } |
| 470 | 470 | ||
| 471 | static plist_t plist_copy_node(node_t *node) | 471 | static plist_t plist_copy_node(node_t node) |
| 472 | { | 472 | { |
| 473 | plist_type node_type = PLIST_NONE; | 473 | plist_type node_type = PLIST_NONE; |
| 474 | plist_t newnode = NULL; | 474 | plist_t newnode = NULL; |
| @@ -509,7 +509,7 @@ static plist_t plist_copy_node(node_t *node) | |||
| 509 | } | 509 | } |
| 510 | newnode = plist_new_node(newdata); | 510 | newnode = plist_new_node(newdata); |
| 511 | 511 | ||
| 512 | node_t *ch; | 512 | node_t ch; |
| 513 | unsigned int node_index = 0; | 513 | unsigned int node_index = 0; |
| 514 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { | 514 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { |
| 515 | /* copy child node */ | 515 | /* copy child node */ |
| @@ -525,7 +525,7 @@ static plist_t plist_copy_node(node_t *node) | |||
| 525 | break; | 525 | break; |
| 526 | case PLIST_DICT: | 526 | case PLIST_DICT: |
| 527 | if (newdata->hashtable && (node_index % 2 != 0)) { | 527 | if (newdata->hashtable && (node_index % 2 != 0)) { |
| 528 | hash_table_insert((hashtable_t*)newdata->hashtable, (node_prev_sibling((node_t*)newch))->data, newch); | 528 | hash_table_insert((hashtable_t*)newdata->hashtable, (node_prev_sibling((node_t)newch))->data, newch); |
| 529 | } | 529 | } |
| 530 | break; | 530 | break; |
| 531 | default: | 531 | default: |
| @@ -556,7 +556,7 @@ PLIST_API plist_t plist_array_get_item(plist_t node, uint32_t n) | |||
| 556 | plist_t ret = NULL; | 556 | plist_t ret = NULL; |
| 557 | if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) | 557 | if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) |
| 558 | { | 558 | { |
| 559 | ptrarray_t *pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 559 | ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 560 | if (pa) { | 560 | if (pa) { |
| 561 | ret = (plist_t)ptr_array_index(pa, n); | 561 | ret = (plist_t)ptr_array_index(pa, n); |
| 562 | } else { | 562 | } else { |
| @@ -578,12 +578,12 @@ PLIST_API uint32_t plist_array_get_item_index(plist_t node) | |||
| 578 | 578 | ||
| 579 | static void _plist_array_post_insert(plist_t node, plist_t item, long n) | 579 | static void _plist_array_post_insert(plist_t node, plist_t item, long n) |
| 580 | { | 580 | { |
| 581 | ptrarray_t *pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 581 | ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 582 | if (pa) { | 582 | if (pa) { |
| 583 | /* store pointer to item in array */ | 583 | /* store pointer to item in array */ |
| 584 | ptr_array_insert(pa, item, n); | 584 | ptr_array_insert(pa, item, n); |
| 585 | } else { | 585 | } else { |
| 586 | if (((node_t*)node)->count > 100) { | 586 | if (((node_t)node)->count > 100) { |
| 587 | /* make new lookup array */ | 587 | /* make new lookup array */ |
| 588 | pa = ptr_array_new(128); | 588 | pa = ptr_array_new(128); |
| 589 | plist_t current = NULL; | 589 | plist_t current = NULL; |
| @@ -593,7 +593,7 @@ static void _plist_array_post_insert(plist_t node, plist_t item, long n) | |||
| 593 | { | 593 | { |
| 594 | ptr_array_add(pa, current); | 594 | ptr_array_add(pa, current); |
| 595 | } | 595 | } |
| 596 | ((plist_data_t)((node_t*)node)->data)->hashtable = pa; | 596 | ((plist_data_t)((node_t)node)->data)->hashtable = pa; |
| 597 | } | 597 | } |
| 598 | } | 598 | } |
| 599 | } | 599 | } |
| @@ -611,7 +611,7 @@ PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n) | |||
| 611 | return; | 611 | return; |
| 612 | } | 612 | } |
| 613 | node_insert(node, idx, item); | 613 | node_insert(node, idx, item); |
| 614 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 614 | ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 615 | if (pa) { | 615 | if (pa) { |
| 616 | ptr_array_set(pa, item, idx); | 616 | ptr_array_set(pa, item, idx); |
| 617 | } | 617 | } |
| @@ -644,7 +644,7 @@ PLIST_API void plist_array_remove_item(plist_t node, uint32_t n) | |||
| 644 | plist_t old_item = plist_array_get_item(node, n); | 644 | plist_t old_item = plist_array_get_item(node, n); |
| 645 | if (old_item) | 645 | if (old_item) |
| 646 | { | 646 | { |
| 647 | ptrarray_t* pa = ((plist_data_t)((node_t*)node)->data)->hashtable; | 647 | ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 648 | if (pa) { | 648 | if (pa) { |
| 649 | ptr_array_remove(pa, n); | 649 | ptr_array_remove(pa, n); |
| 650 | } | 650 | } |
| @@ -660,7 +660,7 @@ PLIST_API void plist_array_item_remove(plist_t node) | |||
| 660 | { | 660 | { |
| 661 | int n = node_child_position(father, node); | 661 | int n = node_child_position(father, node); |
| 662 | if (n < 0) return; | 662 | if (n < 0) return; |
| 663 | ptrarray_t* pa = ((plist_data_t)((node_t*)father)->data)->hashtable; | 663 | ptrarray_t* pa = ((plist_data_t)((node_t)father)->data)->hashtable; |
| 664 | if (pa) { | 664 | if (pa) { |
| 665 | ptr_array_remove(pa, n); | 665 | ptr_array_remove(pa, n); |
| 666 | } | 666 | } |
| @@ -672,14 +672,14 @@ PLIST_API void plist_array_new_iter(plist_t node, plist_array_iter *iter) | |||
| 672 | { | 672 | { |
| 673 | if (iter) | 673 | if (iter) |
| 674 | { | 674 | { |
| 675 | *iter = malloc(sizeof(node_t*)); | 675 | *iter = malloc(sizeof(node_t)); |
| 676 | *((node_t**)(*iter)) = node_first_child(node); | 676 | *((node_t*)(*iter)) = node_first_child(node); |
| 677 | } | 677 | } |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | PLIST_API void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item) | 680 | PLIST_API void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item) |
| 681 | { | 681 | { |
| 682 | node_t** iter_node = (node_t**)iter; | 682 | node_t* iter_node = (node_t*)iter; |
| 683 | 683 | ||
| 684 | if (item) | 684 | if (item) |
| 685 | { | 685 | { |
| @@ -710,14 +710,14 @@ PLIST_API void plist_dict_new_iter(plist_t node, plist_dict_iter *iter) | |||
| 710 | { | 710 | { |
| 711 | if (iter) | 711 | if (iter) |
| 712 | { | 712 | { |
| 713 | *iter = malloc(sizeof(node_t*)); | 713 | *iter = malloc(sizeof(node_t)); |
| 714 | *((node_t**)(*iter)) = node_first_child(node); | 714 | *((node_t*)(*iter)) = node_first_child(node); |
| 715 | } | 715 | } |
| 716 | } | 716 | } |
| 717 | 717 | ||
| 718 | PLIST_API void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val) | 718 | PLIST_API void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val) |
| 719 | { | 719 | { |
| 720 | node_t** iter_node = (node_t**)iter; | 720 | node_t* iter_node = (node_t*)iter; |
| 721 | 721 | ||
| 722 | if (key) | 722 | if (key) |
| 723 | { | 723 | { |
| @@ -799,7 +799,7 @@ PLIST_API plist_t plist_dict_get_item(plist_t node, const char* key) | |||
| 799 | PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) | 799 | PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) |
| 800 | { | 800 | { |
| 801 | if (node && PLIST_DICT == plist_get_node_type(node)) { | 801 | if (node && PLIST_DICT == plist_get_node_type(node)) { |
| 802 | node_t* old_item = plist_dict_get_item(node, key); | 802 | node_t old_item = plist_dict_get_item(node, key); |
| 803 | plist_t key_node = NULL; | 803 | plist_t key_node = NULL; |
| 804 | if (old_item) { | 804 | if (old_item) { |
| 805 | int idx = plist_free_node(old_item); | 805 | int idx = plist_free_node(old_item); |
| @@ -815,12 +815,12 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) | |||
| 815 | node_attach(node, item); | 815 | node_attach(node, item); |
| 816 | } | 816 | } |
| 817 | 817 | ||
| 818 | hashtable_t *ht = ((plist_data_t)((node_t*)node)->data)->hashtable; | 818 | hashtable_t *ht = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 819 | if (ht) { | 819 | if (ht) { |
| 820 | /* store pointer to item in hash table */ | 820 | /* store pointer to item in hash table */ |
| 821 | hash_table_insert(ht, (plist_data_t)((node_t*)key_node)->data, item); | 821 | hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item); |
| 822 | } else { | 822 | } else { |
| 823 | if (((node_t*)node)->count > 500) { | 823 | if (((node_t)node)->count > 500) { |
| 824 | /* make new hash table */ | 824 | /* make new hash table */ |
| 825 | ht = hash_table_new(dict_key_hash, dict_key_compare, NULL); | 825 | ht = hash_table_new(dict_key_hash, dict_key_compare, NULL); |
| 826 | /* calculate the hashes for all entries we have so far */ | 826 | /* calculate the hashes for all entries we have so far */ |
| @@ -829,9 +829,9 @@ PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) | |||
| 829 | ht && current; | 829 | ht && current; |
| 830 | current = (plist_t)node_next_sibling(node_next_sibling(current))) | 830 | current = (plist_t)node_next_sibling(node_next_sibling(current))) |
| 831 | { | 831 | { |
| 832 | hash_table_insert(ht, ((node_t*)current)->data, node_next_sibling(current)); | 832 | hash_table_insert(ht, ((node_t)current)->data, node_next_sibling(current)); |
| 833 | } | 833 | } |
| 834 | ((plist_data_t)((node_t*)node)->data)->hashtable = ht; | 834 | ((plist_data_t)((node_t)node)->data)->hashtable = ht; |
| 835 | } | 835 | } |
| 836 | } | 836 | } |
| 837 | } | 837 | } |
| @@ -850,9 +850,9 @@ PLIST_API void plist_dict_remove_item(plist_t node, const char* key) | |||
| 850 | if (old_item) | 850 | if (old_item) |
| 851 | { | 851 | { |
| 852 | plist_t key_node = node_prev_sibling(old_item); | 852 | plist_t key_node = node_prev_sibling(old_item); |
| 853 | hashtable_t* ht = ((plist_data_t)((node_t*)node)->data)->hashtable; | 853 | hashtable_t* ht = ((plist_data_t)((node_t)node)->data)->hashtable; |
| 854 | if (ht) { | 854 | if (ht) { |
| 855 | hash_table_remove(ht, ((node_t*)key_node)->data); | 855 | hash_table_remove(ht, ((node_t)key_node)->data); |
| 856 | } | 856 | } |
| 857 | plist_free(key_node); | 857 | plist_free(key_node); |
| 858 | plist_free(old_item); | 858 | plist_free(old_item); |
| @@ -961,7 +961,7 @@ static void plist_get_type_and_value(plist_t node, plist_type * type, void *valu | |||
| 961 | 961 | ||
| 962 | PLIST_API plist_t plist_get_parent(plist_t node) | 962 | PLIST_API plist_t plist_get_parent(plist_t node) |
| 963 | { | 963 | { |
| 964 | return node ? (plist_t) ((node_t*) node)->parent : NULL; | 964 | return node ? (plist_t) ((node_t) node)->parent : NULL; |
| 965 | } | 965 | } |
| 966 | 966 | ||
| 967 | PLIST_API plist_type plist_get_node_type(plist_t node) | 967 | PLIST_API plist_type plist_get_node_type(plist_t node) |
| @@ -1119,7 +1119,7 @@ int plist_data_compare(const void *a, const void *b) | |||
| 1119 | if (!a || !b) | 1119 | if (!a || !b) |
| 1120 | return FALSE; | 1120 | return FALSE; |
| 1121 | 1121 | ||
| 1122 | if (!((node_t*) a)->data || !((node_t*) b)->data) | 1122 | if (!((node_t) a)->data || !((node_t) b)->data) |
| 1123 | return FALSE; | 1123 | return FALSE; |
| 1124 | 1124 | ||
| 1125 | val_a = plist_get_data((plist_t) a); | 1125 | val_a = plist_get_data((plist_t) a); |
| @@ -1509,8 +1509,8 @@ PLIST_API void plist_sort(plist_t plist) | |||
| 1509 | plist_sort(plist_array_get_item(plist, i)); | 1509 | plist_sort(plist_array_get_item(plist, i)); |
| 1510 | } | 1510 | } |
| 1511 | } else if (PLIST_IS_DICT(plist)) { | 1511 | } else if (PLIST_IS_DICT(plist)) { |
| 1512 | node_t *node = (node_t*)plist; | 1512 | node_t node = (node_t)plist; |
| 1513 | node_t *ch; | 1513 | node_t ch; |
| 1514 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { | 1514 | for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { |
| 1515 | ch = node_next_sibling(ch); | 1515 | ch = node_next_sibling(ch); |
| 1516 | plist_sort((plist_t)ch); | 1516 | plist_sort((plist_t)ch); |
| @@ -1521,22 +1521,22 @@ PLIST_API void plist_sort(plist_t plist) | |||
| 1521 | int swapped = 0; | 1521 | int swapped = 0; |
| 1522 | do { | 1522 | do { |
| 1523 | swapped = 0; | 1523 | swapped = 0; |
| 1524 | node_t *lptr = NULL; | 1524 | node_t lptr = NULL; |
| 1525 | node_t *cur_key = node_first_child((node_t*)plist); | 1525 | node_t cur_key = node_first_child((node_t)plist); |
| 1526 | 1526 | ||
| 1527 | while (NEXT_KEY(cur_key) != lptr) { | 1527 | while (NEXT_KEY(cur_key) != lptr) { |
| 1528 | node_t *next_key = NEXT_KEY(cur_key); | 1528 | node_t next_key = NEXT_KEY(cur_key); |
| 1529 | if (strcmp(KEY_STRVAL(cur_key), KEY_STRVAL(next_key)) > 0) { | 1529 | if (strcmp(KEY_STRVAL(cur_key), KEY_STRVAL(next_key)) > 0) { |
| 1530 | node_t *cur_val = cur_key->next; | 1530 | node_t cur_val = cur_key->next; |
| 1531 | node_t *next_val = next_key->next; | 1531 | node_t next_val = next_key->next; |
| 1532 | // we need to swap 2 consecutive nodes with the 2 after them | 1532 | // we need to swap 2 consecutive nodes with the 2 after them |
| 1533 | // a -> b -> [c] -> [d] -> [e] -> [f] -> g -> h | 1533 | // a -> b -> [c] -> [d] -> [e] -> [f] -> g -> h |
| 1534 | // cur next | 1534 | // cur next |
| 1535 | // swapped: | 1535 | // swapped: |
| 1536 | // a -> b -> [e] -> [f] -> [c] -> [d] -> g -> h | 1536 | // a -> b -> [e] -> [f] -> [c] -> [d] -> g -> h |
| 1537 | // next cur | 1537 | // next cur |
| 1538 | node_t *tmp_prev = cur_key->prev; | 1538 | node_t tmp_prev = cur_key->prev; |
| 1539 | node_t *tmp_next = next_val->next; | 1539 | node_t tmp_next = next_val->next; |
| 1540 | cur_key->prev = next_val; | 1540 | cur_key->prev = next_val; |
| 1541 | cur_val->next = tmp_next; | 1541 | cur_val->next = tmp_next; |
| 1542 | next_val->next = cur_key; | 1542 | next_val->next = cur_key; |
| @@ -1544,12 +1544,12 @@ PLIST_API void plist_sort(plist_t plist) | |||
| 1544 | if (tmp_prev) { | 1544 | if (tmp_prev) { |
| 1545 | tmp_prev->next = next_key; | 1545 | tmp_prev->next = next_key; |
| 1546 | } else { | 1546 | } else { |
| 1547 | ((node_t*)plist)->children->begin = next_key; | 1547 | ((node_t)plist)->children->begin = next_key; |
| 1548 | } | 1548 | } |
| 1549 | if (tmp_next) { | 1549 | if (tmp_next) { |
| 1550 | tmp_next->prev = cur_val; | 1550 | tmp_next->prev = cur_val; |
| 1551 | } else { | 1551 | } else { |
| 1552 | ((node_t*)plist)->children->end = cur_val; | 1552 | ((node_t)plist)->children->end = cur_val; |
| 1553 | } | 1553 | } |
| 1554 | cur_key = next_key; | 1554 | cur_key = next_key; |
| 1555 | swapped = 1; | 1555 | swapped = 1; |
