summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-04-21 13:48:29 +0200
committerGravatar Nikias Bassen2023-04-21 13:48:29 +0200
commit4af7c9accb2844d9810470e16a4dd7f81ab1f49d (patch)
treefd57ae5b97a57dd74bed8f87aeaad504128c7d16
parent8aeda7886c590decfddb86ca2d17333b49f1a9d3 (diff)
downloadlibplist-4af7c9accb2844d9810470e16a4dd7f81ab1f49d.tar.gz
libplist-4af7c9accb2844d9810470e16a4dd7f81ab1f49d.tar.bz2
plistutil: Add -p command line switch to print plist in human-readable format
-rw-r--r--tools/plistutil.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index 6da53e4..8121a7d 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -65,6 +65,7 @@ static void print_usage(int argc, char *argv[])
65 printf(" FORMAT is one of xml, bin, json, or openstep\n"); 65 printf(" FORMAT is one of xml, bin, json, or openstep\n");
66 printf(" If omitted, XML will be converted to binary,\n"); 66 printf(" If omitted, XML will be converted to binary,\n");
67 printf(" and binary to XML.\n"); 67 printf(" and binary to XML.\n");
68 printf(" -p, --print FILE Print the PList in human-readable format.\n");
68 printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n"); 69 printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n");
69 printf(" By default, the output will be pretty-printed.\n"); 70 printf(" By default, the output will be pretty-printed.\n");
70 printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n"); 71 printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n");
@@ -138,6 +139,26 @@ static options_t *parse_arguments(int argc, char *argv[])
138 { 139 {
139 options->flags |= OPT_SORT; 140 options->flags |= OPT_SORT;
140 } 141 }
142 else if (!strcmp(argv[i], "--print") || !strcmp(argv[i], "-p"))
143 {
144 if ((i + 1) == argc)
145 {
146 free(options);
147 return NULL;
148 }
149 options->in_file = argv[i + 1];
150 options->out_fmt = PLIST_FORMAT_PRINT;
151 char *env_fmt = getenv("PLIST_OUTPUT_FORMAT");
152 if (env_fmt) {
153 if (!strcmp(env_fmt, "plutil")) {
154 options->out_fmt = PLIST_FORMAT_PLUTIL;
155 } else if (!strcmp(env_fmt, "limd")) {
156 options->out_fmt = PLIST_FORMAT_LIMD;
157 }
158 }
159 i++;
160 continue;
161 }
141 else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) 162 else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d"))
142 { 163 {
143 options->flags |= OPT_DEBUG; 164 options->flags |= OPT_DEBUG;
@@ -297,6 +318,12 @@ int main(int argc, char *argv[])
297 output_res = plist_to_json(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT)); 318 output_res = plist_to_json(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
298 } else if (options->out_fmt == PLIST_FORMAT_OSTEP) { 319 } else if (options->out_fmt == PLIST_FORMAT_OSTEP) {
299 output_res = plist_to_openstep(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT)); 320 output_res = plist_to_openstep(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
321 } else {
322 plist_write_to_stream(root_node, stdout, options->out_fmt, PLIST_OPT_PARTIAL_DATA);
323 plist_free(root_node);
324 free(plist_entire);
325 free(options);
326 return 0;
300 } 327 }
301 } 328 }
302 } 329 }