summaryrefslogtreecommitdiffstats
path: root/tools/plistutil.c
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 /tools/plistutil.c
parent8aeda7886c590decfddb86ca2d17333b49f1a9d3 (diff)
downloadlibplist-4af7c9accb2844d9810470e16a4dd7f81ab1f49d.tar.gz
libplist-4af7c9accb2844d9810470e16a4dd7f81ab1f49d.tar.bz2
plistutil: Add -p command line switch to print plist in human-readable format
Diffstat (limited to 'tools/plistutil.c')
-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[])
printf(" FORMAT is one of xml, bin, json, or openstep\n");
printf(" If omitted, XML will be converted to binary,\n");
printf(" and binary to XML.\n");
+ printf(" -p, --print FILE Print the PList in human-readable format.\n");
printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n");
printf(" By default, the output will be pretty-printed.\n");
printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n");
@@ -138,6 +139,26 @@ static options_t *parse_arguments(int argc, char *argv[])
{
options->flags |= OPT_SORT;
}
+ else if (!strcmp(argv[i], "--print") || !strcmp(argv[i], "-p"))
+ {
+ if ((i + 1) == argc)
+ {
+ free(options);
+ return NULL;
+ }
+ options->in_file = argv[i + 1];
+ options->out_fmt = PLIST_FORMAT_PRINT;
+ char *env_fmt = getenv("PLIST_OUTPUT_FORMAT");
+ if (env_fmt) {
+ if (!strcmp(env_fmt, "plutil")) {
+ options->out_fmt = PLIST_FORMAT_PLUTIL;
+ } else if (!strcmp(env_fmt, "limd")) {
+ options->out_fmt = PLIST_FORMAT_LIMD;
+ }
+ }
+ i++;
+ continue;
+ }
else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d"))
{
options->flags |= OPT_DEBUG;
@@ -297,6 +318,12 @@ int main(int argc, char *argv[])
output_res = plist_to_json(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
} else if (options->out_fmt == PLIST_FORMAT_OSTEP) {
output_res = plist_to_openstep(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT));
+ } else {
+ plist_write_to_stream(root_node, stdout, options->out_fmt, PLIST_OPT_PARTIAL_DATA);
+ plist_free(root_node);
+ free(plist_entire);
+ free(options);
+ return 0;
}
}
}