summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/plistutil.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index 6254b7c..1c199fe 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -41,10 +41,12 @@
41typedef struct _options 41typedef struct _options
42{ 42{
43 char *in_file, *out_file; 43 char *in_file, *out_file;
44 uint8_t debug;
45 uint8_t compact;
46 uint8_t in_fmt, out_fmt; // fmts 0 = undef, 1 = bin, 2 = xml, 3 = json, 4 = openstep 44 uint8_t in_fmt, out_fmt; // fmts 0 = undef, 1 = bin, 2 = xml, 3 = json, 4 = openstep
45 uint8_t flags;
47} options_t; 46} options_t;
47#define OPT_DEBUG (1 << 0)
48#define OPT_COMPACT (1 << 1)
49#define OPT_SORT (1 << 2)
48 50
49static void print_usage(int argc, char *argv[]) 51static void print_usage(int argc, char *argv[])
50{ 52{
@@ -65,6 +67,8 @@ static void print_usage(int argc, char *argv[])
65 printf(" and binary to XML.\n"); 67 printf(" and binary to XML.\n");
66 printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n"); 68 printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n");
67 printf(" By default, the output will be pretty-printed.\n"); 69 printf(" By default, the output will be pretty-printed.\n");
70 printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n");
71 printf(" before converting to the output format.\n");
68 printf(" -d, --debug Enable extended debug output\n"); 72 printf(" -d, --debug Enable extended debug output\n");
69 printf(" -v, --version Print version information\n"); 73 printf(" -v, --version Print version information\n");
70 printf("\n"); 74 printf("\n");
@@ -128,11 +132,15 @@ static options_t *parse_arguments(int argc, char *argv[])
128 } 132 }
129 else if (!strcmp(argv[i], "--compact") || !strcmp(argv[i], "-c")) 133 else if (!strcmp(argv[i], "--compact") || !strcmp(argv[i], "-c"))
130 { 134 {
131 options->compact = 1; 135 options->flags |= OPT_COMPACT;
136 }
137 else if (!strcmp(argv[i], "--sort") || !strcmp(argv[i], "-s"))
138 {
139 options->flags |= OPT_SORT;
132 } 140 }
133 else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) 141 else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d"))
134 { 142 {
135 options->debug = 1; 143 options->flags |= OPT_DEBUG;
136 } 144 }
137 else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) 145 else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
138 { 146 {
@@ -252,6 +260,9 @@ int main(int argc, char *argv[])
252 { 260 {
253 input_res = plist_from_bin(plist_entire, read_size, &root_node); 261 input_res = plist_from_bin(plist_entire, read_size, &root_node);
254 if (input_res == PLIST_ERR_SUCCESS) { 262 if (input_res == PLIST_ERR_SUCCESS) {
263 if (options->flags & OPT_SORT) {
264 plist_sort(root_node);
265 }
255 output_res = plist_to_xml(root_node, &plist_out, &size); 266 output_res = plist_to_xml(root_node, &plist_out, &size);
256 } 267 }
257 } 268 }
@@ -259,6 +270,9 @@ int main(int argc, char *argv[])
259 { 270 {
260 input_res = plist_from_xml(plist_entire, read_size, &root_node); 271 input_res = plist_from_xml(plist_entire, read_size, &root_node);
261 if (input_res == PLIST_ERR_SUCCESS) { 272 if (input_res == PLIST_ERR_SUCCESS) {
273 if (options->flags & OPT_SORT) {
274 plist_sort(root_node);
275 }
262 output_res = plist_to_bin(root_node, &plist_out, &size); 276 output_res = plist_to_bin(root_node, &plist_out, &size);
263 } 277 }
264 } 278 }
@@ -267,14 +281,17 @@ int main(int argc, char *argv[])
267 { 281 {
268 input_res = plist_from_memory(plist_entire, read_size, &root_node); 282 input_res = plist_from_memory(plist_entire, read_size, &root_node);
269 if (input_res == PLIST_ERR_SUCCESS) { 283 if (input_res == PLIST_ERR_SUCCESS) {
284 if (options->flags & OPT_SORT) {
285 plist_sort(root_node);
286 }
270 if (options->out_fmt == 1) { 287 if (options->out_fmt == 1) {
271 output_res = plist_to_bin(root_node, &plist_out, &size); 288 output_res = plist_to_bin(root_node, &plist_out, &size);
272 } else if (options->out_fmt == 2) { 289 } else if (options->out_fmt == 2) {
273 output_res = plist_to_xml(root_node, &plist_out, &size); 290 output_res = plist_to_xml(root_node, &plist_out, &size);
274 } else if (options->out_fmt == 3) { 291 } else if (options->out_fmt == 3) {
275 output_res = plist_to_json(root_node, &plist_out, &size, !options->compact); 292 output_res = plist_to_json(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
276 } else if (options->out_fmt == 4) { 293 } else if (options->out_fmt == 4) {
277 output_res = plist_to_openstep(root_node, &plist_out, &size, !options->compact); 294 output_res = plist_to_openstep(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
278 } 295 }
279 } 296 }
280 } 297 }