summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c90
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 @@
47#include <hashtable.h> 47#include <hashtable.h>
48#include <ptrarray.h> 48#include <ptrarray.h>
49 49
50#ifdef _MSC_VER
51typedef SSIZE_T ssize_t;
52#endif
53
50extern void plist_xml_init(void); 54extern void plist_xml_init(void);
51extern void plist_xml_deinit(void); 55extern void plist_xml_deinit(void);
52extern void plist_bin_init(void); 56extern void plist_bin_init(void);
@@ -199,7 +203,7 @@ int plist_is_binary(const char *plist_data, uint32_t length)
199 203
200plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format) 204plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format)
201{ 205{
202 int res = -1; 206 plist_err_t res = PLIST_ERR_UNKNOWN;
203 if (!plist) { 207 if (!plist) {
204 return PLIST_ERR_INVALID_ARG; 208 return PLIST_ERR_INVALID_ARG;
205 } 209 }
@@ -284,7 +288,7 @@ plist_err_t plist_read_from_file(const char *filename, plist_t *plist, plist_for
284 if (total == 0) { 288 if (total == 0) {
285 return PLIST_ERR_PARSE; 289 return PLIST_ERR_PARSE;
286 } 290 }
287 char *buf = malloc(total); 291 char *buf = (char*)malloc(total);
288 if (!buf) { 292 if (!buf) {
289 fclose(f); 293 fclose(f);
290 return PLIST_ERR_NO_MEM; 294 return PLIST_ERR_NO_MEM;
@@ -316,7 +320,7 @@ plist_data_t plist_get_data(plist_t node)
316{ 320{
317 if (!node) 321 if (!node)
318 return NULL; 322 return NULL;
319 return ((node_t)node)->data; 323 return (plist_data_t)((node_t)node)->data;
320} 324}
321 325
322plist_data_t plist_new_plist_data(void) 326plist_data_t plist_new_plist_data(void)
@@ -364,10 +368,10 @@ void plist_free_data(plist_data_t data)
364 free(data->buff); 368 free(data->buff);
365 break; 369 break;
366 case PLIST_ARRAY: 370 case PLIST_ARRAY:
367 ptr_array_free(data->hashtable); 371 ptr_array_free((ptrarray_t*)data->hashtable);
368 break; 372 break;
369 case PLIST_DICT: 373 case PLIST_DICT:
370 hash_table_destroy(data->hashtable); 374 hash_table_destroy((hashtable_t*)data->hashtable);
371 break; 375 break;
372 default: 376 default:
373 break; 377 break;
@@ -506,7 +510,7 @@ void plist_free(plist_t plist)
506{ 510{
507 if (plist) 511 if (plist)
508 { 512 {
509 plist_free_node(plist); 513 plist_free_node((node_t)plist);
510 } 514 }
511} 515}
512 516
@@ -565,7 +569,7 @@ static plist_t plist_copy_node(node_t node)
565 /* copy child node */ 569 /* copy child node */
566 plist_t newch = plist_copy_node(ch); 570 plist_t newch = plist_copy_node(ch);
567 /* attach to new parent node */ 571 /* attach to new parent node */
568 node_attach(newnode, newch); 572 node_attach((node_t)newnode, (node_t)newch);
569 /* if needed, add child node to lookup table of parent node */ 573 /* if needed, add child node to lookup table of parent node */
570 switch (node_type) { 574 switch (node_type) {
571 case PLIST_ARRAY: 575 case PLIST_ARRAY:
@@ -588,7 +592,7 @@ static plist_t plist_copy_node(node_t node)
588 592
589plist_t plist_copy(plist_t node) 593plist_t plist_copy(plist_t node)
590{ 594{
591 return node ? plist_copy_node(node) : NULL; 595 return node ? plist_copy_node((node_t)node) : NULL;
592} 596}
593 597
594uint32_t plist_array_get_size(plist_t node) 598uint32_t plist_array_get_size(plist_t node)
@@ -596,7 +600,7 @@ uint32_t plist_array_get_size(plist_t node)
596 uint32_t ret = 0; 600 uint32_t ret = 0;
597 if (node && PLIST_ARRAY == plist_get_node_type(node)) 601 if (node && PLIST_ARRAY == plist_get_node_type(node))
598 { 602 {
599 ret = node_n_children(node); 603 ret = node_n_children((node_t)node);
600 } 604 }
601 return ret; 605 return ret;
602} 606}
@@ -606,11 +610,11 @@ plist_t plist_array_get_item(plist_t node, uint32_t n)
606 plist_t ret = NULL; 610 plist_t ret = NULL;
607 if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) 611 if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX)
608 { 612 {
609 ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; 613 ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
610 if (pa) { 614 if (pa) {
611 ret = (plist_t)ptr_array_index(pa, n); 615 ret = (plist_t)ptr_array_index(pa, n);
612 } else { 616 } else {
613 ret = (plist_t)node_nth_child(node, n); 617 ret = (plist_t)node_nth_child((node_t)node, n);
614 } 618 }
615 } 619 }
616 return ret; 620 return ret;
@@ -621,14 +625,14 @@ uint32_t plist_array_get_item_index(plist_t node)
621 plist_t father = plist_get_parent(node); 625 plist_t father = plist_get_parent(node);
622 if (PLIST_ARRAY == plist_get_node_type(father)) 626 if (PLIST_ARRAY == plist_get_node_type(father))
623 { 627 {
624 return node_child_position(father, node); 628 return node_child_position((node_t)father, (node_t)node);
625 } 629 }
626 return UINT_MAX; 630 return UINT_MAX;
627} 631}
628 632
629static void _plist_array_post_insert(plist_t node, plist_t item, long n) 633static void _plist_array_post_insert(plist_t node, plist_t item, long n)
630{ 634{
631 ptrarray_t *pa = ((plist_data_t)((node_t)node)->data)->hashtable; 635 ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
632 if (pa) { 636 if (pa) {
633 /* store pointer to item in array */ 637 /* store pointer to item in array */
634 ptr_array_insert(pa, item, n); 638 ptr_array_insert(pa, item, n);
@@ -637,9 +641,9 @@ static void _plist_array_post_insert(plist_t node, plist_t item, long n)
637 /* make new lookup array */ 641 /* make new lookup array */
638 pa = ptr_array_new(128); 642 pa = ptr_array_new(128);
639 plist_t current = NULL; 643 plist_t current = NULL;
640 for (current = (plist_t)node_first_child(node); 644 for (current = (plist_t)node_first_child((node_t)node);
641 pa && current; 645 pa && current;
642 current = (plist_t)node_next_sibling(current)) 646 current = (plist_t)node_next_sibling((node_t)current))
643 { 647 {
644 ptr_array_add(pa, current); 648 ptr_array_add(pa, current);
645 } 649 }
@@ -655,13 +659,13 @@ void plist_array_set_item(plist_t node, plist_t item, uint32_t n)
655 plist_t old_item = plist_array_get_item(node, n); 659 plist_t old_item = plist_array_get_item(node, n);
656 if (old_item) 660 if (old_item)
657 { 661 {
658 int idx = plist_free_node(old_item); 662 int idx = plist_free_node((node_t)old_item);
659 assert(idx >= 0); 663 assert(idx >= 0);
660 if (idx < 0) { 664 if (idx < 0) {
661 return; 665 return;
662 } 666 }
663 node_insert(node, idx, item); 667 node_insert((node_t)node, idx, (node_t)item);
664 ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; 668 ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
665 if (pa) { 669 if (pa) {
666 ptr_array_set(pa, item, idx); 670 ptr_array_set(pa, item, idx);
667 } 671 }
@@ -673,7 +677,7 @@ void plist_array_append_item(plist_t node, plist_t item)
673{ 677{
674 if (node && PLIST_ARRAY == plist_get_node_type(node)) 678 if (node && PLIST_ARRAY == plist_get_node_type(node))
675 { 679 {
676 node_attach(node, item); 680 node_attach((node_t)node, (node_t)item);
677 _plist_array_post_insert(node, item, -1); 681 _plist_array_post_insert(node, item, -1);
678 } 682 }
679} 683}
@@ -682,7 +686,7 @@ void plist_array_insert_item(plist_t node, plist_t item, uint32_t n)
682{ 686{
683 if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX) 687 if (node && PLIST_ARRAY == plist_get_node_type(node) && n < INT_MAX)
684 { 688 {
685 node_insert(node, n, item); 689 node_insert((node_t)node, n, (node_t)item);
686 _plist_array_post_insert(node, item, (long)n); 690 _plist_array_post_insert(node, item, (long)n);
687 } 691 }
688} 692}
@@ -694,7 +698,7 @@ void plist_array_remove_item(plist_t node, uint32_t n)
694 plist_t old_item = plist_array_get_item(node, n); 698 plist_t old_item = plist_array_get_item(node, n);
695 if (old_item) 699 if (old_item)
696 { 700 {
697 ptrarray_t* pa = ((plist_data_t)((node_t)node)->data)->hashtable; 701 ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
698 if (pa) { 702 if (pa) {
699 ptr_array_remove(pa, n); 703 ptr_array_remove(pa, n);
700 } 704 }
@@ -708,9 +712,9 @@ void plist_array_item_remove(plist_t node)
708 plist_t father = plist_get_parent(node); 712 plist_t father = plist_get_parent(node);
709 if (PLIST_ARRAY == plist_get_node_type(father)) 713 if (PLIST_ARRAY == plist_get_node_type(father))
710 { 714 {
711 int n = node_child_position(father, node); 715 int n = node_child_position((node_t)father, (node_t)node);
712 if (n < 0) return; 716 if (n < 0) return;
713 ptrarray_t* pa = ((plist_data_t)((node_t)father)->data)->hashtable; 717 ptrarray_t* pa = (ptrarray_t*)((plist_data_t)((node_t)father)->data)->hashtable;
714 if (pa) { 718 if (pa) {
715 ptr_array_remove(pa, n); 719 ptr_array_remove(pa, n);
716 } 720 }
@@ -723,7 +727,7 @@ void plist_array_new_iter(plist_t node, plist_array_iter *iter)
723 if (iter) 727 if (iter)
724 { 728 {
725 *iter = malloc(sizeof(node_t)); 729 *iter = malloc(sizeof(node_t));
726 *((node_t*)(*iter)) = node_first_child(node); 730 *((node_t*)(*iter)) = node_first_child((node_t)node);
727 } 731 }
728} 732}
729 733
@@ -751,7 +755,7 @@ uint32_t plist_dict_get_size(plist_t node)
751 uint32_t ret = 0; 755 uint32_t ret = 0;
752 if (node && PLIST_DICT == plist_get_node_type(node)) 756 if (node && PLIST_DICT == plist_get_node_type(node))
753 { 757 {
754 ret = node_n_children(node) / 2; 758 ret = node_n_children((node_t)node) / 2;
755 } 759 }
756 return ret; 760 return ret;
757} 761}
@@ -761,7 +765,7 @@ void plist_dict_new_iter(plist_t node, plist_dict_iter *iter)
761 if (iter) 765 if (iter)
762 { 766 {
763 *iter = malloc(sizeof(node_t)); 767 *iter = malloc(sizeof(node_t));
764 *((node_t*)(*iter)) = node_first_child(node); 768 *((node_t*)(*iter)) = node_first_child((node_t)node);
765 } 769 }
766} 770}
767 771
@@ -798,7 +802,7 @@ void plist_dict_get_item_key(plist_t node, char **key)
798 plist_t father = plist_get_parent(node); 802 plist_t father = plist_get_parent(node);
799 if (PLIST_DICT == plist_get_node_type(father)) 803 if (PLIST_DICT == plist_get_node_type(father))
800 { 804 {
801 plist_get_key_val( (plist_t) node_prev_sibling(node), key); 805 plist_get_key_val( (plist_t) node_prev_sibling((node_t)node), key);
802 } 806 }
803} 807}
804 808
@@ -808,7 +812,7 @@ plist_t plist_dict_item_get_key(plist_t node)
808 plist_t father = plist_get_parent(node); 812 plist_t father = plist_get_parent(node);
809 if (PLIST_DICT == plist_get_node_type(father)) 813 if (PLIST_DICT == plist_get_node_type(father))
810 { 814 {
811 ret = (plist_t)node_prev_sibling(node); 815 ret = (plist_t)node_prev_sibling((node_t)node);
812 } 816 }
813 return ret; 817 return ret;
814} 818}
@@ -828,16 +832,16 @@ plist_t plist_dict_get_item(plist_t node, const char* key)
828 ret = (plist_t)hash_table_lookup(ht, &sdata); 832 ret = (plist_t)hash_table_lookup(ht, &sdata);
829 } else { 833 } else {
830 plist_t current = NULL; 834 plist_t current = NULL;
831 for (current = (plist_t)node_first_child(node); 835 for (current = (plist_t)node_first_child((node_t)node);
832 current; 836 current;
833 current = (plist_t)node_next_sibling(node_next_sibling(current))) 837 current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
834 { 838 {
835 data = plist_get_data(current); 839 data = plist_get_data(current);
836 assert( PLIST_KEY == plist_get_node_type(current) ); 840 assert( PLIST_KEY == plist_get_node_type(current) );
837 841
838 if (data && !strcmp(key, data->strval)) 842 if (data && !strcmp(key, data->strval))
839 { 843 {
840 ret = (plist_t)node_next_sibling(current); 844 ret = (plist_t)node_next_sibling((node_t)current);
841 break; 845 break;
842 } 846 }
843 } 847 }
@@ -849,23 +853,23 @@ plist_t plist_dict_get_item(plist_t node, const char* key)
849void plist_dict_set_item(plist_t node, const char* key, plist_t item) 853void plist_dict_set_item(plist_t node, const char* key, plist_t item)
850{ 854{
851 if (node && PLIST_DICT == plist_get_node_type(node)) { 855 if (node && PLIST_DICT == plist_get_node_type(node)) {
852 node_t old_item = plist_dict_get_item(node, key); 856 plist_t old_item = plist_dict_get_item(node, key);
853 plist_t key_node = NULL; 857 plist_t key_node = NULL;
854 if (old_item) { 858 if (old_item) {
855 int idx = plist_free_node(old_item); 859 int idx = plist_free_node((node_t)old_item);
856 assert(idx >= 0); 860 assert(idx >= 0);
857 if (idx < 0) { 861 if (idx < 0) {
858 return; 862 return;
859 } 863 }
860 node_insert(node, idx, item); 864 node_insert((node_t)node, idx, (node_t)item);
861 key_node = node_prev_sibling(item); 865 key_node = node_prev_sibling((node_t)item);
862 } else { 866 } else {
863 key_node = plist_new_key(key); 867 key_node = plist_new_key(key);
864 node_attach(node, key_node); 868 node_attach((node_t)node, (node_t)key_node);
865 node_attach(node, item); 869 node_attach((node_t)node, (node_t)item);
866 } 870 }
867 871
868 hashtable_t *ht = ((plist_data_t)((node_t)node)->data)->hashtable; 872 hashtable_t *ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
869 if (ht) { 873 if (ht) {
870 /* store pointer to item in hash table */ 874 /* store pointer to item in hash table */
871 hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item); 875 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)
875 ht = hash_table_new(dict_key_hash, dict_key_compare, NULL); 879 ht = hash_table_new(dict_key_hash, dict_key_compare, NULL);
876 /* calculate the hashes for all entries we have so far */ 880 /* calculate the hashes for all entries we have so far */
877 plist_t current = NULL; 881 plist_t current = NULL;
878 for (current = (plist_t)node_first_child(node); 882 for (current = (plist_t)node_first_child((node_t)node);
879 ht && current; 883 ht && current;
880 current = (plist_t)node_next_sibling(node_next_sibling(current))) 884 current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
881 { 885 {
882 hash_table_insert(ht, ((node_t)current)->data, node_next_sibling(current)); 886 hash_table_insert(ht, ((node_t)current)->data, node_next_sibling((node_t)current));
883 } 887 }
884 ((plist_data_t)((node_t)node)->data)->hashtable = ht; 888 ((plist_data_t)((node_t)node)->data)->hashtable = ht;
885 } 889 }
@@ -894,8 +898,8 @@ void plist_dict_remove_item(plist_t node, const char* key)
894 plist_t old_item = plist_dict_get_item(node, key); 898 plist_t old_item = plist_dict_get_item(node, key);
895 if (old_item) 899 if (old_item)
896 { 900 {
897 plist_t key_node = node_prev_sibling(old_item); 901 plist_t key_node = node_prev_sibling((node_t)old_item);
898 hashtable_t* ht = ((plist_data_t)((node_t)node)->data)->hashtable; 902 hashtable_t* ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
899 if (ht) { 903 if (ht) {
900 hash_table_remove(ht, ((node_t)key_node)->data); 904 hash_table_remove(ht, ((node_t)key_node)->data);
901 } 905 }