summaryrefslogtreecommitdiffstats
path: root/test/plist_cmp.c
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-10-28 18:31:34 +0100
committerGravatar Jonathan Beck2009-10-28 18:31:34 +0100
commit6710f4bfb980dd0fe6e75e4d6cba75532cde30e8 (patch)
tree6429eb306d3d464ebbcc0de558559b636d8058c2 /test/plist_cmp.c
parentfed2573566c2da1c5489260069a99ae9d2abf255 (diff)
downloadlibplist-6710f4bfb980dd0fe6e75e4d6cba75532cde30e8.tar.gz
libplist-6710f4bfb980dd0fe6e75e4d6cba75532cde30e8.tar.bz2
Format sources to ANSI style using AStyle (astyle --style=ansi).
Diffstat (limited to 'test/plist_cmp.c')
-rw-r--r--test/plist_cmp.c200
1 files changed, 102 insertions, 98 deletions
diff --git a/test/plist_cmp.c b/test/plist_cmp.c
index 386264a..709e8d0 100644
--- a/test/plist_cmp.c
+++ b/test/plist_cmp.c
@@ -8,15 +8,15 @@
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details. 15 * Lesser General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Lesser General Public 17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22 22
@@ -33,110 +33,114 @@
33 33
34char compare_plist(plist_t node_l, plist_t node_r) 34char compare_plist(plist_t node_l, plist_t node_r)
35{ 35{
36 plist_t cur_l = NULL; 36 plist_t cur_l = NULL;
37 plist_t cur_r = NULL; 37 plist_t cur_r = NULL;
38 int res = 1; 38 int res = 1;
39 39
40 cur_l = plist_get_first_child(node_l); 40 cur_l = plist_get_first_child(node_l);
41 cur_r = plist_get_first_child(node_r); 41 cur_r = plist_get_first_child(node_r);
42 42
43 if ( (!cur_l && cur_r) || (cur_l && !cur_r)) 43 if ( (!cur_l && cur_r) || (cur_l && !cur_r))
44 return 0; 44 return 0;
45 45
46 if ( !cur_l && !cur_r ) 46 if ( !cur_l && !cur_r )
47 return plist_compare_node_value( node_l, node_r ); 47 return plist_compare_node_value( node_l, node_r );
48 48
49 while(cur_l && cur_r && res) { 49 while (cur_l && cur_r && res)
50 {
50 51
51 if (!(res = compare_plist(cur_l, cur_r))) 52 if (!(res = compare_plist(cur_l, cur_r)))
52 return res; 53 return res;
53 54
54 cur_l = plist_get_next_sibling(cur_l); 55 cur_l = plist_get_next_sibling(cur_l);
55 cur_r = plist_get_next_sibling(cur_r); 56 cur_r = plist_get_next_sibling(cur_r);
56 if ( (!cur_l && cur_r) || (cur_l && !cur_r)) 57 if ( (!cur_l && cur_r) || (cur_l && !cur_r))
57 return 0; 58 return 0;
58 } 59 }
59 60
60 return res; 61 return res;
61} 62}
62 63
63int main(int argc, char *argv[]) 64int main(int argc, char *argv[])
64{ 65{
65 FILE *iplist1 = NULL; 66 FILE *iplist1 = NULL;
66 FILE *iplist2 = NULL; 67 FILE *iplist2 = NULL;
67 plist_t root_node1 = NULL; 68 plist_t root_node1 = NULL;
68 plist_t root_node2 = NULL; 69 plist_t root_node2 = NULL;
69 char *plist_1 = NULL; 70 char *plist_1 = NULL;
70 char *plist_2 = NULL; 71 char *plist_2 = NULL;
71 int size_in1 = 0; 72 int size_in1 = 0;
72 int size_in2 = 0; 73 int size_in2 = 0;
73 char *file_in1 = NULL; 74 char *file_in1 = NULL;
74 char *file_in2 = NULL; 75 char *file_in2 = NULL;
75 int res = 0; 76 int res = 0;
76 77
77 struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat)); 78 struct stat *filestats1 = (struct stat *) malloc(sizeof(struct stat));
78 struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat)); 79 struct stat *filestats2 = (struct stat *) malloc(sizeof(struct stat));
79 80
80 if (argc!= 3) { 81 if (argc!= 3)
81 printf("Wrong input\n"); 82 {
82 return 1; 83 printf("Wrong input\n");
83 } 84 return 1;
84 85 }
85 file_in1 = argv[1]; 86
86 file_in2 = argv[2]; 87 file_in1 = argv[1];
87 88 file_in2 = argv[2];
88 //read input file 89
89 iplist1 = fopen(file_in1, "rb"); 90 //read input file
90 iplist2 = fopen(file_in2, "rb"); 91 iplist1 = fopen(file_in1, "rb");
91 92 iplist2 = fopen(file_in2, "rb");
92 if (!iplist1 || !iplist2) { 93
93 printf("File does not exists\n"); 94 if (!iplist1 || !iplist2)
94 return 2; 95 {
95 } 96 printf("File does not exists\n");
96 97 return 2;
97 stat(file_in1, filestats1); 98 }
98 stat(file_in2, filestats2); 99
99 100 stat(file_in1, filestats1);
100 size_in1 = filestats1->st_size; 101 stat(file_in2, filestats2);
101 size_in2 = filestats2->st_size; 102
102 103 size_in1 = filestats1->st_size;
103 plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1)); 104 size_in2 = filestats2->st_size;
104 plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1)); 105
105 106 plist_1 = (char *) malloc(sizeof(char) * (size_in1 + 1));
106 fread(plist_1, sizeof(char), size_in1, iplist1); 107 plist_2 = (char *) malloc(sizeof(char) * (size_in2 + 1));
107 fread(plist_2, sizeof(char), size_in2, iplist2); 108
108 109 fread(plist_1, sizeof(char), size_in1, iplist1);
109 fclose(iplist1); 110 fread(plist_2, sizeof(char), size_in2, iplist2);
110 fclose(iplist2); 111
111 112 fclose(iplist1);
112 if (memcmp(plist_1, "bplist00", 8) == 0) 113 fclose(iplist2);
113 plist_from_bin(plist_1, size_in1, &root_node1); 114
114 else 115 if (memcmp(plist_1, "bplist00", 8) == 0)
115 plist_from_xml(plist_1, size_in1, &root_node1); 116 plist_from_bin(plist_1, size_in1, &root_node1);
116 117 else
117 if (memcmp(plist_2, "bplist00", 8) == 0) 118 plist_from_xml(plist_1, size_in1, &root_node1);
118 plist_from_bin(plist_2, size_in2, &root_node2); 119
119 else 120 if (memcmp(plist_2, "bplist00", 8) == 0)
120 plist_from_xml(plist_2, size_in2, &root_node2); 121 plist_from_bin(plist_2, size_in2, &root_node2);
121 122 else
122 if (!root_node1 || !root_node2) { 123 plist_from_xml(plist_2, size_in2, &root_node2);
123 printf("PList parsing failed\n"); 124
124 return 3; 125 if (!root_node1 || !root_node2)
125 } 126 {
126 else 127 printf("PList parsing failed\n");
127 printf("PList parsing succeeded\n"); 128 return 3;
128 129 }
129 res = compare_plist(root_node1, root_node2); 130 else
130 131 printf("PList parsing succeeded\n");
131 132
132 plist_free(root_node1); 133 res = compare_plist(root_node1, root_node2);
133 plist_free(root_node2); 134
134 135
135 free(plist_1); 136 plist_free(root_node1);
136 free(plist_2); 137 plist_free(root_node2);
137 free(filestats1); 138
138 free(filestats2); 139 free(plist_1);
139 140 free(plist_2);
140 return !res; 141 free(filestats1);
142 free(filestats2);
143
144 return !res;
141} 145}
142 146