summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/plistutil.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index bd83e92..28848fa 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -148,6 +148,8 @@ static options_t *parse_arguments(int argc, char *argv[])
148int main(int argc, char *argv[]) 148int main(int argc, char *argv[])
149{ 149{
150 int ret = 0; 150 int ret = 0;
151 int input_res = PLIST_ERR_UNKNOWN;
152 int output_res = PLIST_ERR_UNKNOWN;
151 FILE *iplist = NULL; 153 FILE *iplist = NULL;
152 plist_t root_node = NULL; 154 plist_t root_node = NULL;
153 char *plist_out = NULL; 155 char *plist_out = NULL;
@@ -251,24 +253,30 @@ int main(int argc, char *argv[])
251 // convert from binary to xml or vice-versa 253 // convert from binary to xml or vice-versa
252 if (plist_is_binary(plist_entire, read_size)) 254 if (plist_is_binary(plist_entire, read_size))
253 { 255 {
254 plist_from_bin(plist_entire, read_size, &root_node); 256 input_res = plist_from_bin(plist_entire, read_size, &root_node);
255 plist_to_xml(root_node, &plist_out, &size); 257 if (input_res == PLIST_ERR_SUCCESS) {
258 output_res = plist_to_xml(root_node, &plist_out, &size);
259 }
256 } 260 }
257 else 261 else
258 { 262 {
259 plist_from_xml(plist_entire, read_size, &root_node); 263 input_res = plist_from_xml(plist_entire, read_size, &root_node);
260 plist_to_bin(root_node, &plist_out, &size); 264 if (input_res == PLIST_ERR_SUCCESS) {
265 output_res = plist_to_bin(root_node, &plist_out, &size);
266 }
261 } 267 }
262 } 268 }
263 else 269 else
264 { 270 {
265 plist_from_memory(plist_entire, read_size, &root_node); 271 input_res = plist_from_memory(plist_entire, read_size, &root_node);
266 if (options->out_fmt == 1) { 272 if (input_res == PLIST_ERR_SUCCESS) {
267 plist_to_bin(root_node, &plist_out, &size); 273 if (options->out_fmt == 1) {
268 } else if (options->out_fmt == 2) { 274 output_res = plist_to_bin(root_node, &plist_out, &size);
269 plist_to_xml(root_node, &plist_out, &size); 275 } else if (options->out_fmt == 2) {
270 } else if (options->out_fmt == 3) { 276 output_res = plist_to_xml(root_node, &plist_out, &size);
271 plist_to_json(root_node, &plist_out, &size, 0); 277 } else if (options->out_fmt == 3) {
278 output_res = plist_to_json(root_node, &plist_out, &size, 0);
279 }
272 } 280 }
273 } 281 }
274 plist_free(root_node); 282 plist_free(root_node);
@@ -293,9 +301,22 @@ int main(int argc, char *argv[])
293 301
294 free(plist_out); 302 free(plist_out);
295 } 303 }
296 else { 304
297 fprintf(stderr, "ERROR: Failed to convert input file.\n"); 305 if (input_res == PLIST_ERR_SUCCESS) {
298 ret = 2; 306 switch (output_res) {
307 case PLIST_ERR_SUCCESS:
308 break;
309 case PLIST_ERR_FORMAT:
310 fprintf(stderr, "ERROR: Input plist data is not compatible with output format.\n");
311 ret = 2;
312 break;
313 default:
314 fprintf(stderr, "ERROR: Failed to convert plist data (%d)\n", output_res);
315 ret = 1;
316 }
317 } else {
318 fprintf(stderr, "ERROR: Could not parse plist data (%d)\n", input_res);
319 ret = 1;
299 } 320 }
300 321
301 free(options); 322 free(options);