diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/plistutil.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c index 677e432..6254b7c 100644 --- a/tools/plistutil.c +++ b/tools/plistutil.c | |||
| @@ -41,7 +41,9 @@ | |||
| 41 | typedef struct _options | 41 | typedef struct _options |
| 42 | { | 42 | { |
| 43 | char *in_file, *out_file; | 43 | char *in_file, *out_file; |
| 44 | uint8_t debug, in_fmt, out_fmt; // fmts 0 = undef, 1 = bin, 2 = xml, 3 = json | 44 | uint8_t debug; |
| 45 | uint8_t compact; | ||
| 46 | uint8_t in_fmt, out_fmt; // fmts 0 = undef, 1 = bin, 2 = xml, 3 = json, 4 = openstep | ||
| 45 | } options_t; | 47 | } options_t; |
| 46 | 48 | ||
| 47 | static void print_usage(int argc, char *argv[]) | 49 | static void print_usage(int argc, char *argv[]) |
| @@ -50,17 +52,19 @@ static void print_usage(int argc, char *argv[]) | |||
| 50 | name = strrchr(argv[0], '/'); | 52 | name = strrchr(argv[0], '/'); |
| 51 | printf("Usage: %s [OPTIONS] [-i FILE] [-o FILE]\n", (name ? name + 1: argv[0])); | 53 | printf("Usage: %s [OPTIONS] [-i FILE] [-o FILE]\n", (name ? name + 1: argv[0])); |
| 52 | printf("\n"); | 54 | printf("\n"); |
| 53 | printf("Convert a plist FILE between binary, XML, and JSON format.\n"); | 55 | printf("Convert a plist FILE between binary, XML, JSON, and OpenStep format.\n"); |
| 54 | printf("If -f is omitted, XML plist data will be converted to binary and vice-versa.\n"); | 56 | printf("If -f is omitted, XML plist data will be converted to binary and vice-versa.\n"); |
| 55 | printf("To convert to/from JSON the output format needs to be specified.\n"); | 57 | printf("To convert to/from JSON or OpenStep the output format needs to be specified.\n"); |
| 56 | printf("\n"); | 58 | printf("\n"); |
| 57 | printf("OPTIONS:\n"); | 59 | printf("OPTIONS:\n"); |
| 58 | printf(" -i, --infile FILE Optional FILE to convert from or stdin if - or not used\n"); | 60 | printf(" -i, --infile FILE Optional FILE to convert from or stdin if - or not used\n"); |
| 59 | printf(" -o, --outfile FILE Optional FILE to convert to or stdout if - or not used\n"); | 61 | printf(" -o, --outfile FILE Optional FILE to convert to or stdout if - or not used\n"); |
| 60 | printf(" -f, --format FORMAT Force output format, regardless of input type\n"); | 62 | printf(" -f, --format FORMAT Force output format, regardless of input type\n"); |
| 61 | printf(" FORMAT is one of xml, bin, or json\n"); | 63 | printf(" FORMAT is one of xml, bin, json, or openstep\n"); |
| 62 | printf(" If omitted XML will be converted to binary,\n"); | 64 | printf(" If omitted, XML will be converted to binary,\n"); |
| 63 | printf(" and binary to XML.\n"); | 65 | printf(" and binary to XML.\n"); |
| 66 | printf(" -c, --compact JSON and OpenStep only: Print output in compact form.\n"); | ||
| 67 | printf(" By default, the output will be pretty-printed.\n"); | ||
| 64 | printf(" -d, --debug Enable extended debug output\n"); | 68 | printf(" -d, --debug Enable extended debug output\n"); |
| 65 | printf(" -v, --version Print version information\n"); | 69 | printf(" -v, --version Print version information\n"); |
| 66 | printf("\n"); | 70 | printf("\n"); |
| @@ -112,6 +116,8 @@ static options_t *parse_arguments(int argc, char *argv[]) | |||
| 112 | options->out_fmt = 2; | 116 | options->out_fmt = 2; |
| 113 | } else if (!strncmp(argv[i+1], "json", 4)) { | 117 | } else if (!strncmp(argv[i+1], "json", 4)) { |
| 114 | options->out_fmt = 3; | 118 | options->out_fmt = 3; |
| 119 | } else if (!strncmp(argv[i+1], "openstep", 8) || !strncmp(argv[i+1], "ostep", 5)) { | ||
| 120 | options->out_fmt = 4; | ||
| 115 | } else { | 121 | } else { |
| 116 | fprintf(stderr, "ERROR: Unsupported output format\n"); | 122 | fprintf(stderr, "ERROR: Unsupported output format\n"); |
| 117 | free(options); | 123 | free(options); |
| @@ -120,6 +126,10 @@ static options_t *parse_arguments(int argc, char *argv[]) | |||
| 120 | i++; | 126 | i++; |
| 121 | continue; | 127 | continue; |
| 122 | } | 128 | } |
| 129 | else if (!strcmp(argv[i], "--compact") || !strcmp(argv[i], "-c")) | ||
| 130 | { | ||
| 131 | options->compact = 1; | ||
| 132 | } | ||
| 123 | else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) | 133 | else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) |
| 124 | { | 134 | { |
| 125 | options->debug = 1; | 135 | options->debug = 1; |
| @@ -216,13 +226,6 @@ int main(int argc, char *argv[]) | |||
| 216 | free(options); | 226 | free(options); |
| 217 | return 1; | 227 | return 1; |
| 218 | } | 228 | } |
| 219 | |||
| 220 | if (read_size < 8) { | ||
| 221 | fprintf(stderr, "ERROR: Input file is too small to contain valid plist data.\n"); | ||
| 222 | free(plist_entire); | ||
| 223 | free(options); | ||
| 224 | return 1; | ||
| 225 | } | ||
| 226 | } | 229 | } |
| 227 | else | 230 | else |
| 228 | { | 231 | { |
| @@ -237,13 +240,6 @@ int main(int argc, char *argv[]) | |||
| 237 | memset(&filestats, '\0', sizeof(struct stat)); | 240 | memset(&filestats, '\0', sizeof(struct stat)); |
| 238 | fstat(fileno(iplist), &filestats); | 241 | fstat(fileno(iplist), &filestats); |
| 239 | 242 | ||
| 240 | if (filestats.st_size < 8) { | ||
| 241 | fprintf(stderr, "ERROR: Input file is too small to contain valid plist data.\n"); | ||
| 242 | free(options); | ||
| 243 | fclose(iplist); | ||
| 244 | return -1; | ||
| 245 | } | ||
| 246 | |||
| 247 | plist_entire = (char *) malloc(sizeof(char) * (filestats.st_size + 1)); | 243 | plist_entire = (char *) malloc(sizeof(char) * (filestats.st_size + 1)); |
| 248 | read_size = fread(plist_entire, sizeof(char), filestats.st_size, iplist); | 244 | read_size = fread(plist_entire, sizeof(char), filestats.st_size, iplist); |
| 249 | plist_entire[read_size] = '\0'; | 245 | plist_entire[read_size] = '\0'; |
| @@ -276,7 +272,9 @@ int main(int argc, char *argv[]) | |||
| 276 | } else if (options->out_fmt == 2) { | 272 | } else if (options->out_fmt == 2) { |
| 277 | output_res = plist_to_xml(root_node, &plist_out, &size); | 273 | output_res = plist_to_xml(root_node, &plist_out, &size); |
| 278 | } else if (options->out_fmt == 3) { | 274 | } else if (options->out_fmt == 3) { |
| 279 | output_res = plist_to_json(root_node, &plist_out, &size, 0); | 275 | output_res = plist_to_json(root_node, &plist_out, &size, !options->compact); |
| 276 | } else if (options->out_fmt == 4) { | ||
| 277 | output_res = plist_to_openstep(root_node, &plist_out, &size, !options->compact); | ||
| 280 | } | 278 | } |
| 281 | } | 279 | } |
| 282 | } | 280 | } |
| @@ -316,8 +314,20 @@ int main(int argc, char *argv[]) | |||
| 316 | ret = 1; | 314 | ret = 1; |
| 317 | } | 315 | } |
| 318 | } else { | 316 | } else { |
| 319 | fprintf(stderr, "ERROR: Could not parse plist data (%d)\n", input_res); | 317 | switch (input_res) { |
| 320 | ret = 1; | 318 | case PLIST_ERR_PARSE: |
| 319 | if (options->out_fmt == 0) { | ||
| 320 | fprintf(stderr, "ERROR: Could not parse plist data, expected XML or binary plist\n"); | ||
| 321 | } else { | ||
| 322 | fprintf(stderr, "ERROR: Could not parse plist data (%d)\n", input_res); | ||
| 323 | } | ||
| 324 | ret = 3; | ||
| 325 | break; | ||
| 326 | default: | ||
| 327 | fprintf(stderr, "ERROR: Could not parse plist data (%d)\n", input_res); | ||
| 328 | ret = 1; | ||
| 329 | break; | ||
| 330 | } | ||
| 321 | } | 331 | } |
| 322 | 332 | ||
| 323 | free(options); | 333 | free(options); |
