From 4af7c9accb2844d9810470e16a4dd7f81ab1f49d Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 21 Apr 2023 13:48:29 +0200 Subject: plistutil: Add -p command line switch to print plist in human-readable format --- tools/plistutil.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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; } } } -- cgit v1.1-32-gdbae