summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libcnary/include/node.h42
-rw-r--r--libcnary/include/node_list.h23
-rw-r--r--libcnary/node.c49
-rw-r--r--libcnary/node_list.c28
-rw-r--r--src/bplist.c16
-rw-r--r--src/jplist.c11
-rw-r--r--src/oplist.c11
-rw-r--r--src/plist.c82
-rw-r--r--src/xplist.c11
-rw-r--r--test/plist_cmp.c4
10 files changed, 143 insertions, 134 deletions
diff --git a/libcnary/include/node.h b/libcnary/include/node.h
index 7e9da50..123241a 100644
--- a/libcnary/include/node.h
+++ b/libcnary/include/node.h
@@ -24,42 +24,42 @@
24#ifndef NODE_H_ 24#ifndef NODE_H_
25#define NODE_H_ 25#define NODE_H_
26 26
27#include "node_list.h"
27#include "object.h" 28#include "object.h"
28 29
29#define NODE_TYPE 1; 30#define NODE_TYPE 1;
30 31
31struct node_list_t;
32
33// This class implements the abstract iterator class 32// This class implements the abstract iterator class
34typedef struct node_t { 33typedef struct node* node_t;
34struct node {
35 // Super class 35 // Super class
36 struct node_t* next; 36 node_t next;
37 struct node_t* prev; 37 node_t prev;
38 unsigned int count; 38 unsigned int count;
39 39
40 // Local Members 40 // Local Members
41 void *data; 41 void *data;
42 struct node_t* parent; 42 node_t parent;
43 struct node_list_t* children; 43 node_list_t children;
44} node_t; 44};
45 45
46void node_destroy(struct node_t* node); 46void node_destroy(node_t node);
47struct node_t* node_create(struct node_t* parent, void* data); 47node_t node_create(node_t parent, void* data);
48 48
49int node_attach(struct node_t* parent, struct node_t* child); 49int node_attach(node_t parent, node_t child);
50int node_detach(struct node_t* parent, struct node_t* child); 50int node_detach(node_t parent, node_t child);
51int node_insert(struct node_t* parent, unsigned int index, struct node_t* child); 51int node_insert(node_t parent, unsigned int index, node_t child);
52 52
53unsigned int node_n_children(struct node_t* node); 53unsigned int node_n_children(node_t node);
54node_t* node_nth_child(struct node_t* node, unsigned int n); 54node_t node_nth_child(node_t node, unsigned int n);
55node_t* node_first_child(struct node_t* node); 55node_t node_first_child(node_t node);
56node_t* node_prev_sibling(struct node_t* node); 56node_t node_prev_sibling(node_t node);
57node_t* node_next_sibling(struct node_t* node); 57node_t node_next_sibling(node_t node);
58int node_child_position(struct node_t* parent, node_t* child); 58int node_child_position(node_t parent, node_t child);
59 59
60typedef void* (*copy_func_t)(const void *src); 60typedef void* (*copy_func_t)(const void *src);
61node_t* node_copy_deep(node_t* node, copy_func_t copy_func); 61node_t node_copy_deep(node_t node, copy_func_t copy_func);
62 62
63void node_debug(struct node_t* node); 63void node_debug(node_t node);
64 64
65#endif /* NODE_H_ */ 65#endif /* NODE_H_ */
diff --git a/libcnary/include/node_list.h b/libcnary/include/node_list.h
index 380916e..d566b00 100644
--- a/libcnary/include/node_list.h
+++ b/libcnary/include/node_list.h
@@ -24,24 +24,27 @@
24#ifndef NODE_LIST_H_ 24#ifndef NODE_LIST_H_
25#define NODE_LIST_H_ 25#define NODE_LIST_H_
26 26
27struct node_t; 27#include "node.h"
28
29typedef struct node* node_t;
28 30
29// This class implements the list_t abstract class 31// This class implements the list_t abstract class
30typedef struct node_list_t { 32struct node_list {
31 // list_t members 33 // list_t members
32 struct node_t* begin; 34 node_t begin;
33 struct node_t* end; 35 node_t end;
34 36
35 // node_list_t members 37 // node_list_t members
36 unsigned int count; 38 unsigned int count;
37 39
38} node_list_t; 40};
41typedef struct node_list* node_list_t;
39 42
40void node_list_destroy(struct node_list_t* list); 43void node_list_destroy(node_list_t list);
41struct node_list_t* node_list_create(); 44node_list_t node_list_create();
42 45
43int node_list_add(node_list_t* list, node_t* node); 46int node_list_add(node_list_t list, node_t node);
44int node_list_insert(node_list_t* list, unsigned int index, node_t* node); 47int node_list_insert(node_list_t list, unsigned int index, node_t node);
45int node_list_remove(node_list_t* list, node_t* node); 48int node_list_remove(node_list_t list, node_t node);
46 49
47#endif /* NODE_LIST_H_ */ 50#endif /* NODE_LIST_H_ */
diff --git a/libcnary/node.c b/libcnary/node.c
index 6d68f6e..8d3708b 100644
--- a/libcnary/node.c
+++ b/libcnary/node.c
@@ -27,11 +27,12 @@
27#include "node.h" 27#include "node.h"
28#include "node_list.h" 28#include "node_list.h"
29 29
30void node_destroy(node_t* node) { 30void node_destroy(node_t node)
31{
31 if(!node) return; 32 if(!node) return;
32 33
33 if (node->children && node->children->count > 0) { 34 if (node->children && node->children->count > 0) {
34 node_t* ch; 35 node_t ch;
35 while ((ch = node->children->begin)) { 36 while ((ch = node->children->begin)) {
36 node_list_remove(node->children, ch); 37 node_list_remove(node->children, ch);
37 node_destroy(ch); 38 node_destroy(ch);
@@ -43,10 +44,11 @@ void node_destroy(node_t* node) {
43 free(node); 44 free(node);
44} 45}
45 46
46node_t* node_create(node_t* parent, void* data) { 47node_t node_create(node_t parent, void* data)
48{
47 int error = 0; 49 int error = 0;
48 50
49 node_t* node = (node_t*)calloc(1, sizeof(node_t)); 51 node_t node = (node_t)calloc(1, sizeof(struct node));
50 if (node == NULL) { 52 if (node == NULL) {
51 return NULL; 53 return NULL;
52 } 54 }
@@ -73,7 +75,8 @@ node_t* node_create(node_t* parent, void* data) {
73 return node; 75 return node;
74} 76}
75 77
76int node_attach(node_t* parent, node_t* child) { 78int node_attach(node_t parent, node_t child)
79{
77 if (!parent || !child) return -1; 80 if (!parent || !child) return -1;
78 child->parent = parent; 81 child->parent = parent;
79 if(!parent->children) { 82 if(!parent->children) {
@@ -86,7 +89,8 @@ int node_attach(node_t* parent, node_t* child) {
86 return res; 89 return res;
87} 90}
88 91
89int node_detach(node_t* parent, node_t* child) { 92int node_detach(node_t parent, node_t child)
93{
90 if (!parent || !child) return -1; 94 if (!parent || !child) return -1;
91 int node_index = node_list_remove(parent->children, child); 95 int node_index = node_list_remove(parent->children, child);
92 if (node_index >= 0) { 96 if (node_index >= 0) {
@@ -95,7 +99,7 @@ int node_detach(node_t* parent, node_t* child) {
95 return node_index; 99 return node_index;
96} 100}
97 101
98int node_insert(node_t* parent, unsigned int node_index, node_t* child) 102int node_insert(node_t parent, unsigned int node_index, node_t child)
99{ 103{
100 if (!parent || !child) return -1; 104 if (!parent || !child) return -1;
101 child->parent = parent; 105 child->parent = parent;
@@ -109,9 +113,10 @@ int node_insert(node_t* parent, unsigned int node_index, node_t* child)
109 return res; 113 return res;
110} 114}
111 115
112static void _node_debug(node_t* node, unsigned int depth) { 116static void _node_debug(node_t node, unsigned int depth)
117{
113 unsigned int i = 0; 118 unsigned int i = 0;
114 node_t* current = NULL; 119 node_t current = NULL;
115 for(i = 0; i < depth; i++) { 120 for(i = 0; i < depth; i++) {
116 printf("\t"); 121 printf("\t");
117 } 122 }
@@ -132,23 +137,23 @@ static void _node_debug(node_t* node, unsigned int depth) {
132 137
133} 138}
134 139
135void node_debug(node_t* node) 140void node_debug(node_t node)
136{ 141{
137 _node_debug(node, 0); 142 _node_debug(node, 0);
138} 143}
139 144
140unsigned int node_n_children(struct node_t* node) 145unsigned int node_n_children(node_t node)
141{ 146{
142 if (!node) return 0; 147 if (!node) return 0;
143 return node->count; 148 return node->count;
144} 149}
145 150
146node_t* node_nth_child(struct node_t* node, unsigned int n) 151node_t node_nth_child(node_t node, unsigned int n)
147{ 152{
148 if (!node || !node->children || !node->children->begin) return NULL; 153 if (!node || !node->children || !node->children->begin) return NULL;
149 unsigned int node_index = 0; 154 unsigned int node_index = 0;
150 int found = 0; 155 int found = 0;
151 node_t *ch; 156 node_t ch;
152 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 157 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
153 if (node_index++ == n) { 158 if (node_index++ == n) {
154 found = 1; 159 found = 1;
@@ -161,30 +166,30 @@ node_t* node_nth_child(struct node_t* node, unsigned int n)
161 return ch; 166 return ch;
162} 167}
163 168
164node_t* node_first_child(struct node_t* node) 169node_t node_first_child(node_t node)
165{ 170{
166 if (!node || !node->children) return NULL; 171 if (!node || !node->children) return NULL;
167 return node->children->begin; 172 return node->children->begin;
168} 173}
169 174
170node_t* node_prev_sibling(struct node_t* node) 175node_t node_prev_sibling(node_t node)
171{ 176{
172 if (!node) return NULL; 177 if (!node) return NULL;
173 return node->prev; 178 return node->prev;
174} 179}
175 180
176node_t* node_next_sibling(struct node_t* node) 181node_t node_next_sibling(node_t node)
177{ 182{
178 if (!node) return NULL; 183 if (!node) return NULL;
179 return node->next; 184 return node->next;
180} 185}
181 186
182int node_child_position(struct node_t* parent, node_t* child) 187int node_child_position(node_t parent, node_t child)
183{ 188{
184 if (!parent || !parent->children || !parent->children->begin || !child) return -1; 189 if (!parent || !parent->children || !parent->children->begin || !child) return -1;
185 int node_index = 0; 190 int node_index = 0;
186 int found = 0; 191 int found = 0;
187 node_t *ch; 192 node_t ch;
188 for (ch = node_first_child(parent); ch; ch = node_next_sibling(ch)) { 193 for (ch = node_first_child(parent); ch; ch = node_next_sibling(ch)) {
189 if (ch == child) { 194 if (ch == child) {
190 found = 1; 195 found = 1;
@@ -198,17 +203,17 @@ int node_child_position(struct node_t* parent, node_t* child)
198 return node_index; 203 return node_index;
199} 204}
200 205
201node_t* node_copy_deep(node_t* node, copy_func_t copy_func) 206node_t node_copy_deep(node_t node, copy_func_t copy_func)
202{ 207{
203 if (!node) return NULL; 208 if (!node) return NULL;
204 void *data = NULL; 209 void *data = NULL;
205 if (copy_func) { 210 if (copy_func) {
206 data = copy_func(node->data); 211 data = copy_func(node->data);
207 } 212 }
208 node_t* copy = node_create(NULL, data); 213 node_t copy = node_create(NULL, data);
209 node_t* ch; 214 node_t ch;
210 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 215 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
211 node_t* cc = node_copy_deep(ch, copy_func); 216 node_t cc = node_copy_deep(ch, copy_func);
212 node_attach(copy, cc); 217 node_attach(copy, cc);
213 } 218 }
214 return copy; 219 return copy;
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index aee3bd6..f6c2c70 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -28,12 +28,14 @@
28#include "node.h" 28#include "node.h"
29#include "node_list.h" 29#include "node_list.h"
30 30
31void node_list_destroy(node_list_t* list) { 31void node_list_destroy(node_list_t list)
32{
32 free(list); 33 free(list);
33} 34}
34 35
35node_list_t* node_list_create() { 36node_list_t node_list_create()
36 node_list_t* list = (node_list_t*)calloc(1, sizeof(node_list_t)); 37{
38 node_list_t list = (node_list_t)calloc(1, sizeof(struct node_list));
37 if (list == NULL) { 39 if (list == NULL) {
38 return NULL; 40 return NULL;
39 } 41 }
@@ -45,11 +47,12 @@ node_list_t* node_list_create() {
45 return list; 47 return list;
46} 48}
47 49
48int node_list_add(node_list_t* list, node_t* node) { 50int node_list_add(node_list_t list, node_t node)
51{
49 if (!list || !node) return -1; 52 if (!list || !node) return -1;
50 53
51 // Find the last element in the list 54 // Find the last element in the list
52 node_t* last = list->end; 55 node_t last = list->end;
53 56
54 // Setup our new node as the new last element 57 // Setup our new node as the new last element
55 node->next = NULL; 58 node->next = NULL;
@@ -72,17 +75,18 @@ int node_list_add(node_list_t* list, node_t* node) {
72 return 0; 75 return 0;
73} 76}
74 77
75int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) { 78int node_list_insert(node_list_t list, unsigned int node_index, node_t node)
79{
76 if (!list || !node) return -1; 80 if (!list || !node) return -1;
77 if (node_index >= list->count) { 81 if (node_index >= list->count) {
78 return node_list_add(list, node); 82 return node_list_add(list, node);
79 } 83 }
80 84
81 // Get the first element in the list 85 // Get the first element in the list
82 node_t* cur = list->begin; 86 node_t cur = list->begin;
83 87
84 unsigned int pos = 0; 88 unsigned int pos = 0;
85 node_t* prev = NULL; 89 node_t prev = NULL;
86 90
87 if (node_index > 0) { 91 if (node_index > 0) {
88 while (pos < node_index) { 92 while (pos < node_index) {
@@ -120,15 +124,16 @@ int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) {
120 return 0; 124 return 0;
121} 125}
122 126
123int node_list_remove(node_list_t* list, node_t* node) { 127int node_list_remove(node_list_t list, node_t node)
128{
124 if (!list || !node) return -1; 129 if (!list || !node) return -1;
125 if (list->count == 0) return -1; 130 if (list->count == 0) return -1;
126 131
127 int node_index = 0; 132 int node_index = 0;
128 node_t* n; 133 node_t n;
129 for (n = list->begin; n; n = n->next) { 134 for (n = list->begin; n; n = n->next) {
130 if (node == n) { 135 if (node == n) {
131 node_t* newnode = node->next; 136 node_t newnode = node->next;
132 if (node->prev) { 137 if (node->prev) {
133 node->prev->next = newnode; 138 node->prev->next = newnode;
134 if (newnode) { 139 if (newnode) {
@@ -153,4 +158,3 @@ int node_list_remove(node_list_t* list, node_t* node) {
153 } 158 }
154 return -1; 159 return -1;
155} 160}
156
diff --git a/src/bplist.c b/src/bplist.c
index c0d0fc8..ff0b399 100644
--- a/src/bplist.c
+++ b/src/bplist.c
@@ -191,7 +191,7 @@ static int uint64_mul_overflow(uint64_t a, uint64_t b, uint64_t *res)
191} 191}
192#endif 192#endif
193 193
194#define NODE_IS_ROOT(x) (((node_t*)(x))->isRoot) 194#define NODE_IS_ROOT(x) (((node_t)(x))->isRoot)
195 195
196struct bplist_data { 196struct bplist_data {
197 const char* data; 197 const char* data;
@@ -936,7 +936,7 @@ struct serialize_s
936 hashtable_t* ref_table; 936 hashtable_t* ref_table;
937}; 937};
938 938
939static void serialize_plist(node_t* node, void* data) 939static void serialize_plist(node_t node, void* data)
940{ 940{
941 uint64_t *index_val = NULL; 941 uint64_t *index_val = NULL;
942 struct serialize_s *ser = (struct serialize_s *) data; 942 struct serialize_s *ser = (struct serialize_s *) data;
@@ -959,7 +959,7 @@ static void serialize_plist(node_t* node, void* data)
959 ptr_array_add(ser->objects, node); 959 ptr_array_add(ser->objects, node);
960 960
961 //now recurse on children 961 //now recurse on children
962 node_t *ch; 962 node_t ch;
963 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 963 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
964 serialize_plist(ch, data); 964 serialize_plist(ch, data);
965 } 965 }
@@ -1111,9 +1111,9 @@ static void write_unicode(bytearray_t * bplist, char *val, uint64_t size)
1111 free(unicodestr); 1111 free(unicodestr);
1112} 1112}
1113 1113
1114static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) 1114static void write_array(bytearray_t * bplist, node_t node, hashtable_t* ref_table, uint8_t ref_size)
1115{ 1115{
1116 node_t* cur = NULL; 1116 node_t cur = NULL;
1117 uint64_t i = 0; 1117 uint64_t i = 0;
1118 1118
1119 uint64_t size = node_n_children(node); 1119 uint64_t size = node_n_children(node);
@@ -1130,9 +1130,9 @@ static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_tab
1130 } 1130 }
1131} 1131}
1132 1132
1133static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_table, uint8_t ref_size) 1133static void write_dict(bytearray_t * bplist, node_t node, hashtable_t* ref_table, uint8_t ref_size)
1134{ 1134{
1135 node_t* cur = NULL; 1135 node_t cur = NULL;
1136 uint64_t i = 0; 1136 uint64_t i = 0;
1137 1137
1138 uint64_t size = node_n_children(node) / 2; 1138 uint64_t size = node_n_children(node) / 2;
@@ -1235,7 +1235,7 @@ PLIST_API plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * l
1235 uint64_t req = 0; 1235 uint64_t req = 0;
1236 for (i = 0; i < num_objects; i++) 1236 for (i = 0; i < num_objects; i++)
1237 { 1237 {
1238 node_t* node = ptr_array_index(objects, i); 1238 node_t node = ptr_array_index(objects, i);
1239 plist_data_t data = plist_get_data(node); 1239 plist_data_t data = plist_get_data(node);
1240 uint64_t size; 1240 uint64_t size;
1241 uint8_t bsize; 1241 uint8_t bsize;
diff --git a/src/jplist.c b/src/jplist.c
index 23fb45b..99a8877 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -34,7 +34,6 @@
34#include <limits.h> 34#include <limits.h>
35 35
36#include <node.h> 36#include <node.h>
37#include <node_list.h>
38 37
39#include "plist.h" 38#include "plist.h"
40#include "strbuf.h" 39#include "strbuf.h"
@@ -101,7 +100,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
101 return len; 100 return len;
102} 101}
103 102
104static int node_to_json(node_t* node, bytearray_t **outbuf, uint32_t depth, int prettify) 103static int node_to_json(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
105{ 104{
106 plist_data_t node_data = NULL; 105 plist_data_t node_data = NULL;
107 106
@@ -185,7 +184,7 @@ static int node_to_json(node_t* node, bytearray_t **outbuf, uint32_t depth, int
185 184
186 case PLIST_ARRAY: { 185 case PLIST_ARRAY: {
187 str_buf_append(*outbuf, "[", 1); 186 str_buf_append(*outbuf, "[", 1);
188 node_t *ch; 187 node_t ch;
189 uint32_t cnt = 0; 188 uint32_t cnt = 0;
190 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 189 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
191 if (cnt > 0) { 190 if (cnt > 0) {
@@ -213,7 +212,7 @@ static int node_to_json(node_t* node, bytearray_t **outbuf, uint32_t depth, int
213 } break; 212 } break;
214 case PLIST_DICT: { 213 case PLIST_DICT: {
215 str_buf_append(*outbuf, "{", 1); 214 str_buf_append(*outbuf, "{", 1);
216 node_t *ch; 215 node_t ch;
217 uint32_t cnt = 0; 216 uint32_t cnt = 0;
218 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 217 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
219 if (cnt > 0 && cnt % 2 == 0) { 218 if (cnt > 0 && cnt % 2 == 0) {
@@ -302,7 +301,7 @@ static int num_digits_u(uint64_t i)
302 return n; 301 return n;
303} 302}
304 303
305static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth, int prettify) 304static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
306{ 305{
307 plist_data_t data; 306 plist_data_t data;
308 if (!node) { 307 if (!node) {
@@ -310,7 +309,7 @@ static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth, int
310 } 309 }
311 data = plist_get_data(node); 310 data = plist_get_data(node);
312 if (node->children) { 311 if (node->children) {
313 node_t *ch; 312 node_t ch;
314 unsigned int n_children = node_n_children(node); 313 unsigned int n_children = node_n_children(node);
315 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 314 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
316 int res = node_estimate_size(ch, size, depth + 1, prettify); 315 int res = node_estimate_size(ch, size, depth + 1, prettify);
diff --git a/src/oplist.c b/src/oplist.c
index 420cbd6..287d5a2 100644
--- a/src/oplist.c
+++ b/src/oplist.c
@@ -34,7 +34,6 @@
34#include <limits.h> 34#include <limits.h>
35 35
36#include <node.h> 36#include <node.h>
37#include <node_list.h>
38 37
39#include "plist.h" 38#include "plist.h"
40#include "strbuf.h" 39#include "strbuf.h"
@@ -130,7 +129,7 @@ static int str_needs_quotes(const char* str, size_t len)
130 return 0; 129 return 0;
131} 130}
132 131
133static int node_to_openstep(node_t* node, bytearray_t **outbuf, uint32_t depth, int prettify) 132static int node_to_openstep(node_t node, bytearray_t **outbuf, uint32_t depth, int prettify)
134{ 133{
135 plist_data_t node_data = NULL; 134 plist_data_t node_data = NULL;
136 135
@@ -209,7 +208,7 @@ static int node_to_openstep(node_t* node, bytearray_t **outbuf, uint32_t depth,
209 208
210 case PLIST_ARRAY: { 209 case PLIST_ARRAY: {
211 str_buf_append(*outbuf, "(", 1); 210 str_buf_append(*outbuf, "(", 1);
212 node_t *ch; 211 node_t ch;
213 uint32_t cnt = 0; 212 uint32_t cnt = 0;
214 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 213 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
215 if (cnt > 0) { 214 if (cnt > 0) {
@@ -237,7 +236,7 @@ static int node_to_openstep(node_t* node, bytearray_t **outbuf, uint32_t depth,
237 } break; 236 } break;
238 case PLIST_DICT: { 237 case PLIST_DICT: {
239 str_buf_append(*outbuf, "{", 1); 238 str_buf_append(*outbuf, "{", 1);
240 node_t *ch; 239 node_t ch;
241 uint32_t cnt = 0; 240 uint32_t cnt = 0;
242 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 241 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
243 if (cnt > 0 && cnt % 2 == 0) { 242 if (cnt > 0 && cnt % 2 == 0) {
@@ -346,7 +345,7 @@ static int num_digits_u(uint64_t i)
346 return n; 345 return n;
347} 346}
348 347
349static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth, int prettify) 348static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth, int prettify)
350{ 349{
351 plist_data_t data; 350 plist_data_t data;
352 if (!node) { 351 if (!node) {
@@ -354,7 +353,7 @@ static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth, int
354 } 353 }
355 data = plist_get_data(node); 354 data = plist_get_data(node);
356 if (node->children) { 355 if (node->children) {
357 node_t *ch; 356 node_t ch;
358 unsigned int n_children = node_n_children(node); 357 unsigned int n_children = node_n_children(node);
359 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 358 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
360 int res = node_estimate_size(ch, size, depth + 1, prettify); 359 int res = node_estimate_size(ch, size, depth + 1, prettify);
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
272plist_data_t plist_new_plist_data(void) 272plist_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
329static int plist_free_node(node_t* node) 329static 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
471static plist_t plist_copy_node(node_t *node) 471static 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
579static void _plist_array_post_insert(plist_t node, plist_t item, long n) 579static 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
680PLIST_API void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item) 680PLIST_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
718PLIST_API void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val) 718PLIST_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)
799PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item) 799PLIST_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
962PLIST_API plist_t plist_get_parent(plist_t node) 962PLIST_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
967PLIST_API plist_type plist_get_node_type(plist_t node) 967PLIST_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;
diff --git a/src/xplist.c b/src/xplist.c
index 0a6be57..1abc46d 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -41,7 +41,6 @@
41#include <limits.h> 41#include <limits.h>
42 42
43#include <node.h> 43#include <node.h>
44#include <node_list.h>
45 44
46#include "plist.h" 45#include "plist.h"
47#include "base64.h" 46#include "base64.h"
@@ -127,7 +126,7 @@ static size_t dtostr(char *buf, size_t bufsize, double realval)
127 return len; 126 return len;
128} 127}
129 128
130static int node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth) 129static int node_to_xml(node_t node, bytearray_t **outbuf, uint32_t depth)
131{ 130{
132 plist_data_t node_data = NULL; 131 plist_data_t node_data = NULL;
133 132
@@ -358,7 +357,7 @@ static int node_to_xml(node_t* node, bytearray_t **outbuf, uint32_t depth)
358 if (node_data->type == PLIST_DICT && node->children) { 357 if (node_data->type == PLIST_DICT && node->children) {
359 assert((node->children->count % 2) == 0); 358 assert((node->children->count % 2) == 0);
360 } 359 }
361 node_t *ch; 360 node_t ch;
362 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 361 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
363 int res = node_to_xml(ch, outbuf, depth+1); 362 int res = node_to_xml(ch, outbuf, depth+1);
364 if (res < 0) return res; 363 if (res < 0) return res;
@@ -438,7 +437,7 @@ static int num_digits_u(uint64_t i)
438 return n; 437 return n;
439} 438}
440 439
441static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth) 440static int node_estimate_size(node_t node, uint64_t *size, uint32_t depth)
442{ 441{
443 plist_data_t data; 442 plist_data_t data;
444 if (!node) { 443 if (!node) {
@@ -446,7 +445,7 @@ static int node_estimate_size(node_t *node, uint64_t *size, uint32_t depth)
446 } 445 }
447 data = plist_get_data(node); 446 data = plist_get_data(node);
448 if (node->children) { 447 if (node->children) {
449 node_t *ch; 448 node_t ch;
450 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) { 449 for (ch = node_first_child(node); ch; ch = node_next_sibling(ch)) {
451 node_estimate_size(ch, size, depth + 1); 450 node_estimate_size(ch, size, depth + 1);
452 } 451 }
@@ -1413,7 +1412,7 @@ static int node_from_xml(parse_ctx ctx, plist_t *plist)
1413 node_path = node_path->prev; 1412 node_path = node_path->prev;
1414 free(path_item); 1413 free(path_item);
1415 1414
1416 parent = ((node_t*)parent)->parent; 1415 parent = ((node_t)parent)->parent;
1417 if (!parent) { 1416 if (!parent) {
1418 goto err_out; 1417 goto err_out;
1419 } 1418 }
diff --git a/test/plist_cmp.c b/test/plist_cmp.c
index 1b4a36a..4947276 100644
--- a/test/plist_cmp.c
+++ b/test/plist_cmp.c
@@ -35,12 +35,12 @@
35 35
36static plist_t plist_get_first_child(plist_t node) 36static plist_t plist_get_first_child(plist_t node)
37{ 37{
38 return (plist_t) node_first_child((node_t*) node); 38 return (plist_t) node_first_child((node_t) node);
39} 39}
40 40
41static plist_t plist_get_next_sibling(plist_t node) 41static plist_t plist_get_next_sibling(plist_t node)
42{ 42{
43 return (plist_t) node_next_sibling((node_t*) node); 43 return (plist_t) node_next_sibling((node_t) node);
44} 44}
45 45
46static char compare_plist(plist_t node_l, plist_t node_r) 46static char compare_plist(plist_t node_l, plist_t node_r)