diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/Makefile.am | 7 | ||||
| -rw-r--r-- | tools/plistutil.c | 164 | ||||
| -rw-r--r-- | tools/plistutil.h | 29 |
3 files changed, 200 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..a50f819 --- /dev/null +++ b/tools/Makefile.am | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | AM_CFLAGS = $(GLOBAL_CFLAGS) -I$(top_srcdir)/include | ||
| 2 | AM_LDFLAGS = | ||
| 3 | |||
| 4 | bin_PROGRAMS = plistutil | ||
| 5 | |||
| 6 | plistutil_SOURCES = plistutil.c plistutil.h | ||
| 7 | plistutil_LDADD = ../src/libplist.la | ||
diff --git a/tools/plistutil.c b/tools/plistutil.c new file mode 100644 index 0000000..3e09bb2 --- /dev/null +++ b/tools/plistutil.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /* | ||
| 2 | * plistutil.c | ||
| 3 | * source for plist convertion tool | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Zach C. All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | |||
| 23 | #include "plist/plist.h" | ||
| 24 | #include "plistutil.h" | ||
| 25 | |||
| 26 | #include <stdio.h> | ||
| 27 | #include <stdlib.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <sys/stat.h> | ||
| 30 | |||
| 31 | #ifdef _MSC_VER | ||
| 32 | #pragma warning(disable:4996) | ||
| 33 | #endif | ||
| 34 | |||
| 35 | |||
| 36 | int main(int argc, char *argv[]) | ||
| 37 | { | ||
| 38 | FILE *iplist = NULL; | ||
| 39 | plist_t root_node = NULL; | ||
| 40 | char *plist_out = NULL; | ||
| 41 | uint32_t size = 0; | ||
| 42 | int read_size = 0; | ||
| 43 | char *plist_entire = NULL; | ||
| 44 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | ||
| 45 | Options *options = parse_arguments(argc, argv); | ||
| 46 | |||
| 47 | if (!options) | ||
| 48 | { | ||
| 49 | print_usage(); | ||
| 50 | free(filestats); | ||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | //read input file | ||
| 54 | iplist = fopen(options->in_file, "rb"); | ||
| 55 | if (!iplist) | ||
| 56 | return 1; | ||
| 57 | stat(options->in_file, filestats); | ||
| 58 | plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); | ||
| 59 | read_size = fread(plist_entire, sizeof(char), filestats->st_size, iplist); | ||
| 60 | fclose(iplist); | ||
| 61 | |||
| 62 | |||
| 63 | //convert one format to another | ||
| 64 | |||
| 65 | |||
| 66 | if (memcmp(plist_entire, "bplist00", 8) == 0) | ||
| 67 | { | ||
| 68 | plist_from_bin(plist_entire, read_size, &root_node); | ||
| 69 | plist_to_xml(root_node, &plist_out, &size); | ||
| 70 | } | ||
| 71 | else | ||
| 72 | { | ||
| 73 | plist_from_xml(plist_entire, read_size, &root_node); | ||
| 74 | plist_to_bin(root_node, &plist_out, &size); | ||
| 75 | } | ||
| 76 | plist_free(root_node); | ||
| 77 | free(plist_entire); | ||
| 78 | free(filestats); | ||
| 79 | |||
| 80 | if (plist_out) | ||
| 81 | { | ||
| 82 | if (options->out_file != NULL) | ||
| 83 | { | ||
| 84 | FILE *oplist = fopen(options->out_file, "wb"); | ||
| 85 | if (!oplist) | ||
| 86 | return 1; | ||
| 87 | fwrite(plist_out, size, sizeof(char), oplist); | ||
| 88 | fclose(oplist); | ||
| 89 | } | ||
| 90 | //if no output file specified, write to stdout | ||
| 91 | else | ||
| 92 | fwrite(plist_out, size, sizeof(char), stdout); | ||
| 93 | |||
| 94 | free(plist_out); | ||
| 95 | } | ||
| 96 | else | ||
| 97 | printf("ERROR\n"); | ||
| 98 | |||
| 99 | free(options); | ||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | Options *parse_arguments(int argc, char *argv[]) | ||
| 104 | { | ||
| 105 | int i = 0; | ||
| 106 | |||
| 107 | Options *options = (Options *) malloc(sizeof(Options)); | ||
| 108 | memset(options, 0, sizeof(Options)); | ||
| 109 | |||
| 110 | for (i = 1; i < argc; i++) | ||
| 111 | { | ||
| 112 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) | ||
| 113 | { | ||
| 114 | if ((i + 1) == argc) | ||
| 115 | { | ||
| 116 | free(options); | ||
| 117 | return NULL; | ||
| 118 | } | ||
| 119 | options->in_file = argv[i + 1]; | ||
| 120 | i++; | ||
| 121 | continue; | ||
| 122 | } | ||
| 123 | |||
| 124 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) | ||
| 125 | { | ||
| 126 | if ((i + 1) == argc) | ||
| 127 | { | ||
| 128 | free(options); | ||
| 129 | return NULL; | ||
| 130 | } | ||
| 131 | options->out_file = argv[i + 1]; | ||
| 132 | i++; | ||
| 133 | continue; | ||
| 134 | } | ||
| 135 | |||
| 136 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) | ||
| 137 | { | ||
| 138 | options->debug = 1; | ||
| 139 | } | ||
| 140 | |||
| 141 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) | ||
| 142 | { | ||
| 143 | free(options); | ||
| 144 | return NULL; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | if (!options->in_file /*|| !options->out_file */ ) | ||
| 149 | { | ||
| 150 | free(options); | ||
| 151 | return NULL; | ||
| 152 | } | ||
| 153 | |||
| 154 | return options; | ||
| 155 | } | ||
| 156 | |||
| 157 | void print_usage() | ||
| 158 | { | ||
| 159 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); | ||
| 160 | printf("\n"); | ||
| 161 | printf("\t-i or --infile: The file to read in.\n"); | ||
| 162 | printf("\t-o or --outfile: The file to convert to.\n"); | ||
| 163 | printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); | ||
| 164 | } | ||
diff --git a/tools/plistutil.h b/tools/plistutil.h new file mode 100644 index 0000000..40421a3 --- /dev/null +++ b/tools/plistutil.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* | ||
| 2 | * plistutil.h | ||
| 3 | * header for plist convertion tool | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Zach C. All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | typedef struct _options | ||
| 23 | { | ||
| 24 | char *in_file, *out_file; | ||
| 25 | uint8_t debug, in_fmt, out_fmt; | ||
| 26 | } Options; | ||
| 27 | |||
| 28 | Options *parse_arguments(int argc, char *argv[]); | ||
| 29 | void print_usage(); | ||
