summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/plistutil.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index 4a4b75e..99f7e93 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -39,7 +39,7 @@
39typedef struct _options 39typedef struct _options
40{ 40{
41 char *in_file, *out_file; 41 char *in_file, *out_file;
42 uint8_t debug, in_fmt, out_fmt; 42 uint8_t debug, in_fmt, out_fmt; // fmts 0 = undef, 1 = bin, 2 = xml, 3 = json someday
43} options_t; 43} options_t;
44 44
45static void print_usage(int argc, char *argv[]) 45static void print_usage(int argc, char *argv[])
@@ -50,6 +50,7 @@ static void print_usage(int argc, char *argv[])
50 printf("Convert a plist FILE from binary to XML format or vice-versa.\n\n"); 50 printf("Convert a plist FILE from binary to XML format or vice-versa.\n\n");
51 printf(" -i, --infile FILE\tOptional FILE to convert from or stdin if - or not used\n"); 51 printf(" -i, --infile FILE\tOptional FILE to convert from or stdin if - or not used\n");
52 printf(" -o, --outfile FILE\tOptional FILE to convert to or stdout if - or not used\n"); 52 printf(" -o, --outfile FILE\tOptional FILE to convert to or stdout if - or not used\n");
53 printf(" -f, --format [bin|xml]\t\tForce output format, regardless of input type\n");
53 printf(" -d, --debug\t\tEnable extended debug output\n"); 54 printf(" -d, --debug\t\tEnable extended debug output\n");
54 printf("\n"); 55 printf("\n");
55} 56}
@@ -60,6 +61,7 @@ static options_t *parse_arguments(int argc, char *argv[])
60 61
61 options_t *options = (options_t *) malloc(sizeof(options_t)); 62 options_t *options = (options_t *) malloc(sizeof(options_t));
62 memset(options, 0, sizeof(options_t)); 63 memset(options, 0, sizeof(options_t));
64 options->out_fmt = 0;
63 65
64 for (i = 1; i < argc; i++) 66 for (i = 1; i < argc; i++)
65 { 67 {
@@ -87,6 +89,26 @@ static options_t *parse_arguments(int argc, char *argv[])
87 continue; 89 continue;
88 } 90 }
89 91
92 if (!strcmp(argv[i], "--format") || !strcmp(argv[i], "-f"))
93 {
94 if ((i + 1) == argc)
95 {
96 free(options);
97 return NULL;
98 }
99 if (!strncmp(argv[i+1], "bin", 3)) {
100 options->out_fmt = 1;
101 } else if (!strncmp(argv[i+1], "xml", 3)) {
102 options->out_fmt = 2;
103 } else {
104 printf("ERROR: Unsupported output format\n");
105 free(options);
106 return NULL;
107 }
108 i++;
109 continue;
110 }
111
90 if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d")) 112 if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d"))
91 { 113 {
92 options->debug = 1; 114 options->debug = 1;
@@ -190,16 +212,45 @@ int main(int argc, char *argv[])
190 fclose(iplist); 212 fclose(iplist);
191 } 213 }
192 214
193 // convert from binary to xml or vice-versa 215 if (options->out_fmt == 0) {
194 if (plist_is_binary(plist_entire, read_size)) 216 // convert from binary to xml or vice-versa<br>
195 { 217 if (plist_is_binary(plist_entire, read_size))
196 plist_from_bin(plist_entire, read_size, &root_node); 218 {
197 plist_to_xml(root_node, &plist_out, &size); 219 plist_from_bin(plist_entire, read_size, &root_node);
220 plist_to_xml(root_node, &plist_out, &size);
221 }
222 else
223 {
224 plist_from_xml(plist_entire, read_size, &root_node);
225 plist_to_bin(root_node, &plist_out, &size);
226 }
198 } 227 }
199 else 228 else
200 { 229 {
201 plist_from_xml(plist_entire, read_size, &root_node); 230 if (options->out_fmt == 1) {
202 plist_to_bin(root_node, &plist_out, &size); 231 if (plist_is_binary(plist_entire, read_size))
232 {
233 plist_out = malloc(sizeof(char) * read_size);
234 memcpy(plist_out, plist_entire, read_size);
235 size = read_size;
236 }
237 else
238 {
239 plist_from_xml(plist_entire, read_size, &root_node);
240 plist_to_bin(root_node, &plist_out, &size);
241 }
242 } else if (options->out_fmt == 2) {
243 if (plist_is_binary(plist_entire, read_size)) {
244 plist_from_bin(plist_entire, read_size, &root_node);
245 plist_to_xml(root_node, &plist_out, &size);
246 }
247 else
248 {
249 plist_out = malloc(sizeof(char) * read_size);
250 memcpy(plist_out, plist_entire, read_size);
251 size = read_size;
252 }
253 }
203 } 254 }
204 plist_free(root_node); 255 plist_free(root_node);
205 free(plist_entire); 256 free(plist_entire);