diff options
| author | 2026-03-22 19:16:51 +0100 | |
|---|---|---|
| committer | 2026-03-22 19:16:51 +0100 | |
| commit | c8b36a80bad4a1fe488927af4da0ecbcf10079bb (patch) | |
| tree | 657066f92a85dc43bd51af7698e76d00c29c0b4a /tools/plistutil.c | |
| parent | 3edac28498d883f1f768699ee15ce85a82bb2a7b (diff) | |
| download | libplist-c8b36a80bad4a1fe488927af4da0ecbcf10079bb.tar.gz libplist-c8b36a80bad4a1fe488927af4da0ecbcf10079bb.tar.bz2 | |
Add OpenStep coercion support for non-OpenStep plist types
- Use PLIST_OPT_COERCE option to coerce PLIST_BOOLEAN, PLIST_DATE, PLIST_UID, and PLIST_NULL to OpenStep-compatible types (1 or 0, ISO 8601 strings, integers, and 'NULL' string)
- Add plist_to_openstep_with_options() function to allow passing coercion option (and others)
- Update plist_write_to_string() and plist_write_to_stream() accordingly
Diffstat (limited to 'tools/plistutil.c')
| -rw-r--r-- | tools/plistutil.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c index fef72b7..95ec254 100644 --- a/tools/plistutil.c +++ b/tools/plistutil.c | |||
| @@ -75,10 +75,14 @@ static void print_usage(int argc, char *argv[]) | |||
| 75 | printf(" -n, --nodepath PATH Restrict output to nodepath defined by PATH.\n"); | 75 | printf(" -n, --nodepath PATH Restrict output to nodepath defined by PATH.\n"); |
| 76 | printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n"); | 76 | printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n"); |
| 77 | printf(" By default, the output will be pretty-printed.\n"); | 77 | printf(" By default, the output will be pretty-printed.\n"); |
| 78 | printf(" -C, --coerce JSON only: Coerce non-JSON plist types to JSON-compatible\n"); | 78 | printf(" -C, --coerce JSON + OpenStep only: Coerce non-compatible plist types\n"); |
| 79 | printf(" representations. Date values become ISO 8601 strings,\n"); | 79 | printf(" to JSON/OpenStep compatible representations.\n"); |
| 80 | printf(" data values become Base64-encoded strings, and UID values\n"); | 80 | printf(" Date values become ISO 8601 strings,\n"); |
| 81 | printf(" become integers. Implied when invoked as plist2json.\n"); | 81 | printf(" data values become Base64-encoded strings (JSON),\n"); |
| 82 | printf(" UID values become integers,\n"); | ||
| 83 | printf(" boolean becomes 1 or 0 (OpenStep),\n"); | ||
| 84 | printf(" and NULL becomes a string 'NULL' (OpenStep)\n"); | ||
| 85 | printf(" This options is implied when invoked as plist2json.\n"); | ||
| 82 | printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n"); | 86 | printf(" -s, --sort Sort all dictionary nodes lexicographically by key\n"); |
| 83 | printf(" before converting to the output format.\n"); | 87 | printf(" before converting to the output format.\n"); |
| 84 | printf(" -d, --debug Enable extended debug output\n"); | 88 | printf(" -d, --debug Enable extended debug output\n"); |
| @@ -431,7 +435,10 @@ int main(int argc, char *argv[]) | |||
| 431 | if (options->flags & OPT_COERCE) wropts |= PLIST_OPT_COERCE; | 435 | if (options->flags & OPT_COERCE) wropts |= PLIST_OPT_COERCE; |
| 432 | output_res = plist_to_json_with_options(root_node, &plist_out, &size, wropts); | 436 | output_res = plist_to_json_with_options(root_node, &plist_out, &size, wropts); |
| 433 | } else if (options->out_fmt == PLIST_FORMAT_OSTEP) { | 437 | } else if (options->out_fmt == PLIST_FORMAT_OSTEP) { |
| 434 | output_res = plist_to_openstep(root_node, &plist_out, &size, !(options->flags & OPT_COMPACT)); | 438 | plist_write_options_t wropts = PLIST_OPT_NONE; |
| 439 | if (options->flags & OPT_COMPACT) wropts |= PLIST_OPT_COMPACT; | ||
| 440 | if (options->flags & OPT_COERCE) wropts |= PLIST_OPT_COERCE; | ||
| 441 | output_res = plist_to_openstep_with_options(root_node, &plist_out, &size, wropts); | ||
| 435 | } else { | 442 | } else { |
| 436 | plist_write_to_stream(root_node, stdout, options->out_fmt, PLIST_OPT_PARTIAL_DATA); | 443 | plist_write_to_stream(root_node, stdout, options->out_fmt, PLIST_OPT_PARTIAL_DATA); |
| 437 | plist_free(root_node); | 444 | plist_free(root_node); |
