plistutil: Add -p command line switch to print plist in human-readable format
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 @@
     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 @@
         {
             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 @@
                 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;
             }
         }
     }